digdig 0.0.1 → 0.0.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.
Files changed (272) hide show
  1. package/README.md +439 -2
  2. package/digdig.config.example.json +14 -0
  3. package/dist/claims/deterministic-checks.d.ts +48 -0
  4. package/dist/claims/deterministic-checks.d.ts.map +1 -0
  5. package/dist/claims/deterministic-checks.js +162 -0
  6. package/dist/claims/deterministic-checks.js.map +1 -0
  7. package/dist/claims/policy.d.ts +25 -0
  8. package/dist/claims/policy.d.ts.map +1 -0
  9. package/dist/claims/policy.js +168 -0
  10. package/dist/claims/policy.js.map +1 -0
  11. package/dist/claims/store.d.ts +37 -0
  12. package/dist/claims/store.d.ts.map +1 -0
  13. package/dist/claims/store.js +152 -0
  14. package/dist/claims/store.js.map +1 -0
  15. package/dist/claims/types.d.ts +98 -0
  16. package/dist/claims/types.d.ts.map +1 -0
  17. package/dist/claims/types.js +9 -0
  18. package/dist/claims/types.js.map +1 -0
  19. package/dist/commands/build-graph.d.ts +8 -0
  20. package/dist/commands/build-graph.d.ts.map +1 -0
  21. package/dist/commands/build-graph.js +70 -0
  22. package/dist/commands/build-graph.js.map +1 -0
  23. package/dist/commands/claim.d.ts +13 -0
  24. package/dist/commands/claim.d.ts.map +1 -0
  25. package/dist/commands/claim.js +131 -0
  26. package/dist/commands/claim.js.map +1 -0
  27. package/dist/commands/doc-index.d.ts +12 -0
  28. package/dist/commands/doc-index.d.ts.map +1 -0
  29. package/dist/commands/doc-index.js +49 -0
  30. package/dist/commands/doc-index.js.map +1 -0
  31. package/dist/commands/doc-search.d.ts +16 -0
  32. package/dist/commands/doc-search.d.ts.map +1 -0
  33. package/dist/commands/doc-search.js +41 -0
  34. package/dist/commands/doc-search.js.map +1 -0
  35. package/dist/commands/evidence.d.ts +20 -0
  36. package/dist/commands/evidence.d.ts.map +1 -0
  37. package/dist/commands/evidence.js +215 -0
  38. package/dist/commands/evidence.js.map +1 -0
  39. package/dist/commands/extract.d.ts +10 -0
  40. package/dist/commands/extract.d.ts.map +1 -0
  41. package/dist/commands/extract.js +77 -0
  42. package/dist/commands/extract.js.map +1 -0
  43. package/dist/commands/graph-add.d.ts +7 -0
  44. package/dist/commands/graph-add.d.ts.map +1 -0
  45. package/dist/commands/graph-add.d.ts.sync-conflict-20260629-232900-2SGIW5T.map +1 -0
  46. package/dist/commands/graph-add.js +93 -0
  47. package/dist/commands/graph-add.js.map +1 -0
  48. package/dist/commands/graph-add.js.sync-conflict-20260629-232916-2SGIW5T.map +1 -0
  49. package/dist/commands/graph-add.sync-conflict-20260629-232853-2SGIW5T.js +163 -0
  50. package/dist/commands/graph-drill.d.ts +11 -0
  51. package/dist/commands/graph-drill.d.ts.map +1 -0
  52. package/dist/commands/graph-drill.js +26 -0
  53. package/dist/commands/graph-drill.js.map +1 -0
  54. package/dist/commands/graph-explore.d.ts +10 -0
  55. package/dist/commands/graph-explore.d.ts.map +1 -0
  56. package/dist/commands/graph-explore.js +32 -0
  57. package/dist/commands/graph-explore.js.map +1 -0
  58. package/dist/commands/graph-obfuscate.d.ts +17 -0
  59. package/dist/commands/graph-obfuscate.d.ts.map +1 -0
  60. package/dist/commands/graph-obfuscate.js +110 -0
  61. package/dist/commands/graph-obfuscate.js.map +1 -0
  62. package/dist/commands/graph-search.d.ts +11 -0
  63. package/dist/commands/graph-search.d.ts.map +1 -0
  64. package/dist/commands/graph-search.js +19 -0
  65. package/dist/commands/graph-search.js.map +1 -0
  66. package/dist/commands/graph-traverse.d.ts +10 -0
  67. package/dist/commands/graph-traverse.d.ts.map +1 -0
  68. package/dist/commands/graph-traverse.js +39 -0
  69. package/dist/commands/graph-traverse.js.map +1 -0
  70. package/dist/commands/json-input.d.ts +18 -0
  71. package/dist/commands/json-input.d.ts.map +1 -0
  72. package/dist/commands/json-input.js +50 -0
  73. package/dist/commands/json-input.js.map +1 -0
  74. package/dist/commands/query-graph.d.ts +13 -0
  75. package/dist/commands/query-graph.d.ts.map +1 -0
  76. package/dist/commands/query-graph.js +219 -0
  77. package/dist/commands/query-graph.js.map +1 -0
  78. package/dist/commands/raw.d.ts +14 -0
  79. package/dist/commands/raw.d.ts.map +1 -0
  80. package/dist/commands/raw.js +125 -0
  81. package/dist/commands/raw.js.map +1 -0
  82. package/dist/commands/results-add.d.ts +10 -0
  83. package/dist/commands/results-add.d.ts.map +1 -0
  84. package/dist/commands/results-add.js +80 -0
  85. package/dist/commands/results-add.js.map +1 -0
  86. package/dist/commands/review.d.ts +12 -0
  87. package/dist/commands/review.d.ts.map +1 -0
  88. package/dist/commands/review.js +119 -0
  89. package/dist/commands/review.js.map +1 -0
  90. package/dist/commands/session.d.ts +28 -0
  91. package/dist/commands/session.d.ts.map +1 -0
  92. package/dist/commands/session.js +149 -0
  93. package/dist/commands/session.js.map +1 -0
  94. package/dist/commands/verdict.d.ts +9 -0
  95. package/dist/commands/verdict.d.ts.map +1 -0
  96. package/dist/commands/verdict.js +40 -0
  97. package/dist/commands/verdict.js.map +1 -0
  98. package/dist/config.d.ts +28 -0
  99. package/dist/config.d.ts.map +1 -0
  100. package/dist/config.js +148 -0
  101. package/dist/config.js.map +1 -0
  102. package/dist/deep/co-occurrence.d.ts +50 -0
  103. package/dist/deep/co-occurrence.d.ts.map +1 -0
  104. package/dist/deep/co-occurrence.js +95 -0
  105. package/dist/deep/co-occurrence.js.map +1 -0
  106. package/dist/deep/dedupe.d.ts +19 -0
  107. package/dist/deep/dedupe.d.ts.map +1 -0
  108. package/dist/deep/dedupe.js +96 -0
  109. package/dist/deep/dedupe.js.map +1 -0
  110. package/dist/deep/degree-utils.d.ts +39 -0
  111. package/dist/deep/degree-utils.d.ts.map +1 -0
  112. package/dist/deep/degree-utils.js +42 -0
  113. package/dist/deep/degree-utils.js.map +1 -0
  114. package/dist/deep/extractor.d.sync-conflict-20260629-232902-2SGIW5T.ts +37 -0
  115. package/dist/deep/extractor.d.ts +42 -0
  116. package/dist/deep/extractor.d.ts.map +1 -0
  117. package/dist/deep/extractor.d.ts.sync-conflict-20260629-232921-2SGIW5T.map +1 -0
  118. package/dist/deep/extractor.js +392 -0
  119. package/dist/deep/extractor.js.map +1 -0
  120. package/dist/deep/extractor.js.sync-conflict-20260629-232921-2SGIW5T.map +1 -0
  121. package/dist/deep/extractor.sync-conflict-20260629-232903-2SGIW5T.js +203 -0
  122. package/dist/deep/graph-explore.d.ts +115 -0
  123. package/dist/deep/graph-explore.d.ts.map +1 -0
  124. package/dist/deep/graph-explore.js +588 -0
  125. package/dist/deep/graph-explore.js.map +1 -0
  126. package/dist/deep/graph-obfuscate.d.ts +51 -0
  127. package/dist/deep/graph-obfuscate.d.ts.map +1 -0
  128. package/dist/deep/graph-obfuscate.js +226 -0
  129. package/dist/deep/graph-obfuscate.js.map +1 -0
  130. package/dist/deep/graph-preprocess.d.ts +48 -0
  131. package/dist/deep/graph-preprocess.d.ts.map +1 -0
  132. package/dist/deep/graph-preprocess.js +40 -0
  133. package/dist/deep/graph-preprocess.js.map +1 -0
  134. package/dist/deep/graph-sampling.d.ts +51 -0
  135. package/dist/deep/graph-sampling.d.ts.map +1 -0
  136. package/dist/deep/graph-sampling.js +410 -0
  137. package/dist/deep/graph-sampling.js.map +1 -0
  138. package/dist/deep/graph.d.sync-conflict-20260629-232917-2SGIW5T.ts +78 -0
  139. package/dist/deep/graph.d.ts +87 -0
  140. package/dist/deep/graph.d.ts.map +1 -0
  141. package/dist/deep/graph.d.ts.sync-conflict-20260629-232911-2SGIW5T.map +1 -0
  142. package/dist/deep/graph.js +200 -0
  143. package/dist/deep/graph.js.map +1 -0
  144. package/dist/deep/graph.js.sync-conflict-20260629-232855-2SGIW5T.map +1 -0
  145. package/dist/deep/graph.sync-conflict-20260629-232907-2SGIW5T.js +194 -0
  146. package/dist/deep/index.d.ts +10 -0
  147. package/dist/deep/index.d.ts.map +1 -0
  148. package/dist/deep/index.js +10 -0
  149. package/dist/deep/index.js.map +1 -0
  150. package/dist/deep/iteration-data.d.ts +38 -0
  151. package/dist/deep/iteration-data.d.ts.map +1 -0
  152. package/dist/deep/iteration-data.js +49 -0
  153. package/dist/deep/iteration-data.js.map +1 -0
  154. package/dist/deep/keywords.d.ts +27 -0
  155. package/dist/deep/keywords.d.ts.map +1 -0
  156. package/dist/deep/keywords.js +293 -0
  157. package/dist/deep/keywords.js.map +1 -0
  158. package/dist/deep/local-doc/indexer.d.ts +30 -0
  159. package/dist/deep/local-doc/indexer.d.ts.map +1 -0
  160. package/dist/deep/local-doc/indexer.js +402 -0
  161. package/dist/deep/local-doc/indexer.js.map +1 -0
  162. package/dist/deep/local-doc/scanner.d.ts +10 -0
  163. package/dist/deep/local-doc/scanner.d.ts.map +1 -0
  164. package/dist/deep/local-doc/scanner.js +165 -0
  165. package/dist/deep/local-doc/scanner.js.map +1 -0
  166. package/dist/deep/local-doc/searcher.d.ts +38 -0
  167. package/dist/deep/local-doc/searcher.d.ts.map +1 -0
  168. package/dist/deep/local-doc/searcher.js +212 -0
  169. package/dist/deep/local-doc/searcher.js.map +1 -0
  170. package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.d.ts +38 -0
  171. package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.d.ts.map +1 -0
  172. package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.js +212 -0
  173. package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.js.map +1 -0
  174. package/dist/deep/local-doc/types.d.ts +61 -0
  175. package/dist/deep/local-doc/types.d.ts.map +1 -0
  176. package/dist/deep/local-doc/types.js +18 -0
  177. package/dist/deep/local-doc/types.js.map +1 -0
  178. package/dist/deep/path-extraction.d.ts +53 -0
  179. package/dist/deep/path-extraction.d.ts.map +1 -0
  180. package/dist/deep/path-extraction.js +229 -0
  181. package/dist/deep/path-extraction.js.map +1 -0
  182. package/dist/deep/quality-assess.d.ts +46 -0
  183. package/dist/deep/quality-assess.d.ts.map +1 -0
  184. package/dist/deep/quality-assess.js +122 -0
  185. package/dist/deep/quality-assess.js.map +1 -0
  186. package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.d.ts +46 -0
  187. package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.d.ts.map +1 -0
  188. package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.js +122 -0
  189. package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.js.map +1 -0
  190. package/dist/deep/query-redundancy.d.ts +52 -0
  191. package/dist/deep/query-redundancy.d.ts.map +1 -0
  192. package/dist/deep/query-redundancy.js +122 -0
  193. package/dist/deep/query-redundancy.js.map +1 -0
  194. package/dist/deep/query-suggest.d.ts +35 -0
  195. package/dist/deep/query-suggest.d.ts.map +1 -0
  196. package/dist/deep/query-suggest.js +98 -0
  197. package/dist/deep/query-suggest.js.map +1 -0
  198. package/dist/deep/recovery-analysis.d.ts +60 -0
  199. package/dist/deep/recovery-analysis.d.ts.map +1 -0
  200. package/dist/deep/recovery-analysis.js +185 -0
  201. package/dist/deep/recovery-analysis.js.map +1 -0
  202. package/dist/deep/rrf.d.ts +13 -0
  203. package/dist/deep/rrf.d.ts.map +1 -0
  204. package/dist/deep/rrf.js +23 -0
  205. package/dist/deep/rrf.js.map +1 -0
  206. package/dist/deep/search-strategy.d.ts +37 -0
  207. package/dist/deep/search-strategy.d.ts.map +1 -0
  208. package/dist/deep/search-strategy.js +106 -0
  209. package/dist/deep/search-strategy.js.map +1 -0
  210. package/dist/deep/session.d.sync-conflict-20260629-232917-2SGIW5T.ts +71 -0
  211. package/dist/deep/session.d.ts +180 -0
  212. package/dist/deep/session.d.ts.map +1 -0
  213. package/dist/deep/session.d.ts.sync-conflict-20260629-232921-2SGIW5T.map +1 -0
  214. package/dist/deep/session.js +643 -0
  215. package/dist/deep/session.js.map +1 -0
  216. package/dist/deep/session.js.sync-conflict-20260629-232854-2SGIW5T.map +1 -0
  217. package/dist/deep/simhash.d.ts +17 -0
  218. package/dist/deep/simhash.d.ts.map +1 -0
  219. package/dist/deep/simhash.js +72 -0
  220. package/dist/deep/simhash.js.map +1 -0
  221. package/dist/deep/tfidf.d.ts +38 -0
  222. package/dist/deep/tfidf.d.ts.map +1 -0
  223. package/dist/deep/tfidf.js +103 -0
  224. package/dist/deep/tfidf.js.map +1 -0
  225. package/dist/deepseek-service.d.ts +22 -0
  226. package/dist/deepseek-service.d.ts.map +1 -0
  227. package/dist/deepseek-service.js +80 -0
  228. package/dist/deepseek-service.js.map +1 -0
  229. package/dist/entry.d.ts +9 -0
  230. package/dist/entry.d.ts.map +1 -0
  231. package/dist/entry.js +24 -0
  232. package/dist/entry.js.map +1 -0
  233. package/dist/index.d.ts +6 -0
  234. package/dist/index.d.ts.map +1 -0
  235. package/dist/index.js +7 -0
  236. package/dist/index.js.map +1 -0
  237. package/dist/init.d.ts +16 -0
  238. package/dist/init.d.ts.map +1 -0
  239. package/dist/init.js +143 -0
  240. package/dist/init.js.map +1 -0
  241. package/dist/legacy.d.ts +60 -0
  242. package/dist/legacy.d.ts.map +1 -0
  243. package/dist/legacy.js +119 -0
  244. package/dist/legacy.js.map +1 -0
  245. package/dist/ollama-service.d.ts +22 -0
  246. package/dist/ollama-service.d.ts.map +1 -0
  247. package/dist/ollama-service.js +50 -0
  248. package/dist/ollama-service.js.map +1 -0
  249. package/dist/protocol.d.ts +23 -0
  250. package/dist/protocol.d.ts.map +1 -0
  251. package/dist/protocol.js +26 -0
  252. package/dist/protocol.js.map +1 -0
  253. package/dist/runCli.d.ts +8 -0
  254. package/dist/runCli.d.ts.map +1 -0
  255. package/dist/runCli.d.ts.sync-conflict-20260629-232854-2SGIW5T.map +1 -0
  256. package/dist/runCli.js +1564 -0
  257. package/dist/runCli.js.map +1 -0
  258. package/dist/runCli.js.sync-conflict-20260629-232857-2SGIW5T.map +1 -0
  259. package/dist/runCli.sync-conflict-20260629-232915-2SGIW5T.js +1109 -0
  260. package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.d.ts +8 -0
  261. package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.d.ts.map +1 -0
  262. package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.js +1111 -0
  263. package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.js.map +1 -0
  264. package/dist/service.d.ts +63 -0
  265. package/dist/service.d.ts.map +1 -0
  266. package/dist/service.js +139 -0
  267. package/dist/service.js.map +1 -0
  268. package/dist/sxng.d.ts +11 -0
  269. package/dist/sxng.d.ts.map +1 -0
  270. package/dist/sxng.js +14 -0
  271. package/dist/sxng.js.map +1 -0
  272. package/package.json +56 -12
package/README.md CHANGED
@@ -1,4 +1,441 @@
1
- # digdig
1
+ # 🔍 digdig
2
2
 
3
- Reserved package name for the upcoming `sxng-cli` rename.
3
+ > 📖 **完整文档请访问 GitHub**: https://github.com/hkwuks/digdig#readme
4
+ >
5
+ > 本 README 为快速参考,详细的安装指南(包括 SearXNG 自托管配置、Docker 部署、settings.yml 配置等)请参阅 GitHub 文档。
4
6
 
7
+ <p align="center">
8
+ <b>A multi-backend web search CLI for agents</b><br>
9
+ SearXNG · Ollama · DeepSeek — privacy-respecting search from your terminal
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://www.npmjs.com/package/digdig">
14
+ <img src="https://img.shields.io/npm/v/digdig?style=flat-square&color=cb3837" alt="npm version">
15
+ </a>
16
+ <a href="https://www.npmjs.com/package/digdig">
17
+ <img src="https://img.shields.io/npm/dm/digdig?style=flat-square&color=cb3837" alt="npm downloads">
18
+ </a>
19
+ <a href="https://github.com/hkwuks/digdig/blob/main/LICENSE">
20
+ <img src="https://img.shields.io/github/license/hkwuks/digdig?style=flat-square&color=green" alt="license">
21
+ </a>
22
+ <img src="https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen?style=flat-square" alt="node version">
23
+ </p>
24
+
25
+ ## ✨ Features
26
+
27
+ - 🔎 **Multi-Engine Search** — Search across Google, Bing, DuckDuckGo, GitHub, StackOverflow, and 30+ engines simultaneously
28
+ - 🔌 **Pluggable Backends** — SearXNG is the default; select Ollama web search or DeepSeek Search with `-e ollama` / `-e deepseek`. No backend is an automatic fallback for another.
29
+ - 🔌 **Pluggable Backends** — SearXNG is the default; select Ollama web search or DeepSeek Search with `-e ollama` / `-e deepseek`. No backend is an automatic fallback for another.
30
+ - 🔄 **Dynamic Discovery** — Auto-fetches available engines and categories from your SearXNG server
31
+ - 📄 **Multiple Formats** — Markdown (LLM-optimized) or JSON output
32
+ - 🧠 **Deep Search** — Multi-round iterative research with session accumulation, quality assessment, and recovery strategies
33
+ - 🔍 **Content Extraction** — Extract full article content from URLs or session results, with Obscura fallback and Agent-selected Jina Reader extraction
34
+ - 🗂️ **Session Management** — Separates search discovery from extracted bodies; stable result IDs and revisions prevent stale approvals in parallel work
35
+ - 🔗 **External Result Fusion** — Import external search or extraction output from session-scoped JSON files, without PowerShell inline-JSON escaping risks
36
+ - ⭐ **Quality Assessment** — 3 independent indicators: content depth, source diversity, and novelty
37
+ - 🕸️ **Knowledge Graph** — Structural (query→result→domain) + semantic (entity relations with approved result-ID provenance) graph layers
38
+ - 🔄 **Query Redundancy Check** — Word-level or character-bigram Jaccard detects repeated queries
39
+ - 💡 **Agent-First Design** — Outputs structured analysis data (quality, suggestions, recovery) for LLM Agent decision-making
40
+ - 📁 **Local Document Search** — Index and BM25-search local Markdown/text files; results auto-injected into the session pipeline as `source: "local"`
41
+ - ✅ **Claim—Evidence—Review Pipeline** — L2/L3 only: submit atomic claims, auto-search evidence, verify with stance, then policy-aggregate by publisher-domain diversity for auto-approval or Agent review
42
+
43
+ ## 📦 Installation
44
+
45
+ > ⚠️ **完整安装指南**: [GitHub - Installation](https://github.com/hkwuks/digdig#installation)
46
+ >
47
+ > 包含 SearXNG 自托管配置、Docker 部署、30+ 搜索引擎 settings.yml 配置等。
48
+
49
+ ```bash
50
+ npm install -g digdig
51
+ ```
52
+
53
+ This installs three names for the same program: **`dg`** (recommended, short), **`digdig`** (explicit), and the transitional **`sxng`** alias.
54
+
55
+ > ⚠️ **Upgrading from `sxng-cli`?** The new package is `digdig`; version numbers restart, so `digdig@0.0.2` is newer than `sxng-cli@1.3.2`. Uninstall the old package first. The `sxng` command, `.sxng/` sessions, `sxng.config.json`, and `SEARXNG_*` variables keep working (with a `[deprecation]` line on stderr) until `0.5.0`.
56
+
57
+ ```bash
58
+ npx skills add hkwuks/digdig
59
+ ```
60
+
61
+ > ⚠️ **Skill 同步**:更新 `digdig` 后,请同步更新 `digdig` skill 以保持功能一致:
62
+ >
63
+ > ```bash
64
+ > npx skills update hkwuks/digdig
65
+ > ```
66
+
67
+ Or from source:
68
+
69
+ ```bash
70
+ git clone https://github.com/hkwuks/digdig.git
71
+ cd digdig/cli
72
+ npm install
73
+ npm run build
74
+ npm link
75
+ ```
76
+
77
+ ### Obscura (Optional — for JS-heavy pages)
78
+
79
+ Content extraction uses **Defuddle + linkedom** by default. For JS-rendered pages (SPAs), enable [Obscura](https://github.com/h4ckf0r0day/obscura). When `--obscura` is used and the binary is absent, digdig automatically downloads the matching release asset from the official GitHub HTTPS download endpoint.
80
+
81
+ ```bash
82
+ # Linux x86_64
83
+ curl -LO https://github.com/h4ckf0r0day/obscura/releases/latest/download/obscura-x86_64-linux.tar.gz
84
+ tar xzf obscura-x86_64-linux.tar.gz
85
+ cp obscura ~/.local/bin/
86
+
87
+ # Verify
88
+ obscura --version
89
+ ```
90
+
91
+ ## 🚀 Quick Start
92
+
93
+ 1. **Configure the CLI:**
94
+ ```bash
95
+ dg init
96
+ ```
97
+ Or set environment variable:
98
+ ```bash
99
+ export DIGDIG_BASE_URL=http://your-searxng-instance:8080
100
+ ```
101
+
102
+ 2. **Perform a search:**
103
+ ```bash
104
+ dg "TypeScript tutorial"
105
+ ```
106
+
107
+ ## 📖 Usage
108
+
109
+ ### Commands
110
+
111
+ | Command | Description |
112
+ |---------|-------------|
113
+ | `dg init` | Interactive configuration setup |
114
+ | `dg <query>` | Perform a web search |
115
+ | `dg --queries "q1,q2"` | Multi-query search with RRF fusion |
116
+ | `dg extract --urls <urls>` | Extract content from web pages |
117
+ | `dg extract --session <name>` | Extract session results and merge content |
118
+ | `dg extract --obscura` | JS-rendering fallback for SPA pages |
119
+ | `dg extract --urls <url> --session <name> --jina` | Agent-selected Jina Reader extraction for explicit URLs, merged into a session |
120
+ | `dg --session new` | Create deep search session |
121
+ | `dg --session <name> --quality` | Assess result quality, list pending results |
122
+ | `dg --session <name> --quality --approve-file <path>` | Approve verified pending results selected by `{id, revision}` JSON |
123
+ | `dg suggest-queries <session>` | Get query suggestion data for Agent |
124
+ | `dg strategy-info <session>` | Check current search stage |
125
+ | `dg recovery-analysis <session>` | Get recovery strategies for poor quality |
126
+ | `dg session-report <session>` | Full session analysis report |
127
+ | `dg session-list` | List all sessions |
128
+ | `dg session-delete <name>` | Delete a session |
129
+ | `dg graph-preprocess <session>` | TF-IDF + co-occurrence + result provenance analysis |
130
+ | `dg graph-add <session> --data-file <path>` | Add semantic entities/edges backed by approved result IDs |
131
+ | `dg graph-search <session>` | Discover entities by keyword |
132
+ | `dg graph-explore <session>` | View entity relations |
133
+ | `dg graph-drill <session>` | Follow specific relations |
134
+ | `dg graph-traverse <session>` | Traverse reasoning paths |
135
+ | `dg graph-obfuscate <session>` | List obfuscation candidates |
136
+ | `dg results-add <session> --kind <search|extracted> --data-file <path>` | Import external discovery or extracted bodies from session-scoped UTF-8 JSON |
137
+ | `dg doc-index <path>` | Index local documents for BM25 search |
138
+ | `dg doc-search <session> <query> --path <path>` | Search indexed docs and inject results into session |
139
+ | `dg claim-add <session> --claims-file <path>` | Submit atomic claims from UTF-8 JSON (single or batch, auto evidence-search) |
140
+ | `dg claim-list <session>` | List claims |
141
+ | `dg evidence-search <session> --claim-id <id>` | Search candidate evidence (read-only) |
142
+ | `dg evidence-verify <session> --claim-id <id> --evidence-file <path>` | Confirm UTF-8 JSON evidence + submit stance (+ optional auto-policy) |
143
+ | `dg evidence-list <session> --claim-id <id>` | List evidence for a claim |
144
+ | `dg verdict-list <session> --claim-id <id>` | List verdicts for a claim |
145
+ | `dg policy-aggregate <session>` | Run policy aggregation manually |
146
+ | `dg review-list <session>` | List reviews |
147
+ | `dg --health` | Check the SearXNG backend health (Ollama/DeepSeek have no health endpoint) |
148
+ | `dg --engines-list` | List available search engines (includes `ollama` if configured) |
149
+ | `dg --categories-list` | List available categories |
150
+
151
+ ### Search Options
152
+
153
+ | Option | Description |
154
+ |--------|-------------|
155
+ | `-e, --engines <list>` | Comma-separated list of search engines (e.g., `google,github`); `ollama` and `deepseek` route to those providers instead of SearXNG |
156
+ | `-c, --categories <list>` | Comma-separated list of categories (e.g., `it,science`) |
157
+ | `-l, --limit <n>` | Maximum number of results (default: 10) |
158
+ | `-p, --page <n>` | Page number for pagination |
159
+ | `--lang <code>` | Language code (e.g., `en`, `zh`, `ja`) |
160
+ | `--time <range>` | Time range: `day`, `week`, `month`, `year`, `all` |
161
+ | `-f, --format <fmt>` | Output format: `md` (default) or `json` |
162
+ | `--queries <list>` | Multi-query with RRF fusion (e.g., `q1,q2,q3`) |
163
+ | `--session <session-name>` | Session directory or `new` for deep search |
164
+ | `--owner <session-name>` | Session owner identifier |
165
+ | `--desc <text>` | Session description |
166
+ | `--redundancy <action>` | Query redundancy check: `warn`, `adjust`, `skip` |
167
+ | `--quality` | Assess result quality (requires --session) |
168
+ | `--approve-file <path>` | Approve `{id, revision}` selections from this session's `agent-inputs` directory |
169
+ | `--skip-file <path>` / `--unskip-file <path>` | Skip or restore `{id, revision}` selections from this session's `agent-inputs` directory |
170
+ | `--threshold-override <json>` | Override quality thresholds (JSON) |
171
+ | `--merge <file>` | Merge new results with previous search JSON |
172
+
173
+ ### Examples
174
+
175
+ ```bash
176
+ # Basic search (outputs Markdown by default)
177
+ dg "machine learning"
178
+
179
+ # Output as JSON
180
+ dg --format json "machine learning"
181
+
182
+ # Search with specific engines
183
+ dg --engines google,duckduckgo "privacy tools"
184
+
185
+ # Search IT and Science categories
186
+ dg --categories it,science "kubernetes tutorial"
187
+
188
+ # Limit results and filter by time
189
+ dg --limit 5 --time week "latest AI news"
190
+
191
+ # Multi-query search with RRF fusion
192
+ dg --queries "tokio tutorial,rust async basics,async-std guide"
193
+
194
+ # List available engines (fetched from server)
195
+ dg --engines-list
196
+ ```
197
+
198
+ ## ⚙️ Configuration
199
+
200
+ Configuration priority (highest to lowest):
201
+ 1. Environment variables
202
+ 2. Local config file (`./digdig.config.json`)
203
+ 3. Global config file (`~/digdig/digdig.config.json`)
204
+ 4. Default values
205
+
206
+ ### Environment Variables
207
+
208
+ | Variable | Description | Default |
209
+ |----------|-------------|---------|
210
+ | `DIGDIG_BASE_URL` | SearXNG server URL | *(required)* |
211
+ | `DIGDIG_DEFAULT_ENGINE` | Default search engine | *(none)* |
212
+ | `DIGDIG_ALLOWED_ENGINES` | Comma-separated allowed engines | *(all)* |
213
+ | `DIGDIG_DEFAULT_LIMIT` | Default result limit | `10` |
214
+ | `DIGDIG_DEFAULT_FORMAT` | Default output format (`md` or `json`) | `md` |
215
+ | `DIGDIG_USE_PROXY` | Use proxy (`true`/`false`) | `false` |
216
+ | `DIGDIG_PROXY_URL` | Proxy URL | *(none)* |
217
+ | `DIGDIG_TIMEOUT` | Request timeout in ms | `10000` |
218
+ | `DIGDIG_REDUNDANCY_THRESHOLD` | Word-level Jaccard threshold for redundancy | `0.7` |
219
+ | `DIGDIG_REDUNDANCY_BIGRAM_THRESHOLD` | Bigram-level Jaccard threshold (short queries) | `0.5` |
220
+ | `OLLAMA_API_KEY` | [Ollama web search](https://ollama.com) API key; enable with `-e ollama` (not an automatic fallback) | *(none)* |
221
+ | `DEEPSEEK_API_KEY` | [DeepSeek Search](https://api-docs.deepseek.com/api/search) API key (optional backend; billed per successful request) | *(none)* |
222
+
223
+ > `SEARXNG_*` variable names are still read until `0.5.0` and emit one `[deprecation]` line on stderr; `DIGDIG_*` wins when both are set.
224
+
225
+ ### Config File
226
+
227
+ Create `digdig.config.json`:
228
+
229
+ ```json
230
+ {
231
+ "baseUrl": "http://localhost:8080",
232
+ "defaultEngine": "",
233
+ "allowedEngines": [],
234
+ "defaultLimit": 10,
235
+ "defaultFormat": "md",
236
+ "useProxy": false,
237
+ "proxyUrl": "",
238
+ "timeout": 10000,
239
+ "ollamaApiKey": "",
240
+ "deepseekApiKey": "",
241
+ "redundancyThreshold": 0.7,
242
+ "redundancyBigramThreshold": 0.5
243
+ }
244
+ ```
245
+
246
+ ## 🧠 Deep Search
247
+
248
+ Deep search enables multi-round iterative research with session accumulation, quality assessment, agent-controlled graph injection, and recovery strategies.
249
+
250
+ ### Workflow
251
+
252
+ ```
253
+ Search → Extract → Quality Assess → Approve → Build Graph → (Loop or Explore)
254
+ ↓
255
+ (L2/L3) Claim—Evidence—Review → Final Output
256
+ ```
257
+
258
+ ### Quick Example
259
+
260
+ ```bash
261
+ # 1. Create a session and search
262
+ dg --session new --owner "agent-1" --desc "Rust async study" "rust async ecosystem"
263
+ # Outputs session path, e.g. .digdig/sessions/ds_1712345678_abcdef
264
+
265
+ # 2. Extract content from results
266
+ dg extract --session ds_1712345678_abcdef
267
+
268
+ # 3. Check extraction output: stats.success and session.updated identify
269
+ # results that received source text; failed URLs remain pending.
270
+
271
+ # 4. Assess quality and see each result's verified state
272
+ dg --session ds_1712345678_abcdef --quality
273
+
274
+ # 5. Copy selected {id, revision} objects from quality output into
275
+ # .digdig/sessions/ds_1712345678_abcdef/agent-inputs/approve.json, then approve them.
276
+ dg --session ds_1712345678_abcdef --quality --approve-file .\.digdig\sessions\ds_1712345678_abcdef\agent-inputs\approve.json
277
+
278
+ # 6. Preprocess session content for entity discovery and provenance
279
+ dg graph-preprocess ds_1712345678_abcdef
280
+
281
+ # 7. Put complex graph JSON in this session's Agent scratch directory, then add semantic edges
282
+ dg graph-add ds_1712345678_abcdef --data-file .\.digdig\sessions\ds_1712345678_abcdef\agent-inputs\graph-data.json
283
+
284
+ # 8. Continue research with redundancy check
285
+ dg --session ds_1712345678_abcdef --queries "tokio vs async-std,benchmark 2026" --redundancy warn
286
+ ```
287
+
288
+ ### Quality and Evidence Semantics
289
+
290
+ - Extracted web content is deduplicated by normalized URL, then by full-text character 5-gram Jaccard similarity. Query redundancy uses a separate word-level or character-bigram Jaccard check.
291
+ - `--quality` assesses the newest recorded round against earlier approved results. A URL already seen in an earlier round is non-novel, even when it reappears in the newest round.
292
+ - Quality is a diagnostic, not a fact verifier. A search discovery can be approved only after `extract` writes a non-empty body and extraction timestamp. An explicitly imported external body must provide non-empty `content` and an `extractor`; absent `extractedAt` is recorded as its import time.
293
+ - Claim policy treats two normalized publisher domains as two sources. It does not infer corporate ownership, editorial relationships, or syndication across domains.
294
+
295
+ ### Session Management
296
+
297
+ | Command | Description |
298
+ |---------|-------------|
299
+ | `dg --session new` | Create new auto-named session |
300
+ | `dg --session <session-name>` | Use session by name |
301
+ | `dg session-list` | List all sessions with stats |
302
+ | `dg session-delete <session-name>` | Delete specific session |
303
+ | `dg session-delete --older <hours>` | Delete old sessions |
304
+
305
+ **Session Path Resolution:**
306
+ - Pure name (e.g., `my-session`) → `.digdig/sessions/my-session`
307
+ - Full path (e.g., `/custom/path/session`) → used as-is
308
+ - `new` → auto-generate unique name under `.digdig/sessions/`
309
+
310
+ ### Knowledge Graph
311
+
312
+ Two layers:
313
+
314
+ **Structural** (auto-built):
315
+ | Prefix | Type | Example |
316
+ |--------|------|---------|
317
+ | `q:` | Query node | `q:rust_async` |
318
+ | `r:` | Result node | `r:https://example.com/page` |
319
+ | `d:` | Domain node | `d:github_com` |
320
+
321
+ **Semantic** (via `graph-add`):
322
+ | Prefix | Type | Example |
323
+ |--------|------|---------|
324
+ | `e:` | Entity node | `e:tokio` |
325
+ | `p:` | Path node | `p:chain_001` |
326
+
327
+ Graph navigation commands: `graph-search` (discover entities), `graph-explore` (view relations), `graph-drill` (follow specific relations), `graph-traverse` (traverse reasoning paths).
328
+
329
+ `graph-preprocess` returns `resultProvenance` (`id`, `revision`, `url`, `title`, `approval`) for every extracted body. For each semantic entity or edge, copy one or more currently approved `id` values into `sourceResultIds`. This keeps semantic facts traceable to the exact approved bodies rather than a search round.
330
+
331
+ ### External Search Results
332
+
333
+ Results from other search tools (Tavily, Exa, etc.) can be injected into any active session via `results-add`, following the same pipeline as native dg results:
334
+
335
+ ```powershell
336
+ # Import search discovery; its excerpts remain summaries and require extraction.
337
+ dg results-add <session-name> --kind search --tool exa --query "async runtime" `
338
+ --data-file .\.digdig\sessions\<session-name>\agent-inputs\exa-search.json
339
+ ```
340
+
341
+ Search imports become `pending` and require `extract --session`; inspect `stats.success`, `stats.failed`, and `session.updated`, then approve only entries whose quality output reports `verified: true`. An external tool that already returned a body must instead use `--kind extracted` with non-empty `content` and `extractor`; it becomes pending approval without another extraction. A failed extraction remains pending and cannot enter the graph. `tool` and `query` record the discovery provenance.
342
+
343
+ ### Structured JSON Input
344
+
345
+ All structured writes use a UTF-8 JSON file under `.digdig/sessions/<session-name>/agent-inputs/`. This avoids PowerShell quoting and Windows command-line length limits, keeps concurrent sessions isolated, and gives each command one inspectable input artifact. The CLI rejects inline JSON and files outside the owning session.
346
+
347
+ | Command | Required file option |
348
+ |---|---|
349
+ | External search or extracted bodies | `results-add --data-file <path>` |
350
+ | Graph entities/edges | `graph-add --data-file <path>` |
351
+ | Approval, skip, restore selections | `--approve-file` / `--skip-file` / `--unskip-file <path>` |
352
+ | One/batch Claim | `claim-add --claim-file` / `--claims-file <path>` |
353
+ | Evidence verification | `evidence-verify --evidence-file <path>` |
354
+
355
+ The file must be UTF-8 (a UTF-8 BOM is accepted). Missing, malformed, cross-session, or out-of-directory input fails before state changes. The CLI never deletes Agent input files automatically; `session-delete` removes the entire session only when explicitly requested.
356
+
357
+ ### Claim—Evidence—Review Pipeline (L2/L3 Only)
358
+
359
+ After search, extraction, and graph building, the Agent can run the claim audit pipeline to verify individual statements before final output. CLI does the deterministic work (evidence anchoring, hash verification, Jaccard matching, policy rules); the Agent does all semantic reasoning (claim extraction, stance judgement, final output decisions).
360
+
361
+ **Workflow:**
362
+
363
+ ```
364
+ Agent writes draft → claim-add (auto evidence-search) →
365
+ evidence-verify (with --complete auto-policy) → Review → Agent adjusts output
366
+ ```
367
+
368
+ **Quick Example:**
369
+
370
+ ```powershell
371
+ # 1. Put claims from your draft in the session's UTF-8 Agent input directory, then submit it.
372
+ dg claim-add my-session --claims-file .\.digdig\sessions\my-session\agent-inputs\claims.json
373
+ # → returns claims with IDs + auto-discovered evidence candidates
374
+
375
+ # 2. Put {resultId, quote, charStart, charEnd} in the session's UTF-8 Agent input directory.
376
+ dg evidence-verify my-session --claim-id "cl_001" \
377
+ --evidence-file .\.digdig\sessions\my-session\agent-inputs\evidence.json \
378
+ --stance support --reason "Official docs confirm" --complete
379
+ # → returns evidence + verdict + review (decision: approved / needsReview)
380
+
381
+ # 3. Check final reviews
382
+ dg review-list my-session
383
+ ```
384
+
385
+ **Key Principles:**
386
+ - **Deterministic checks**: CLI validates `resultId` against approved extracted results, UTF-16 offsets within range, and the SHA256 hash of the quoted source span
387
+ - **No embedded LLM**: All semantic work (claim extraction, stance) is done by the Agent outside the CLI
388
+ - **Policy rules**: 7 rules (singleRefute → highRiskInsufficient → dualSourceSupport → dualSourceMixed → singleSource → allInsufficient → fallback) — pure rule engine, no model calls
389
+ - **`--complete` flag**: Evidence + verdict + auto-policy in one call
390
+
391
+ | Commands | Purpose |
392
+ |----------|---------|
393
+ | `claim-add` | Submit claims (auto-triggers evidence search) |
394
+ | `evidence-verify` | Confirm evidence + submit stance + optional auto-policy |
395
+ | `policy-aggregate` | Manual re-aggregation |
396
+ | `claim-list` / `evidence-list` / `verdict-list` / `review-list` | Query pipeline state |
397
+
398
+ The pipeline is **only available for L2/L3 deep search sessions** — L1 simple searches have no session or approved results pool.
399
+
400
+ ### Local Document Search
401
+
402
+ `doc-index` and `doc-search` enable BM25 full-text search over local documents, with results flowing directly into the session pipeline:
403
+
404
+ ```bash
405
+ # Index (auto-triggered by doc-search)
406
+ dg doc-index ./docs
407
+
408
+ # Search and inject into session
409
+ dg doc-search <session-name> "query" --path ./docs
410
+ ```
411
+
412
+ **How it works:** auto-indexing on first use (Orama BM25, title×3 / headings×2 / content×1), each matched chunk is injected as an `extracted` result with `extractor: "local-index"`, then follows `--quality` → `--approve-file` → `graph-add`. Use `graph-preprocess` before adding new entities so approved IDs become `sourceResultIds`. Local searches do **not** increment the round counter.
413
+
414
+ **Quality note:** Pure local search yields `sourceDiversity: 1`. Combine with web results for adequate diversity.
415
+
416
+ ### Known Limitations
417
+
418
+ - Session result and graph mutations use a per-session lock plus atomic replacement; Claim, Evidence, and Review files still have no cross-file transaction.
419
+ - URL extraction is not an SSRF security boundary; use only trusted public URLs.
420
+ - Local document scanning has no defined symbolic-link boundary or cycle policy.
421
+ - Index rebuilds overwrite the current persistence files; an interruption or disk failure can require re-indexing.
422
+
423
+ See the local, not-yet-published PRD-005 design-improvements document for the deferred remediation plan.
424
+
425
+ ## 💡 Projects Using digdig
426
+
427
+ digdig's deep search workflow (session accumulation, quality assessment, knowledge graph, claim–evidence–review) is used by projects that need persistent, multi-round research capabilities:
428
+
429
+ - **[1052 OS](https://github.com/1052666/1052-OS)** — A personal AI operating system. Its `search-pack` integrates persistent research sessions, quality assessment, content extraction, and a claim–evidence–review pipeline, all powered by the same deep search concepts that drive digdig.
430
+
431
+ > Open a PR to add your project here.
432
+
433
+ ## 🔗 Links
434
+
435
+ - **GitHub:** https://github.com/hkwuks/digdig
436
+ - **npm:** https://www.npmjs.com/package/digdig
437
+ - **SearXNG:** https://github.com/searxng/searxng
438
+
439
+ ## 📄 License
440
+
441
+ MIT
@@ -0,0 +1,14 @@
1
+ {
2
+ "baseUrl": "http://localhost:8080",
3
+ "defaultEngine": "",
4
+ "allowedEngines": [],
5
+ "defaultLimit": 10,
6
+ "defaultFormat": "md",
7
+ "useProxy": false,
8
+ "proxyUrl": "",
9
+ "timeout": 10000,
10
+ "ollamaApiKey": "",
11
+ "deepseekApiKey": "",
12
+ "redundancyThreshold": 0.7,
13
+ "redundancyBigramThreshold": 0.5
14
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Deterministic checks — no LLM dependency.
3
+ *
4
+ * - checkAnchor: URL in approved results, offset in range, hash matches
5
+ * - computeSourceClusterId: normalized publisher domain → SHA256 fingerprint
6
+ * - searchCandidates: keyword + Jaccard sentence matching
7
+ */
8
+ import { EvidenceSpan } from './types.js';
9
+ export interface AnchorCheck {
10
+ url: boolean;
11
+ offsetInRange: boolean;
12
+ hashMatches: boolean;
13
+ }
14
+ /**
15
+ * Verify that an EvidenceSpan is properly anchored to approved content.
16
+ */
17
+ export declare function checkAnchor(evidence: EvidenceSpan, content: string): AnchorCheck;
18
+ /**
19
+ * Verify that evidence.resultUrl exists in the session's approved results.
20
+ * Returns the matching Result's content, or null if not found.
21
+ */
22
+ export declare function resolveApprovedContent(sessionDir: string, resultUrl: string): {
23
+ content: string;
24
+ } | null;
25
+ /**
26
+ * Compute a source cluster ID for an EvidenceSpan.
27
+ * Groups evidence by normalized publisher domain for domain-level checks.
28
+ * It does not determine cross-domain corporate or editorial affiliation.
29
+ */
30
+ export declare function computeSourceClusterId(evidence: EvidenceSpan): string;
31
+ /** A candidate evidence match, not persisted until verified by Agent. */
32
+ export interface EvidenceCandidate {
33
+ resultId: string;
34
+ resultUrl: string;
35
+ quote: string;
36
+ charStart: number;
37
+ charEnd: number;
38
+ contentHash: string;
39
+ domain: string;
40
+ author?: string;
41
+ siteName?: string;
42
+ }
43
+ /**
44
+ * Search approved session results for candidate evidence supporting the claim.
45
+ * Uses keyword + Jaccard sentence matching. Read-only — results not persisted.
46
+ */
47
+ export declare function searchCandidates(sessionDir: string, claimText: string): EvidenceCandidate[];
48
+ //# sourceMappingURL=deterministic-checks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deterministic-checks.d.ts","sourceRoot":"","sources":["../../src/claims/deterministic-checks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK1C,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,OAAO,CAAC;IACb,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,MAAM,GACd,WAAW,CAQb;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQ5B;AAID;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,YAAY,GACrB,MAAM,CAQR;AAID,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAyDD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,iBAAiB,EAAE,CA2DrB"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Deterministic checks — no LLM dependency.
3
+ *
4
+ * - checkAnchor: URL in approved results, offset in range, hash matches
5
+ * - computeSourceClusterId: normalized publisher domain → SHA256 fingerprint
6
+ * - searchCandidates: keyword + Jaccard sentence matching
7
+ */
8
+ import { createHash } from 'crypto';
9
+ import { getApprovedResults } from '../deep/session.js';
10
+ /**
11
+ * Verify that an EvidenceSpan is properly anchored to approved content.
12
+ */
13
+ export function checkAnchor(evidence, content) {
14
+ const slice = content.slice(evidence.charStart, evidence.charEnd);
15
+ const computedHash = createHash('sha256').update(slice).digest('hex');
16
+ return {
17
+ url: true, // caller must have resolved url → content already
18
+ offsetInRange: evidence.charEnd <= content.length && evidence.charStart >= 0,
19
+ hashMatches: computedHash === evidence.contentHash,
20
+ };
21
+ }
22
+ /**
23
+ * Verify that evidence.resultUrl exists in the session's approved results.
24
+ * Returns the matching Result's content, or null if not found.
25
+ */
26
+ export function resolveApprovedContent(sessionDir, resultUrl) {
27
+ const approved = getApprovedResults(sessionDir);
28
+ for (const r of approved) {
29
+ if (r.url === resultUrl && r.content) {
30
+ return { content: r.content };
31
+ }
32
+ }
33
+ return null;
34
+ }
35
+ // ── Source clustering ───────────────────────────────────────────────
36
+ /**
37
+ * Compute a source cluster ID for an EvidenceSpan.
38
+ * Groups evidence by normalized publisher domain for domain-level checks.
39
+ * It does not determine cross-domain corporate or editorial affiliation.
40
+ */
41
+ export function computeSourceClusterId(evidence) {
42
+ let publisher = '';
43
+ try {
44
+ publisher = new URL(evidence.resultUrl ?? '').hostname.toLowerCase().replace(/^www\./, '');
45
+ }
46
+ catch { /* empty */ }
47
+ // Unknown publishers share one cluster so they cannot inflate domain diversity.
48
+ return createHash('sha256').update(publisher).digest('hex').slice(0, 16);
49
+ }
50
+ /** Simple stopwords for tokenization */
51
+ const STOPWORDS = new Set([
52
+ 'a', 'an', 'the', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
53
+ 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
54
+ 'should', 'may', 'might', 'shall', 'can', 'need', 'dare', 'ought',
55
+ 'to', 'of', 'in', 'for', 'on', 'with', 'at', 'by', 'from', 'as',
56
+ 'into', 'through', 'during', 'before', 'after', 'above', 'below',
57
+ 'between', 'out', 'off', 'over', 'under', 'again', 'further',
58
+ 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how',
59
+ 'all', 'each', 'every', 'both', 'few', 'more', 'most', 'other',
60
+ 'some', 'such', 'no', 'not', 'only', 'own', 'same', 'so', 'than',
61
+ 'too', 'very', 'just', 'because', 'but', 'and', 'or', 'if', 'while',
62
+ 'although', 'this', 'that', 'these', 'those', 'it', 'its',
63
+ 'the', 'which', 'who', 'whom', 'what',
64
+ ]);
65
+ function tokenize(text) {
66
+ const normalized = text.toLowerCase();
67
+ const tokens = [];
68
+ // CJK text has no reliable whitespace boundaries, so use adjacent-character bigrams.
69
+ for (const match of normalized.matchAll(/[\u3400-\u9fff]+/gu)) {
70
+ const run = match[0];
71
+ if (run.length === 1) {
72
+ tokens.push(run);
73
+ continue;
74
+ }
75
+ for (let index = 0; index < run.length - 1; index++) {
76
+ tokens.push(run.slice(index, index + 2));
77
+ }
78
+ }
79
+ // Keep dotted versions intact so "1.2.4" and "v1.2.4" remain searchable terms.
80
+ for (const match of normalized.matchAll(/[a-z]+(?:[._-][a-z0-9]+)*|\d+(?:[._-]\d+)+|[a-z0-9]+/g)) {
81
+ const token = match[0];
82
+ if (token.length > 1 && !STOPWORDS.has(token))
83
+ tokens.push(token);
84
+ }
85
+ return tokens;
86
+ }
87
+ function jaccardSimilarity(a, b) {
88
+ if (a.size === 0 && b.size === 0)
89
+ return 0;
90
+ let intersection = 0;
91
+ for (const word of a) {
92
+ if (b.has(word))
93
+ intersection++;
94
+ }
95
+ const union = a.size + b.size - intersection;
96
+ return union === 0 ? 0 : intersection / union;
97
+ }
98
+ const JACCARD_THRESHOLD = 0.3;
99
+ const CJK_JACCARD_THRESHOLD = 0.2;
100
+ const MAX_CANDIDATES = 5;
101
+ /**
102
+ * Search approved session results for candidate evidence supporting the claim.
103
+ * Uses keyword + Jaccard sentence matching. Read-only — results not persisted.
104
+ */
105
+ export function searchCandidates(sessionDir, claimText) {
106
+ const keywords = tokenize(claimText);
107
+ if (keywords.length === 0)
108
+ return [];
109
+ const keywordSet = new Set(keywords);
110
+ const threshold = /[\u3400-\u9fff]/u.test(claimText)
111
+ ? CJK_JACCARD_THRESHOLD
112
+ : JACCARD_THRESHOLD;
113
+ const approved = getApprovedResults(sessionDir);
114
+ const candidates = [];
115
+ for (const result of approved) {
116
+ const content = result.content;
117
+ // Split into sentences
118
+ const sentences = content.split(/(?<=[!?。!?])\s*|(?<=\.)\s+|(?<=\n)\s*/);
119
+ for (const sentence of sentences) {
120
+ const trimmed = sentence.trim();
121
+ if (trimmed.length < 10)
122
+ continue;
123
+ const words = tokenize(trimmed);
124
+ if (words.length === 0)
125
+ continue;
126
+ const wordSet = new Set(words);
127
+ const score = jaccardSimilarity(keywordSet, wordSet);
128
+ if (score < threshold)
129
+ continue;
130
+ const charStart = content.indexOf(trimmed);
131
+ if (charStart === -1)
132
+ continue;
133
+ const charEnd = charStart + trimmed.length;
134
+ const contentHash = createHash('sha256')
135
+ .update(trimmed)
136
+ .digest('hex');
137
+ let domain = '';
138
+ try {
139
+ domain = new URL(result.url).hostname;
140
+ }
141
+ catch { /* empty */ }
142
+ candidates.push({
143
+ score,
144
+ candidate: {
145
+ resultId: result.id,
146
+ resultUrl: result.url,
147
+ quote: trimmed,
148
+ charStart,
149
+ charEnd,
150
+ contentHash,
151
+ domain,
152
+ author: result.byline || undefined,
153
+ siteName: result.siteName || undefined,
154
+ },
155
+ });
156
+ }
157
+ }
158
+ // Sort by Jaccard score descending, take top N
159
+ candidates.sort((a, b) => b.score - a.score);
160
+ return candidates.slice(0, MAX_CANDIDATES).map(c => c.candidate);
161
+ }
162
+ //# sourceMappingURL=deterministic-checks.js.map