sxng-cli 1.1.9 β 1.2.1
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 +72 -33
- package/dist/commands/extract.d.ts +0 -1
- package/dist/commands/extract.d.ts.map +1 -1
- package/dist/commands/extract.js +30 -26
- package/dist/commands/extract.js.map +1 -1
- package/dist/commands/graph-add.d.ts +8 -4
- package/dist/commands/graph-add.d.ts.map +1 -1
- package/dist/commands/graph-add.js +16 -38
- package/dist/commands/graph-add.js.map +1 -1
- package/dist/commands/results-add.d.ts +13 -0
- package/dist/commands/results-add.d.ts.map +1 -0
- package/dist/commands/results-add.js +39 -0
- package/dist/commands/results-add.js.map +1 -0
- package/dist/deep/iteration-data.d.ts.map +1 -1
- package/dist/deep/iteration-data.js +1 -1
- package/dist/deep/iteration-data.js.map +1 -1
- package/dist/deep/quality-assess.d.ts +16 -17
- package/dist/deep/quality-assess.d.ts.map +1 -1
- package/dist/deep/quality-assess.js +24 -37
- package/dist/deep/quality-assess.js.map +1 -1
- package/dist/deep/recovery-analysis.d.ts +1 -2
- package/dist/deep/recovery-analysis.d.ts.map +1 -1
- package/dist/deep/recovery-analysis.js +6 -9
- package/dist/deep/recovery-analysis.js.map +1 -1
- package/dist/deep/session.d.ts +25 -2
- package/dist/deep/session.d.ts.map +1 -1
- package/dist/deep/session.js +89 -7
- package/dist/deep/session.js.map +1 -1
- package/dist/runCli.d.ts.map +1 -1
- package/dist/runCli.js +110 -76
- package/dist/runCli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,15 +26,14 @@
|
|
|
26
26
|
|
|
27
27
|
- π **Multi-Engine Search** β Search across Google, Bing, DuckDuckGo, GitHub, StackOverflow, and 30+ engines simultaneously
|
|
28
28
|
- π **Dynamic Discovery** β Auto-fetches available engines and categories from your SearXNG server
|
|
29
|
-
- π **Multiple Formats** β Markdown (LLM-optimized)
|
|
30
|
-
- π§ **Deep Search** β Multi-round iterative research with session accumulation and
|
|
31
|
-
- π **Content Extraction** β Extract full article content from
|
|
32
|
-
- ποΈ **Session Management** β Accumulate search results across
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
- π **Proxy Support** β HTTP/HTTPS proxy configuration
|
|
29
|
+
- π **Multiple Formats** β Markdown (LLM-optimized) or JSON output
|
|
30
|
+
- π§ **Deep Search** β Multi-round iterative research with session accumulation, quality assessment, and recovery strategies
|
|
31
|
+
- π **Content Extraction** β Extract full article content from URLs or session results, with Obscura (JS rendering) and Jina Reader fallbacks
|
|
32
|
+
- ποΈ **Session Management** β Accumulate search results across rounds with deduplication; pending β approve β graph injection workflow
|
|
33
|
+
- β **Quality Assessment** β 4 independent indicators: content depth, entity richness, source diversity, novelty
|
|
34
|
+
- πΈοΈ **Knowledge Graph** β Structural (queryβresultβdomain) + semantic (entity relations) graph layers
|
|
35
|
+
- π **Query Redundancy Check** β Jaccard similarity + SimHash to avoid repeated queries
|
|
36
|
+
- π‘ **Agent-First Design** β Outputs structured analysis data (quality, suggestions, recovery) for LLM Agent decision-making
|
|
38
37
|
|
|
39
38
|
## π¦ Installation
|
|
40
39
|
|
|
@@ -106,15 +105,28 @@ obscura --version
|
|
|
106
105
|
| `sxng <query>` | Perform a web search |
|
|
107
106
|
| `sxng --queries "q1,q2"` | Multi-query search with RRF fusion |
|
|
108
107
|
| `sxng extract --urls <urls>` | Extract content from web pages |
|
|
109
|
-
| `sxng extract --
|
|
108
|
+
| `sxng extract --session <name>` | Extract session results and merge content |
|
|
109
|
+
| `sxng extract --obscura` | JS-rendering fallback for SPA pages |
|
|
110
|
+
| `sxng extract --jina` | Jina Reader fallback for complex pages |
|
|
110
111
|
| `sxng --session new` | Create deep search session |
|
|
112
|
+
| `sxng --session <name> --quality` | Assess result quality, list pending results |
|
|
113
|
+
| `sxng --session <name> --quality --approve "0,1"` | Approve pending results by index |
|
|
114
|
+
| `sxng suggest-queries <session>` | Get query suggestion data for Agent |
|
|
115
|
+
| `sxng strategy-info <session>` | Check current search stage |
|
|
116
|
+
| `sxng recovery-analysis <session>` | Get recovery strategies for poor quality |
|
|
117
|
+
| `sxng session-report <session>` | Full session analysis report |
|
|
111
118
|
| `sxng session-list` | List all sessions |
|
|
112
|
-
| `sxng session-delete <
|
|
113
|
-
| `sxng graph-
|
|
114
|
-
| `sxng
|
|
119
|
+
| `sxng session-delete <name>` | Delete a session |
|
|
120
|
+
| `sxng graph-preprocess <session>` | TF-IDF + co-occurrence analysis |
|
|
121
|
+
| `sxng graph-add <session>` | Add entities/edges to knowledge graph |
|
|
122
|
+
| `sxng graph-search <session>` | Discover entities by keyword |
|
|
123
|
+
| `sxng graph-explore <session>` | View entity relations |
|
|
124
|
+
| `sxng graph-drill <session>` | Follow specific relations |
|
|
125
|
+
| `sxng graph-traverse <session>` | Traverse reasoning paths |
|
|
126
|
+
| `sxng graph-obfuscate <session>` | List obfuscation candidates |
|
|
115
127
|
| `sxng --health` | Check SearXNG server health |
|
|
116
|
-
| `sxng --engines-list` | List available search engines
|
|
117
|
-
| `sxng --categories-list` | List available categories
|
|
128
|
+
| `sxng --engines-list` | List available search engines |
|
|
129
|
+
| `sxng --categories-list` | List available categories |
|
|
118
130
|
|
|
119
131
|
### Search Options
|
|
120
132
|
|
|
@@ -126,11 +138,16 @@ obscura --version
|
|
|
126
138
|
| `-p, --page <n>` | Page number for pagination |
|
|
127
139
|
| `--lang <code>` | Language code (e.g., `en`, `zh`, `ja`) |
|
|
128
140
|
| `--time <range>` | Time range: `day`, `week`, `month`, `year`, `all` |
|
|
129
|
-
| `-f, --format <fmt>` | Output format: `md
|
|
141
|
+
| `-f, --format <fmt>` | Output format: `md` (default) or `json` |
|
|
130
142
|
| `--queries <list>` | Multi-query with RRF fusion (e.g., `q1,q2,q3`) |
|
|
131
143
|
| `--session <session-name>` | Session directory or `new` for deep search |
|
|
132
144
|
| `--owner <session-name>` | Session owner identifier |
|
|
133
145
|
| `--desc <text>` | Session description |
|
|
146
|
+
| `--redundancy <action>` | Query redundancy check: `warn`, `adjust`, `skip` |
|
|
147
|
+
| `--quality` | Assess result quality (requires --session) |
|
|
148
|
+
| `--approve <indices>` | Approve pending results by comma-separated indices |
|
|
149
|
+
| `--threshold-override <json>` | Override quality thresholds (JSON) |
|
|
150
|
+
| `--merge <file>` | Merge new results with previous search JSON |
|
|
134
151
|
|
|
135
152
|
### Examples
|
|
136
153
|
|
|
@@ -197,19 +214,29 @@ Create `sxng.config.json`:
|
|
|
197
214
|
|
|
198
215
|
## π§ Deep Search
|
|
199
216
|
|
|
200
|
-
Deep search enables multi-round iterative research with session accumulation
|
|
217
|
+
Deep search enables multi-round iterative research with session accumulation, quality assessment, agent-controlled graph injection, and recovery strategies.
|
|
218
|
+
|
|
219
|
+
### Workflow
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
Search β Extract β Preprocess β Build Graph β Quality Assess β Approve β (Loop or Explore)
|
|
223
|
+
```
|
|
201
224
|
|
|
202
225
|
### Quick Example
|
|
203
226
|
|
|
204
227
|
```bash
|
|
205
|
-
# Create a session and search
|
|
206
|
-
sxng --session new --owner "
|
|
228
|
+
# 1. Create a session and search
|
|
229
|
+
sxng --session new --owner "agent-1" --desc "Rust async study" "rust async ecosystem"
|
|
230
|
+
# Outputs session path, e.g. .sxng/sessions/ds_1712345678_abcdef
|
|
207
231
|
|
|
208
|
-
# Extract content from results
|
|
209
|
-
sxng extract --session
|
|
232
|
+
# 2. Extract content from results
|
|
233
|
+
sxng extract --session ds_1712345678_abcdef
|
|
210
234
|
|
|
211
|
-
#
|
|
212
|
-
sxng graph-
|
|
235
|
+
# 3. Preprocess for entity discovery (TF-IDF + co-occurrence)
|
|
236
|
+
sxng graph-preprocess ds_1712345678_abcdef
|
|
237
|
+
|
|
238
|
+
# 4. Add entities to knowledge graph
|
|
239
|
+
sxng graph-add ds_1712345678_abcdef --data '{
|
|
213
240
|
"entities": [
|
|
214
241
|
{"label": "tokio", "entityType": "runtime", "score": 0.95},
|
|
215
242
|
{"label": "async-std", "entityType": "runtime", "score": 0.85}
|
|
@@ -219,11 +246,14 @@ sxng graph-add <session-name> --data '{
|
|
|
219
246
|
]
|
|
220
247
|
}'
|
|
221
248
|
|
|
222
|
-
#
|
|
223
|
-
sxng
|
|
249
|
+
# 5. Assess quality β results are pending until approved
|
|
250
|
+
sxng --session ds_1712345678_abcdef --quality
|
|
251
|
+
|
|
252
|
+
# 6. Approve pending results by index (injects into graph)
|
|
253
|
+
sxng --session ds_1712345678_abcdef --quality --approve "0,1,2,3"
|
|
224
254
|
|
|
225
|
-
# Continue research
|
|
226
|
-
sxng --session
|
|
255
|
+
# 7. Continue research with redundancy check
|
|
256
|
+
sxng --session ds_1712345678_abcdef --queries "tokio vs async-std,benchmark 2026" --redundancy warn
|
|
227
257
|
```
|
|
228
258
|
|
|
229
259
|
### Session Management
|
|
@@ -243,13 +273,22 @@ sxng --session <session-name> --queries "tokio vs async-std,benchmark 2024"
|
|
|
243
273
|
|
|
244
274
|
### Knowledge Graph
|
|
245
275
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
-
|
|
249
|
-
|
|
276
|
+
Two layers:
|
|
277
|
+
|
|
278
|
+
**Structural** (auto-built):
|
|
279
|
+
| Prefix | Type | Example |
|
|
280
|
+
|--------|------|---------|
|
|
281
|
+
| `q:` | Query node | `q:rust_async` |
|
|
282
|
+
| `r:` | Result node | `r:https://example.com/page` |
|
|
283
|
+
| `d:` | Domain node | `d:github_com` |
|
|
284
|
+
|
|
285
|
+
**Semantic** (via `graph-add`):
|
|
286
|
+
| Prefix | Type | Example |
|
|
287
|
+
|--------|------|---------|
|
|
288
|
+
| `e:` | Entity node | `e:tokio` |
|
|
289
|
+
| `p:` | Path node | `p:chain_001` |
|
|
250
290
|
|
|
251
|
-
|
|
252
|
-
- `e:` β Entity nodes with type and score
|
|
291
|
+
Graph navigation commands: `graph-search` (discover entities), `graph-explore` (view relations), `graph-drill` (follow specific relations), `graph-traverse` (traverse reasoning paths).
|
|
253
292
|
|
|
254
293
|
## π Links
|
|
255
294
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/commands/extract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAoB,MAAM,sBAAsB,CAAC;AAK1E,MAAM,WAAW,cAAc;IAC3B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/commands/extract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAoB,MAAM,sBAAsB,CAAC;AAK1E,MAAM,WAAW,cAAc;IAC3B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAYD,wBAAsB,UAAU,CAC5B,SAAS,EAAE,gBAAgB,EAC3B,OAAO,EAAE,cAAc,GACxB,OAAO,CAAC,MAAM,CAAC,CAyGjB"}
|
package/dist/commands/extract.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Extract subcommand - content extraction from URLs or search results
|
|
3
3
|
*/
|
|
4
4
|
import { createSuccessEnvelope, createErrorEnvelope } from '../protocol.js';
|
|
5
|
-
import { readFileSync } from 'fs';
|
|
6
5
|
import { loadSessionResults, mergeExtractedContent, resolveSessionPath } from '../deep/session.js';
|
|
6
|
+
import { SimHash } from '../deep/simhash.js';
|
|
7
7
|
export async function runExtract(extractor, options) {
|
|
8
8
|
let urls = [];
|
|
9
9
|
// Resolve session path if provided
|
|
@@ -23,41 +23,45 @@ export async function runExtract(extractor, options) {
|
|
|
23
23
|
}
|
|
24
24
|
urls = results.map(r => r.url).filter(u => typeof u === 'string' && u.length > 0);
|
|
25
25
|
}
|
|
26
|
-
else if (options.fromJson) {
|
|
27
|
-
try {
|
|
28
|
-
const raw = readFileSync(options.fromJson, 'utf-8');
|
|
29
|
-
const parsed = JSON.parse(raw);
|
|
30
|
-
// Handle envelope format
|
|
31
|
-
let data = parsed;
|
|
32
|
-
if (parsed.status === 'ok' && parsed.data) {
|
|
33
|
-
data = parsed.data;
|
|
34
|
-
}
|
|
35
|
-
// Extract URLs from results array
|
|
36
|
-
const results = data.results || [];
|
|
37
|
-
urls = results
|
|
38
|
-
.map((r) => r.url)
|
|
39
|
-
.filter((u) => typeof u === 'string' && u.length > 0);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
const envelope = createErrorEnvelope('FILE_READ_FAILED', `Failed to read or parse file: ${options.fromJson}`, { hint: 'Ensure the file exists and contains valid JSON with a results array' });
|
|
43
|
-
console.log(JSON.stringify(envelope, null, 2));
|
|
44
|
-
return 1;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
26
|
else {
|
|
48
|
-
const envelope = createErrorEnvelope('MISSING_INPUT', 'No URLs or input file provided for extraction', { hint: 'Use: sxng extract --urls "url1,url2" or sxng extract --
|
|
27
|
+
const envelope = createErrorEnvelope('MISSING_INPUT', 'No URLs or input file provided for extraction', { hint: 'Use: sxng extract --urls "url1,url2" or sxng extract --session <session>' });
|
|
49
28
|
console.log(JSON.stringify(envelope, null, 2));
|
|
50
29
|
return 1;
|
|
51
30
|
}
|
|
52
31
|
if (urls.length === 0) {
|
|
53
|
-
const envelope = createErrorEnvelope('NO_URLS', 'No URLs found to extract', { hint: 'Provide URLs directly or ensure the
|
|
32
|
+
const envelope = createErrorEnvelope('NO_URLS', 'No URLs found to extract', { hint: 'Provide URLs directly or ensure the session contains results with URLs' });
|
|
54
33
|
console.log(JSON.stringify(envelope, null, 2));
|
|
55
34
|
return 1;
|
|
56
35
|
}
|
|
57
36
|
try {
|
|
58
37
|
const contents = await extractor.extractBatch(urls);
|
|
59
|
-
|
|
60
|
-
const
|
|
38
|
+
// Deduplicate extracted content by first 500 chars using SimHash
|
|
39
|
+
const simhash = new SimHash();
|
|
40
|
+
const seenHashes = [];
|
|
41
|
+
const extracted = [];
|
|
42
|
+
const failed = [];
|
|
43
|
+
for (const c of contents) {
|
|
44
|
+
if (c.error || c.content.length <= 100) {
|
|
45
|
+
failed.push(c.url);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const prefix = c.content.slice(0, 500);
|
|
49
|
+
const h = simhash.hash(prefix);
|
|
50
|
+
let isDuplicate = false;
|
|
51
|
+
for (const existing of seenHashes) {
|
|
52
|
+
if (simhash.similarity(h, existing) >= 0.85) {
|
|
53
|
+
isDuplicate = true;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!isDuplicate) {
|
|
58
|
+
extracted.push(c);
|
|
59
|
+
seenHashes.push(h);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
failed.push(c.url);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
61
65
|
// Merge extracted content into session if --session provided
|
|
62
66
|
let sessionMerge = null;
|
|
63
67
|
if (options.session) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/commands/extract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/commands/extract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAiB7C,MAAM,CAAC,KAAK,UAAU,UAAU,CAC5B,SAA2B,EAC3B,OAAuB;IAEvB,IAAI,IAAI,GAAa,EAAE,CAAC;IAExB,m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|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* graph-add subcommand - Add entities and edges to
|
|
2
|
+
* graph-add subcommand - Add entities and edges to knowledge graph.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* This command receives entities and edges AFTER results have been approved
|
|
5
|
+
* via --quality --approve. Results must already exist as graph nodes before
|
|
6
|
+
* referencing them in edges.
|
|
7
|
+
*
|
|
8
|
+
* - Entities are added immediately (semantic layer)
|
|
9
|
+
* - Edges can reference existing result, entity, domain, or query nodes
|
|
10
|
+
* - Does NOT accept results β use `sxng results-add` for external results
|
|
7
11
|
*/
|
|
8
12
|
export interface GraphAddOptions {
|
|
9
13
|
graphFile: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-add.d.ts","sourceRoot":"","sources":["../../src/commands/graph-add.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"graph-add.d.ts","sourceRoot":"","sources":["../../src/commands/graph-add.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA2BH,MAAM,WAAW,eAAe;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CAChB;AAoBD,wBAAsB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAmI3E"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* graph-add subcommand - Add entities and edges to
|
|
2
|
+
* graph-add subcommand - Add entities and edges to knowledge graph.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* This command receives entities and edges AFTER results have been approved
|
|
5
|
+
* via --quality --approve. Results must already exist as graph nodes before
|
|
6
|
+
* referencing them in edges.
|
|
7
|
+
*
|
|
8
|
+
* - Entities are added immediately (semantic layer)
|
|
9
|
+
* - Edges can reference existing result, entity, domain, or query nodes
|
|
10
|
+
* - Does NOT accept results β use `sxng results-add` for external results
|
|
7
11
|
*/
|
|
8
12
|
import { readFileSync, writeFileSync, existsSync, statSync } from 'fs';
|
|
9
13
|
import { join } from 'path';
|
|
10
|
-
import { deserializeGraph, serializeGraph, graphStats, entityId
|
|
14
|
+
import { deserializeGraph, serializeGraph, graphStats, entityId } from '../deep/graph.js';
|
|
11
15
|
import { DirectedGraph } from 'graphology';
|
|
12
16
|
import { createSuccessEnvelope, createErrorEnvelope } from '../protocol.js';
|
|
13
17
|
import { getDefaultSessionRoot } from './session.js';
|
|
@@ -42,7 +46,7 @@ export async function runGraphAdd(options) {
|
|
|
42
46
|
parsed = JSON.parse(options.data);
|
|
43
47
|
}
|
|
44
48
|
catch {
|
|
45
|
-
const envelope = createErrorEnvelope('INVALID_JSON', 'Failed to parse --data JSON', { hint: 'Ensure --data contains valid JSON with "entities"
|
|
49
|
+
const envelope = createErrorEnvelope('INVALID_JSON', 'Failed to parse --data JSON', { hint: 'Ensure --data contains valid JSON with "entities" and/or "edges" arrays' });
|
|
46
50
|
console.log(JSON.stringify(envelope, null, 2));
|
|
47
51
|
return 1;
|
|
48
52
|
}
|
|
@@ -69,9 +73,7 @@ export async function runGraphAdd(options) {
|
|
|
69
73
|
graph = new DirectedGraph();
|
|
70
74
|
}
|
|
71
75
|
let entitiesAdded = 0;
|
|
72
|
-
|
|
73
|
-
let edgesAdded = 0;
|
|
74
|
-
// Add entity nodes
|
|
76
|
+
// Add entity nodes (semantic layer β goes directly to graph)
|
|
75
77
|
for (const entity of parsed.entities || []) {
|
|
76
78
|
const id = entity.id || entityId(entity.label);
|
|
77
79
|
if (!graph.hasNode(id)) {
|
|
@@ -102,34 +104,10 @@ export async function runGraphAdd(options) {
|
|
|
102
104
|
});
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
|
-
// Add result
|
|
106
|
-
|
|
107
|
-
const id = resultId(result.url);
|
|
108
|
-
if (!graph.hasNode(id)) {
|
|
109
|
-
graph.mergeNode(id, {
|
|
110
|
-
type: 'result',
|
|
111
|
-
label: result.title,
|
|
112
|
-
url: result.url,
|
|
113
|
-
title: result.title,
|
|
114
|
-
rank: result.rank,
|
|
115
|
-
source: result.source,
|
|
116
|
-
});
|
|
117
|
-
resultsAdded++;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// Update rank if better, merge source if provided
|
|
121
|
-
const existing = graph.getNodeAttributes(id);
|
|
122
|
-
if (result.rank !== undefined) {
|
|
123
|
-
graph.mergeNode(id, {
|
|
124
|
-
...existing,
|
|
125
|
-
rank: result.rank < (existing.rank ?? Infinity) ? result.rank : existing.rank,
|
|
126
|
-
source: result.source ?? existing.source,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
// Add edges (entity-entity and entity-result relationships)
|
|
107
|
+
// Add edges (entity-entity relationships only β entity-result edges will be
|
|
108
|
+
// skipped and reported since result nodes are pending, not yet in graph).
|
|
132
109
|
const skippedEdges = [];
|
|
110
|
+
let edgesAdded = 0;
|
|
133
111
|
for (const edge of parsed.edges || []) {
|
|
134
112
|
if (!graph.hasNode(edge.source) || !graph.hasNode(edge.target)) {
|
|
135
113
|
skippedEdges.push({ source: edge.source, target: edge.target, relation: edge.relation });
|
|
@@ -154,9 +132,9 @@ export async function runGraphAdd(options) {
|
|
|
154
132
|
}
|
|
155
133
|
const envelope = createSuccessEnvelope({
|
|
156
134
|
entitiesAdded,
|
|
157
|
-
resultsAdded,
|
|
158
135
|
edgesAdded,
|
|
159
|
-
skippedEdges,
|
|
136
|
+
skippedEdges: skippedEdges.length > 0 ? skippedEdges : undefined,
|
|
137
|
+
...(skippedEdges.length > 0 ? { hint: `${skippedEdges.length} edge(s) skipped β target nodes not found in graph.` } : {}),
|
|
160
138
|
stats,
|
|
161
139
|
});
|
|
162
140
|
console.log(JSON.stringify(envelope, null, 2));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-add.js","sourceRoot":"","sources":["../../src/commands/graph-add.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"graph-add.js","sourceRoot":"","sources":["../../src/commands/graph-add.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAkC,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC1H,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD;;GAEG;AACH,SAAS,gBAAgB,CAAC,IAAY;IAClC,qEAAqE;IACrE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,IAAI,GAAG,IAAI,CAAC,qBAAqB,EAAE,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QACpC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACL,+BAA+B;IACnC,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAyBD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAwB;IACtD,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEtD,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,MAAM,QAAQ,GAAG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* results-add subcommand - Append external search results to session as pending.
|
|
3
|
+
*
|
|
4
|
+
* Use this to inject results from other search tools (tavily, exa, etc.)
|
|
5
|
+
* into the session pipeline. Results go through the same pending β approve
|
|
6
|
+
* β graph injection flow as sxng-native results.
|
|
7
|
+
*/
|
|
8
|
+
export interface ResultsAddOptions {
|
|
9
|
+
session: string;
|
|
10
|
+
data: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function runResultsAdd(options: ResultsAddOptions): Promise<number>;
|
|
13
|
+
//# sourceMappingURL=results-add.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results-add.d.ts","sourceRoot":"","sources":["../../src/commands/results-add.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,WAAW,iBAAiB;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAuC/E"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* results-add subcommand - Append external search results to session as pending.
|
|
3
|
+
*
|
|
4
|
+
* Use this to inject results from other search tools (tavily, exa, etc.)
|
|
5
|
+
* into the session pipeline. Results go through the same pending β approve
|
|
6
|
+
* β graph injection flow as sxng-native results.
|
|
7
|
+
*/
|
|
8
|
+
import { createSuccessEnvelope, createErrorEnvelope } from '../protocol.js';
|
|
9
|
+
import { appendSessionResults, resolveSessionPath, getPendingResults } from '../deep/session.js';
|
|
10
|
+
export async function runResultsAdd(options) {
|
|
11
|
+
const sessionDir = resolveSessionPath(options.session);
|
|
12
|
+
// Parse input data
|
|
13
|
+
let results;
|
|
14
|
+
try {
|
|
15
|
+
const parsed = JSON.parse(options.data);
|
|
16
|
+
results = Array.isArray(parsed) ? parsed : (parsed.results || []);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
const envelope = createErrorEnvelope('INVALID_JSON', 'Failed to parse --data JSON', { hint: 'Provide a JSON array of results or an object with a "results" array' });
|
|
20
|
+
console.log(JSON.stringify(envelope, null, 2));
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
23
|
+
if (results.length === 0) {
|
|
24
|
+
const envelope = createErrorEnvelope('NO_RESULTS', 'No results found in --data', { hint: 'Ensure the JSON contains a non-empty results array' });
|
|
25
|
+
console.log(JSON.stringify(envelope, null, 2));
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
const result = appendSessionResults(sessionDir, results);
|
|
29
|
+
const pendingCount = getPendingResults(sessionDir).length;
|
|
30
|
+
const envelope = createSuccessEnvelope({
|
|
31
|
+
added: result.added,
|
|
32
|
+
total: result.total,
|
|
33
|
+
pendingCount,
|
|
34
|
+
message: `Added ${result.added} results from external source as pending (${pendingCount} total pending). Run --quality --approve to inject into graph.`,
|
|
35
|
+
});
|
|
36
|
+
console.log(JSON.stringify(envelope, null, 2));
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=results-add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results-add.js","sourceRoot":"","sources":["../../src/commands/results-add.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAOjG,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA0B;IAC1D,MAAM,UAAU,GAAG,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEvD,mBAAmB;IACnB,IAAI,OAAiF,CAAC;IACtF,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACxC,OAAO,GAAG,KAAK,CAAC,OA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d.ts","sourceRoot":"","sources":["../../src/deep/iteration-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAuB,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,mBAAmB,EAAyC,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAmB,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAA0B,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAIjG,MAAM,WAAW,eAAe;IAC5B,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;IACvB,WAAW,EAAE,mBAAmB,CAAC;IACjC,QAAQ,EAAE,gBAAgB,CAAC;CAC9B;AAID;;4EAE4E;AAC5E,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EACpD,cAAc,EAAE,aAAa,EAAE,EAC/B,OAAO,CAAC,EAAE;IACN,iBAAiB,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC/C,cAAc,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5C,GACF,eAAe,
|
|
1
|
+
{"version":3,"file":"iteration-data.d.ts","sourceRoot":"","sources":["../../src/deep/iteration-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAuB,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,mBAAmB,EAAyC,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAmB,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAA0B,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAIjG,MAAM,WAAW,eAAe;IAC5B,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;IACvB,WAAW,EAAE,mBAAmB,CAAC;IACjC,QAAQ,EAAE,gBAAgB,CAAC;CAC9B;AAID;;4EAE4E;AAC5E,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EACpD,cAAc,EAAE,aAAa,EAAE,EAC/B,OAAO,CAAC,EAAE;IACN,iBAAiB,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC/C,cAAc,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5C,GACF,eAAe,CA4BjB;AAED;gFACgF;AAChF,wBAAgB,uBAAuB,CACnC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EACpD,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GACnC,gBAAgB,CAYlB"}
|
|
@@ -22,7 +22,7 @@ import { checkQueryRedundancy } from './query-redundancy.js';
|
|
|
22
22
|
* and recovery analysis into a single output for Agent decision-making. */
|
|
23
23
|
export function getSessionAnalysis(graph, sessionResults, options) {
|
|
24
24
|
// Quality assessment
|
|
25
|
-
const quality = assessResultQuality(sessionResults, sessionResults,
|
|
25
|
+
const quality = assessResultQuality(sessionResults, sessionResults, options?.qualityThresholds);
|
|
26
26
|
// Strategy info
|
|
27
27
|
const strategy = getStrategyInfo(graph, options?.strategyConfig);
|
|
28
28
|
// Query suggestions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iteration-data.js","sourceRoot":"","sources":["../../src/deep/iteration-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAmC,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAoC,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAgC,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAoB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAsC,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAWjG,qEAAqE;AAErE;;4EAE4E;AAC5E,MAAM,UAAU,kBAAkB,CAC9B,KAAoD,EACpD,cAA+B,EAC/B,OAGC;IAED,qBAAqB;IACrB,MAAM,OAAO,GAAG,mBAAmB,CAC/B,cAAc,EACd,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"iteration-data.js","sourceRoot":"","sources":["../../src/deep/iteration-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAmC,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAoC,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAgC,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAoB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAsC,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAWjG,qEAAqE;AAErE;;4EAE4E;AAC5E,MAAM,UAAU,kBAAkB,CAC9B,KAAoD,EACpD,cAA+B,EAC/B,OAGC;IAED,qBAAqB;IACrB,MAAM,OAAO,GAAG,mBAAmB,CAC/B,cAAc,EACd,cAAc,EACd,OAAO,EAAE,iBAAiB,CAC7B,CAAC;IAEF,gBAAgB;IAChB,MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IAEjE,oBAAoB;IACpB,MAAM,WAAW,GAAG,wBAAwB,CACxC,KAAK,EACL,cAAc,EACd,QAAQ,CAAC,YAAY,EACrB,OAAO,CACV,CAAC;IAEF,oBAAoB;IACpB,MAAM,QAAQ,GAAG,sBAAsB,CACnC,KAAK,EACL,cAAc,EACd,OAAO,EACP,OAAO,EAAE,cAAc,CAC1B,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACxD,CAAC;AAED;gFACgF;AAChF,MAAM,UAAU,uBAAuB,CACnC,QAAgB,EAChB,KAAoD,EACpD,MAAkC;IAElC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,CAAC,WAAW,CAAC,CAAC,KAAa,EAAE,KAAqB,EAAE,EAAE;QACvD,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACxC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE;QAC3C,gBAAgB,EAAE,MAAM,EAAE,gBAAgB,IAAI,GAAG;QACjD,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,MAAM;KACnC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Result quality assessment for deep search sessions.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Programmatic pre-filter: removes obviously poor results before
|
|
5
|
+
* Agent review. Agent makes the final quality decision based on
|
|
6
|
+
* title, content, and source.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
8
|
+
* Three indicators (independent thresholds, no weighted sum):
|
|
9
|
+
* - contentDepth: average extracted content length
|
|
10
|
+
* - sourceDiversity: number of distinct domains
|
|
11
|
+
* - novelty: fraction not similar to existing results (SimHash)
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* Verdict logic:
|
|
14
|
+
* - good: all pass
|
|
15
|
+
* - acceptable: 1 fails
|
|
16
|
+
* - poor: β₯2 fail
|
|
14
17
|
*/
|
|
15
|
-
import { DirectedGraph } from 'graphology';
|
|
16
18
|
import { SessionResult } from './session.js';
|
|
17
|
-
import { GraphNodeAttrs, GraphEdgeAttrs } from './graph.js';
|
|
18
19
|
export interface IndicatorResult {
|
|
19
20
|
value: number;
|
|
20
21
|
threshold: number;
|
|
21
22
|
pass: boolean;
|
|
22
23
|
}
|
|
23
24
|
export interface QualityBreakdown {
|
|
24
|
-
resultCount: IndicatorResult;
|
|
25
25
|
contentDepth: IndicatorResult;
|
|
26
|
-
entityRichness: IndicatorResult;
|
|
27
26
|
sourceDiversity: IndicatorResult;
|
|
28
27
|
novelty: IndicatorResult;
|
|
29
28
|
}
|
|
@@ -33,13 +32,13 @@ export interface QualityScore {
|
|
|
33
32
|
failedIndicators: string[];
|
|
34
33
|
}
|
|
35
34
|
export interface QualityThresholds {
|
|
36
|
-
resultCount: number;
|
|
37
35
|
contentDepth: number;
|
|
38
|
-
entityRichness: number;
|
|
39
36
|
sourceDiversity: number;
|
|
40
37
|
novelty: number;
|
|
41
38
|
}
|
|
42
|
-
/** Assess the quality of
|
|
43
|
-
*
|
|
44
|
-
|
|
39
|
+
/** Assess the quality of results against session context.
|
|
40
|
+
* Programmatic pre-filter only β Agent makes final quality decision.
|
|
41
|
+
* All indicators use independent thresholds β no weighted sum.
|
|
42
|
+
*/
|
|
43
|
+
export declare function assessResultQuality(results: SessionResult[], sessionResults: SessionResult[], thresholds?: Partial<QualityThresholds>): QualityScore;
|
|
45
44
|
//# sourceMappingURL=quality-assess.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quality-assess.d.ts","sourceRoot":"","sources":["../../src/deep/quality-assess.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quality-assess.d.ts","sourceRoot":"","sources":["../../src/deep/quality-assess.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC7B,YAAY,EAAE,eAAe,CAAC;IAC9B,eAAe,EAAE,eAAe,CAAC;IACjC,OAAO,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,MAAM,CAAC;IACxC,SAAS,EAAE,gBAAgB,CAAC;IAC5B,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACnB;AAoFD;;;GAGG;AACH,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,aAAa,EAAE,EACxB,cAAc,EAAE,aAAa,EAAE,EAC/B,UAAU,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACxC,YAAY,CAuBd"}
|