digdig 0.0.2 → 0.0.4
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 +12 -14
- package/digdig.config.example.json +0 -0
- package/dist/claims/deterministic-checks.d.ts +0 -0
- package/dist/claims/deterministic-checks.d.ts.map +0 -0
- package/dist/claims/deterministic-checks.js +0 -0
- package/dist/claims/deterministic-checks.js.map +0 -0
- package/dist/claims/policy.d.ts +0 -0
- package/dist/claims/policy.d.ts.map +0 -0
- package/dist/claims/policy.js +0 -0
- package/dist/claims/policy.js.map +0 -0
- package/dist/claims/store.d.ts +0 -0
- package/dist/claims/store.d.ts.map +0 -0
- package/dist/claims/store.js +0 -0
- package/dist/claims/store.js.map +0 -0
- package/dist/claims/types.d.ts +0 -0
- package/dist/claims/types.d.ts.map +0 -0
- package/dist/claims/types.js +0 -0
- package/dist/claims/types.js.map +0 -0
- package/dist/commands/claim.d.ts +0 -0
- package/dist/commands/claim.d.ts.map +0 -0
- package/dist/commands/claim.js +0 -0
- package/dist/commands/claim.js.map +0 -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 +0 -0
- package/dist/commands/doc-index.d.ts.map +0 -0
- package/dist/commands/doc-index.js +0 -0
- package/dist/commands/doc-index.js.map +0 -0
- package/dist/commands/doc-search.d.ts +0 -0
- package/dist/commands/doc-search.d.ts.map +0 -0
- package/dist/commands/doc-search.js +0 -0
- package/dist/commands/doc-search.js.map +0 -0
- package/dist/commands/evidence.d.ts +0 -0
- package/dist/commands/evidence.d.ts.map +0 -0
- package/dist/commands/evidence.js +0 -0
- package/dist/commands/evidence.js.map +0 -0
- package/dist/commands/extract.d.ts +0 -0
- package/dist/commands/extract.d.ts.map +0 -0
- package/dist/commands/extract.js +5 -5
- package/dist/commands/extract.js.map +1 -1
- package/dist/commands/graph-add.d.ts +0 -0
- package/dist/commands/graph-add.d.ts.map +0 -0
- package/dist/commands/graph-add.js +0 -0
- package/dist/commands/graph-add.js.map +1 -1
- package/dist/commands/graph-drill.d.ts +0 -0
- package/dist/commands/graph-drill.d.ts.map +0 -0
- package/dist/commands/graph-drill.js +0 -0
- package/dist/commands/graph-drill.js.map +0 -0
- package/dist/commands/graph-explore.d.ts +0 -0
- package/dist/commands/graph-explore.d.ts.map +0 -0
- package/dist/commands/graph-explore.js +0 -0
- package/dist/commands/graph-explore.js.map +0 -0
- package/dist/commands/graph-obfuscate.d.ts +0 -0
- package/dist/commands/graph-obfuscate.d.ts.map +0 -0
- package/dist/commands/graph-obfuscate.js +0 -0
- package/dist/commands/graph-obfuscate.js.map +0 -0
- package/dist/commands/graph-search.d.ts +0 -0
- package/dist/commands/graph-search.d.ts.map +0 -0
- package/dist/commands/graph-search.js +0 -0
- package/dist/commands/graph-search.js.map +0 -0
- package/dist/commands/graph-traverse.d.ts +0 -0
- package/dist/commands/graph-traverse.d.ts.map +0 -0
- package/dist/commands/graph-traverse.js +0 -0
- package/dist/commands/graph-traverse.js.map +0 -0
- package/dist/commands/json-input.d.ts +0 -0
- package/dist/commands/json-input.d.ts.map +0 -0
- package/dist/commands/json-input.js +0 -0
- package/dist/commands/json-input.js.map +0 -0
- package/dist/commands/query-graph.d.ts +0 -0
- package/dist/commands/query-graph.d.ts.map +0 -0
- package/dist/commands/query-graph.js +0 -0
- package/dist/commands/query-graph.js.map +0 -0
- package/dist/commands/results-add.d.ts +0 -0
- package/dist/commands/results-add.d.ts.map +0 -0
- package/dist/commands/results-add.js +0 -0
- package/dist/commands/results-add.js.map +0 -0
- package/dist/commands/review.d.ts +0 -0
- package/dist/commands/review.d.ts.map +0 -0
- package/dist/commands/review.js +0 -0
- package/dist/commands/review.js.map +0 -0
- package/dist/commands/session.d.ts +0 -0
- package/dist/commands/session.d.ts.map +0 -0
- package/dist/commands/session.js +0 -0
- package/dist/commands/session.js.map +0 -0
- package/dist/commands/verdict.d.ts +0 -0
- package/dist/commands/verdict.d.ts.map +0 -0
- package/dist/commands/verdict.js +0 -0
- package/dist/commands/verdict.js.map +0 -0
- package/dist/config.d.ts +0 -0
- package/dist/config.d.ts.map +0 -0
- package/dist/config.js +0 -0
- package/dist/config.js.map +0 -0
- package/dist/deep/co-occurrence.d.ts +0 -0
- package/dist/deep/co-occurrence.d.ts.map +0 -0
- package/dist/deep/co-occurrence.js +0 -0
- package/dist/deep/co-occurrence.js.map +0 -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 +9 -1
- package/dist/deep/dedupe.d.ts.map +1 -1
- package/dist/deep/dedupe.js +21 -2
- package/dist/deep/dedupe.js.map +1 -1
- package/dist/deep/degree-utils.d.ts +0 -0
- package/dist/deep/degree-utils.d.ts.map +0 -0
- package/dist/deep/degree-utils.js +0 -0
- package/dist/deep/degree-utils.js.map +0 -0
- package/dist/deep/extractor.d.ts +0 -0
- package/dist/deep/extractor.d.ts.map +0 -0
- package/dist/deep/extractor.js +0 -0
- package/dist/deep/extractor.js.map +0 -0
- package/dist/deep/fuse.d.ts +63 -0
- package/dist/deep/fuse.d.ts.map +1 -0
- package/dist/deep/fuse.js +122 -0
- package/dist/deep/fuse.js.map +1 -0
- package/dist/deep/graph-explore.d.ts +0 -0
- package/dist/deep/graph-explore.d.ts.map +0 -0
- package/dist/deep/graph-explore.js +0 -0
- package/dist/deep/graph-explore.js.map +0 -0
- package/dist/deep/graph-obfuscate.d.ts +0 -0
- package/dist/deep/graph-obfuscate.d.ts.map +0 -0
- package/dist/deep/graph-obfuscate.js +0 -0
- package/dist/deep/graph-obfuscate.js.map +0 -0
- package/dist/deep/graph-preprocess.d.ts +0 -0
- package/dist/deep/graph-preprocess.d.ts.map +0 -0
- package/dist/deep/graph-preprocess.js +0 -0
- package/dist/deep/graph-preprocess.js.map +0 -0
- package/dist/deep/graph-sampling.d.ts +0 -0
- package/dist/deep/graph-sampling.d.ts.map +0 -0
- package/dist/deep/graph-sampling.js +0 -0
- package/dist/deep/graph-sampling.js.map +0 -0
- package/dist/deep/graph.d.ts +0 -0
- package/dist/deep/graph.d.ts.map +0 -0
- package/dist/deep/graph.js +0 -0
- package/dist/deep/graph.js.map +0 -0
- package/dist/deep/index.d.ts +1 -1
- package/dist/deep/index.d.ts.map +0 -0
- package/dist/deep/index.js +1 -1
- package/dist/deep/index.js.map +0 -0
- package/dist/deep/iteration-data.d.ts +9 -13
- package/dist/deep/iteration-data.d.ts.map +1 -1
- package/dist/deep/iteration-data.js +12 -16
- package/dist/deep/iteration-data.js.map +1 -1
- package/dist/deep/local-doc/indexer.d.ts +0 -4
- package/dist/deep/local-doc/indexer.d.ts.map +1 -1
- package/dist/deep/local-doc/indexer.js +21 -3
- package/dist/deep/local-doc/indexer.js.map +1 -1
- package/dist/deep/local-doc/scanner.d.ts +0 -0
- package/dist/deep/local-doc/scanner.d.ts.map +0 -0
- package/dist/deep/local-doc/scanner.js +0 -0
- package/dist/deep/local-doc/scanner.js.map +0 -0
- package/dist/deep/local-doc/searcher.d.ts +0 -0
- package/dist/deep/local-doc/searcher.d.ts.map +1 -1
- package/dist/deep/local-doc/searcher.js +3 -4
- package/dist/deep/local-doc/searcher.js.map +1 -1
- package/dist/deep/local-doc/types.d.ts +0 -0
- package/dist/deep/local-doc/types.d.ts.map +0 -0
- package/dist/deep/local-doc/types.js +0 -0
- package/dist/deep/local-doc/types.js.map +0 -0
- package/dist/deep/path-extraction.d.ts +0 -0
- package/dist/deep/path-extraction.d.ts.map +0 -0
- package/dist/deep/path-extraction.js +0 -0
- package/dist/deep/path-extraction.js.map +0 -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 +0 -0
- package/dist/deep/query-redundancy.d.ts.map +0 -0
- package/dist/deep/query-redundancy.js +0 -0
- package/dist/deep/query-redundancy.js.map +0 -0
- package/dist/deep/query-suggest.d.ts +1 -3
- package/dist/deep/query-suggest.d.ts.map +1 -1
- package/dist/deep/query-suggest.js +3 -11
- package/dist/deep/query-suggest.js.map +1 -1
- package/dist/deep/rrf.d.ts +0 -0
- package/dist/deep/rrf.d.ts.map +0 -0
- package/dist/deep/rrf.js +0 -0
- package/dist/deep/rrf.js.map +0 -0
- package/dist/deep/search-strategy.d.ts +0 -0
- package/dist/deep/search-strategy.d.ts.map +0 -0
- package/dist/deep/search-strategy.js +0 -0
- package/dist/deep/search-strategy.js.map +0 -0
- package/dist/deep/session.d.ts +5 -3
- package/dist/deep/session.d.ts.map +1 -1
- package/dist/deep/session.js +29 -9
- package/dist/deep/session.js.map +1 -1
- package/dist/deep/simhash.d.ts +0 -0
- package/dist/deep/simhash.d.ts.map +0 -0
- package/dist/deep/simhash.js +0 -0
- package/dist/deep/simhash.js.map +0 -0
- package/dist/deep/tfidf.d.ts +0 -0
- package/dist/deep/tfidf.d.ts.map +0 -0
- package/dist/deep/tfidf.js +0 -0
- package/dist/deep/tfidf.js.map +0 -0
- package/dist/deepseek-service.d.ts +0 -0
- package/dist/deepseek-service.d.ts.map +1 -1
- package/dist/deepseek-service.js +7 -3
- package/dist/deepseek-service.js.map +1 -1
- package/dist/entry.d.ts +5 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +7 -2
- package/dist/entry.js.map +1 -1
- 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 +0 -0
- package/dist/index.d.ts.map +0 -0
- package/dist/index.js.map +0 -0
- package/dist/init.d.ts +0 -0
- package/dist/init.d.ts.map +0 -0
- package/dist/init.js +0 -0
- package/dist/init.js.map +0 -0
- package/dist/legacy.d.ts +0 -0
- package/dist/legacy.d.ts.map +0 -0
- package/dist/legacy.js +0 -0
- package/dist/legacy.js.map +0 -0
- package/dist/ollama-service.d.ts +0 -0
- package/dist/ollama-service.d.ts.map +1 -1
- package/dist/ollama-service.js +27 -6
- package/dist/ollama-service.js.map +1 -1
- package/dist/protocol.d.ts +0 -0
- package/dist/protocol.d.ts.map +0 -0
- package/dist/protocol.js +0 -0
- package/dist/protocol.js.map +0 -0
- package/dist/runCli.d.ts +1 -1
- package/dist/runCli.d.ts.map +1 -1
- package/dist/runCli.js +274 -434
- package/dist/runCli.js.map +1 -1
- package/dist/service.d.ts +39 -1
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +76 -22
- package/dist/service.js.map +1 -1
- package/dist/sxng.d.ts +0 -0
- package/dist/sxng.d.ts.map +0 -0
- package/dist/sxng.js.map +0 -0
- package/package.json +2 -2
- package/dist/commands/build-graph.d.ts +0 -8
- package/dist/commands/build-graph.d.ts.map +0 -1
- package/dist/commands/build-graph.js +0 -70
- package/dist/commands/build-graph.js.map +0 -1
- package/dist/commands/graph-add.d.ts.sync-conflict-20260629-232900-2SGIW5T.map +0 -1
- package/dist/commands/graph-add.js.sync-conflict-20260629-232916-2SGIW5T.map +0 -1
- package/dist/commands/graph-add.sync-conflict-20260629-232853-2SGIW5T.js +0 -163
- package/dist/commands/raw.d.ts +0 -14
- package/dist/commands/raw.d.ts.map +0 -1
- package/dist/commands/raw.js +0 -125
- package/dist/commands/raw.js.map +0 -1
- package/dist/deep/extractor.d.sync-conflict-20260629-232902-2SGIW5T.ts +0 -37
- package/dist/deep/extractor.d.ts.sync-conflict-20260629-232921-2SGIW5T.map +0 -1
- package/dist/deep/extractor.js.sync-conflict-20260629-232921-2SGIW5T.map +0 -1
- package/dist/deep/extractor.sync-conflict-20260629-232903-2SGIW5T.js +0 -203
- package/dist/deep/graph.d.sync-conflict-20260629-232917-2SGIW5T.ts +0 -78
- package/dist/deep/graph.d.ts.sync-conflict-20260629-232911-2SGIW5T.map +0 -1
- package/dist/deep/graph.js.sync-conflict-20260629-232855-2SGIW5T.map +0 -1
- package/dist/deep/graph.sync-conflict-20260629-232907-2SGIW5T.js +0 -194
- package/dist/deep/keywords.d.ts +0 -27
- package/dist/deep/keywords.d.ts.map +0 -1
- package/dist/deep/keywords.js +0 -293
- package/dist/deep/keywords.js.map +0 -1
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.d.ts +0 -38
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.d.ts.map +0 -1
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.js +0 -212
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.js.map +0 -1
- package/dist/deep/quality-assess.d.ts +0 -46
- package/dist/deep/quality-assess.d.ts.map +0 -1
- package/dist/deep/quality-assess.js +0 -122
- package/dist/deep/quality-assess.js.map +0 -1
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.d.ts +0 -46
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.d.ts.map +0 -1
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.js +0 -122
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.js.map +0 -1
- package/dist/deep/recovery-analysis.d.ts +0 -60
- package/dist/deep/recovery-analysis.d.ts.map +0 -1
- package/dist/deep/recovery-analysis.js +0 -185
- package/dist/deep/recovery-analysis.js.map +0 -1
- package/dist/deep/session.d.sync-conflict-20260629-232917-2SGIW5T.ts +0 -71
- package/dist/deep/session.d.ts.sync-conflict-20260629-232921-2SGIW5T.map +0 -1
- package/dist/deep/session.js.sync-conflict-20260629-232854-2SGIW5T.map +0 -1
- package/dist/runCli.d.ts.sync-conflict-20260629-232854-2SGIW5T.map +0 -1
- package/dist/runCli.js.sync-conflict-20260629-232857-2SGIW5T.map +0 -1
- package/dist/runCli.sync-conflict-20260629-232915-2SGIW5T.js +0 -1109
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.d.ts +0 -8
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.d.ts.map +0 -1
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.js +0 -1111
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.js.map +0 -1
package/dist/runCli.js
CHANGED
|
@@ -8,6 +8,7 @@ import { dirname, join } from 'path';
|
|
|
8
8
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
9
|
const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
|
|
10
10
|
import { createSuccessEnvelope, createErrorEnvelope } from './protocol.js';
|
|
11
|
+
import { SearchError } from './errors.js';
|
|
11
12
|
import { config } from './config.js';
|
|
12
13
|
import { OllamaService } from './ollama-service.js';
|
|
13
14
|
import { DeepSeekService } from './deepseek-service.js';
|
|
@@ -20,18 +21,18 @@ import { runDocIndex } from './commands/doc-index.js';
|
|
|
20
21
|
import { runDocSearch } from './commands/doc-search.js';
|
|
21
22
|
import { runGraphObfuscateCommand } from './commands/graph-obfuscate.js';
|
|
22
23
|
import { ContentExtractor } from './deep/extractor.js';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
24
|
+
import { resultUrlKey } from './deep/dedupe.js';
|
|
25
|
+
import { fuseResults, mergeEnvelopeMetadata } from './deep/fuse.js';
|
|
25
26
|
import { graphStats } from './deep/graph.js';
|
|
26
|
-
import { initSessionDir, resolveSessionPath, appendSessionResults, loadSessionResults, loadSessionGraph, countPendingResults, getPendingResults, approveResults, injectApprovedResults,
|
|
27
|
+
import { initSessionDir, resolveSessionPath, appendSessionResults, loadSessionResults, loadSessionGraph, countPendingResults, getPendingResults, approveResults, injectApprovedResults, setSkipped } from './deep/session.js';
|
|
27
28
|
import { runSessionList, runSessionDelete } from './commands/session.js';
|
|
28
29
|
import { graphPreprocess } from './deep/graph-preprocess.js';
|
|
29
30
|
import { checkQueryRedundancy } from './deep/query-redundancy.js';
|
|
30
|
-
import {
|
|
31
|
+
import { buildPendingReport, describeResult } from './deep/pending-facts.js';
|
|
31
32
|
import { generateQuerySuggestions } from './deep/query-suggest.js';
|
|
32
33
|
import { determineSearchStage, getStrategyInfo } from './deep/search-strategy.js';
|
|
33
|
-
import { analyzeRecoveryOptions } from './deep/recovery-analysis.js';
|
|
34
34
|
import { getSessionAnalysis } from './deep/iteration-data.js';
|
|
35
|
+
import { runCoverage } from './commands/coverage.js';
|
|
35
36
|
import { runGraphExplore } from './commands/graph-explore.js';
|
|
36
37
|
import { runGraphDrill } from './commands/graph-drill.js';
|
|
37
38
|
import { runGraphTraverse } from './commands/graph-traverse.js';
|
|
@@ -54,6 +55,38 @@ import { readSessionJsonInput } from './commands/json-input.js';
|
|
|
54
55
|
function displayText(result) {
|
|
55
56
|
return result.snippet || result.excerpt || result.content || '';
|
|
56
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* How many engines returned this result, naming each and its rank.
|
|
60
|
+
*
|
|
61
|
+
* Only shown when more than one engine agreed. A single-engine result is the
|
|
62
|
+
* common case and saying "1 engine" on every line is noise; two engines
|
|
63
|
+
* independently placing a URL is the thing worth surfacing, because it is the
|
|
64
|
+
* only part of the ordering a reader can check against its own judgement.
|
|
65
|
+
*/
|
|
66
|
+
function agreementLabel(votes) {
|
|
67
|
+
if (!votes || votes.length < 2)
|
|
68
|
+
return '';
|
|
69
|
+
const parts = votes.map(vote => `${vote.engine} #${vote.position}`);
|
|
70
|
+
return ` [${votes.length} engines: ${parts.join(', ')}]`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Says so when a filter was asked for but no per-engine confirmation exists.
|
|
74
|
+
*
|
|
75
|
+
* `--time` and `--lang` go to SearXNG as one request parameter, and which
|
|
76
|
+
* engines honour them is the server's business — the payload never reports
|
|
77
|
+
* per-engine filter support. Printing a filtered-looking result set without this
|
|
78
|
+
* note would let a caller assume the constraint held everywhere.
|
|
79
|
+
*/
|
|
80
|
+
function filterScopeNote(data) {
|
|
81
|
+
const requested = [];
|
|
82
|
+
if (data.timeRange)
|
|
83
|
+
requested.push(`time=${data.timeRange}`);
|
|
84
|
+
if (data.language)
|
|
85
|
+
requested.push(`lang=${data.language}`);
|
|
86
|
+
if (requested.length === 0)
|
|
87
|
+
return '';
|
|
88
|
+
return `*Filter (${requested.join(', ')}) was sent as one request parameter; whether every engine applied it is not reported.*`;
|
|
89
|
+
}
|
|
57
90
|
function formatAsMarkdown(data) {
|
|
58
91
|
const lines = [];
|
|
59
92
|
lines.push(`## Search: ${data.query || 'Unknown'}`);
|
|
@@ -68,7 +101,7 @@ function formatAsMarkdown(data) {
|
|
|
68
101
|
if (r.score !== undefined && r.score !== null) {
|
|
69
102
|
scoreIndicator = ` [Source score: ${r.score}]`;
|
|
70
103
|
}
|
|
71
|
-
lines.push(`### ${i + 1}. [${r.title || 'No Title'}](${r.url || '#'})${scoreIndicator}`);
|
|
104
|
+
lines.push(`### ${i + 1}. [${r.title || 'No Title'}](${r.url || '#'})${scoreIndicator}${agreementLabel(r.votes)}`);
|
|
72
105
|
lines.push('');
|
|
73
106
|
if (displayText(r)) {
|
|
74
107
|
lines.push(displayText(r));
|
|
@@ -95,10 +128,21 @@ function formatAsMarkdown(data) {
|
|
|
95
128
|
lines.push('');
|
|
96
129
|
}
|
|
97
130
|
if (data.unresponsiveEngines && data.unresponsiveEngines.length > 0) {
|
|
98
|
-
|
|
131
|
+
// The reason travels with the name: "google" alone reads as a blip,
|
|
132
|
+
// "google (Suspended: access denied)" reads as a reason to stop asking.
|
|
133
|
+
const unresponsive = data.unresponsiveEngines.map((entry) => {
|
|
134
|
+
const engine = typeof entry === 'string' ? entry : entry?.engine ?? '';
|
|
135
|
+
const reason = typeof entry === 'string' ? '' : entry?.reason ?? '';
|
|
136
|
+
return reason ? `${engine} (${reason})` : engine;
|
|
137
|
+
}).filter(Boolean).join(', ');
|
|
99
138
|
lines.push(`*Unresponsive: ${unresponsive}*`);
|
|
100
139
|
lines.push('');
|
|
101
140
|
}
|
|
141
|
+
const note = filterScopeNote(data);
|
|
142
|
+
if (note) {
|
|
143
|
+
lines.push(note);
|
|
144
|
+
lines.push('');
|
|
145
|
+
}
|
|
102
146
|
if (data.suggestions && data.suggestions.length > 0) {
|
|
103
147
|
lines.push('**Suggestions:** ' + data.suggestions.join(' · '));
|
|
104
148
|
lines.push('');
|
|
@@ -160,35 +204,23 @@ function formatPreprocessAsMarkdown(data) {
|
|
|
160
204
|
}
|
|
161
205
|
return lines.join('\n');
|
|
162
206
|
}
|
|
163
|
-
function
|
|
207
|
+
function formatFactsAsMarkdown(facts) {
|
|
164
208
|
const lines = [];
|
|
165
|
-
lines.push('##
|
|
209
|
+
lines.push('## Session Facts');
|
|
166
210
|
lines.push('');
|
|
167
|
-
|
|
168
|
-
lines.push(`**
|
|
211
|
+
lines.push(`**Results:** ${facts.total} — ${facts.extracted} with an extracted body, ${facts.unextracted} without`);
|
|
212
|
+
lines.push(`**Sources:** ${facts.sources}`);
|
|
213
|
+
if (facts.sourceList.length)
|
|
214
|
+
lines.push(`**Source list:** ${facts.sourceList.join(' · ')}`);
|
|
169
215
|
lines.push('');
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
lines.push('| Indicator | Value | Threshold | Pass |');
|
|
173
|
-
lines.push('|-----------|-------|-----------|------|');
|
|
174
|
-
const indicators = ['contentDepth', 'sourceDiversity', 'novelty'];
|
|
175
|
-
const labels = {
|
|
176
|
-
contentDepth: 'Content Depth',
|
|
177
|
-
sourceDiversity: 'Source Diversity',
|
|
178
|
-
novelty: 'Novelty',
|
|
179
|
-
};
|
|
180
|
-
for (const key of indicators) {
|
|
181
|
-
const ind = breakdown[key];
|
|
182
|
-
if (ind) {
|
|
183
|
-
const valueStr = key === 'novelty' ? ind.value.toFixed(2) : String(Math.round(ind.value * 100) / 100);
|
|
184
|
-
const thStr = key === 'novelty' ? ind.threshold.toFixed(2) : String(ind.threshold);
|
|
185
|
-
lines.push(`| ${labels[key] || key} | ${valueStr} | ${thStr} | ${ind.pass ? '✓' : '✗'} |`);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
216
|
+
if (facts.pending.length) {
|
|
217
|
+
lines.push(`**Awaiting approval:** ${facts.pending.length}`);
|
|
188
218
|
lines.push('');
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
219
|
+
lines.push('| # | Source | Body | Verified | Round | Title |');
|
|
220
|
+
lines.push('|---|--------|------|----------|-------|-------|');
|
|
221
|
+
facts.pending.forEach((fact, index) => {
|
|
222
|
+
lines.push(`| ${index} | ${fact.domain || '-'} | ${fact.contentLength} | ${fact.verified ? '✓' : '✗'} | ${fact.round ?? '-'} | ${fact.title || fact.url} |`);
|
|
223
|
+
});
|
|
192
224
|
lines.push('');
|
|
193
225
|
}
|
|
194
226
|
return lines.join('\n');
|
|
@@ -227,13 +259,6 @@ function formatSuggestAsMarkdown(data) {
|
|
|
227
259
|
}
|
|
228
260
|
lines.push('');
|
|
229
261
|
}
|
|
230
|
-
if (data.qualityLastRound) {
|
|
231
|
-
lines.push(`**Last Round Quality:** ${data.qualityLastRound.verdict}`);
|
|
232
|
-
if (data.qualityLastRound.failedIndicators?.length) {
|
|
233
|
-
lines.push(` (failed: ${data.qualityLastRound.failedIndicators.join(', ')})`);
|
|
234
|
-
}
|
|
235
|
-
lines.push('');
|
|
236
|
-
}
|
|
237
262
|
return lines.join('\n');
|
|
238
263
|
}
|
|
239
264
|
function formatStrategyAsMarkdown(data) {
|
|
@@ -253,67 +278,19 @@ function formatStrategyAsMarkdown(data) {
|
|
|
253
278
|
lines.push('');
|
|
254
279
|
return lines.join('\n');
|
|
255
280
|
}
|
|
256
|
-
function formatRecoveryAsMarkdown(data) {
|
|
257
|
-
const lines = [];
|
|
258
|
-
lines.push('## Recovery Analysis');
|
|
259
|
-
lines.push('');
|
|
260
|
-
const verdictEmoji = { good: '✓', acceptable: '△', poor: '✗' };
|
|
261
|
-
lines.push(`**Quality:** ${data.qualityScore.verdict.toUpperCase()} ${verdictEmoji[data.qualityScore.verdict] || ''}`);
|
|
262
|
-
lines.push(`**Consecutive Failures:** ${data.recentFailures}`);
|
|
263
|
-
lines.push('');
|
|
264
|
-
if (data.lastSuccessfulRound) {
|
|
265
|
-
lines.push(`**Last Successful Round:** Round ${data.lastSuccessfulRound.round} — "${data.lastSuccessfulRound.query}"`);
|
|
266
|
-
lines.push('');
|
|
267
|
-
}
|
|
268
|
-
if (data.availableStrategies.length > 0) {
|
|
269
|
-
lines.push('### Available Strategies');
|
|
270
|
-
lines.push('');
|
|
271
|
-
for (const s of data.availableStrategies) {
|
|
272
|
-
lines.push(`**${s.strategy}**`);
|
|
273
|
-
lines.push(`- Reason: ${s.reason}`);
|
|
274
|
-
lines.push(`- Suggestion: ${s.suggestion}`);
|
|
275
|
-
if (s.backtrackTo) {
|
|
276
|
-
lines.push(`- Backtrack to: Round ${s.backtrackTo.round} — "${s.backtrackTo.query}"`);
|
|
277
|
-
}
|
|
278
|
-
lines.push('');
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (data.roundQualityHistory.length > 0) {
|
|
282
|
-
lines.push('### Quality History');
|
|
283
|
-
lines.push('');
|
|
284
|
-
lines.push('| Round | Query | Verdict | Failed |');
|
|
285
|
-
lines.push('|-------|-------|---------|--------|');
|
|
286
|
-
for (const r of data.roundQualityHistory) {
|
|
287
|
-
lines.push(`| ${r.round} | ${r.query} | ${r.verdict} | ${r.failedIndicators.join(', ') || '-'} |`);
|
|
288
|
-
}
|
|
289
|
-
lines.push('');
|
|
290
|
-
}
|
|
291
|
-
return lines.join('\n');
|
|
292
|
-
}
|
|
293
281
|
function formatSessionReportAsMarkdown(data) {
|
|
294
282
|
const lines = [];
|
|
295
283
|
lines.push('## Session Report');
|
|
296
284
|
lines.push('');
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
285
|
+
// What the session has gathered. The per-round view lives in `dg coverage`
|
|
286
|
+
// and the pending list in `dg --quality`; repeating them here would make
|
|
287
|
+
// three places to keep in step.
|
|
288
|
+
const p = data.pending;
|
|
289
|
+
lines.push(`### Gathered: ${p.total} results from ${p.sources} sources`);
|
|
290
|
+
lines.push(`- With an extracted body: ${p.extracted}`);
|
|
291
|
+
lines.push(`- Awaiting extraction: ${p.unextracted}`);
|
|
292
|
+
lines.push(`- Awaiting approval: ${p.pending.length}`);
|
|
301
293
|
lines.push('');
|
|
302
|
-
if (q.breakdown) {
|
|
303
|
-
const indicators = ['contentDepth', 'entityRichness', 'sourceDiversity', 'novelty'];
|
|
304
|
-
const labels = {
|
|
305
|
-
contentDepth: 'Content Depth',
|
|
306
|
-
entityRichness: 'Entity Richness', sourceDiversity: 'Source Diversity', novelty: 'Novelty',
|
|
307
|
-
};
|
|
308
|
-
for (const key of indicators) {
|
|
309
|
-
const ind = q.breakdown[key];
|
|
310
|
-
if (ind) {
|
|
311
|
-
const valueStr = key === 'novelty' ? ind.value.toFixed(2) : String(Math.round(ind.value * 100) / 100);
|
|
312
|
-
lines.push(`- ${labels[key]}: ${valueStr} (threshold: ${ind.threshold}) ${ind.pass ? '✓' : '✗'}`);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
lines.push('');
|
|
316
|
-
}
|
|
317
294
|
// Strategy
|
|
318
295
|
const s = data.strategy;
|
|
319
296
|
lines.push(`### Strategy: ${s.currentStage}`);
|
|
@@ -333,11 +310,8 @@ function formatSessionReportAsMarkdown(data) {
|
|
|
333
310
|
}
|
|
334
311
|
lines.push('');
|
|
335
312
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
lines.push(`> Recovery: ${data.recovery.availableStrategies.length} strategies available. Use \`dg recovery-analysis <session>\` for details.`);
|
|
339
|
-
lines.push('');
|
|
340
|
-
}
|
|
313
|
+
lines.push('For what each round looked at, run `dg coverage <session>`.');
|
|
314
|
+
lines.push('');
|
|
341
315
|
return lines.join('\n');
|
|
342
316
|
}
|
|
343
317
|
/** Load query strings from session graph history. */
|
|
@@ -394,26 +368,32 @@ async function searchOneQuery(service, plan, searchOptions, limit) {
|
|
|
394
368
|
}
|
|
395
369
|
return { providerResponses, sxngResponse };
|
|
396
370
|
}
|
|
397
|
-
/** Merge provider and SearXNG responses into the single response shape callers expect. */
|
|
398
|
-
function mergeResponses(providerResponses, sxngResponse) {
|
|
399
|
-
if (providerResponses.length === 0 && sxngResponse)
|
|
400
|
-
return sxngResponse;
|
|
401
|
-
if (providerResponses.length === 1 && !sxngResponse)
|
|
402
|
-
return providerResponses[0];
|
|
403
|
-
// SearXNG's envelope carries the query suggestions and answers, so it is the
|
|
404
|
-
// base whenever it ran; provider-only searches fall back to the first provider.
|
|
405
|
-
const all = sxngResponse ? [...providerResponses, sxngResponse] : providerResponses;
|
|
406
|
-
const base = sxngResponse ?? providerResponses[0];
|
|
407
|
-
return {
|
|
408
|
-
...base,
|
|
409
|
-
results: all.flatMap(r => r.results),
|
|
410
|
-
numberOfResults: all.reduce((sum, r) => sum + r.numberOfResults, 0),
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
371
|
/** Attribute a result to the tool that produced it, for session origin records. */
|
|
414
372
|
function originTool(engine) {
|
|
415
373
|
return EXTERNAL_PROVIDERS.includes(engine) ? engine : 'digdig';
|
|
416
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* Resolve `--format` for a subcommand.
|
|
377
|
+
*
|
|
378
|
+
* The root program declares `-f, --format` too, and Commander assigns a flag to
|
|
379
|
+
* the program it appears *after* — but a subcommand's own `opts.format` then
|
|
380
|
+
* arrives as `undefined`, while the parent reports its default (`md`). Neither
|
|
381
|
+
* `opts` nor `command.rawArgs` (empty for a nested command) can answer, so the
|
|
382
|
+
* argv handed to `runCli` is carried through `createProgram` and read here.
|
|
383
|
+
*/
|
|
384
|
+
function subcommandFormat(argv, command, fallback) {
|
|
385
|
+
const start = argv.indexOf(command);
|
|
386
|
+
if (start === -1)
|
|
387
|
+
return fallback;
|
|
388
|
+
for (let i = start + 1; i < argv.length; i++) {
|
|
389
|
+
const arg = argv[i];
|
|
390
|
+
if (arg === '--format' || arg === '-f')
|
|
391
|
+
return argv[i + 1];
|
|
392
|
+
if (arg.startsWith('--format='))
|
|
393
|
+
return arg.slice('--format='.length);
|
|
394
|
+
}
|
|
395
|
+
return fallback;
|
|
396
|
+
}
|
|
417
397
|
async function runSearch(service, options) {
|
|
418
398
|
const queries = options.queries || (options.query ? [options.query] : []);
|
|
419
399
|
if (queries.length === 0) {
|
|
@@ -490,7 +470,7 @@ async function runSearch(service, options) {
|
|
|
490
470
|
if (stats.entities >= 3) {
|
|
491
471
|
// Graph has matured → deep graph-based advice
|
|
492
472
|
const sessionResults = loadSessionResults(options.session);
|
|
493
|
-
const analysis = getSessionAnalysis(graph, sessionResults);
|
|
473
|
+
const analysis = getSessionAnalysis(graph, sessionResults, getPendingResults(options.session));
|
|
494
474
|
const topLabels = analysis.suggestions.topEntities
|
|
495
475
|
.slice(0, 3)
|
|
496
476
|
.map(e => e.label);
|
|
@@ -545,85 +525,31 @@ async function runSearch(service, options) {
|
|
|
545
525
|
queries.push(...adjustedQueries);
|
|
546
526
|
}
|
|
547
527
|
try {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const plan = planProviderSearch(searchOptions.engines ?? []);
|
|
559
|
-
const { providerResponses, sxngResponse } = await searchOneQuery(service, plan, searchOptions, limit);
|
|
560
|
-
const results = mergeResponses(providerResponses, sxngResponse);
|
|
561
|
-
let sessionInfo = null;
|
|
562
|
-
if (options.session) {
|
|
563
|
-
sessionInfo = appendSessionResults(options.session, results.results.map(result => ({
|
|
564
|
-
...result,
|
|
565
|
-
origins: [{ tool: originTool(result.engine), engine: result.engine, query: queries[0] }],
|
|
566
|
-
})));
|
|
567
|
-
injectApprovedResults(options.session, sessionInfo.approvedResults);
|
|
568
|
-
// Check pending count and warn if >= 30
|
|
569
|
-
const pendingCount = countPendingResults(options.session);
|
|
570
|
-
if (pendingCount >= 30) {
|
|
571
|
-
console.error(`[session] ${pendingCount} pending results awaiting Agent quality assessment. Run --quality to evaluate.`);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
const outputFormat = (options.format || config.defaultFormat);
|
|
575
|
-
let displayResults = results.results;
|
|
576
|
-
if (options.session) {
|
|
577
|
-
const allSessionResults = loadSessionResults(options.session);
|
|
578
|
-
const rankings = [
|
|
579
|
-
results.results.map(r => ({ ...r, id: resultUrlKey(r) })),
|
|
580
|
-
allSessionResults.map(r => ({ ...r, id: resultUrlKey(r) })),
|
|
581
|
-
];
|
|
582
|
-
const fused = rrf(rankings);
|
|
583
|
-
const urlMap = new Map();
|
|
584
|
-
for (const r of allSessionResults)
|
|
585
|
-
urlMap.set(resultUrlKey(r), r);
|
|
586
|
-
// Keep current search content when it overlaps with older session data.
|
|
587
|
-
for (const r of results.results)
|
|
588
|
-
urlMap.set(resultUrlKey(r), r);
|
|
589
|
-
displayResults = fused
|
|
590
|
-
.map(item => {
|
|
591
|
-
const original = urlMap.get(item.id);
|
|
592
|
-
return original ? { ...original, fusionScore: item.score } : null;
|
|
593
|
-
})
|
|
594
|
-
.filter(Boolean);
|
|
595
|
-
if (limit > 0)
|
|
596
|
-
displayResults = displayResults.slice(0, limit);
|
|
597
|
-
}
|
|
598
|
-
const displayData = {
|
|
599
|
-
query: results.query,
|
|
600
|
-
totalResults: results.numberOfResults,
|
|
601
|
-
results: displayResults,
|
|
602
|
-
answers: results.answers,
|
|
603
|
-
suggestions: results.suggestions,
|
|
604
|
-
unresponsiveEngines: results.unresponsiveEngines,
|
|
605
|
-
...(sessionInfo ? { session: { dir: options.session, added: sessionInfo.added, total: sessionInfo.total } } : {}),
|
|
606
|
-
};
|
|
607
|
-
if (outputFormat === 'md') {
|
|
608
|
-
console.log(formatOutput(displayData, 'md'));
|
|
528
|
+
// Read the merge file before anything writes, so a bad path cannot leave
|
|
529
|
+
// half a session behind.
|
|
530
|
+
let mergeResults;
|
|
531
|
+
let mergeMeta = {};
|
|
532
|
+
if (options.merge) {
|
|
533
|
+
try {
|
|
534
|
+
const parsed = JSON.parse(readFileSync(options.merge, 'utf-8'));
|
|
535
|
+
const payload = parsed.status === 'ok' && parsed.data ? parsed.data : parsed;
|
|
536
|
+
mergeResults = (payload.results || []);
|
|
537
|
+
mergeMeta = { suggestions: payload.suggestions, answers: payload.answers };
|
|
609
538
|
}
|
|
610
|
-
|
|
611
|
-
console.log(JSON.stringify(
|
|
612
|
-
|
|
613
|
-
returnedResults: displayResults.length,
|
|
614
|
-
}), null, 2));
|
|
539
|
+
catch {
|
|
540
|
+
console.log(JSON.stringify(createErrorEnvelope('MERGE_FILE_FAILED', `Failed to read merge file: ${options.merge}`, { hint: 'Ensure the file exists and contains valid search results JSON' }), null, 2));
|
|
541
|
+
return 1;
|
|
615
542
|
}
|
|
616
|
-
// Results are now managed by session (pending -> approved -> graph)
|
|
617
|
-
// Do NOT auto-inject into graph. Use --quality --approve for Agent-controlled injection.
|
|
618
|
-
return 0;
|
|
619
543
|
}
|
|
620
|
-
|
|
544
|
+
// One invocation, N queries: the only difference from a single query is
|
|
545
|
+
// how many responses land in the array.
|
|
621
546
|
const engines = options.engines ?? [];
|
|
622
547
|
const plan = planProviderSearch(engines);
|
|
548
|
+
const responses = [];
|
|
623
549
|
for (const query of queries) {
|
|
624
550
|
const searchOptions = {
|
|
625
551
|
query,
|
|
626
|
-
engines
|
|
552
|
+
engines,
|
|
627
553
|
categories: options.categories,
|
|
628
554
|
limit,
|
|
629
555
|
page: options.page,
|
|
@@ -631,121 +557,61 @@ async function runSearch(service, options) {
|
|
|
631
557
|
timeRange: options.timeRange,
|
|
632
558
|
};
|
|
633
559
|
const { providerResponses, sxngResponse } = await searchOneQuery(service, plan, searchOptions, limit);
|
|
634
|
-
|
|
560
|
+
responses.push(...providerResponses);
|
|
635
561
|
if (sxngResponse)
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
let rankings = allResponses.map(resp => resp.results.map((r) => ({ id: normalizeUrl(r.url), ...r })));
|
|
639
|
-
let mergeData = null;
|
|
640
|
-
if (options.merge) {
|
|
641
|
-
try {
|
|
642
|
-
const raw = readFileSync(options.merge, 'utf-8');
|
|
643
|
-
mergeData = JSON.parse(raw);
|
|
644
|
-
let mergeResults = mergeData;
|
|
645
|
-
if (mergeData.status === 'ok' && mergeData.data) {
|
|
646
|
-
mergeResults = mergeData.data;
|
|
647
|
-
}
|
|
648
|
-
const historicalResults = (mergeResults.results || []);
|
|
649
|
-
if (historicalResults.length > 0) {
|
|
650
|
-
rankings.push(historicalResults.map((r) => ({ id: normalizeUrl(r.url), ...r })));
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
catch (error) {
|
|
654
|
-
const envelope = createErrorEnvelope('MERGE_FILE_FAILED', `Failed to read merge file: ${options.merge}`, { hint: 'Ensure the file exists and contains valid search results JSON' });
|
|
655
|
-
console.log(JSON.stringify(envelope, null, 2));
|
|
656
|
-
return 1;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
const rrfFused = rrf(rankings);
|
|
660
|
-
const allResults = [];
|
|
661
|
-
const allSuggestions = [];
|
|
662
|
-
const allAnswers = [];
|
|
663
|
-
const allUnresponsive = [];
|
|
664
|
-
for (const resp of allResponses) {
|
|
665
|
-
allResults.push(...resp.results);
|
|
666
|
-
for (const s of resp.suggestions) {
|
|
667
|
-
if (!allSuggestions.includes(s))
|
|
668
|
-
allSuggestions.push(s);
|
|
669
|
-
}
|
|
670
|
-
for (const a of resp.answers) {
|
|
671
|
-
if (!allAnswers.includes(a))
|
|
672
|
-
allAnswers.push(a);
|
|
673
|
-
}
|
|
674
|
-
for (const u of resp.unresponsiveEngines) {
|
|
675
|
-
const name = Array.isArray(u) ? u[0] : u;
|
|
676
|
-
if (!allUnresponsive.includes(name))
|
|
677
|
-
allUnresponsive.push(name);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
if (mergeData) {
|
|
681
|
-
let mergeResults = mergeData;
|
|
682
|
-
if (mergeData.status === 'ok' && mergeData.data) {
|
|
683
|
-
mergeResults = mergeData.data;
|
|
684
|
-
}
|
|
685
|
-
const historical = mergeResults.results || [];
|
|
686
|
-
allResults.push(...historical);
|
|
687
|
-
if (mergeResults.suggestions) {
|
|
688
|
-
for (const s of mergeResults.suggestions) {
|
|
689
|
-
if (!allSuggestions.includes(s))
|
|
690
|
-
allSuggestions.push(s);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
if (mergeResults.answers) {
|
|
694
|
-
for (const a of mergeResults.answers) {
|
|
695
|
-
if (!allAnswers.includes(a))
|
|
696
|
-
allAnswers.push(a);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
const urlMap = new Map();
|
|
701
|
-
for (const r of allResults) {
|
|
702
|
-
const norm = normalizeUrl(r.url);
|
|
703
|
-
if (!urlMap.has(norm))
|
|
704
|
-
urlMap.set(norm, r);
|
|
705
|
-
}
|
|
706
|
-
let fusedResults = rrfFused
|
|
707
|
-
.map((item) => {
|
|
708
|
-
const original = urlMap.get(item.id);
|
|
709
|
-
if (!original)
|
|
710
|
-
return null;
|
|
711
|
-
return { ...original, fusionScore: item.score };
|
|
712
|
-
})
|
|
713
|
-
.filter(Boolean);
|
|
714
|
-
if (limit > 0) {
|
|
715
|
-
fusedResults = fusedResults.slice(0, limit);
|
|
562
|
+
responses.push(sxngResponse);
|
|
716
563
|
}
|
|
564
|
+
// Snapshot before writing: history must not include this invocation's own
|
|
565
|
+
// results, or every current result votes for itself a second time.
|
|
566
|
+
const sessionSnapshot = options.session ? loadSessionResults(options.session) : undefined;
|
|
567
|
+
const fusion = fuseResults({
|
|
568
|
+
responses,
|
|
569
|
+
mergeResults,
|
|
570
|
+
sessionSnapshot,
|
|
571
|
+
onlyCurrent: Boolean(options.session),
|
|
572
|
+
limit,
|
|
573
|
+
toolFor: engine => originTool(engine),
|
|
574
|
+
});
|
|
717
575
|
let sessionInfo = null;
|
|
718
576
|
if (options.session) {
|
|
719
|
-
|
|
720
|
-
for (const response of allResponses) {
|
|
721
|
-
for (const result of response.results) {
|
|
722
|
-
const key = normalizeUrl(result.url);
|
|
723
|
-
const origins = originsByUrl.get(key) || [];
|
|
724
|
-
origins.push({ tool: originTool(result.engine), engine: result.engine, query: response.query });
|
|
725
|
-
originsByUrl.set(key, origins);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
sessionInfo = appendSessionResults(options.session, fusedResults.map(result => ({
|
|
577
|
+
sessionInfo = appendSessionResults(options.session, fusion.display.map((result, index) => ({
|
|
729
578
|
...result,
|
|
730
|
-
|
|
579
|
+
// The fused position, so `rank` and `fusionScore` describe the same
|
|
580
|
+
// order instead of one provider's and one RRF's.
|
|
581
|
+
rank: index + 1,
|
|
582
|
+
origins: fusion.originsByKey.get(resultUrlKey(result)),
|
|
731
583
|
})));
|
|
732
584
|
injectApprovedResults(options.session, sessionInfo.approvedResults);
|
|
733
|
-
// Check pending count and warn if >= 30
|
|
734
585
|
const pendingCount = countPendingResults(options.session);
|
|
735
586
|
if (pendingCount >= 30) {
|
|
736
|
-
console.error(`[session] ${pendingCount} pending results awaiting Agent
|
|
587
|
+
console.error(`[session] ${pendingCount} pending results awaiting Agent review. Run --quality to list them.`);
|
|
737
588
|
}
|
|
738
589
|
}
|
|
739
|
-
const
|
|
590
|
+
const meta = mergeEnvelopeMetadata(responses, null);
|
|
591
|
+
for (const suggestion of mergeMeta.suggestions ?? []) {
|
|
592
|
+
if (!meta.suggestions.includes(suggestion))
|
|
593
|
+
meta.suggestions.push(suggestion);
|
|
594
|
+
}
|
|
595
|
+
for (const answer of mergeMeta.answers ?? []) {
|
|
596
|
+
if (!meta.answers.includes(answer))
|
|
597
|
+
meta.answers.push(answer);
|
|
598
|
+
}
|
|
740
599
|
const outputFormat = (options.format || config.defaultFormat);
|
|
741
600
|
const displayData = {
|
|
742
|
-
query:
|
|
601
|
+
query: queries.length > 1 ? queries.join(' · ') : queries[0],
|
|
743
602
|
queries,
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
603
|
+
// The deduplicated candidate pool, not a sum of provider self-reports
|
|
604
|
+
// and not the pre-dedup array length.
|
|
605
|
+
totalResults: fusion.fused.length,
|
|
606
|
+
results: fusion.display,
|
|
607
|
+
answers: meta.answers,
|
|
608
|
+
suggestions: meta.suggestions,
|
|
609
|
+
unresponsiveEngines: meta.unresponsiveEngines,
|
|
610
|
+
// Carried so the display layer can say the filter's reach is
|
|
611
|
+
// unconfirmed. Not part of the result ranking — it describes the
|
|
612
|
+
// request, not any individual result.
|
|
613
|
+
...(options.timeRange ? { timeRange: options.timeRange } : {}),
|
|
614
|
+
...(options.language ? { language: options.language } : {}),
|
|
749
615
|
...(sessionInfo ? { session: { dir: options.session, added: sessionInfo.added, total: sessionInfo.total } } : {}),
|
|
750
616
|
};
|
|
751
617
|
if (outputFormat === 'md') {
|
|
@@ -754,7 +620,7 @@ async function runSearch(service, options) {
|
|
|
754
620
|
else if (outputFormat === 'json') {
|
|
755
621
|
console.log(JSON.stringify(createSuccessEnvelope({
|
|
756
622
|
...displayData,
|
|
757
|
-
returnedResults:
|
|
623
|
+
returnedResults: fusion.display.length,
|
|
758
624
|
}), null, 2));
|
|
759
625
|
}
|
|
760
626
|
else {
|
|
@@ -765,15 +631,26 @@ async function runSearch(service, options) {
|
|
|
765
631
|
return 0;
|
|
766
632
|
}
|
|
767
633
|
catch (error) {
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
634
|
+
// `retryable` and the hint come from the error, not from this block.
|
|
635
|
+
// They used to be the literals `true` and a SearXNG hint, which meant a
|
|
636
|
+
// DeepSeek 401 was reported as retryable and blamed on a server the
|
|
637
|
+
// request never touched. An unclassified error now reports neither:
|
|
638
|
+
// calling it retryable is a claim this catch cannot support.
|
|
639
|
+
if (error instanceof SearchError) {
|
|
640
|
+
const envelope = createErrorEnvelope(error.code, error.message, {
|
|
641
|
+
retryable: error.retryable,
|
|
642
|
+
hint: error.hint,
|
|
643
|
+
details: { provider: error.provider, ...(error.status === undefined ? {} : { status: error.status }) },
|
|
644
|
+
});
|
|
645
|
+
console.log(JSON.stringify(envelope, null, 2));
|
|
646
|
+
return 1;
|
|
647
|
+
}
|
|
648
|
+
const envelope = createErrorEnvelope('SEARCH_FAILED', error instanceof Error ? error.message : 'Search request failed');
|
|
772
649
|
console.log(JSON.stringify(envelope, null, 2));
|
|
773
650
|
return 1;
|
|
774
651
|
}
|
|
775
652
|
}
|
|
776
|
-
export function createProgram() {
|
|
653
|
+
export function createProgram(argv = []) {
|
|
777
654
|
const program = new Command();
|
|
778
655
|
program
|
|
779
656
|
.name('dg')
|
|
@@ -794,8 +671,7 @@ export function createProgram() {
|
|
|
794
671
|
.option('--desc <text>', 'Session description (stored in meta.json)')
|
|
795
672
|
.option('--graph <file>', 'Save search result metadata to knowledge graph file')
|
|
796
673
|
.option('--redundancy <action>', 'Query redundancy check: warn | adjust | skip')
|
|
797
|
-
.option('--quality', '
|
|
798
|
-
.option('--threshold-override <json>', 'Override quality thresholds (JSON, e.g. \'{"contentDepth":100}\')')
|
|
674
|
+
.option('--quality', 'List pending results with what the session has gathered, as counted facts')
|
|
799
675
|
.option('--approve-file <path>', 'UTF-8 approval JSON array under this session agent-inputs directory')
|
|
800
676
|
.option('--skip-file <path>', 'UTF-8 skip JSON array under this session agent-inputs directory')
|
|
801
677
|
.option('--unskip-file <path>', 'UTF-8 restore JSON array under this session agent-inputs directory')
|
|
@@ -808,7 +684,7 @@ export function createProgram() {
|
|
|
808
684
|
.description('Interactive configuration setup')
|
|
809
685
|
.action(async () => {
|
|
810
686
|
const code = await initConfig();
|
|
811
|
-
process.
|
|
687
|
+
process.exitCode = code;
|
|
812
688
|
});
|
|
813
689
|
program
|
|
814
690
|
.command('extract')
|
|
@@ -833,7 +709,7 @@ export function createProgram() {
|
|
|
833
709
|
jina: opts.jina ?? false,
|
|
834
710
|
};
|
|
835
711
|
const code = await runExtract(extractor, extractOptions);
|
|
836
|
-
process.
|
|
712
|
+
process.exitCode = code;
|
|
837
713
|
});
|
|
838
714
|
program
|
|
839
715
|
.command('query-graph')
|
|
@@ -853,7 +729,7 @@ export function createProgram() {
|
|
|
853
729
|
format: graphFormat,
|
|
854
730
|
strategy: opts.strategy,
|
|
855
731
|
});
|
|
856
|
-
process.
|
|
732
|
+
process.exitCode = code;
|
|
857
733
|
});
|
|
858
734
|
program
|
|
859
735
|
.command('graph-add')
|
|
@@ -865,7 +741,7 @@ export function createProgram() {
|
|
|
865
741
|
session,
|
|
866
742
|
dataFile: opts.dataFile,
|
|
867
743
|
});
|
|
868
|
-
process.
|
|
744
|
+
process.exitCode = code;
|
|
869
745
|
});
|
|
870
746
|
program
|
|
871
747
|
.command('results-add')
|
|
@@ -888,7 +764,7 @@ Search imports await extraction; extracted imports await approval.`)
|
|
|
888
764
|
query: opts.query,
|
|
889
765
|
tool: opts.tool,
|
|
890
766
|
});
|
|
891
|
-
process.
|
|
767
|
+
process.exitCode = code;
|
|
892
768
|
});
|
|
893
769
|
program
|
|
894
770
|
.command('doc-index')
|
|
@@ -904,7 +780,7 @@ Examples:
|
|
|
904
780
|
path,
|
|
905
781
|
extensions: opts.type?.split(',').map((e) => e.trim()).filter(Boolean),
|
|
906
782
|
});
|
|
907
|
-
process.
|
|
783
|
+
process.exitCode = code;
|
|
908
784
|
});
|
|
909
785
|
program
|
|
910
786
|
.command('doc-search')
|
|
@@ -926,14 +802,14 @@ Examples:
|
|
|
926
802
|
topK: opts.top,
|
|
927
803
|
boost: opts.boost,
|
|
928
804
|
});
|
|
929
|
-
process.
|
|
805
|
+
process.exitCode = code;
|
|
930
806
|
});
|
|
931
807
|
program
|
|
932
808
|
.command('session-list')
|
|
933
809
|
.description('List all sessions')
|
|
934
810
|
.action(async () => {
|
|
935
811
|
const code = await runSessionList();
|
|
936
|
-
process.
|
|
812
|
+
process.exitCode = code;
|
|
937
813
|
});
|
|
938
814
|
program
|
|
939
815
|
.command('session-delete')
|
|
@@ -942,7 +818,7 @@ Examples:
|
|
|
942
818
|
.action(async (names, opts) => {
|
|
943
819
|
const nameList = (names || '').split(',').map((n) => n.trim()).filter(Boolean);
|
|
944
820
|
const code = await runSessionDelete(nameList, opts.older);
|
|
945
|
-
process.
|
|
821
|
+
process.exitCode = code;
|
|
946
822
|
});
|
|
947
823
|
program
|
|
948
824
|
.command('graph-obfuscate')
|
|
@@ -968,7 +844,7 @@ and write them back via graph-add.`)
|
|
|
968
844
|
format: opts.format === 'md' ? 'md' : 'json',
|
|
969
845
|
skipEntityTypes: opts.skipTypes?.split(',').map((t) => t.trim()).filter(Boolean),
|
|
970
846
|
});
|
|
971
|
-
process.
|
|
847
|
+
process.exitCode = code;
|
|
972
848
|
});
|
|
973
849
|
program
|
|
974
850
|
.command('graph-preprocess')
|
|
@@ -995,7 +871,26 @@ Examples:
|
|
|
995
871
|
else {
|
|
996
872
|
console.log(JSON.stringify(createSuccessEnvelope(result), null, 2));
|
|
997
873
|
}
|
|
998
|
-
process.
|
|
874
|
+
process.exitCode = 0;
|
|
875
|
+
});
|
|
876
|
+
program
|
|
877
|
+
.command('coverage')
|
|
878
|
+
.argument('<session>', 'Session directory or name')
|
|
879
|
+
.description('Report what the session has looked at, as counted facts (rounds, queries, repetition, distinctive terms)')
|
|
880
|
+
.option('-f, --format <fmt>', 'Output format: json (default), md')
|
|
881
|
+
.addHelpText('after', `
|
|
882
|
+
Reports what has been searched and what came back, without deciding what it means.
|
|
883
|
+
Reads results.json only, so it works before any result has been approved.
|
|
884
|
+
|
|
885
|
+
Examples:
|
|
886
|
+
dg coverage my-session
|
|
887
|
+
dg coverage my-session --format md`)
|
|
888
|
+
.action(async (session, opts, command) => {
|
|
889
|
+
const code = await runCoverage({
|
|
890
|
+
session,
|
|
891
|
+
format: subcommandFormat(argv, command.name(), opts.format) === 'md' ? 'md' : 'json',
|
|
892
|
+
});
|
|
893
|
+
process.exitCode = code;
|
|
999
894
|
});
|
|
1000
895
|
program
|
|
1001
896
|
.command('suggest-queries')
|
|
@@ -1011,15 +906,14 @@ Examples:
|
|
|
1011
906
|
const graph = loadSessionGraph(sessionDir);
|
|
1012
907
|
const results = loadSessionResults(sessionDir);
|
|
1013
908
|
const stage = determineSearchStage(graph);
|
|
1014
|
-
const
|
|
1015
|
-
const data = generateQuerySuggestions(graph, results, stage, quality);
|
|
909
|
+
const data = generateQuerySuggestions(graph, results, stage);
|
|
1016
910
|
if (opts.format === 'md') {
|
|
1017
911
|
console.log(formatSuggestAsMarkdown(data));
|
|
1018
912
|
}
|
|
1019
913
|
else {
|
|
1020
914
|
console.log(JSON.stringify(createSuccessEnvelope(data), null, 2));
|
|
1021
915
|
}
|
|
1022
|
-
process.
|
|
916
|
+
process.exitCode = 0;
|
|
1023
917
|
});
|
|
1024
918
|
program
|
|
1025
919
|
.command('strategy-info')
|
|
@@ -1045,35 +939,12 @@ Examples:
|
|
|
1045
939
|
else {
|
|
1046
940
|
console.log(JSON.stringify(createSuccessEnvelope(info), null, 2));
|
|
1047
941
|
}
|
|
1048
|
-
process.
|
|
1049
|
-
});
|
|
1050
|
-
program
|
|
1051
|
-
.command('recovery-analysis')
|
|
1052
|
-
.argument('<session>', 'Session directory or name')
|
|
1053
|
-
.description('Output recovery strategy analysis for Agent decision-making')
|
|
1054
|
-
.option('-f, --format <fmt>', 'Output format: json (default), md')
|
|
1055
|
-
.addHelpText('after', `
|
|
1056
|
-
Examples:
|
|
1057
|
-
dg recovery-analysis my-session
|
|
1058
|
-
dg recovery-analysis my-session --format md`)
|
|
1059
|
-
.action(async (session, opts) => {
|
|
1060
|
-
const sessionDir = resolveSessionPath(session);
|
|
1061
|
-
const graph = loadSessionGraph(sessionDir);
|
|
1062
|
-
const results = loadSessionResults(sessionDir);
|
|
1063
|
-
const quality = assessLatestResultQuality(results);
|
|
1064
|
-
const analysis = analyzeRecoveryOptions(graph, results, quality);
|
|
1065
|
-
if (opts.format === 'md') {
|
|
1066
|
-
console.log(formatRecoveryAsMarkdown(analysis));
|
|
1067
|
-
}
|
|
1068
|
-
else {
|
|
1069
|
-
console.log(JSON.stringify(createSuccessEnvelope(analysis), null, 2));
|
|
1070
|
-
}
|
|
1071
|
-
process.exit(0);
|
|
942
|
+
process.exitCode = 0;
|
|
1072
943
|
});
|
|
1073
944
|
program
|
|
1074
945
|
.command('session-report')
|
|
1075
946
|
.argument('<session>', 'Session directory or name')
|
|
1076
|
-
.description('Show session
|
|
947
|
+
.description('Show what the session has gathered and how far the search has moved')
|
|
1077
948
|
.option('-f, --format <fmt>', 'Output format: json (default), md')
|
|
1078
949
|
.addHelpText('after', `
|
|
1079
950
|
Examples:
|
|
@@ -1083,14 +954,14 @@ Examples:
|
|
|
1083
954
|
const sessionDir = resolveSessionPath(session);
|
|
1084
955
|
const graph = loadSessionGraph(sessionDir);
|
|
1085
956
|
const results = loadSessionResults(sessionDir);
|
|
1086
|
-
const analysis = getSessionAnalysis(graph, results);
|
|
957
|
+
const analysis = getSessionAnalysis(graph, results, getPendingResults(sessionDir));
|
|
1087
958
|
if (opts.format === 'md') {
|
|
1088
959
|
console.log(formatSessionReportAsMarkdown(analysis));
|
|
1089
960
|
}
|
|
1090
961
|
else {
|
|
1091
962
|
console.log(JSON.stringify(createSuccessEnvelope(analysis), null, 2));
|
|
1092
963
|
}
|
|
1093
|
-
process.
|
|
964
|
+
process.exitCode = 0;
|
|
1094
965
|
});
|
|
1095
966
|
program
|
|
1096
967
|
.command('graph-explore')
|
|
@@ -1110,7 +981,7 @@ See also: graph-drill, graph-search`)
|
|
|
1110
981
|
seed: opts.seed,
|
|
1111
982
|
format: opts.format === 'json' ? 'json' : 'md',
|
|
1112
983
|
});
|
|
1113
|
-
process.
|
|
984
|
+
process.exitCode = code;
|
|
1114
985
|
});
|
|
1115
986
|
program
|
|
1116
987
|
.command('graph-drill')
|
|
@@ -1132,7 +1003,7 @@ See also: graph-explore`)
|
|
|
1132
1003
|
relations: opts.relations.split(',').map((r) => r.trim()).filter(Boolean),
|
|
1133
1004
|
format: opts.format === 'json' ? 'json' : 'md',
|
|
1134
1005
|
});
|
|
1135
|
-
process.
|
|
1006
|
+
process.exitCode = code;
|
|
1136
1007
|
});
|
|
1137
1008
|
program
|
|
1138
1009
|
.command('graph-traverse')
|
|
@@ -1153,7 +1024,7 @@ the command will list available path node IDs.`)
|
|
|
1153
1024
|
pathId: opts.path,
|
|
1154
1025
|
format: opts.format === 'json' ? 'json' : 'md',
|
|
1155
1026
|
});
|
|
1156
|
-
process.
|
|
1027
|
+
process.exitCode = code;
|
|
1157
1028
|
});
|
|
1158
1029
|
program
|
|
1159
1030
|
.command('graph-search')
|
|
@@ -1175,7 +1046,7 @@ See also: graph-explore (for viewing relations of a known entity)`)
|
|
|
1175
1046
|
limit: opts.limit,
|
|
1176
1047
|
format: opts.format === 'json' ? 'json' : 'md',
|
|
1177
1048
|
});
|
|
1178
|
-
process.
|
|
1049
|
+
process.exitCode = code;
|
|
1179
1050
|
});
|
|
1180
1051
|
// ── Claim commands ──────────────────────────────────────────
|
|
1181
1052
|
program
|
|
@@ -1195,7 +1066,7 @@ Examples:
|
|
|
1195
1066
|
claimsFile: opts.claimsFile,
|
|
1196
1067
|
format: opts.format,
|
|
1197
1068
|
});
|
|
1198
|
-
process.
|
|
1069
|
+
process.exitCode = code;
|
|
1199
1070
|
});
|
|
1200
1071
|
program
|
|
1201
1072
|
.command('claim-list')
|
|
@@ -1208,7 +1079,7 @@ Examples:
|
|
|
1208
1079
|
status: opts.status,
|
|
1209
1080
|
format: opts.format,
|
|
1210
1081
|
});
|
|
1211
|
-
process.
|
|
1082
|
+
process.exitCode = code;
|
|
1212
1083
|
});
|
|
1213
1084
|
program
|
|
1214
1085
|
.command('evidence-search')
|
|
@@ -1221,7 +1092,7 @@ Examples:
|
|
|
1221
1092
|
claimId: opts.claimId,
|
|
1222
1093
|
format: opts.format,
|
|
1223
1094
|
});
|
|
1224
|
-
process.
|
|
1095
|
+
process.exitCode = code;
|
|
1225
1096
|
});
|
|
1226
1097
|
program
|
|
1227
1098
|
.command('evidence-verify')
|
|
@@ -1244,7 +1115,7 @@ Examples:
|
|
|
1244
1115
|
complete: opts.complete ?? false,
|
|
1245
1116
|
format: opts.format,
|
|
1246
1117
|
});
|
|
1247
|
-
process.
|
|
1118
|
+
process.exitCode = code;
|
|
1248
1119
|
});
|
|
1249
1120
|
program
|
|
1250
1121
|
.command('evidence-list')
|
|
@@ -1257,7 +1128,7 @@ Examples:
|
|
|
1257
1128
|
claimId: opts.claimId,
|
|
1258
1129
|
format: opts.format,
|
|
1259
1130
|
});
|
|
1260
|
-
process.
|
|
1131
|
+
process.exitCode = code;
|
|
1261
1132
|
});
|
|
1262
1133
|
program
|
|
1263
1134
|
.command('verdict-list')
|
|
@@ -1270,7 +1141,7 @@ Examples:
|
|
|
1270
1141
|
claimId: opts.claimId,
|
|
1271
1142
|
format: opts.format,
|
|
1272
1143
|
});
|
|
1273
|
-
process.
|
|
1144
|
+
process.exitCode = code;
|
|
1274
1145
|
});
|
|
1275
1146
|
program
|
|
1276
1147
|
.command('policy-aggregate')
|
|
@@ -1283,7 +1154,7 @@ Examples:
|
|
|
1283
1154
|
claimId: opts.claimId,
|
|
1284
1155
|
format: opts.format,
|
|
1285
1156
|
});
|
|
1286
|
-
process.
|
|
1157
|
+
process.exitCode = code;
|
|
1287
1158
|
});
|
|
1288
1159
|
program
|
|
1289
1160
|
.command('review-list')
|
|
@@ -1296,19 +1167,19 @@ Examples:
|
|
|
1296
1167
|
status: opts.status,
|
|
1297
1168
|
format: opts.format,
|
|
1298
1169
|
});
|
|
1299
|
-
process.
|
|
1170
|
+
process.exitCode = code;
|
|
1300
1171
|
});
|
|
1301
1172
|
return program;
|
|
1302
1173
|
}
|
|
1303
1174
|
export async function runCli(args, service) {
|
|
1304
|
-
const program = createProgram();
|
|
1175
|
+
const program = createProgram(args);
|
|
1305
1176
|
// Custom action for default command (search)
|
|
1306
1177
|
// Commander passes the [query] argument as first param, then opts
|
|
1307
1178
|
program.action(async (query, opts) => {
|
|
1308
1179
|
const queryString = query || '';
|
|
1309
1180
|
if (opts.version) {
|
|
1310
1181
|
console.log(program.version());
|
|
1311
|
-
process.
|
|
1182
|
+
process.exitCode = 0;
|
|
1312
1183
|
return;
|
|
1313
1184
|
}
|
|
1314
1185
|
if (opts.health) {
|
|
@@ -1317,14 +1188,14 @@ export async function runCli(args, service) {
|
|
|
1317
1188
|
? createSuccessEnvelope(health)
|
|
1318
1189
|
: createErrorEnvelope('HEALTH_CHECK_FAILED', health.error || 'SearXNG server is not responding', { hint: `Check if SearXNG is running at ${config.baseUrl}` });
|
|
1319
1190
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1320
|
-
process.
|
|
1191
|
+
process.exitCode = health.status === 'healthy' ? 0 : 1;
|
|
1321
1192
|
return;
|
|
1322
1193
|
}
|
|
1323
1194
|
if (opts.quality) {
|
|
1324
1195
|
if (!opts.session) {
|
|
1325
1196
|
const envelope = createErrorEnvelope('QUALITY_NO_SESSION', '--quality requires --session', { hint: 'Use: dg --session <name> --quality' });
|
|
1326
1197
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1327
|
-
process.
|
|
1198
|
+
process.exitCode = 1;
|
|
1328
1199
|
return;
|
|
1329
1200
|
}
|
|
1330
1201
|
const sessionDir = resolveSessionPath(opts.session);
|
|
@@ -1353,45 +1224,21 @@ export async function runCli(args, service) {
|
|
|
1353
1224
|
if (opts.skipFile || opts.unskipFile) {
|
|
1354
1225
|
if (opts.skipFile && opts.unskipFile) {
|
|
1355
1226
|
console.log(JSON.stringify(createErrorEnvelope('MULTIPLE_SKIP_ACTIONS', 'Use only one of --skip-file or --unskip-file'), null, 2));
|
|
1356
|
-
process.
|
|
1227
|
+
process.exitCode = 1;
|
|
1357
1228
|
return;
|
|
1358
1229
|
}
|
|
1359
|
-
process.
|
|
1230
|
+
process.exitCode = applySkip(opts.skipFile ? '--skip-file' : '--unskip-file', opts.skipFile ?? opts.unskipFile, Boolean(opts.skipFile)) ? 0 : 1;
|
|
1360
1231
|
return;
|
|
1361
1232
|
}
|
|
1362
|
-
let thresholdOverride;
|
|
1363
|
-
if (opts.thresholdOverride) {
|
|
1364
|
-
try {
|
|
1365
|
-
thresholdOverride = JSON.parse(opts.thresholdOverride);
|
|
1366
|
-
}
|
|
1367
|
-
catch {
|
|
1368
|
-
const envelope = createErrorEnvelope('INVALID_THRESHOLD_OVERRIDE', '--threshold-override must be valid JSON', { hint: 'Example: \'{"contentDepth":100}\'' });
|
|
1369
|
-
console.log(JSON.stringify(envelope, null, 2));
|
|
1370
|
-
process.exit(1);
|
|
1371
|
-
return;
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
1233
|
// Get pending results for Agent review
|
|
1375
1234
|
const pending = getPendingResults(sessionDir);
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
const quality = assessResultQuality(pending, priorResults, thresholdOverride);
|
|
1380
|
-
const describeResult = (result, index) => ({
|
|
1381
|
-
...(index === undefined ? {} : { index }),
|
|
1382
|
-
id: result.id,
|
|
1383
|
-
revision: result.revision,
|
|
1384
|
-
url: result.url,
|
|
1385
|
-
source: result.source || 'digdig',
|
|
1386
|
-
contentLength: result.content?.length ?? 0,
|
|
1387
|
-
extractedAt: result.extractedAt,
|
|
1388
|
-
verified: hasVerifiedContent(result),
|
|
1389
|
-
});
|
|
1390
|
-
// Approval is allowed only after reporting current quality and verification state.
|
|
1235
|
+
const facts = buildPendingReport(sessionResults, pending);
|
|
1236
|
+
// Approval is allowed only after reporting what is waiting and how
|
|
1237
|
+
// much of it carries a body.
|
|
1391
1238
|
if (opts.approveFile) {
|
|
1392
1239
|
const selections = readSelections('--approve-file', opts.approveFile);
|
|
1393
1240
|
if (!selections) {
|
|
1394
|
-
process.
|
|
1241
|
+
process.exitCode = 1;
|
|
1395
1242
|
return;
|
|
1396
1243
|
}
|
|
1397
1244
|
const selectedResults = selections
|
|
@@ -1401,10 +1248,10 @@ export async function runCli(args, service) {
|
|
|
1401
1248
|
const approval = approveResults(sessionDir, selections);
|
|
1402
1249
|
if (approval.error) {
|
|
1403
1250
|
console.log(JSON.stringify(createErrorEnvelope(approval.error.code, approval.error.message, {
|
|
1404
|
-
details: {
|
|
1251
|
+
details: { facts, selectedResults, error: approval.error },
|
|
1405
1252
|
hint: 'Run dg extract --session <session> for unverified results, then review and approve again.',
|
|
1406
1253
|
}), null, 2));
|
|
1407
|
-
process.
|
|
1254
|
+
process.exitCode = 1;
|
|
1408
1255
|
return;
|
|
1409
1256
|
}
|
|
1410
1257
|
// Inject only the results selected by this approval action.
|
|
@@ -1414,66 +1261,47 @@ export async function runCli(args, service) {
|
|
|
1414
1261
|
total: approval.total,
|
|
1415
1262
|
nodesAdded: injectInfo.nodesAdded,
|
|
1416
1263
|
edgesAdded: injectInfo.edgesAdded,
|
|
1417
|
-
|
|
1264
|
+
facts,
|
|
1418
1265
|
selectedResults,
|
|
1419
1266
|
message: `Approved ${approval.approved} results, injected into graph (+${injectInfo.nodesAdded} nodes, +${injectInfo.edgesAdded} edges)`,
|
|
1420
1267
|
}), null, 2));
|
|
1421
|
-
process.
|
|
1268
|
+
process.exitCode = 0;
|
|
1422
1269
|
return;
|
|
1423
1270
|
}
|
|
1424
1271
|
if (pending.length === 0) {
|
|
1425
|
-
//
|
|
1426
|
-
const quality = assessResultQuality(sessionResults, priorResults, thresholdOverride);
|
|
1272
|
+
// Nothing to approve: the counts still describe the session.
|
|
1427
1273
|
const outputFormat = (opts.format || config.defaultFormat);
|
|
1428
1274
|
if (outputFormat === 'md') {
|
|
1429
|
-
console.log(
|
|
1275
|
+
console.log(formatFactsAsMarkdown(facts));
|
|
1430
1276
|
}
|
|
1431
1277
|
else {
|
|
1432
|
-
console.log(JSON.stringify(createSuccessEnvelope(
|
|
1278
|
+
console.log(JSON.stringify(createSuccessEnvelope(facts), null, 2));
|
|
1433
1279
|
}
|
|
1434
|
-
process.
|
|
1280
|
+
process.exitCode = 0;
|
|
1435
1281
|
return;
|
|
1436
1282
|
}
|
|
1437
1283
|
const outputFormat = (opts.format || config.defaultFormat);
|
|
1438
1284
|
if (outputFormat === 'json') {
|
|
1439
|
-
//
|
|
1285
|
+
// The body under review, alongside the per-result facts. The
|
|
1286
|
+
// preview is deliberately `content` and not the display
|
|
1287
|
+
// fallback: this list exists so the Agent can read the
|
|
1288
|
+
// extracted text before approving it.
|
|
1440
1289
|
console.log(JSON.stringify(createSuccessEnvelope({
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
title: r.title,
|
|
1447
|
-
url: r.url,
|
|
1448
|
-
source: r.source || 'digdig',
|
|
1449
|
-
status: r.status,
|
|
1450
|
-
// The body under review, deliberately not the display fallback:
|
|
1451
|
-
// this list exists so the Agent can read the extracted text
|
|
1452
|
-
// before approving it, and `excerpt` here is the page
|
|
1453
|
-
// description — the wrong text to judge an extraction by.
|
|
1454
|
-
contentPreview: r.content ? r.content.slice(0, 300) : undefined,
|
|
1455
|
-
contentLength: r.content?.length ?? 0,
|
|
1456
|
-
domain: (() => { try {
|
|
1457
|
-
return new URL(r.url).hostname;
|
|
1458
|
-
}
|
|
1459
|
-
catch {
|
|
1460
|
-
return '';
|
|
1461
|
-
} })(),
|
|
1462
|
-
extractedAt: r.extractedAt,
|
|
1463
|
-
verified: hasVerifiedContent(r),
|
|
1290
|
+
...facts,
|
|
1291
|
+
pending: facts.pending.map((fact, index) => ({
|
|
1292
|
+
...fact,
|
|
1293
|
+
index,
|
|
1294
|
+
contentPreview: pending[index].content?.slice(0, 300),
|
|
1464
1295
|
})),
|
|
1465
1296
|
hint: 'Agent reviews content and approves with the id/revision objects returned here.',
|
|
1466
1297
|
}), null, 2));
|
|
1467
1298
|
}
|
|
1468
1299
|
else {
|
|
1469
|
-
console.log(
|
|
1300
|
+
console.log(formatFactsAsMarkdown(facts));
|
|
1470
1301
|
console.log('\n## Pending Results (awaiting Agent approval)\n');
|
|
1471
1302
|
for (let i = 0; i < pending.length; i++) {
|
|
1472
1303
|
const r = pending[i];
|
|
1473
1304
|
console.log(`${i}. [${r.title || 'No Title'}](${r.url}) [${r.source || 'digdig'}]`);
|
|
1474
|
-
// These are extracted results awaiting approval, so the text to
|
|
1475
|
-
// review is `content` — the body that will be cited — and not the
|
|
1476
|
-
// display fallback, which would surface the page description.
|
|
1477
1305
|
if (r.content) {
|
|
1478
1306
|
const preview = r.content.slice(0, 300).replace(/\s+/g, ' ');
|
|
1479
1307
|
console.log(` Preview: ${preview}${r.content.length > 300 ? '...' : ''}`);
|
|
@@ -1481,28 +1309,40 @@ export async function runCli(args, service) {
|
|
|
1481
1309
|
}
|
|
1482
1310
|
console.log('\n**Agent writes ID/revision selections to session agent-inputs, then uses --approve-file.**');
|
|
1483
1311
|
}
|
|
1484
|
-
process.
|
|
1312
|
+
process.exitCode = 0;
|
|
1485
1313
|
return;
|
|
1486
1314
|
}
|
|
1487
1315
|
if (opts.enginesList) {
|
|
1488
1316
|
try {
|
|
1489
|
-
const
|
|
1317
|
+
const serverEngines = await service.getEngines();
|
|
1490
1318
|
const configuredProviders = EXTERNAL_PROVIDERS.filter(p => PROVIDER_IMPLS[p].configured());
|
|
1491
|
-
|
|
1319
|
+
// Both empty is a legitimate-looking but useless answer: nothing
|
|
1320
|
+
// this CLI can search with. Reaching here already means the
|
|
1321
|
+
// server answered (a failed fetch throws), so `serverEngines`
|
|
1322
|
+
// being empty now says exactly one thing — the server has no
|
|
1323
|
+
// enabled engines — and the `&&` reads correctly.
|
|
1324
|
+
if (serverEngines.length === 0 && configuredProviders.length === 0) {
|
|
1492
1325
|
const envelope = createErrorEnvelope('ENGINES_FETCH_EMPTY', 'No engines returned from SearXNG server', { hint: 'Check if SearXNG server is properly configured' });
|
|
1493
1326
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1494
|
-
process.
|
|
1327
|
+
process.exitCode = 1;
|
|
1495
1328
|
return;
|
|
1496
1329
|
}
|
|
1497
|
-
|
|
1498
|
-
|
|
1330
|
+
// `source: 'server'` used to be a literal, so a provider name
|
|
1331
|
+
// configured locally was reported as if the server had returned
|
|
1332
|
+
// it. The breakdown cannot make that claim: each name is listed
|
|
1333
|
+
// under where it actually came from. `engines` stays flat so a
|
|
1334
|
+
// consumer reading the list is unaffected.
|
|
1335
|
+
const envelope = createSuccessEnvelope({
|
|
1336
|
+
engines: [...serverEngines, ...configuredProviders],
|
|
1337
|
+
sources: { server: serverEngines, local: configuredProviders },
|
|
1338
|
+
});
|
|
1499
1339
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1500
|
-
process.
|
|
1340
|
+
process.exitCode = 0;
|
|
1501
1341
|
}
|
|
1502
1342
|
catch (error) {
|
|
1503
|
-
const envelope = createErrorEnvelope('ENGINES_FETCH_FAILED', error instanceof Error ? error.message : 'Failed to fetch engines', { hint:
|
|
1343
|
+
const envelope = createErrorEnvelope('ENGINES_FETCH_FAILED', error instanceof Error ? error.message : 'Failed to fetch engines', { retryable: true, hint: `Could not reach the SearXNG server at ${config.baseUrl}. Check that it is running and that the base URL is correct.` });
|
|
1504
1344
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1505
|
-
process.
|
|
1345
|
+
process.exitCode = 1;
|
|
1506
1346
|
}
|
|
1507
1347
|
return;
|
|
1508
1348
|
}
|
|
@@ -1512,17 +1352,17 @@ export async function runCli(args, service) {
|
|
|
1512
1352
|
if (categories.length === 0) {
|
|
1513
1353
|
const envelope = createErrorEnvelope('CATEGORIES_FETCH_EMPTY', 'No categories returned from SearXNG server', { hint: 'Check if SearXNG server is properly configured' });
|
|
1514
1354
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1515
|
-
process.
|
|
1355
|
+
process.exitCode = 1;
|
|
1516
1356
|
return;
|
|
1517
1357
|
}
|
|
1518
1358
|
const envelope = createSuccessEnvelope({ categories, source: 'server' });
|
|
1519
1359
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1520
|
-
process.
|
|
1360
|
+
process.exitCode = 0;
|
|
1521
1361
|
}
|
|
1522
1362
|
catch (error) {
|
|
1523
1363
|
const envelope = createErrorEnvelope('CATEGORIES_FETCH_FAILED', error instanceof Error ? error.message : 'Failed to fetch categories', { hint: 'Check your network connection and SearXNG server status' });
|
|
1524
1364
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1525
|
-
process.
|
|
1365
|
+
process.exitCode = 1;
|
|
1526
1366
|
}
|
|
1527
1367
|
return;
|
|
1528
1368
|
}
|
|
@@ -1547,7 +1387,7 @@ export async function runCli(args, service) {
|
|
|
1547
1387
|
merge: opts.merge,
|
|
1548
1388
|
redundancy: opts.redundancy,
|
|
1549
1389
|
});
|
|
1550
|
-
process.
|
|
1390
|
+
process.exitCode = code;
|
|
1551
1391
|
});
|
|
1552
1392
|
try {
|
|
1553
1393
|
await program.parseAsync(args, { from: 'user' });
|