digdig 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/README.md +437 -2
  2. package/digdig.config.example.json +14 -0
  3. package/dist/claims/deterministic-checks.d.ts +48 -0
  4. package/dist/claims/deterministic-checks.d.ts.map +1 -0
  5. package/dist/claims/deterministic-checks.js +162 -0
  6. package/dist/claims/deterministic-checks.js.map +1 -0
  7. package/dist/claims/policy.d.ts +25 -0
  8. package/dist/claims/policy.d.ts.map +1 -0
  9. package/dist/claims/policy.js +168 -0
  10. package/dist/claims/policy.js.map +1 -0
  11. package/dist/claims/store.d.ts +37 -0
  12. package/dist/claims/store.d.ts.map +1 -0
  13. package/dist/claims/store.js +152 -0
  14. package/dist/claims/store.js.map +1 -0
  15. package/dist/claims/types.d.ts +98 -0
  16. package/dist/claims/types.d.ts.map +1 -0
  17. package/dist/claims/types.js +9 -0
  18. package/dist/claims/types.js.map +1 -0
  19. package/dist/commands/claim.d.ts +13 -0
  20. package/dist/commands/claim.d.ts.map +1 -0
  21. package/dist/commands/claim.js +131 -0
  22. package/dist/commands/claim.js.map +1 -0
  23. package/dist/commands/coverage.d.ts +7 -0
  24. package/dist/commands/coverage.d.ts.map +1 -0
  25. package/dist/commands/coverage.js +78 -0
  26. package/dist/commands/coverage.js.map +1 -0
  27. package/dist/commands/doc-index.d.ts +12 -0
  28. package/dist/commands/doc-index.d.ts.map +1 -0
  29. package/dist/commands/doc-index.js +49 -0
  30. package/dist/commands/doc-index.js.map +1 -0
  31. package/dist/commands/doc-search.d.ts +16 -0
  32. package/dist/commands/doc-search.d.ts.map +1 -0
  33. package/dist/commands/doc-search.js +41 -0
  34. package/dist/commands/doc-search.js.map +1 -0
  35. package/dist/commands/evidence.d.ts +20 -0
  36. package/dist/commands/evidence.d.ts.map +1 -0
  37. package/dist/commands/evidence.js +215 -0
  38. package/dist/commands/evidence.js.map +1 -0
  39. package/dist/commands/extract.d.ts +10 -0
  40. package/dist/commands/extract.d.ts.map +1 -0
  41. package/dist/commands/extract.js +77 -0
  42. package/dist/commands/extract.js.map +1 -0
  43. package/dist/commands/graph-add.d.ts +7 -0
  44. package/dist/commands/graph-add.d.ts.map +1 -0
  45. package/dist/commands/graph-add.js +93 -0
  46. package/dist/commands/graph-add.js.map +1 -0
  47. package/dist/commands/graph-drill.d.ts +11 -0
  48. package/dist/commands/graph-drill.d.ts.map +1 -0
  49. package/dist/commands/graph-drill.js +26 -0
  50. package/dist/commands/graph-drill.js.map +1 -0
  51. package/dist/commands/graph-explore.d.ts +10 -0
  52. package/dist/commands/graph-explore.d.ts.map +1 -0
  53. package/dist/commands/graph-explore.js +32 -0
  54. package/dist/commands/graph-explore.js.map +1 -0
  55. package/dist/commands/graph-obfuscate.d.ts +17 -0
  56. package/dist/commands/graph-obfuscate.d.ts.map +1 -0
  57. package/dist/commands/graph-obfuscate.js +110 -0
  58. package/dist/commands/graph-obfuscate.js.map +1 -0
  59. package/dist/commands/graph-search.d.ts +11 -0
  60. package/dist/commands/graph-search.d.ts.map +1 -0
  61. package/dist/commands/graph-search.js +19 -0
  62. package/dist/commands/graph-search.js.map +1 -0
  63. package/dist/commands/graph-traverse.d.ts +10 -0
  64. package/dist/commands/graph-traverse.d.ts.map +1 -0
  65. package/dist/commands/graph-traverse.js +39 -0
  66. package/dist/commands/graph-traverse.js.map +1 -0
  67. package/dist/commands/json-input.d.ts +18 -0
  68. package/dist/commands/json-input.d.ts.map +1 -0
  69. package/dist/commands/json-input.js +50 -0
  70. package/dist/commands/json-input.js.map +1 -0
  71. package/dist/commands/query-graph.d.ts +13 -0
  72. package/dist/commands/query-graph.d.ts.map +1 -0
  73. package/dist/commands/query-graph.js +219 -0
  74. package/dist/commands/query-graph.js.map +1 -0
  75. package/dist/commands/results-add.d.ts +10 -0
  76. package/dist/commands/results-add.d.ts.map +1 -0
  77. package/dist/commands/results-add.js +80 -0
  78. package/dist/commands/results-add.js.map +1 -0
  79. package/dist/commands/review.d.ts +12 -0
  80. package/dist/commands/review.d.ts.map +1 -0
  81. package/dist/commands/review.js +119 -0
  82. package/dist/commands/review.js.map +1 -0
  83. package/dist/commands/session.d.ts +28 -0
  84. package/dist/commands/session.d.ts.map +1 -0
  85. package/dist/commands/session.js +149 -0
  86. package/dist/commands/session.js.map +1 -0
  87. package/dist/commands/verdict.d.ts +9 -0
  88. package/dist/commands/verdict.d.ts.map +1 -0
  89. package/dist/commands/verdict.js +40 -0
  90. package/dist/commands/verdict.js.map +1 -0
  91. package/dist/config.d.ts +28 -0
  92. package/dist/config.d.ts.map +1 -0
  93. package/dist/config.js +148 -0
  94. package/dist/config.js.map +1 -0
  95. package/dist/deep/co-occurrence.d.ts +50 -0
  96. package/dist/deep/co-occurrence.d.ts.map +1 -0
  97. package/dist/deep/co-occurrence.js +95 -0
  98. package/dist/deep/co-occurrence.js.map +1 -0
  99. package/dist/deep/coverage.d.ts +81 -0
  100. package/dist/deep/coverage.d.ts.map +1 -0
  101. package/dist/deep/coverage.js +183 -0
  102. package/dist/deep/coverage.js.map +1 -0
  103. package/dist/deep/dedupe.d.ts +27 -0
  104. package/dist/deep/dedupe.d.ts.map +1 -0
  105. package/dist/deep/dedupe.js +115 -0
  106. package/dist/deep/dedupe.js.map +1 -0
  107. package/dist/deep/degree-utils.d.ts +39 -0
  108. package/dist/deep/degree-utils.d.ts.map +1 -0
  109. package/dist/deep/degree-utils.js +42 -0
  110. package/dist/deep/degree-utils.js.map +1 -0
  111. package/dist/deep/extractor.d.ts +42 -0
  112. package/dist/deep/extractor.d.ts.map +1 -0
  113. package/dist/deep/extractor.js +392 -0
  114. package/dist/deep/extractor.js.map +1 -0
  115. package/dist/deep/fuse.d.ts +63 -0
  116. package/dist/deep/fuse.d.ts.map +1 -0
  117. package/dist/deep/fuse.js +108 -0
  118. package/dist/deep/fuse.js.map +1 -0
  119. package/dist/deep/graph-explore.d.ts +115 -0
  120. package/dist/deep/graph-explore.d.ts.map +1 -0
  121. package/dist/deep/graph-explore.js +588 -0
  122. package/dist/deep/graph-explore.js.map +1 -0
  123. package/dist/deep/graph-obfuscate.d.ts +51 -0
  124. package/dist/deep/graph-obfuscate.d.ts.map +1 -0
  125. package/dist/deep/graph-obfuscate.js +226 -0
  126. package/dist/deep/graph-obfuscate.js.map +1 -0
  127. package/dist/deep/graph-preprocess.d.ts +48 -0
  128. package/dist/deep/graph-preprocess.d.ts.map +1 -0
  129. package/dist/deep/graph-preprocess.js +40 -0
  130. package/dist/deep/graph-preprocess.js.map +1 -0
  131. package/dist/deep/graph-sampling.d.ts +51 -0
  132. package/dist/deep/graph-sampling.d.ts.map +1 -0
  133. package/dist/deep/graph-sampling.js +410 -0
  134. package/dist/deep/graph-sampling.js.map +1 -0
  135. package/dist/deep/graph.d.ts +87 -0
  136. package/dist/deep/graph.d.ts.map +1 -0
  137. package/dist/deep/graph.js +200 -0
  138. package/dist/deep/graph.js.map +1 -0
  139. package/dist/deep/index.d.ts +10 -0
  140. package/dist/deep/index.d.ts.map +1 -0
  141. package/dist/deep/index.js +10 -0
  142. package/dist/deep/index.js.map +1 -0
  143. package/dist/deep/iteration-data.d.ts +34 -0
  144. package/dist/deep/iteration-data.d.ts.map +1 -0
  145. package/dist/deep/iteration-data.js +45 -0
  146. package/dist/deep/iteration-data.js.map +1 -0
  147. package/dist/deep/local-doc/indexer.d.ts +26 -0
  148. package/dist/deep/local-doc/indexer.d.ts.map +1 -0
  149. package/dist/deep/local-doc/indexer.js +420 -0
  150. package/dist/deep/local-doc/indexer.js.map +1 -0
  151. package/dist/deep/local-doc/scanner.d.ts +10 -0
  152. package/dist/deep/local-doc/scanner.d.ts.map +1 -0
  153. package/dist/deep/local-doc/scanner.js +165 -0
  154. package/dist/deep/local-doc/scanner.js.map +1 -0
  155. package/dist/deep/local-doc/searcher.d.ts +38 -0
  156. package/dist/deep/local-doc/searcher.d.ts.map +1 -0
  157. package/dist/deep/local-doc/searcher.js +211 -0
  158. package/dist/deep/local-doc/searcher.js.map +1 -0
  159. package/dist/deep/local-doc/types.d.ts +61 -0
  160. package/dist/deep/local-doc/types.d.ts.map +1 -0
  161. package/dist/deep/local-doc/types.js +18 -0
  162. package/dist/deep/local-doc/types.js.map +1 -0
  163. package/dist/deep/path-extraction.d.ts +53 -0
  164. package/dist/deep/path-extraction.d.ts.map +1 -0
  165. package/dist/deep/path-extraction.js +229 -0
  166. package/dist/deep/path-extraction.js.map +1 -0
  167. package/dist/deep/pending-facts.d.ts +64 -0
  168. package/dist/deep/pending-facts.d.ts.map +1 -0
  169. package/dist/deep/pending-facts.js +74 -0
  170. package/dist/deep/pending-facts.js.map +1 -0
  171. package/dist/deep/query-redundancy.d.ts +52 -0
  172. package/dist/deep/query-redundancy.d.ts.map +1 -0
  173. package/dist/deep/query-redundancy.js +122 -0
  174. package/dist/deep/query-redundancy.js.map +1 -0
  175. package/dist/deep/query-suggest.d.ts +33 -0
  176. package/dist/deep/query-suggest.d.ts.map +1 -0
  177. package/dist/deep/query-suggest.js +90 -0
  178. package/dist/deep/query-suggest.js.map +1 -0
  179. package/dist/deep/rrf.d.ts +13 -0
  180. package/dist/deep/rrf.d.ts.map +1 -0
  181. package/dist/deep/rrf.js +23 -0
  182. package/dist/deep/rrf.js.map +1 -0
  183. package/dist/deep/search-strategy.d.ts +37 -0
  184. package/dist/deep/search-strategy.d.ts.map +1 -0
  185. package/dist/deep/search-strategy.js +106 -0
  186. package/dist/deep/search-strategy.js.map +1 -0
  187. package/dist/deep/session.d.ts +182 -0
  188. package/dist/deep/session.d.ts.map +1 -0
  189. package/dist/deep/session.js +663 -0
  190. package/dist/deep/session.js.map +1 -0
  191. package/dist/deep/simhash.d.ts +17 -0
  192. package/dist/deep/simhash.d.ts.map +1 -0
  193. package/dist/deep/simhash.js +72 -0
  194. package/dist/deep/simhash.js.map +1 -0
  195. package/dist/deep/tfidf.d.ts +38 -0
  196. package/dist/deep/tfidf.d.ts.map +1 -0
  197. package/dist/deep/tfidf.js +103 -0
  198. package/dist/deep/tfidf.js.map +1 -0
  199. package/dist/deepseek-service.d.ts +22 -0
  200. package/dist/deepseek-service.d.ts.map +1 -0
  201. package/dist/deepseek-service.js +84 -0
  202. package/dist/deepseek-service.js.map +1 -0
  203. package/dist/entry.d.ts +14 -0
  204. package/dist/entry.d.ts.map +1 -0
  205. package/dist/entry.js +29 -0
  206. package/dist/entry.js.map +1 -0
  207. package/dist/errors.d.ts +76 -0
  208. package/dist/errors.d.ts.map +1 -0
  209. package/dist/errors.js +117 -0
  210. package/dist/errors.js.map +1 -0
  211. package/dist/index.d.ts +6 -0
  212. package/dist/index.d.ts.map +1 -0
  213. package/dist/index.js +7 -0
  214. package/dist/index.js.map +1 -0
  215. package/dist/init.d.ts +16 -0
  216. package/dist/init.d.ts.map +1 -0
  217. package/dist/init.js +143 -0
  218. package/dist/init.js.map +1 -0
  219. package/dist/legacy.d.ts +60 -0
  220. package/dist/legacy.d.ts.map +1 -0
  221. package/dist/legacy.js +119 -0
  222. package/dist/legacy.js.map +1 -0
  223. package/dist/ollama-service.d.ts +22 -0
  224. package/dist/ollama-service.d.ts.map +1 -0
  225. package/dist/ollama-service.js +71 -0
  226. package/dist/ollama-service.js.map +1 -0
  227. package/dist/protocol.d.ts +23 -0
  228. package/dist/protocol.d.ts.map +1 -0
  229. package/dist/protocol.js +26 -0
  230. package/dist/protocol.js.map +1 -0
  231. package/dist/runCli.d.ts +8 -0
  232. package/dist/runCli.d.ts.map +1 -0
  233. package/dist/runCli.js +1356 -0
  234. package/dist/runCli.js.map +1 -0
  235. package/dist/service.d.ts +73 -0
  236. package/dist/service.d.ts.map +1 -0
  237. package/dist/service.js +145 -0
  238. package/dist/service.js.map +1 -0
  239. package/dist/sxng.d.ts +11 -0
  240. package/dist/sxng.d.ts.map +1 -0
  241. package/dist/sxng.js +14 -0
  242. package/dist/sxng.js.map +1 -0
  243. package/package.json +56 -12
@@ -0,0 +1,183 @@
1
+ /**
2
+ * What this session has looked at, as countable facts.
3
+ *
4
+ * A search now shows only what it just found, so the shape of the whole session
5
+ * has to come from somewhere. It does not come from the knowledge graph: graph
6
+ * structure is built from *approved* results, so it is empty exactly while the
7
+ * decision is still open, and a session that is three rounds in but has not
8
+ * approved anything has no graph at all.
9
+ *
10
+ * It does not come from a topic model either. The judgement "these results
11
+ * cover four aspects and miss a fifth" is a judgement, and the cheap ways of
12
+ * automating it do not work at this scale: word-bag clustering cannot group two
13
+ * phrasings of one aspect (measured cosine 0.102 same-aspect against 0.012
14
+ * cross-aspect, and no pair cleared a 0.3 threshold), and a real embedding model
15
+ * is too heavy for a CLI. So this module reports only what can be counted, and
16
+ * the caller draws the conclusion.
17
+ */
18
+ import { sourceKey } from './dedupe.js';
19
+ import { tokenize } from './tfidf.js';
20
+ const REPEATED_TITLES_PER_ROUND = 15;
21
+ /**
22
+ * Source types a deep question usually needs and a general web search rarely
23
+ * returns: papers, code, package registries, Q&A. Kept as a list rather than
24
+ * derived, because "is this a primary source for this question" is not
25
+ * something a hostname can answer.
26
+ */
27
+ const SPECIALIZED_SOURCES = [
28
+ 'arxiv.org',
29
+ 'semanticscholar.org',
30
+ 'github.com',
31
+ 'stackoverflow.com',
32
+ 'docs.rs',
33
+ 'npmjs.com',
34
+ 'pypi.org',
35
+ 'crates.io',
36
+ 'medium.com',
37
+ 'dev.to',
38
+ 'reddit.com',
39
+ 'hackernews.com',
40
+ ];
41
+ /**
42
+ * The round a result first appeared in.
43
+ *
44
+ * Exported because the pending-facts report needs the same fact, and a second
45
+ * implementation of "first sighting" would eventually disagree with this one.
46
+ */
47
+ export function firstRound(result) {
48
+ let earliest;
49
+ for (const origin of result.origins ?? []) {
50
+ const round = origin.round;
51
+ if (!Number.isInteger(round))
52
+ continue;
53
+ if (earliest === undefined || round < earliest)
54
+ earliest = round;
55
+ }
56
+ return earliest;
57
+ }
58
+ /** Every round that produced this result, deduplicated and sorted. */
59
+ function roundsOf(result) {
60
+ const rounds = new Set();
61
+ for (const origin of result.origins ?? []) {
62
+ if (Number.isInteger(origin.round))
63
+ rounds.add(origin.round);
64
+ }
65
+ return [...rounds].sort((a, b) => a - b);
66
+ }
67
+ export function buildCoverage(results, rounds, options) {
68
+ const titlesPerRound = options?.titlesPerRound ?? REPEATED_TITLES_PER_ROUND;
69
+ const maxTerms = options?.maxTerms ?? 40;
70
+ const byRound = new Map();
71
+ const repeated = [];
72
+ const factsFor = (round) => {
73
+ const existing = byRound.get(round);
74
+ if (existing)
75
+ return existing;
76
+ const created = {
77
+ round, queries: [], engines: [], newResults: 0,
78
+ repeatedFromEarlier: 0, titles: [],
79
+ };
80
+ byRound.set(round, created);
81
+ return created;
82
+ };
83
+ for (const result of results) {
84
+ const seen = roundsOf(result);
85
+ if (seen.length > 1)
86
+ repeated.push({ url: result.url, rounds: seen });
87
+ const first = firstRound(result);
88
+ if (first === undefined)
89
+ continue;
90
+ // A result belongs to the round that first saw it. Counting it again in
91
+ // a later round would make a re-run look productive.
92
+ const home = factsFor(first);
93
+ home.newResults++;
94
+ if (result.title && home.titles.length < titlesPerRound)
95
+ home.titles.push(result.title);
96
+ // Every round that saw it still recorded a query, and a round whose
97
+ // results were all already known is what saturation looks like.
98
+ for (const round of seen) {
99
+ const facts = factsFor(round);
100
+ if (round > first)
101
+ facts.repeatedFromEarlier++;
102
+ for (const origin of result.origins ?? []) {
103
+ if (origin.round !== round)
104
+ continue;
105
+ if (origin.query && !facts.queries.includes(origin.query))
106
+ facts.queries.push(origin.query);
107
+ if (origin.engine && !facts.engines.includes(origin.engine))
108
+ facts.engines.push(origin.engine);
109
+ }
110
+ }
111
+ }
112
+ return {
113
+ rounds,
114
+ uniqueResults: results.length,
115
+ byRound: [...byRound.values()].sort((a, b) => a.round - b.round),
116
+ repeated: repeated.sort((a, b) => b.rounds.length - a.rounds.length || a.url.localeCompare(b.url)),
117
+ distinctiveTerms: distinctiveTermsOf(results, maxTerms),
118
+ ...domainFactsOf(results),
119
+ };
120
+ }
121
+ /**
122
+ * Which hosts the session has drawn from, and which specialized ones it has not.
123
+ *
124
+ * A `file:` result is a local document; its source is its path, so it counts
125
+ * like any other source rather than vanishing under an empty hostname.
126
+ */
127
+ function domainFactsOf(results) {
128
+ const counts = new Map();
129
+ for (const result of results) {
130
+ const source = sourceKey(result.url);
131
+ if (!source)
132
+ continue;
133
+ counts.set(source, (counts.get(source) ?? 0) + 1);
134
+ }
135
+ const domainsSeen = [...counts.entries()]
136
+ .map(([domain, count]) => ({ domain, results: count }))
137
+ .sort((a, b) => b.results - a.results || a.domain.localeCompare(b.domain));
138
+ const touched = new Set(domainsSeen.map(entry => entry.domain));
139
+ return {
140
+ domainsSeen,
141
+ untouchedSpecialized: SPECIALIZED_SOURCES.filter(source => !touched.has(source)),
142
+ };
143
+ }
144
+ /** Terms that name one round's subject rather than the session's. */
145
+ function distinctiveTermsOf(results, maxTerms) {
146
+ // term → the rounds that used it → how many results in that round used it
147
+ const uses = new Map();
148
+ for (const result of results) {
149
+ // At zero extraction a search result carries only its snippet, and the
150
+ // snippet is what the round actually returned. Extracted results carry
151
+ // the full body instead, so prefer that.
152
+ const text = result.content || result.excerpt;
153
+ if (!text && !result.title)
154
+ continue;
155
+ const round = firstRound(result);
156
+ if (round === undefined)
157
+ continue;
158
+ const seen = new Set(tokenize(`${result.title ?? ''} ${text ?? ''}`));
159
+ for (const term of seen) {
160
+ const byRoundCount = uses.get(term) ?? new Map();
161
+ byRoundCount.set(round, (byRoundCount.get(round) ?? 0) + 1);
162
+ uses.set(term, byRoundCount);
163
+ }
164
+ }
165
+ const terms = [];
166
+ for (const [term, byRoundCount] of uses) {
167
+ // Used in more than one round: it belongs to the shared subject, not to
168
+ // any single round's aspect.
169
+ if (byRoundCount.size !== 1)
170
+ continue;
171
+ const [round, count] = [...byRoundCount.entries()][0];
172
+ // Seen once is a stray token, not a pattern.
173
+ if (count < 2)
174
+ continue;
175
+ terms.push({ term, round, docFreq: count });
176
+ }
177
+ // Strongest within-round repetition first, then alphabetical so the output
178
+ // is stable across runs.
179
+ return terms
180
+ .sort((a, b) => b.docFreq - a.docFreq || a.round - b.round || a.term.localeCompare(b.term))
181
+ .slice(0, maxTerms);
182
+ }
183
+ //# sourceMappingURL=coverage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.js","sourceRoot":"","sources":["../../src/deep/coverage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA6CtC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG;IACxB,WAAW;IACX,qBAAqB;IACrB,YAAY;IACZ,mBAAmB;IACnB,SAAS;IACT,WAAW;IACX,UAAU;IACV,WAAW;IACX,YAAY;IACZ,QAAQ;IACR,YAAY;IACZ,gBAAgB;CACnB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,MAAqB;IAC5C,IAAI,QAA4B,CAAC;IACjC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAAE,SAAS;QACvC,IAAI,QAAQ,KAAK,SAAS,IAAI,KAAM,GAAG,QAAQ;YAAE,QAAQ,GAAG,KAAK,CAAC;IACtE,CAAC;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,sEAAsE;AACtE,SAAS,QAAQ,CAAC,MAAqB;IACnC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;QACxC,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CA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EAAwE;QACxE,6BAA6B;QAC7B,IAAI,YAAY,CAAC,IAAI,KAAK,CAAC;YAAE,SAAS;QACtC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACtD,6CAA6C;QAC7C,IAAI,KAAK,GAAG,CAAC;YAAE,SAAS;QACxB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,2EAA2E;IAC3E,yBAAyB;IACzB,OAAO,KAAK;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SAC1F,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Deduplication utilities for search results
3
+ */
4
+ export interface DedupItem {
5
+ url: string;
6
+ title: string;
7
+ content: string;
8
+ }
9
+ /** Keep a local document's chunk fragment, while normalizing all other URLs. */
10
+ export declare function resultUrlKey(result: {
11
+ url: string;
12
+ source?: string;
13
+ }): string;
14
+ /**
15
+ * The source a result came from, for counting distinct sources.
16
+ *
17
+ * Distinct from `resultUrlKey`, which identifies the result itself. A `file:`
18
+ * URL has no host, and returning an empty string for it — as the hand-rolled
19
+ * copies of this logic variously did — made a pure local session report zero
20
+ * sources. A local document's source is its path.
21
+ */
22
+ export declare function sourceKey(url: string): string | undefined;
23
+ export declare function dedupeByUrl<T extends DedupItem>(items: T[]): T[];
24
+ export declare function jaccardSimilarity(left: string, right: string): number;
25
+ export declare function dedupeByJaccard<T extends DedupItem>(items: T[], threshold?: number): T[];
26
+ export declare function dedupe<T extends DedupItem>(items: T[], threshold?: number): T[];
27
+ //# sourceMappingURL=dedupe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dedupe.d.ts","sourceRoot":"","sources":["../../src/deep/dedupe.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,SAAS;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB;AAeD,gFAAgF;AAChF,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAS7E;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQzD;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAWhE;AAiBD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAarE;AAQD,wBAAgB,eAAe,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,GAAE,MAAa,GAAG,CAAC,EAAE,CAsB9F;AAED,wBAAgB,MAAM,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,GAAE,MAAa,GAAG,CAAC,EAAE,CAGrF"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Deduplication utilities for search results
3
+ */
4
+ function normalizeUrl(url) {
5
+ try {
6
+ const u = new URL(url);
7
+ // Remove trailing slash, sort params, strip fragments
8
+ u.pathname = u.pathname.replace(/\/$/, '') || '/';
9
+ u.hash = '';
10
+ u.searchParams.sort();
11
+ return u.toString();
12
+ }
13
+ catch {
14
+ return url;
15
+ }
16
+ }
17
+ /** Keep a local document's chunk fragment, while normalizing all other URLs. */
18
+ export function resultUrlKey(result) {
19
+ const normalized = normalizeUrl(result.url);
20
+ if (result.source !== 'local' && !result.url.startsWith('file:'))
21
+ return normalized;
22
+ try {
23
+ return `${normalized}${new URL(result.url).hash}`;
24
+ }
25
+ catch {
26
+ return result.url;
27
+ }
28
+ }
29
+ /**
30
+ * The source a result came from, for counting distinct sources.
31
+ *
32
+ * Distinct from `resultUrlKey`, which identifies the result itself. A `file:`
33
+ * URL has no host, and returning an empty string for it — as the hand-rolled
34
+ * copies of this logic variously did — made a pure local session report zero
35
+ * sources. A local document's source is its path.
36
+ */
37
+ export function sourceKey(url) {
38
+ try {
39
+ const parsed = new URL(url);
40
+ if (parsed.protocol === 'file:')
41
+ return parsed.pathname || undefined;
42
+ return parsed.hostname.replace(/^www\./, '').toLowerCase() || undefined;
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
48
+ export function dedupeByUrl(items) {
49
+ const seen = new Map();
50
+ for (const item of items) {
51
+ const norm = resultUrlKey(item);
52
+ if (!seen.has(norm)) {
53
+ seen.set(norm, item);
54
+ }
55
+ }
56
+ return Array.from(seen.values());
57
+ }
58
+ const NGRAM_SIZE = 5;
59
+ const SHORT_TEXT_LENGTH = 300;
60
+ function normalizeText(text) {
61
+ return text.toLowerCase().replace(/\s+/g, ' ').trim();
62
+ }
63
+ function characterNgrams(text) {
64
+ const ngrams = new Set();
65
+ for (let index = 0; index <= text.length - NGRAM_SIZE; index++) {
66
+ ngrams.add(text.slice(index, index + NGRAM_SIZE));
67
+ }
68
+ return ngrams;
69
+ }
70
+ export function jaccardSimilarity(left, right) {
71
+ const normalizedLeft = normalizeText(left);
72
+ const normalizedRight = normalizeText(right);
73
+ if (normalizedLeft === normalizedRight)
74
+ return 1;
75
+ if (normalizedLeft.length < NGRAM_SIZE || normalizedRight.length < NGRAM_SIZE)
76
+ return 0;
77
+ const leftNgrams = characterNgrams(normalizedLeft);
78
+ const rightNgrams = characterNgrams(normalizedRight);
79
+ let intersection = 0;
80
+ for (const ngram of leftNgrams) {
81
+ if (rightNgrams.has(ngram))
82
+ intersection++;
83
+ }
84
+ return intersection / (leftNgrams.size + rightNgrams.size - intersection);
85
+ }
86
+ function jaccardThreshold(left, right, threshold) {
87
+ return Math.min(left.length, right.length) < SHORT_TEXT_LENGTH
88
+ ? Math.max(threshold, 0.97)
89
+ : threshold;
90
+ }
91
+ export function dedupeByJaccard(items, threshold = 0.92) {
92
+ const kept = [];
93
+ const contents = [];
94
+ // ponytail: O(n^2) comparison is acceptable for bounded result batches; add candidate indexing if batches grow.
95
+ for (const item of items) {
96
+ const content = item.content;
97
+ let isDuplicate = false;
98
+ for (const existing of contents) {
99
+ if (jaccardSimilarity(content, existing) >= jaccardThreshold(content, existing, threshold)) {
100
+ isDuplicate = true;
101
+ break;
102
+ }
103
+ }
104
+ if (!isDuplicate) {
105
+ kept.push(item);
106
+ contents.push(content);
107
+ }
108
+ }
109
+ return kept;
110
+ }
111
+ export function dedupe(items, threshold = 0.92) {
112
+ const urlDeduped = dedupeByUrl(items);
113
+ return dedupeByJaccard(urlDeduped, threshold);
114
+ }
115
+ //# sourceMappingURL=dedupe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dedupe.js","sourceRoot":"","sources":["../../src/deep/dedupe.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,SAAS,YAAY,CAAC,GAAW;IAC7B,IAAI,CAAC;QACD,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,sDAAsD;QACtD,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;QAClD,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QACtB,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC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C,CAAC;IACtC,OAAO,eAAe,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * On-demand degree computation for entity nodes.
3
+ *
4
+ * Degree is NOT stored in node attributes — it's computed on-the-fly
5
+ * from the graph topology using graphology's O(1) inDegree/outDegree.
6
+ * This ensures degree is always consistent with the current graph state.
7
+ */
8
+ import { DirectedGraph } from 'graphology';
9
+ import { GraphNodeAttrs, GraphEdgeAttrs } from './graph.js';
10
+ /** Get the total degree (in + out) for a single node. O(1) via graphology. */
11
+ export declare function getEntityDegree(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, nodeId: string): number;
12
+ /** Get degree for all entity nodes (type === 'entity') in the graph. */
13
+ export declare function getEntitiesWithDegrees(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>): Array<{
14
+ id: string;
15
+ degree: number;
16
+ label: string;
17
+ }>;
18
+ /** Compute adaptive degree range for filtering entity nodes.
19
+ * - d_max = min(50, floor(graph.order / 5))
20
+ * - d_min = 1 by default
21
+ * Small graphs auto-shrink: 30 nodes → d_max=6, 100 nodes → d_max=20
22
+ */
23
+ export declare function adaptiveDegreeRange(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, opts?: {
24
+ minDegree?: number;
25
+ maxDegreeCap?: number;
26
+ }): {
27
+ min: number;
28
+ max: number;
29
+ };
30
+ /** Filter entity nodes within the adaptive degree range. */
31
+ export declare function filterEntitiesByDegree(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, opts?: {
32
+ minDegree?: number;
33
+ maxDegreeCap?: number;
34
+ }): Array<{
35
+ id: string;
36
+ degree: number;
37
+ label: string;
38
+ }>;
39
+ //# sourceMappingURL=degree-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"degree-utils.d.ts","sourceRoot":"","sources":["../../src/deep/degree-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5D,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE5G;AAED,wEAAwE;AACxE,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,GACrD,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAYtD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EACpD,IAAI,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAK9B;AAED,4DAA4D;AAC5D,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EACpD,IAAI,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAGtD"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * On-demand degree computation for entity nodes.
3
+ *
4
+ * Degree is NOT stored in node attributes — it's computed on-the-fly
5
+ * from the graph topology using graphology's O(1) inDegree/outDegree.
6
+ * This ensures degree is always consistent with the current graph state.
7
+ */
8
+ /** Get the total degree (in + out) for a single node. O(1) via graphology. */
9
+ export function getEntityDegree(graph, nodeId) {
10
+ return graph.inDegree(nodeId) + graph.outDegree(nodeId);
11
+ }
12
+ /** Get degree for all entity nodes (type === 'entity') in the graph. */
13
+ export function getEntitiesWithDegrees(graph) {
14
+ const result = [];
15
+ graph.forEachNode((node, attrs) => {
16
+ if (attrs.type === 'entity') {
17
+ result.push({
18
+ id: node,
19
+ degree: getEntityDegree(graph, node),
20
+ label: attrs.label,
21
+ });
22
+ }
23
+ });
24
+ return result.sort((a, b) => b.degree - a.degree);
25
+ }
26
+ /** Compute adaptive degree range for filtering entity nodes.
27
+ * - d_max = min(50, floor(graph.order / 5))
28
+ * - d_min = 1 by default
29
+ * Small graphs auto-shrink: 30 nodes → d_max=6, 100 nodes → d_max=20
30
+ */
31
+ export function adaptiveDegreeRange(graph, opts) {
32
+ const dMin = opts?.minDegree ?? 1;
33
+ const cap = opts?.maxDegreeCap ?? 50;
34
+ const dMax = Math.min(cap, Math.floor(graph.order / 5));
35
+ return { min: dMin, max: Math.max(dMax, dMin) };
36
+ }
37
+ /** Filter entity nodes within the adaptive degree range. */
38
+ export function filterEntitiesByDegree(graph, opts) {
39
+ const range = adaptiveDegreeRange(graph, opts);
40
+ return getEntitiesWithDegrees(graph).filter(e => e.degree >= range.min && e.degree <= range.max);
41
+ }
42
+ //# sourceMappingURL=degree-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"degree-utils.js","sourceRoot":"","sources":["../../src/deep/degree-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,8EAA8E;AAC9E,MAAM,UAAU,eAAe,CAAC,KAAoD,EAAE,MAAc;IAChG,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAC5D,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,sBAAsB,CAClC,KAAoD;IAEpD,MAAM,MAAM,GAAyD,EAAE,CA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AAC;AACrG,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Content extraction: Defuddle (linkedom) → optional Obscura fallback, or explicit Jina Reader
3
+ */
4
+ export interface ExtractorOptions {
5
+ timeoutMs?: number;
6
+ concurrency?: number;
7
+ maxResponseBytes?: number;
8
+ obscura?: boolean;
9
+ obscuraPath?: string;
10
+ obscuraDumpFormat?: 'html' | 'markdown';
11
+ jina?: boolean;
12
+ }
13
+ export interface ExtractedContent {
14
+ title: string;
15
+ content: string;
16
+ excerpt: string;
17
+ url: string;
18
+ byline?: string;
19
+ siteName?: string;
20
+ length: number;
21
+ extractedAt: number;
22
+ error?: string;
23
+ retryAfterMs?: number;
24
+ retryAt?: number;
25
+ method?: 'defuddle' | 'obscura' | 'jina';
26
+ }
27
+ export declare function obscuraDownloadUrl(tarball: string): string;
28
+ export declare class ContentExtractor {
29
+ private timeoutMs;
30
+ private concurrency;
31
+ private maxResponseBytes;
32
+ private useObscura;
33
+ private obscuraPath?;
34
+ private obscuraDumpFormat;
35
+ private useJina;
36
+ constructor(options?: ExtractorOptions);
37
+ extract(url: string): Promise<ExtractedContent>;
38
+ private fetchHtml;
39
+ extractFromHtml(html: string, url: string): Promise<ExtractedContent>;
40
+ extractBatch(urls: string[]): Promise<ExtractedContent[]>;
41
+ }
42
+ //# sourceMappingURL=extractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../src/deep/extractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAkCH,MAAM,WAAW,gBAAgB;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IACxC,IAAI,CAAC,EAAE,OAA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