argo-search 2.11.2 → 2.12.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.
Files changed (72) hide show
  1. package/README.en.md +25 -21
  2. package/README.es.md +24 -20
  3. package/README.ja.md +25 -21
  4. package/README.ko.md +24 -20
  5. package/README.md +30 -22
  6. package/SKILL.md +6 -6
  7. package/backends/domain_profiles.json +12 -0
  8. package/backends/engine_registry.yaml +26 -1
  9. package/backends/quota_profiles.json +20 -0
  10. package/bin/argo +7 -0
  11. package/config.yaml +18 -3
  12. package/docs/ENGINE_CATALOG.md +8 -6
  13. package/docs/MCP_SETUP.md +16 -4
  14. package/docs/RELEASE_NOTES_v2.11.2.md +116 -0
  15. package/docs/RELEASE_NOTES_v2.12.0.md +65 -0
  16. package/docs/engines/pixiv.md +27 -0
  17. package/engines/specs/pixiv.yaml +52 -0
  18. package/engines/specs/tracemoe.yaml +33 -0
  19. package/package.json +3 -2
  20. package/packages/dsh-plugin/README.md +20 -11
  21. package/packages/dsh-plugin/dsh/client.js +3 -3
  22. package/packages/dsh-plugin/dsh/index.js +22 -176
  23. package/packages/dsh-plugin/dsh/runner.js +12 -2
  24. package/packages/dsh-plugin/dsh/specs.js +133 -0
  25. package/packages/dsh-plugin/package.json +10 -2
  26. package/packages/dsh-plugin/test/client.test.js +4 -4
  27. package/packages/dsh-plugin/test/diagnostics.test.js +1 -1
  28. package/packages/dsh-plugin/test/index.test.js +28 -2
  29. package/scripts/adaptive.py +101 -27
  30. package/scripts/build_route_labels.py +122 -169
  31. package/scripts/caliber_dedupe.py +4 -4
  32. package/scripts/caliber_isolation.py +17 -17
  33. package/scripts/concept_lookup.py +14 -1
  34. package/scripts/config.py +21 -3
  35. package/scripts/engine_admission.py +35 -17
  36. package/scripts/engine_dispatch.py +16 -16
  37. package/scripts/engine_env.py +4 -0
  38. package/scripts/engine_families.py +6 -4
  39. package/scripts/engines.py +5 -0
  40. package/scripts/engines_base.py +1 -1
  41. package/scripts/engines_builders_data.py +10 -10
  42. package/scripts/engines_builders_pixiv.py +633 -0
  43. package/scripts/engines_builders_reverse_image.py +175 -0
  44. package/scripts/env_store.py +216 -0
  45. package/scripts/extend_route_labels_by_capability.py +4 -4
  46. package/scripts/extend_route_labels_full_coverage.py +329 -0
  47. package/scripts/fetch_v3.py +74 -5
  48. package/scripts/job.py +31 -6
  49. package/scripts/local_image.py +22 -8
  50. package/scripts/mcp_compact.py +9 -1
  51. package/scripts/mcp_launch.sh +1 -1
  52. package/scripts/mcp_setup.py +85 -1
  53. package/scripts/mcp_transport.py +1 -1
  54. package/scripts/plan.py +2 -2
  55. package/scripts/pre-commit +4 -1
  56. package/scripts/query_signals.py +35 -20
  57. package/scripts/quota.py +9 -4
  58. package/scripts/recovery.py +38 -13
  59. package/scripts/redskill/redskill_engine.py +33 -10
  60. package/scripts/route.py +2 -2
  61. package/scripts/route_accuracy_eval.py +2 -2
  62. package/scripts/route_combo.py +22 -3
  63. package/scripts/route_domains.py +182 -50
  64. package/scripts/search.py +0 -2
  65. package/scripts/search_entry.py +38 -42
  66. package/scripts/search_output.py +3 -0
  67. package/scripts/search_pipeline.py +3 -8
  68. package/scripts/search_rank.py +22 -7
  69. package/scripts/serp_guard.py +7 -16
  70. package/scripts/settings_page.py +486 -0
  71. package/scripts/straggler_policy.py +8 -4
  72. package/scripts/tfidf_router.py +82 -24
@@ -0,0 +1,133 @@
1
+ import { NATIVE_TOOLS as NATIVE_TOOL_SPECS } from "./native-tools.mjs"
2
+ import { DEFAULTS } from "./runner.js"
3
+
4
+ export const asStringArray = (value, maximum) => Array.isArray(value)
5
+ ? value.filter(entry => typeof entry === "string").map(entry => entry.trim()).filter(Boolean).slice(0, maximum)
6
+ : []
7
+
8
+ export const CREDENTIAL_REF_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/
9
+
10
+ let hostCredentials = undefined
11
+ let activeConfig = DEFAULTS
12
+
13
+ export function setHostCredentials(creds) {
14
+ hostCredentials = creds
15
+ }
16
+
17
+ export function setActiveConfig(config) {
18
+ activeConfig = config
19
+ }
20
+
21
+ const MCP_CHILD_TOOLS = Object.keys(NATIVE_TOOL_SPECS).map(name => `mcp__argo__${name}`)
22
+ export const DEFAULT_CHILD_TOOLS = Object.freeze([
23
+ ...MCP_CHILD_TOOLS,
24
+ 'argo_search',
25
+ 'argo_fetch',
26
+ 'web_search',
27
+ 'web_fetch',
28
+ ])
29
+
30
+ export function buildChildToolFilters(config, toolName) {
31
+ const base = Array.isArray(config?.childToolAllow) ? config.childToolAllow : DEFAULT_CHILD_TOOLS
32
+ const blocked = new Set([toolName, 'mcp__argo__argo_research'])
33
+ const deny = [...new Set([toolName, ...asStringArray(config?.childToolDeny, 100)])]
34
+ const denySet = new Set(deny)
35
+ const allow = [...new Set(asStringArray(base, 100).filter(tool => !blocked.has(tool) && !denySet.has(tool)))]
36
+ return { allow, deny }
37
+ }
38
+
39
+ /**
40
+ * 面板可露出的 argo 环境变量开关(curated 白名单)。
41
+ *
42
+ * 选录标准:日常会开合的行为开关,语义单一、默认值在 argo 侧稳定;授权位
43
+ * (ARGO_ALLOW_RECOMPUTE / ARGO_ALLOW_PRIVATE_URLS,argo 要求 expand=False
44
+ * + strict=True)与路径/状态类内部变量(ARGO_STATE_DIR / ARGO_HOME /
45
+ * ARGO_DAEMON 等)刻意不收——前者不该一键放行,后者改了会动摇凭证 seam 的
46
+ * 解析前提。每个名字都在 argo 仓 scripts/ 有读取点,由
47
+ * tests/test_dsh_plugin_env_gate.py 对拍,防白名单漂移成 Fiction。
48
+ *
49
+ * kind:bool=开关(值 0/1)、num=数字,str=字符串,list=名单(逗号或路径分隔符分隔,照 argo 原语义)。
50
+ * def=argo 侧默认值(仅面板展示用,缺省即不写该行、由 argo 自己决定)。
51
+ *
52
+ * 开关文案一律写「正向行为」或「明确的关闭动作」,**不要再用 invert 反转**:
53
+ * 历史 bug(2026-10-22)——`关闭搜索结果缓存` 配 invert 后,未配置时面板显示
54
+ * 为「开」,点一下反而把 ARGO_NO_CACHE 写成 0,缓存始终没关掉。
55
+ */
56
+ export const ARGO_ENV_SPECS = Object.freeze([
57
+ { name: 'ARGO_NO_CACHE', kind: 'bool', group: 'cache', def: false, zh: '测试模式(关闭结果缓存)', en: 'Test mode (disable result cache)', hintZh: '日常保持关闭:结果缓存 1 小时。改进 Skill/插件、需要看实时结果时再打开', hintEn: 'Off by default: results are cached for 1h. Enable only when developing the skill/plugin' },
58
+ { name: 'ARGO_TFIDF_RERANK', kind: 'bool', group: 'cache', def: true, zh: 'TF-IDF 重排', en: 'TF-IDF rerank', hintZh: '多引擎结果融合前的相关性重排,默认开', hintEn: 'Relevance rerank before fusion, on by default' },
59
+ { name: 'ARGO_NUMBER_CROSSCHECK', kind: 'bool', group: 'cache', def: true, zh: '数值交叉校验', en: 'Number cross-check', hintZh: '对查询里的数值主张做跨源核对,默认开', hintEn: 'Cross-check numeric claims across sources, on by default' },
60
+ { name: 'ARGO_MINHASH_DEDUPE', kind: 'bool', group: 'cache', def: true, zh: 'MinHash 去重', en: 'MinHash dedupe', hintZh: '近重复结果合并,默认开', hintEn: 'Merge near-duplicate results, on by default' },
61
+ { name: 'ARGO_MINHASH_THRESHOLD', kind: 'num', group: 'cache', def: 0.85, min: 0.5, max: 1, step: 0.05, zh: '去重阈值', en: 'Dedupe threshold', hintZh: '越高越严(越多判为不同),默认 0.85', hintEn: 'Higher = stricter, default 0.85' },
62
+ { name: 'ARGO_SERP_GUARD', kind: 'bool', group: 'cache', def: true, zh: 'SERP 守卫', en: 'SERP guard', hintZh: '拦截壳页/风控页混入结果,默认开;误杀时先关它复现', hintEn: 'Keep shell/blocked pages out of results, on by default' },
63
+ { name: 'ARGO_FETCH_JINA', kind: 'bool', group: 'fetch', def: true, zh: 'Jina 阅读器抓取', en: 'Jina reader fetch', hintZh: 'r.jina.ai 正文提取,默认开', hintEn: 'r.jina.ai text extraction, on by default' },
64
+ { name: 'ARGO_FETCH_MOBILE', kind: 'bool', group: 'fetch', def: true, zh: '移动端 UA 抓取', en: 'Mobile UA fetch', hintZh: '按 host 记忆移动端身份,默认开', hintEn: 'Per-host mobile identity, on by default' },
65
+ { name: 'ARGO_FETCH_PARALLEL', kind: 'bool', group: 'fetch', def: true, zh: 'Parallel 免费渲染抓取', en: 'Parallel free render fetch', hintZh: 'keyless 云端渲染兜底,默认开', hintEn: 'Keyless cloud render fallback, on by default' },
66
+ { name: 'ARGO_FETCH_DEADLINE_S', kind: 'num', group: 'fetch', def: 60, min: 5, max: 300, step: 5, zh: '抓取总截止(秒)', en: 'Fetch deadline (s)', hintZh: '单次抓取全链路墙钟上限,默认 60', hintEn: 'Wall-clock cap per fetch, default 60' },
67
+ { name: 'ARGO_SEMANTIC_EVIDENCE', kind: 'bool', group: 'semantic', def: false, zh: '语义证据层', en: 'Semantic evidence', hintZh: '显式核验链路的零样本判定,默认关;开启后多一次外呼', hintEn: 'Zero-shot support check on the verify path, off by default' },
68
+ { name: 'ARGO_ADAPTIVE_GRACE', kind: 'bool', group: 'semantic', def: true, zh: '对冲宽限自适应', en: 'Adaptive hedge grace', hintZh: '按引擎历史 p75 收窄对冲等待窗,默认开', hintEn: 'Narrow hedge window by engine p75, on by default' },
69
+ { name: 'ARGO_ADAPTIVE_TAIL', kind: 'bool', group: 'semantic', def: false, zh: '分层尾宽', en: 'Layered straggler tail', hintZh: '尾宽按未回来引擎分层取值,默认关', hintEn: 'Per-engine layered tail width, off by default' },
70
+ { name: 'ARGO_STRAGGLER_GRACE_S', kind: 'num', group: 'semantic', def: 1.5, min: 0, max: 30, step: 0.5, zh: '掉队宽限(秒)', en: 'Straggler grace (s)', hintZh: '已有引擎交付后还等多久,默认 1.5;0 关闭', hintEn: 'Wait after first delivery, default 1.5; 0 disables' },
71
+ { name: 'ARGO_SERIAL_STAGGER_S', kind: 'num', group: 'semantic', def: 0.8, min: 0, max: 30, step: 0.5, zh: '串行起步间隔(秒)', en: 'Serial stagger (s)', hintZh: '首引擎超时前补发备选源的提前量,默认 0.8;0 最激进', hintEn: 'Lead before firing a backup source, default 0.8; 0 = fire together' },
72
+ { name: 'ARGO_ENABLE_ENGINES', kind: 'list', group: 'engines', zh: '额外启用引擎', en: 'Extra enabled engines', hintZh: '逗号分隔;叠加在 config.yaml 启用集之上', hintEn: 'Comma-separated; adds to the config.yaml enabled set' },
73
+ { name: 'ARGO_DISABLE_ENGINES', kind: 'list', group: 'engines', zh: '停用引擎', en: 'Disabled engines', hintZh: '逗号分隔;优先级高于启用集,调试单引擎时用', hintEn: 'Comma-separated; wins over the enabled set' },
74
+ { name: 'ARGO_PROXY', kind: 'str', group: 'net', zh: 'argo 全局代理', en: 'argo global proxy', hintZh: 'http:// 代理 URL,或 direct 强制直连;留空走环境变量', hintEn: 'http:// proxy URL, or direct; empty falls back to env' },
75
+ { name: 'ARGO_GDELT_PROXY', kind: 'str', group: 'net', zh: 'GDELT 代理', en: 'GDELT proxy', hintZh: 'GDELT 按出口 IP 限流,经本地代理更稳;留空自动直连', hintEn: 'GDELT rate-limits by egress IP; empty = direct' },
76
+ { name: 'ARGO_LOCAL_SEEK_ROOTS', kind: 'list', group: 'local', zh: '本机检索根目录', en: 'Local seek roots', hintZh: '路径分隔符分隔;seek.py 的候选安装根,默认用打包位置', hintEn: 'Path-separated roots for seek.py; default uses the bundled copy' },
77
+ { name: 'ARGO_LOCAL_SEEK_PATH', kind: 'str', group: 'local', zh: 'seek.py 绝对路径', en: 'seek.py path', hintZh: '显式指定 seek.py,优先于根目录候选', hintEn: 'Explicit seek.py, wins over root candidates' },
78
+ { name: 'ARGO_LOCAL_READ_DIRS', kind: 'list', group: 'local', zh: '本机读取白名单', en: 'Local read allowlist', hintZh: '逗号分隔;不配置则 local_read 一律不放行', hintEn: 'Comma-separated; empty means local_read allows nothing' },
79
+ { name: 'ARGO_TEXT_LEXICON', kind: 'str', group: 'local', zh: '词表 JSON 路径', en: 'Lexicon JSON path', hintZh: '文本处理词表覆盖,默认用打包词表', hintEn: 'Text lexicon override; default uses the bundled one' },
80
+ { name: 'ARGO_PAID_SEARCH', kind: 'str', group: 'paid', def: 'auto', zh: '付费源策略', en: 'Paid source policy', hintZh: 'auto=优势域自动使用付费源;off=只用免费源。额度见下方', hintEn: 'auto = use paid sources in proven domains; off = free sources only. See quotas below' },
81
+ { name: 'ARGO_BUDGET_DEEPSEEK_SEARCH', kind: 'num', group: 'paid', def: 5, min: 0, max: 1000, step: 1, zh: 'DeepSeek 月度预算(元)', en: 'DeepSeek monthly budget (CNY)', hintZh: '0=关闭;¥5≈1000次成功调用(¥0.005/次)', hintEn: '0 = off; CNY 5 ≈ 1000 successful calls (CNY 0.005 each)' },
82
+ { name: 'ARGO_BUDGET_EXA', kind: 'num', group: 'paid', def: 10, min: 0, max: 10000, step: 1, zh: 'Exa 每月预算(美元)', en: 'Exa monthly budget (USD)', hintZh: '默认 $10/月(约 1000 次);0=关闭自动使用。按成功调用计费', hintEn: 'Default $10/month (~1000 calls); 0 = off. Billed per successful call' },
83
+ { name: 'ARGO_QUOTA_ANYSEARCH_LIMIT', kind: 'num', group: 'paid', def: 1000, min: 0, max: 1000000, step: 1, zh: 'AnySearch 每日次数上限', en: 'AnySearch daily call cap', hintZh: '默认 1000/日;0=不限制。改动对下一次新建连接生效', hintEn: 'Default 1000/day; 0 = unlimited. Applies to new connections' },
84
+ { name: 'ARGO_QUOTA_ZHIHU_LIMIT', kind: 'num', group: 'paid', def: 5000, min: 0, max: 1000000, step: 1, zh: '知乎 每日次数上限', en: 'Zhihu daily call cap', hintZh: '默认 5000/日;0=不限制。改动对下一次新建连接生效', hintEn: 'Default 5000/day; 0 = unlimited. Applies to new connections' },
85
+ { name: 'ARGO_QUOTA_YUANBAO_LIMIT', kind: 'num', group: 'paid', def: 2000, min: 0, max: 1000000, step: 1, zh: '元宝 每月次数上限', en: 'Yuanbao monthly call cap', hintZh: '默认 2000/月;0=不限制。改动对下一次新建连接生效', hintEn: 'Default 2000/month; 0 = unlimited. Applies to new connections' },
86
+ { name: 'ARGO_QUOTA_TAVILY_LIMIT', kind: 'num', group: 'paid', def: 1000, min: 0, max: 1000000, step: 1, zh: 'Tavily 每月次数上限', en: 'Tavily monthly call cap', hintZh: '默认 1000/月;0=不限制。改动对下一次新建连接生效', hintEn: 'Default 1000/month; 0 = unlimited. Applies to new connections' },
87
+ { name: 'ARGO_NO_PREWARM', kind: 'bool', group: 'misc', def: false, zh: '关闭连接预热', en: 'Disable prewarm', hintZh: 'MCP 握手后预热引擎注册表,默认开;开启本项即关闭预热', hintEn: 'Prewarm the engine registry after handshake, on by default; enable this to turn it off' },
88
+ { name: 'ARGO_USAGE_LOG', kind: 'bool', group: 'misc', def: true, zh: '使用日志', en: 'Usage log', hintZh: 'argo 侧 JSONL 使用账本,默认开', hintEn: 'argo JSONL usage ledger, on by default' },
89
+ { name: 'ARGO_ENGINE_HTTP_CLIENT', kind: 'bool', group: 'misc', def: true, zh: 'HttpClient 连接池', en: 'HttpClient pool', hintZh: '引擎 HTTP 走连接池,默认开;=0 回退 urllib(诊断用)', hintEn: 'Pooled engine HTTP, on by default; =0 falls back to urllib' },
90
+ { name: 'ARGO_ADMISSION_TTL_S', kind: 'num', group: 'misc', def: 1, min: 0, max: 60, step: 0.5, zh: '准入记忆 TTL(秒)', en: 'Admission memo TTL (s)', hintZh: '引擎准入状态记忆时长,默认 1;0 每次现查', hintEn: 'Admission memo window, default 1; 0 = always fresh' },
91
+ { name: 'ARGO_CONFIG_STAMP_TTL_S', kind: 'num', group: 'misc', def: 1, min: 0, max: 60, step: 0.5, zh: '配置戳记忆 TTL(秒)', en: 'Config stamp memo TTL (s)', hintZh: '外部引擎扫描记忆时长,默认 1;0 每次现扫', hintEn: 'External engine scan memo window, default 1; 0 = always rescan' },
92
+ ])
93
+
94
+ export const ARGO_ENV_NAMES = new Set(ARGO_ENV_SPECS.map(spec => spec.name))
95
+
96
+ export function parseArgoEnvLine(line) {
97
+ const eq = line.indexOf('=')
98
+ if (eq <= 0) return null
99
+ const name = line.slice(0, eq).trim()
100
+ const value = line.slice(eq + 1)
101
+ if (!CREDENTIAL_REF_PATTERN.test(name)) return null
102
+ return { name, value }
103
+ }
104
+
105
+ export function argoEnvOverlay(config = activeConfig) {
106
+ const overlay = {}
107
+ for (const entry of asStringArray(config?.argoEnv, 64)) {
108
+ const parsed = parseArgoEnvLine(entry)
109
+ if (parsed === null || !ARGO_ENV_NAMES.has(parsed.name)) continue
110
+ overlay[parsed.name] = parsed.value
111
+ }
112
+ return overlay
113
+ }
114
+
115
+ export async function resolveArgoEnv(config, options = {}) {
116
+ const cfg = config ?? activeConfig
117
+ const overlay = argoEnvOverlay(cfg)
118
+ const refs = asStringArray(cfg?.keyRefs, 20)
119
+ if (refs.length > 0) {
120
+ const provider = options.credentials ?? cfg?.credentials ?? hostCredentials
121
+ if (provider !== undefined) {
122
+ for (const ref of refs) {
123
+ try {
124
+ const resolved = await provider.resolve(ref)
125
+ if (typeof resolved?.value === "string" && resolved.value !== "") {
126
+ overlay[ref] = resolved.value
127
+ }
128
+ } catch { /* ignore */ }
129
+ }
130
+ }
131
+ }
132
+ return Object.keys(overlay).length > 0 ? { ...process.env, ...overlay } : undefined
133
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taxueseek/argo-dsh",
3
- "version": "2.11.2",
3
+ "version": "2.12.0",
4
4
  "description": "Argo 阿尔戈 — DSH plugin:argo 原生搜索/抓取工具 + web_search seam + wide_research 编排;自带设置页(接入/工具/API 密钥/研究/高级);argo MCP 19 工具全量面按需挂载。安装:dsh plugin --profile web add @taxueseek/argo-dsh(或从 GitHub main 装:dsh plugin --profile web add \"github:taxueseek/argo#main&path:packages/dsh-plugin\")",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -8,6 +8,7 @@
8
8
  "exports": {
9
9
  ".": "./dsh/index.js",
10
10
  "./dsh": "./dsh/index.js",
11
+ "./specs": "./dsh/specs.js",
11
12
  "./client": "./dsh/client.js",
12
13
  "./cordis.patch.yml": "./cordis.patch.yml",
13
14
  "./package.json": "./package.json"
@@ -26,13 +27,20 @@
26
27
  "inject": [
27
28
  "@deepseek-ai/dsh-client-ui-settings"
28
29
  ]
30
+ },
31
+ "compatibility": {
32
+ "dsh": "^0.2.0-rc.1 || ^0.2.1 || ^0.2.2-0",
33
+ "dshReleases": {
34
+ "0.2.2-rc.1": "compatible"
35
+ }
29
36
  }
30
37
  },
31
38
  "engines": {
32
39
  "node": ">=18"
33
40
  },
34
41
  "scripts": {
35
- "check": "node --check dsh/index.js && node --check dsh/runner.js && node --check dsh/wide-research.js && node --check dsh/diagnostics.js && node --check dsh/client.js",
42
+ "check": "node --check dsh/index.js && node --check dsh/specs.js && node --check dsh/runner.js && node --check dsh/wide-research.js && node --check dsh/diagnostics.js && node --check dsh/client.js",
43
+ "typecheck": "npm run check",
36
44
  "test": "node --test test/*.test.js"
37
45
  }
38
46
  }
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict'
3
3
  import { readFileSync } from 'node:fs'
4
4
  import vm from 'node:vm'
5
5
  import { NATIVE_TOOLS } from '../dsh/native-tools.mjs'
6
- import { ARGO_ENV_SPECS } from '../dsh/index.js'
6
+ import { ARGO_ENV_SPECS } from '../dsh/specs.js'
7
7
 
8
8
  /** 在最小沙箱里执行 lazy-CJS bundle,返回 ModuleLoader 收到的定义。 */
9
9
  function loadBundle() {
@@ -130,11 +130,11 @@ test('client TOOLS mirror native-tools.mjs (drift gate)', () => {
130
130
  })
131
131
 
132
132
  test('client ENGINE_TOGGLES mirror ARGO_ENV_SPECS (drift gate)', () => {
133
- // 面板引擎开关与 index.js 白名单同一份名单:名字、双语标签、数值域都要对得上。
133
+ // 面板引擎开关与 specs.js 白名单同一份名单:名字、双语标签、数值域都要对得上。
134
134
  const mod = factory(loadBundle())
135
135
  const specNames = ARGO_ENV_SPECS.map((spec) => spec.name).sort()
136
136
  const toggleNames = [...mod.ENGINE_TOGGLES].map((spec) => spec.name).sort()
137
- assert.deepEqual(toggleNames, specNames, '面板 ENGINE_TOGGLES 与 index.js ARGO_ENV_SPECS 漂移,请同步两边')
137
+ assert.deepEqual(toggleNames, specNames, '面板 ENGINE_TOGGLES 与 specs.js ARGO_ENV_SPECS 漂移,请同步两边')
138
138
  const specByName = new Map(ARGO_ENV_SPECS.map((spec) => [spec.name, spec]))
139
139
  for (const toggle of mod.ENGINE_TOGGLES) {
140
140
  const spec = specByName.get(toggle.name)
@@ -289,7 +289,7 @@ test('ArgoPanel renders every tab without undefined references', () => {
289
289
  })
290
290
 
291
291
  test('engines tab renders a control for every ENGINE_TOGGLES switch (no invisible group)', () => {
292
- // 上面的 mirror 测试只核对「index.js 白名单 ↔ client.js 镜像」同名同字段,
292
+ // 上面的 mirror 测试只核对「specs.js 白名单 ↔ client.js 镜像」同名同字段,
293
293
  // 核对不到「这个 group 到底渲不渲染」。2026-10-21 实锤:`paid` 分组没进渲染
294
294
  // 清单,ARGO_PAID_SEARCH 与 ARGO_BUDGET_DEEPSEEK_SEARCH 在白名单、镜像、
295
295
  // 双语文案三处都齐全,面板上却完全不显示——用户配了预算却找不到入口,
@@ -1,6 +1,6 @@
1
1
  import { test } from 'node:test'
2
2
  import assert from 'node:assert/strict'
3
- import { getMcpPoolStats, resetMcpPool } from '../dsh/index.js'
3
+ import { getMcpPoolStats, resetMcpPool } from '../dsh/diagnostics.js'
4
4
 
5
5
  test('diagnostics: getMcpPoolStats returns pool status and active loads', () => {
6
6
  const dummyPool = [
@@ -3,7 +3,33 @@ import assert from 'node:assert/strict'
3
3
  import { mkdtempSync, writeFileSync, readFileSync, existsSync } from 'node:fs'
4
4
  import { tmpdir } from 'node:os'
5
5
  import { join } from 'node:path'
6
- import { normalizeTracks, stageTracks, evaluateGates, normalizeSource, normalizeSourceUrl, mapArgoToWebResult, buildLocalSources, parseJsonArray, parseJsonObject, extractValues, resolveNativeSpawn, resolveArgoEnv, makeNativeTool, buildChildToolFilters, apply, nativeViaMcpPool, disposeSharedMcp, startStructured, providerSupportsStructured, fetchViaArgo, mapArgoToWebFetch, classifyFetchError, runNativeCall, searchViaArgoMCP } from '../dsh/index.js'
6
+ import { apply } from '../dsh/index.js'
7
+ import { buildChildToolFilters, resolveArgoEnv } from '../dsh/specs.js'
8
+ import {
9
+ normalizeTracks,
10
+ stageTracks,
11
+ evaluateGates,
12
+ normalizeSource,
13
+ normalizeSourceUrl,
14
+ buildLocalSources,
15
+ parseJsonArray,
16
+ parseJsonObject,
17
+ extractValues,
18
+ startStructured,
19
+ providerSupportsStructured,
20
+ } from '../dsh/wide-research.js'
21
+ import {
22
+ mapArgoToWebResult,
23
+ resolveNativeSpawn,
24
+ makeNativeTool,
25
+ nativeViaMcpPool,
26
+ disposeSharedMcp,
27
+ fetchViaArgo,
28
+ mapArgoToWebFetch,
29
+ classifyFetchError,
30
+ runNativeCall,
31
+ searchViaArgoMCP,
32
+ } from '../dsh/runner.js'
7
33
  import { NATIVE_TOOLS } from '../dsh/native-tools.mjs'
8
34
 
9
35
  test('mapArgoToWebResult maps compact argo payload to web sources', () => {
@@ -179,7 +205,7 @@ test('persistReport writes to <dir>/<ts>-<slug>.md and returns absolute path', a
179
205
  const { mkdtemp, readFile } = await import('node:fs/promises')
180
206
  const { tmpdir } = await import('node:os')
181
207
  const { join } = await import('node:path')
182
- const { persistReport } = await import('../dsh/index.js')
208
+ const { persistReport } = await import('../dsh/wide-research.js')
183
209
  const dir = await mkdtemp(join(tmpdir(), 'argo-report-'))
184
210
  const file = await persistReport(dir, '测试 报告?问题', '# Report\ncontent')
185
211
  assert.ok(file.startsWith(dir))
@@ -82,6 +82,43 @@ def quality_factor(avg_quality: float | None, sum_quality: float | int | None) -
82
82
  min(QUALITY_FACTOR_MAX, 0.75 + 0.5 * avg))
83
83
 
84
84
 
85
+ def marginal_contribution(merged: list[dict] | None, k: int,
86
+ participants: list[str]) -> dict[str, float]:
87
+ """终榜边际贡献:每个参与引擎在融合后 top-k 里实际占了多少份额。
88
+
89
+ 为什么不用词面相关度:旧口径给每个引擎记 `result_relevance(query, res)`,
90
+ 五个源返回同一批结果时五个都拿高分——它奖励的是「看着相关」,不是
91
+ 「对最终答案有贡献」。这里改为覆盖博弈的 Shapley 值:top-k 每条结果
92
+ 价值 1,由 `consensus_engines` 里的引擎均分。独家结果整条归一个源,
93
+ 被五个源同时召回的结果每个源只分到 1/5,同质冗余源的分数因此自然下降。
94
+
95
+ 归一到「公平份额」:q = 0.5 × 份额占比 × 参与引擎数,截到 [0, 1]。恰好
96
+ 拿到公平份额(含单引擎查询)记 0.5,`quality_factor` 映射成 1.0,中性;
97
+ 两倍公平份额及以上记 1.0;没有一条进入 top-k 记 0.01(地板,原因见下)。两个源返回完全
98
+ 相同的结果时各记 0.5,冗余不加分。
99
+
100
+ `merged` 为空时返回 {}:结果被后置过滤清空不是任何源的责任,调用方
101
+ 据此记 None(不参与质量评分)。纯内存计算,O(k × 共识数)。
102
+ """
103
+ top = [r for r in (merged or [])[:max(int(k or 0), 1)] if isinstance(r, dict)]
104
+ names = [e for e in dict.fromkeys(participants or []) if e]
105
+ if not top or not names:
106
+ return {}
107
+ share = dict.fromkeys(names, 0.0)
108
+ for r in top:
109
+ cons = [e for e in dict.fromkeys(r.get("consensus_engines") or []) if e]
110
+ if not cons:
111
+ src = r.get("_engine") or r.get("source") or ""
112
+ cons = [src] if src else []
113
+ for e in cons:
114
+ if e in share:
115
+ share[e] += 1.0 / len(cons)
116
+ scale = 0.5 * len(names) / len(top)
117
+ # 地板 0.01 而不是 0:`quality_factor` 以 SUM(quality)>0 判「有无质量数据」,
118
+ # 一个从不进终榜的源若全记 0,会被当成「无数据」拿中性 1.0,反而逃过降权。
119
+ return {e: round(max(0.01, min(1.0, v * scale)), 4) for e, v in share.items()}
120
+
121
+
85
122
  def scenario_of(decision: dict | None) -> dict[str, str]:
86
123
  """从路由决策里抽 (domain, lang) 场景标签,供 record 分桶使用。
87
124
 
@@ -273,7 +310,7 @@ class AdaptiveLearner:
273
310
  " SUM(CASE WHEN empty = 0 THEN 1 ELSE 0 END), "
274
311
  " SUM(CASE WHEN empty = 0 THEN success ELSE 0 END), "
275
312
  " AVG(latency_ms), AVG(cost), "
276
- " AVG(quality), SUM(quality), MAX(created_at) "
313
+ " AVG(CASE WHEN empty = 0 THEN quality END), SUM(quality), MAX(created_at) "
277
314
  "FROM engine_perf WHERE engine = ? AND created_at > ?",
278
315
  (engine, cutoff),
279
316
  ).fetchone()
@@ -285,35 +322,41 @@ class AdaptiveLearner:
285
322
  " SUM(CASE WHEN empty = 0 THEN 1 ELSE 0 END), "
286
323
  " SUM(CASE WHEN empty = 0 THEN success ELSE 0 END), "
287
324
  " AVG(latency_ms), AVG(cost), "
288
- " AVG(quality), SUM(quality), MAX(created_at) "
325
+ " AVG(CASE WHEN empty = 0 THEN quality END), SUM(quality), MAX(created_at), "
326
+ " SUM(CASE WHEN empty = 1 THEN 1 ELSE 0 END) "
289
327
  "FROM engine_perf WHERE engine = ? AND created_at > ? "
290
328
  "AND domain = ? AND lang = ?",
291
329
  (engine, cutoff, domain, lang),
292
330
  ).fetchone()
293
331
 
332
+ @staticmethod
333
+ def heb_ucb_score(score: float, samples: int,
334
+ floor: float = 0.15, c_ucb: float = 0.35) -> float:
335
+ """HEB-DCB 经验贝叶斯置信上界(防小样本垂直源饿死)。
336
+
337
+ 对尚未跌破死源地板(score >= floor)的低样本引擎补偿后验标准差:
338
+ UCB(s, n) = s + c_ucb * sqrt(max(s*(1-s), 0.04) / (n + 3))
339
+ 随样本数 n 增长探索奖励以 1/sqrt(n) 自然衰减,死源(< floor)不获补偿。
340
+ """
341
+ if score < floor:
342
+ return score
343
+ import math
344
+ n = max(0, int(samples or 0))
345
+ var = max(score * (1.0 - score), 0.04)
346
+ return round(min(1.0, score + c_ucb * math.sqrt(var / (n + 3.0))), 4)
347
+
294
348
  def get_score(self, engine: str, domain: str | None = None,
295
349
  lang: str | None = None, purpose: str = "daily") -> float:
296
350
  """获取引擎的综合推荐分数(0.0 ~ 1.0)。
297
351
 
298
- **只按「有明确结果」的调用算成功率**(`empty=0`)。
299
-
300
- 为什么要把空结果排除:分数被用来决定「这个源该不该继续用」,
301
- 而「这次查询它没东西」说明的是**查询与源不匹配**,不是源坏了。
302
- 两者混在一起会误杀:实测 github 在窗口内 63 次调用、成功率 6%,
303
- 失败归因全是 empty——它被用来回答各种查询,只有少数落进它的覆盖范围;
304
- 而它却在 `local_code` / `package_search` 这些**声明要用它**的域里
305
- 因分数低于 0.3 被整个剔除。同类还有 wikipedia(0.17)、
306
- openalex(0.29)、hackernews(0.10)、twitter(0.17)、open_library(0.17)。
352
+ **全局层**(不传 domain/lang):只按 `empty=0` 算成功率,防止垂直源
353
+ 被跨域无召回查询误杀。
307
354
 
308
- 延迟与成本仍按全部调用统计——空结果也是真实开销。
355
+ **场景层**(给 `domain` / `lang`):全局分 × 桶内健康度收缩 × 场景
356
+ 召回率,见 `_blend_bucket`。某源在特定场景持续空结果只压低该场景分。
309
357
 
310
- **场景分桶**(2026-10-24):给 `domain` / `lang` 时,按 (engine, domain,
311
- lang) 聚合出「桶分」,与全局分加权融合(桶样本 <3 时权重 0.3,≥3 时 0.5)。
312
- 这让「引擎在 A 域强、B 域弱」可表达,新引擎也能在建议域里被更快识别。
313
- 桶为空时回退全局分——旧调用方(不传 domain/lang)行为逐位不变。
314
-
315
- `purpose`:daily(默认)沿用 2s 延迟悬崖;research 抬到 8s,见
316
- `_score_from_row`。默认值保证旧调用方逐位不变。
358
+ `quality` 列自 2026-11-07 起记的是终榜边际贡献(`marginal_contribution`),
359
+ 不再是词面相关度。
317
360
  """
318
361
  return self.get_score_with_samples(
319
362
  engine, domain, lang, purpose)[0]
@@ -325,7 +368,7 @@ class AdaptiveLearner:
325
368
 
326
369
  选源层需要区分「0.5 分是因为没数据」与「0.5 分是因为确实平庸」:
327
370
  对无样本的源,实测先验应当做主,而不是被自适应默认分稀释。样本数
328
- 取场景桶的 judged(桶为空时取全局 judged)。
371
+ 取场景桶的有效观测数(桶为空时取全局 judged)。
329
372
  """
330
373
  key = (engine, domain or "", lang or "", purpose)
331
374
  now = time.time()
@@ -341,17 +384,48 @@ class AdaptiveLearner:
341
384
  score = self._score_from_row(grow, purpose)
342
385
  samples = int((grow[1] if grow else 0) or 0)
343
386
  if domain or lang:
344
- brow = self._bucket_row(engine, domain or "", lang or "")
345
- b_judged = int(brow[1] or 0)
346
- if b_judged > 0:
347
- b_score = self._score_from_row(brow, purpose)
348
- w = 0.5 if b_judged >= 3 else 0.3
349
- score = round((1 - w) * score + w * b_score, 4)
350
- samples = b_judged
387
+ score, samples = self._blend_bucket(
388
+ score, samples,
389
+ self._bucket_row(engine, domain or "", lang or ""), purpose)
351
390
 
352
391
  self._score_cache[key] = (score, samples, now + self.SCORE_CACHE_TTL)
353
392
  return score, samples
354
393
 
394
+ # 场景桶向全局分收缩的先验强度:桶内有效观测 n 条时桶的权重为 n/(n+2)。
395
+ # n=1 → 0.33,n=3 → 0.6,n=6 → 0.75,样本越多越信桶,无需分段常数。
396
+ BUCKET_PRIOR_N = 2.0
397
+ # 场景召回的 Beta 先验:未观测时召回率视为 1(不先验地惩罚任何源)。
398
+ RECALL_PRIOR_OK = 2.0
399
+
400
+ def _blend_bucket(self, g_score: float, g_samples: int, brow,
401
+ purpose: str) -> tuple[float, int]:
402
+ """场景桶分 = 健康度 H × 场景召回率 R,两个因子各自做经验贝叶斯收缩。
403
+
404
+ - H:桶内有判定样本(非空结果)时,按 `BUCKET_PRIOR_N` 向全局分收缩;
405
+ 没有判定样本时 H 就是全局分。
406
+ - R:Beta 后验均值 (a + 有结果次数) / (a + 有结果次数 + 空结果次数)。
407
+ 某源在这个 (domain, lang) 下持续空结果,只压低这一桶,全局分不动。
408
+
409
+ 替换此前的三条分支(w=0.3/0.5 固定权重、空结果另走 rho_recall 并把
410
+ 基准截到 0.5、w 封顶 0.75)。桶完全无行时 H=全局分、R=1,与只看全局
411
+ 逐位一致。
412
+ """
413
+ if not brow:
414
+ return g_score, g_samples
415
+ b_judged = int(brow[1] or 0)
416
+ b_ok = int(brow[2] or 0)
417
+ b_empty = int(brow[8] or 0) if len(brow) > 8 else 0
418
+ if b_judged + b_empty == 0:
419
+ return g_score, g_samples
420
+ health = g_score
421
+ if b_judged > 0:
422
+ b_health = self._score_from_row(brow[:8], purpose)
423
+ w = b_judged / (b_judged + self.BUCKET_PRIOR_N)
424
+ health = (1 - w) * g_score + w * b_health
425
+ a = self.RECALL_PRIOR_OK
426
+ recall = (a + b_ok) / (a + b_ok + b_empty)
427
+ return round(health * recall, 4), b_judged + b_empty
428
+
355
429
  def get_ranking(self) -> list[tuple[str, float]]:
356
430
  """获取所有引擎的推荐排名(降序)。空结果的排除口径同 `get_score`。"""
357
431
  with self._lock: