digdig 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -14
- package/digdig.config.example.json +0 -0
- package/dist/claims/deterministic-checks.d.ts +0 -0
- package/dist/claims/deterministic-checks.d.ts.map +0 -0
- package/dist/claims/deterministic-checks.js +0 -0
- package/dist/claims/deterministic-checks.js.map +0 -0
- package/dist/claims/policy.d.ts +0 -0
- package/dist/claims/policy.d.ts.map +0 -0
- package/dist/claims/policy.js +0 -0
- package/dist/claims/policy.js.map +0 -0
- package/dist/claims/store.d.ts +0 -0
- package/dist/claims/store.d.ts.map +0 -0
- package/dist/claims/store.js +0 -0
- package/dist/claims/store.js.map +0 -0
- package/dist/claims/types.d.ts +0 -0
- package/dist/claims/types.d.ts.map +0 -0
- package/dist/claims/types.js +0 -0
- package/dist/claims/types.js.map +0 -0
- package/dist/commands/claim.d.ts +0 -0
- package/dist/commands/claim.d.ts.map +0 -0
- package/dist/commands/claim.js +0 -0
- package/dist/commands/claim.js.map +0 -0
- package/dist/commands/coverage.d.ts +7 -0
- package/dist/commands/coverage.d.ts.map +1 -0
- package/dist/commands/coverage.js +78 -0
- package/dist/commands/coverage.js.map +1 -0
- package/dist/commands/doc-index.d.ts +0 -0
- package/dist/commands/doc-index.d.ts.map +0 -0
- package/dist/commands/doc-index.js +0 -0
- package/dist/commands/doc-index.js.map +0 -0
- package/dist/commands/doc-search.d.ts +0 -0
- package/dist/commands/doc-search.d.ts.map +0 -0
- package/dist/commands/doc-search.js +0 -0
- package/dist/commands/doc-search.js.map +0 -0
- package/dist/commands/evidence.d.ts +0 -0
- package/dist/commands/evidence.d.ts.map +0 -0
- package/dist/commands/evidence.js +0 -0
- package/dist/commands/evidence.js.map +0 -0
- package/dist/commands/extract.d.ts +0 -0
- package/dist/commands/extract.d.ts.map +0 -0
- package/dist/commands/extract.js +5 -5
- package/dist/commands/extract.js.map +1 -1
- package/dist/commands/graph-add.d.ts +0 -0
- package/dist/commands/graph-add.d.ts.map +0 -0
- package/dist/commands/graph-add.js +0 -0
- package/dist/commands/graph-add.js.map +1 -1
- package/dist/commands/graph-drill.d.ts +0 -0
- package/dist/commands/graph-drill.d.ts.map +0 -0
- package/dist/commands/graph-drill.js +0 -0
- package/dist/commands/graph-drill.js.map +0 -0
- package/dist/commands/graph-explore.d.ts +0 -0
- package/dist/commands/graph-explore.d.ts.map +0 -0
- package/dist/commands/graph-explore.js +0 -0
- package/dist/commands/graph-explore.js.map +0 -0
- package/dist/commands/graph-obfuscate.d.ts +0 -0
- package/dist/commands/graph-obfuscate.d.ts.map +0 -0
- package/dist/commands/graph-obfuscate.js +0 -0
- package/dist/commands/graph-obfuscate.js.map +0 -0
- package/dist/commands/graph-search.d.ts +0 -0
- package/dist/commands/graph-search.d.ts.map +0 -0
- package/dist/commands/graph-search.js +0 -0
- package/dist/commands/graph-search.js.map +0 -0
- package/dist/commands/graph-traverse.d.ts +0 -0
- package/dist/commands/graph-traverse.d.ts.map +0 -0
- package/dist/commands/graph-traverse.js +0 -0
- package/dist/commands/graph-traverse.js.map +0 -0
- package/dist/commands/json-input.d.ts +0 -0
- package/dist/commands/json-input.d.ts.map +0 -0
- package/dist/commands/json-input.js +0 -0
- package/dist/commands/json-input.js.map +0 -0
- package/dist/commands/query-graph.d.ts +0 -0
- package/dist/commands/query-graph.d.ts.map +0 -0
- package/dist/commands/query-graph.js +0 -0
- package/dist/commands/query-graph.js.map +0 -0
- package/dist/commands/results-add.d.ts +0 -0
- package/dist/commands/results-add.d.ts.map +0 -0
- package/dist/commands/results-add.js +0 -0
- package/dist/commands/results-add.js.map +0 -0
- package/dist/commands/review.d.ts +0 -0
- package/dist/commands/review.d.ts.map +0 -0
- package/dist/commands/review.js +0 -0
- package/dist/commands/review.js.map +0 -0
- package/dist/commands/session.d.ts +0 -0
- package/dist/commands/session.d.ts.map +0 -0
- package/dist/commands/session.js +0 -0
- package/dist/commands/session.js.map +0 -0
- package/dist/commands/verdict.d.ts +0 -0
- package/dist/commands/verdict.d.ts.map +0 -0
- package/dist/commands/verdict.js +0 -0
- package/dist/commands/verdict.js.map +0 -0
- package/dist/config.d.ts +0 -0
- package/dist/config.d.ts.map +0 -0
- package/dist/config.js +0 -0
- package/dist/config.js.map +0 -0
- package/dist/deep/co-occurrence.d.ts +0 -0
- package/dist/deep/co-occurrence.d.ts.map +0 -0
- package/dist/deep/co-occurrence.js +0 -0
- package/dist/deep/co-occurrence.js.map +0 -0
- package/dist/deep/coverage.d.ts +81 -0
- package/dist/deep/coverage.d.ts.map +1 -0
- package/dist/deep/coverage.js +183 -0
- package/dist/deep/coverage.js.map +1 -0
- package/dist/deep/dedupe.d.ts +9 -1
- package/dist/deep/dedupe.d.ts.map +1 -1
- package/dist/deep/dedupe.js +21 -2
- package/dist/deep/dedupe.js.map +1 -1
- package/dist/deep/degree-utils.d.ts +0 -0
- package/dist/deep/degree-utils.d.ts.map +0 -0
- package/dist/deep/degree-utils.js +0 -0
- package/dist/deep/degree-utils.js.map +0 -0
- package/dist/deep/extractor.d.ts +0 -0
- package/dist/deep/extractor.d.ts.map +0 -0
- package/dist/deep/extractor.js +0 -0
- package/dist/deep/extractor.js.map +0 -0
- package/dist/deep/fuse.d.ts +63 -0
- package/dist/deep/fuse.d.ts.map +1 -0
- package/dist/deep/fuse.js +122 -0
- package/dist/deep/fuse.js.map +1 -0
- package/dist/deep/graph-explore.d.ts +0 -0
- package/dist/deep/graph-explore.d.ts.map +0 -0
- package/dist/deep/graph-explore.js +0 -0
- package/dist/deep/graph-explore.js.map +0 -0
- package/dist/deep/graph-obfuscate.d.ts +0 -0
- package/dist/deep/graph-obfuscate.d.ts.map +0 -0
- package/dist/deep/graph-obfuscate.js +0 -0
- package/dist/deep/graph-obfuscate.js.map +0 -0
- package/dist/deep/graph-preprocess.d.ts +0 -0
- package/dist/deep/graph-preprocess.d.ts.map +0 -0
- package/dist/deep/graph-preprocess.js +0 -0
- package/dist/deep/graph-preprocess.js.map +0 -0
- package/dist/deep/graph-sampling.d.ts +0 -0
- package/dist/deep/graph-sampling.d.ts.map +0 -0
- package/dist/deep/graph-sampling.js +0 -0
- package/dist/deep/graph-sampling.js.map +0 -0
- package/dist/deep/graph.d.ts +0 -0
- package/dist/deep/graph.d.ts.map +0 -0
- package/dist/deep/graph.js +0 -0
- package/dist/deep/graph.js.map +0 -0
- package/dist/deep/index.d.ts +1 -1
- package/dist/deep/index.d.ts.map +0 -0
- package/dist/deep/index.js +1 -1
- package/dist/deep/index.js.map +0 -0
- package/dist/deep/iteration-data.d.ts +9 -13
- package/dist/deep/iteration-data.d.ts.map +1 -1
- package/dist/deep/iteration-data.js +12 -16
- package/dist/deep/iteration-data.js.map +1 -1
- package/dist/deep/local-doc/indexer.d.ts +0 -4
- package/dist/deep/local-doc/indexer.d.ts.map +1 -1
- package/dist/deep/local-doc/indexer.js +21 -3
- package/dist/deep/local-doc/indexer.js.map +1 -1
- package/dist/deep/local-doc/scanner.d.ts +0 -0
- package/dist/deep/local-doc/scanner.d.ts.map +0 -0
- package/dist/deep/local-doc/scanner.js +0 -0
- package/dist/deep/local-doc/scanner.js.map +0 -0
- package/dist/deep/local-doc/searcher.d.ts +0 -0
- package/dist/deep/local-doc/searcher.d.ts.map +1 -1
- package/dist/deep/local-doc/searcher.js +3 -4
- package/dist/deep/local-doc/searcher.js.map +1 -1
- package/dist/deep/local-doc/types.d.ts +0 -0
- package/dist/deep/local-doc/types.d.ts.map +0 -0
- package/dist/deep/local-doc/types.js +0 -0
- package/dist/deep/local-doc/types.js.map +0 -0
- package/dist/deep/path-extraction.d.ts +0 -0
- package/dist/deep/path-extraction.d.ts.map +0 -0
- package/dist/deep/path-extraction.js +0 -0
- package/dist/deep/path-extraction.js.map +0 -0
- package/dist/deep/pending-facts.d.ts +64 -0
- package/dist/deep/pending-facts.d.ts.map +1 -0
- package/dist/deep/pending-facts.js +74 -0
- package/dist/deep/pending-facts.js.map +1 -0
- package/dist/deep/query-redundancy.d.ts +0 -0
- package/dist/deep/query-redundancy.d.ts.map +0 -0
- package/dist/deep/query-redundancy.js +0 -0
- package/dist/deep/query-redundancy.js.map +0 -0
- package/dist/deep/query-suggest.d.ts +1 -3
- package/dist/deep/query-suggest.d.ts.map +1 -1
- package/dist/deep/query-suggest.js +3 -11
- package/dist/deep/query-suggest.js.map +1 -1
- package/dist/deep/rrf.d.ts +0 -0
- package/dist/deep/rrf.d.ts.map +0 -0
- package/dist/deep/rrf.js +0 -0
- package/dist/deep/rrf.js.map +0 -0
- package/dist/deep/search-strategy.d.ts +0 -0
- package/dist/deep/search-strategy.d.ts.map +0 -0
- package/dist/deep/search-strategy.js +0 -0
- package/dist/deep/search-strategy.js.map +0 -0
- package/dist/deep/session.d.ts +5 -3
- package/dist/deep/session.d.ts.map +1 -1
- package/dist/deep/session.js +29 -9
- package/dist/deep/session.js.map +1 -1
- package/dist/deep/simhash.d.ts +0 -0
- package/dist/deep/simhash.d.ts.map +0 -0
- package/dist/deep/simhash.js +0 -0
- package/dist/deep/simhash.js.map +0 -0
- package/dist/deep/tfidf.d.ts +0 -0
- package/dist/deep/tfidf.d.ts.map +0 -0
- package/dist/deep/tfidf.js +0 -0
- package/dist/deep/tfidf.js.map +0 -0
- package/dist/deepseek-service.d.ts +0 -0
- package/dist/deepseek-service.d.ts.map +1 -1
- package/dist/deepseek-service.js +7 -3
- package/dist/deepseek-service.js.map +1 -1
- package/dist/entry.d.ts +5 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +7 -2
- package/dist/entry.js.map +1 -1
- package/dist/errors.d.ts +76 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +117 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.d.ts.map +0 -0
- package/dist/index.js.map +0 -0
- package/dist/init.d.ts +0 -0
- package/dist/init.d.ts.map +0 -0
- package/dist/init.js +0 -0
- package/dist/init.js.map +0 -0
- package/dist/legacy.d.ts +0 -0
- package/dist/legacy.d.ts.map +0 -0
- package/dist/legacy.js +0 -0
- package/dist/legacy.js.map +0 -0
- package/dist/ollama-service.d.ts +0 -0
- package/dist/ollama-service.d.ts.map +1 -1
- package/dist/ollama-service.js +27 -6
- package/dist/ollama-service.js.map +1 -1
- package/dist/protocol.d.ts +0 -0
- package/dist/protocol.d.ts.map +0 -0
- package/dist/protocol.js +0 -0
- package/dist/protocol.js.map +0 -0
- package/dist/runCli.d.ts +1 -1
- package/dist/runCli.d.ts.map +1 -1
- package/dist/runCli.js +274 -434
- package/dist/runCli.js.map +1 -1
- package/dist/service.d.ts +39 -1
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +76 -22
- package/dist/service.js.map +1 -1
- package/dist/sxng.d.ts +0 -0
- package/dist/sxng.d.ts.map +0 -0
- package/dist/sxng.js.map +0 -0
- package/package.json +2 -2
- package/dist/commands/build-graph.d.ts +0 -8
- package/dist/commands/build-graph.d.ts.map +0 -1
- package/dist/commands/build-graph.js +0 -70
- package/dist/commands/build-graph.js.map +0 -1
- package/dist/commands/graph-add.d.ts.sync-conflict-20260629-232900-2SGIW5T.map +0 -1
- package/dist/commands/graph-add.js.sync-conflict-20260629-232916-2SGIW5T.map +0 -1
- package/dist/commands/graph-add.sync-conflict-20260629-232853-2SGIW5T.js +0 -163
- package/dist/commands/raw.d.ts +0 -14
- package/dist/commands/raw.d.ts.map +0 -1
- package/dist/commands/raw.js +0 -125
- package/dist/commands/raw.js.map +0 -1
- package/dist/deep/extractor.d.sync-conflict-20260629-232902-2SGIW5T.ts +0 -37
- package/dist/deep/extractor.d.ts.sync-conflict-20260629-232921-2SGIW5T.map +0 -1
- package/dist/deep/extractor.js.sync-conflict-20260629-232921-2SGIW5T.map +0 -1
- package/dist/deep/extractor.sync-conflict-20260629-232903-2SGIW5T.js +0 -203
- package/dist/deep/graph.d.sync-conflict-20260629-232917-2SGIW5T.ts +0 -78
- package/dist/deep/graph.d.ts.sync-conflict-20260629-232911-2SGIW5T.map +0 -1
- package/dist/deep/graph.js.sync-conflict-20260629-232855-2SGIW5T.map +0 -1
- package/dist/deep/graph.sync-conflict-20260629-232907-2SGIW5T.js +0 -194
- package/dist/deep/keywords.d.ts +0 -27
- package/dist/deep/keywords.d.ts.map +0 -1
- package/dist/deep/keywords.js +0 -293
- package/dist/deep/keywords.js.map +0 -1
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.d.ts +0 -38
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.d.ts.map +0 -1
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.js +0 -212
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.js.map +0 -1
- package/dist/deep/quality-assess.d.ts +0 -46
- package/dist/deep/quality-assess.d.ts.map +0 -1
- package/dist/deep/quality-assess.js +0 -122
- package/dist/deep/quality-assess.js.map +0 -1
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.d.ts +0 -46
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.d.ts.map +0 -1
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.js +0 -122
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.js.map +0 -1
- package/dist/deep/recovery-analysis.d.ts +0 -60
- package/dist/deep/recovery-analysis.d.ts.map +0 -1
- package/dist/deep/recovery-analysis.js +0 -185
- package/dist/deep/recovery-analysis.js.map +0 -1
- package/dist/deep/session.d.sync-conflict-20260629-232917-2SGIW5T.ts +0 -71
- package/dist/deep/session.d.ts.sync-conflict-20260629-232921-2SGIW5T.map +0 -1
- package/dist/deep/session.js.sync-conflict-20260629-232854-2SGIW5T.map +0 -1
- package/dist/runCli.d.ts.sync-conflict-20260629-232854-2SGIW5T.map +0 -1
- package/dist/runCli.js.sync-conflict-20260629-232857-2SGIW5T.map +0 -1
- package/dist/runCli.sync-conflict-20260629-232915-2SGIW5T.js +0 -1109
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.d.ts +0 -8
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.d.ts.map +0 -1
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.js +0 -1111
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.js.map +0 -1
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Content extraction: Defuddle (linkedom) → Obscura fallback
|
|
3
|
-
*/
|
|
4
|
-
import { parseHTML } from 'linkedom';
|
|
5
|
-
import { Defuddle } from 'defuddle/node';
|
|
6
|
-
import { execFile } from 'child_process';
|
|
7
|
-
import { promisify } from 'util';
|
|
8
|
-
import { homedir } from 'os';
|
|
9
|
-
import { join } from 'path';
|
|
10
|
-
const execFileAsync = promisify(execFile);
|
|
11
|
-
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
12
|
-
const DEFAULT_CONCURRENCY = 3;
|
|
13
|
-
const MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
|
|
14
|
-
const MIN_CONTENT_LENGTH = 100;
|
|
15
|
-
const OBSCURA_THRESHOLD = 50;
|
|
16
|
-
const OBSCURA_SEARCH_PATHS = [
|
|
17
|
-
'obscura',
|
|
18
|
-
join(homedir(), '.local/bin/obscura'),
|
|
19
|
-
'/usr/local/bin/obscura',
|
|
20
|
-
];
|
|
21
|
-
let _obscuraAvailable = null;
|
|
22
|
-
async function findObscura(path) {
|
|
23
|
-
const candidates = path ? [path] : OBSCURA_SEARCH_PATHS;
|
|
24
|
-
for (const candidate of candidates) {
|
|
25
|
-
try {
|
|
26
|
-
await execFileAsync(candidate, ['--version'], { timeout: 5_000 });
|
|
27
|
-
return candidate;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
async function isObscuraAvailable(path) {
|
|
36
|
-
if (_obscuraAvailable !== null && !path)
|
|
37
|
-
return _obscuraAvailable;
|
|
38
|
-
const found = await findObscura(path);
|
|
39
|
-
const available = found !== null;
|
|
40
|
-
if (!path)
|
|
41
|
-
_obscuraAvailable = available;
|
|
42
|
-
return available;
|
|
43
|
-
}
|
|
44
|
-
async function defuddleExtract(html, url) {
|
|
45
|
-
try {
|
|
46
|
-
const { document } = parseHTML(html);
|
|
47
|
-
const result = await Defuddle(document, url, {
|
|
48
|
-
markdown: true,
|
|
49
|
-
useAsync: false,
|
|
50
|
-
});
|
|
51
|
-
const content = (result.content || '').trim();
|
|
52
|
-
if (!content) {
|
|
53
|
-
return {
|
|
54
|
-
title: result.title || '',
|
|
55
|
-
content: '',
|
|
56
|
-
excerpt: result.description || '',
|
|
57
|
-
url,
|
|
58
|
-
byline: result.author || undefined,
|
|
59
|
-
siteName: result.site || undefined,
|
|
60
|
-
length: 0,
|
|
61
|
-
extractedAt: Date.now(),
|
|
62
|
-
method: 'defuddle',
|
|
63
|
-
error: 'Defuddle could not extract content',
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
title: result.title || '',
|
|
68
|
-
content,
|
|
69
|
-
excerpt: result.description || '',
|
|
70
|
-
url,
|
|
71
|
-
byline: result.author || undefined,
|
|
72
|
-
siteName: result.site || undefined,
|
|
73
|
-
length: result.wordCount || content.length,
|
|
74
|
-
extractedAt: Date.now(),
|
|
75
|
-
method: 'defuddle',
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
return {
|
|
80
|
-
title: '',
|
|
81
|
-
content: '',
|
|
82
|
-
excerpt: '',
|
|
83
|
-
url,
|
|
84
|
-
length: 0,
|
|
85
|
-
extractedAt: Date.now(),
|
|
86
|
-
method: 'defuddle',
|
|
87
|
-
error: error instanceof Error ? error.message : 'Defuddle parsing failed',
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async function obscuraExtract(url, options) {
|
|
92
|
-
const obscuraBin = await findObscura(options.obscuraPath);
|
|
93
|
-
if (!obscuraBin)
|
|
94
|
-
return null;
|
|
95
|
-
try {
|
|
96
|
-
const dumpFormat = options.dumpFormat ?? 'html';
|
|
97
|
-
const timeoutSec = Math.ceil(options.timeoutMs / 1000);
|
|
98
|
-
const { stdout } = await execFileAsync(obscuraBin, ['fetch', url, '--dump', dumpFormat, '--timeout', String(timeoutSec)], { timeout: options.timeoutMs + 5_000, maxBuffer: 10 * 1024 * 1024 });
|
|
99
|
-
if (!stdout || !stdout.trim())
|
|
100
|
-
return null;
|
|
101
|
-
if (dumpFormat === 'markdown') {
|
|
102
|
-
return {
|
|
103
|
-
title: '',
|
|
104
|
-
content: stdout.trim(),
|
|
105
|
-
excerpt: '',
|
|
106
|
-
url,
|
|
107
|
-
length: stdout.trim().length,
|
|
108
|
-
extractedAt: Date.now(),
|
|
109
|
-
method: 'obscura',
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
const html = stdout.trim();
|
|
113
|
-
const result = await defuddleExtract(html, url);
|
|
114
|
-
result.method = 'obscura';
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
export class ContentExtractor {
|
|
122
|
-
timeoutMs;
|
|
123
|
-
concurrency;
|
|
124
|
-
maxResponseBytes;
|
|
125
|
-
useObscura;
|
|
126
|
-
obscuraPath;
|
|
127
|
-
obscuraDumpFormat;
|
|
128
|
-
constructor(options) {
|
|
129
|
-
this.timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
130
|
-
this.concurrency = options?.concurrency ?? DEFAULT_CONCURRENCY;
|
|
131
|
-
this.maxResponseBytes = options?.maxResponseBytes ?? MAX_RESPONSE_BYTES;
|
|
132
|
-
this.useObscura = options?.obscura ?? false;
|
|
133
|
-
this.obscuraPath = options?.obscuraPath;
|
|
134
|
-
this.obscuraDumpFormat = options?.obscuraDumpFormat ?? 'html';
|
|
135
|
-
}
|
|
136
|
-
async extract(url) {
|
|
137
|
-
try {
|
|
138
|
-
const html = await this.fetchHtml(url);
|
|
139
|
-
const result = await defuddleExtract(html, url);
|
|
140
|
-
if (result.content.length >= MIN_CONTENT_LENGTH)
|
|
141
|
-
return result;
|
|
142
|
-
// Defuddle insufficient → Obscura fallback
|
|
143
|
-
if (this.useObscura && result.content.length < OBSCURA_THRESHOLD) {
|
|
144
|
-
const obsResult = await obscuraExtract(url, {
|
|
145
|
-
timeoutMs: this.timeoutMs,
|
|
146
|
-
obscuraPath: this.obscuraPath,
|
|
147
|
-
dumpFormat: this.obscuraDumpFormat,
|
|
148
|
-
});
|
|
149
|
-
if (obsResult && obsResult.content.length > result.content.length)
|
|
150
|
-
return obsResult;
|
|
151
|
-
}
|
|
152
|
-
if (result.content.length < MIN_CONTENT_LENGTH && !result.error) {
|
|
153
|
-
result.error = 'Extracted content too short';
|
|
154
|
-
}
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
catch (error) {
|
|
158
|
-
return {
|
|
159
|
-
title: '',
|
|
160
|
-
content: '',
|
|
161
|
-
excerpt: '',
|
|
162
|
-
url,
|
|
163
|
-
length: 0,
|
|
164
|
-
extractedAt: Date.now(),
|
|
165
|
-
error: error instanceof Error ? error.message : String(error),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async fetchHtml(url) {
|
|
170
|
-
const response = await fetch(url, {
|
|
171
|
-
headers: {
|
|
172
|
-
'User-Agent': 'Mozilla/5.0 (compatible; SxngDeepSearch/1.0)',
|
|
173
|
-
'Accept': 'text/html,application/xhtml+xml',
|
|
174
|
-
},
|
|
175
|
-
signal: AbortSignal.timeout(this.timeoutMs),
|
|
176
|
-
});
|
|
177
|
-
if (!response.ok) {
|
|
178
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
179
|
-
}
|
|
180
|
-
const contentLength = response.headers.get('content-length');
|
|
181
|
-
if (contentLength && parseInt(contentLength, 10) > this.maxResponseBytes) {
|
|
182
|
-
throw new Error(`Response too large: ${contentLength} bytes (max ${this.maxResponseBytes})`);
|
|
183
|
-
}
|
|
184
|
-
const html = await response.text();
|
|
185
|
-
if (html.length > this.maxResponseBytes) {
|
|
186
|
-
throw new Error(`Response too large: ${html.length} bytes (max ${this.maxResponseBytes})`);
|
|
187
|
-
}
|
|
188
|
-
return html;
|
|
189
|
-
}
|
|
190
|
-
async extractFromHtml(html, url) {
|
|
191
|
-
return defuddleExtract(html, url);
|
|
192
|
-
}
|
|
193
|
-
async extractBatch(urls) {
|
|
194
|
-
const results = [];
|
|
195
|
-
for (let i = 0; i < urls.length; i += this.concurrency) {
|
|
196
|
-
const batch = urls.slice(i, i + this.concurrency);
|
|
197
|
-
const batchResults = await Promise.all(batch.map(u => this.extract(u)));
|
|
198
|
-
results.push(...batchResults);
|
|
199
|
-
}
|
|
200
|
-
return results;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
//# sourceMappingURL=extractor.js.map
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Entity-centric knowledge graph using graphology
|
|
3
|
-
*
|
|
4
|
-
* The graph stores entities and their relationships.
|
|
5
|
-
* Search results are stored as lightweight metadata nodes (title, url, rank)
|
|
6
|
-
* connected to entities via "mentions" edges.
|
|
7
|
-
*
|
|
8
|
-
* Entity extraction is done by the Agent (LLM), not by the CLI.
|
|
9
|
-
* The CLI only stores what the Agent sends via graph-add.
|
|
10
|
-
*/
|
|
11
|
-
import { DirectedGraph } from 'graphology';
|
|
12
|
-
/** Semantic edge relation types */
|
|
13
|
-
export declare const EDGE_RELATIONS: {
|
|
14
|
-
readonly yields: "yields";
|
|
15
|
-
readonly belongs_to: "belongs_to";
|
|
16
|
-
readonly mentions: "mentions";
|
|
17
|
-
readonly alternative_to: "alternative_to";
|
|
18
|
-
readonly depends_on: "depends_on";
|
|
19
|
-
readonly co_occurs_with: "co_occurs_with";
|
|
20
|
-
readonly mentioned_in: "mentioned_in";
|
|
21
|
-
readonly includes: "includes";
|
|
22
|
-
};
|
|
23
|
-
export type PathType = 'composition_chain' | 'conjunction' | 'augmented_chain' | 'community_core_path' | 'dual_core_bridge';
|
|
24
|
-
export interface GraphNodeAttrs {
|
|
25
|
-
type: 'entity' | 'result' | 'query' | 'domain' | 'path';
|
|
26
|
-
label: string;
|
|
27
|
-
entityType?: string;
|
|
28
|
-
score?: number;
|
|
29
|
-
reasoningPaths?: string[];
|
|
30
|
-
sourceRounds?: number[];
|
|
31
|
-
frequency?: number;
|
|
32
|
-
obfuscatedLabel?: string;
|
|
33
|
-
url?: string;
|
|
34
|
-
rank?: number;
|
|
35
|
-
title?: string;
|
|
36
|
-
query?: string;
|
|
37
|
-
round?: number;
|
|
38
|
-
domain?: string;
|
|
39
|
-
pathType?: PathType;
|
|
40
|
-
hops?: number;
|
|
41
|
-
entities?: string[];
|
|
42
|
-
}
|
|
43
|
-
export interface GraphEdgeAttrs {
|
|
44
|
-
relation: string;
|
|
45
|
-
weight: number;
|
|
46
|
-
}
|
|
47
|
-
/** Create an empty entity-centric knowledge graph */
|
|
48
|
-
export declare function createGraph(): DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>;
|
|
49
|
-
/** Generate a node ID for an entity */
|
|
50
|
-
export declare function entityId(label: string): string;
|
|
51
|
-
/** Generate a node ID for a result */
|
|
52
|
-
export declare function resultId(url: string): string;
|
|
53
|
-
/** Generate a node ID for a query */
|
|
54
|
-
export declare function queryId(query: string): string;
|
|
55
|
-
/** Generate a node ID for a domain */
|
|
56
|
-
export declare function domainId(domain: string): string;
|
|
57
|
-
/** Generate the next path node ID for a given path type.
|
|
58
|
-
* Scans existing graph nodes to find the current max counter. */
|
|
59
|
-
export declare function nextPathId(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, pathType: PathType): string;
|
|
60
|
-
/** Auto-build structural edges: query→result→domain */
|
|
61
|
-
export declare function buildStructuralEdges(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, query: string, results: Array<{
|
|
62
|
-
url: string;
|
|
63
|
-
title: string;
|
|
64
|
-
rank?: number;
|
|
65
|
-
}>, round?: number): void;
|
|
66
|
-
export declare function bfsSubgraph(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, seeds: string[], depth?: number): DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>;
|
|
67
|
-
export declare function serializeGraph(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>): object;
|
|
68
|
-
export declare function deserializeGraph(data: any): DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>;
|
|
69
|
-
export declare function graphStats(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>): {
|
|
70
|
-
nodes: number;
|
|
71
|
-
edges: number;
|
|
72
|
-
entities: number;
|
|
73
|
-
results: number;
|
|
74
|
-
queries: number;
|
|
75
|
-
domains: number;
|
|
76
|
-
paths: number;
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/deep/graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,mCAAmC;AACnC,eAAO,MAAM,cAAc;;;;;;;;;CASjB,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,mBAAmB,GAAG,aAAa,GAAG,iBAAiB,GAAG,qBAAqB,GAAG,kBAAkB,CAAC;AAE5H,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IACxD,KAAK,EAAE,MAAM,CAAC;IAEd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,YA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,QAAQ;YAAE,OAAO,EAAE,CAAC;aACvC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;YAAE,KAAK,EAAE,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,OAAO;QACH,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,KAAK,EAAE,KAAK,CAAC,IAAI;QACjB,QAAQ;QACR,OAAO;QACP,OAAO;QACP,OAAO;QACP,KAAK;KACR,CAAC;AACN,CAAC"}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Entity-centric knowledge graph using graphology
|
|
3
|
-
*
|
|
4
|
-
* The graph stores entities and their relationships.
|
|
5
|
-
* Search results are stored as lightweight metadata nodes (title, url, rank)
|
|
6
|
-
* connected to entities via "mentions" edges.
|
|
7
|
-
*
|
|
8
|
-
* Entity extraction is done by the Agent (LLM), not by the CLI.
|
|
9
|
-
* The CLI only stores what the Agent sends via graph-add.
|
|
10
|
-
*/
|
|
11
|
-
import { DirectedGraph } from 'graphology';
|
|
12
|
-
/** Semantic edge relation types */
|
|
13
|
-
export const EDGE_RELATIONS = {
|
|
14
|
-
yields: 'yields', // query → result
|
|
15
|
-
belongs_to: 'belongs_to', // result → domain
|
|
16
|
-
mentions: 'mentions', // result → entity
|
|
17
|
-
alternative_to: 'alternative_to', // entity ↔ entity
|
|
18
|
-
depends_on: 'depends_on', // entity → entity
|
|
19
|
-
co_occurs_with: 'co_occurs_with', // entity ↔ entity
|
|
20
|
-
mentioned_in: 'mentioned_in', // entity → result
|
|
21
|
-
includes: 'includes', // path → entity
|
|
22
|
-
};
|
|
23
|
-
function generateId(prefix, value) {
|
|
24
|
-
return `${prefix}:${value.toLowerCase().replace(/[^\w]+/g, '_').slice(0, 60)}`;
|
|
25
|
-
}
|
|
26
|
-
/** Create an empty entity-centric knowledge graph */
|
|
27
|
-
export function createGraph() {
|
|
28
|
-
return new DirectedGraph();
|
|
29
|
-
}
|
|
30
|
-
/** Generate a node ID for an entity */
|
|
31
|
-
export function entityId(label) {
|
|
32
|
-
return generateId('e', label);
|
|
33
|
-
}
|
|
34
|
-
/** Generate a node ID for a result */
|
|
35
|
-
export function resultId(url) {
|
|
36
|
-
return generateId('r', url);
|
|
37
|
-
}
|
|
38
|
-
/** Generate a node ID for a query */
|
|
39
|
-
export function queryId(query) {
|
|
40
|
-
return generateId('q', query);
|
|
41
|
-
}
|
|
42
|
-
/** Generate a node ID for a domain */
|
|
43
|
-
export function domainId(domain) {
|
|
44
|
-
return generateId('d', domain);
|
|
45
|
-
}
|
|
46
|
-
/** Map from PathType to ID prefix */
|
|
47
|
-
const PATH_TYPE_PREFIX = {
|
|
48
|
-
composition_chain: 'chain',
|
|
49
|
-
conjunction: 'conj',
|
|
50
|
-
augmented_chain: 'aug',
|
|
51
|
-
community_core_path: 'core',
|
|
52
|
-
dual_core_bridge: 'bridge',
|
|
53
|
-
};
|
|
54
|
-
/** Generate the next path node ID for a given path type.
|
|
55
|
-
* Scans existing graph nodes to find the current max counter. */
|
|
56
|
-
export function nextPathId(graph, pathType) {
|
|
57
|
-
const prefix = PATH_TYPE_PREFIX[pathType];
|
|
58
|
-
let maxCounter = 0;
|
|
59
|
-
graph.forEachNode((node, attrs) => {
|
|
60
|
-
if (attrs.type === 'path' && attrs.pathType === pathType) {
|
|
61
|
-
// Extract counter from node ID: p:<prefix>_NNN
|
|
62
|
-
const match = node.match(new RegExp(`^p:${prefix}_(\\d+)$`));
|
|
63
|
-
if (match) {
|
|
64
|
-
const counter = parseInt(match[1], 10);
|
|
65
|
-
if (counter > maxCounter)
|
|
66
|
-
maxCounter = counter;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
const next = maxCounter + 1;
|
|
71
|
-
return `p:${prefix}_${String(next).padStart(3, '0')}`;
|
|
72
|
-
}
|
|
73
|
-
/** Extract domain from URL */
|
|
74
|
-
function extractDomain(url) {
|
|
75
|
-
try {
|
|
76
|
-
return new URL(url).hostname;
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
return url;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/** Auto-build structural edges: query→result→domain */
|
|
83
|
-
export function buildStructuralEdges(graph, query, results, round) {
|
|
84
|
-
const qId = queryId(query);
|
|
85
|
-
// Ensure query node exists
|
|
86
|
-
if (!graph.hasNode(qId)) {
|
|
87
|
-
graph.mergeNode(qId, {
|
|
88
|
-
type: 'query',
|
|
89
|
-
label: query,
|
|
90
|
-
query,
|
|
91
|
-
round,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
for (let i = 0; i < results.length; i++) {
|
|
95
|
-
const r = results[i];
|
|
96
|
-
const rId = resultId(r.url);
|
|
97
|
-
// Ensure result node exists
|
|
98
|
-
if (!graph.hasNode(rId)) {
|
|
99
|
-
graph.mergeNode(rId, {
|
|
100
|
-
type: 'result',
|
|
101
|
-
label: r.title,
|
|
102
|
-
url: r.url,
|
|
103
|
-
title: r.title,
|
|
104
|
-
rank: r.rank ?? i + 1,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
// query→result edge
|
|
108
|
-
if (!graph.hasEdge(qId, rId)) {
|
|
109
|
-
graph.addEdge(qId, rId, {
|
|
110
|
-
relation: 'yields',
|
|
111
|
-
weight: 1 / (i + 1),
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
// domain node and result→domain edge
|
|
115
|
-
const domain = extractDomain(r.url);
|
|
116
|
-
if (domain) {
|
|
117
|
-
const dId = domainId(domain);
|
|
118
|
-
if (!graph.hasNode(dId)) {
|
|
119
|
-
graph.mergeNode(dId, {
|
|
120
|
-
type: 'domain',
|
|
121
|
-
label: domain,
|
|
122
|
-
domain,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if (!graph.hasEdge(rId, dId)) {
|
|
126
|
-
graph.addEdge(rId, dId, {
|
|
127
|
-
relation: 'belongs_to',
|
|
128
|
-
weight: 1,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
export function bfsSubgraph(graph, seeds, depth = 2) {
|
|
135
|
-
const visited = new Set();
|
|
136
|
-
const queue = seeds
|
|
137
|
-
.filter(id => graph.hasNode(id))
|
|
138
|
-
.map(id => ({ id, depth: 0 }));
|
|
139
|
-
while (queue.length > 0) {
|
|
140
|
-
const { id, depth: d } = queue.shift();
|
|
141
|
-
if (d > depth || visited.has(id))
|
|
142
|
-
continue;
|
|
143
|
-
visited.add(id);
|
|
144
|
-
graph.forEachNeighbor(id, (neighbor) => {
|
|
145
|
-
if (!visited.has(neighbor)) {
|
|
146
|
-
queue.push({ id: neighbor, depth: d + 1 });
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
const subgraph = new DirectedGraph();
|
|
151
|
-
for (const nodeId of visited) {
|
|
152
|
-
const attrs = graph.getNodeAttributes(nodeId);
|
|
153
|
-
subgraph.mergeNode(nodeId, attrs);
|
|
154
|
-
}
|
|
155
|
-
graph.forEachEdge((edge, attrs, source, target) => {
|
|
156
|
-
if (visited.has(source) && visited.has(target)) {
|
|
157
|
-
subgraph.mergeEdge(source, target, attrs);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
return subgraph;
|
|
161
|
-
}
|
|
162
|
-
export function serializeGraph(graph) {
|
|
163
|
-
return graph.export();
|
|
164
|
-
}
|
|
165
|
-
export function deserializeGraph(data) {
|
|
166
|
-
const graph = new DirectedGraph();
|
|
167
|
-
graph.import(data);
|
|
168
|
-
return graph;
|
|
169
|
-
}
|
|
170
|
-
export function graphStats(graph) {
|
|
171
|
-
let entities = 0, results = 0, queries = 0, domains = 0, paths = 0;
|
|
172
|
-
graph.forEachNode((node, attrs) => {
|
|
173
|
-
if (attrs.type === 'entity')
|
|
174
|
-
entities++;
|
|
175
|
-
else if (attrs.type === 'result')
|
|
176
|
-
results++;
|
|
177
|
-
else if (attrs.type === 'query')
|
|
178
|
-
queries++;
|
|
179
|
-
else if (attrs.type === 'domain')
|
|
180
|
-
domains++;
|
|
181
|
-
else if (attrs.type === 'path')
|
|
182
|
-
paths++;
|
|
183
|
-
});
|
|
184
|
-
return {
|
|
185
|
-
nodes: graph.order,
|
|
186
|
-
edges: graph.size,
|
|
187
|
-
entities,
|
|
188
|
-
results,
|
|
189
|
-
queries,
|
|
190
|
-
domains,
|
|
191
|
-
paths,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
//# sourceMappingURL=graph.js.map
|
package/dist/deep/keywords.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Entity extraction using compromise NLP (English) + BM25 bigrams (CJK)
|
|
3
|
-
*
|
|
4
|
-
* English: compromise extracts named entities + noun phrases (POS-aware)
|
|
5
|
-
* CJK: character bigrams with BM25 scoring (compromise doesn't support CJK)
|
|
6
|
-
* Both phases use BM25 cross-document scoring for relevance ranking.
|
|
7
|
-
*/
|
|
8
|
-
export interface KeywordResult {
|
|
9
|
-
term: string;
|
|
10
|
-
score: number;
|
|
11
|
-
type: 'named' | 'proper' | 'phrase';
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Extract keywords from a collection of documents.
|
|
15
|
-
*
|
|
16
|
-
* English: compromise for POS-aware candidate extraction (named entities,
|
|
17
|
-
* proper nouns, noun phrases), filtered for validity.
|
|
18
|
-
* CJK: character bigrams with stop word filtering.
|
|
19
|
-
* Both: BM25 cross-document scoring for relevance ranking.
|
|
20
|
-
*/
|
|
21
|
-
export declare function extractKeywords(documents: string[], topN?: number): KeywordResult[][];
|
|
22
|
-
/**
|
|
23
|
-
* Extract global keywords across all documents.
|
|
24
|
-
* Aggregates scores and boosts terms appearing in multiple documents.
|
|
25
|
-
*/
|
|
26
|
-
export declare function extractGlobalKeywords(documents: string[], topN?: number): KeywordResult[];
|
|
27
|
-
//# sourceMappingURL=keywords.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../src/deep/keywords.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACvC;AAkQD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC3B,SAAS,EAAE,MAAM,EAAE,EACnB,IAAI,GAAE,MAAU,GACjB,aAAa,EAAE,EAAE,CAwBnB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACjC,SAAS,EAAE,MAAM,EAAE,EACnB,IAAI,GAAE,MAAW,GAClB,aAAa,EAAE,CAwBjB"}
|