digdig 0.1.0 → 0.1.2

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.
Files changed (97) hide show
  1. package/README.md +44 -9
  2. package/dist/commands/claim.d.ts +2 -0
  3. package/dist/commands/claim.d.ts.map +1 -1
  4. package/dist/commands/claim.js +3 -1
  5. package/dist/commands/claim.js.map +1 -1
  6. package/dist/commands/doc-search.d.ts.map +1 -1
  7. package/dist/commands/doc-search.js +14 -1
  8. package/dist/commands/doc-search.js.map +1 -1
  9. package/dist/commands/evidence.d.ts +6 -0
  10. package/dist/commands/evidence.d.ts.map +1 -1
  11. package/dist/commands/evidence.js +4 -1
  12. package/dist/commands/evidence.js.map +1 -1
  13. package/dist/commands/graph-add.d.ts +1 -0
  14. package/dist/commands/graph-add.d.ts.map +1 -1
  15. package/dist/commands/graph-add.js +4 -1
  16. package/dist/commands/graph-add.js.map +1 -1
  17. package/dist/commands/json-input.d.ts +4 -2
  18. package/dist/commands/json-input.d.ts.map +1 -1
  19. package/dist/commands/json-input.js +30 -13
  20. package/dist/commands/json-input.js.map +1 -1
  21. package/dist/commands/results-add.d.ts +1 -0
  22. package/dist/commands/results-add.d.ts.map +1 -1
  23. package/dist/commands/results-add.js +4 -1
  24. package/dist/commands/results-add.js.map +1 -1
  25. package/dist/commands/review.js +3 -3
  26. package/dist/commands/review.js.map +1 -1
  27. package/dist/commands/source-relations.d.ts +3 -0
  28. package/dist/commands/source-relations.d.ts.map +1 -1
  29. package/dist/commands/source-relations.js +5 -2
  30. package/dist/commands/source-relations.js.map +1 -1
  31. package/dist/commands/verdict.js +2 -2
  32. package/dist/commands/verdict.js.map +1 -1
  33. package/dist/config.d.ts.map +1 -1
  34. package/dist/config.js +24 -6
  35. package/dist/config.js.map +1 -1
  36. package/dist/deep/extractor.d.ts +2 -0
  37. package/dist/deep/extractor.d.ts.map +1 -1
  38. package/dist/deep/extractor.js +44 -11
  39. package/dist/deep/extractor.js.map +1 -1
  40. package/dist/deep/fuse.d.ts.map +1 -1
  41. package/dist/deep/fuse.js +17 -1
  42. package/dist/deep/fuse.js.map +1 -1
  43. package/dist/deep/graph.d.ts +1 -1
  44. package/dist/deep/graph.d.ts.map +1 -1
  45. package/dist/deep/graph.js +0 -3
  46. package/dist/deep/graph.js.map +1 -1
  47. package/dist/deep/installed-firecrawl.d.ts +6 -0
  48. package/dist/deep/installed-firecrawl.d.ts.map +1 -0
  49. package/dist/deep/installed-firecrawl.js +71 -0
  50. package/dist/deep/installed-firecrawl.js.map +1 -0
  51. package/dist/deep/local-doc/scanner.d.ts.map +1 -1
  52. package/dist/deep/local-doc/scanner.js +5 -1
  53. package/dist/deep/local-doc/scanner.js.map +1 -1
  54. package/dist/deep/local-doc/searcher.d.ts.map +1 -1
  55. package/dist/deep/local-doc/searcher.js +3 -5
  56. package/dist/deep/local-doc/searcher.js.map +1 -1
  57. package/dist/deep/pending-facts.d.ts +6 -0
  58. package/dist/deep/pending-facts.d.ts.map +1 -1
  59. package/dist/deep/pending-facts.js +3 -0
  60. package/dist/deep/pending-facts.js.map +1 -1
  61. package/dist/deep/session-db.d.ts.map +1 -1
  62. package/dist/deep/session-db.js +22 -1
  63. package/dist/deep/session-db.js.map +1 -1
  64. package/dist/deep/session-lock.d.ts +12 -2
  65. package/dist/deep/session-lock.d.ts.map +1 -1
  66. package/dist/deep/session-lock.js +9 -0
  67. package/dist/deep/session-lock.js.map +1 -1
  68. package/dist/errors.d.ts +16 -16
  69. package/dist/errors.d.ts.map +1 -1
  70. package/dist/errors.js +35 -0
  71. package/dist/errors.js.map +1 -1
  72. package/dist/external-search.js +1 -1
  73. package/dist/external-search.js.map +1 -1
  74. package/dist/feedback-log.d.ts +20 -2
  75. package/dist/feedback-log.d.ts.map +1 -1
  76. package/dist/feedback-log.js +22 -2
  77. package/dist/feedback-log.js.map +1 -1
  78. package/dist/protocol.d.ts +20 -2
  79. package/dist/protocol.d.ts.map +1 -1
  80. package/dist/protocol.js +94 -0
  81. package/dist/protocol.js.map +1 -1
  82. package/dist/runCli.d.ts.map +1 -1
  83. package/dist/runCli.js +126 -132
  84. package/dist/runCli.js.map +1 -1
  85. package/dist/service.d.ts +1 -0
  86. package/dist/service.d.ts.map +1 -1
  87. package/dist/service.js +8 -9
  88. package/dist/service.js.map +1 -1
  89. package/package.json +3 -3
  90. package/dist/commands/query-graph.d.ts +0 -13
  91. package/dist/commands/query-graph.d.ts.map +0 -1
  92. package/dist/commands/query-graph.js +0 -208
  93. package/dist/commands/query-graph.js.map +0 -1
  94. package/dist/deep/graph-sampling.d.ts +0 -51
  95. package/dist/deep/graph-sampling.d.ts.map +0 -1
  96. package/dist/deep/graph-sampling.js +0 -410
  97. package/dist/deep/graph-sampling.js.map +0 -1
package/dist/runCli.js CHANGED
@@ -1,4 +1,5 @@
1
- import { installedTavilyReady, installedTavilySearch, installedTavilyStatus } from './deep/installed-tavily.js';
1
+ import { installedFirecrawlStatus, installedFirecrawlSearch } from './deep/installed-firecrawl.js';
2
+ import { installedTavilySearch, installedTavilyStatus } from './deep/installed-tavily.js';
2
3
  import { externalSearch } from './external-search.js';
3
4
  import { feedbackLog, feedbackError } from './feedback-log.js';
4
5
  /**
@@ -19,7 +20,6 @@ import { OllamaService, MAX_RESULTS as OLLAMA_MAX_RESULTS } from './ollama-servi
19
20
  import { DeepSeekService, MAX_RESULTS as DEEPSEEK_MAX_RESULTS } from './deepseek-service.js';
20
21
  import { initConfig } from './init.js';
21
22
  import { runExtract } from './commands/extract.js';
22
- import { runQueryGraph } from './commands/query-graph.js';
23
23
  import { runGraphAdd } from './commands/graph-add.js';
24
24
  import { runResultsAdd } from './commands/results-add.js';
25
25
  import { runDocIndex } from './commands/doc-index.js';
@@ -34,8 +34,7 @@ import { runSessionList, runSessionDelete } from './commands/session.js';
34
34
  import { graphPreprocess } from './deep/graph-preprocess.js';
35
35
  import { checkQueryRedundancy } from './deep/query-redundancy.js';
36
36
  import { buildPendingReport, describeResult } from './deep/pending-facts.js';
37
- import { generateQuerySuggestions } from './deep/query-suggest.js';
38
- import { determineSearchStage, getStrategyInfo } from './deep/search-strategy.js';
37
+ import { getStrategyInfo } from './deep/search-strategy.js';
39
38
  import { getSessionAnalysis } from './deep/iteration-data.js';
40
39
  import { runCoverage } from './commands/coverage.js';
41
40
  import { runGraphExplore } from './commands/graph-explore.js';
@@ -117,6 +116,8 @@ function formatAsMarkdown(data) {
117
116
  if (r.rank !== undefined)
118
117
  meta.push(`Rank: ${r.rank}`);
119
118
  meta.push(`Engine: ${r.engine || 'unknown'}`);
119
+ if (r.contentCompleteness === 'unverified')
120
+ meta.push('Content completeness: unverified');
120
121
  if (r.category)
121
122
  meta.push(`Category: ${r.category}`);
122
123
  if (r.publishedDate)
@@ -133,6 +134,10 @@ function formatAsMarkdown(data) {
133
134
  lines.push('No results found.');
134
135
  lines.push('');
135
136
  }
137
+ if (data.providerResults?.length) {
138
+ 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(' · '));
139
+ lines.push('');
140
+ }
136
141
  if (data.unresponsiveEngines && data.unresponsiveEngines.length > 0) {
137
142
  // The reason travels with the name: "google" alone reads as a blip,
138
143
  // "google (Suspended: access denied)" reads as a reason to stop asking.
@@ -218,6 +223,10 @@ function formatFactsAsMarkdown(facts) {
218
223
  if (facts.sourceList.length)
219
224
  lines.push(`**Source list:** ${facts.sourceList.join(' · ')}`);
220
225
  lines.push('');
226
+ if (facts.jinaSearchWarnings?.length) {
227
+ lines.push('**Jina search content needs completeness review:** ' + facts.jinaSearchWarnings.map(item => `${item.id} (${item.url})`).join(' · '));
228
+ lines.push('');
229
+ }
221
230
  if (facts.pending.length) {
222
231
  lines.push(`**Awaiting approval:** ${facts.pending.length}`);
223
232
  lines.push('');
@@ -234,42 +243,6 @@ function formatFactsAsMarkdown(facts) {
234
243
  }
235
244
  return lines.join('\n');
236
245
  }
237
- function formatSuggestAsMarkdown(data) {
238
- const lines = [];
239
- lines.push('## Query Suggestion Data');
240
- lines.push('');
241
- lines.push(`**Current Stage:** ${data.currentStage}`);
242
- lines.push('');
243
- if (data.topEntities?.length) {
244
- lines.push('### Top Entities');
245
- lines.push('');
246
- lines.push('| Entity | Obfuscated Label | Degree | Frequency | Type |');
247
- lines.push('|--------|------------------|--------|-----------|------|');
248
- for (const e of data.topEntities.slice(0, 15)) {
249
- lines.push(`| ${e.label} | ${e.obfuscatedLabel || '-'} | ${e.degree} | ${e.frequency} | ${e.entityType || '-'} |`);
250
- }
251
- lines.push('');
252
- }
253
- if (data.unexploredDomains?.length) {
254
- lines.push('### Unexplored Domains');
255
- lines.push('');
256
- for (const d of data.unexploredDomains) {
257
- lines.push(`- ${d}`);
258
- }
259
- lines.push('');
260
- }
261
- if (data.roundHistory?.length) {
262
- lines.push('### Round History');
263
- lines.push('');
264
- lines.push('| Round | Query | Results |');
265
- lines.push('|-------|-------|---------|');
266
- for (const r of data.roundHistory) {
267
- lines.push(`| ${r.round} | ${r.query} | ${r.resultCount} |`);
268
- }
269
- lines.push('');
270
- }
271
- return lines.join('\n');
272
- }
273
246
  function formatStrategyAsMarkdown(data) {
274
247
  const lines = [];
275
248
  lines.push('## Search Strategy Info');
@@ -347,16 +320,33 @@ const PROVIDER_IMPLS = {
347
320
  async function configuredExternalProviders() {
348
321
  const providers = EXTERNAL_PROVIDERS.filter(p => PROVIDER_IMPLS[p].configured());
349
322
  const tavilyCli = await installedTavilyStatus();
323
+ const firecrawlCli = await installedFirecrawlStatus();
324
+ if (!providers.includes('firecrawl') && firecrawlCli === 'authenticated')
325
+ providers.push('firecrawl');
350
326
  if (!providers.includes('tavily') && (tavilyCli === 'authenticated' || tavilyCli === 'keyless'))
351
327
  providers.push('tavily');
352
- return { providers, tavilyCli };
328
+ const details = EXTERNAL_PROVIDERS.map(provider => ({
329
+ provider, configured: providers.includes(provider), access: providers.includes(provider) ? 'unverified' : 'not_configured',
330
+ ...(provider === 'tavily' ? { cliStatus: tavilyCli } : provider === 'firecrawl' ? { cliStatus: firecrawlCli } : {}),
331
+ }));
332
+ return { providers, tavilyCli, details };
333
+ }
334
+ function summarizeAttempts(attempts, returnedKeys) {
335
+ return attempts.map(attempt => attempt.status === 'ok' ? {
336
+ query: attempt.query, provider: attempt.provider, status: 'ok', received: attempt.response.results.length,
337
+ returned: new Set(attempt.response.results.map(result => resultUrlKey(result)).filter(key => returnedKeys.has(key))).size,
338
+ } : {
339
+ query: attempt.query, provider: attempt.provider, status: 'error', received: 0, returned: 0,
340
+ error: attempt.error instanceof SearchError ? attempt.error.code : 'SEARCH_FAILED',
341
+ retryable: attempt.error instanceof SearchError ? attempt.error.retryable : false,
342
+ });
353
343
  }
354
- function planProviderSearch(engines, tavilyCli = false) {
344
+ function planProviderSearch(engines, tavilyCli = false, firecrawlCli = false) {
355
345
  const selected = EXTERNAL_PROVIDERS.filter(p => engines.includes(p));
356
346
  return {
357
- tavilyCli,
358
- usable: selected.filter(p => PROVIDER_IMPLS[p].configured() || (p === 'tavily' && tavilyCli)),
359
- unconfigured: selected.filter(p => !PROVIDER_IMPLS[p].configured() && !(p === 'tavily' && tavilyCli)),
347
+ tavilyCli, firecrawlCli,
348
+ usable: selected.filter(p => PROVIDER_IMPLS[p].configured() || ((p === 'tavily' && tavilyCli) || (p === 'firecrawl' && firecrawlCli))),
349
+ unconfigured: selected.filter(p => !PROVIDER_IMPLS[p].configured() && !((p === 'tavily' && tavilyCli) || (p === 'firecrawl' && firecrawlCli))),
360
350
  sxngEngines: engines.filter(e => !EXTERNAL_PROVIDERS.includes(e)),
361
351
  };
362
352
  }
@@ -370,6 +360,7 @@ async function searchOneQuery(service, plan, searchOptions, limit) {
370
360
  if (plan.usable.length === 0 || plan.sxngEngines.length > 0)
371
361
  assertSearXNGConfig();
372
362
  const providerResponses = [];
363
+ const attempts = [];
373
364
  const limitNotes = [];
374
365
  for (const provider of plan.usable) {
375
366
  const started = Date.now();
@@ -377,7 +368,8 @@ async function searchOneQuery(service, plan, searchOptions, limit) {
377
368
  try {
378
369
  const response = provider === 'tavily' && plan.tavilyCli
379
370
  ? await installedTavilySearch(searchOptions.query, limit)
380
- : await PROVIDER_IMPLS[provider].search(searchOptions.query, limit);
371
+ : provider === 'firecrawl' && plan.firecrawlCli ? await installedFirecrawlSearch(searchOptions.query, limit)
372
+ : await PROVIDER_IMPLS[provider].search(searchOptions.query, limit);
381
373
  feedbackLog('provider', 'ok', { provider, durationMs: Date.now() - started, count: response.results.length });
382
374
  // The provider caps the count itself, so compare against its ceiling
383
375
  // rather than against what came back: a provider may also return
@@ -387,10 +379,11 @@ async function searchOneQuery(service, plan, searchOptions, limit) {
387
379
  if (limit > applied)
388
380
  limitNotes.push({ provider, requested: limit, applied });
389
381
  providerResponses.push(response);
382
+ attempts.push({ provider, query: searchOptions.query, status: 'ok', response });
390
383
  }
391
384
  catch (error) {
392
385
  feedbackLog('provider', 'error', { provider, durationMs: Date.now() - started, error: feedbackError(error) });
393
- throw error;
386
+ attempts.push({ provider, query: searchOptions.query, status: 'error', error });
394
387
  }
395
388
  }
396
389
  let sxngResponse = null;
@@ -403,13 +396,14 @@ async function searchOneQuery(service, plan, searchOptions, limit) {
403
396
  engines: plan.sxngEngines.length > 0 ? plan.sxngEngines : searchOptions.engines,
404
397
  });
405
398
  feedbackLog('provider', 'ok', { provider: 'searxng', durationMs: Date.now() - started, count: sxngResponse.results.length });
399
+ attempts.push({ provider: 'searxng', query: searchOptions.query, status: 'ok', response: sxngResponse });
406
400
  }
407
401
  catch (error) {
408
402
  feedbackLog('provider', 'error', { provider: 'searxng', durationMs: Date.now() - started, error: feedbackError(error) });
409
- throw error;
403
+ attempts.push({ provider: 'searxng', query: searchOptions.query, status: 'error', error });
410
404
  }
411
405
  }
412
- return { providerResponses, sxngResponse, limitNotes };
406
+ return { providerResponses, sxngResponse, limitNotes, attempts };
413
407
  }
414
408
  /** Attribute a result to the tool that produced it, for session origin records. */
415
409
  function originTool(engine) {
@@ -418,19 +412,19 @@ function originTool(engine) {
418
412
  async function runSearchInner(service, options) {
419
413
  feedbackLog('validation', 'start');
420
414
  if (options.limit !== undefined && (!Number.isSafeInteger(options.limit) || options.limit <= 0)) {
421
- feedbackLog('validation', 'error', { error: 'validation' });
415
+ feedbackLog('validation', 'error', { error: 'INVALID_LIMIT' });
422
416
  console.log(JSON.stringify(createErrorEnvelope('INVALID_LIMIT', 'Limit must be a positive safe integer'), null, 2));
423
417
  return 1;
424
418
  }
425
419
  const queries = options.queries || (options.query ? [options.query] : []);
426
420
  if (queries.length === 0) {
427
- feedbackLog('validation', 'error', { error: 'validation' });
421
+ feedbackLog('validation', 'error', { error: 'MISSING_QUERY' });
428
422
  const envelope = createErrorEnvelope('MISSING_QUERY', 'No search query provided', { hint: 'Use: dg "your search query" or dg --queries "q1,q2,q3"' });
429
423
  console.log(JSON.stringify(envelope, null, 2));
430
424
  return 1;
431
425
  }
432
426
  if (options.engines && options.engines.length === 0) {
433
- feedbackLog('validation', 'error', { error: 'validation' });
427
+ feedbackLog('validation', 'error', { error: 'INVALID_ENGINES' });
434
428
  console.log(JSON.stringify(createErrorEnvelope('INVALID_ENGINES', 'At least one engine must be specified'), null, 2));
435
429
  return 1;
436
430
  }
@@ -438,19 +432,21 @@ async function runSearchInner(service, options) {
438
432
  if (config.allowedEngines.length > 0) {
439
433
  const invalid = engines.filter(e => !config.allowedEngines.includes(e));
440
434
  if (invalid.length > 0) {
441
- feedbackLog('validation', 'error', { error: 'validation' });
435
+ feedbackLog('validation', 'error', { error: 'INVALID_ENGINES' });
442
436
  const envelope = createErrorEnvelope('INVALID_ENGINES', `Engines not allowed: ${invalid.join(', ')}`, { hint: `Allowed engines: ${config.allowedEngines.join(', ')}` });
443
437
  console.log(JSON.stringify(envelope, null, 2));
444
438
  return 1;
445
439
  }
446
440
  }
447
- const tavilyCli = engines.includes('tavily') && !process.env.TAVILY_API_KEY && await installedTavilyReady();
441
+ const tavilyStatus = engines.includes('tavily') ? await installedTavilyStatus() : 'not_installed';
442
+ const tavilyCli = tavilyStatus === 'authenticated' || (tavilyStatus === 'keyless' && !process.env.TAVILY_API_KEY);
443
+ const firecrawlCli = engines.includes('firecrawl') && await installedFirecrawlStatus() === 'authenticated';
448
444
  // A selected provider without its API key cannot run. Failing loudly beats
449
445
  // silently answering from SearXNG, which would make the provider look active.
450
446
  if (engines.length > 0) {
451
- const unconfigured = planProviderSearch(engines, tavilyCli).unconfigured;
447
+ const unconfigured = planProviderSearch(engines, tavilyCli, firecrawlCli).unconfigured;
452
448
  if (unconfigured.length > 0) {
453
- feedbackLog('validation', 'error', { error: 'CONFIG_MISSING' });
449
+ feedbackLog('validation', 'error', { error: 'PROVIDER_NOT_CONFIGURED' });
454
450
  const envelope = createErrorEnvelope('PROVIDER_NOT_CONFIGURED', `Provider selected but no API key configured: ${unconfigured.join(', ')}`, { hint: unconfigured.map(p => p === 'ollama'
455
451
  ? 'Set OLLAMA_API_KEY or add "ollamaApiKey" to digdig.config.json'
456
452
  : p === 'deepseek' ? 'Set DEEPSEEK_API_KEY or add "deepseekApiKey" to digdig.config.json'
@@ -566,6 +562,7 @@ async function runSearchInner(service, options) {
566
562
  queries.length = 0;
567
563
  queries.push(...adjustedQueries);
568
564
  }
565
+ const attempts = [];
569
566
  try {
570
567
  // Read the merge file before anything writes, so a bad path cannot leave
571
568
  // half a session behind.
@@ -585,7 +582,7 @@ async function runSearchInner(service, options) {
585
582
  }
586
583
  // One invocation, N queries: the only difference from a single query is
587
584
  // how many responses land in the array.
588
- const plan = planProviderSearch(engines, tavilyCli);
585
+ const plan = planProviderSearch(engines, tavilyCli, firecrawlCli);
589
586
  const responses = [];
590
587
  // One note per provider across every query in this invocation: repeating
591
588
  // "ollama capped at 10" once per query would bury the fact in noise.
@@ -601,8 +598,9 @@ async function runSearchInner(service, options) {
601
598
  language: options.language,
602
599
  timeRange: options.timeRange,
603
600
  };
604
- const { providerResponses, sxngResponse, limitNotes: notes } = await searchOneQuery(service, plan, searchOptions, limit);
605
- if (options.session)
601
+ const { providerResponses, sxngResponse, limitNotes: notes, attempts: queryAttempts } = await searchOneQuery(service, plan, searchOptions, limit);
602
+ attempts.push(...queryAttempts);
603
+ if (options.session && queryAttempts.some(attempt => attempt.status === 'ok'))
606
604
  searchRound = recordSuccessfulQuery(options.session, query, searchRound);
607
605
  for (const note of notes) {
608
606
  if (!limitNotes.some(existing => existing.provider === note.provider))
@@ -612,6 +610,11 @@ async function runSearchInner(service, options) {
612
610
  if (sxngResponse)
613
611
  responses.push(sxngResponse);
614
612
  }
613
+ if (!responses.length) {
614
+ const failure = attempts.find(attempt => attempt.status === 'error');
615
+ if (failure?.status === 'error')
616
+ throw failure.error;
617
+ }
615
618
  // Snapshot before writing: history must not include this invocation's own
616
619
  // results, or every current result votes for itself a second time.
617
620
  const sessionSnapshot = options.session ? loadSessionResults(options.session) : undefined;
@@ -629,11 +632,9 @@ async function runSearchInner(service, options) {
629
632
  let sessionInfo = null;
630
633
  if (options.session) {
631
634
  feedbackLog('session', 'start');
632
- sessionInfo = appendAndInjectSessionResults(options.session, fusion.display.map((result, index) => ({
635
+ sessionInfo = appendAndInjectSessionResults(options.session, fusion.display.map(result => ({
633
636
  ...result,
634
- // The fused position, so `rank` and `fusionScore` describe the same
635
- // order instead of one provider's and one RRF's.
636
- rank: index + 1,
637
+ // `rank` comes from the fusion, so it is not restated here.
637
638
  origins: fusion.originsByKey.get(resultUrlKey(result)),
638
639
  })), searchRound);
639
640
  feedbackLog('session', 'ok', { count: sessionInfo.added, total: sessionInfo.total });
@@ -652,7 +653,10 @@ async function runSearchInner(service, options) {
652
653
  meta.answers.push(answer);
653
654
  }
654
655
  const outputFormat = (options.format || config.defaultFormat);
656
+ const returnedKeys = new Set(fusion.display.map(result => resultUrlKey(result)));
657
+ const providerResults = summarizeAttempts(attempts, returnedKeys);
655
658
  const displayData = {
659
+ providerResults,
656
660
  query: queries.length > 1 ? queries.join(' · ') : queries[0],
657
661
  queries,
658
662
  // The deduplicated candidate pool, not a sum of provider self-reports
@@ -670,7 +674,7 @@ async function runSearchInner(service, options) {
670
674
  // Absent when nothing was capped, so a request the providers could
671
675
  // honour in full keeps the exact shape it had before this field.
672
676
  ...(limitNotes.length ? { limitNotes } : {}),
673
- ...(sessionInfo ? { session: { dir: options.session, added: sessionInfo.added, total: sessionInfo.total } } : {}),
677
+ ...(sessionInfo ? { session: { dir: options.session, added: sessionInfo.added, updated: sessionInfo.updated, total: sessionInfo.total } } : {}),
674
678
  };
675
679
  if (outputFormat === 'md') {
676
680
  console.log(formatOutput(displayData, 'md'));
@@ -691,7 +695,12 @@ async function runSearchInner(service, options) {
691
695
  catch (error) {
692
696
  feedbackLog('search', 'error', { error: feedbackError(error) });
693
697
  if (error instanceof SessionStateError) {
694
- console.log(JSON.stringify(createErrorEnvelope(error.code, error.message, { retryable: error.code === 'SESSION_BUSY' }), null, 2));
698
+ const partialResults = attempts.flatMap(attempt => attempt.status === 'ok' ? attempt.response.results : []);
699
+ const details = attempts.length ? {
700
+ providerResults: summarizeAttempts(attempts, new Set(partialResults.map(result => resultUrlKey(result)))),
701
+ partialResults, sessionWrite: 'unconfirmed',
702
+ } : undefined;
703
+ console.log(JSON.stringify(createErrorEnvelope(error.code, error.message, { retryable: error.code === 'SESSION_BUSY', details }), null, 2));
695
704
  return 1;
696
705
  }
697
706
  // `retryable` and the hint come from the error, not from this block.
@@ -703,12 +712,12 @@ async function runSearchInner(service, options) {
703
712
  const envelope = createErrorEnvelope(error.code, error.message, {
704
713
  retryable: error.retryable,
705
714
  hint: error.hint,
706
- details: { provider: error.provider, ...(error.status === undefined ? {} : { status: error.status }) },
715
+ details: { provider: error.provider, ...(error.status === undefined ? {} : { status: error.status }), ...(attempts.length ? { providerResults: summarizeAttempts(attempts, new Set()) } : {}) },
707
716
  });
708
717
  console.log(JSON.stringify(envelope, null, 2));
709
718
  return 1;
710
719
  }
711
- const envelope = createErrorEnvelope('SEARCH_FAILED', error instanceof Error ? error.message : 'Search request failed');
720
+ 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()) } } : {});
712
721
  console.log(JSON.stringify(envelope, null, 2));
713
722
  return 1;
714
723
  }
@@ -762,6 +771,9 @@ export function createProgram(argv = []) {
762
771
  .option('--approve-file <path>', 'UTF-8 approval JSON array under this session agent-inputs directory')
763
772
  .option('--skip-file <path>', 'UTF-8 skip JSON array under this session agent-inputs directory')
764
773
  .option('--unskip-file <path>', 'UTF-8 restore JSON array under this session agent-inputs directory')
774
+ .option('--approve-stdin', 'Read the approval array from stdin')
775
+ .option('--skip-stdin', 'Read the skip array from stdin')
776
+ .option('--unskip-stdin', 'Read the restore array from stdin')
765
777
  .option('--health', 'Check the SearXNG backend health (Ollama/DeepSeek have no health endpoint)')
766
778
  .option('--engines-list', 'List available search engines')
767
779
  .option('--categories-list', 'List available categories')
@@ -790,11 +802,12 @@ export function createProgram(argv = []) {
790
802
  jina: opts.jina ?? false,
791
803
  jinaApiKey: process.env.JINA_API_KEY,
792
804
  useInstalledTavily: true,
805
+ useInstalledFirecrawl: true,
793
806
  externalKeys: {
794
807
  exa: process.env.EXA_API_KEY, tavily: process.env.TAVILY_API_KEY,
795
808
  firecrawl: process.env.FIRECRAWL_API_KEY,
796
- ollama: process.env.OLLAMA_API_KEY || config.ollamaApiKey,
797
- deepseek: process.env.DEEPSEEK_API_KEY || config.deepseekApiKey,
809
+ ollama: config.ollamaApiKey,
810
+ deepseek: config.deepseekApiKey,
798
811
  },
799
812
  });
800
813
  const extractOptions = {
@@ -807,35 +820,17 @@ export function createProgram(argv = []) {
807
820
  const code = await runExtract(extractor, extractOptions);
808
821
  process.exitCode = code;
809
822
  });
810
- program
811
- .command('query-graph')
812
- .argument('<path>', 'Graph file or session name')
813
- .description('[DEPRECATED] Query subgraph via BFS. Use graph-explore + graph-drill instead.')
814
- .option('--seeds <s1,s2>', 'Seed nodes for BFS')
815
- .option('--depth <n>', 'BFS depth (default: 2)', val => parseInt(val, 10), 2)
816
- .option('--strategy <strategy>', 'Sampling strategy: augmented_chain | dual_core_bridge | community_core_path | deep_chain | mixed')
817
- .option('-f, --format <fmt>', 'Output format: md, json')
818
- .action(async (path, opts, command) => {
819
- console.warn('[DEPRECATED] query-graph is deprecated. Use graph-explore + graph-drill instead.');
820
- const graphFormat = command.optsWithGlobals().format === 'json' ? 'json' : 'md';
821
- const code = await runQueryGraph({
822
- graphFile: path,
823
- seeds: opts.seeds?.split(',').map((s) => s.trim()).filter(Boolean) || [],
824
- depth: opts.depth ?? 2,
825
- format: graphFormat,
826
- strategy: opts.strategy,
827
- });
828
- process.exitCode = code;
829
- });
830
823
  program
831
824
  .command('graph-add')
832
825
  .argument('<session>', 'Session directory or name')
833
826
  .description('Add semantic entities/edges supported by approved extracted result IDs.')
834
- .requiredOption('--data-file <path>', 'UTF-8 JSON under this session agent-inputs directory')
827
+ .option('--data-file <path>', 'UTF-8 JSON under this session agent-inputs directory')
828
+ .option('--data-stdin', 'Read the same JSON from stdin instead of a file')
835
829
  .action(async (session, opts) => {
836
830
  const code = await runGraphAdd({
837
831
  session,
838
832
  dataFile: opts.dataFile,
833
+ dataStdin: opts.dataStdin ?? false,
839
834
  });
840
835
  process.exitCode = code;
841
836
  });
@@ -844,12 +839,14 @@ export function createProgram(argv = []) {
844
839
  .argument('<session>', 'Session directory or name')
845
840
  .description('Import external search records or extracted bodies into a session')
846
841
  .requiredOption('--kind <kind>', 'Import kind: search or extracted')
847
- .requiredOption('--data-file <path>', 'UTF-8 JSON under this session agent-inputs directory')
842
+ .option('--data-file <path>', 'UTF-8 JSON under this session agent-inputs directory')
843
+ .option('--data-stdin', 'Read the same JSON from stdin instead of a file')
848
844
  .option('--query <query>', 'Discovery query (may instead be supplied per item)')
849
845
  .option('--tool <tool>', 'Origin tool (may instead be supplied per item)')
850
846
  .addHelpText('after', `
851
847
  Examples:
852
848
  dg results-add my-session --kind search --tool exa --query "async runtime" --data-file .digdig/sessions/my-session/agent-inputs/results.json
849
+ dg results-add my-session --kind extracted --data-stdin < results.json
853
850
 
854
851
  Search imports await extraction; extracted imports await approval.`)
855
852
  .action(async (session, opts) => {
@@ -857,6 +854,7 @@ Search imports await extraction; extracted imports await approval.`)
857
854
  session,
858
855
  kind: opts.kind,
859
856
  dataFile: opts.dataFile,
857
+ dataStdin: opts.dataStdin ?? false,
860
858
  query: opts.query,
861
859
  tool: opts.tool,
862
860
  });
@@ -998,31 +996,7 @@ Examples:
998
996
  console.log(JSON.stringify(createSuccessEnvelope(listPendingGraph(resolveSessionPath(session))), null, 2));
999
997
  process.exitCode = 0;
1000
998
  });
1001
- program
1002
- .command('suggest-queries')
1003
- .argument('<session>', 'Session directory or name')
1004
- .description('Output query suggestion data for Agent follow-up query generation')
1005
- .option('-f, --format <fmt>', 'Output format: json (default), md')
1006
- .addHelpText('after', `
1007
- Examples:
1008
- dg suggest-queries my-session
1009
- dg suggest-queries my-session --format md`)
1010
- .action(async (session, opts, command) => {
1011
- const sessionDir = resolveSessionPath(session);
1012
- const results = loadSessionResults(sessionDir);
1013
- if (reportEmptySession(results.length))
1014
- return;
1015
- const graph = loadSessionGraph(sessionDir);
1016
- const stage = determineSearchStage(graph, undefined, loadSessionRounds(sessionDir));
1017
- const data = generateQuerySuggestions(graph, results, stage);
1018
- if (command.optsWithGlobals().format === 'md') {
1019
- console.log(formatSuggestAsMarkdown(data));
1020
- }
1021
- else {
1022
- console.log(JSON.stringify(createSuccessEnvelope(data), null, 2));
1023
- }
1024
- process.exitCode = 0;
1025
- });
999
+ program;
1026
1000
  program
1027
1001
  .command('strategy-info')
1028
1002
  .argument('<session>', 'Session directory or name')
@@ -1171,15 +1145,20 @@ See also: graph-explore (for viewing relations of a known entity)`)
1171
1145
  .description('Add claims (single or batch) with auto evidence-search')
1172
1146
  .option('--claim-file <path>', 'UTF-8 JSON file with one claim')
1173
1147
  .option('--claims-file <path>', 'UTF-8 JSON file with a claim array')
1148
+ .option('--claim-stdin', 'Read one claim from stdin')
1149
+ .option('--claims-stdin', 'Read a claim array from stdin')
1174
1150
  .option('-f, --format <fmt>', 'Output format: json (default), md')
1175
1151
  .addHelpText('after', `
1176
1152
  Examples:
1177
1153
  dg claim-add my-session --claim-file .digdig/sessions/my-session/agent-inputs/claim.json
1178
- dg claim-add my-session --claims-file .digdig/sessions/my-session/agent-inputs/claims.json`)
1154
+ dg claim-add my-session --claims-file .digdig/sessions/my-session/agent-inputs/claims.json
1155
+ dg claim-add my-session --claims-stdin < claims.json`)
1179
1156
  .action(async (session, opts, command) => {
1180
1157
  const code = await runClaimAdd(session, {
1181
1158
  claimFile: opts.claimFile,
1182
1159
  claimsFile: opts.claimsFile,
1160
+ claimStdin: opts.claimStdin ?? false,
1161
+ claimsStdin: opts.claimsStdin ?? false,
1183
1162
  format: command.optsWithGlobals().format,
1184
1163
  });
1185
1164
  process.exitCode = code;
@@ -1216,6 +1195,7 @@ Examples:
1216
1195
  .description('Confirm evidence + submit stance + optional auto-policy')
1217
1196
  .requiredOption('--claim-id <id>', 'Claim ID')
1218
1197
  .requiredOption('--evidence-file <path>', 'UTF-8 JSON file with evidence object under this session agent-inputs directory')
1198
+ .option('--evidence-stdin', 'Read the same JSON from stdin instead of a file')
1219
1199
  .requiredOption('--stance <s>', 'Stance: support, refute, insufficient')
1220
1200
  .requiredOption('--reason <text>', 'Judgement rationale')
1221
1201
  .option('--confidence <n>', 'Confidence 0-1')
@@ -1225,6 +1205,7 @@ Examples:
1225
1205
  const code = await runEvidenceVerify(session, {
1226
1206
  claimId: opts.claimId,
1227
1207
  evidenceFile: opts.evidenceFile,
1208
+ evidenceStdin: opts.evidenceStdin ?? false,
1228
1209
  stance: opts.stance,
1229
1210
  reason: opts.reason,
1230
1211
  confidence: opts.confidence === undefined ? undefined : (opts.confidence.trim() ? Number(opts.confidence) : NaN),
@@ -1267,7 +1248,8 @@ Examples:
1267
1248
  .description('List or record source independence judgments')
1268
1249
  .requiredOption('--claim-id <id>', 'Claim ID')
1269
1250
  .option('--data-file <path>', 'Judgment or revocation JSON in agent-inputs')
1270
- .action(async (session, opts) => { process.exitCode = await runSourceRelations(session, { claimId: opts.claimId, dataFile: opts.dataFile }); });
1251
+ .option('--data-stdin', 'Read the same JSON from stdin instead of a file')
1252
+ .action(async (session, opts) => { process.exitCode = await runSourceRelations(session, { claimId: opts.claimId, dataFile: opts.dataFile, dataStdin: opts.dataStdin ?? false }); });
1271
1253
  program
1272
1254
  .command('policy-aggregate')
1273
1255
  .argument('<session>', 'Session directory or name')
@@ -1343,16 +1325,19 @@ export async function runCli(args, service) {
1343
1325
  if (!opts.skipFile && !opts.unskipFile && !opts.approveFile && reportEmptySession(sessionResults.length))
1344
1326
  return;
1345
1327
  const sessionGraph = loadSessionGraph(sessionDir);
1346
- const readSelections = (option, file) => {
1347
- const input = readSessionJsonInput(sessionDir, [{ option, value: file, file: true }]);
1328
+ const readSelections = (option, file, stdin) => {
1329
+ const input = readSessionJsonInput(sessionDir, [
1330
+ { option, value: file, file: true },
1331
+ { option: `${option.slice(0, -'-file'.length)}-stdin`, stdin },
1332
+ ]);
1348
1333
  if (!input.ok || !Array.isArray(input.value) || !input.value.every(item => typeof item === 'object' && item !== null && typeof item.id === 'string' && Number.isSafeInteger(item.revision))) {
1349
1334
  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));
1350
1335
  return undefined;
1351
1336
  }
1352
1337
  return input.value;
1353
1338
  };
1354
- const applySkip = (option, file, skipped) => {
1355
- const selections = readSelections(option, file);
1339
+ const applySkip = (option, file, stdin, skipped) => {
1340
+ const selections = readSelections(option, file, stdin);
1356
1341
  if (!selections)
1357
1342
  return false;
1358
1343
  const result = setSkipped(sessionDir, selections, skipped);
@@ -1363,13 +1348,15 @@ export async function runCli(args, service) {
1363
1348
  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));
1364
1349
  return true;
1365
1350
  };
1366
- if (opts.skipFile || opts.unskipFile) {
1367
- if (opts.skipFile && opts.unskipFile) {
1368
- console.log(JSON.stringify(createErrorEnvelope('MULTIPLE_SKIP_ACTIONS', 'Use only one of --skip-file or --unskip-file'), null, 2));
1351
+ if (opts.skipFile || opts.unskipFile || opts.skipStdin || opts.unskipStdin) {
1352
+ if ((opts.skipFile || opts.skipStdin) && (opts.unskipFile || opts.unskipStdin)) {
1353
+ console.log(JSON.stringify(createErrorEnvelope('MULTIPLE_SKIP_ACTIONS', 'Use only one of --skip-file, --skip-stdin, --unskip-file or --unskip-stdin'), null, 2));
1369
1354
  process.exitCode = 1;
1370
1355
  return;
1371
1356
  }
1372
- process.exitCode = applySkip(opts.skipFile ? '--skip-file' : '--unskip-file', opts.skipFile ?? opts.unskipFile, Boolean(opts.skipFile)) ? 0 : 1;
1357
+ const skipping = Boolean(opts.skipFile || opts.skipStdin);
1358
+ const option = skipping ? '--skip-file' : '--unskip-file';
1359
+ process.exitCode = applySkip(option, opts.skipFile ?? opts.unskipFile, skipping ? opts.skipStdin : opts.unskipStdin, skipping) ? 0 : 1;
1373
1360
  return;
1374
1361
  }
1375
1362
  // Get pending results for Agent review
@@ -1378,7 +1365,7 @@ export async function runCli(args, service) {
1378
1365
  // Approval is allowed only after reporting what is waiting and how
1379
1366
  // much of it carries a body.
1380
1367
  if (opts.approveFile) {
1381
- const selections = readSelections('--approve-file', opts.approveFile);
1368
+ const selections = readSelections('--approve-file', opts.approveFile, opts.approveStdin);
1382
1369
  if (!selections) {
1383
1370
  process.exitCode = 1;
1384
1371
  return;
@@ -1455,14 +1442,14 @@ export async function runCli(args, service) {
1455
1442
  if (opts.enginesList) {
1456
1443
  try {
1457
1444
  const serverEngines = await service.getEngines();
1458
- const { providers: configuredProviders, tavilyCli } = await configuredExternalProviders();
1445
+ const { providers: configuredProviders, tavilyCli, details } = await configuredExternalProviders();
1459
1446
  // Both empty is a legitimate-looking but useless answer: nothing
1460
1447
  // this CLI can search with. Reaching here already means the
1461
1448
  // server answered (a failed fetch throws), so `serverEngines`
1462
1449
  // being empty now says exactly one thing — the server has no
1463
1450
  // enabled engines — and the `&&` reads correctly.
1464
1451
  if (serverEngines.length === 0 && configuredProviders.length === 0) {
1465
- const envelope = createErrorEnvelope('ENGINES_FETCH_EMPTY', 'No engines returned from SearXNG server', { hint: 'Check if SearXNG server is properly configured' });
1452
+ const envelope = createErrorEnvelope('ENGINES_FETCH_EMPTY', 'No engines returned from SearXNG server', { hint: 'Check if SearXNG server is properly configured', details: { providers: details, tavilyCli } });
1466
1453
  console.log(JSON.stringify(envelope, null, 2));
1467
1454
  process.exitCode = 1;
1468
1455
  return;
@@ -1476,24 +1463,31 @@ export async function runCli(args, service) {
1476
1463
  engines: [...serverEngines, ...configuredProviders],
1477
1464
  sources: { server: serverEngines, local: configuredProviders },
1478
1465
  tavilyCli,
1466
+ providers: details,
1479
1467
  });
1480
1468
  console.log(JSON.stringify(envelope, null, 2));
1481
1469
  process.exitCode = 0;
1482
1470
  }
1483
1471
  catch (error) {
1484
- if (printConfigError(error))
1485
- return;
1486
- const { providers: configuredProviders, tavilyCli } = await configuredExternalProviders();
1472
+ const { providers: configuredProviders, tavilyCli, details } = await configuredExternalProviders();
1487
1473
  if (configuredProviders.length) {
1488
1474
  console.log(JSON.stringify(createSuccessEnvelope({
1489
1475
  engines: configuredProviders,
1490
1476
  sources: { server: [], local: configuredProviders },
1491
1477
  tavilyCli,
1478
+ providers: details,
1492
1479
  serverUnavailable: true,
1493
1480
  }), null, 2));
1494
1481
  process.exitCode = 0;
1495
1482
  return;
1496
1483
  }
1484
+ if (error instanceof SearchError && error.code === 'CONFIG_MISSING') {
1485
+ console.log(JSON.stringify(createErrorEnvelope(error.code, error.message, {
1486
+ retryable: error.retryable, hint: error.hint, details: { providers: details, tavilyCli },
1487
+ }), null, 2));
1488
+ process.exitCode = 1;
1489
+ return;
1490
+ }
1497
1491
  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.` });
1498
1492
  console.log(JSON.stringify(envelope, null, 2));
1499
1493
  process.exitCode = 1;