digdig 0.1.1 → 0.1.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 +68 -42
- package/digdig.config.example.json +6 -0
- package/dist/commands/claim.d.ts +2 -0
- package/dist/commands/claim.d.ts.map +1 -1
- package/dist/commands/claim.js +3 -1
- package/dist/commands/claim.js.map +1 -1
- package/dist/commands/doc-search.d.ts.map +1 -1
- package/dist/commands/doc-search.js +14 -1
- package/dist/commands/doc-search.js.map +1 -1
- package/dist/commands/evidence.d.ts +6 -0
- package/dist/commands/evidence.d.ts.map +1 -1
- package/dist/commands/evidence.js +6 -3
- package/dist/commands/evidence.js.map +1 -1
- package/dist/commands/extract.d.ts.map +1 -1
- package/dist/commands/extract.js +18 -5
- package/dist/commands/extract.js.map +1 -1
- package/dist/commands/graph-add.d.ts +1 -0
- package/dist/commands/graph-add.d.ts.map +1 -1
- package/dist/commands/graph-add.js +4 -1
- package/dist/commands/graph-add.js.map +1 -1
- package/dist/commands/json-input.d.ts +4 -2
- package/dist/commands/json-input.d.ts.map +1 -1
- package/dist/commands/json-input.js +30 -13
- package/dist/commands/json-input.js.map +1 -1
- package/dist/commands/results-add.d.ts +1 -0
- package/dist/commands/results-add.d.ts.map +1 -1
- package/dist/commands/results-add.js +6 -1
- package/dist/commands/results-add.js.map +1 -1
- package/dist/commands/review.d.ts.map +1 -1
- package/dist/commands/review.js +5 -4
- package/dist/commands/review.js.map +1 -1
- package/dist/commands/source-relations.d.ts +3 -0
- package/dist/commands/source-relations.d.ts.map +1 -1
- package/dist/commands/source-relations.js +5 -2
- package/dist/commands/source-relations.js.map +1 -1
- package/dist/commands/verdict.js +2 -2
- package/dist/commands/verdict.js.map +1 -1
- package/dist/config.d.ts +17 -15
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +73 -101
- package/dist/config.js.map +1 -1
- package/dist/deep/dedupe.d.ts +16 -12
- package/dist/deep/dedupe.d.ts.map +1 -1
- package/dist/deep/dedupe.js +27 -27
- package/dist/deep/dedupe.js.map +1 -1
- package/dist/deep/extractor.d.ts.map +1 -1
- package/dist/deep/extractor.js +20 -0
- package/dist/deep/extractor.js.map +1 -1
- package/dist/deep/fuse.d.ts +2 -1
- package/dist/deep/fuse.d.ts.map +1 -1
- package/dist/deep/fuse.js +27 -12
- package/dist/deep/fuse.js.map +1 -1
- package/dist/deep/graph.d.ts +4 -2
- package/dist/deep/graph.d.ts.map +1 -1
- package/dist/deep/graph.js +6 -8
- package/dist/deep/graph.js.map +1 -1
- package/dist/deep/installed-firecrawl.d.ts +2 -1
- package/dist/deep/installed-firecrawl.d.ts.map +1 -1
- package/dist/deep/installed-firecrawl.js +8 -9
- package/dist/deep/installed-firecrawl.js.map +1 -1
- package/dist/deep/installed-tavily.d.ts +2 -1
- package/dist/deep/installed-tavily.d.ts.map +1 -1
- package/dist/deep/installed-tavily.js +6 -4
- package/dist/deep/installed-tavily.js.map +1 -1
- package/dist/deep/local-doc/indexer.d.ts +13 -3
- package/dist/deep/local-doc/indexer.d.ts.map +1 -1
- package/dist/deep/local-doc/indexer.js +28 -19
- package/dist/deep/local-doc/indexer.js.map +1 -1
- package/dist/deep/local-doc/scanner.d.ts.map +1 -1
- package/dist/deep/local-doc/scanner.js +6 -2
- package/dist/deep/local-doc/scanner.js.map +1 -1
- package/dist/deep/local-doc/searcher.d.ts.map +1 -1
- package/dist/deep/local-doc/searcher.js +13 -14
- package/dist/deep/local-doc/searcher.js.map +1 -1
- package/dist/deep/local-doc/types.d.ts +2 -0
- package/dist/deep/local-doc/types.d.ts.map +1 -1
- package/dist/deep/local-doc/types.js.map +1 -1
- package/dist/deep/session-db.d.ts.map +1 -1
- package/dist/deep/session-db.js +22 -1
- package/dist/deep/session-db.js.map +1 -1
- package/dist/deep/session-lock.d.ts +12 -2
- package/dist/deep/session-lock.d.ts.map +1 -1
- package/dist/deep/session-lock.js +9 -0
- package/dist/deep/session-lock.js.map +1 -1
- package/dist/deep/session.d.ts +4 -1
- package/dist/deep/session.d.ts.map +1 -1
- package/dist/deep/session.js +25 -16
- package/dist/deep/session.js.map +1 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +6 -0
- package/dist/entry.js.map +1 -1
- package/dist/errors.d.ts +17 -16
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +40 -19
- package/dist/errors.js.map +1 -1
- package/dist/external-search.d.ts +3 -1
- package/dist/external-search.d.ts.map +1 -1
- package/dist/external-search.js +41 -16
- package/dist/external-search.js.map +1 -1
- package/dist/feedback-log.d.ts +20 -2
- package/dist/feedback-log.d.ts.map +1 -1
- package/dist/feedback-log.js +24 -3
- package/dist/feedback-log.js.map +1 -1
- package/dist/firecrawl-results.d.ts +3 -0
- package/dist/firecrawl-results.d.ts.map +1 -0
- package/dist/firecrawl-results.js +27 -0
- package/dist/firecrawl-results.js.map +1 -0
- package/dist/init.d.ts +1 -11
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +54 -36
- package/dist/init.js.map +1 -1
- package/dist/legacy.d.ts +1 -23
- package/dist/legacy.d.ts.map +1 -1
- package/dist/legacy.js +2 -57
- package/dist/legacy.js.map +1 -1
- package/dist/protocol.d.ts +20 -2
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +96 -0
- package/dist/protocol.js.map +1 -1
- package/dist/runCli.d.ts.map +1 -1
- package/dist/runCli.js +155 -177
- package/dist/runCli.js.map +1 -1
- package/dist/search-filters.d.ts +13 -0
- package/dist/search-filters.d.ts.map +1 -0
- package/dist/search-filters.js +59 -0
- package/dist/search-filters.js.map +1 -0
- package/dist/service.d.ts +11 -1
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +51 -13
- package/dist/service.js.map +1 -1
- package/package.json +1 -1
- package/dist/commands/query-graph.d.ts +0 -13
- package/dist/commands/query-graph.d.ts.map +0 -1
- package/dist/commands/query-graph.js +0 -208
- package/dist/commands/query-graph.js.map +0 -1
- package/dist/deep/graph-sampling.d.ts +0 -51
- package/dist/deep/graph-sampling.d.ts.map +0 -1
- package/dist/deep/graph-sampling.js +0 -410
- package/dist/deep/graph-sampling.js.map +0 -1
package/dist/runCli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { installedFirecrawlStatus, installedFirecrawlSearch } from './deep/installed-firecrawl.js';
|
|
2
2
|
import { installedTavilySearch, installedTavilyStatus } from './deep/installed-tavily.js';
|
|
3
|
-
import {
|
|
3
|
+
import { directFilters, isTimeRange } from './search-filters.js';
|
|
4
|
+
import { externalSearch, searchLimits } from './external-search.js';
|
|
4
5
|
import { feedbackLog, feedbackError } from './feedback-log.js';
|
|
5
6
|
/**
|
|
6
7
|
* SearXNG CLI - CLI Runner (Commander-based)
|
|
@@ -15,12 +16,11 @@ import { assertSearXNGConfig } from './service.js';
|
|
|
15
16
|
import { SessionStateError } from './deep/session-lock.js';
|
|
16
17
|
import { createSuccessEnvelope, createErrorEnvelope } from './protocol.js';
|
|
17
18
|
import { SearchError } from './errors.js';
|
|
18
|
-
import { config } from './config.js';
|
|
19
|
+
import { config, EXTERNAL_PROVIDERS } from './config.js';
|
|
19
20
|
import { OllamaService, MAX_RESULTS as OLLAMA_MAX_RESULTS } from './ollama-service.js';
|
|
20
21
|
import { DeepSeekService, MAX_RESULTS as DEEPSEEK_MAX_RESULTS } from './deepseek-service.js';
|
|
21
22
|
import { initConfig } from './init.js';
|
|
22
23
|
import { runExtract } from './commands/extract.js';
|
|
23
|
-
import { runQueryGraph } from './commands/query-graph.js';
|
|
24
24
|
import { runGraphAdd } from './commands/graph-add.js';
|
|
25
25
|
import { runResultsAdd } from './commands/results-add.js';
|
|
26
26
|
import { runDocIndex } from './commands/doc-index.js';
|
|
@@ -35,8 +35,7 @@ import { runSessionList, runSessionDelete } from './commands/session.js';
|
|
|
35
35
|
import { graphPreprocess } from './deep/graph-preprocess.js';
|
|
36
36
|
import { checkQueryRedundancy } from './deep/query-redundancy.js';
|
|
37
37
|
import { buildPendingReport, describeResult } from './deep/pending-facts.js';
|
|
38
|
-
import {
|
|
39
|
-
import { determineSearchStage, getStrategyInfo } from './deep/search-strategy.js';
|
|
38
|
+
import { getStrategyInfo } from './deep/search-strategy.js';
|
|
40
39
|
import { getSessionAnalysis } from './deep/iteration-data.js';
|
|
41
40
|
import { runCoverage } from './commands/coverage.js';
|
|
42
41
|
import { runGraphExplore } from './commands/graph-explore.js';
|
|
@@ -76,28 +75,56 @@ function agreementLabel(votes) {
|
|
|
76
75
|
const parts = votes.map(vote => `${vote.engine} #${vote.position}`);
|
|
77
76
|
return ` [${votes.length} engines: ${parts.join(', ')}]`;
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
78
|
+
function searchFilterScope(options, attempts) {
|
|
79
|
+
const requested = {
|
|
80
|
+
...(options.timeRange && { timeRange: options.timeRange }),
|
|
81
|
+
...(options.language && { language: options.language }),
|
|
82
|
+
...(options.page !== undefined && { page: options.page }),
|
|
83
|
+
...(options.categories?.length && { categories: options.categories }),
|
|
84
|
+
};
|
|
85
|
+
const keys = Object.keys(requested);
|
|
86
|
+
if (!keys.length || !attempts.length)
|
|
87
|
+
return {};
|
|
88
|
+
const providers = {};
|
|
89
|
+
for (const attempt of attempts) {
|
|
90
|
+
// All queries in a batch use the same filters. A successful response
|
|
91
|
+
// confirms this route even when another query on the same route failed.
|
|
92
|
+
if (attempt.status === 'error' && providers[attempt.provider])
|
|
93
|
+
continue;
|
|
94
|
+
const mapped = attempt.provider === 'searxng' ? keys : attempt.mapped ?? [];
|
|
95
|
+
providers[attempt.provider] = {
|
|
96
|
+
forwarded: attempt.status === 'ok' ? mapped : [],
|
|
97
|
+
notForwarded: keys.filter(key => !mapped.includes(key)),
|
|
98
|
+
...(attempt.status === 'error' && mapped.length && { unconfirmed: mapped }),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return { filterScope: { requested, providers } };
|
|
102
|
+
}
|
|
103
|
+
function filterScopeNote(scope) {
|
|
104
|
+
if (!scope)
|
|
94
105
|
return '';
|
|
95
|
-
|
|
106
|
+
const lines = [];
|
|
107
|
+
for (const [name, route] of Object.entries(scope.providers)) {
|
|
108
|
+
const values = (keys) => keys.map(key => `${key}=${scope.requested[key]}`).join(', ');
|
|
109
|
+
if (route.forwarded.length)
|
|
110
|
+
lines.push(`${name} forwarded ${values(route.forwarded)}.`);
|
|
111
|
+
if (route.notForwarded.length)
|
|
112
|
+
lines.push(`${name} did not forward ${values(route.notForwarded)}.`);
|
|
113
|
+
if (route.unconfirmed?.length)
|
|
114
|
+
lines.push(`${name} request failed, forwarding unconfirmed for ${values(route.unconfirmed)}.`);
|
|
115
|
+
}
|
|
116
|
+
return lines.join('\n');
|
|
96
117
|
}
|
|
97
118
|
function formatAsMarkdown(data) {
|
|
98
119
|
const lines = [];
|
|
99
120
|
lines.push(`## Search: ${data.query || 'Unknown'}`);
|
|
100
121
|
lines.push('');
|
|
122
|
+
const answers = (data.answers ?? []).map((answer) => typeof answer === 'string' ? answer : answer?.answer ?? JSON.stringify(answer)).filter(Boolean);
|
|
123
|
+
if (answers.length) {
|
|
124
|
+
lines.push('**Direct answers**', '');
|
|
125
|
+
for (const answer of answers)
|
|
126
|
+
lines.push(answer, '');
|
|
127
|
+
}
|
|
101
128
|
const results = data.results || [];
|
|
102
129
|
if (results.length > 0) {
|
|
103
130
|
lines.push(`**${results.length}** results`);
|
|
@@ -110,6 +137,8 @@ function formatAsMarkdown(data) {
|
|
|
110
137
|
}
|
|
111
138
|
lines.push(`### ${i + 1}. [${r.title || 'No Title'}](${r.url || '#'})${scoreIndicator}${agreementLabel(r.votes)}`);
|
|
112
139
|
lines.push('');
|
|
140
|
+
if (r.imageUrl)
|
|
141
|
+
lines.push(`[Image](${r.imageUrl})`, '');
|
|
113
142
|
if (displayText(r)) {
|
|
114
143
|
lines.push(displayText(r));
|
|
115
144
|
lines.push('');
|
|
@@ -132,11 +161,15 @@ function formatAsMarkdown(data) {
|
|
|
132
161
|
lines.push('');
|
|
133
162
|
}
|
|
134
163
|
}
|
|
135
|
-
else {
|
|
164
|
+
else if (!answers.length) {
|
|
136
165
|
lines.push('No results found.');
|
|
137
166
|
lines.push('');
|
|
138
167
|
}
|
|
139
168
|
if (data.providerResults?.length) {
|
|
169
|
+
for (const item of data.providerResults) {
|
|
170
|
+
if (item.paginationError)
|
|
171
|
+
lines.push(`Partial ${item.provider} results: page ${item.paginationError.page} failed (${item.paginationError.code}).`, '');
|
|
172
|
+
}
|
|
140
173
|
lines.push('**Search providers:** ' + data.providerResults.map((item) => `${item.provider} (${item.query}): ${item.status}${item.error ? ` (${item.error})` : ''}, received ${item.received}, returned ${item.returned}`).join(' · '));
|
|
141
174
|
lines.push('');
|
|
142
175
|
}
|
|
@@ -151,7 +184,7 @@ function formatAsMarkdown(data) {
|
|
|
151
184
|
lines.push(`*Unresponsive: ${unresponsive}*`);
|
|
152
185
|
lines.push('');
|
|
153
186
|
}
|
|
154
|
-
const note = filterScopeNote(data);
|
|
187
|
+
const note = filterScopeNote(data.filterScope);
|
|
155
188
|
if (note) {
|
|
156
189
|
lines.push(note);
|
|
157
190
|
lines.push('');
|
|
@@ -245,42 +278,6 @@ function formatFactsAsMarkdown(facts) {
|
|
|
245
278
|
}
|
|
246
279
|
return lines.join('\n');
|
|
247
280
|
}
|
|
248
|
-
function formatSuggestAsMarkdown(data) {
|
|
249
|
-
const lines = [];
|
|
250
|
-
lines.push('## Query Suggestion Data');
|
|
251
|
-
lines.push('');
|
|
252
|
-
lines.push(`**Current Stage:** ${data.currentStage}`);
|
|
253
|
-
lines.push('');
|
|
254
|
-
if (data.topEntities?.length) {
|
|
255
|
-
lines.push('### Top Entities');
|
|
256
|
-
lines.push('');
|
|
257
|
-
lines.push('| Entity | Obfuscated Label | Degree | Frequency | Type |');
|
|
258
|
-
lines.push('|--------|------------------|--------|-----------|------|');
|
|
259
|
-
for (const e of data.topEntities.slice(0, 15)) {
|
|
260
|
-
lines.push(`| ${e.label} | ${e.obfuscatedLabel || '-'} | ${e.degree} | ${e.frequency} | ${e.entityType || '-'} |`);
|
|
261
|
-
}
|
|
262
|
-
lines.push('');
|
|
263
|
-
}
|
|
264
|
-
if (data.unexploredDomains?.length) {
|
|
265
|
-
lines.push('### Unexplored Domains');
|
|
266
|
-
lines.push('');
|
|
267
|
-
for (const d of data.unexploredDomains) {
|
|
268
|
-
lines.push(`- ${d}`);
|
|
269
|
-
}
|
|
270
|
-
lines.push('');
|
|
271
|
-
}
|
|
272
|
-
if (data.roundHistory?.length) {
|
|
273
|
-
lines.push('### Round History');
|
|
274
|
-
lines.push('');
|
|
275
|
-
lines.push('| Round | Query | Results |');
|
|
276
|
-
lines.push('|-------|-------|---------|');
|
|
277
|
-
for (const r of data.roundHistory) {
|
|
278
|
-
lines.push(`| ${r.round} | ${r.query} | ${r.resultCount} |`);
|
|
279
|
-
}
|
|
280
|
-
lines.push('');
|
|
281
|
-
}
|
|
282
|
-
return lines.join('\n');
|
|
283
|
-
}
|
|
284
281
|
function formatStrategyAsMarkdown(data) {
|
|
285
282
|
const lines = [];
|
|
286
283
|
lines.push('## Search Strategy Info');
|
|
@@ -338,25 +335,23 @@ function formatSessionReportAsMarkdown(data) {
|
|
|
338
335
|
* Search providers reachable through `--engines` magic words. Each is selected
|
|
339
336
|
* by placing its name in the engine list; every other name goes to SearXNG.
|
|
340
337
|
*/
|
|
341
|
-
const EXTERNAL_PROVIDERS = ['ollama', 'deepseek', 'exa', 'tavily', 'firecrawl', 'jina'];
|
|
342
338
|
const PROVIDER_IMPLS = {
|
|
343
339
|
ollama: {
|
|
344
|
-
configured: () => Boolean(config.ollamaApiKey),
|
|
345
340
|
maxResults: OLLAMA_MAX_RESULTS,
|
|
346
341
|
search: (query, limit) => new OllamaService({ apiKey: config.ollamaApiKey }).search({ query, limit }),
|
|
347
342
|
},
|
|
348
343
|
deepseek: {
|
|
349
|
-
configured: () => Boolean(config.deepseekApiKey),
|
|
350
344
|
maxResults: DEEPSEEK_MAX_RESULTS,
|
|
351
345
|
search: (query, limit) => new DeepSeekService({ apiKey: config.deepseekApiKey }).search({ query, limit }),
|
|
352
346
|
},
|
|
353
|
-
exa: {
|
|
354
|
-
tavily: {
|
|
355
|
-
firecrawl: {
|
|
356
|
-
jina: {
|
|
347
|
+
exa: { maxResults: searchLimits.exa, search: (query, limit, params) => externalSearch('exa', config.exaApiKey, query, limit, params) },
|
|
348
|
+
tavily: { maxResults: searchLimits.tavily, search: (query, limit, params) => externalSearch('tavily', config.tavilyApiKey, query, limit, params) },
|
|
349
|
+
firecrawl: { maxResults: searchLimits.firecrawl, search: (query, limit, params) => externalSearch('firecrawl', config.firecrawlApiKey, query, limit, params) },
|
|
350
|
+
jina: { maxResults: searchLimits.jina, search: (query, limit, params) => externalSearch('jina', config.jinaApiKey, query, limit, params) },
|
|
357
351
|
};
|
|
352
|
+
const hostSearchHint = 'If your Agent host offers the requested source, call its search tool. To save those results, pipe them to dg results-add <session> --kind search --tool <tool> --query "<query>" --data-stdin.';
|
|
358
353
|
async function configuredExternalProviders() {
|
|
359
|
-
const providers = EXTERNAL_PROVIDERS.filter(p =>
|
|
354
|
+
const providers = EXTERNAL_PROVIDERS.filter(p => config[`${p}ApiKey`]);
|
|
360
355
|
const tavilyCli = await installedTavilyStatus();
|
|
361
356
|
const firecrawlCli = await installedFirecrawlStatus();
|
|
362
357
|
if (!providers.includes('firecrawl') && firecrawlCli === 'authenticated')
|
|
@@ -372,6 +367,7 @@ async function configuredExternalProviders() {
|
|
|
372
367
|
function summarizeAttempts(attempts, returnedKeys) {
|
|
373
368
|
return attempts.map(attempt => attempt.status === 'ok' ? {
|
|
374
369
|
query: attempt.query, provider: attempt.provider, status: 'ok', received: attempt.response.results.length,
|
|
370
|
+
...(attempt.response.paginationError && { paginationError: attempt.response.paginationError }),
|
|
375
371
|
returned: new Set(attempt.response.results.map(result => resultUrlKey(result)).filter(key => returnedKeys.has(key))).size,
|
|
376
372
|
} : {
|
|
377
373
|
query: attempt.query, provider: attempt.provider, status: 'error', received: 0, returned: 0,
|
|
@@ -381,10 +377,11 @@ function summarizeAttempts(attempts, returnedKeys) {
|
|
|
381
377
|
}
|
|
382
378
|
function planProviderSearch(engines, tavilyCli = false, firecrawlCli = false) {
|
|
383
379
|
const selected = EXTERNAL_PROVIDERS.filter(p => engines.includes(p));
|
|
380
|
+
const usable = selected.filter(p => config[`${p}ApiKey`] || (p === 'tavily' && tavilyCli) || (p === 'firecrawl' && firecrawlCli));
|
|
384
381
|
return {
|
|
385
382
|
tavilyCli, firecrawlCli,
|
|
386
|
-
usable
|
|
387
|
-
unconfigured: selected.filter(p => !
|
|
383
|
+
usable,
|
|
384
|
+
unconfigured: selected.filter(p => !usable.includes(p)),
|
|
388
385
|
sxngEngines: engines.filter(e => !EXTERNAL_PROVIDERS.includes(e)),
|
|
389
386
|
};
|
|
390
387
|
}
|
|
@@ -401,13 +398,14 @@ async function searchOneQuery(service, plan, searchOptions, limit) {
|
|
|
401
398
|
const attempts = [];
|
|
402
399
|
const limitNotes = [];
|
|
403
400
|
for (const provider of plan.usable) {
|
|
401
|
+
const { params, forwarded } = directFilters(provider, searchOptions);
|
|
404
402
|
const started = Date.now();
|
|
405
403
|
feedbackLog('provider', 'start', { provider });
|
|
406
404
|
try {
|
|
407
405
|
const response = provider === 'tavily' && plan.tavilyCli
|
|
408
|
-
? await installedTavilySearch(searchOptions.query, limit)
|
|
409
|
-
: provider === 'firecrawl' && plan.firecrawlCli ? await installedFirecrawlSearch(searchOptions.query, limit)
|
|
410
|
-
: await PROVIDER_IMPLS[provider].search(searchOptions.query, limit);
|
|
406
|
+
? await installedTavilySearch(searchOptions.query, limit, params)
|
|
407
|
+
: provider === 'firecrawl' && plan.firecrawlCli ? await installedFirecrawlSearch(searchOptions.query, limit, params)
|
|
408
|
+
: await PROVIDER_IMPLS[provider].search(searchOptions.query, limit, params);
|
|
411
409
|
feedbackLog('provider', 'ok', { provider, durationMs: Date.now() - started, count: response.results.length });
|
|
412
410
|
// The provider caps the count itself, so compare against its ceiling
|
|
413
411
|
// rather than against what came back: a provider may also return
|
|
@@ -417,11 +415,11 @@ async function searchOneQuery(service, plan, searchOptions, limit) {
|
|
|
417
415
|
if (limit > applied)
|
|
418
416
|
limitNotes.push({ provider, requested: limit, applied });
|
|
419
417
|
providerResponses.push(response);
|
|
420
|
-
attempts.push({ provider, query: searchOptions.query, status: 'ok', response });
|
|
418
|
+
attempts.push({ provider, query: searchOptions.query, mapped: forwarded, status: 'ok', response });
|
|
421
419
|
}
|
|
422
420
|
catch (error) {
|
|
423
421
|
feedbackLog('provider', 'error', { provider, durationMs: Date.now() - started, error: feedbackError(error) });
|
|
424
|
-
attempts.push({ provider, query: searchOptions.query, status: 'error', error });
|
|
422
|
+
attempts.push({ provider, query: searchOptions.query, mapped: forwarded, status: 'error', error });
|
|
425
423
|
}
|
|
426
424
|
}
|
|
427
425
|
let sxngResponse = null;
|
|
@@ -450,19 +448,29 @@ function originTool(engine) {
|
|
|
450
448
|
async function runSearchInner(service, options) {
|
|
451
449
|
feedbackLog('validation', 'start');
|
|
452
450
|
if (options.limit !== undefined && (!Number.isSafeInteger(options.limit) || options.limit <= 0)) {
|
|
453
|
-
feedbackLog('validation', 'error', { error: '
|
|
451
|
+
feedbackLog('validation', 'error', { error: 'INVALID_LIMIT' });
|
|
454
452
|
console.log(JSON.stringify(createErrorEnvelope('INVALID_LIMIT', 'Limit must be a positive safe integer'), null, 2));
|
|
455
453
|
return 1;
|
|
456
454
|
}
|
|
457
|
-
|
|
455
|
+
if (options.page !== undefined && (!Number.isSafeInteger(options.page) || options.page <= 0)) {
|
|
456
|
+
console.log(JSON.stringify(createErrorEnvelope('INVALID_PAGE', 'Page must be a positive safe integer'), null, 2));
|
|
457
|
+
return 1;
|
|
458
|
+
}
|
|
459
|
+
const timeRange = options.timeRange;
|
|
460
|
+
if (timeRange !== undefined && !isTimeRange(timeRange)) {
|
|
461
|
+
console.log(JSON.stringify(createErrorEnvelope('INVALID_TIME_RANGE', 'Time range must be day, week, month, year or all'), null, 2));
|
|
462
|
+
return 1;
|
|
463
|
+
}
|
|
464
|
+
const filters = { timeRange, language: options.language, page: options.page, categories: options.categories };
|
|
465
|
+
let queries = options.queries ? [...new Set(options.queries)] : (options.query ? [options.query] : []);
|
|
458
466
|
if (queries.length === 0) {
|
|
459
|
-
feedbackLog('validation', 'error', { error: '
|
|
467
|
+
feedbackLog('validation', 'error', { error: 'MISSING_QUERY' });
|
|
460
468
|
const envelope = createErrorEnvelope('MISSING_QUERY', 'No search query provided', { hint: 'Use: dg "your search query" or dg --queries "q1,q2,q3"' });
|
|
461
469
|
console.log(JSON.stringify(envelope, null, 2));
|
|
462
470
|
return 1;
|
|
463
471
|
}
|
|
464
472
|
if (options.engines && options.engines.length === 0) {
|
|
465
|
-
feedbackLog('validation', 'error', { error: '
|
|
473
|
+
feedbackLog('validation', 'error', { error: 'INVALID_ENGINES' });
|
|
466
474
|
console.log(JSON.stringify(createErrorEnvelope('INVALID_ENGINES', 'At least one engine must be specified'), null, 2));
|
|
467
475
|
return 1;
|
|
468
476
|
}
|
|
@@ -470,25 +478,30 @@ async function runSearchInner(service, options) {
|
|
|
470
478
|
if (config.allowedEngines.length > 0) {
|
|
471
479
|
const invalid = engines.filter(e => !config.allowedEngines.includes(e));
|
|
472
480
|
if (invalid.length > 0) {
|
|
473
|
-
feedbackLog('validation', 'error', { error: '
|
|
481
|
+
feedbackLog('validation', 'error', { error: 'INVALID_ENGINES' });
|
|
474
482
|
const envelope = createErrorEnvelope('INVALID_ENGINES', `Engines not allowed: ${invalid.join(', ')}`, { hint: `Allowed engines: ${config.allowedEngines.join(', ')}` });
|
|
475
483
|
console.log(JSON.stringify(envelope, null, 2));
|
|
476
484
|
return 1;
|
|
477
485
|
}
|
|
478
486
|
}
|
|
479
487
|
const tavilyStatus = engines.includes('tavily') ? await installedTavilyStatus() : 'not_installed';
|
|
480
|
-
const tavilyCli = tavilyStatus === 'authenticated' || (tavilyStatus === 'keyless' && !
|
|
488
|
+
const tavilyCli = tavilyStatus === 'authenticated' || (tavilyStatus === 'keyless' && !config.tavilyApiKey);
|
|
481
489
|
const firecrawlCli = engines.includes('firecrawl') && await installedFirecrawlStatus() === 'authenticated';
|
|
482
490
|
// A selected provider without its API key cannot run. Failing loudly beats
|
|
483
491
|
// silently answering from SearXNG, which would make the provider look active.
|
|
484
492
|
if (engines.length > 0) {
|
|
485
493
|
const unconfigured = planProviderSearch(engines, tavilyCli, firecrawlCli).unconfigured;
|
|
486
494
|
if (unconfigured.length > 0) {
|
|
487
|
-
feedbackLog('validation', 'error', { error: '
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
495
|
+
feedbackLog('validation', 'error', { error: 'PROVIDER_NOT_CONFIGURED' });
|
|
496
|
+
const directHints = unconfigured.map(provider => {
|
|
497
|
+
const keyHint = `Run dg init or set "${provider}ApiKey" in digdig.config.json.`;
|
|
498
|
+
if (provider === 'tavily')
|
|
499
|
+
return `${keyHint} The tvly CLI is also supported.`;
|
|
500
|
+
if (provider === 'firecrawl')
|
|
501
|
+
return `${keyHint} An authenticated official firecrawl CLI is also supported.`;
|
|
502
|
+
return keyHint;
|
|
503
|
+
});
|
|
504
|
+
const envelope = createErrorEnvelope('PROVIDER_NOT_CONFIGURED', `Search provider unavailable to the dg CLI: ${unconfigured.join(', ')}`, { hint: [...directHints, hostSearchHint].join(' ') });
|
|
492
505
|
console.log(JSON.stringify(envelope, null, 2));
|
|
493
506
|
return 1;
|
|
494
507
|
}
|
|
@@ -597,8 +610,7 @@ async function runSearchInner(service, options) {
|
|
|
597
610
|
}
|
|
598
611
|
feedbackLog('redundancy', 'ok', { count: adjustedQueries.length, failed: skippedQueries.length });
|
|
599
612
|
// Replace queries with adjusted ones (skipped ones removed)
|
|
600
|
-
queries
|
|
601
|
-
queries.push(...adjustedQueries);
|
|
613
|
+
queries = [...new Set(adjustedQueries)];
|
|
602
614
|
}
|
|
603
615
|
const attempts = [];
|
|
604
616
|
try {
|
|
@@ -630,11 +642,8 @@ async function runSearchInner(service, options) {
|
|
|
630
642
|
const searchOptions = {
|
|
631
643
|
query,
|
|
632
644
|
engines,
|
|
633
|
-
|
|
645
|
+
...filters,
|
|
634
646
|
limit,
|
|
635
|
-
page: options.page,
|
|
636
|
-
language: options.language,
|
|
637
|
-
timeRange: options.timeRange,
|
|
638
647
|
};
|
|
639
648
|
const { providerResponses, sxngResponse, limitNotes: notes, attempts: queryAttempts } = await searchOneQuery(service, plan, searchOptions, limit);
|
|
640
649
|
attempts.push(...queryAttempts);
|
|
@@ -670,11 +679,9 @@ async function runSearchInner(service, options) {
|
|
|
670
679
|
let sessionInfo = null;
|
|
671
680
|
if (options.session) {
|
|
672
681
|
feedbackLog('session', 'start');
|
|
673
|
-
sessionInfo = appendAndInjectSessionResults(options.session, fusion.display.map(
|
|
682
|
+
sessionInfo = appendAndInjectSessionResults(options.session, fusion.display.map(result => ({
|
|
674
683
|
...result,
|
|
675
|
-
//
|
|
676
|
-
// order instead of one provider's and one RRF's.
|
|
677
|
-
rank: index + 1,
|
|
684
|
+
// `rank` comes from the fusion, so it is not restated here.
|
|
678
685
|
origins: fusion.originsByKey.get(resultUrlKey(result)),
|
|
679
686
|
})), searchRound);
|
|
680
687
|
feedbackLog('session', 'ok', { count: sessionInfo.added, total: sessionInfo.total });
|
|
@@ -683,20 +690,13 @@ async function runSearchInner(service, options) {
|
|
|
683
690
|
console.error(`[session] ${pendingCount} pending results awaiting Agent review. Run --quality to list them.`);
|
|
684
691
|
}
|
|
685
692
|
}
|
|
686
|
-
const meta = mergeEnvelopeMetadata(responses,
|
|
687
|
-
for (const suggestion of mergeMeta.suggestions ?? []) {
|
|
688
|
-
if (!meta.suggestions.includes(suggestion))
|
|
689
|
-
meta.suggestions.push(suggestion);
|
|
690
|
-
}
|
|
691
|
-
for (const answer of mergeMeta.answers ?? []) {
|
|
692
|
-
if (!meta.answers.includes(answer))
|
|
693
|
-
meta.answers.push(answer);
|
|
694
|
-
}
|
|
693
|
+
const meta = mergeEnvelopeMetadata(responses, mergeMeta);
|
|
695
694
|
const outputFormat = (options.format || config.defaultFormat);
|
|
696
695
|
const returnedKeys = new Set(fusion.display.map(result => resultUrlKey(result)));
|
|
697
696
|
const providerResults = summarizeAttempts(attempts, returnedKeys);
|
|
698
697
|
const displayData = {
|
|
699
698
|
providerResults,
|
|
699
|
+
...searchFilterScope(filters, attempts),
|
|
700
700
|
query: queries.length > 1 ? queries.join(' · ') : queries[0],
|
|
701
701
|
queries,
|
|
702
702
|
// The deduplicated candidate pool, not a sum of provider self-reports
|
|
@@ -706,9 +706,7 @@ async function runSearchInner(service, options) {
|
|
|
706
706
|
answers: meta.answers,
|
|
707
707
|
suggestions: meta.suggestions,
|
|
708
708
|
unresponsiveEngines: meta.unresponsiveEngines,
|
|
709
|
-
//
|
|
710
|
-
// unconfirmed. Not part of the result ranking — it describes the
|
|
711
|
-
// request, not any individual result.
|
|
709
|
+
// Original request values. filterScope reports forwarding by provider.
|
|
712
710
|
...(options.timeRange ? { timeRange: options.timeRange } : {}),
|
|
713
711
|
...(options.language ? { language: options.language } : {}),
|
|
714
712
|
// Absent when nothing was capped, so a request the providers could
|
|
@@ -738,6 +736,7 @@ async function runSearchInner(service, options) {
|
|
|
738
736
|
const partialResults = attempts.flatMap(attempt => attempt.status === 'ok' ? attempt.response.results : []);
|
|
739
737
|
const details = attempts.length ? {
|
|
740
738
|
providerResults: summarizeAttempts(attempts, new Set(partialResults.map(result => resultUrlKey(result)))),
|
|
739
|
+
...searchFilterScope(filters, attempts),
|
|
741
740
|
partialResults, sessionWrite: 'unconfirmed',
|
|
742
741
|
} : undefined;
|
|
743
742
|
console.log(JSON.stringify(createErrorEnvelope(error.code, error.message, { retryable: error.code === 'SESSION_BUSY', details }), null, 2));
|
|
@@ -751,13 +750,13 @@ async function runSearchInner(service, options) {
|
|
|
751
750
|
if (error instanceof SearchError) {
|
|
752
751
|
const envelope = createErrorEnvelope(error.code, error.message, {
|
|
753
752
|
retryable: error.retryable,
|
|
754
|
-
hint: error.hint,
|
|
755
|
-
details: { provider: error.provider, ...(error.status === undefined ? {} : { status: error.status }), ...(attempts.length ? { providerResults: summarizeAttempts(attempts, new Set()) } : {}) },
|
|
753
|
+
hint: error.code === 'CONFIG_MISSING' ? `${error.hint} ${hostSearchHint}` : error.hint,
|
|
754
|
+
details: { provider: error.provider, ...(error.status === undefined ? {} : { status: error.status }), ...(attempts.length ? { providerResults: summarizeAttempts(attempts, new Set()) } : {}), ...searchFilterScope(filters, attempts) },
|
|
756
755
|
});
|
|
757
756
|
console.log(JSON.stringify(envelope, null, 2));
|
|
758
757
|
return 1;
|
|
759
758
|
}
|
|
760
|
-
const envelope = createErrorEnvelope('SEARCH_FAILED', attempts.length ? 'Search request failed' : error instanceof Error ? error.message : 'Search request failed', attempts.length ? { details: { providerResults: summarizeAttempts(attempts, new Set()) } } : {});
|
|
759
|
+
const envelope = createErrorEnvelope('SEARCH_FAILED', attempts.length ? 'Search request failed' : error instanceof Error ? error.message : 'Search request failed', attempts.length ? { details: { providerResults: summarizeAttempts(attempts, new Set()), ...searchFilterScope(filters, attempts) } } : {});
|
|
761
760
|
console.log(JSON.stringify(envelope, null, 2));
|
|
762
761
|
return 1;
|
|
763
762
|
}
|
|
@@ -782,7 +781,7 @@ function reportEmptySession(count) {
|
|
|
782
781
|
if (count)
|
|
783
782
|
return false;
|
|
784
783
|
console.log(JSON.stringify(createErrorEnvelope('EMPTY_SESSION', 'This session has no stored results to report on', {
|
|
785
|
-
retryable: false, hint: '
|
|
784
|
+
retryable: false, hint: 'Add host search results with dg results-add or run a dg search with --session before reporting on this session',
|
|
786
785
|
}), null, 2));
|
|
787
786
|
process.exitCode = 1;
|
|
788
787
|
return true;
|
|
@@ -797,7 +796,7 @@ export function createProgram(argv = []) {
|
|
|
797
796
|
.option('-e, --engines <engines>', `Comma-separated list of search engines; "${EXTERNAL_PROVIDERS.join('"/"')}" route to non-SearXNG providers`)
|
|
798
797
|
.option('-c, --categories <cats>', 'Comma-separated list of categories')
|
|
799
798
|
.option('-l, --limit <n>', 'Maximum number of results', parseLimit)
|
|
800
|
-
.option('-p, --page <n>', 'Page number
|
|
799
|
+
.option('-p, --page <n>', 'Page number (SearXNG starts here and fetches more if needed)', parseLimit)
|
|
801
800
|
.option('--lang <code>', 'Language code (e.g., en, zh, ja)')
|
|
802
801
|
.option('--time <range>', 'Time range: day, week, month, year, all')
|
|
803
802
|
.option('-f, --format <fmt>', 'Output format: md (default), json')
|
|
@@ -811,8 +810,11 @@ export function createProgram(argv = []) {
|
|
|
811
810
|
.option('--approve-file <path>', 'UTF-8 approval JSON array under this session agent-inputs directory')
|
|
812
811
|
.option('--skip-file <path>', 'UTF-8 skip JSON array under this session agent-inputs directory')
|
|
813
812
|
.option('--unskip-file <path>', 'UTF-8 restore JSON array under this session agent-inputs directory')
|
|
813
|
+
.option('--approve-stdin', 'Read the approval array from stdin')
|
|
814
|
+
.option('--skip-stdin', 'Read the skip array from stdin')
|
|
815
|
+
.option('--unskip-stdin', 'Read the restore array from stdin')
|
|
814
816
|
.option('--health', 'Check the SearXNG backend health (Ollama/DeepSeek have no health endpoint)')
|
|
815
|
-
.option('--engines-list', 'List
|
|
817
|
+
.option('--engines-list', 'List CLI search engines and provider configuration')
|
|
816
818
|
.option('--categories-list', 'List available categories')
|
|
817
819
|
.allowUnknownOption(false);
|
|
818
820
|
program
|
|
@@ -837,12 +839,12 @@ export function createProgram(argv = []) {
|
|
|
837
839
|
obscuraPath: opts.obscuraPath,
|
|
838
840
|
obscuraDumpFormat: opts.obscuraDump === 'markdown' ? 'markdown' : 'html',
|
|
839
841
|
jina: opts.jina ?? false,
|
|
840
|
-
jinaApiKey:
|
|
842
|
+
jinaApiKey: config.jinaApiKey,
|
|
841
843
|
useInstalledTavily: true,
|
|
842
844
|
useInstalledFirecrawl: true,
|
|
843
845
|
externalKeys: {
|
|
844
|
-
exa:
|
|
845
|
-
firecrawl:
|
|
846
|
+
exa: config.exaApiKey, tavily: config.tavilyApiKey,
|
|
847
|
+
firecrawl: config.firecrawlApiKey,
|
|
846
848
|
ollama: config.ollamaApiKey,
|
|
847
849
|
deepseek: config.deepseekApiKey,
|
|
848
850
|
},
|
|
@@ -857,35 +859,17 @@ export function createProgram(argv = []) {
|
|
|
857
859
|
const code = await runExtract(extractor, extractOptions);
|
|
858
860
|
process.exitCode = code;
|
|
859
861
|
});
|
|
860
|
-
program
|
|
861
|
-
.command('query-graph')
|
|
862
|
-
.argument('<path>', 'Graph file or session name')
|
|
863
|
-
.description('[DEPRECATED] Query subgraph via BFS. Use graph-explore + graph-drill instead.')
|
|
864
|
-
.option('--seeds <s1,s2>', 'Seed nodes for BFS')
|
|
865
|
-
.option('--depth <n>', 'BFS depth (default: 2)', val => parseInt(val, 10), 2)
|
|
866
|
-
.option('--strategy <strategy>', 'Sampling strategy: augmented_chain | dual_core_bridge | community_core_path | deep_chain | mixed')
|
|
867
|
-
.option('-f, --format <fmt>', 'Output format: md, json')
|
|
868
|
-
.action(async (path, opts, command) => {
|
|
869
|
-
console.warn('[DEPRECATED] query-graph is deprecated. Use graph-explore + graph-drill instead.');
|
|
870
|
-
const graphFormat = command.optsWithGlobals().format === 'json' ? 'json' : 'md';
|
|
871
|
-
const code = await runQueryGraph({
|
|
872
|
-
graphFile: path,
|
|
873
|
-
seeds: opts.seeds?.split(',').map((s) => s.trim()).filter(Boolean) || [],
|
|
874
|
-
depth: opts.depth ?? 2,
|
|
875
|
-
format: graphFormat,
|
|
876
|
-
strategy: opts.strategy,
|
|
877
|
-
});
|
|
878
|
-
process.exitCode = code;
|
|
879
|
-
});
|
|
880
862
|
program
|
|
881
863
|
.command('graph-add')
|
|
882
864
|
.argument('<session>', 'Session directory or name')
|
|
883
865
|
.description('Add semantic entities/edges supported by approved extracted result IDs.')
|
|
884
|
-
.
|
|
866
|
+
.option('--data-file <path>', 'UTF-8 JSON under this session agent-inputs directory')
|
|
867
|
+
.option('--data-stdin', 'Read the same JSON from stdin instead of a file')
|
|
885
868
|
.action(async (session, opts) => {
|
|
886
869
|
const code = await runGraphAdd({
|
|
887
870
|
session,
|
|
888
871
|
dataFile: opts.dataFile,
|
|
872
|
+
dataStdin: opts.dataStdin ?? false,
|
|
889
873
|
});
|
|
890
874
|
process.exitCode = code;
|
|
891
875
|
});
|
|
@@ -894,12 +878,14 @@ export function createProgram(argv = []) {
|
|
|
894
878
|
.argument('<session>', 'Session directory or name')
|
|
895
879
|
.description('Import external search records or extracted bodies into a session')
|
|
896
880
|
.requiredOption('--kind <kind>', 'Import kind: search or extracted')
|
|
897
|
-
.
|
|
881
|
+
.option('--data-file <path>', 'UTF-8 JSON under this session agent-inputs directory')
|
|
882
|
+
.option('--data-stdin', 'Read the same JSON from stdin instead of a file')
|
|
898
883
|
.option('--query <query>', 'Discovery query (may instead be supplied per item)')
|
|
899
884
|
.option('--tool <tool>', 'Origin tool (may instead be supplied per item)')
|
|
900
885
|
.addHelpText('after', `
|
|
901
886
|
Examples:
|
|
902
887
|
dg results-add my-session --kind search --tool exa --query "async runtime" --data-file .digdig/sessions/my-session/agent-inputs/results.json
|
|
888
|
+
dg results-add my-session --kind extracted --data-stdin < results.json
|
|
903
889
|
|
|
904
890
|
Search imports await extraction; extracted imports await approval.`)
|
|
905
891
|
.action(async (session, opts) => {
|
|
@@ -907,6 +893,7 @@ Search imports await extraction; extracted imports await approval.`)
|
|
|
907
893
|
session,
|
|
908
894
|
kind: opts.kind,
|
|
909
895
|
dataFile: opts.dataFile,
|
|
896
|
+
dataStdin: opts.dataStdin ?? false,
|
|
910
897
|
query: opts.query,
|
|
911
898
|
tool: opts.tool,
|
|
912
899
|
});
|
|
@@ -1048,31 +1035,7 @@ Examples:
|
|
|
1048
1035
|
console.log(JSON.stringify(createSuccessEnvelope(listPendingGraph(resolveSessionPath(session))), null, 2));
|
|
1049
1036
|
process.exitCode = 0;
|
|
1050
1037
|
});
|
|
1051
|
-
program
|
|
1052
|
-
.command('suggest-queries')
|
|
1053
|
-
.argument('<session>', 'Session directory or name')
|
|
1054
|
-
.description('Output query suggestion data for Agent follow-up query generation')
|
|
1055
|
-
.option('-f, --format <fmt>', 'Output format: json (default), md')
|
|
1056
|
-
.addHelpText('after', `
|
|
1057
|
-
Examples:
|
|
1058
|
-
dg suggest-queries my-session
|
|
1059
|
-
dg suggest-queries my-session --format md`)
|
|
1060
|
-
.action(async (session, opts, command) => {
|
|
1061
|
-
const sessionDir = resolveSessionPath(session);
|
|
1062
|
-
const results = loadSessionResults(sessionDir);
|
|
1063
|
-
if (reportEmptySession(results.length))
|
|
1064
|
-
return;
|
|
1065
|
-
const graph = loadSessionGraph(sessionDir);
|
|
1066
|
-
const stage = determineSearchStage(graph, undefined, loadSessionRounds(sessionDir));
|
|
1067
|
-
const data = generateQuerySuggestions(graph, results, stage);
|
|
1068
|
-
if (command.optsWithGlobals().format === 'md') {
|
|
1069
|
-
console.log(formatSuggestAsMarkdown(data));
|
|
1070
|
-
}
|
|
1071
|
-
else {
|
|
1072
|
-
console.log(JSON.stringify(createSuccessEnvelope(data), null, 2));
|
|
1073
|
-
}
|
|
1074
|
-
process.exitCode = 0;
|
|
1075
|
-
});
|
|
1038
|
+
program;
|
|
1076
1039
|
program
|
|
1077
1040
|
.command('strategy-info')
|
|
1078
1041
|
.argument('<session>', 'Session directory or name')
|
|
@@ -1221,15 +1184,20 @@ See also: graph-explore (for viewing relations of a known entity)`)
|
|
|
1221
1184
|
.description('Add claims (single or batch) with auto evidence-search')
|
|
1222
1185
|
.option('--claim-file <path>', 'UTF-8 JSON file with one claim')
|
|
1223
1186
|
.option('--claims-file <path>', 'UTF-8 JSON file with a claim array')
|
|
1187
|
+
.option('--claim-stdin', 'Read one claim from stdin')
|
|
1188
|
+
.option('--claims-stdin', 'Read a claim array from stdin')
|
|
1224
1189
|
.option('-f, --format <fmt>', 'Output format: json (default), md')
|
|
1225
1190
|
.addHelpText('after', `
|
|
1226
1191
|
Examples:
|
|
1227
1192
|
dg claim-add my-session --claim-file .digdig/sessions/my-session/agent-inputs/claim.json
|
|
1228
|
-
dg claim-add my-session --claims-file .digdig/sessions/my-session/agent-inputs/claims.json
|
|
1193
|
+
dg claim-add my-session --claims-file .digdig/sessions/my-session/agent-inputs/claims.json
|
|
1194
|
+
dg claim-add my-session --claims-stdin < claims.json`)
|
|
1229
1195
|
.action(async (session, opts, command) => {
|
|
1230
1196
|
const code = await runClaimAdd(session, {
|
|
1231
1197
|
claimFile: opts.claimFile,
|
|
1232
1198
|
claimsFile: opts.claimsFile,
|
|
1199
|
+
claimStdin: opts.claimStdin ?? false,
|
|
1200
|
+
claimsStdin: opts.claimsStdin ?? false,
|
|
1233
1201
|
format: command.optsWithGlobals().format,
|
|
1234
1202
|
});
|
|
1235
1203
|
process.exitCode = code;
|
|
@@ -1265,7 +1233,8 @@ Examples:
|
|
|
1265
1233
|
.argument('<session>', 'Session directory or name')
|
|
1266
1234
|
.description('Confirm evidence + submit stance + optional auto-policy')
|
|
1267
1235
|
.requiredOption('--claim-id <id>', 'Claim ID')
|
|
1268
|
-
.
|
|
1236
|
+
.option('--evidence-file <path>', 'UTF-8 JSON file with evidence object under this session agent-inputs directory')
|
|
1237
|
+
.option('--evidence-stdin', 'Read the same JSON from stdin instead of a file')
|
|
1269
1238
|
.requiredOption('--stance <s>', 'Stance: support, refute, insufficient')
|
|
1270
1239
|
.requiredOption('--reason <text>', 'Judgement rationale')
|
|
1271
1240
|
.option('--confidence <n>', 'Confidence 0-1')
|
|
@@ -1275,6 +1244,7 @@ Examples:
|
|
|
1275
1244
|
const code = await runEvidenceVerify(session, {
|
|
1276
1245
|
claimId: opts.claimId,
|
|
1277
1246
|
evidenceFile: opts.evidenceFile,
|
|
1247
|
+
evidenceStdin: opts.evidenceStdin ?? false,
|
|
1278
1248
|
stance: opts.stance,
|
|
1279
1249
|
reason: opts.reason,
|
|
1280
1250
|
confidence: opts.confidence === undefined ? undefined : (opts.confidence.trim() ? Number(opts.confidence) : NaN),
|
|
@@ -1317,7 +1287,8 @@ Examples:
|
|
|
1317
1287
|
.description('List or record source independence judgments')
|
|
1318
1288
|
.requiredOption('--claim-id <id>', 'Claim ID')
|
|
1319
1289
|
.option('--data-file <path>', 'Judgment or revocation JSON in agent-inputs')
|
|
1320
|
-
.
|
|
1290
|
+
.option('--data-stdin', 'Read the same JSON from stdin instead of a file')
|
|
1291
|
+
.action(async (session, opts) => { process.exitCode = await runSourceRelations(session, { claimId: opts.claimId, dataFile: opts.dataFile, dataStdin: opts.dataStdin ?? false }); });
|
|
1321
1292
|
program
|
|
1322
1293
|
.command('policy-aggregate')
|
|
1323
1294
|
.argument('<session>', 'Session directory or name')
|
|
@@ -1390,19 +1361,24 @@ export async function runCli(args, service) {
|
|
|
1390
1361
|
}
|
|
1391
1362
|
const sessionDir = resolveSessionPath(opts.session);
|
|
1392
1363
|
const sessionResults = loadSessionResults(sessionDir);
|
|
1393
|
-
|
|
1364
|
+
const approving = Boolean(opts.approveFile || opts.approveStdin);
|
|
1365
|
+
const changingSkip = Boolean(opts.skipFile || opts.skipStdin || opts.unskipFile || opts.unskipStdin);
|
|
1366
|
+
if (!approving && !changingSkip && reportEmptySession(sessionResults.length))
|
|
1394
1367
|
return;
|
|
1395
1368
|
const sessionGraph = loadSessionGraph(sessionDir);
|
|
1396
|
-
const readSelections = (option, file) => {
|
|
1397
|
-
const input = readSessionJsonInput(sessionDir, [
|
|
1369
|
+
const readSelections = (option, file, stdin) => {
|
|
1370
|
+
const input = readSessionJsonInput(sessionDir, [
|
|
1371
|
+
{ option, value: file, file: true },
|
|
1372
|
+
{ option: `${option.slice(0, -'-file'.length)}-stdin`, stdin },
|
|
1373
|
+
]);
|
|
1398
1374
|
if (!input.ok || !Array.isArray(input.value) || !input.value.every(item => typeof item === 'object' && item !== null && typeof item.id === 'string' && Number.isSafeInteger(item.revision))) {
|
|
1399
1375
|
console.log(JSON.stringify(createErrorEnvelope(input.ok ? 'INVALID_APPROVAL_SELECTION' : input.code, input.ok ? `${option} must contain an array of {id, revision}` : input.message), null, 2));
|
|
1400
1376
|
return undefined;
|
|
1401
1377
|
}
|
|
1402
1378
|
return input.value;
|
|
1403
1379
|
};
|
|
1404
|
-
const applySkip = (option, file, skipped) => {
|
|
1405
|
-
const selections = readSelections(option, file);
|
|
1380
|
+
const applySkip = (option, file, stdin, skipped) => {
|
|
1381
|
+
const selections = readSelections(option, file, stdin);
|
|
1406
1382
|
if (!selections)
|
|
1407
1383
|
return false;
|
|
1408
1384
|
const result = setSkipped(sessionDir, selections, skipped);
|
|
@@ -1413,13 +1389,15 @@ export async function runCli(args, service) {
|
|
|
1413
1389
|
console.log(JSON.stringify(createSuccessEnvelope({ changed: result.changed, skipped, results: result.results.map(item => ({ id: item.id, revision: item.revision, skippedAt: item.skippedAt })) }), null, 2));
|
|
1414
1390
|
return true;
|
|
1415
1391
|
};
|
|
1416
|
-
if (
|
|
1417
|
-
if (opts.skipFile && opts.unskipFile) {
|
|
1418
|
-
console.log(JSON.stringify(createErrorEnvelope('MULTIPLE_SKIP_ACTIONS', 'Use only one of --skip-file or --unskip-
|
|
1392
|
+
if (changingSkip) {
|
|
1393
|
+
if ((opts.skipFile || opts.skipStdin) && (opts.unskipFile || opts.unskipStdin)) {
|
|
1394
|
+
console.log(JSON.stringify(createErrorEnvelope('MULTIPLE_SKIP_ACTIONS', 'Use only one of --skip-file, --skip-stdin, --unskip-file or --unskip-stdin'), null, 2));
|
|
1419
1395
|
process.exitCode = 1;
|
|
1420
1396
|
return;
|
|
1421
1397
|
}
|
|
1422
|
-
|
|
1398
|
+
const skipping = Boolean(opts.skipFile || opts.skipStdin);
|
|
1399
|
+
const option = skipping ? '--skip-file' : '--unskip-file';
|
|
1400
|
+
process.exitCode = applySkip(option, opts.skipFile ?? opts.unskipFile, skipping ? opts.skipStdin : opts.unskipStdin, skipping) ? 0 : 1;
|
|
1423
1401
|
return;
|
|
1424
1402
|
}
|
|
1425
1403
|
// Get pending results for Agent review
|
|
@@ -1427,8 +1405,8 @@ export async function runCli(args, service) {
|
|
|
1427
1405
|
const facts = buildPendingReport(sessionResults, pending);
|
|
1428
1406
|
// Approval is allowed only after reporting what is waiting and how
|
|
1429
1407
|
// much of it carries a body.
|
|
1430
|
-
if (
|
|
1431
|
-
const selections = readSelections('--approve-file', opts.approveFile);
|
|
1408
|
+
if (approving) {
|
|
1409
|
+
const selections = readSelections('--approve-file', opts.approveFile, opts.approveStdin);
|
|
1432
1410
|
if (!selections) {
|
|
1433
1411
|
process.exitCode = 1;
|
|
1434
1412
|
return;
|