@allansantos-dev/smart-tool 0.0.0-stage → 0.9.1
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/CHANGELOG.md +35 -0
- package/LICENSE +202 -0
- package/NOTICE +32 -0
- package/README.md +116 -2
- package/atomic_io.py +94 -0
- package/autostart.py +199 -0
- package/bin/smart-tool.mjs +86 -0
- package/browser_service_client.py +232 -0
- package/capabilities.py +63 -0
- package/client_hooks.py +192 -0
- package/code_graph.py +403 -0
- package/code_graph_java.mjs +49 -0
- package/code_graph_js.cjs +135 -0
- package/config.py +241 -0
- package/daemon_launcher.py +165 -0
- package/directory_watch.py +131 -0
- package/document_text.py +69 -0
- package/duplicates.py +313 -0
- package/embedding_cache.py +99 -0
- package/endpoint_sync.py +179 -0
- package/folder_picker.py +73 -0
- package/freshness.py +278 -0
- package/gateway.py +220 -0
- package/hook_decision.py +96 -0
- package/hooks/pretool_router.py +45 -0
- package/index_inventory.py +75 -0
- package/index_profile.py +167 -0
- package/index_scope.py +458 -0
- package/index_views.py +121 -0
- package/indexer.py +878 -0
- package/install.py +353 -0
- package/install_runtime.py +283 -0
- package/integration_metrics.py +82 -0
- package/local_embedder.py +172 -0
- package/model_adapters/__init__.py +0 -0
- package/model_adapters/openai_compatible.py +57 -0
- package/model_catalog.py +74 -0
- package/model_client.py +38 -0
- package/model_defaults.py +70 -0
- package/package.json +33 -4
- package/paths.py +6 -0
- package/project_identity.py +42 -0
- package/project_insights_ui.py +38 -0
- package/project_maps_ui.py +96 -0
- package/project_monitor.py +204 -0
- package/project_scheduler.py +61 -0
- package/project_storage.py +165 -0
- package/project_store.py +220 -0
- package/projects_ui.py +146 -0
- package/requirements.txt +8 -0
- package/research_cache.py +171 -0
- package/research_metrics.py +110 -0
- package/router.py +582 -0
- package/secret_store.py +121 -0
- package/setup_ui.py +986 -0
- package/site_memory.py +53 -0
- package/smart_tool_daemon.py +3604 -0
- package/tray.py +245 -0
- package/update_check.py +22 -0
- package/usage_meter.py +124 -0
- package/version.py +18 -0
- package/view_compare.py +68 -0
- package/web_adapters/browser/browser_service.py +302 -0
- package/web_adapters/browser/crawl4ai_search.py +236 -0
- package/web_adapters/browser/fetch_camoufox.py +28 -0
- package/web_adapters/browser/requirements.txt +2 -0
- package/web_adapters/node/adapter-common.mjs +40 -0
- package/web_adapters/node/ddg-search.mjs +89 -0
- package/web_adapters/node/open-websearch-adapter.mjs +77 -0
- package/web_adapters/node/package-lock.json +2720 -0
- package/web_adapters/node/package.json +12 -0
- package/web_adapters/node/wikipedia-search.mjs +44 -0
- package/web_document_graph.py +71 -0
- package/web_fetch.py +242 -0
- package/web_search_adapters.py +193 -0
- package/web_search_ddgs.py +42 -0
- package/web_search_external.py +288 -0
- package/web_search_health.py +88 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Uso: node ddg-search.mjs "consulta" [--num 8] [--region br-pt]
|
|
3
|
+
// Saída: JSON no stdout — [{ title, url, snippet }, ...]
|
|
4
|
+
import { parseArgs, stripTags } from './adapter-common.mjs';
|
|
5
|
+
|
|
6
|
+
function realUrlFromDdgHref(href) {
|
|
7
|
+
const match = /uddg=([^&]+)/.exec(href);
|
|
8
|
+
if (!match) return href.startsWith('//') ? `https:${href}` : href;
|
|
9
|
+
try {
|
|
10
|
+
return decodeURIComponent(match[1]);
|
|
11
|
+
} catch {
|
|
12
|
+
return match[1];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function main() {
|
|
17
|
+
const { query, num, region } = parseArgs(process.argv.slice(2),
|
|
18
|
+
'Usage: node ddg-search.mjs "query" [--num 8] [--region br-pt]', { num: 8, region: null });
|
|
19
|
+
|
|
20
|
+
const params = new URLSearchParams({ q: query });
|
|
21
|
+
if (region) params.set('kl', region);
|
|
22
|
+
const url = `https://html.duckduckgo.com/html/?${params.toString()}`;
|
|
23
|
+
|
|
24
|
+
const res = await fetch(url, {
|
|
25
|
+
headers: {
|
|
26
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0 Safari/537.36',
|
|
27
|
+
'Accept-Language': 'pt-BR,pt;q=0.9,en;q=0.8',
|
|
28
|
+
},
|
|
29
|
+
signal: AbortSignal.timeout(15000),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
throw new Error(`DuckDuckGo answered HTTP ${res.status}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const html = await res.text();
|
|
37
|
+
|
|
38
|
+
// Um resultado patrocinado usa a mesma classe `result__a` no link de título que um
|
|
39
|
+
// resultado orgânico — só o container (`<div class="result ... result--ad ...">`)
|
|
40
|
+
// distingue os dois. Por isso a extração é por bloco (do início de um `<div
|
|
41
|
+
// class="result ` até o início do próximo), não por duas regexes globais pareadas por
|
|
42
|
+
// posição: título+snippet do mesmo bloco nunca desalinha com o resultado seguinte, e um
|
|
43
|
+
// bloco com `result--ad` na própria classe é descartado antes de extrair.
|
|
44
|
+
const BLOCK_START = '<div class="result ';
|
|
45
|
+
const startPositions = [];
|
|
46
|
+
for (let i = html.indexOf(BLOCK_START); i !== -1; i = html.indexOf(BLOCK_START, i + BLOCK_START.length)) {
|
|
47
|
+
startPositions.push(i);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const titleRe = /<a[^>]*class="result__a"[^>]*href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/;
|
|
51
|
+
const snippetRe = /<a[^>]*class="result__snippet"[^>]*href="[^"]+"[^>]*>([\s\S]*?)<\/a>/;
|
|
52
|
+
|
|
53
|
+
const results = [];
|
|
54
|
+
for (let i = 0; i < startPositions.length && results.length < num; i++) {
|
|
55
|
+
const start = startPositions[i];
|
|
56
|
+
const end = i + 1 < startPositions.length ? startPositions[i + 1] : html.length;
|
|
57
|
+
const block = html.slice(start, end);
|
|
58
|
+
|
|
59
|
+
const classEnd = block.indexOf('"', BLOCK_START.length);
|
|
60
|
+
const classAttr = block.slice(BLOCK_START.length, classEnd);
|
|
61
|
+
if (classAttr.split(/\s+/).includes('result--ad')) continue;
|
|
62
|
+
|
|
63
|
+
const titleMatch = titleRe.exec(block);
|
|
64
|
+
if (!titleMatch) continue;
|
|
65
|
+
const snippetMatch = snippetRe.exec(block);
|
|
66
|
+
|
|
67
|
+
results.push({
|
|
68
|
+
title: stripTags(titleMatch[2]),
|
|
69
|
+
url: realUrlFromDdgHref(titleMatch[1]),
|
|
70
|
+
snippet: snippetMatch ? stripTags(snippetMatch[1]) : '',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (results.length === 0) {
|
|
75
|
+
throw new Error('No result extracted: DuckDuckGo may have blocked or changed the HTML. Try again or rephrase the query.');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
process.stdout.write(JSON.stringify(results, null, 2));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Nunca chamar process.exit() aqui: com stdout/stderr em pipe (caso do
|
|
82
|
+
// subprocess.run que consome este script), abortar o processo enquanto ainda
|
|
83
|
+
// há handles assíncronos pendentes (ex.: o timer do AbortSignal.timeout do
|
|
84
|
+
// fetch) pode disparar um crash nativo do libuv no Windows. Só marcar o
|
|
85
|
+
// exit code e deixar o event loop drenar sozinho.
|
|
86
|
+
main().catch((err) => {
|
|
87
|
+
console.error(String(err?.message ?? err));
|
|
88
|
+
process.exitCode = 1;
|
|
89
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Uso: node open-websearch-adapter.mjs "consulta" [--num 8] [--engine duckduckgo]
|
|
3
|
+
// Saída: JSON no stdout — [{ title, url, snippet }, ...]
|
|
4
|
+
// Wrapper fino sobre o pacote npm `open-websearch` (scraping multi-engine, sem chave de
|
|
5
|
+
// API) para expor o mesmo contrato dos demais adaptadores de web_search do Smart Tool
|
|
6
|
+
// (ver web_search_adapters.py no smart-tool) — o CLI do pacote devolve um envelope
|
|
7
|
+
// {data:{results:[...],partialFailures:[...]}} com campo `description`, não o array
|
|
8
|
+
// {title,url,snippet} que este contrato exige.
|
|
9
|
+
import { execFileSync } from 'node:child_process';
|
|
10
|
+
import { existsSync } from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
import { parseArgs } from './adapter-common.mjs';
|
|
15
|
+
|
|
16
|
+
// `npm root -g`/`npx` são `.cmd` no Windows -- `execFileSync` sem shell não invoca (EINVAL),
|
|
17
|
+
// e com shell:true o Node concatena argumentos sem escapar (DEP0190). O pacote fica
|
|
18
|
+
// instalado ao lado deste script por `install_runtime.py`; a chamada usa o arquivo JS
|
|
19
|
+
// diretamente com `process.execPath`. `OPEN_WEBSEARCH_CLI` permite diagnóstico local.
|
|
20
|
+
const LOCAL_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const OPEN_WEBSEARCH_CLI = process.env.OPEN_WEBSEARCH_CLI || path.join(
|
|
22
|
+
LOCAL_DIR, 'node_modules', 'open-websearch', 'build', 'index.js',
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
function main() {
|
|
26
|
+
const { query, num, engine } = parseArgs(process.argv.slice(2),
|
|
27
|
+
'Usage: node open-websearch-adapter.mjs "query" [--num 8] [--engine name]', { num: 8, engine: 'duckduckgo' });
|
|
28
|
+
|
|
29
|
+
if (!existsSync(OPEN_WEBSEARCH_CLI)) {
|
|
30
|
+
throw new Error(`open-websearch is not installed (${OPEN_WEBSEARCH_CLI} does not exist); run: python install_runtime.py`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// O banner de log do pacote vai pro stderr (confirmado ao vivo); stdout fica só com o
|
|
34
|
+
// JSON do `--json`, então captar só stdout aqui não mistura texto solto com o parse.
|
|
35
|
+
let raw;
|
|
36
|
+
try {
|
|
37
|
+
raw = execFileSync(
|
|
38
|
+
process.execPath,
|
|
39
|
+
[OPEN_WEBSEARCH_CLI, 'search', query, '--engine', engine, '--limit', String(num), '--json'],
|
|
40
|
+
{ encoding: 'utf-8', timeout: 25000 },
|
|
41
|
+
);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
const detail = (err.stderr || '').toString().trim();
|
|
44
|
+
throw new Error(detail || String(err.message || err));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const envelope = JSON.parse(raw);
|
|
48
|
+
if (envelope.error) {
|
|
49
|
+
throw new Error(String(envelope.error));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const results = (envelope.data?.results ?? []).slice(0, num).map((r) => ({
|
|
53
|
+
title: r.title ?? '',
|
|
54
|
+
url: r.url ?? '',
|
|
55
|
+
snippet: r.description ?? '',
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
if (results.length === 0) {
|
|
59
|
+
const failures = envelope.data?.partialFailures ?? [];
|
|
60
|
+
const reason = failures.length
|
|
61
|
+
? failures.map((f) => `${f.engine}: ${f.message}`).join('; ')
|
|
62
|
+
: 'no results';
|
|
63
|
+
throw new Error(`No result extracted (${engine}): ${reason}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
process.stdout.write(JSON.stringify(results));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Nunca process.exit() aqui: execFileSync já é síncrono (sem handle assíncrono pendente
|
|
70
|
+
// no momento do catch), mas o padrão do projeto (ver ddg-search.mjs) é sempre
|
|
71
|
+
// process.exitCode em vez de exit() com stdout/stderr em pipe.
|
|
72
|
+
try {
|
|
73
|
+
main();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error(String(err?.message ?? err));
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
}
|