argo-search 2.16.0 → 2.18.0
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/AGENTS.md +4 -2
- package/README.es.md +15 -5
- package/README.ja.md +15 -5
- package/README.ko.md +15 -5
- package/README.md +16 -6
- package/README.zh.md +16 -6
- package/SKILL.md +12 -11
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +3 -3
- package/assets/readme/hero.template.svg +121 -0
- package/assets/readme/proof-routes.svg +17 -16
- package/backends/domain_profiles.json +121 -18
- package/backends/engine_registry.yaml +23 -0
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +20 -0
- package/bin/argo +78 -12
- package/docs/CHANGELOG.md +35 -1
- package/docs/COMMIT_STANDARD.md +12 -2
- package/docs/ENGINE_CATALOG.md +36 -33
- package/docs/RELEASE_NOTES_v2.17.0.md +66 -0
- package/docs/RELEASE_NOTES_v2.18.0.md +87 -0
- package/docs/RELEASING.md +2 -2
- package/engines/specs/crossref.yaml +2 -0
- package/engines/specs/hackernews.yaml +2 -0
- package/engines/specs/helve.yaml +49 -0
- package/engines/specs/hf_papers.yaml +2 -0
- package/engines/specs/openalex.yaml +9 -2
- package/engines/specs/twitter_cli.yaml +17 -0
- package/engines/specs/twitter_syndication.yaml +2 -3
- package/package.json +3 -1
- package/packages/dsh-plugin/README.md +5 -2
- package/packages/dsh-plugin/cordis.patch.yml +4 -1
- package/packages/dsh-plugin/dsh/client.js +57 -63
- package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
- package/packages/dsh-plugin/dsh/index.js +109 -21
- package/packages/dsh-plugin/dsh/native-tools.mjs +10 -0
- package/packages/dsh-plugin/dsh/route-guard.js +95 -0
- package/packages/dsh-plugin/dsh/runner.js +49 -6
- package/packages/dsh-plugin/dsh/wide-research.js +20 -18
- package/packages/dsh-plugin/dsh/workbench-client.js +119 -20
- package/packages/dsh-plugin/dsh/workbench-io.js +182 -0
- package/packages/dsh-plugin/dsh/workbench-search.js +445 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +387 -75
- package/packages/dsh-plugin/dsh/workbench.js +277 -497
- package/packages/dsh-plugin/package.json +4 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
- package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
- package/packages/dsh-plugin/test/client.test.js +26 -0
- package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
- package/packages/dsh-plugin/test/index.test.js +150 -1
- package/packages/dsh-plugin/test/workbench-concurrency.test.js +96 -0
- package/packages/dsh-plugin/test/workbench.test.js +422 -9
- package/scripts/adaptive.py +13 -11
- package/scripts/affected_tests.py +324 -0
- package/scripts/badcase_ledger.py +93 -2
- package/scripts/browser_auth.py +178 -4
- package/scripts/cache.py +68 -69
- package/scripts/check_commit_report.py +59 -9
- package/scripts/chrome_cdp.py +71 -0
- package/scripts/circuit_breaker.py +77 -12
- package/scripts/cli_io.py +8 -3
- package/scripts/config_cache.py +4 -3
- package/scripts/daemon.py +9 -2
- package/scripts/engine_add.py +45 -0
- package/scripts/engine_dispatch.py +27 -47
- package/scripts/engine_failure.py +33 -0
- package/scripts/engine_families.py +1 -0
- package/scripts/engine_fingerprint.py +114 -0
- package/scripts/engine_health.py +130 -0
- package/scripts/engine_states.py +54 -4
- package/scripts/engines.py +2 -0
- package/scripts/engines_base.py +19 -44
- package/scripts/engines_builders_intl.py +20 -94
- package/scripts/engines_builders_search.py +19 -8
- package/scripts/engines_builders_tech.py +16 -16
- package/scripts/engines_fields.py +23 -0
- package/scripts/engines_twitter_cli.py +182 -0
- package/scripts/evidence_grounding.py +182 -0
- package/scripts/fetch_browser.py +25 -10
- package/scripts/fetch_cli_output.py +75 -0
- package/scripts/fetch_dispatch.py +248 -0
- package/scripts/fetch_quality.py +11 -0
- package/scripts/fetch_v3.py +48 -114
- package/scripts/gate_manifest_check.py +75 -0
- package/scripts/gen_readme_art.py +264 -0
- package/scripts/intent_router.py +224 -0
- package/scripts/mcp_compact.py +3 -0
- package/scripts/mcp_handlers.py +24 -4
- package/scripts/mcp_tools.py +2 -0
- package/scripts/mcp_transport.py +24 -5
- package/scripts/mcp_warm.py +15 -11
- package/scripts/numeric_verify.py +9 -0
- package/scripts/output_transparency.py +10 -0
- package/scripts/pre-commit +65 -8
- package/scripts/query_operators.py +229 -1
- package/scripts/quota.py +19 -37
- package/scripts/release.py +16 -1
- package/scripts/release_check.py +1 -2
- package/scripts/research_gates.py +85 -1
- package/scripts/research_notes.py +52 -5
- package/scripts/retry_policy.py +17 -3
- package/scripts/route_combo.py +21 -4
- package/scripts/search.py +29 -29
- package/scripts/search_cli.py +104 -8
- package/scripts/search_output.py +4 -1
- package/scripts/social_research.py +8 -6
- package/scripts/source_discovery.py +611 -0
- package/scripts/sync_backends.py +45 -0
- package/scripts/time_utils.py +28 -0
- package/scripts/twitter_single_read.py +107 -0
- package/scripts/x_keyword_route.py +138 -0
- package/scripts/x_search.py +24 -33
- package/scripts/zhihu_answer_body.py +96 -0
- package/scripts/zhihu_answer_fetch.py +66 -0
- package/scripts/zhihu_answer_lookup.py +138 -0
- package/sub-skills/ego-search/README.md +9 -0
- package/sub-skills/ego-search/scripts/ego_search.py +182 -15
- package/sub-skills/ego-search/scripts/pacing.py +291 -0
- package/sub-skills/ego-search/scripts/quality.py +262 -6
- package/sub-skills/ego-search/scripts/runtime.py +7 -1
- package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
- package/sub-skills/local-seek/SKILL.md +3 -1
- package/sub-skills/local-seek/scripts/seek.py +80 -109
- package/sub-skills/local-seek/scripts/seek_git.py +65 -0
- package/sub-skills/local-seek/scripts/seek_inspect.py +242 -0
|
@@ -192,6 +192,7 @@ window.__ModuleLoader__.load({
|
|
|
192
192
|
{ ref: "FOURGET_URL", common: false, label: "4get 极简元搜索", en: "4get", engines: ["fourget"] },
|
|
193
193
|
{ ref: "GEMINI_API_KEY", common: false, label: "语义证据·Gemini 决策", en: "Semantic Evidence · Gemini Decision", engines: [] },
|
|
194
194
|
{ ref: "GITHUB_TOKEN", common: false, label: "GitHub", en: "GitHub", engines: ["github"] },
|
|
195
|
+
{ ref: "HELVE_API_KEY", common: false, label: "Helve", en: "Helve", engines: ["helve"] },
|
|
195
196
|
{ ref: "KEENABLE_API_KEY", common: false, label: "Keenable", en: "Keenable", engines: ["keenable"] },
|
|
196
197
|
{ ref: "METASO_API_KEY", common: false, label: "秘塔", en: "Metaso", engines: ["metaso", "metaso_doc", "metaso_image", "metaso_podcast", "metaso_scholar", "metaso_video"] },
|
|
197
198
|
{ ref: "OCTEN_API_KEY", common: false, label: "Octen", en: "Octen", engines: ["octen"] },
|
|
@@ -309,21 +310,9 @@ window.__ModuleLoader__.load({
|
|
|
309
310
|
};
|
|
310
311
|
|
|
311
312
|
const PRESETS = [
|
|
312
|
-
{
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
fields: { searchTimeoutMs: 15000, fetchTimeoutMs: 15000 },
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
id: 'standard', titleKey: 'presetStandard', descKey: 'presetStandardDesc', badge: '标准生产', badgeColor: 'green', active: true,
|
|
319
|
-
env: { ARGO_TFIDF_RERANK: '1', ARGO_NUMBER_CROSSCHECK: '1', ARGO_MINHASH_DEDUPE: '1', ARGO_PAID_SEARCH: 'auto', ARGO_ADAPTIVE_GRACE: '1', ARGO_SERIAL_STAGGER_S: '0.8' },
|
|
320
|
-
fields: { searchTimeoutMs: 30000, fetchTimeoutMs: 25000 },
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
id: 'deep', titleKey: 'presetDeep', descKey: 'presetDeepDesc', badge: '深度核验', badgeColor: 'blue', active: false,
|
|
324
|
-
env: { ARGO_TFIDF_RERANK: '1', ARGO_NUMBER_CROSSCHECK: '1', ARGO_MINHASH_DEDUPE: '1', ARGO_SEMANTIC_EVIDENCE: '1', ARGO_ADAPTIVE_GRACE: '1', ARGO_PAID_SEARCH: 'auto' },
|
|
325
|
-
fields: { searchTimeoutMs: 45000, fetchTimeoutMs: 35000, nativeTimeoutMs: 60000 },
|
|
326
|
-
},
|
|
313
|
+
{ id: 'fast', titleKey: 'presetFast', descKey: 'presetFastDesc', badge: '15s 超时', badgeColor: 'blue', env: { ARGO_TFIDF_RERANK: '0', ARGO_NUMBER_CROSSCHECK: '0', ARGO_PAID_SEARCH: 'off', ARGO_ADAPTIVE_GRACE: '1', ARGO_SERIAL_STAGGER_S: '0.5' }, fields: { searchTimeoutMs: 15000, fetchTimeoutMs: 15000 } },
|
|
314
|
+
{ id: 'standard', titleKey: 'presetStandard', descKey: 'presetStandardDesc', badge: '标准生产', badgeColor: 'green', env: { ARGO_TFIDF_RERANK: '1', ARGO_NUMBER_CROSSCHECK: '1', ARGO_MINHASH_DEDUPE: '1', ARGO_PAID_SEARCH: 'auto', ARGO_ADAPTIVE_GRACE: '1', ARGO_SERIAL_STAGGER_S: '0.8' }, fields: { searchTimeoutMs: 30000, fetchTimeoutMs: 25000 } },
|
|
315
|
+
{ id: 'deep', titleKey: 'presetDeep', descKey: 'presetDeepDesc', badge: '深度核验', badgeColor: 'blue', env: { ARGO_TFIDF_RERANK: '1', ARGO_NUMBER_CROSSCHECK: '1', ARGO_MINHASH_DEDUPE: '1', ARGO_SEMANTIC_EVIDENCE: '1', ARGO_ADAPTIVE_GRACE: '1', ARGO_PAID_SEARCH: 'auto' }, fields: { searchTimeoutMs: 45000, fetchTimeoutMs: 35000, nativeTimeoutMs: 60000 } },
|
|
327
316
|
];
|
|
328
317
|
|
|
329
318
|
const col = (gap) => ({ display: 'flex', flexDirection: 'column', gap });
|
|
@@ -508,7 +497,7 @@ window.__ModuleLoader__.load({
|
|
|
508
497
|
if (typeof offRoute === 'function') offs.push(offRoute);
|
|
509
498
|
}
|
|
510
499
|
return () => { for (const off of offs) off(); };
|
|
511
|
-
}, [
|
|
500
|
+
}, [props.view, props.remote]);
|
|
512
501
|
|
|
513
502
|
const edit = (key, text) => { dirty.current.add(key); setDraft((p) => ({ ...p, [key]: text })); };
|
|
514
503
|
const report = (ok, text) => { setError(!ok); setMessage(text); };
|
|
@@ -565,11 +554,13 @@ window.__ModuleLoader__.load({
|
|
|
565
554
|
void setField('nativeTools', ordered);
|
|
566
555
|
};
|
|
567
556
|
|
|
568
|
-
const applyToolPreset = async (
|
|
557
|
+
const applyToolPreset = (tools) => runSave('nativeTools', async () => {
|
|
569
558
|
const ordered = TOOLS.map((tool) => tool.id).filter((tid) => tools.includes(tid));
|
|
570
559
|
for (const extra of tools) if (!ordered.includes(extra)) ordered.push(extra);
|
|
571
|
-
await props.set('nativeTools', ordered);
|
|
572
|
-
|
|
560
|
+
const ok = await props.set('nativeTools', ordered);
|
|
561
|
+
report(ok, ok ? t('saved') : t('refused'));
|
|
562
|
+
return ok;
|
|
563
|
+
});
|
|
573
564
|
|
|
574
565
|
const mutateKey = async (ref, action) => {
|
|
575
566
|
setKeyBusy(ref);
|
|
@@ -658,7 +649,13 @@ window.__ModuleLoader__.load({
|
|
|
658
649
|
try {
|
|
659
650
|
const ok = await writeEnvLines(updates);
|
|
660
651
|
report(ok, ok ? t('saved') : t('refused'));
|
|
661
|
-
if (ok)
|
|
652
|
+
if (ok) {
|
|
653
|
+
setEnvDraft((prev) => {
|
|
654
|
+
const next = { ...prev };
|
|
655
|
+
for (const spec of specs) delete next[spec.name];
|
|
656
|
+
return next;
|
|
657
|
+
});
|
|
658
|
+
}
|
|
662
659
|
} catch (cause) { report(false, cause && cause.message ? cause.message : String(cause)); }
|
|
663
660
|
finally { setEnvBusy(''); }
|
|
664
661
|
};
|
|
@@ -801,10 +798,16 @@ window.__ModuleLoader__.load({
|
|
|
801
798
|
: h('p', { key: 'hint', style: S.hint }, t('routeHealthFallback')),
|
|
802
799
|
]));
|
|
803
800
|
panel.push(h(Card, { key: 'presets', title: t('presetTitle'), hint: t('presetHint') }, [
|
|
804
|
-
h('div', { key: 'grid', style: S.presetGrid }, PRESETS.map((p) =>
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
801
|
+
h('div', { key: 'grid', style: S.presetGrid }, PRESETS.map((p) => {
|
|
802
|
+
const cur = liveValue();
|
|
803
|
+
const em = envMap();
|
|
804
|
+
const isMatch = Object.entries(p.fields || {}).every(([k, v]) => cur[k] === v)
|
|
805
|
+
&& Object.entries(p.env || {}).every(([k, v]) => String(em[k] ?? '') === String(v));
|
|
806
|
+
return h('div', { key: p.id, style: S.presetCard(isMatch), onClick: () => { void applyPreset(p); } }, [
|
|
807
|
+
h('div', { key: 't', style: rowBetween() }, [h('span', { key: 'title', style: S.label }, t(p.titleKey)), h('span', { key: 'badge', style: S.badge(p.badgeColor) }, p.badge)]),
|
|
808
|
+
h('span', { key: 'd', style: S.sub }, t(p.descKey)),
|
|
809
|
+
]);
|
|
810
|
+
})),
|
|
808
811
|
]));
|
|
809
812
|
panel.push(h(Card, { key: 'matrix', title: t('matrixTitle'), hint: t('matrixHint') }, [
|
|
810
813
|
h('div', { key: 'grid', style: S.matrixGrid }, CORE_ENGINES.map((engine) => {
|
|
@@ -927,47 +930,48 @@ window.__ModuleLoader__.load({
|
|
|
927
930
|
|
|
928
931
|
const inject = ['slots', 'locale', 'configForms', 'remote', 'remote.credentials'];
|
|
929
932
|
|
|
933
|
+
// 局部 ErrorBoundary:设置页渲染异常时降级为局部报错卡,绝不拖垮宿主界面。
|
|
934
|
+
const PanelBoundary = typeof react.Component === 'function'
|
|
935
|
+
? class ArgoErrorBoundary extends react.Component {
|
|
936
|
+
constructor(p) { super(p); this.state = { error: null }; }
|
|
937
|
+
static getDerivedStateFromError(error) { return { error }; }
|
|
938
|
+
render() {
|
|
939
|
+
if (this.state.error) {
|
|
940
|
+
return h('div', { style: { padding: 12, color: '#dc2626', fontSize: 12, whiteSpace: 'pre-wrap' } },
|
|
941
|
+
'[argo-dsh] 设置页渲染异常:' + String(this.state.error?.message ?? this.state.error));
|
|
942
|
+
}
|
|
943
|
+
return this.props.children;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
: null;
|
|
947
|
+
|
|
948
|
+
function SafeArgoPanel(props) {
|
|
949
|
+
return PanelBoundary ? h(PanelBoundary, null, h(ArgoPanel, props)) : h(ArgoPanel, props);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// plugins.item 仅渲染一行只读摘要,完整 7-Tab 配置收敛至唯一 settings.section 入口。
|
|
953
|
+
function PluginSummaryItem(props) {
|
|
954
|
+
return SafeArgoPanel({ ...props, view: 'summary' });
|
|
955
|
+
}
|
|
956
|
+
|
|
930
957
|
function apply(ctx) {
|
|
931
958
|
const form = ctx.configForms.get(NS);
|
|
932
959
|
const locale = ctx.locale ?? (typeof ctx.get === 'function' ? ctx.get('locale') : undefined);
|
|
933
960
|
const credentials = ctx.remote ? ctx.remote.credentials : undefined;
|
|
934
961
|
const label = () => 'Argo 搜索';
|
|
935
|
-
|
|
936
|
-
const injected = () => ({
|
|
937
|
-
hooks: { argoForm: form },
|
|
938
|
-
set: (field, next) => form.set(field, next),
|
|
939
|
-
mutate: (ops) => form.mutate(ops),
|
|
940
|
-
credentials,
|
|
941
|
-
remote: ctx.remote,
|
|
942
|
-
locale,
|
|
943
|
-
});
|
|
962
|
+
const injected = () => ({ hooks: { argoForm: form }, set: (f, n) => form.set(f, n), mutate: (ops) => form.mutate(ops), credentials, remote: ctx.remote, locale });
|
|
944
963
|
|
|
945
964
|
ctx.effect(() => ctx.configForms.whileServed([NS], () => {
|
|
946
965
|
const offs = [
|
|
947
|
-
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
948
|
-
|
|
949
|
-
id: SECTION_ID,
|
|
950
|
-
order: 26,
|
|
951
|
-
label,
|
|
952
|
-
inject: injected,
|
|
953
|
-
}, ArgoPanel)),
|
|
954
|
-
ctx.slots.inject('plugins.item', () => ctx.slots.register({
|
|
955
|
-
name: 'plugins.item',
|
|
956
|
-
id: SECTION_ID,
|
|
957
|
-
order: 50,
|
|
958
|
-
label,
|
|
959
|
-
inject: injected,
|
|
960
|
-
}, ArgoPanel)),
|
|
966
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({ name: 'settings.section', id: SECTION_ID, order: 26, label, inject: injected }, SafeArgoPanel)),
|
|
967
|
+
ctx.slots.inject('plugins.item', () => ctx.slots.register({ name: 'plugins.item', id: SECTION_ID, order: 50, label, inject: injected }, PluginSummaryItem)),
|
|
961
968
|
];
|
|
962
|
-
return () => {
|
|
963
|
-
for (const off of offs) if (typeof off === 'function') off();
|
|
964
|
-
};
|
|
969
|
+
return () => { for (const off of offs) if (typeof off === 'function') off(); };
|
|
965
970
|
}), 'argo-dsh: settings page');
|
|
966
971
|
|
|
967
972
|
if (typeof window !== 'undefined' && typeof document !== 'undefined' && ctx.slots) {
|
|
968
973
|
ctx.effect(() => {
|
|
969
|
-
let disposed = false;
|
|
970
|
-
let unmount = null;
|
|
974
|
+
let disposed = false, unmount = null;
|
|
971
975
|
import('/argo/workbench-client.js').then((mod) => {
|
|
972
976
|
if (!disposed && typeof mod?.mountArgoWorkbench === 'function') unmount = mod.mountArgoWorkbench(ctx, react);
|
|
973
977
|
}).catch(() => {});
|
|
@@ -976,17 +980,7 @@ window.__ModuleLoader__.load({
|
|
|
976
980
|
}
|
|
977
981
|
}
|
|
978
982
|
|
|
979
|
-
exports
|
|
980
|
-
exports.inject = inject;
|
|
981
|
-
exports.ArgoPanel = ArgoPanel;
|
|
982
|
-
// 静态数据导出供漂移门禁核对:TOOLS 必须与 native-tools.mjs(mcp_tools.py
|
|
983
|
-
// 生成产物)同名同集合,ENGINE_TOGGLES 必须与 specs.js 的 ARGO_ENV_SPECS
|
|
984
|
-
// 同名同集合——两边任何一边增删而另一边没跟上,测试即红。
|
|
985
|
-
exports.TOOLS = TOOLS;
|
|
986
|
-
exports.TOOL_GROUPS = TOOL_GROUPS;
|
|
987
|
-
exports.ENGINE_TOGGLES = ENGINE_TOGGLES;
|
|
988
|
-
exports.KEYS = KEYS;
|
|
989
|
-
|
|
983
|
+
Object.assign(exports, { apply, inject, ArgoPanel, SafeArgoPanel, PanelBoundary, TOOLS, TOOL_GROUPS, ENGINE_TOGGLES, KEYS });
|
|
990
984
|
return module.exports;
|
|
991
985
|
}
|
|
992
986
|
});
|
|
@@ -10,7 +10,29 @@ import { homedir } from 'node:os'
|
|
|
10
10
|
import { join } from 'node:path'
|
|
11
11
|
|
|
12
12
|
const MAX_BYTES = 1024 * 1024 // 显式读取上限 1MB,防超大日志文件撑爆内存
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
async function readTailUtf8(filePath, maxBytes) {
|
|
15
|
+
let fh
|
|
16
|
+
try {
|
|
17
|
+
fh = await fs.open(filePath, 'r')
|
|
18
|
+
const { size } = await fh.stat()
|
|
19
|
+
if (size <= 0) return ''
|
|
20
|
+
const len = Math.min(size, maxBytes)
|
|
21
|
+
const offset = size - len
|
|
22
|
+
const buf = Buffer.allocUnsafe(len)
|
|
23
|
+
const { bytesRead } = await fh.read(buf, 0, len, offset)
|
|
24
|
+
const text = buf.subarray(0, bytesRead).toString('utf8')
|
|
25
|
+
if (offset > 0) {
|
|
26
|
+
const firstNl = text.indexOf('\n')
|
|
27
|
+
return firstNl >= 0 ? text.slice(firstNl + 1) : text
|
|
28
|
+
}
|
|
29
|
+
return text
|
|
30
|
+
} finally {
|
|
31
|
+
if (fh) {
|
|
32
|
+
try { await fh.close() } catch { /* ignore */ }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
14
36
|
|
|
15
37
|
/**
|
|
16
38
|
* 解析 argo 运行时状态目录,遵循 argo_paths.py 跨平台约定:
|
|
@@ -52,8 +74,7 @@ export async function getRouteHealth(stateDir, limit = 10) {
|
|
|
52
74
|
try {
|
|
53
75
|
const routePath = join(dir, 'usage_log', 'route.jsonl')
|
|
54
76
|
if (existsSync(routePath)) {
|
|
55
|
-
const
|
|
56
|
-
const truncated = text.length > MAX_BYTES ? text.slice(-MAX_BYTES) : text
|
|
77
|
+
const truncated = await readTailUtf8(routePath, MAX_BYTES)
|
|
57
78
|
const lines = truncated.split('\n').filter(Boolean)
|
|
58
79
|
for (const line of lines) {
|
|
59
80
|
try {
|
|
@@ -114,7 +135,7 @@ export function getMcpPoolStats(pool = []) {
|
|
|
114
135
|
const connections = pool.map((conn, index) => ({
|
|
115
136
|
index,
|
|
116
137
|
load: typeof conn.load === 'function' ? conn.load() : 0,
|
|
117
|
-
hasProcess: Boolean(conn.proc
|
|
138
|
+
hasProcess: Boolean(conn.proc),
|
|
118
139
|
}))
|
|
119
140
|
|
|
120
141
|
const totalLoad = connections.reduce((sum, item) => sum + item.load, 0)
|
|
@@ -44,7 +44,9 @@ import {
|
|
|
44
44
|
resetEnvResolver,
|
|
45
45
|
makeNativeTool,
|
|
46
46
|
disposeSharedMcp,
|
|
47
|
+
searchViaArgoMCP,
|
|
47
48
|
fetchViaArgo,
|
|
49
|
+
resolveEntry,
|
|
48
50
|
mapArgoToWebResult,
|
|
49
51
|
classifyFetchError,
|
|
50
52
|
} from './runner.js'
|
|
@@ -220,12 +222,87 @@ function runEffect(ctx, fn) {
|
|
|
220
222
|
|
|
221
223
|
const asString = (value, fallback = '') => typeof value === 'string' ? value.trim() : fallback
|
|
222
224
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
const DEEPSEEK_MODEL_ROUTES = new Set(['deepseek-official', 'deepseek-account'])
|
|
226
|
+
|
|
227
|
+
export function capWebSearchSources(result, maxResults) {
|
|
228
|
+
if (!result || !Array.isArray(result.sources)) return result
|
|
229
|
+
if (typeof maxResults !== 'number' || !Number.isFinite(maxResults) || maxResults < 0) return result
|
|
230
|
+
if (result.sources.length <= maxResults) return result
|
|
231
|
+
return {
|
|
232
|
+
...result,
|
|
233
|
+
sources: result.sources.slice(0, maxResults),
|
|
234
|
+
truncated: true,
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function readConfiguredSearchProvider(web) {
|
|
239
|
+
try {
|
|
240
|
+
const raw = typeof web?.config?.searchProvider?.get === 'function'
|
|
241
|
+
? web.config.searchProvider.get()
|
|
242
|
+
: web?.config?.searchProvider
|
|
243
|
+
const configured = typeof raw === 'string' && raw !== '' ? raw : web?.searchProviderEnv
|
|
244
|
+
return typeof configured === 'string' && configured !== '' ? configured : undefined
|
|
245
|
+
} catch {
|
|
246
|
+
return undefined
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* DSH v0.2.2-rc.5 起,未 pin `web.searchProvider` 时宿主默认把 DeepSeek 路由
|
|
252
|
+
* 交给免费的 `deepseek-official` 服务端搜索,把其他路由写死回落到按次计费的
|
|
253
|
+
* `deepseek-search-api`。这里在不抢占配置位的前提下按 `llmProvider` 透明分流:
|
|
254
|
+
* DeepSeek 路由透传宿主原生搜索;其余路由改由 argo 承接,用户显式 pin 时让位。
|
|
255
|
+
*/
|
|
256
|
+
export function installWebSearchRouteDecorator(ctx, web, config, runArgoSearch) {
|
|
257
|
+
if (!web || typeof web.search !== 'function') return undefined
|
|
258
|
+
|
|
259
|
+
const shouldRouteToArgo = (llmProvider) =>
|
|
260
|
+
config.searchProviderEnabled !== false
|
|
261
|
+
&& readConfiguredSearchProvider(web) === undefined
|
|
262
|
+
&& !DEEPSEEK_MODEL_ROUTES.has(llmProvider)
|
|
263
|
+
|
|
264
|
+
const hadOwnSearch = Object.prototype.hasOwnProperty.call(web, 'search')
|
|
265
|
+
const rawOrigSearch = web.search
|
|
266
|
+
const wrappedSearch = async (request, signal) => {
|
|
267
|
+
if (shouldRouteToArgo(request?.llmProvider)) {
|
|
268
|
+
return capWebSearchSources(await runArgoSearch(request, signal), request?.maxResults)
|
|
269
|
+
}
|
|
270
|
+
return rawOrigSearch.call(web, request, signal)
|
|
271
|
+
}
|
|
272
|
+
web.search = wrappedSearch
|
|
273
|
+
|
|
274
|
+
const hasSearchReady = typeof web.searchReady === 'function'
|
|
275
|
+
const hadOwnSearchReady = hasSearchReady && Object.prototype.hasOwnProperty.call(web, 'searchReady')
|
|
276
|
+
const rawOrigSearchReady = hasSearchReady ? web.searchReady : undefined
|
|
277
|
+
let wrappedSearchReady
|
|
278
|
+
if (hasSearchReady) {
|
|
279
|
+
wrappedSearchReady = async (llmProvider) => {
|
|
280
|
+
if (shouldRouteToArgo(llmProvider)) return true
|
|
281
|
+
return rawOrigSearchReady.call(web, llmProvider)
|
|
282
|
+
}
|
|
283
|
+
web.searchReady = wrappedSearchReady
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const restore = () => {
|
|
287
|
+
if (web.search === wrappedSearch) {
|
|
288
|
+
if (hadOwnSearch) web.search = rawOrigSearch
|
|
289
|
+
else delete web.search
|
|
290
|
+
}
|
|
291
|
+
if (hasSearchReady && web.searchReady === wrappedSearchReady) {
|
|
292
|
+
if (hadOwnSearchReady) web.searchReady = rawOrigSearchReady
|
|
293
|
+
else delete web.searchReady
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
runEffect(ctx, () => restore)
|
|
297
|
+
return restore
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const _envResolverImpl = async (options, config) => resolveArgoEnv(config, options)
|
|
301
|
+
// 模块导入时预注册,apply() 内也会重注册以保证同进程 HMR 重载不丢失
|
|
302
|
+
setEnvResolver(_envResolverImpl)
|
|
227
303
|
|
|
228
304
|
export function apply(ctx, providedConfig = {}) {
|
|
305
|
+
setEnvResolver(_envResolverImpl)
|
|
229
306
|
const config = liveConfig(providedConfig)
|
|
230
307
|
const toolName = asString(config.toolName, DEFAULTS.toolName)
|
|
231
308
|
const providerName = asString(config.provider, DEFAULTS.provider)
|
|
@@ -246,7 +323,7 @@ export function apply(ctx, providedConfig = {}) {
|
|
|
246
323
|
}
|
|
247
324
|
}
|
|
248
325
|
|
|
249
|
-
for (const ref of asStringArray(config.keyRefs,
|
|
326
|
+
for (const ref of asStringArray(config.keyRefs, 64)) {
|
|
250
327
|
if (!CREDENTIAL_REF_PATTERN.test(ref)) {
|
|
251
328
|
throw new Error(`argo-dsh: keyRefs entry "${ref}" must be a POSIX-style identifier (e.g. DEEPSEEK_API_KEY)`)
|
|
252
329
|
}
|
|
@@ -290,28 +367,36 @@ export function apply(ctx, providedConfig = {}) {
|
|
|
290
367
|
|
|
291
368
|
const web = ctx.get?.('web') ?? ctx.web
|
|
292
369
|
if (web && typeof web.registerSearchProvider === 'function') {
|
|
370
|
+
const runArgoSearch = (request, signal) => {
|
|
371
|
+
const entry = resolveEntry(config)
|
|
372
|
+
return searchViaArgoMCP(request.query, request.maxResults, signal, {
|
|
373
|
+
command: entry.command,
|
|
374
|
+
args: entry.args,
|
|
375
|
+
timeoutMs: config.searchTimeoutMs,
|
|
376
|
+
idleMs: config.searchIdleMs,
|
|
377
|
+
max: config.searchConcurrency,
|
|
378
|
+
config,
|
|
379
|
+
// issue #41:显式带上宿主凭证服务,否则池内连接 envResolver 解析
|
|
380
|
+
// keyRefs 时 provider 为 undefined,所有需 key 引擎静默 skipped。
|
|
381
|
+
credentials: hostCredentials,
|
|
382
|
+
})
|
|
383
|
+
}
|
|
293
384
|
web.registerSearchProvider({
|
|
294
385
|
id: asString(config.searchProviderId, DEFAULTS.searchProviderId),
|
|
386
|
+
title: 'Argo Multi-Engine Search',
|
|
387
|
+
description: '多引擎融合搜索、证据核验与中文增强(通过本机 argo-search 路由)',
|
|
295
388
|
available: () => config.searchProviderEnabled !== false,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return searchViaArgoMCP(request.query, request.maxResults, signal, {
|
|
299
|
-
command: entry.command,
|
|
300
|
-
args: entry.args,
|
|
301
|
-
timeoutMs: config.searchTimeoutMs,
|
|
302
|
-
idleMs: config.searchIdleMs,
|
|
303
|
-
max: config.searchConcurrency,
|
|
304
|
-
config,
|
|
305
|
-
// issue #41:显式带上宿主凭证服务,否则池内连接 envResolver 解析
|
|
306
|
-
// keyRefs 时 provider 为 undefined,所有需 key 引擎静默 skipped。
|
|
307
|
-
credentials: hostCredentials,
|
|
308
|
-
})
|
|
309
|
-
},
|
|
389
|
+
ready: () => config.searchProviderEnabled !== false,
|
|
390
|
+
search: runArgoSearch,
|
|
310
391
|
})
|
|
392
|
+
installWebSearchRouteDecorator(ctx, web, config, runArgoSearch)
|
|
311
393
|
if (typeof web.registerFetchProvider === 'function') {
|
|
312
394
|
web.registerFetchProvider({
|
|
313
395
|
id: asString(config.fetchProviderId, DEFAULTS.fetchProviderId),
|
|
396
|
+
title: 'Argo Web Fetch',
|
|
397
|
+
description: '多级降级网页全文提取与反爬绕过(通过本机 argo-search)',
|
|
314
398
|
available: () => config.fetchProviderEnabled !== false,
|
|
399
|
+
ready: () => config.fetchProviderEnabled !== false,
|
|
315
400
|
fetch: (request, signal) => {
|
|
316
401
|
const entry = resolveEntry(config)
|
|
317
402
|
return fetchViaArgo(request.url, signal, {
|
|
@@ -332,10 +417,14 @@ export function apply(ctx, providedConfig = {}) {
|
|
|
332
417
|
|
|
333
418
|
const nativeRegistrations = new Map()
|
|
334
419
|
// 路由观测推送:原生工具执行后读 argo 使用日志,经 remote 事件推给设置面板。
|
|
335
|
-
//
|
|
420
|
+
// 节流 3s 避免高频搜索连续读盘;失败静默,无 remote 事件总线时跳过。
|
|
421
|
+
let lastRouteEmitAt = 0
|
|
336
422
|
const emitRouteHealth = async () => {
|
|
337
423
|
try {
|
|
338
424
|
if (!ctx.remote || typeof ctx.remote.$emit !== 'function') return
|
|
425
|
+
const now = Date.now()
|
|
426
|
+
if (now - lastRouteEmitAt < 3000) return
|
|
427
|
+
lastRouteEmitAt = now
|
|
339
428
|
const data = await getRouteHealth()
|
|
340
429
|
if (Array.isArray(data.samples) && data.samples.length > 0) {
|
|
341
430
|
ctx.remote.$emit('route-health/updated', data)
|
|
@@ -374,7 +463,6 @@ export function apply(ctx, providedConfig = {}) {
|
|
|
374
463
|
}
|
|
375
464
|
nativeRegistrations.clear()
|
|
376
465
|
resetEnvResolver()
|
|
377
|
-
disposeSharedMcp()
|
|
378
466
|
})
|
|
379
467
|
|
|
380
468
|
ctx.tools.register(createWideResearchTool(ctx, config, {
|
|
@@ -30,6 +30,10 @@ export const NATIVE_TOOLS = {
|
|
|
30
30
|
],
|
|
31
31
|
"description": "搜索领域:web 统一网络搜索(默认),social 社交媒体/论坛讨论,job 招聘岗位聚合,local 本机文件搜索"
|
|
32
32
|
},
|
|
33
|
+
"platforms": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"description": "domain=social 的平台名,逗号分隔。twitter 表示 X 关键词自动选路;固定通道用 engine=fxtwitter/twitter_cli/twitter。"
|
|
36
|
+
},
|
|
33
37
|
"engine": {
|
|
34
38
|
"type": "string",
|
|
35
39
|
"description": "指定搜索引擎(auto 自动选择;可选 octen/anysearch/exa/zhihu/eastmoney/arxiv/byted/bocha/tavily/deepseek_search/github/wikipedia/semantic_scholar/local_search 等,默认 auto;deepseek_search 为按次计费的官方 DeepSeek 搜索,结果带权威分级与发布时间,新闻时事类查询优先考虑)"
|
|
@@ -106,6 +110,7 @@ export const NATIVE_TOOLS = {
|
|
|
106
110
|
"allowed": [
|
|
107
111
|
"query",
|
|
108
112
|
"domain",
|
|
113
|
+
"platforms",
|
|
109
114
|
"engine",
|
|
110
115
|
"max_results",
|
|
111
116
|
"depth",
|
|
@@ -349,6 +354,10 @@ export const NATIVE_TOOLS = {
|
|
|
349
354
|
"type": "integer",
|
|
350
355
|
"description": "返回正文最大字符数(500-50000,默认 8000)"
|
|
351
356
|
},
|
|
357
|
+
"answer_offset": {
|
|
358
|
+
"type": "integer",
|
|
359
|
+
"description": "知乎回答摘要查询偏移:首轮省略;仅在用户明确要求续查时传上次的 next_offset"
|
|
360
|
+
},
|
|
352
361
|
"use_browser": {
|
|
353
362
|
"type": "boolean",
|
|
354
363
|
"description": "强制用反检测浏览器(HTTP 失败时已自动升级,默认关)"
|
|
@@ -369,6 +378,7 @@ export const NATIVE_TOOLS = {
|
|
|
369
378
|
"extract_mode",
|
|
370
379
|
"focus",
|
|
371
380
|
"max_chars",
|
|
381
|
+
"answer_offset",
|
|
372
382
|
"use_browser",
|
|
373
383
|
"include_links"
|
|
374
384
|
]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @taxueseek/argo-dsh — 控制面路由安全围栏(TCP Peer 主防线 + Host/Origin 纵深)
|
|
3
|
+
*
|
|
4
|
+
* 仅允许本机回环对端访问控制面接口:
|
|
5
|
+
* 1. 当存在底层 TCP socket 时,以 req.socket.remoteAddress 为唯一主判据
|
|
6
|
+
* (无法被客户端伪造,绝不信任 X-Forwarded-For);
|
|
7
|
+
* 2. 叠加 Host 与 Origin 的回环/同源校验,防御本机浏览器的 DNS Rebinding。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const IPV4_LOOPBACK_RE = /^127\.(?:25[0-5]|2[0-4]\d|1?\d?\d)\.(?:25[0-5]|2[0-4]\d|1?\d?\d)\.(?:25[0-5]|2[0-4]\d|1?\d?\d)$/
|
|
11
|
+
|
|
12
|
+
export function isLoopbackAddress(addr) {
|
|
13
|
+
if (typeof addr !== 'string') return false
|
|
14
|
+
const raw = addr.trim().toLowerCase()
|
|
15
|
+
if (!raw) return false
|
|
16
|
+
if (raw === '::1' || raw === 'localhost') return true
|
|
17
|
+
if (IPV4_LOOPBACK_RE.test(raw)) return true
|
|
18
|
+
if (raw.startsWith('::ffff:')) {
|
|
19
|
+
return IPV4_LOOPBACK_RE.test(raw.slice(7))
|
|
20
|
+
}
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function extractHostname(hostHeader) {
|
|
25
|
+
if (typeof hostHeader !== 'string' || !hostHeader.trim()) return ''
|
|
26
|
+
try {
|
|
27
|
+
return new URL(`http://${hostHeader.trim()}`).hostname.toLowerCase()
|
|
28
|
+
} catch {
|
|
29
|
+
return ''
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isLoopbackHost(hostHeader) {
|
|
34
|
+
const host = extractHostname(hostHeader)
|
|
35
|
+
if (!host) return false
|
|
36
|
+
if (host === 'localhost' || host === '[::1]' || host === '::1') return true
|
|
37
|
+
return IPV4_LOOPBACK_RE.test(host)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function checkLoopbackAndOrigin(ctx, req) {
|
|
41
|
+
const peer = req?.socket?.remoteAddress ?? req?.connection?.remoteAddress ?? req?.remoteAddress
|
|
42
|
+
if (peer !== undefined && peer !== null && peer !== '') {
|
|
43
|
+
if (!isLoopbackAddress(String(peer))) return false
|
|
44
|
+
} else if (!isLoopbackHost(req?.headers?.host)) {
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const hostHeader = req?.headers?.host
|
|
49
|
+
if (hostHeader && !isLoopbackHost(hostHeader)) {
|
|
50
|
+
const expected = ctx?.webServer?.getOrigin?.()
|
|
51
|
+
if (!expected) return false
|
|
52
|
+
try {
|
|
53
|
+
const expectedHost = new URL(expected).hostname.toLowerCase()
|
|
54
|
+
if (extractHostname(hostHeader) !== expectedHost) return false
|
|
55
|
+
} catch {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const origin = req?.headers?.origin
|
|
61
|
+
if (!origin) return true
|
|
62
|
+
try {
|
|
63
|
+
const expected = ctx?.webServer?.getOrigin?.()
|
|
64
|
+
if (expected && origin === expected) return true
|
|
65
|
+
const parsed = new URL(origin)
|
|
66
|
+
return isLoopbackAddress(parsed.hostname)
|
|
67
|
+
} catch {
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 查询登录态 Profile 列表,并对冷启动未核验站点后台静默触发一次活体复核(60s 缓存)。 */
|
|
73
|
+
export async function resolveAuthStatusWithBgVerify({ runCli, verifyCache, inflight, allowVerify = true }) {
|
|
74
|
+
let profiles = []
|
|
75
|
+
try {
|
|
76
|
+
const out = await runCli(['auth', 'status', '--json'])
|
|
77
|
+
profiles = Array.isArray(out?.profiles) ? out.profiles : []
|
|
78
|
+
} catch {
|
|
79
|
+
profiles = []
|
|
80
|
+
}
|
|
81
|
+
const now = Date.now()
|
|
82
|
+
return profiles.map((p) => {
|
|
83
|
+
const site = String(p?.site || '')
|
|
84
|
+
const cached = verifyCache.get(site)
|
|
85
|
+
const fresh = cached && (now - cached.ts < 60_000) ? cached.data : null
|
|
86
|
+
if (site && !fresh && !inflight.has(site) && allowVerify) {
|
|
87
|
+
inflight.add(site)
|
|
88
|
+
runCli(['auth', 'verify', site, '--json'])
|
|
89
|
+
.then((v) => { verifyCache.set(site, { ts: Date.now(), data: v }) })
|
|
90
|
+
.catch(() => {})
|
|
91
|
+
.finally(() => { inflight.delete(site) })
|
|
92
|
+
}
|
|
93
|
+
return { ...p, verification: fresh || { pending: Boolean(site) } }
|
|
94
|
+
})
|
|
95
|
+
}
|
|
@@ -80,6 +80,7 @@ export const DEFAULTS = Object.freeze({
|
|
|
80
80
|
'FOURGET_URL',
|
|
81
81
|
'GEMINI_API_KEY',
|
|
82
82
|
'GITHUB_TOKEN',
|
|
83
|
+
'HELVE_API_KEY',
|
|
83
84
|
'KEENABLE_API_KEY',
|
|
84
85
|
'METASO_API_KEY',
|
|
85
86
|
'OCTEN_API_KEY',
|
|
@@ -295,8 +296,9 @@ export function createMcpConnection(options) {
|
|
|
295
296
|
return initPromise
|
|
296
297
|
},
|
|
297
298
|
request: (method, params, timeoutMs = 0) => {
|
|
299
|
+
const p = send(method, params, timeoutMs)
|
|
298
300
|
if (claims > 0) claims -= 1
|
|
299
|
-
return
|
|
301
|
+
return p
|
|
300
302
|
},
|
|
301
303
|
claim: () => {
|
|
302
304
|
claims += 1
|
|
@@ -361,10 +363,13 @@ export async function acquireMcp(options, signal) {
|
|
|
361
363
|
if (mcpPool.length >= max) throw err
|
|
362
364
|
}
|
|
363
365
|
}
|
|
366
|
+
const envCfg = (options.config && ('keyRefs' in options.config || 'argoEnv' in options.config))
|
|
367
|
+
? options.config
|
|
368
|
+
: undefined
|
|
364
369
|
if (mcpPool.length < max) {
|
|
365
370
|
const conn = createMcpConnection({
|
|
366
371
|
...options,
|
|
367
|
-
envResolver: () => resolveEnv(options),
|
|
372
|
+
envResolver: () => resolveEnv(options, envCfg),
|
|
368
373
|
configKey: targetConfigKey,
|
|
369
374
|
})
|
|
370
375
|
mcpPool.push(conn)
|
|
@@ -378,7 +383,29 @@ export async function acquireMcp(options, signal) {
|
|
|
378
383
|
}
|
|
379
384
|
return conn
|
|
380
385
|
}
|
|
381
|
-
const
|
|
386
|
+
const matching = mcpPool.filter(entry => entry.configKey === undefined || entry.configKey === targetConfigKey)
|
|
387
|
+
if (matching.length === 0) {
|
|
388
|
+
// 满池且全部为旧 configKey 的忙连接:不可关闭在跑的连接,只能新建一条
|
|
389
|
+
// 临时超限(pool 瞬时 > max)。超限是自限的:函数开头会把空转的旧
|
|
390
|
+
// configKey 连接回收,新建的匹配连接下次会被 354 行的 idle 分支复用,
|
|
391
|
+
// 池随之收敛回 max 以内(2026-11-21 审计:原注释「替换最闲旧连接」与代码不符)
|
|
392
|
+
const conn = createMcpConnection({
|
|
393
|
+
...options,
|
|
394
|
+
envResolver: () => resolveEnv(options, envCfg),
|
|
395
|
+
configKey: targetConfigKey,
|
|
396
|
+
})
|
|
397
|
+
mcpPool.push(conn)
|
|
398
|
+
conn.claim()
|
|
399
|
+
try {
|
|
400
|
+
await initializeWithSignal(conn, initMs, signal)
|
|
401
|
+
} catch (err) {
|
|
402
|
+
dropFromPool(conn)
|
|
403
|
+
conn.close()
|
|
404
|
+
throw err
|
|
405
|
+
}
|
|
406
|
+
return conn
|
|
407
|
+
}
|
|
408
|
+
const least = matching.reduce((a, b) => (a.load() <= b.load() ? a : b))
|
|
382
409
|
least.claim()
|
|
383
410
|
try {
|
|
384
411
|
await initializeWithSignal(least, initMs, signal)
|
|
@@ -477,7 +504,11 @@ export async function fetchViaArgo(url, signal, options = {}, deps = {}) {
|
|
|
477
504
|
return
|
|
478
505
|
}
|
|
479
506
|
const text = value?.content?.[0]?.text
|
|
480
|
-
|
|
507
|
+
try {
|
|
508
|
+
resolve(typeof text === 'string' ? JSON.parse(text) : {})
|
|
509
|
+
} catch (parseErr) {
|
|
510
|
+
reject(argoToolError(`argo_fetch returned invalid JSON: ${parseErr.message}`))
|
|
511
|
+
}
|
|
481
512
|
}, (err) => {
|
|
482
513
|
if (signal !== undefined) signal.removeEventListener('abort', onAbort)
|
|
483
514
|
reject(err)
|
|
@@ -616,12 +647,24 @@ export function runNativeCall({ command, args, env }, timeoutMs, signal) {
|
|
|
616
647
|
signal.addEventListener('abort', onAbort, { once: true })
|
|
617
648
|
detachAbort = () => signal.removeEventListener('abort', onAbort)
|
|
618
649
|
}
|
|
650
|
+
const MAX_NATIVE_BYTES = 4 * 1024 * 1024
|
|
651
|
+
let stdoutBytes = 0
|
|
652
|
+
let stderrBytes = 0
|
|
619
653
|
timer = setTimeout(() => {
|
|
620
654
|
try { child.kill('SIGKILL') } catch { /* already gone */ }
|
|
621
655
|
settle(reject, new Error(`argo native call timed out after ${timeoutMs}ms`))
|
|
622
656
|
}, timeoutMs)
|
|
623
|
-
|
|
624
|
-
child.
|
|
657
|
+
if (typeof timer.unref === 'function') timer.unref()
|
|
658
|
+
child.stdout.setEncoding('utf8')
|
|
659
|
+
child.stderr.setEncoding('utf8')
|
|
660
|
+
child.stdout.on('data', (chunk) => {
|
|
661
|
+
stdoutBytes += Buffer.byteLength(chunk, 'utf8')
|
|
662
|
+
if (stdoutBytes <= MAX_NATIVE_BYTES) stdout += chunk
|
|
663
|
+
})
|
|
664
|
+
child.stderr.on('data', (chunk) => {
|
|
665
|
+
stderrBytes += Buffer.byteLength(chunk, 'utf8')
|
|
666
|
+
if (stderrBytes <= 256 * 1024) stderr += chunk
|
|
667
|
+
})
|
|
625
668
|
child.on('error', (err) => settle(reject, err))
|
|
626
669
|
child.on('close', (code) => {
|
|
627
670
|
if (code === 0) { settle(resolve, stdout); return }
|