digdig 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +437 -2
- package/digdig.config.example.json +14 -0
- package/dist/claims/deterministic-checks.d.ts +48 -0
- package/dist/claims/deterministic-checks.d.ts.map +1 -0
- package/dist/claims/deterministic-checks.js +162 -0
- package/dist/claims/deterministic-checks.js.map +1 -0
- package/dist/claims/policy.d.ts +25 -0
- package/dist/claims/policy.d.ts.map +1 -0
- package/dist/claims/policy.js +168 -0
- package/dist/claims/policy.js.map +1 -0
- package/dist/claims/store.d.ts +37 -0
- package/dist/claims/store.d.ts.map +1 -0
- package/dist/claims/store.js +152 -0
- package/dist/claims/store.js.map +1 -0
- package/dist/claims/types.d.ts +98 -0
- package/dist/claims/types.d.ts.map +1 -0
- package/dist/claims/types.js +9 -0
- package/dist/claims/types.js.map +1 -0
- package/dist/commands/claim.d.ts +13 -0
- package/dist/commands/claim.d.ts.map +1 -0
- package/dist/commands/claim.js +131 -0
- package/dist/commands/claim.js.map +1 -0
- package/dist/commands/coverage.d.ts +7 -0
- package/dist/commands/coverage.d.ts.map +1 -0
- package/dist/commands/coverage.js +78 -0
- package/dist/commands/coverage.js.map +1 -0
- package/dist/commands/doc-index.d.ts +12 -0
- package/dist/commands/doc-index.d.ts.map +1 -0
- package/dist/commands/doc-index.js +49 -0
- package/dist/commands/doc-index.js.map +1 -0
- package/dist/commands/doc-search.d.ts +16 -0
- package/dist/commands/doc-search.d.ts.map +1 -0
- package/dist/commands/doc-search.js +41 -0
- package/dist/commands/doc-search.js.map +1 -0
- package/dist/commands/evidence.d.ts +20 -0
- package/dist/commands/evidence.d.ts.map +1 -0
- package/dist/commands/evidence.js +215 -0
- package/dist/commands/evidence.js.map +1 -0
- package/dist/commands/extract.d.ts +10 -0
- package/dist/commands/extract.d.ts.map +1 -0
- package/dist/commands/extract.js +77 -0
- package/dist/commands/extract.js.map +1 -0
- package/dist/commands/graph-add.d.ts +7 -0
- package/dist/commands/graph-add.d.ts.map +1 -0
- package/dist/commands/graph-add.js +93 -0
- package/dist/commands/graph-add.js.map +1 -0
- package/dist/commands/graph-drill.d.ts +11 -0
- package/dist/commands/graph-drill.d.ts.map +1 -0
- package/dist/commands/graph-drill.js +26 -0
- package/dist/commands/graph-drill.js.map +1 -0
- package/dist/commands/graph-explore.d.ts +10 -0
- package/dist/commands/graph-explore.d.ts.map +1 -0
- package/dist/commands/graph-explore.js +32 -0
- package/dist/commands/graph-explore.js.map +1 -0
- package/dist/commands/graph-obfuscate.d.ts +17 -0
- package/dist/commands/graph-obfuscate.d.ts.map +1 -0
- package/dist/commands/graph-obfuscate.js +110 -0
- package/dist/commands/graph-obfuscate.js.map +1 -0
- package/dist/commands/graph-search.d.ts +11 -0
- package/dist/commands/graph-search.d.ts.map +1 -0
- package/dist/commands/graph-search.js +19 -0
- package/dist/commands/graph-search.js.map +1 -0
- package/dist/commands/graph-traverse.d.ts +10 -0
- package/dist/commands/graph-traverse.d.ts.map +1 -0
- package/dist/commands/graph-traverse.js +39 -0
- package/dist/commands/graph-traverse.js.map +1 -0
- package/dist/commands/json-input.d.ts +18 -0
- package/dist/commands/json-input.d.ts.map +1 -0
- package/dist/commands/json-input.js +50 -0
- package/dist/commands/json-input.js.map +1 -0
- package/dist/commands/query-graph.d.ts +13 -0
- package/dist/commands/query-graph.d.ts.map +1 -0
- package/dist/commands/query-graph.js +219 -0
- package/dist/commands/query-graph.js.map +1 -0
- package/dist/commands/results-add.d.ts +10 -0
- package/dist/commands/results-add.d.ts.map +1 -0
- package/dist/commands/results-add.js +80 -0
- package/dist/commands/results-add.js.map +1 -0
- package/dist/commands/review.d.ts +12 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.js +119 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/session.d.ts +28 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +149 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/verdict.d.ts +9 -0
- package/dist/commands/verdict.d.ts.map +1 -0
- package/dist/commands/verdict.js +40 -0
- package/dist/commands/verdict.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +148 -0
- package/dist/config.js.map +1 -0
- package/dist/deep/co-occurrence.d.ts +50 -0
- package/dist/deep/co-occurrence.d.ts.map +1 -0
- package/dist/deep/co-occurrence.js +95 -0
- package/dist/deep/co-occurrence.js.map +1 -0
- package/dist/deep/coverage.d.ts +81 -0
- package/dist/deep/coverage.d.ts.map +1 -0
- package/dist/deep/coverage.js +183 -0
- package/dist/deep/coverage.js.map +1 -0
- package/dist/deep/dedupe.d.ts +27 -0
- package/dist/deep/dedupe.d.ts.map +1 -0
- package/dist/deep/dedupe.js +115 -0
- package/dist/deep/dedupe.js.map +1 -0
- package/dist/deep/degree-utils.d.ts +39 -0
- package/dist/deep/degree-utils.d.ts.map +1 -0
- package/dist/deep/degree-utils.js +42 -0
- package/dist/deep/degree-utils.js.map +1 -0
- package/dist/deep/extractor.d.ts +42 -0
- package/dist/deep/extractor.d.ts.map +1 -0
- package/dist/deep/extractor.js +392 -0
- package/dist/deep/extractor.js.map +1 -0
- package/dist/deep/fuse.d.ts +63 -0
- package/dist/deep/fuse.d.ts.map +1 -0
- package/dist/deep/fuse.js +108 -0
- package/dist/deep/fuse.js.map +1 -0
- package/dist/deep/graph-explore.d.ts +115 -0
- package/dist/deep/graph-explore.d.ts.map +1 -0
- package/dist/deep/graph-explore.js +588 -0
- package/dist/deep/graph-explore.js.map +1 -0
- package/dist/deep/graph-obfuscate.d.ts +51 -0
- package/dist/deep/graph-obfuscate.d.ts.map +1 -0
- package/dist/deep/graph-obfuscate.js +226 -0
- package/dist/deep/graph-obfuscate.js.map +1 -0
- package/dist/deep/graph-preprocess.d.ts +48 -0
- package/dist/deep/graph-preprocess.d.ts.map +1 -0
- package/dist/deep/graph-preprocess.js +40 -0
- package/dist/deep/graph-preprocess.js.map +1 -0
- package/dist/deep/graph-sampling.d.ts +51 -0
- package/dist/deep/graph-sampling.d.ts.map +1 -0
- package/dist/deep/graph-sampling.js +410 -0
- package/dist/deep/graph-sampling.js.map +1 -0
- package/dist/deep/graph.d.ts +87 -0
- package/dist/deep/graph.d.ts.map +1 -0
- package/dist/deep/graph.js +200 -0
- package/dist/deep/graph.js.map +1 -0
- package/dist/deep/index.d.ts +10 -0
- package/dist/deep/index.d.ts.map +1 -0
- package/dist/deep/index.js +10 -0
- package/dist/deep/index.js.map +1 -0
- package/dist/deep/iteration-data.d.ts +34 -0
- package/dist/deep/iteration-data.d.ts.map +1 -0
- package/dist/deep/iteration-data.js +45 -0
- package/dist/deep/iteration-data.js.map +1 -0
- package/dist/deep/local-doc/indexer.d.ts +26 -0
- package/dist/deep/local-doc/indexer.d.ts.map +1 -0
- package/dist/deep/local-doc/indexer.js +420 -0
- package/dist/deep/local-doc/indexer.js.map +1 -0
- package/dist/deep/local-doc/scanner.d.ts +10 -0
- package/dist/deep/local-doc/scanner.d.ts.map +1 -0
- package/dist/deep/local-doc/scanner.js +165 -0
- package/dist/deep/local-doc/scanner.js.map +1 -0
- package/dist/deep/local-doc/searcher.d.ts +38 -0
- package/dist/deep/local-doc/searcher.d.ts.map +1 -0
- package/dist/deep/local-doc/searcher.js +211 -0
- package/dist/deep/local-doc/searcher.js.map +1 -0
- package/dist/deep/local-doc/types.d.ts +61 -0
- package/dist/deep/local-doc/types.d.ts.map +1 -0
- package/dist/deep/local-doc/types.js +18 -0
- package/dist/deep/local-doc/types.js.map +1 -0
- package/dist/deep/path-extraction.d.ts +53 -0
- package/dist/deep/path-extraction.d.ts.map +1 -0
- package/dist/deep/path-extraction.js +229 -0
- package/dist/deep/path-extraction.js.map +1 -0
- package/dist/deep/pending-facts.d.ts +64 -0
- package/dist/deep/pending-facts.d.ts.map +1 -0
- package/dist/deep/pending-facts.js +74 -0
- package/dist/deep/pending-facts.js.map +1 -0
- package/dist/deep/query-redundancy.d.ts +52 -0
- package/dist/deep/query-redundancy.d.ts.map +1 -0
- package/dist/deep/query-redundancy.js +122 -0
- package/dist/deep/query-redundancy.js.map +1 -0
- package/dist/deep/query-suggest.d.ts +33 -0
- package/dist/deep/query-suggest.d.ts.map +1 -0
- package/dist/deep/query-suggest.js +90 -0
- package/dist/deep/query-suggest.js.map +1 -0
- package/dist/deep/rrf.d.ts +13 -0
- package/dist/deep/rrf.d.ts.map +1 -0
- package/dist/deep/rrf.js +23 -0
- package/dist/deep/rrf.js.map +1 -0
- package/dist/deep/search-strategy.d.ts +37 -0
- package/dist/deep/search-strategy.d.ts.map +1 -0
- package/dist/deep/search-strategy.js +106 -0
- package/dist/deep/search-strategy.js.map +1 -0
- package/dist/deep/session.d.ts +182 -0
- package/dist/deep/session.d.ts.map +1 -0
- package/dist/deep/session.js +663 -0
- package/dist/deep/session.js.map +1 -0
- package/dist/deep/simhash.d.ts +17 -0
- package/dist/deep/simhash.d.ts.map +1 -0
- package/dist/deep/simhash.js +72 -0
- package/dist/deep/simhash.js.map +1 -0
- package/dist/deep/tfidf.d.ts +38 -0
- package/dist/deep/tfidf.d.ts.map +1 -0
- package/dist/deep/tfidf.js +103 -0
- package/dist/deep/tfidf.js.map +1 -0
- package/dist/deepseek-service.d.ts +22 -0
- package/dist/deepseek-service.d.ts.map +1 -0
- package/dist/deepseek-service.js +84 -0
- package/dist/deepseek-service.js.map +1 -0
- package/dist/entry.d.ts +14 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +29 -0
- package/dist/entry.js.map +1 -0
- package/dist/errors.d.ts +76 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +117 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +16 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +143 -0
- package/dist/init.js.map +1 -0
- package/dist/legacy.d.ts +60 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/legacy.js +119 -0
- package/dist/legacy.js.map +1 -0
- package/dist/ollama-service.d.ts +22 -0
- package/dist/ollama-service.d.ts.map +1 -0
- package/dist/ollama-service.js +71 -0
- package/dist/ollama-service.js.map +1 -0
- package/dist/protocol.d.ts +23 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +26 -0
- package/dist/protocol.js.map +1 -0
- package/dist/runCli.d.ts +8 -0
- package/dist/runCli.d.ts.map +1 -0
- package/dist/runCli.js +1356 -0
- package/dist/runCli.js.map +1 -0
- package/dist/service.d.ts +73 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +145 -0
- package/dist/service.js.map +1 -0
- package/dist/sxng.d.ts +11 -0
- package/dist/sxng.d.ts.map +1 -0
- package/dist/sxng.js +14 -0
- package/dist/sxng.js.map +1 -0
- package/package.json +56 -12
package/README.md
CHANGED
|
@@ -1,4 +1,439 @@
|
|
|
1
|
-
# digdig
|
|
1
|
+
# 🔍 digdig
|
|
2
2
|
|
|
3
|
-
|
|
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 and counted coverage facts
|
|
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
|
+
- ⭐ **Counted Facts, Not Verdicts** — `--quality` reports result counts, extraction state, sources, and per-result facts; the judgement stays with the Agent
|
|
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 (facts, suggestions, strategy) 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` | List pending results with what the session has gathered, as counted facts |
|
|
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 session-report <session>` | Full session analysis report |
|
|
126
|
+
| `dg session-list` | List all sessions |
|
|
127
|
+
| `dg session-delete <name>` | Delete a session |
|
|
128
|
+
| `dg graph-preprocess <session>` | TF-IDF + co-occurrence + result provenance analysis |
|
|
129
|
+
| `dg graph-add <session> --data-file <path>` | Add semantic entities/edges backed by approved result IDs |
|
|
130
|
+
| `dg graph-search <session>` | Discover entities by keyword |
|
|
131
|
+
| `dg graph-explore <session>` | View entity relations |
|
|
132
|
+
| `dg graph-drill <session>` | Follow specific relations |
|
|
133
|
+
| `dg graph-traverse <session>` | Traverse reasoning paths |
|
|
134
|
+
| `dg graph-obfuscate <session>` | List obfuscation candidates |
|
|
135
|
+
| `dg results-add <session> --kind <search|extracted> --data-file <path>` | Import external discovery or extracted bodies from session-scoped UTF-8 JSON |
|
|
136
|
+
| `dg doc-index <path>` | Index local documents for BM25 search |
|
|
137
|
+
| `dg doc-search <session> <query> --path <path>` | Search indexed docs and inject results into session |
|
|
138
|
+
| `dg claim-add <session> --claims-file <path>` | Submit atomic claims from UTF-8 JSON (single or batch, auto evidence-search) |
|
|
139
|
+
| `dg claim-list <session>` | List claims |
|
|
140
|
+
| `dg evidence-search <session> --claim-id <id>` | Search candidate evidence (read-only) |
|
|
141
|
+
| `dg evidence-verify <session> --claim-id <id> --evidence-file <path>` | Confirm UTF-8 JSON evidence + submit stance (+ optional auto-policy) |
|
|
142
|
+
| `dg evidence-list <session> --claim-id <id>` | List evidence for a claim |
|
|
143
|
+
| `dg verdict-list <session> --claim-id <id>` | List verdicts for a claim |
|
|
144
|
+
| `dg policy-aggregate <session>` | Run policy aggregation manually |
|
|
145
|
+
| `dg review-list <session>` | List reviews |
|
|
146
|
+
| `dg --health` | Check the SearXNG backend health (Ollama/DeepSeek have no health endpoint) |
|
|
147
|
+
| `dg --engines-list` | List available search engines (includes `ollama` if configured) |
|
|
148
|
+
| `dg --categories-list` | List available categories |
|
|
149
|
+
|
|
150
|
+
### Search Options
|
|
151
|
+
|
|
152
|
+
| Option | Description |
|
|
153
|
+
|--------|-------------|
|
|
154
|
+
| `-e, --engines <list>` | Comma-separated list of search engines (e.g., `google,github`); `ollama` and `deepseek` route to those providers instead of SearXNG |
|
|
155
|
+
| `-c, --categories <list>` | Comma-separated list of categories (e.g., `it,science`) |
|
|
156
|
+
| `-l, --limit <n>` | Maximum number of results (default: 10) |
|
|
157
|
+
| `-p, --page <n>` | Page number for pagination |
|
|
158
|
+
| `--lang <code>` | Language code (e.g., `en`, `zh`, `ja`) |
|
|
159
|
+
| `--time <range>` | Time range: `day`, `week`, `month`, `year`, `all` |
|
|
160
|
+
| `-f, --format <fmt>` | Output format: `md` (default) or `json` |
|
|
161
|
+
| `--queries <list>` | Multi-query with RRF fusion (e.g., `q1,q2,q3`) |
|
|
162
|
+
| `--session <session-name>` | Session directory or `new` for deep search |
|
|
163
|
+
| `--owner <session-name>` | Session owner identifier |
|
|
164
|
+
| `--desc <text>` | Session description |
|
|
165
|
+
| `--redundancy <action>` | Query redundancy check: `warn`, `adjust`, `skip` |
|
|
166
|
+
| `--quality` | List pending results and counted session facts (requires --session) |
|
|
167
|
+
| `--approve-file <path>` | Approve `{id, revision}` selections from this session's `agent-inputs` directory |
|
|
168
|
+
| `--skip-file <path>` / `--unskip-file <path>` | Skip or restore `{id, revision}` selections from this session's `agent-inputs` directory |
|
|
169
|
+
| `--merge <file>` | Merge new results with previous search JSON |
|
|
170
|
+
|
|
171
|
+
### Examples
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# Basic search (outputs Markdown by default)
|
|
175
|
+
dg "machine learning"
|
|
176
|
+
|
|
177
|
+
# Output as JSON
|
|
178
|
+
dg --format json "machine learning"
|
|
179
|
+
|
|
180
|
+
# Search with specific engines
|
|
181
|
+
dg --engines google,duckduckgo "privacy tools"
|
|
182
|
+
|
|
183
|
+
# Search IT and Science categories
|
|
184
|
+
dg --categories it,science "kubernetes tutorial"
|
|
185
|
+
|
|
186
|
+
# Limit results and filter by time
|
|
187
|
+
dg --limit 5 --time week "latest AI news"
|
|
188
|
+
|
|
189
|
+
# Multi-query search with RRF fusion
|
|
190
|
+
dg --queries "tokio tutorial,rust async basics,async-std guide"
|
|
191
|
+
|
|
192
|
+
# List available engines (fetched from server)
|
|
193
|
+
dg --engines-list
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## ⚙️ Configuration
|
|
197
|
+
|
|
198
|
+
Configuration priority (highest to lowest):
|
|
199
|
+
1. Environment variables
|
|
200
|
+
2. Local config file (`./digdig.config.json`)
|
|
201
|
+
3. Global config file (`~/digdig/digdig.config.json`)
|
|
202
|
+
4. Default values
|
|
203
|
+
|
|
204
|
+
### Environment Variables
|
|
205
|
+
|
|
206
|
+
| Variable | Description | Default |
|
|
207
|
+
|----------|-------------|---------|
|
|
208
|
+
| `DIGDIG_BASE_URL` | SearXNG server URL | *(required)* |
|
|
209
|
+
| `DIGDIG_DEFAULT_ENGINE` | Default search engine | *(none)* |
|
|
210
|
+
| `DIGDIG_ALLOWED_ENGINES` | Comma-separated allowed engines | *(all)* |
|
|
211
|
+
| `DIGDIG_DEFAULT_LIMIT` | Default result limit | `10` |
|
|
212
|
+
| `DIGDIG_DEFAULT_FORMAT` | Default output format (`md` or `json`) | `md` |
|
|
213
|
+
| `DIGDIG_USE_PROXY` | Use proxy (`true`/`false`) | `false` |
|
|
214
|
+
| `DIGDIG_PROXY_URL` | Proxy URL | *(none)* |
|
|
215
|
+
| `DIGDIG_TIMEOUT` | Request timeout in ms | `10000` |
|
|
216
|
+
| `DIGDIG_REDUNDANCY_THRESHOLD` | Word-level Jaccard threshold for redundancy | `0.7` |
|
|
217
|
+
| `DIGDIG_REDUNDANCY_BIGRAM_THRESHOLD` | Bigram-level Jaccard threshold (short queries) | `0.5` |
|
|
218
|
+
| `OLLAMA_API_KEY` | [Ollama web search](https://ollama.com) API key; enable with `-e ollama` (not an automatic fallback) | *(none)* |
|
|
219
|
+
| `DEEPSEEK_API_KEY` | [DeepSeek Search](https://api-docs.deepseek.com/api/search) API key (optional backend; billed per successful request) | *(none)* |
|
|
220
|
+
|
|
221
|
+
> `SEARXNG_*` variable names are still read until `0.5.0` and emit one `[deprecation]` line on stderr; `DIGDIG_*` wins when both are set.
|
|
222
|
+
|
|
223
|
+
### Config File
|
|
224
|
+
|
|
225
|
+
Create `digdig.config.json`:
|
|
226
|
+
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"baseUrl": "http://localhost:8080",
|
|
230
|
+
"defaultEngine": "",
|
|
231
|
+
"allowedEngines": [],
|
|
232
|
+
"defaultLimit": 10,
|
|
233
|
+
"defaultFormat": "md",
|
|
234
|
+
"useProxy": false,
|
|
235
|
+
"proxyUrl": "",
|
|
236
|
+
"timeout": 10000,
|
|
237
|
+
"ollamaApiKey": "",
|
|
238
|
+
"deepseekApiKey": "",
|
|
239
|
+
"redundancyThreshold": 0.7,
|
|
240
|
+
"redundancyBigramThreshold": 0.5
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## 🧠 Deep Search
|
|
245
|
+
|
|
246
|
+
Deep search enables multi-round iterative research with session accumulation, counted coverage facts, agent-controlled graph injection, and a Query Plan that records what is still missing.
|
|
247
|
+
|
|
248
|
+
### Workflow
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
Search → Extract → Quality Assess → Approve → Build Graph → (Loop or Explore)
|
|
252
|
+
↓
|
|
253
|
+
(L2/L3) Claim—Evidence—Review → Final Output
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Quick Example
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
# 1. Create a session and search
|
|
260
|
+
dg --session new --owner "agent-1" --desc "Rust async study" "rust async ecosystem"
|
|
261
|
+
# Outputs session path, e.g. .digdig/sessions/ds_1712345678_abcdef
|
|
262
|
+
|
|
263
|
+
# 2. Extract content from results
|
|
264
|
+
dg extract --session ds_1712345678_abcdef
|
|
265
|
+
|
|
266
|
+
# 3. Check extraction output: stats.success and session.updated identify
|
|
267
|
+
# results that received source text; failed URLs remain pending.
|
|
268
|
+
|
|
269
|
+
# 4. Review the pending facts and each result's verified state
|
|
270
|
+
dg --session ds_1712345678_abcdef --quality
|
|
271
|
+
|
|
272
|
+
# 5. Copy selected {id, revision} objects from the --quality output into
|
|
273
|
+
# .digdig/sessions/ds_1712345678_abcdef/agent-inputs/approve.json, then approve them.
|
|
274
|
+
dg --session ds_1712345678_abcdef --quality --approve-file .\.digdig\sessions\ds_1712345678_abcdef\agent-inputs\approve.json
|
|
275
|
+
|
|
276
|
+
# 6. Preprocess session content for entity discovery and provenance
|
|
277
|
+
dg graph-preprocess ds_1712345678_abcdef
|
|
278
|
+
|
|
279
|
+
# 7. Put complex graph JSON in this session's Agent scratch directory, then add semantic edges
|
|
280
|
+
dg graph-add ds_1712345678_abcdef --data-file .\.digdig\sessions\ds_1712345678_abcdef\agent-inputs\graph-data.json
|
|
281
|
+
|
|
282
|
+
# 8. Continue research with redundancy check
|
|
283
|
+
dg --session ds_1712345678_abcdef --queries "tokio vs async-std,benchmark 2026" --redundancy warn
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Quality and Evidence Semantics
|
|
287
|
+
|
|
288
|
+
- 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.
|
|
289
|
+
- `--quality` reports counted facts: how many results the session holds, how many carry an extracted body, how many distinct sources, and each pending result's id, revision, source, body length, extraction and verification state, and the round that first saw it. It does not score them.
|
|
290
|
+
- 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.
|
|
291
|
+
- Claim policy treats two normalized publisher domains as two sources. It does not infer corporate ownership, editorial relationships, or syndication across domains.
|
|
292
|
+
|
|
293
|
+
### Session Management
|
|
294
|
+
|
|
295
|
+
| Command | Description |
|
|
296
|
+
|---------|-------------|
|
|
297
|
+
| `dg --session new` | Create new auto-named session |
|
|
298
|
+
| `dg --session <session-name>` | Use session by name |
|
|
299
|
+
| `dg session-list` | List all sessions with stats |
|
|
300
|
+
| `dg session-delete <session-name>` | Delete specific session |
|
|
301
|
+
| `dg session-delete --older <hours>` | Delete old sessions |
|
|
302
|
+
|
|
303
|
+
**Session Path Resolution:**
|
|
304
|
+
- Pure name (e.g., `my-session`) → `.digdig/sessions/my-session`
|
|
305
|
+
- Full path (e.g., `/custom/path/session`) → used as-is
|
|
306
|
+
- `new` → auto-generate unique name under `.digdig/sessions/`
|
|
307
|
+
|
|
308
|
+
### Knowledge Graph
|
|
309
|
+
|
|
310
|
+
Two layers:
|
|
311
|
+
|
|
312
|
+
**Structural** (auto-built):
|
|
313
|
+
| Prefix | Type | Example |
|
|
314
|
+
|--------|------|---------|
|
|
315
|
+
| `q:` | Query node | `q:rust_async` |
|
|
316
|
+
| `r:` | Result node | `r:https://example.com/page` |
|
|
317
|
+
| `d:` | Domain node | `d:github_com` |
|
|
318
|
+
|
|
319
|
+
**Semantic** (via `graph-add`):
|
|
320
|
+
| Prefix | Type | Example |
|
|
321
|
+
|--------|------|---------|
|
|
322
|
+
| `e:` | Entity node | `e:tokio` |
|
|
323
|
+
| `p:` | Path node | `p:chain_001` |
|
|
324
|
+
|
|
325
|
+
Graph navigation commands: `graph-search` (discover entities), `graph-explore` (view relations), `graph-drill` (follow specific relations), `graph-traverse` (traverse reasoning paths).
|
|
326
|
+
|
|
327
|
+
`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.
|
|
328
|
+
|
|
329
|
+
### External Search Results
|
|
330
|
+
|
|
331
|
+
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:
|
|
332
|
+
|
|
333
|
+
```powershell
|
|
334
|
+
# Import search discovery; its excerpts remain summaries and require extraction.
|
|
335
|
+
dg results-add <session-name> --kind search --tool exa --query "async runtime" `
|
|
336
|
+
--data-file .\.digdig\sessions\<session-name>\agent-inputs\exa-search.json
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
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.
|
|
340
|
+
|
|
341
|
+
### Structured JSON Input
|
|
342
|
+
|
|
343
|
+
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.
|
|
344
|
+
|
|
345
|
+
| Command | Required file option |
|
|
346
|
+
|---|---|
|
|
347
|
+
| External search or extracted bodies | `results-add --data-file <path>` |
|
|
348
|
+
| Graph entities/edges | `graph-add --data-file <path>` |
|
|
349
|
+
| Approval, skip, restore selections | `--approve-file` / `--skip-file` / `--unskip-file <path>` |
|
|
350
|
+
| One/batch Claim | `claim-add --claim-file` / `--claims-file <path>` |
|
|
351
|
+
| Evidence verification | `evidence-verify --evidence-file <path>` |
|
|
352
|
+
|
|
353
|
+
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.
|
|
354
|
+
|
|
355
|
+
### Claim—Evidence—Review Pipeline (L2/L3 Only)
|
|
356
|
+
|
|
357
|
+
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).
|
|
358
|
+
|
|
359
|
+
**Workflow:**
|
|
360
|
+
|
|
361
|
+
```
|
|
362
|
+
Agent writes draft → claim-add (auto evidence-search) →
|
|
363
|
+
evidence-verify (with --complete auto-policy) → Review → Agent adjusts output
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
**Quick Example:**
|
|
367
|
+
|
|
368
|
+
```powershell
|
|
369
|
+
# 1. Put claims from your draft in the session's UTF-8 Agent input directory, then submit it.
|
|
370
|
+
dg claim-add my-session --claims-file .\.digdig\sessions\my-session\agent-inputs\claims.json
|
|
371
|
+
# → returns claims with IDs + auto-discovered evidence candidates
|
|
372
|
+
|
|
373
|
+
# 2. Put {resultId, quote, charStart, charEnd} in the session's UTF-8 Agent input directory.
|
|
374
|
+
dg evidence-verify my-session --claim-id "cl_001" \
|
|
375
|
+
--evidence-file .\.digdig\sessions\my-session\agent-inputs\evidence.json \
|
|
376
|
+
--stance support --reason "Official docs confirm" --complete
|
|
377
|
+
# → returns evidence + verdict + review (decision: approved / needsReview)
|
|
378
|
+
|
|
379
|
+
# 3. Check final reviews
|
|
380
|
+
dg review-list my-session
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
**Key Principles:**
|
|
384
|
+
- **Deterministic checks**: CLI validates `resultId` against approved extracted results, UTF-16 offsets within range, and the SHA256 hash of the quoted source span
|
|
385
|
+
- **No embedded LLM**: All semantic work (claim extraction, stance) is done by the Agent outside the CLI
|
|
386
|
+
- **Policy rules**: 7 rules (singleRefute → highRiskInsufficient → dualSourceSupport → dualSourceMixed → singleSource → allInsufficient → fallback) — pure rule engine, no model calls
|
|
387
|
+
- **`--complete` flag**: Evidence + verdict + auto-policy in one call
|
|
388
|
+
|
|
389
|
+
| Commands | Purpose |
|
|
390
|
+
|----------|---------|
|
|
391
|
+
| `claim-add` | Submit claims (auto-triggers evidence search) |
|
|
392
|
+
| `evidence-verify` | Confirm evidence + submit stance + optional auto-policy |
|
|
393
|
+
| `policy-aggregate` | Manual re-aggregation |
|
|
394
|
+
| `claim-list` / `evidence-list` / `verdict-list` / `review-list` | Query pipeline state |
|
|
395
|
+
|
|
396
|
+
The pipeline is **only available for L2/L3 deep search sessions** — L1 simple searches have no session or approved results pool.
|
|
397
|
+
|
|
398
|
+
### Local Document Search
|
|
399
|
+
|
|
400
|
+
`doc-index` and `doc-search` enable BM25 full-text search over local documents, with results flowing directly into the session pipeline:
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
# Index (auto-triggered by doc-search)
|
|
404
|
+
dg doc-index ./docs
|
|
405
|
+
|
|
406
|
+
# Search and inject into session
|
|
407
|
+
dg doc-search <session-name> "query" --path ./docs
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
**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.
|
|
411
|
+
|
|
412
|
+
**Quality note:** Pure local search yields `sourceDiversity: 1`. Combine with web results for adequate diversity.
|
|
413
|
+
|
|
414
|
+
### Known Limitations
|
|
415
|
+
|
|
416
|
+
- Session result and graph mutations use a per-session lock plus atomic replacement; Claim, Evidence, and Review files still have no cross-file transaction.
|
|
417
|
+
- URL extraction is not an SSRF security boundary; use only trusted public URLs.
|
|
418
|
+
- Local document scanning has no defined symbolic-link boundary or cycle policy.
|
|
419
|
+
- Index rebuilds overwrite the current persistence files; an interruption or disk failure can require re-indexing.
|
|
420
|
+
|
|
421
|
+
See the local, not-yet-published PRD-005 design-improvements document for the deferred remediation plan.
|
|
422
|
+
|
|
423
|
+
## 💡 Projects Using digdig
|
|
424
|
+
|
|
425
|
+
digdig's deep search workflow (session accumulation, counted coverage facts, knowledge graph, claim–evidence–review) is used by projects that need persistent, multi-round research capabilities:
|
|
426
|
+
|
|
427
|
+
- **[1052 OS](https://github.com/1052666/1052-OS)** — A personal AI operating system. Its `search-pack` integrates persistent research sessions, counted coverage facts, content extraction, and a claim–evidence–review pipeline, all powered by the same deep search concepts that drive digdig.
|
|
428
|
+
|
|
429
|
+
> Open a PR to add your project here.
|
|
430
|
+
|
|
431
|
+
## 🔗 Links
|
|
432
|
+
|
|
433
|
+
- **GitHub:** https://github.com/hkwuks/digdig
|
|
434
|
+
- **npm:** https://www.npmjs.com/package/digdig
|
|
435
|
+
- **SearXNG:** https://github.com/searxng/searxng
|
|
436
|
+
|
|
437
|
+
## 📄 License
|
|
438
|
+
|
|
439
|
+
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
|