digdig 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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 +108 -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 +224 -432
- package/dist/runCli.js.map +1 -1
- package/dist/service.d.ts +10 -0
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +27 -21
- 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';
|
|
@@ -160,35 +161,23 @@ function formatPreprocessAsMarkdown(data) {
|
|
|
160
161
|
}
|
|
161
162
|
return lines.join('\n');
|
|
162
163
|
}
|
|
163
|
-
function
|
|
164
|
+
function formatFactsAsMarkdown(facts) {
|
|
164
165
|
const lines = [];
|
|
165
|
-
lines.push('##
|
|
166
|
+
lines.push('## Session Facts');
|
|
166
167
|
lines.push('');
|
|
167
|
-
|
|
168
|
-
lines.push(`**
|
|
168
|
+
lines.push(`**Results:** ${facts.total} — ${facts.extracted} with an extracted body, ${facts.unextracted} without`);
|
|
169
|
+
lines.push(`**Sources:** ${facts.sources}`);
|
|
170
|
+
if (facts.sourceList.length)
|
|
171
|
+
lines.push(`**Source list:** ${facts.sourceList.join(' · ')}`);
|
|
169
172
|
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
|
-
}
|
|
173
|
+
if (facts.pending.length) {
|
|
174
|
+
lines.push(`**Awaiting approval:** ${facts.pending.length}`);
|
|
188
175
|
lines.push('');
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
176
|
+
lines.push('| # | Source | Body | Verified | Round | Title |');
|
|
177
|
+
lines.push('|---|--------|------|----------|-------|-------|');
|
|
178
|
+
facts.pending.forEach((fact, index) => {
|
|
179
|
+
lines.push(`| ${index} | ${fact.domain || '-'} | ${fact.contentLength} | ${fact.verified ? '✓' : '✗'} | ${fact.round ?? '-'} | ${fact.title || fact.url} |`);
|
|
180
|
+
});
|
|
192
181
|
lines.push('');
|
|
193
182
|
}
|
|
194
183
|
return lines.join('\n');
|
|
@@ -227,13 +216,6 @@ function formatSuggestAsMarkdown(data) {
|
|
|
227
216
|
}
|
|
228
217
|
lines.push('');
|
|
229
218
|
}
|
|
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
219
|
return lines.join('\n');
|
|
238
220
|
}
|
|
239
221
|
function formatStrategyAsMarkdown(data) {
|
|
@@ -253,67 +235,19 @@ function formatStrategyAsMarkdown(data) {
|
|
|
253
235
|
lines.push('');
|
|
254
236
|
return lines.join('\n');
|
|
255
237
|
}
|
|
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
238
|
function formatSessionReportAsMarkdown(data) {
|
|
294
239
|
const lines = [];
|
|
295
240
|
lines.push('## Session Report');
|
|
296
241
|
lines.push('');
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
242
|
+
// What the session has gathered. The per-round view lives in `dg coverage`
|
|
243
|
+
// and the pending list in `dg --quality`; repeating them here would make
|
|
244
|
+
// three places to keep in step.
|
|
245
|
+
const p = data.pending;
|
|
246
|
+
lines.push(`### Gathered: ${p.total} results from ${p.sources} sources`);
|
|
247
|
+
lines.push(`- With an extracted body: ${p.extracted}`);
|
|
248
|
+
lines.push(`- Awaiting extraction: ${p.unextracted}`);
|
|
249
|
+
lines.push(`- Awaiting approval: ${p.pending.length}`);
|
|
301
250
|
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
251
|
// Strategy
|
|
318
252
|
const s = data.strategy;
|
|
319
253
|
lines.push(`### Strategy: ${s.currentStage}`);
|
|
@@ -333,11 +267,8 @@ function formatSessionReportAsMarkdown(data) {
|
|
|
333
267
|
}
|
|
334
268
|
lines.push('');
|
|
335
269
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
lines.push(`> Recovery: ${data.recovery.availableStrategies.length} strategies available. Use \`dg recovery-analysis <session>\` for details.`);
|
|
339
|
-
lines.push('');
|
|
340
|
-
}
|
|
270
|
+
lines.push('For what each round looked at, run `dg coverage <session>`.');
|
|
271
|
+
lines.push('');
|
|
341
272
|
return lines.join('\n');
|
|
342
273
|
}
|
|
343
274
|
/** Load query strings from session graph history. */
|
|
@@ -394,26 +325,32 @@ async function searchOneQuery(service, plan, searchOptions, limit) {
|
|
|
394
325
|
}
|
|
395
326
|
return { providerResponses, sxngResponse };
|
|
396
327
|
}
|
|
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
328
|
/** Attribute a result to the tool that produced it, for session origin records. */
|
|
414
329
|
function originTool(engine) {
|
|
415
330
|
return EXTERNAL_PROVIDERS.includes(engine) ? engine : 'digdig';
|
|
416
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Resolve `--format` for a subcommand.
|
|
334
|
+
*
|
|
335
|
+
* The root program declares `-f, --format` too, and Commander assigns a flag to
|
|
336
|
+
* the program it appears *after* — but a subcommand's own `opts.format` then
|
|
337
|
+
* arrives as `undefined`, while the parent reports its default (`md`). Neither
|
|
338
|
+
* `opts` nor `command.rawArgs` (empty for a nested command) can answer, so the
|
|
339
|
+
* argv handed to `runCli` is carried through `createProgram` and read here.
|
|
340
|
+
*/
|
|
341
|
+
function subcommandFormat(argv, command, fallback) {
|
|
342
|
+
const start = argv.indexOf(command);
|
|
343
|
+
if (start === -1)
|
|
344
|
+
return fallback;
|
|
345
|
+
for (let i = start + 1; i < argv.length; i++) {
|
|
346
|
+
const arg = argv[i];
|
|
347
|
+
if (arg === '--format' || arg === '-f')
|
|
348
|
+
return argv[i + 1];
|
|
349
|
+
if (arg.startsWith('--format='))
|
|
350
|
+
return arg.slice('--format='.length);
|
|
351
|
+
}
|
|
352
|
+
return fallback;
|
|
353
|
+
}
|
|
417
354
|
async function runSearch(service, options) {
|
|
418
355
|
const queries = options.queries || (options.query ? [options.query] : []);
|
|
419
356
|
if (queries.length === 0) {
|
|
@@ -490,7 +427,7 @@ async function runSearch(service, options) {
|
|
|
490
427
|
if (stats.entities >= 3) {
|
|
491
428
|
// Graph has matured → deep graph-based advice
|
|
492
429
|
const sessionResults = loadSessionResults(options.session);
|
|
493
|
-
const analysis = getSessionAnalysis(graph, sessionResults);
|
|
430
|
+
const analysis = getSessionAnalysis(graph, sessionResults, getPendingResults(options.session));
|
|
494
431
|
const topLabels = analysis.suggestions.topEntities
|
|
495
432
|
.slice(0, 3)
|
|
496
433
|
.map(e => e.label);
|
|
@@ -545,85 +482,31 @@ async function runSearch(service, options) {
|
|
|
545
482
|
queries.push(...adjustedQueries);
|
|
546
483
|
}
|
|
547
484
|
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'));
|
|
485
|
+
// Read the merge file before anything writes, so a bad path cannot leave
|
|
486
|
+
// half a session behind.
|
|
487
|
+
let mergeResults;
|
|
488
|
+
let mergeMeta = {};
|
|
489
|
+
if (options.merge) {
|
|
490
|
+
try {
|
|
491
|
+
const parsed = JSON.parse(readFileSync(options.merge, 'utf-8'));
|
|
492
|
+
const payload = parsed.status === 'ok' && parsed.data ? parsed.data : parsed;
|
|
493
|
+
mergeResults = (payload.results || []);
|
|
494
|
+
mergeMeta = { suggestions: payload.suggestions, answers: payload.answers };
|
|
609
495
|
}
|
|
610
|
-
|
|
611
|
-
console.log(JSON.stringify(
|
|
612
|
-
|
|
613
|
-
returnedResults: displayResults.length,
|
|
614
|
-
}), null, 2));
|
|
496
|
+
catch {
|
|
497
|
+
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));
|
|
498
|
+
return 1;
|
|
615
499
|
}
|
|
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
500
|
}
|
|
620
|
-
|
|
501
|
+
// One invocation, N queries: the only difference from a single query is
|
|
502
|
+
// how many responses land in the array.
|
|
621
503
|
const engines = options.engines ?? [];
|
|
622
504
|
const plan = planProviderSearch(engines);
|
|
505
|
+
const responses = [];
|
|
623
506
|
for (const query of queries) {
|
|
624
507
|
const searchOptions = {
|
|
625
508
|
query,
|
|
626
|
-
engines
|
|
509
|
+
engines,
|
|
627
510
|
categories: options.categories,
|
|
628
511
|
limit,
|
|
629
512
|
page: options.page,
|
|
@@ -631,121 +514,56 @@ async function runSearch(service, options) {
|
|
|
631
514
|
timeRange: options.timeRange,
|
|
632
515
|
};
|
|
633
516
|
const { providerResponses, sxngResponse } = await searchOneQuery(service, plan, searchOptions, limit);
|
|
634
|
-
|
|
517
|
+
responses.push(...providerResponses);
|
|
635
518
|
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);
|
|
519
|
+
responses.push(sxngResponse);
|
|
716
520
|
}
|
|
521
|
+
// Snapshot before writing: history must not include this invocation's own
|
|
522
|
+
// results, or every current result votes for itself a second time.
|
|
523
|
+
const sessionSnapshot = options.session ? loadSessionResults(options.session) : undefined;
|
|
524
|
+
const fusion = fuseResults({
|
|
525
|
+
responses,
|
|
526
|
+
mergeResults,
|
|
527
|
+
sessionSnapshot,
|
|
528
|
+
onlyCurrent: Boolean(options.session),
|
|
529
|
+
limit,
|
|
530
|
+
toolFor: engine => originTool(engine),
|
|
531
|
+
});
|
|
717
532
|
let sessionInfo = null;
|
|
718
533
|
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 => ({
|
|
534
|
+
sessionInfo = appendSessionResults(options.session, fusion.display.map((result, index) => ({
|
|
729
535
|
...result,
|
|
730
|
-
|
|
536
|
+
// The fused position, so `rank` and `fusionScore` describe the same
|
|
537
|
+
// order instead of one provider's and one RRF's.
|
|
538
|
+
rank: index + 1,
|
|
539
|
+
origins: fusion.originsByKey.get(resultUrlKey(result)),
|
|
731
540
|
})));
|
|
732
541
|
injectApprovedResults(options.session, sessionInfo.approvedResults);
|
|
733
|
-
// Check pending count and warn if >= 30
|
|
734
542
|
const pendingCount = countPendingResults(options.session);
|
|
735
543
|
if (pendingCount >= 30) {
|
|
736
|
-
console.error(`[session] ${pendingCount} pending results awaiting Agent
|
|
544
|
+
console.error(`[session] ${pendingCount} pending results awaiting Agent review. Run --quality to list them.`);
|
|
737
545
|
}
|
|
738
546
|
}
|
|
739
|
-
const
|
|
547
|
+
const meta = mergeEnvelopeMetadata(responses, null);
|
|
548
|
+
for (const suggestion of mergeMeta.suggestions ?? []) {
|
|
549
|
+
if (!meta.suggestions.includes(suggestion))
|
|
550
|
+
meta.suggestions.push(suggestion);
|
|
551
|
+
}
|
|
552
|
+
for (const answer of mergeMeta.answers ?? []) {
|
|
553
|
+
if (!meta.answers.includes(answer))
|
|
554
|
+
meta.answers.push(answer);
|
|
555
|
+
}
|
|
740
556
|
const outputFormat = (options.format || config.defaultFormat);
|
|
741
557
|
const displayData = {
|
|
742
|
-
query:
|
|
558
|
+
query: queries.length > 1 ? queries.join(' · ') : queries[0],
|
|
743
559
|
queries,
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
560
|
+
// The deduplicated candidate pool, not a sum of provider self-reports
|
|
561
|
+
// and not the pre-dedup array length.
|
|
562
|
+
totalResults: fusion.fused.length,
|
|
563
|
+
results: fusion.display,
|
|
564
|
+
answers: meta.answers,
|
|
565
|
+
suggestions: meta.suggestions,
|
|
566
|
+
unresponsiveEngines: meta.unresponsiveEngines,
|
|
749
567
|
...(sessionInfo ? { session: { dir: options.session, added: sessionInfo.added, total: sessionInfo.total } } : {}),
|
|
750
568
|
};
|
|
751
569
|
if (outputFormat === 'md') {
|
|
@@ -754,7 +572,7 @@ async function runSearch(service, options) {
|
|
|
754
572
|
else if (outputFormat === 'json') {
|
|
755
573
|
console.log(JSON.stringify(createSuccessEnvelope({
|
|
756
574
|
...displayData,
|
|
757
|
-
returnedResults:
|
|
575
|
+
returnedResults: fusion.display.length,
|
|
758
576
|
}), null, 2));
|
|
759
577
|
}
|
|
760
578
|
else {
|
|
@@ -765,15 +583,26 @@ async function runSearch(service, options) {
|
|
|
765
583
|
return 0;
|
|
766
584
|
}
|
|
767
585
|
catch (error) {
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
586
|
+
// `retryable` and the hint come from the error, not from this block.
|
|
587
|
+
// They used to be the literals `true` and a SearXNG hint, which meant a
|
|
588
|
+
// DeepSeek 401 was reported as retryable and blamed on a server the
|
|
589
|
+
// request never touched. An unclassified error now reports neither:
|
|
590
|
+
// calling it retryable is a claim this catch cannot support.
|
|
591
|
+
if (error instanceof SearchError) {
|
|
592
|
+
const envelope = createErrorEnvelope(error.code, error.message, {
|
|
593
|
+
retryable: error.retryable,
|
|
594
|
+
hint: error.hint,
|
|
595
|
+
details: { provider: error.provider, ...(error.status === undefined ? {} : { status: error.status }) },
|
|
596
|
+
});
|
|
597
|
+
console.log(JSON.stringify(envelope, null, 2));
|
|
598
|
+
return 1;
|
|
599
|
+
}
|
|
600
|
+
const envelope = createErrorEnvelope('SEARCH_FAILED', error instanceof Error ? error.message : 'Search request failed');
|
|
772
601
|
console.log(JSON.stringify(envelope, null, 2));
|
|
773
602
|
return 1;
|
|
774
603
|
}
|
|
775
604
|
}
|
|
776
|
-
export function createProgram() {
|
|
605
|
+
export function createProgram(argv = []) {
|
|
777
606
|
const program = new Command();
|
|
778
607
|
program
|
|
779
608
|
.name('dg')
|
|
@@ -794,8 +623,7 @@ export function createProgram() {
|
|
|
794
623
|
.option('--desc <text>', 'Session description (stored in meta.json)')
|
|
795
624
|
.option('--graph <file>', 'Save search result metadata to knowledge graph file')
|
|
796
625
|
.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}\')')
|
|
626
|
+
.option('--quality', 'List pending results with what the session has gathered, as counted facts')
|
|
799
627
|
.option('--approve-file <path>', 'UTF-8 approval JSON array under this session agent-inputs directory')
|
|
800
628
|
.option('--skip-file <path>', 'UTF-8 skip JSON array under this session agent-inputs directory')
|
|
801
629
|
.option('--unskip-file <path>', 'UTF-8 restore JSON array under this session agent-inputs directory')
|
|
@@ -808,7 +636,7 @@ export function createProgram() {
|
|
|
808
636
|
.description('Interactive configuration setup')
|
|
809
637
|
.action(async () => {
|
|
810
638
|
const code = await initConfig();
|
|
811
|
-
process.
|
|
639
|
+
process.exitCode = code;
|
|
812
640
|
});
|
|
813
641
|
program
|
|
814
642
|
.command('extract')
|
|
@@ -833,7 +661,7 @@ export function createProgram() {
|
|
|
833
661
|
jina: opts.jina ?? false,
|
|
834
662
|
};
|
|
835
663
|
const code = await runExtract(extractor, extractOptions);
|
|
836
|
-
process.
|
|
664
|
+
process.exitCode = code;
|
|
837
665
|
});
|
|
838
666
|
program
|
|
839
667
|
.command('query-graph')
|
|
@@ -853,7 +681,7 @@ export function createProgram() {
|
|
|
853
681
|
format: graphFormat,
|
|
854
682
|
strategy: opts.strategy,
|
|
855
683
|
});
|
|
856
|
-
process.
|
|
684
|
+
process.exitCode = code;
|
|
857
685
|
});
|
|
858
686
|
program
|
|
859
687
|
.command('graph-add')
|
|
@@ -865,7 +693,7 @@ export function createProgram() {
|
|
|
865
693
|
session,
|
|
866
694
|
dataFile: opts.dataFile,
|
|
867
695
|
});
|
|
868
|
-
process.
|
|
696
|
+
process.exitCode = code;
|
|
869
697
|
});
|
|
870
698
|
program
|
|
871
699
|
.command('results-add')
|
|
@@ -888,7 +716,7 @@ Search imports await extraction; extracted imports await approval.`)
|
|
|
888
716
|
query: opts.query,
|
|
889
717
|
tool: opts.tool,
|
|
890
718
|
});
|
|
891
|
-
process.
|
|
719
|
+
process.exitCode = code;
|
|
892
720
|
});
|
|
893
721
|
program
|
|
894
722
|
.command('doc-index')
|
|
@@ -904,7 +732,7 @@ Examples:
|
|
|
904
732
|
path,
|
|
905
733
|
extensions: opts.type?.split(',').map((e) => e.trim()).filter(Boolean),
|
|
906
734
|
});
|
|
907
|
-
process.
|
|
735
|
+
process.exitCode = code;
|
|
908
736
|
});
|
|
909
737
|
program
|
|
910
738
|
.command('doc-search')
|
|
@@ -926,14 +754,14 @@ Examples:
|
|
|
926
754
|
topK: opts.top,
|
|
927
755
|
boost: opts.boost,
|
|
928
756
|
});
|
|
929
|
-
process.
|
|
757
|
+
process.exitCode = code;
|
|
930
758
|
});
|
|
931
759
|
program
|
|
932
760
|
.command('session-list')
|
|
933
761
|
.description('List all sessions')
|
|
934
762
|
.action(async () => {
|
|
935
763
|
const code = await runSessionList();
|
|
936
|
-
process.
|
|
764
|
+
process.exitCode = code;
|
|
937
765
|
});
|
|
938
766
|
program
|
|
939
767
|
.command('session-delete')
|
|
@@ -942,7 +770,7 @@ Examples:
|
|
|
942
770
|
.action(async (names, opts) => {
|
|
943
771
|
const nameList = (names || '').split(',').map((n) => n.trim()).filter(Boolean);
|
|
944
772
|
const code = await runSessionDelete(nameList, opts.older);
|
|
945
|
-
process.
|
|
773
|
+
process.exitCode = code;
|
|
946
774
|
});
|
|
947
775
|
program
|
|
948
776
|
.command('graph-obfuscate')
|
|
@@ -968,7 +796,7 @@ and write them back via graph-add.`)
|
|
|
968
796
|
format: opts.format === 'md' ? 'md' : 'json',
|
|
969
797
|
skipEntityTypes: opts.skipTypes?.split(',').map((t) => t.trim()).filter(Boolean),
|
|
970
798
|
});
|
|
971
|
-
process.
|
|
799
|
+
process.exitCode = code;
|
|
972
800
|
});
|
|
973
801
|
program
|
|
974
802
|
.command('graph-preprocess')
|
|
@@ -995,7 +823,26 @@ Examples:
|
|
|
995
823
|
else {
|
|
996
824
|
console.log(JSON.stringify(createSuccessEnvelope(result), null, 2));
|
|
997
825
|
}
|
|
998
|
-
process.
|
|
826
|
+
process.exitCode = 0;
|
|
827
|
+
});
|
|
828
|
+
program
|
|
829
|
+
.command('coverage')
|
|
830
|
+
.argument('<session>', 'Session directory or name')
|
|
831
|
+
.description('Report what the session has looked at, as counted facts (rounds, queries, repetition, distinctive terms)')
|
|
832
|
+
.option('-f, --format <fmt>', 'Output format: json (default), md')
|
|
833
|
+
.addHelpText('after', `
|
|
834
|
+
Reports what has been searched and what came back, without deciding what it means.
|
|
835
|
+
Reads results.json only, so it works before any result has been approved.
|
|
836
|
+
|
|
837
|
+
Examples:
|
|
838
|
+
dg coverage my-session
|
|
839
|
+
dg coverage my-session --format md`)
|
|
840
|
+
.action(async (session, opts, command) => {
|
|
841
|
+
const code = await runCoverage({
|
|
842
|
+
session,
|
|
843
|
+
format: subcommandFormat(argv, command.name(), opts.format) === 'md' ? 'md' : 'json',
|
|
844
|
+
});
|
|
845
|
+
process.exitCode = code;
|
|
999
846
|
});
|
|
1000
847
|
program
|
|
1001
848
|
.command('suggest-queries')
|
|
@@ -1011,15 +858,14 @@ Examples:
|
|
|
1011
858
|
const graph = loadSessionGraph(sessionDir);
|
|
1012
859
|
const results = loadSessionResults(sessionDir);
|
|
1013
860
|
const stage = determineSearchStage(graph);
|
|
1014
|
-
const
|
|
1015
|
-
const data = generateQuerySuggestions(graph, results, stage, quality);
|
|
861
|
+
const data = generateQuerySuggestions(graph, results, stage);
|
|
1016
862
|
if (opts.format === 'md') {
|
|
1017
863
|
console.log(formatSuggestAsMarkdown(data));
|
|
1018
864
|
}
|
|
1019
865
|
else {
|
|
1020
866
|
console.log(JSON.stringify(createSuccessEnvelope(data), null, 2));
|
|
1021
867
|
}
|
|
1022
|
-
process.
|
|
868
|
+
process.exitCode = 0;
|
|
1023
869
|
});
|
|
1024
870
|
program
|
|
1025
871
|
.command('strategy-info')
|
|
@@ -1045,35 +891,12 @@ Examples:
|
|
|
1045
891
|
else {
|
|
1046
892
|
console.log(JSON.stringify(createSuccessEnvelope(info), null, 2));
|
|
1047
893
|
}
|
|
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);
|
|
894
|
+
process.exitCode = 0;
|
|
1072
895
|
});
|
|
1073
896
|
program
|
|
1074
897
|
.command('session-report')
|
|
1075
898
|
.argument('<session>', 'Session directory or name')
|
|
1076
|
-
.description('Show session
|
|
899
|
+
.description('Show what the session has gathered and how far the search has moved')
|
|
1077
900
|
.option('-f, --format <fmt>', 'Output format: json (default), md')
|
|
1078
901
|
.addHelpText('after', `
|
|
1079
902
|
Examples:
|
|
@@ -1083,14 +906,14 @@ Examples:
|
|
|
1083
906
|
const sessionDir = resolveSessionPath(session);
|
|
1084
907
|
const graph = loadSessionGraph(sessionDir);
|
|
1085
908
|
const results = loadSessionResults(sessionDir);
|
|
1086
|
-
const analysis = getSessionAnalysis(graph, results);
|
|
909
|
+
const analysis = getSessionAnalysis(graph, results, getPendingResults(sessionDir));
|
|
1087
910
|
if (opts.format === 'md') {
|
|
1088
911
|
console.log(formatSessionReportAsMarkdown(analysis));
|
|
1089
912
|
}
|
|
1090
913
|
else {
|
|
1091
914
|
console.log(JSON.stringify(createSuccessEnvelope(analysis), null, 2));
|
|
1092
915
|
}
|
|
1093
|
-
process.
|
|
916
|
+
process.exitCode = 0;
|
|
1094
917
|
});
|
|
1095
918
|
program
|
|
1096
919
|
.command('graph-explore')
|
|
@@ -1110,7 +933,7 @@ See also: graph-drill, graph-search`)
|
|
|
1110
933
|
seed: opts.seed,
|
|
1111
934
|
format: opts.format === 'json' ? 'json' : 'md',
|
|
1112
935
|
});
|
|
1113
|
-
process.
|
|
936
|
+
process.exitCode = code;
|
|
1114
937
|
});
|
|
1115
938
|
program
|
|
1116
939
|
.command('graph-drill')
|
|
@@ -1132,7 +955,7 @@ See also: graph-explore`)
|
|
|
1132
955
|
relations: opts.relations.split(',').map((r) => r.trim()).filter(Boolean),
|
|
1133
956
|
format: opts.format === 'json' ? 'json' : 'md',
|
|
1134
957
|
});
|
|
1135
|
-
process.
|
|
958
|
+
process.exitCode = code;
|
|
1136
959
|
});
|
|
1137
960
|
program
|
|
1138
961
|
.command('graph-traverse')
|
|
@@ -1153,7 +976,7 @@ the command will list available path node IDs.`)
|
|
|
1153
976
|
pathId: opts.path,
|
|
1154
977
|
format: opts.format === 'json' ? 'json' : 'md',
|
|
1155
978
|
});
|
|
1156
|
-
process.
|
|
979
|
+
process.exitCode = code;
|
|
1157
980
|
});
|
|
1158
981
|
program
|
|
1159
982
|
.command('graph-search')
|
|
@@ -1175,7 +998,7 @@ See also: graph-explore (for viewing relations of a known entity)`)
|
|
|
1175
998
|
limit: opts.limit,
|
|
1176
999
|
format: opts.format === 'json' ? 'json' : 'md',
|
|
1177
1000
|
});
|
|
1178
|
-
process.
|
|
1001
|
+
process.exitCode = code;
|
|
1179
1002
|
});
|
|
1180
1003
|
// ── Claim commands ──────────────────────────────────────────
|
|
1181
1004
|
program
|
|
@@ -1195,7 +1018,7 @@ Examples:
|
|
|
1195
1018
|
claimsFile: opts.claimsFile,
|
|
1196
1019
|
format: opts.format,
|
|
1197
1020
|
});
|
|
1198
|
-
process.
|
|
1021
|
+
process.exitCode = code;
|
|
1199
1022
|
});
|
|
1200
1023
|
program
|
|
1201
1024
|
.command('claim-list')
|
|
@@ -1208,7 +1031,7 @@ Examples:
|
|
|
1208
1031
|
status: opts.status,
|
|
1209
1032
|
format: opts.format,
|
|
1210
1033
|
});
|
|
1211
|
-
process.
|
|
1034
|
+
process.exitCode = code;
|
|
1212
1035
|
});
|
|
1213
1036
|
program
|
|
1214
1037
|
.command('evidence-search')
|
|
@@ -1221,7 +1044,7 @@ Examples:
|
|
|
1221
1044
|
claimId: opts.claimId,
|
|
1222
1045
|
format: opts.format,
|
|
1223
1046
|
});
|
|
1224
|
-
process.
|
|
1047
|
+
process.exitCode = code;
|
|
1225
1048
|
});
|
|
1226
1049
|
program
|
|
1227
1050
|
.command('evidence-verify')
|
|
@@ -1244,7 +1067,7 @@ Examples:
|
|
|
1244
1067
|
complete: opts.complete ?? false,
|
|
1245
1068
|
format: opts.format,
|
|
1246
1069
|
});
|
|
1247
|
-
process.
|
|
1070
|
+
process.exitCode = code;
|
|
1248
1071
|
});
|
|
1249
1072
|
program
|
|
1250
1073
|
.command('evidence-list')
|
|
@@ -1257,7 +1080,7 @@ Examples:
|
|
|
1257
1080
|
claimId: opts.claimId,
|
|
1258
1081
|
format: opts.format,
|
|
1259
1082
|
});
|
|
1260
|
-
process.
|
|
1083
|
+
process.exitCode = code;
|
|
1261
1084
|
});
|
|
1262
1085
|
program
|
|
1263
1086
|
.command('verdict-list')
|
|
@@ -1270,7 +1093,7 @@ Examples:
|
|
|
1270
1093
|
claimId: opts.claimId,
|
|
1271
1094
|
format: opts.format,
|
|
1272
1095
|
});
|
|
1273
|
-
process.
|
|
1096
|
+
process.exitCode = code;
|
|
1274
1097
|
});
|
|
1275
1098
|
program
|
|
1276
1099
|
.command('policy-aggregate')
|
|
@@ -1283,7 +1106,7 @@ Examples:
|
|
|
1283
1106
|
claimId: opts.claimId,
|
|
1284
1107
|
format: opts.format,
|
|
1285
1108
|
});
|
|
1286
|
-
process.
|
|
1109
|
+
process.exitCode = code;
|
|
1287
1110
|
});
|
|
1288
1111
|
program
|
|
1289
1112
|
.command('review-list')
|
|
@@ -1296,19 +1119,19 @@ Examples:
|
|
|
1296
1119
|
status: opts.status,
|
|
1297
1120
|
format: opts.format,
|
|
1298
1121
|
});
|
|
1299
|
-
process.
|
|
1122
|
+
process.exitCode = code;
|
|
1300
1123
|
});
|
|
1301
1124
|
return program;
|
|
1302
1125
|
}
|
|
1303
1126
|
export async function runCli(args, service) {
|
|
1304
|
-
const program = createProgram();
|
|
1127
|
+
const program = createProgram(args);
|
|
1305
1128
|
// Custom action for default command (search)
|
|
1306
1129
|
// Commander passes the [query] argument as first param, then opts
|
|
1307
1130
|
program.action(async (query, opts) => {
|
|
1308
1131
|
const queryString = query || '';
|
|
1309
1132
|
if (opts.version) {
|
|
1310
1133
|
console.log(program.version());
|
|
1311
|
-
process.
|
|
1134
|
+
process.exitCode = 0;
|
|
1312
1135
|
return;
|
|
1313
1136
|
}
|
|
1314
1137
|
if (opts.health) {
|
|
@@ -1317,14 +1140,14 @@ export async function runCli(args, service) {
|
|
|
1317
1140
|
? createSuccessEnvelope(health)
|
|
1318
1141
|
: createErrorEnvelope('HEALTH_CHECK_FAILED', health.error || 'SearXNG server is not responding', { hint: `Check if SearXNG is running at ${config.baseUrl}` });
|
|
1319
1142
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1320
|
-
process.
|
|
1143
|
+
process.exitCode = health.status === 'healthy' ? 0 : 1;
|
|
1321
1144
|
return;
|
|
1322
1145
|
}
|
|
1323
1146
|
if (opts.quality) {
|
|
1324
1147
|
if (!opts.session) {
|
|
1325
1148
|
const envelope = createErrorEnvelope('QUALITY_NO_SESSION', '--quality requires --session', { hint: 'Use: dg --session <name> --quality' });
|
|
1326
1149
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1327
|
-
process.
|
|
1150
|
+
process.exitCode = 1;
|
|
1328
1151
|
return;
|
|
1329
1152
|
}
|
|
1330
1153
|
const sessionDir = resolveSessionPath(opts.session);
|
|
@@ -1353,45 +1176,21 @@ export async function runCli(args, service) {
|
|
|
1353
1176
|
if (opts.skipFile || opts.unskipFile) {
|
|
1354
1177
|
if (opts.skipFile && opts.unskipFile) {
|
|
1355
1178
|
console.log(JSON.stringify(createErrorEnvelope('MULTIPLE_SKIP_ACTIONS', 'Use only one of --skip-file or --unskip-file'), null, 2));
|
|
1356
|
-
process.
|
|
1179
|
+
process.exitCode = 1;
|
|
1357
1180
|
return;
|
|
1358
1181
|
}
|
|
1359
|
-
process.
|
|
1182
|
+
process.exitCode = applySkip(opts.skipFile ? '--skip-file' : '--unskip-file', opts.skipFile ?? opts.unskipFile, Boolean(opts.skipFile)) ? 0 : 1;
|
|
1360
1183
|
return;
|
|
1361
1184
|
}
|
|
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
1185
|
// Get pending results for Agent review
|
|
1375
1186
|
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.
|
|
1187
|
+
const facts = buildPendingReport(sessionResults, pending);
|
|
1188
|
+
// Approval is allowed only after reporting what is waiting and how
|
|
1189
|
+
// much of it carries a body.
|
|
1391
1190
|
if (opts.approveFile) {
|
|
1392
1191
|
const selections = readSelections('--approve-file', opts.approveFile);
|
|
1393
1192
|
if (!selections) {
|
|
1394
|
-
process.
|
|
1193
|
+
process.exitCode = 1;
|
|
1395
1194
|
return;
|
|
1396
1195
|
}
|
|
1397
1196
|
const selectedResults = selections
|
|
@@ -1401,10 +1200,10 @@ export async function runCli(args, service) {
|
|
|
1401
1200
|
const approval = approveResults(sessionDir, selections);
|
|
1402
1201
|
if (approval.error) {
|
|
1403
1202
|
console.log(JSON.stringify(createErrorEnvelope(approval.error.code, approval.error.message, {
|
|
1404
|
-
details: {
|
|
1203
|
+
details: { facts, selectedResults, error: approval.error },
|
|
1405
1204
|
hint: 'Run dg extract --session <session> for unverified results, then review and approve again.',
|
|
1406
1205
|
}), null, 2));
|
|
1407
|
-
process.
|
|
1206
|
+
process.exitCode = 1;
|
|
1408
1207
|
return;
|
|
1409
1208
|
}
|
|
1410
1209
|
// Inject only the results selected by this approval action.
|
|
@@ -1414,66 +1213,47 @@ export async function runCli(args, service) {
|
|
|
1414
1213
|
total: approval.total,
|
|
1415
1214
|
nodesAdded: injectInfo.nodesAdded,
|
|
1416
1215
|
edgesAdded: injectInfo.edgesAdded,
|
|
1417
|
-
|
|
1216
|
+
facts,
|
|
1418
1217
|
selectedResults,
|
|
1419
1218
|
message: `Approved ${approval.approved} results, injected into graph (+${injectInfo.nodesAdded} nodes, +${injectInfo.edgesAdded} edges)`,
|
|
1420
1219
|
}), null, 2));
|
|
1421
|
-
process.
|
|
1220
|
+
process.exitCode = 0;
|
|
1422
1221
|
return;
|
|
1423
1222
|
}
|
|
1424
1223
|
if (pending.length === 0) {
|
|
1425
|
-
//
|
|
1426
|
-
const quality = assessResultQuality(sessionResults, priorResults, thresholdOverride);
|
|
1224
|
+
// Nothing to approve: the counts still describe the session.
|
|
1427
1225
|
const outputFormat = (opts.format || config.defaultFormat);
|
|
1428
1226
|
if (outputFormat === 'md') {
|
|
1429
|
-
console.log(
|
|
1227
|
+
console.log(formatFactsAsMarkdown(facts));
|
|
1430
1228
|
}
|
|
1431
1229
|
else {
|
|
1432
|
-
console.log(JSON.stringify(createSuccessEnvelope(
|
|
1230
|
+
console.log(JSON.stringify(createSuccessEnvelope(facts), null, 2));
|
|
1433
1231
|
}
|
|
1434
|
-
process.
|
|
1232
|
+
process.exitCode = 0;
|
|
1435
1233
|
return;
|
|
1436
1234
|
}
|
|
1437
1235
|
const outputFormat = (opts.format || config.defaultFormat);
|
|
1438
1236
|
if (outputFormat === 'json') {
|
|
1439
|
-
//
|
|
1237
|
+
// The body under review, alongside the per-result facts. The
|
|
1238
|
+
// preview is deliberately `content` and not the display
|
|
1239
|
+
// fallback: this list exists so the Agent can read the
|
|
1240
|
+
// extracted text before approving it.
|
|
1440
1241
|
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),
|
|
1242
|
+
...facts,
|
|
1243
|
+
pending: facts.pending.map((fact, index) => ({
|
|
1244
|
+
...fact,
|
|
1245
|
+
index,
|
|
1246
|
+
contentPreview: pending[index].content?.slice(0, 300),
|
|
1464
1247
|
})),
|
|
1465
1248
|
hint: 'Agent reviews content and approves with the id/revision objects returned here.',
|
|
1466
1249
|
}), null, 2));
|
|
1467
1250
|
}
|
|
1468
1251
|
else {
|
|
1469
|
-
console.log(
|
|
1252
|
+
console.log(formatFactsAsMarkdown(facts));
|
|
1470
1253
|
console.log('\n## Pending Results (awaiting Agent approval)\n');
|
|
1471
1254
|
for (let i = 0; i < pending.length; i++) {
|
|
1472
1255
|
const r = pending[i];
|
|
1473
1256
|
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
1257
|
if (r.content) {
|
|
1478
1258
|
const preview = r.content.slice(0, 300).replace(/\s+/g, ' ');
|
|
1479
1259
|
console.log(` Preview: ${preview}${r.content.length > 300 ? '...' : ''}`);
|
|
@@ -1481,28 +1261,40 @@ export async function runCli(args, service) {
|
|
|
1481
1261
|
}
|
|
1482
1262
|
console.log('\n**Agent writes ID/revision selections to session agent-inputs, then uses --approve-file.**');
|
|
1483
1263
|
}
|
|
1484
|
-
process.
|
|
1264
|
+
process.exitCode = 0;
|
|
1485
1265
|
return;
|
|
1486
1266
|
}
|
|
1487
1267
|
if (opts.enginesList) {
|
|
1488
1268
|
try {
|
|
1489
|
-
const
|
|
1269
|
+
const serverEngines = await service.getEngines();
|
|
1490
1270
|
const configuredProviders = EXTERNAL_PROVIDERS.filter(p => PROVIDER_IMPLS[p].configured());
|
|
1491
|
-
|
|
1271
|
+
// Both empty is a legitimate-looking but useless answer: nothing
|
|
1272
|
+
// this CLI can search with. Reaching here already means the
|
|
1273
|
+
// server answered (a failed fetch throws), so `serverEngines`
|
|
1274
|
+
// being empty now says exactly one thing — the server has no
|
|
1275
|
+
// enabled engines — and the `&&` reads correctly.
|
|
1276
|
+
if (serverEngines.length === 0 && configuredProviders.length === 0) {
|
|
1492
1277
|
const envelope = createErrorEnvelope('ENGINES_FETCH_EMPTY', 'No engines returned from SearXNG server', { hint: 'Check if SearXNG server is properly configured' });
|
|
1493
1278
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1494
|
-
process.
|
|
1279
|
+
process.exitCode = 1;
|
|
1495
1280
|
return;
|
|
1496
1281
|
}
|
|
1497
|
-
|
|
1498
|
-
|
|
1282
|
+
// `source: 'server'` used to be a literal, so a provider name
|
|
1283
|
+
// configured locally was reported as if the server had returned
|
|
1284
|
+
// it. The breakdown cannot make that claim: each name is listed
|
|
1285
|
+
// under where it actually came from. `engines` stays flat so a
|
|
1286
|
+
// consumer reading the list is unaffected.
|
|
1287
|
+
const envelope = createSuccessEnvelope({
|
|
1288
|
+
engines: [...serverEngines, ...configuredProviders],
|
|
1289
|
+
sources: { server: serverEngines, local: configuredProviders },
|
|
1290
|
+
});
|
|
1499
1291
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1500
|
-
process.
|
|
1292
|
+
process.exitCode = 0;
|
|
1501
1293
|
}
|
|
1502
1294
|
catch (error) {
|
|
1503
|
-
const envelope = createErrorEnvelope('ENGINES_FETCH_FAILED', error instanceof Error ? error.message : 'Failed to fetch engines', { hint:
|
|
1295
|
+
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
1296
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1505
|
-
process.
|
|
1297
|
+
process.exitCode = 1;
|
|
1506
1298
|
}
|
|
1507
1299
|
return;
|
|
1508
1300
|
}
|
|
@@ -1512,17 +1304,17 @@ export async function runCli(args, service) {
|
|
|
1512
1304
|
if (categories.length === 0) {
|
|
1513
1305
|
const envelope = createErrorEnvelope('CATEGORIES_FETCH_EMPTY', 'No categories returned from SearXNG server', { hint: 'Check if SearXNG server is properly configured' });
|
|
1514
1306
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1515
|
-
process.
|
|
1307
|
+
process.exitCode = 1;
|
|
1516
1308
|
return;
|
|
1517
1309
|
}
|
|
1518
1310
|
const envelope = createSuccessEnvelope({ categories, source: 'server' });
|
|
1519
1311
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1520
|
-
process.
|
|
1312
|
+
process.exitCode = 0;
|
|
1521
1313
|
}
|
|
1522
1314
|
catch (error) {
|
|
1523
1315
|
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
1316
|
console.log(JSON.stringify(envelope, null, 2));
|
|
1525
|
-
process.
|
|
1317
|
+
process.exitCode = 1;
|
|
1526
1318
|
}
|
|
1527
1319
|
return;
|
|
1528
1320
|
}
|
|
@@ -1547,7 +1339,7 @@ export async function runCli(args, service) {
|
|
|
1547
1339
|
merge: opts.merge,
|
|
1548
1340
|
redundancy: opts.redundancy,
|
|
1549
1341
|
});
|
|
1550
|
-
process.
|
|
1342
|
+
process.exitCode = code;
|
|
1551
1343
|
});
|
|
1552
1344
|
try {
|
|
1553
1345
|
await program.parseAsync(args, { from: 'user' });
|