argo-search 2.15.0 → 2.17.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 (183) hide show
  1. package/AGENTS.md +3 -1
  2. package/README.es.md +32 -5
  3. package/README.ja.md +32 -5
  4. package/README.ko.md +32 -5
  5. package/README.md +73 -19
  6. package/README.zh.md +73 -19
  7. package/SKILL.md +7 -7
  8. package/assets/readme/counts.json +1 -1
  9. package/assets/readme/hero.svg +3 -3
  10. package/assets/readme/hero.template.svg +121 -0
  11. package/assets/readme/proof-routes.svg +17 -16
  12. package/backends/domain_profiles.json +222 -24
  13. package/backends/engine_registry.yaml +26 -2
  14. package/backends/env_passthrough.txt +2 -0
  15. package/backends/quota_profiles.json +23 -3
  16. package/bin/argo +3 -0
  17. package/config.yaml +16 -0
  18. package/docs/CHANGELOG.md +31 -0
  19. package/docs/COMMIT_STANDARD.md +10 -0
  20. package/docs/ENGINE_CATALOG.md +40 -37
  21. package/docs/MCP_SETUP.md +9 -0
  22. package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
  23. package/docs/RELEASE_NOTES_v2.17.0.md +64 -0
  24. package/docs/RELEASING.md +1 -1
  25. package/engines/specs/archive_org.yaml +1 -1
  26. package/engines/specs/carbon_intensity.yaml +1 -1
  27. package/engines/specs/crates.yaml +1 -1
  28. package/engines/specs/crossref.yaml +6 -2
  29. package/engines/specs/crt_sh.yaml +1 -1
  30. package/engines/specs/dblp.yaml +1 -1
  31. package/engines/specs/devto.yaml +1 -1
  32. package/engines/specs/docker_hub.yaml +1 -1
  33. package/engines/specs/europepmc.yaml +1 -1
  34. package/engines/specs/fxtwitter.yaml +1 -1
  35. package/engines/specs/gbfs_nyc.yaml +1 -1
  36. package/engines/specs/gleif.yaml +1 -1
  37. package/engines/specs/gov_regulations.yaml +1 -1
  38. package/engines/specs/hackernews.yaml +2 -0
  39. package/engines/specs/helve.yaml +49 -0
  40. package/engines/specs/hf_datasets.yaml +1 -1
  41. package/engines/specs/hf_papers.yaml +2 -0
  42. package/engines/specs/huggingface.yaml +1 -1
  43. package/engines/specs/keenable.yaml +7 -1
  44. package/engines/specs/linux_do.yaml +63 -0
  45. package/engines/specs/local_crossref.yaml +3 -1
  46. package/engines/specs/local_github.yaml +1 -1
  47. package/engines/specs/local_npm.yaml +6 -0
  48. package/engines/specs/local_openstreetmap.yaml +1 -1
  49. package/engines/specs/maven.yaml +1 -1
  50. package/engines/specs/mdn.yaml +1 -1
  51. package/engines/specs/musicbrainz.yaml +1 -1
  52. package/engines/specs/nasa_images.yaml +1 -1
  53. package/engines/specs/nhtsa_vpic.yaml +6 -3
  54. package/engines/specs/npm.yaml +1 -1
  55. package/engines/specs/nuget.yaml +1 -1
  56. package/engines/specs/nvd.yaml +1 -1
  57. package/engines/specs/openalex.yaml +13 -4
  58. package/engines/specs/openreview.yaml +1 -1
  59. package/engines/specs/polymarket.yaml +1 -1
  60. package/engines/specs/sec_edgar.yaml +1 -1
  61. package/engines/specs/steam.yaml +1 -1
  62. package/engines/specs/vam.yaml +1 -1
  63. package/engines/specs/wikidata.yaml +1 -1
  64. package/engines/specs/wikipedia.yaml +1 -1
  65. package/engines/specs/zhihu_hot_app.yaml +1 -1
  66. package/package.json +3 -1
  67. package/packages/dsh-plugin/README.md +5 -2
  68. package/packages/dsh-plugin/cordis.patch.yml +4 -1
  69. package/packages/dsh-plugin/dsh/client.js +69 -74
  70. package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
  71. package/packages/dsh-plugin/dsh/index.js +115 -21
  72. package/packages/dsh-plugin/dsh/route-guard.js +95 -0
  73. package/packages/dsh-plugin/dsh/runner.js +50 -7
  74. package/packages/dsh-plugin/dsh/wide-research.js +20 -18
  75. package/packages/dsh-plugin/dsh/workbench-client.js +895 -0
  76. package/packages/dsh-plugin/dsh/workbench-io.js +163 -0
  77. package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
  78. package/packages/dsh-plugin/dsh/workbench-search.js +385 -0
  79. package/packages/dsh-plugin/dsh/workbench-suggestions.js +460 -0
  80. package/packages/dsh-plugin/dsh/workbench.js +703 -0
  81. package/packages/dsh-plugin/icon.svg +23 -0
  82. package/packages/dsh-plugin/package.json +6 -3
  83. package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
  84. package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
  85. package/packages/dsh-plugin/test/client.test.js +26 -0
  86. package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
  87. package/packages/dsh-plugin/test/index.test.js +150 -1
  88. package/packages/dsh-plugin/test/workbench-concurrency.test.js +98 -0
  89. package/packages/dsh-plugin/test/workbench.test.js +420 -0
  90. package/scripts/adaptive.py +13 -11
  91. package/scripts/argo_paths.py +2 -2
  92. package/scripts/badcase_ledger.py +9 -0
  93. package/scripts/browser_auth.py +178 -4
  94. package/scripts/cache.py +69 -70
  95. package/scripts/check_commit_report.py +46 -0
  96. package/scripts/chrome_cdp.py +71 -0
  97. package/scripts/circuit_breaker.py +91 -13
  98. package/scripts/config_cache.py +23 -10
  99. package/scripts/daemon.py +14 -2
  100. package/scripts/engine_add.py +45 -0
  101. package/scripts/engine_dispatch.py +32 -49
  102. package/scripts/engine_env.py +13 -4
  103. package/scripts/engine_failure.py +33 -0
  104. package/scripts/engine_fingerprint.py +114 -0
  105. package/scripts/engine_health.py +130 -0
  106. package/scripts/engine_states.py +50 -0
  107. package/scripts/engines_base.py +31 -19
  108. package/scripts/engines_builders_archive.py +4 -3
  109. package/scripts/engines_builders_batch11.py +2 -1
  110. package/scripts/engines_builders_batch13.py +4 -3
  111. package/scripts/engines_builders_batch14.py +2 -1
  112. package/scripts/engines_builders_batch15.py +2 -1
  113. package/scripts/engines_builders_batch9.py +2 -2
  114. package/scripts/engines_builders_cn.py +7 -7
  115. package/scripts/engines_builders_data.py +12 -11
  116. package/scripts/engines_builders_data_macro.py +5 -4
  117. package/scripts/engines_builders_dsh.py +2 -1
  118. package/scripts/engines_builders_feeds.py +34 -19
  119. package/scripts/engines_builders_finance.py +2 -1
  120. package/scripts/engines_builders_intl.py +3 -2
  121. package/scripts/engines_builders_media.py +59 -12
  122. package/scripts/engines_builders_science.py +8 -7
  123. package/scripts/engines_builders_search.py +19 -8
  124. package/scripts/engines_builders_skill.py +2 -1
  125. package/scripts/engines_builders_tech.py +19 -19
  126. package/scripts/engines_builders_weather.py +9 -4
  127. package/scripts/engines_fields.py +23 -0
  128. package/scripts/engines_http.py +50 -1
  129. package/scripts/engines_mcp.py +28 -6
  130. package/scripts/evidence_grounding.py +182 -0
  131. package/scripts/evidence_loop.py +15 -1
  132. package/scripts/extend_route_labels.py +6 -0
  133. package/scripts/fetch_browser.py +25 -10
  134. package/scripts/fetch_jina.py +98 -0
  135. package/scripts/fetch_v3.py +52 -93
  136. package/scripts/gate_manifest_check.py +75 -0
  137. package/scripts/gen_readme_art.py +264 -0
  138. package/scripts/image_vision/vision_probe +0 -0
  139. package/scripts/install.sh +2 -0
  140. package/scripts/matrix_search_eval.py +8 -10
  141. package/scripts/mcp_transport.py +33 -9
  142. package/scripts/numeric_verify.py +12 -2
  143. package/scripts/output_transparency.py +3 -0
  144. package/scripts/pre-commit +57 -8
  145. package/scripts/query_operators.py +229 -1
  146. package/scripts/quota.py +46 -63
  147. package/scripts/recovery.py +19 -16
  148. package/scripts/recovery_runner.py +29 -10
  149. package/scripts/redskill/redskill_engine.py +2 -1
  150. package/scripts/release.py +16 -1
  151. package/scripts/research_gates.py +85 -1
  152. package/scripts/route.py +8 -0
  153. package/scripts/route_combo.py +24 -3
  154. package/scripts/route_policy.py +1 -1
  155. package/scripts/search_attribution.py +20 -0
  156. package/scripts/search_entry.py +27 -0
  157. package/scripts/search_output.py +18 -7
  158. package/scripts/search_pipeline.py +3 -3
  159. package/scripts/semantic_evidence.py +20 -11
  160. package/scripts/serp_guard.py +13 -1
  161. package/scripts/settings_page.py +1 -0
  162. package/scripts/single_flight.py +1 -1
  163. package/scripts/social_engines/hackernews_engine.py +2 -1
  164. package/scripts/social_engines/reddit_engine.py +2 -1
  165. package/scripts/social_engines/zhihu_engine.py +2 -1
  166. package/scripts/source_audit.py +42 -7
  167. package/scripts/source_discovery.py +611 -0
  168. package/scripts/sync_backends.py +45 -0
  169. package/scripts/usage_log.py +24 -9
  170. package/scripts/watch.py +3 -3
  171. package/scripts/zhihu_quota.py +2 -1
  172. package/sub-skills/argo-wide-research/SKILL.md +7 -5
  173. package/sub-skills/ego-search/{SKILL.md → README.md} +24 -47
  174. package/sub-skills/ego-search/scripts/ego_search.py +195 -19
  175. package/sub-skills/ego-search/scripts/pacing.py +291 -0
  176. package/sub-skills/ego-search/scripts/quality.py +262 -6
  177. package/sub-skills/ego-search/scripts/runtime.py +7 -1
  178. package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
  179. package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
  180. package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
  181. package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
  182. package/sub-skills/local-search/engine_registry.py +32 -7
  183. package/sub-skills/local-seek/SKILL.md +20 -22
@@ -0,0 +1,385 @@
1
+ /*
2
+ * @taxueseek/argo-dsh — 工作台检索管线:模式规格、卡片归一、CLI 编排与 LLM 直流。
3
+ * 自 workbench.js 拆出以守 1000 行门禁(2026-11-21);HTTP 骨架与宿主 handler 留在 workbench.js。
4
+ */
5
+
6
+ import { homedir } from 'node:os'
7
+ import { join } from 'node:path'
8
+ import { DEFAULTS, stripBoundary } from './runner.js'
9
+ import { runArgoCli } from './workbench-io.js'
10
+ import { boundedMap } from './wide-research.js'
11
+
12
+ export const CITATION_RULE = [
13
+ '严格基于提供的检索证据回答,所有事实判断、数据与观点必须在句末使用方括号编号引用,例如 [1] 或 [2][3]。',
14
+ '严禁编造未出现在证据中的数字、链接或来源;如果证据不足或存在冲突,直接指出并并列呈现不同来源。',
15
+ '使用清晰的中文 Markdown 结构(小标题、要点列表或对比表格),先给核心结论,再展开细节。',
16
+ ].join('\n')
17
+
18
+ export const MODE_SPECS = {
19
+ general: { label: '全网搜索', searchArgs: { max_results: 12, verify: 2, depth: 'balanced' }, prompt: '当前模式为「全网搜索」:先用 2 到 3 句话给出直接结论,再用清晰小标题展开关键依据与延伸信息。' },
20
+ hotspot: { label: '热点分析', searchArgs: { max_results: 14, sort: 'newest', since: '14d', depth: 'balanced', verify: 2 }, socialSupplement: true, prompt: '当前模式为「热点分析」:按「一、核心结论与现状」「二、事件脉络」「三、核心争议与各方立场」「四、影响与后续关注点」组织输出。' },
21
+ verify: { label: '真假核验', searchArgs: { max_results: 12, verify: 5, depth: 'deep', mode: 'deep' }, prompt: '当前模式为「真假核验」:按「一、核验结论(明确给出可信度判断:可信 / 存疑 / 失实 / 证据不足)」「二、关键证据链(优先引用已核验正文)」「三、冲突点与核验边界」组织输出。' },
22
+ research: { label: '深度研究', searchArgs: { max_results: 16, verify: 5, depth: 'deep', mode: 'deep' }, prompt: '当前模式为「深度研究」:按「一、执行摘要」「二、多维拆解与关键发现」「三、数据与案例支撑」「四、风险、局限与待验证项」组织详尽研究报告。' },
23
+ compare: { label: '选型对比', searchArgs: { max_results: 14, verify: 3, depth: 'balanced' }, prompt: '当前模式为「选型对比」:按「一、选型结论与推荐」「二、核心维度对比表(Markdown 表格)」「三、各自优缺点与适用人群」「四、替代方案与踩坑提示」组织输出。' },
24
+ academic: { label: '学术文献', searchArgs: { max_results: 14, domain: 'academic', depth: 'deep', mode: 'deep', verify: 3 }, prompt: '当前模式为「学术文献」:按「一、核心研究结论与共识」「二、代表性论文与方法拆解」「三、实验证据与关键数据」「四、局限性与延伸方向」组织输出。' },
25
+ plugin: { label: '插件评测', searchArgs: { max_results: 14, domain: 'dsh_plugin_search', verify: 3, depth: 'balanced' }, socialSupplement: true, prompt: '当前模式为「插件评测」:按「一、是否值得安装(结论)」「二、核心能力与亮点」「三、社区真实反馈与局限」「四、替代方案与安装配置注意」组织输出。' },
26
+ local: { label: '本机检索', searchArgs: { max_results: 16 }, prompt: '当前模式为「本机检索」:基于本机文件与代码命中证据回答,标明文件路径、行号与上下文关联,禁止编造未命中的本地文件。' },
27
+ }
28
+
29
+ export const MODES = new Set(Object.keys(MODE_SPECS))
30
+ export const MODE_LABELS = Object.fromEntries(Object.entries(MODE_SPECS).map(([k, v]) => [k, v.label]))
31
+
32
+ function extractDomain(url) {
33
+ try {
34
+ return new URL(url).hostname.replace(/^www\./i, '')
35
+ } catch {
36
+ return ''
37
+ }
38
+ }
39
+
40
+ export function normalizeCandidates(payload) {
41
+ const rawList = Array.isArray(payload?.results) ? payload.results : []
42
+ const seen = new Set()
43
+ const cards = []
44
+ for (const item of rawList) {
45
+ if (!item || typeof item.url !== 'string' || !item.url.startsWith('http')) continue
46
+ const key = item.url.trim()
47
+ if (seen.has(key)) continue
48
+ seen.add(key)
49
+ const index = cards.length + 1
50
+ const title = stripBoundary(item.title) || key
51
+ const snippet = stripBoundary(item.snippet || item.content || '') || ''
52
+ const verifiedText = stripBoundary(item.verified_excerpt || item.fetched_excerpt || '') || ''
53
+ const source = item.engine || item.source || item.provider || 'web'
54
+ cards.push({
55
+ id: `c${index}`,
56
+ index,
57
+ title,
58
+ url: key,
59
+ domain: extractDomain(key),
60
+ source,
61
+ snippet,
62
+ verifiedText,
63
+ verified: Boolean(item.verified || verifiedText),
64
+ credibility: typeof item.credibility_fast === 'number'
65
+ ? item.credibility_fast
66
+ : (typeof item.credibility === 'number' ? item.credibility : null),
67
+ publishedAt: item.published_at || item.publishedAt || item.date || '',
68
+ })
69
+ if (cards.length >= 16) break
70
+ }
71
+ return cards
72
+ }
73
+
74
+ export function buildSystemPrompt(mode) {
75
+ const spec = MODE_SPECS[mode] || MODE_SPECS.general
76
+ return `${CITATION_RULE}\n${spec.prompt}`
77
+ }
78
+
79
+ export function normalizeLocalCards(payload) {
80
+ const rawList = Array.isArray(payload?.matches)
81
+ ? payload.matches
82
+ : (Array.isArray(payload?.results) ? payload.results : [])
83
+ const seen = new Set()
84
+ const cards = []
85
+ for (const item of rawList) {
86
+ const filePath = String(item?.path || item?.file || item?.url || '').trim()
87
+ if (!filePath) continue
88
+ const line = item?.line ? `:${item.line}` : ''
89
+ const dedupKey = `${filePath}${line}`
90
+ if (seen.has(dedupKey)) continue
91
+ seen.add(dedupKey)
92
+ const index = cards.length + 1
93
+ const snippet = stripBoundary(item?.snippet || item?.text || item?.preview || (Array.isArray(item?.lines) ? item.lines.join('\n') : '')) || ''
94
+ cards.push({
95
+ id: `c${index}`,
96
+ index,
97
+ title: `${filePath.split('/').slice(-2).join('/')}${line}`,
98
+ url: filePath.startsWith('file://') ? filePath : `file://${filePath}`,
99
+ domain: 'local-seek',
100
+ source: 'local-seek',
101
+ snippet,
102
+ verifiedText: '',
103
+ verified: true,
104
+ credibility: 1,
105
+ publishedAt: item?.mtime || '',
106
+ })
107
+ if (cards.length >= 16) break
108
+ }
109
+ return cards
110
+ }
111
+
112
+ export function buildEvidenceContext(cards, maxChars = 14000) {
113
+ const lines = []
114
+ let used = 0
115
+ for (const c of cards) {
116
+ if (!c || typeof c !== 'object') continue
117
+ const body = c.verifiedText || c.snippet || '(无摘要)'
118
+ const block = [
119
+ `[${c.index}] 标题:${c.title}`,
120
+ `来源:${c.source} (${c.domain})${c.publishedAt ? ` · 时间:${c.publishedAt}` : ''}${c.verified ? ' · [已核验正文]' : ''}`,
121
+ `链接:${c.url}`,
122
+ `内容:${body.slice(0, 900)}`,
123
+ ].join('\n')
124
+ if (used + block.length > maxChars) break
125
+ lines.push(block)
126
+ used += block.length
127
+ }
128
+ return lines.join('\n\n')
129
+ }
130
+
131
+ export function buildFallbackSummary(query, mode, cards, failure = null) {
132
+ const label = MODE_LABELS[mode] || '全网综合'
133
+ if (cards.length === 0) {
134
+ return `### 未检索到相关结果\n\n针对「${query}」在 **${label}** 模式下未命中有效网页结果,建议精简关键词或点击右上角「强制刷新」重试。`
135
+ }
136
+ const rows = cards.slice(0, 8).map((c) => {
137
+ const text = (c.verifiedText || c.snippet || '').slice(0, 180).replace(/\n+/g, ' ')
138
+ return `- **${c.title}** [${c.index}](${c.domain || c.source})\n ${text || '点击右侧卡片查看原文'}`
139
+ })
140
+ const hasRealFailure = failure && failure.reason && failure.reason !== 'no_model'
141
+ const header = hasRealFailure
142
+ ? `### ${label} · 聚合检索结果(模型调用未完成,已切回直出视图)\n\n默认模型(\`${failure.model || 'unknown'}\`)暂不可用:${failure.message || failure.reason}。已为你整理最相关的 ${cards.length} 条多源证据,可直接在右侧核对原文:`
143
+ : `### ${label} · 聚合检索结果(零模型直出模式)\n\n当前宿主未配置可用默认模型,已为你整理最相关的 ${cards.length} 条多源证据,可直接在右侧核对原文:`
144
+ return `${header}\n\n${rows.join('\n\n')}`
145
+ }
146
+
147
+ export function mergeDedupCards(lists, maxCards = 16) {
148
+ const seen = new Set()
149
+ const merged = []
150
+ for (const list of lists) {
151
+ for (const card of list || []) {
152
+ if (!card?.url || seen.has(card.url)) continue
153
+ seen.add(card.url)
154
+ merged.push({ ...card, id: `c${merged.length + 1}`, index: merged.length + 1 })
155
+ if (merged.length >= maxCards) return merged
156
+ }
157
+ }
158
+ return merged
159
+ }
160
+
161
+ // 本机检索根目录唯一出口:callLocalSeek 与本机模式建议词必须同源——
162
+ // 旧版建议词读宿主 cwd、实际搜索另一路径,点了搜不到(2026-11-21 审计)
163
+ export function resolveLocalSearchPath(config) {
164
+ return config?.localSearchPath || process.env.ARGO_LOCAL_SEARCH_PATH || join(homedir(), 'Documents')
165
+ }
166
+
167
+ // track 成败真章:payload 缺失或带 errors 即失败。旧版恒注入
168
+ // completedTracks/failedTracks: 0,no_completed_tracks、all_tracks_failed、
169
+ // partial_track_failure 三类门禁永久失效(2026-11-21 审计:与热榜假成功
170
+ // 同根因——写章条件与读章消费不对齐,凡盖章处必须有契约对拍)。
171
+ export function summarizeTrackRuns(trackRuns) {
172
+ const total = trackRuns.length
173
+ const failed = trackRuns.filter(r => r.payload === null || r.payload === undefined
174
+ || (Array.isArray(r.payload.errors) && r.payload.errors.length > 0)).length
175
+ return { total, completed: total - failed, failed }
176
+ }
177
+
178
+ export async function callLocalSeek(config, env, query, maxResults = 16, signal) {
179
+ const searchPath = resolveLocalSearchPath(config)
180
+ try {
181
+ const payload = await runArgoCli(
182
+ ['seek', '--path', searchPath, '--json', '--max', String(Math.min(20, Math.max(1, maxResults))), '--', query],
183
+ { env, timeoutMs: 15000, signal },
184
+ )
185
+ return { payload, cards: normalizeLocalCards(payload) }
186
+ } catch (err) {
187
+ return { payload: { errors: [String(err?.message ?? err)] }, cards: [] }
188
+ }
189
+ }
190
+
191
+ export async function callArgoSearch(config, env, query, mode, refresh, signal, tracks = null) {
192
+ if (mode === 'local') {
193
+ return callLocalSeek(config, env, query, MODE_SPECS.local.searchArgs.max_results, signal)
194
+ }
195
+
196
+ const timeoutMs = mode === 'research'
197
+ ? Math.max(config.searchTimeoutMs ?? 60000, 90000)
198
+ : (config.searchTimeoutMs ?? DEFAULTS.searchTimeoutMs)
199
+
200
+ if (mode === 'research' && Array.isArray(tracks) && tracks.length > 1) {
201
+ const trackRuns = await boundedMap(tracks, 3, async (track) => {
202
+ const cliArgs = buildSearchCliArgs(track.question || query, 'research', refresh, { max_results: 10, verify: 3 })
203
+ try {
204
+ const payload = await runArgoCli(cliArgs, { env, timeoutMs, signal })
205
+ return { payload, cards: normalizeCandidates(payload) }
206
+ } catch (err) {
207
+ // 失败要留痕:旧 .catch(() => ({})) 把失败伪装成空 payload,
208
+ // track 成败从此不可判(2026-11-21 审计:假章同根因)
209
+ return { payload: null, error: String(err?.message ?? err), cards: [] }
210
+ }
211
+ })
212
+ return {
213
+ payload: trackRuns[0]?.payload || {},
214
+ cards: mergeDedupCards(trackRuns.map(r => r.cards), 16),
215
+ trackStats: summarizeTrackRuns(trackRuns),
216
+ }
217
+ }
218
+
219
+ const primaryTask = runArgoCli(buildSearchCliArgs(query, mode, refresh), { env, timeoutMs, signal })
220
+ .then(payload => ({ payload, cards: normalizeCandidates(payload) }))
221
+
222
+ // 热点分析与插件评测并行补充社区/社交域召回,避免单靠网页引擎错过一手讨论
223
+ const socialTask = MODE_SPECS[mode]?.socialSupplement
224
+ ? runArgoCli(buildSearchCliArgs(query, 'general', refresh, { domain: 'social', max_results: 6, verify: 0 }), { env, timeoutMs: Math.min(timeoutMs, 15000), signal })
225
+ .then(payload => normalizeCandidates(payload))
226
+ .catch(() => [])
227
+ : Promise.resolve([])
228
+
229
+ const [primary, socialCards] = await Promise.all([primaryTask, socialTask])
230
+ let combined = mergeDedupCards([primary.cards, socialCards], 16)
231
+
232
+ if (mode === 'plugin' && combined.length < 6) {
233
+ const fallbackPayload = await runArgoCli(
234
+ buildSearchCliArgs(`${query} 评测 替代`, 'general', refresh, { verify: 2 }),
235
+ { env, timeoutMs, signal },
236
+ ).catch(() => ({}))
237
+ combined = mergeDedupCards([combined, normalizeCandidates(fallbackPayload)], 16)
238
+ }
239
+
240
+ return { payload: primary.payload, cards: combined, trackStats: summarizeTrackRuns([{ payload: primary.payload }]) }
241
+ }
242
+
243
+ export async function runClarifyIfShort(query, mode, env, signal) {
244
+ if (mode === 'local' || query.length > 18) return null
245
+ try {
246
+ const data = await runArgoCli(['clarify', '--json', '--', query], { env, timeoutMs: 3000, signal })
247
+ if (!data || (!data.ambiguities?.length && !data.routing?.explanation)) return null
248
+ return {
249
+ ambiguities: data.ambiguities || [],
250
+ explanation: data.routing?.explanation || '',
251
+ recommendedStrategy: data.recommended_strategy || '',
252
+ }
253
+ } catch {
254
+ return null
255
+ }
256
+ }
257
+
258
+ export async function runEvidenceScoring(query, cards, env, signal) {
259
+ if (!cards.length) return { cards, evidenceSummary: null }
260
+ try {
261
+ const payload = await runArgoCli(
262
+ ['evidence', '--', query],
263
+ {
264
+ env,
265
+ stdin: {
266
+ results: cards.map(c => ({
267
+ title: c.title,
268
+ url: c.url,
269
+ source: c.source,
270
+ snippet: c.verifiedText || c.snippet,
271
+ published_at: c.publishedAt,
272
+ })),
273
+ },
274
+ timeoutMs: 5000,
275
+ signal,
276
+ },
277
+ )
278
+ const scored = Array.isArray(payload?.results) ? payload.results : []
279
+ const enriched = cards.map((c, idx) => {
280
+ const ev = scored[idx]?.credibility
281
+ if (!ev) return c
282
+ return {
283
+ ...c,
284
+ credibility: typeof ev.final === 'number' ? ev.final : c.credibility,
285
+ authorityTier: ev.authority?.tier || null,
286
+ authorityReason: ev.authority?.reason || '',
287
+ }
288
+ })
289
+ return {
290
+ cards: enriched,
291
+ evidenceSummary: {
292
+ crossValidation: payload?.cross_validation || null,
293
+ summary: payload?.summary || null,
294
+ },
295
+ }
296
+ } catch {
297
+ return { cards, evidenceSummary: null }
298
+ }
299
+ }
300
+
301
+ export async function streamLlmAnswer(ctx, { system, messages, signal, onDelta }) {
302
+ const llm = ctx.get?.('llm')
303
+ const modelService = ctx.get?.('agentDefaultModel')
304
+ if (!llm || !modelService) return { ok: false, reason: 'no_model' }
305
+
306
+ let selection
307
+ try {
308
+ selection = modelService.currentSelection?.()
309
+ } catch {
310
+ selection = null
311
+ }
312
+ if (!selection?.provider || !selection?.model) {
313
+ return { ok: false, reason: 'no_model' }
314
+ }
315
+
316
+ let text = ''
317
+ let usage = null
318
+ let finish = null
319
+ try {
320
+ const stream = llm.stream({
321
+ provider: selection.provider,
322
+ model: selection.model,
323
+ ...(selection.reasoningEffort ? { reasoningEffort: selection.reasoningEffort } : {}),
324
+ signal,
325
+ system,
326
+ messages,
327
+ })
328
+ for await (const chunk of stream) {
329
+ if (signal?.aborted) break
330
+ if (chunk?.type === 'text-delta' && typeof chunk.text === 'string') {
331
+ text += chunk.text
332
+ onDelta(chunk.text)
333
+ } else if (chunk?.type === 'usage') {
334
+ usage = chunk.usage
335
+ } else if (chunk?.type === 'finish') {
336
+ finish = chunk.reason
337
+ } else if (chunk?.type === 'error') {
338
+ const msg = chunk.error?.message || chunk.message || 'model stream error'
339
+ return { ok: false, reason: 'error', message: String(msg), text, model: `${selection.provider}/${selection.model}` }
340
+ }
341
+ }
342
+ if (finish && finish.kind !== 'stop') {
343
+ const msg = finish.failure?.message || finish.failure?.code || `finish=${finish.kind}`
344
+ console.warn(`[argo-workbench] llm finish=${finish.kind} model=${selection.provider}/${selection.model} msg=${msg}`)
345
+ return { ok: false, reason: finish.kind, message: String(msg), text, usage, finish, model: `${selection.provider}/${selection.model}` }
346
+ }
347
+ return { ok: true, text, usage, finish, model: `${selection.provider}/${selection.model}` }
348
+ } catch (err) {
349
+ return { ok: false, reason: err?.name === 'AbortError' ? 'aborted' : 'error', message: String(err?.message ?? err), text }
350
+ }
351
+ }
352
+
353
+ export function extractCitations(text, cards) {
354
+ const used = new Set()
355
+ const re = /\[(\d+)\]/g
356
+ let m
357
+ while ((m = re.exec(text)) !== null) {
358
+ const n = Number(m[1])
359
+ if (n >= 1 && n <= cards.length) used.add(n)
360
+ }
361
+ return {
362
+ citedIndices: [...used].sort((a, b) => a - b),
363
+ totalCards: cards.length,
364
+ }
365
+ }
366
+
367
+ // 供测试断言「flag 全部前置、query 经 `--` 分隔殿后」的参数形态
368
+ export function buildSearchCliArgs(query, mode, refresh = false, overrides = {}) {
369
+ const spec = MODE_SPECS[mode] || MODE_SPECS.general
370
+ const merged = { ...spec.searchArgs, ...overrides }
371
+ const args = ['search', '--json', '--envelope']
372
+ if (merged.max_results) args.push('-n', String(merged.max_results))
373
+ if (merged.depth) args.push('--depth', String(merged.depth))
374
+ if (merged.mode) args.push('--mode', String(merged.mode))
375
+ if (merged.domain) args.push('--domain', String(merged.domain))
376
+ if (merged.since) args.push('--since', String(merged.since))
377
+ if (merged.sort) args.push('--sort', String(merged.sort))
378
+ if (merged.verify) args.push('--verify', String(merged.verify))
379
+ if (refresh) args.push('--no-cache')
380
+ // `--` 后的全部 token 被 argparse 当位置参数:flag 必须全部前置,否则
381
+ // 以 `-` 开头的 query(如 `--list-engines`)会被 CLI 当 flag 吃掉
382
+ // (2026-11-18 实跑复现:`argo search "--list-engines"` 返回引擎清单)
383
+ args.push('--', query)
384
+ return args
385
+ }