digdig 0.0.12 → 0.0.14

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 (40) hide show
  1. package/README.md +6 -0
  2. package/dist/commands/extract.d.ts.map +1 -1
  3. package/dist/commands/extract.js +22 -2
  4. package/dist/commands/extract.js.map +1 -1
  5. package/dist/deep/extractor.d.ts +0 -3
  6. package/dist/deep/extractor.d.ts.map +1 -1
  7. package/dist/deep/extractor.js +11 -0
  8. package/dist/deep/extractor.js.map +1 -1
  9. package/dist/deep/session.d.ts +0 -16
  10. package/dist/deep/session.d.ts.map +1 -1
  11. package/dist/deep/session.js +0 -7
  12. package/dist/deep/session.js.map +1 -1
  13. package/dist/deepseek-service.d.ts +6 -0
  14. package/dist/deepseek-service.d.ts.map +1 -1
  15. package/dist/deepseek-service.js +7 -1
  16. package/dist/deepseek-service.js.map +1 -1
  17. package/dist/feedback-log.d.ts +20 -0
  18. package/dist/feedback-log.d.ts.map +1 -0
  19. package/dist/feedback-log.js +76 -0
  20. package/dist/feedback-log.js.map +1 -0
  21. package/dist/ollama-service.d.ts +6 -0
  22. package/dist/ollama-service.d.ts.map +1 -1
  23. package/dist/ollama-service.js +7 -1
  24. package/dist/ollama-service.js.map +1 -1
  25. package/dist/runCli.d.ts.map +1 -1
  26. package/dist/runCli.js +88 -10
  27. package/dist/runCli.js.map +1 -1
  28. package/dist/service.d.ts +0 -3
  29. package/dist/service.d.ts.map +1 -1
  30. package/dist/service.js +2 -0
  31. package/dist/service.js.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/deep/index.d.ts +0 -10
  34. package/dist/deep/index.d.ts.map +0 -1
  35. package/dist/deep/index.js +0 -10
  36. package/dist/deep/index.js.map +0 -1
  37. package/dist/deep/simhash.d.ts +0 -17
  38. package/dist/deep/simhash.d.ts.map +0 -1
  39. package/dist/deep/simhash.js +0 -72
  40. package/dist/deep/simhash.js.map +0 -1
@@ -0,0 +1,76 @@
1
+ import { randomUUID } from 'crypto';
2
+ import { homedir } from 'os';
3
+ import { join } from 'path';
4
+ import { appendFile, mkdir, open, rename, stat, unlink } from 'fs/promises';
5
+ const MAX_BYTES = 10 * 1024 * 1024;
6
+ const runId = randomUUID();
7
+ const events = ['search', 'validation', 'redundancy', 'provider', 'fusion', 'session', 'extract', 'extract_batch', 'extract_method'];
8
+ const statuses = ['start', 'ok', 'error', 'skip'];
9
+ const providers = ['searxng', 'deepseek', 'ollama', 'defuddle', 'obscura', 'jina', 'unknown'];
10
+ const errors = ['CONFIG_MISSING', 'AUTH_FAILED', 'RATE_LIMITED', 'SERVER_ERROR', 'NETWORK_ERROR', 'BAD_REQUEST', 'BAD_RESPONSE', 'SESSION_BUSY', 'validation', 'unknown'];
11
+ let queue = [];
12
+ let writing = false;
13
+ async function writeBatch(lines) {
14
+ const dir = join(homedir(), 'digdig', 'logs');
15
+ const path = join(dir, 'feedback.jsonl');
16
+ await mkdir(dir, { recursive: true, mode: 0o700 });
17
+ const lockPath = join(dir, '.feedback.lock');
18
+ const lock = await open(lockPath, 'wx', 0o600);
19
+ try {
20
+ for (const line of lines) {
21
+ const size = await stat(path).then(s => s.size, () => 0);
22
+ if (size + Buffer.byteLength(line) > MAX_BYTES) {
23
+ for (let n = 3; n >= 1; n--) {
24
+ await rename(`${path}.${n}`, `${path}.${n + 1}`).catch(error => {
25
+ if (error.code !== 'ENOENT')
26
+ throw error;
27
+ });
28
+ }
29
+ await rename(path, `${path}.1`).catch(error => {
30
+ if (error.code !== 'ENOENT')
31
+ throw error;
32
+ });
33
+ }
34
+ await appendFile(path, line, { mode: 0o600 });
35
+ }
36
+ }
37
+ finally {
38
+ await lock.close();
39
+ await unlink(lockPath).catch(() => { });
40
+ }
41
+ }
42
+ function drain() {
43
+ if (writing || !queue.length)
44
+ return;
45
+ writing = true;
46
+ const batch = queue;
47
+ queue = [];
48
+ void writeBatch(batch).catch(() => { }).finally(() => {
49
+ writing = false;
50
+ drain();
51
+ });
52
+ }
53
+ export function feedbackLog(event, status, fields = {}) {
54
+ if (process.env.DIGDIG_LOG !== '1' || !events.includes(event) || !statuses.includes(status))
55
+ return;
56
+ const record = { time: new Date().toISOString(), runId, event, status };
57
+ for (const key of ['durationMs', 'count', 'total', 'failed']) {
58
+ const value = fields[key];
59
+ if (typeof value === 'number' && Number.isFinite(value) && value >= 0)
60
+ record[key] = Math.floor(value);
61
+ }
62
+ if (fields.provider && providers.includes(fields.provider))
63
+ record.provider = fields.provider;
64
+ if (fields.error && errors.includes(fields.error))
65
+ record.error = fields.error;
66
+ // shortcut: events beyond the bounded queue are dropped; upgrade to a durable spool if complete audit records are needed.
67
+ if (queue.length >= 1000)
68
+ return;
69
+ queue.push(`${JSON.stringify(record)}\n`);
70
+ drain();
71
+ }
72
+ export function feedbackError(error) {
73
+ const code = typeof error === 'object' && error !== null && 'code' in error ? error.code : undefined;
74
+ return typeof code === 'string' && errors.includes(code) ? code : 'unknown';
75
+ }
76
+ //# sourceMappingURL=feedback-log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feedback-log.js","sourceRoot":"","sources":["../src/feedback-log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,SAAS,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACnC,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;AAC3B,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,CAAU,CAAC;AAC9I,MAAM,QAA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MAAM,IAAI,KAAK,CAAC,CAAC,CAAE,KAA2B,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5H,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAiB,CAAC,CAAC,CAAC,CAAC,IAAiB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1G,CAAC"}
@@ -5,6 +5,12 @@
5
5
  * used by SearXNGService, so it can be selected explicitly with `-e ollama`.
6
6
  */
7
7
  import { SearchResponse } from './service.js';
8
+ /**
9
+ * Ollama's hard ceiling: `max_results` is documented as "default 5, max 10".
10
+ * Exported so the router can tell the user when a larger `--limit` is capped
11
+ * instead of silently returning fewer results than asked for.
12
+ */
13
+ export declare const MAX_RESULTS = 10;
8
14
  export interface OllamaServiceOptions {
9
15
  apiKey: string;
10
16
  baseUrl?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ollama-service.d.ts","sourceRoot":"","sources":["../src/ollama-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAgB,cAAc,EAAE,MAAM,cAAc,CAAC;AAG5D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAS;gBAEX,IAAI,EAAE,oBAAoB;IAShC,MAAM,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;CAsDlF"}
1
+ {"version":3,"file":"ollama-service.d.ts","sourceRoot":"","sources":["../src/ollama-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAgB,cAAc,EAAE,MAAM,cAAc,CAAC;AAG5D;;;;GAIG;AACH,eAAO,MAAM,WAAW,KAAK,CAAC;AAE9B,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAS;gBAEX,IAAI,EAAE,oBAAoB;IAShC,MAAM,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;CAsDlF"}
@@ -6,6 +6,12 @@
6
6
  */
7
7
  import axios from 'axios';
8
8
  import { SearchError, searchErrorFromStatus } from './errors.js';
9
+ /**
10
+ * Ollama's hard ceiling: `max_results` is documented as "default 5, max 10".
11
+ * Exported so the router can tell the user when a larger `--limit` is capped
12
+ * instead of silently returning fewer results than asked for.
13
+ */
14
+ export const MAX_RESULTS = 10;
9
15
  export class OllamaService {
10
16
  client;
11
17
  apiKey;
@@ -18,7 +24,7 @@ export class OllamaService {
18
24
  });
19
25
  }
20
26
  async search(options) {
21
- const maxResults = Math.min(options.limit ?? 5, 10);
27
+ const maxResults = Math.min(options.limit ?? 5, MAX_RESULTS);
22
28
  // This method used to have no try/catch at all, so axios's raw AxiosError
23
29
  // escaped to the caller, which reported it as `Request failed with status
24
30
  // code 401` — axios's wording, and with no way to tell an auth failure from
@@ -1 +1 @@
1
- {"version":3,"file":"ollama-service.js","sourceRoot":"","sources":["../src/ollama-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAQjE,MAAM,OAAO,aAAa;IAChB,MAAM,CAAgB;IACtB,MAAM,CAAS;IAEvB,YAAY,IAA0B;QACpC,IA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AAE,MAAM,EAAO,GAAG,OAAO,CAmkB1D;AASD,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwR5F"}
1
+ {"version":3,"file":"runCli.d.ts","sourceRoot":"","sources":["../src/runCli.ts"],"names":[],"mappings":"AACA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,OAAO,EAAE,cAAc,EAAoE,MAAM,cAAc,CAAC;AAyzBhH,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAM,EAAO,GAAG,OAAO,CAmkB1D;AASD,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwR5F"}
package/dist/runCli.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { feedbackLog, feedbackError } from './feedback-log.js';
1
2
  /**
2
3
  * SearXNG CLI - CLI Runner (Commander-based)
3
4
  */
@@ -12,8 +13,8 @@ import { SessionStateError } from './deep/session-lock.js';
12
13
  import { createSuccessEnvelope, createErrorEnvelope } from './protocol.js';
13
14
  import { SearchError } from './errors.js';
14
15
  import { config } from './config.js';
15
- import { OllamaService } from './ollama-service.js';
16
- import { DeepSeekService } from './deepseek-service.js';
16
+ import { OllamaService, MAX_RESULTS as OLLAMA_MAX_RESULTS } from './ollama-service.js';
17
+ import { DeepSeekService, MAX_RESULTS as DEEPSEEK_MAX_RESULTS } from './deepseek-service.js';
17
18
  import { initConfig } from './init.js';
18
19
  import { runExtract } from './commands/extract.js';
19
20
  import { runQueryGraph } from './commands/query-graph.js';
@@ -146,6 +147,15 @@ function formatAsMarkdown(data) {
146
147
  lines.push(note);
147
148
  lines.push('');
148
149
  }
150
+ // Same place and form as the unresponsive-engine line: both describe the
151
+ // request that was made, not the results that came back.
152
+ if (data.limitNotes && data.limitNotes.length > 0) {
153
+ const capped = data.limitNotes
154
+ .map((entry) => `${entry.provider} (asked for ${entry.requested}, provider caps at ${entry.applied})`)
155
+ .join(', ');
156
+ lines.push(`*Limit capped: ${capped}*`);
157
+ lines.push('');
158
+ }
149
159
  if (data.suggestions && data.suggestions.length > 0) {
150
160
  lines.push('**Suggestions:** ' + data.suggestions.join(' · '));
151
161
  lines.push('');
@@ -319,10 +329,12 @@ const EXTERNAL_PROVIDERS = ['ollama', 'deepseek'];
319
329
  const PROVIDER_IMPLS = {
320
330
  ollama: {
321
331
  configured: () => Boolean(config.ollamaApiKey),
332
+ maxResults: OLLAMA_MAX_RESULTS,
322
333
  search: (query, limit) => new OllamaService({ apiKey: config.ollamaApiKey }).search({ query, limit }),
323
334
  },
324
335
  deepseek: {
325
336
  configured: () => Boolean(config.deepseekApiKey),
337
+ maxResults: DEEPSEEK_MAX_RESULTS,
326
338
  search: (query, limit) => new DeepSeekService({ apiKey: config.deepseekApiKey }).search({ query, limit }),
327
339
  },
328
340
  };
@@ -344,34 +356,65 @@ async function searchOneQuery(service, plan, searchOptions, limit) {
344
356
  if (plan.usable.length === 0 || plan.sxngEngines.length > 0)
345
357
  assertSearXNGConfig();
346
358
  const providerResponses = [];
359
+ const limitNotes = [];
347
360
  for (const provider of plan.usable) {
348
- providerResponses.push(await PROVIDER_IMPLS[provider].search(searchOptions.query, limit));
361
+ const started = Date.now();
362
+ feedbackLog('provider', 'start', { provider });
363
+ try {
364
+ const response = await PROVIDER_IMPLS[provider].search(searchOptions.query, limit);
365
+ feedbackLog('provider', 'ok', { provider, durationMs: Date.now() - started, count: response.results.length });
366
+ // The provider caps the count itself, so compare against its ceiling
367
+ // rather than against what came back: a provider may also return
368
+ // fewer results than the ceiling for reasons of its own, and that is
369
+ // not a downgrade this invocation caused.
370
+ const applied = PROVIDER_IMPLS[provider].maxResults;
371
+ if (limit > applied)
372
+ limitNotes.push({ provider, requested: limit, applied });
373
+ providerResponses.push(response);
374
+ }
375
+ catch (error) {
376
+ feedbackLog('provider', 'error', { provider, durationMs: Date.now() - started, error: feedbackError(error) });
377
+ throw error;
378
+ }
349
379
  }
350
380
  let sxngResponse = null;
351
381
  if (plan.usable.length === 0 || plan.sxngEngines.length > 0) {
352
- sxngResponse = await service.search({
353
- ...searchOptions,
354
- engines: plan.sxngEngines.length > 0 ? plan.sxngEngines : searchOptions.engines,
355
- });
382
+ const started = Date.now();
383
+ feedbackLog('provider', 'start', { provider: 'searxng' });
384
+ try {
385
+ sxngResponse = await service.search({
386
+ ...searchOptions,
387
+ engines: plan.sxngEngines.length > 0 ? plan.sxngEngines : searchOptions.engines,
388
+ });
389
+ feedbackLog('provider', 'ok', { provider: 'searxng', durationMs: Date.now() - started, count: sxngResponse.results.length });
390
+ }
391
+ catch (error) {
392
+ feedbackLog('provider', 'error', { provider: 'searxng', durationMs: Date.now() - started, error: feedbackError(error) });
393
+ throw error;
394
+ }
356
395
  }
357
- return { providerResponses, sxngResponse };
396
+ return { providerResponses, sxngResponse, limitNotes };
358
397
  }
359
398
  /** Attribute a result to the tool that produced it, for session origin records. */
360
399
  function originTool(engine) {
361
400
  return EXTERNAL_PROVIDERS.includes(engine) ? engine : 'digdig';
362
401
  }
363
- async function runSearch(service, options) {
402
+ async function runSearchInner(service, options) {
403
+ feedbackLog('validation', 'start');
364
404
  if (options.limit !== undefined && (!Number.isSafeInteger(options.limit) || options.limit <= 0)) {
405
+ feedbackLog('validation', 'error', { error: 'validation' });
365
406
  console.log(JSON.stringify(createErrorEnvelope('INVALID_LIMIT', 'Limit must be a positive safe integer'), null, 2));
366
407
  return 1;
367
408
  }
368
409
  const queries = options.queries || (options.query ? [options.query] : []);
369
410
  if (queries.length === 0) {
411
+ feedbackLog('validation', 'error', { error: 'validation' });
370
412
  const envelope = createErrorEnvelope('MISSING_QUERY', 'No search query provided', { hint: 'Use: dg "your search query" or dg --queries "q1,q2,q3"' });
371
413
  console.log(JSON.stringify(envelope, null, 2));
372
414
  return 1;
373
415
  }
374
416
  if (options.engines && options.engines.length === 0) {
417
+ feedbackLog('validation', 'error', { error: 'validation' });
375
418
  console.log(JSON.stringify(createErrorEnvelope('INVALID_ENGINES', 'At least one engine must be specified'), null, 2));
376
419
  return 1;
377
420
  }
@@ -379,6 +422,7 @@ async function runSearch(service, options) {
379
422
  if (config.allowedEngines.length > 0) {
380
423
  const invalid = engines.filter(e => !config.allowedEngines.includes(e));
381
424
  if (invalid.length > 0) {
425
+ feedbackLog('validation', 'error', { error: 'validation' });
382
426
  const envelope = createErrorEnvelope('INVALID_ENGINES', `Engines not allowed: ${invalid.join(', ')}`, { hint: `Allowed engines: ${config.allowedEngines.join(', ')}` });
383
427
  console.log(JSON.stringify(envelope, null, 2));
384
428
  return 1;
@@ -389,6 +433,7 @@ async function runSearch(service, options) {
389
433
  if (engines.length > 0) {
390
434
  const unconfigured = planProviderSearch(engines).unconfigured;
391
435
  if (unconfigured.length > 0) {
436
+ feedbackLog('validation', 'error', { error: 'CONFIG_MISSING' });
392
437
  const envelope = createErrorEnvelope('PROVIDER_NOT_CONFIGURED', `Provider selected but no API key configured: ${unconfigured.join(', ')}`, { hint: unconfigured.map(p => p === 'ollama'
393
438
  ? 'Set OLLAMA_API_KEY or add "ollamaApiKey" to digdig.config.json'
394
439
  : 'Set DEEPSEEK_API_KEY or add "deepseekApiKey" to digdig.config.json').join('; ') });
@@ -396,6 +441,7 @@ async function runSearch(service, options) {
396
441
  return 1;
397
442
  }
398
443
  }
444
+ feedbackLog('validation', 'ok', { count: queries.length });
399
445
  const limit = options.limit ?? config.defaultLimit;
400
446
  if (options.session) {
401
447
  const resolved = resolveSessionPath(options.session);
@@ -404,6 +450,7 @@ async function runSearch(service, options) {
404
450
  }
405
451
  // Pre-search redundancy check
406
452
  if (options.redundancy && options.session) {
453
+ feedbackLog('redundancy', 'start', { count: queries.length });
407
454
  const history = loadSessionQueryHistory(options.session);
408
455
  const redundancyConfig = {
409
456
  jaccardThreshold: config.redundancyThreshold,
@@ -487,6 +534,7 @@ async function runSearch(service, options) {
487
534
  }
488
535
  }
489
536
  if (skippedQueries.length > 0 && skippedQueries.length === queries.length) {
537
+ feedbackLog('redundancy', 'skip', { count: skippedQueries.length });
490
538
  // All queries skipped
491
539
  const envelope = createSuccessEnvelope({
492
540
  message: 'All queries skipped due to redundancy',
@@ -495,6 +543,7 @@ async function runSearch(service, options) {
495
543
  console.log(JSON.stringify(envelope, null, 2));
496
544
  return 0;
497
545
  }
546
+ feedbackLog('redundancy', 'ok', { count: adjustedQueries.length, failed: skippedQueries.length });
498
547
  // Replace queries with adjusted ones (skipped ones removed)
499
548
  queries.length = 0;
500
549
  queries.push(...adjustedQueries);
@@ -520,6 +569,9 @@ async function runSearch(service, options) {
520
569
  // how many responses land in the array.
521
570
  const plan = planProviderSearch(engines);
522
571
  const responses = [];
572
+ // One note per provider across every query in this invocation: repeating
573
+ // "ollama capped at 10" once per query would bury the fact in noise.
574
+ const limitNotes = [];
523
575
  let searchRound;
524
576
  for (const query of queries) {
525
577
  const searchOptions = {
@@ -531,9 +583,13 @@ async function runSearch(service, options) {
531
583
  language: options.language,
532
584
  timeRange: options.timeRange,
533
585
  };
534
- const { providerResponses, sxngResponse } = await searchOneQuery(service, plan, searchOptions, limit);
586
+ const { providerResponses, sxngResponse, limitNotes: notes } = await searchOneQuery(service, plan, searchOptions, limit);
535
587
  if (options.session)
536
588
  searchRound = recordSuccessfulQuery(options.session, query, searchRound);
589
+ for (const note of notes) {
590
+ if (!limitNotes.some(existing => existing.provider === note.provider))
591
+ limitNotes.push(note);
592
+ }
537
593
  responses.push(...providerResponses);
538
594
  if (sxngResponse)
539
595
  responses.push(sxngResponse);
@@ -541,6 +597,8 @@ async function runSearch(service, options) {
541
597
  // Snapshot before writing: history must not include this invocation's own
542
598
  // results, or every current result votes for itself a second time.
543
599
  const sessionSnapshot = options.session ? loadSessionResults(options.session) : undefined;
600
+ const fusionStarted = Date.now();
601
+ feedbackLog('fusion', 'start', { count: responses.length });
544
602
  const fusion = fuseResults({
545
603
  responses,
546
604
  mergeResults,
@@ -549,8 +607,10 @@ async function runSearch(service, options) {
549
607
  limit,
550
608
  toolFor: engine => originTool(engine),
551
609
  });
610
+ feedbackLog('fusion', 'ok', { durationMs: Date.now() - fusionStarted, count: fusion.fused.length, total: fusion.display.length });
552
611
  let sessionInfo = null;
553
612
  if (options.session) {
613
+ feedbackLog('session', 'start');
554
614
  sessionInfo = appendAndInjectSessionResults(options.session, fusion.display.map((result, index) => ({
555
615
  ...result,
556
616
  // The fused position, so `rank` and `fusionScore` describe the same
@@ -558,6 +618,7 @@ async function runSearch(service, options) {
558
618
  rank: index + 1,
559
619
  origins: fusion.originsByKey.get(resultUrlKey(result)),
560
620
  })), searchRound);
621
+ feedbackLog('session', 'ok', { count: sessionInfo.added, total: sessionInfo.total });
561
622
  const pendingCount = countPendingResults(options.session);
562
623
  if (pendingCount >= 30) {
563
624
  console.error(`[session] ${pendingCount} pending results awaiting Agent review. Run --quality to list them.`);
@@ -588,6 +649,9 @@ async function runSearch(service, options) {
588
649
  // request, not any individual result.
589
650
  ...(options.timeRange ? { timeRange: options.timeRange } : {}),
590
651
  ...(options.language ? { language: options.language } : {}),
652
+ // Absent when nothing was capped, so a request the providers could
653
+ // honour in full keeps the exact shape it had before this field.
654
+ ...(limitNotes.length ? { limitNotes } : {}),
591
655
  ...(sessionInfo ? { session: { dir: options.session, added: sessionInfo.added, total: sessionInfo.total } } : {}),
592
656
  };
593
657
  if (outputFormat === 'md') {
@@ -607,6 +671,7 @@ async function runSearch(service, options) {
607
671
  return 0;
608
672
  }
609
673
  catch (error) {
674
+ feedbackLog('search', 'error', { error: feedbackError(error) });
610
675
  if (error instanceof SessionStateError) {
611
676
  console.log(JSON.stringify(createErrorEnvelope(error.code, error.message, { retryable: error.code === 'SESSION_BUSY' }), null, 2));
612
677
  return 1;
@@ -630,6 +695,19 @@ async function runSearch(service, options) {
630
695
  return 1;
631
696
  }
632
697
  }
698
+ async function runSearch(service, options) {
699
+ const started = Date.now();
700
+ feedbackLog('search', 'start');
701
+ try {
702
+ const result = await runSearchInner(service, options);
703
+ feedbackLog('search', result === 0 ? 'ok' : 'error', { durationMs: Date.now() - started });
704
+ return result;
705
+ }
706
+ catch (error) {
707
+ feedbackLog('search', 'error', { durationMs: Date.now() - started, error: feedbackError(error) });
708
+ throw error;
709
+ }
710
+ }
633
711
  function parseLimit(value) {
634
712
  return /^\d+$/.test(value) ? Number(value) : NaN;
635
713
  }