argo-search 2.15.0 → 2.16.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 (134) hide show
  1. package/AGENTS.md +1 -1
  2. package/README.es.md +27 -5
  3. package/README.ja.md +27 -5
  4. package/README.ko.md +27 -5
  5. package/README.md +68 -19
  6. package/README.zh.md +68 -19
  7. package/SKILL.md +7 -7
  8. package/assets/readme/counts.json +1 -1
  9. package/backends/domain_profiles.json +107 -6
  10. package/backends/engine_registry.yaml +15 -2
  11. package/backends/quota_profiles.json +13 -3
  12. package/bin/argo +3 -0
  13. package/config.yaml +16 -0
  14. package/docs/CHANGELOG.md +15 -0
  15. package/docs/ENGINE_CATALOG.md +11 -10
  16. package/docs/MCP_SETUP.md +9 -0
  17. package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
  18. package/engines/specs/archive_org.yaml +1 -1
  19. package/engines/specs/carbon_intensity.yaml +1 -1
  20. package/engines/specs/crates.yaml +1 -1
  21. package/engines/specs/crossref.yaml +4 -2
  22. package/engines/specs/crt_sh.yaml +1 -1
  23. package/engines/specs/dblp.yaml +1 -1
  24. package/engines/specs/devto.yaml +1 -1
  25. package/engines/specs/docker_hub.yaml +1 -1
  26. package/engines/specs/europepmc.yaml +1 -1
  27. package/engines/specs/fxtwitter.yaml +1 -1
  28. package/engines/specs/gbfs_nyc.yaml +1 -1
  29. package/engines/specs/gleif.yaml +1 -1
  30. package/engines/specs/gov_regulations.yaml +1 -1
  31. package/engines/specs/hf_datasets.yaml +1 -1
  32. package/engines/specs/huggingface.yaml +1 -1
  33. package/engines/specs/keenable.yaml +7 -1
  34. package/engines/specs/linux_do.yaml +63 -0
  35. package/engines/specs/local_crossref.yaml +3 -1
  36. package/engines/specs/local_github.yaml +1 -1
  37. package/engines/specs/local_npm.yaml +6 -0
  38. package/engines/specs/local_openstreetmap.yaml +1 -1
  39. package/engines/specs/maven.yaml +1 -1
  40. package/engines/specs/mdn.yaml +1 -1
  41. package/engines/specs/musicbrainz.yaml +1 -1
  42. package/engines/specs/nasa_images.yaml +1 -1
  43. package/engines/specs/nhtsa_vpic.yaml +6 -3
  44. package/engines/specs/npm.yaml +1 -1
  45. package/engines/specs/nuget.yaml +1 -1
  46. package/engines/specs/nvd.yaml +1 -1
  47. package/engines/specs/openalex.yaml +4 -2
  48. package/engines/specs/openreview.yaml +1 -1
  49. package/engines/specs/polymarket.yaml +1 -1
  50. package/engines/specs/sec_edgar.yaml +1 -1
  51. package/engines/specs/steam.yaml +1 -1
  52. package/engines/specs/vam.yaml +1 -1
  53. package/engines/specs/wikidata.yaml +1 -1
  54. package/engines/specs/wikipedia.yaml +1 -1
  55. package/engines/specs/zhihu_hot_app.yaml +1 -1
  56. package/package.json +2 -1
  57. package/packages/dsh-plugin/dsh/client.js +14 -13
  58. package/packages/dsh-plugin/dsh/index.js +6 -0
  59. package/packages/dsh-plugin/dsh/runner.js +1 -1
  60. package/packages/dsh-plugin/dsh/workbench-client.js +796 -0
  61. package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
  62. package/packages/dsh-plugin/dsh/workbench-suggestions.js +148 -0
  63. package/packages/dsh-plugin/dsh/workbench.js +966 -0
  64. package/packages/dsh-plugin/icon.svg +23 -0
  65. package/packages/dsh-plugin/package.json +3 -1
  66. package/packages/dsh-plugin/test/workbench.test.js +92 -0
  67. package/scripts/argo_paths.py +2 -2
  68. package/scripts/badcase_ledger.py +9 -0
  69. package/scripts/cache.py +1 -1
  70. package/scripts/circuit_breaker.py +16 -3
  71. package/scripts/config_cache.py +19 -7
  72. package/scripts/daemon.py +5 -0
  73. package/scripts/engine_dispatch.py +5 -2
  74. package/scripts/engine_env.py +13 -4
  75. package/scripts/engines_base.py +24 -3
  76. package/scripts/engines_builders_archive.py +4 -3
  77. package/scripts/engines_builders_batch11.py +2 -1
  78. package/scripts/engines_builders_batch13.py +4 -3
  79. package/scripts/engines_builders_batch14.py +2 -1
  80. package/scripts/engines_builders_batch15.py +2 -1
  81. package/scripts/engines_builders_batch9.py +2 -2
  82. package/scripts/engines_builders_cn.py +7 -7
  83. package/scripts/engines_builders_data.py +12 -11
  84. package/scripts/engines_builders_data_macro.py +5 -4
  85. package/scripts/engines_builders_dsh.py +2 -1
  86. package/scripts/engines_builders_feeds.py +34 -19
  87. package/scripts/engines_builders_finance.py +2 -1
  88. package/scripts/engines_builders_intl.py +3 -2
  89. package/scripts/engines_builders_media.py +59 -12
  90. package/scripts/engines_builders_science.py +8 -7
  91. package/scripts/engines_builders_skill.py +2 -1
  92. package/scripts/engines_builders_tech.py +3 -3
  93. package/scripts/engines_builders_weather.py +9 -4
  94. package/scripts/engines_http.py +50 -1
  95. package/scripts/engines_mcp.py +28 -6
  96. package/scripts/evidence_loop.py +15 -1
  97. package/scripts/extend_route_labels.py +6 -0
  98. package/scripts/fetch_jina.py +98 -0
  99. package/scripts/fetch_v3.py +52 -93
  100. package/scripts/image_vision/vision_probe +0 -0
  101. package/scripts/install.sh +2 -0
  102. package/scripts/matrix_search_eval.py +8 -10
  103. package/scripts/mcp_transport.py +10 -5
  104. package/scripts/numeric_verify.py +3 -2
  105. package/scripts/output_transparency.py +3 -0
  106. package/scripts/quota.py +30 -29
  107. package/scripts/recovery.py +19 -16
  108. package/scripts/recovery_runner.py +29 -10
  109. package/scripts/redskill/redskill_engine.py +2 -1
  110. package/scripts/route.py +8 -0
  111. package/scripts/route_combo.py +11 -2
  112. package/scripts/route_policy.py +1 -1
  113. package/scripts/search_attribution.py +20 -0
  114. package/scripts/search_entry.py +27 -0
  115. package/scripts/search_output.py +18 -7
  116. package/scripts/search_pipeline.py +3 -3
  117. package/scripts/semantic_evidence.py +20 -11
  118. package/scripts/serp_guard.py +13 -1
  119. package/scripts/settings_page.py +1 -0
  120. package/scripts/single_flight.py +1 -1
  121. package/scripts/social_engines/hackernews_engine.py +2 -1
  122. package/scripts/social_engines/reddit_engine.py +2 -1
  123. package/scripts/social_engines/zhihu_engine.py +2 -1
  124. package/scripts/source_audit.py +42 -7
  125. package/scripts/usage_log.py +24 -9
  126. package/scripts/watch.py +3 -3
  127. package/scripts/zhihu_quota.py +2 -1
  128. package/sub-skills/argo-wide-research/SKILL.md +7 -5
  129. package/sub-skills/ego-search/{SKILL.md → README.md} +15 -47
  130. package/sub-skills/ego-search/scripts/ego_search.py +13 -4
  131. package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
  132. package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
  133. package/sub-skills/local-search/engine_registry.py +32 -7
  134. package/sub-skills/local-seek/SKILL.md +20 -22
@@ -0,0 +1,796 @@
1
+ /*
2
+ * @taxueseek/argo-dsh — 搜索分析工作台前端模块(ES Module,零构建依赖)
3
+ *
4
+ * 通过 /argo/workbench-client.js 由 Host 提供,挂载到 DSH:
5
+ * - main slot(key: 'argo-workbench')
6
+ * - sidebar.panellist(id: 'argo-workbench')
7
+ * - 全局划词浮层(选中对话内容一键进入工作台分析)
8
+ */
9
+
10
+ import { CSS, renderMarkdown } from '/argo/workbench-md.js'
11
+
12
+ const STATE_KEY = 'argo-workbench:state.v1'
13
+ const PREFS_KEY = 'argo-workbench:prefs.v1'
14
+
15
+ const CORE_MODES = [
16
+ { id: 'general', label: '全网搜索', desc: '多源快查,先给结论再列出处', ph: '搜任何问题、概念、报错或资料(Enter 发送,Shift+Enter 换行)…' },
17
+ { id: 'hotspot', label: '热点分析', desc: '梳理近期事件脉络、争议与各方立场', ph: '输入热点事件、行业动态或争议话题,看多方观点…' },
18
+ { id: 'research', label: '深度研究', desc: '多维拆解、原文核验并生成研究报告', ph: '输入需要系统调研的复杂问题,生成带来源账本的报告…' },
19
+ ]
20
+
21
+ const TOPIC_CARDS = [
22
+ {
23
+ id: 'verify',
24
+ label: '真假核验',
25
+ desc: '抓取原文核对出处,给出可信度判断',
26
+ ph: '输入需要核验真假的传闻、数据或说法…',
27
+ samples: [
28
+ '核验某项公开行业统计数据的原始官方出处',
29
+ '核实近期热门科技传闻的官方公告与时间线',
30
+ '核对某软件开源协议或最新收费政策的官方条款',
31
+ ],
32
+ },
33
+ {
34
+ id: 'compare',
35
+ label: '选型对比',
36
+ desc: '多维度对比产品、方案优缺点与替代',
37
+ ph: '输入要对比的两个或多个产品、工具或方案…',
38
+ samples: [
39
+ '主流本地知识库方案对比:架构、成本与适用场景',
40
+ '常见全文检索与向量数据库选型优缺点对比',
41
+ '主流个人知识管理工具功能与迁移成本对比',
42
+ ],
43
+ },
44
+ {
45
+ id: 'academic',
46
+ label: '学术文献',
47
+ desc: '学术多源深挖,梳理方法与实验结论',
48
+ ph: '输入论文主题、研究方向或具体文献关键词…',
49
+ samples: [
50
+ '推理时计算扩展方法最新研究综述与实验对比',
51
+ '多智能体协作与检索增强生成前沿论文梳理',
52
+ '端侧模型量化与低延迟推理优化技术进展',
53
+ ],
54
+ },
55
+ {
56
+ id: 'plugin',
57
+ label: '插件评测',
58
+ desc: '汇总官方说明、社区口碑与安装注意',
59
+ ph: '输入想评估的工具、扩展或插件类型…',
60
+ samples: [
61
+ '热门效率工具与浏览器扩展的真实口碑与安全评估',
62
+ '常用代码编辑器高星插件生态对比与避坑指南',
63
+ '开源自动化工作流插件的局限性与替代方案',
64
+ ],
65
+ },
66
+ {
67
+ id: 'local',
68
+ label: '本机检索',
69
+ desc: '基于 local-seek 检索本机代码与文档',
70
+ ph: '输入要在本机检索的关键词、符号或文件名…',
71
+ samples: [
72
+ 'circuit_breaker',
73
+ 'engine_states',
74
+ 'wide-research',
75
+ ],
76
+ },
77
+ ]
78
+
79
+ const pickSample = (samples) => samples[Math.floor(Math.random() * samples.length)]
80
+
81
+ const ALL_MODES = [...CORE_MODES, ...TOPIC_CARDS]
82
+
83
+ function injectStyle() {
84
+ if (typeof document === 'undefined') return
85
+ if (document.getElementById('argo-wb-style')) return
86
+ const el = document.createElement('style')
87
+ el.id = 'argo-wb-style'
88
+ el.textContent = CSS
89
+ document.head.appendChild(el)
90
+ }
91
+
92
+ function readStorage(key, fallback) {
93
+ try {
94
+ const raw = window.localStorage.getItem(key)
95
+ return raw ? JSON.parse(raw) : fallback
96
+ } catch {
97
+ return fallback
98
+ }
99
+ }
100
+
101
+ function writeStorage(key, value) {
102
+ try {
103
+ window.localStorage.setItem(key, JSON.stringify(value))
104
+ } catch { /* ignore */ }
105
+ }
106
+
107
+ function formatInterval(mins) {
108
+ if (mins >= 43200) return '每月一次'
109
+ if (mins >= 10080) return '每周一次'
110
+ if (mins >= 1440) return '每日一次'
111
+ return mins >= 60 ? `每 ${Math.round(mins / 60)} 小时` : `每 ${mins} 分钟`
112
+ }
113
+
114
+ function formatTime(iso) {
115
+ if (!iso) return '尚未运行'
116
+ try {
117
+ const d = new Date(iso)
118
+ return `${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
119
+ } catch {
120
+ return iso
121
+ }
122
+ }
123
+
124
+ export function mountArgoWorkbench(ctx, react) {
125
+ injectStyle()
126
+ const h = react.createElement
127
+ const { useState, useEffect, useRef } = react
128
+
129
+ let pendingExternal = null
130
+ const listeners = new Set()
131
+
132
+ const requestSearch = (query, mode = 'general') => {
133
+ const clean = String(query || '').trim()
134
+ if (!clean) return false
135
+ pendingExternal = { query: clean, mode }
136
+ for (const fn of listeners) fn(pendingExternal)
137
+ return true
138
+ }
139
+
140
+ const resolveLang = () => {
141
+ const loc = ctx?.locale ?? (typeof ctx?.get === 'function' ? ctx.get('locale') : null)
142
+ const active = loc?.getSnapshot?.()?.active || (typeof navigator !== 'undefined' ? navigator.language : 'zh')
143
+ return String(active).toLowerCase().startsWith('en') ? 'en' : 'zh'
144
+ }
145
+
146
+ function WorkbenchApp() {
147
+ const saved = readStorage(STATE_KEY, null)
148
+ const [prefs, setPrefs] = useState(() => readStorage(PREFS_KEY, { selection: true }))
149
+ const [lang, setLang] = useState(resolveLang)
150
+ const [view, setView] = useState('home')
151
+ const [input, setInput] = useState('')
152
+ const [activeQuery, setActiveQuery] = useState(saved?.query || '')
153
+ const [mode, setMode] = useState('general')
154
+ const [topicSamples, setTopicSamples] = useState(() => Object.fromEntries(TOPIC_CARDS.map(t => [t.id, pickSample(t.samples)])))
155
+ const [suggestions, setSuggestions] = useState([])
156
+ const [cards, setCards] = useState(saved?.cards || [])
157
+ const [turns, setTurns] = useState(saved?.turns || [])
158
+ const [stageText, setStageText] = useState('')
159
+ const [loading, setLoading] = useState(false)
160
+ const [filter, setFilter] = useState('all')
161
+ const [flashId, setFlashId] = useState('')
162
+ const [followup, setFollowup] = useState('')
163
+ const [popover, setPopover] = useState(null) // null | 'debug' | 'settings' | 'watch'
164
+ const [diagItems, setDiagItems] = useState([])
165
+ const [healthInfo, setHealthInfo] = useState(null)
166
+ const [gateResult, setGateResult] = useState(null)
167
+ const [clarifyInfo, setClarifyInfo] = useState(null)
168
+ const [evidenceSummary, setEvidenceSummary] = useState(null)
169
+ const [watches, setWatches] = useState([])
170
+ const [watchQuery, setWatchQuery] = useState('')
171
+ const [watchInterval, setWatchInterval] = useState(1440)
172
+ const [watchBusyId, setWatchBusyId] = useState('')
173
+ const inputRef = useRef(null)
174
+ const esRef = useRef(null)
175
+ const abortRef = useRef(null)
176
+
177
+ useEffect(() => {
178
+ writeStorage(STATE_KEY, { query: activeQuery, mode, cards, turns })
179
+ }, [activeQuery, mode, cards, turns])
180
+
181
+ const refreshWatches = async () => {
182
+ try {
183
+ const res = await fetch('/argo/api/watches')
184
+ const data = await res.json()
185
+ if (Array.isArray(data.items)) setWatches(data.items)
186
+ } catch { /* ignore */ }
187
+ }
188
+
189
+ const refreshSuggestions = async (targetMode = mode, targetLang = lang, shuffle = false) => {
190
+ try {
191
+ const res = await fetch(`/argo/api/suggestions?mode=${encodeURIComponent(targetMode)}&lang=${encodeURIComponent(targetLang)}&shuffle=${shuffle ? '1' : '0'}`)
192
+ const data = await res.json()
193
+ if (Array.isArray(data?.items)) setSuggestions(data.items)
194
+ } catch { /* ignore */ }
195
+ }
196
+
197
+ useEffect(() => {
198
+ const loc = ctx?.locale ?? (typeof ctx?.get === 'function' ? ctx.get('locale') : null)
199
+ if (!loc?.subscribe) return undefined
200
+ return loc.subscribe(() => setLang(resolveLang()))
201
+ }, [])
202
+
203
+ useEffect(() => {
204
+ refreshSuggestions(mode, lang, false)
205
+ }, [mode, lang])
206
+
207
+ useEffect(() => { refreshWatches() }, [])
208
+
209
+ const startSearch = (qText, targetMode = mode, refresh = false) => {
210
+ const q = String(qText || '').trim()
211
+ if (!q) return
212
+ if (esRef.current) { esRef.current.close(); esRef.current = null }
213
+ if (abortRef.current) { abortRef.current.abort(); abortRef.current = null }
214
+
215
+ setView('result')
216
+ setActiveQuery(q)
217
+ setInput(q)
218
+ setMode(targetMode)
219
+ setCards([])
220
+ setTurns([{ role: 'assistant', text: '' }])
221
+ setStageText('正在连接 Argo 多源检索引擎…')
222
+ setLoading(true)
223
+ setFilter('all')
224
+ setPopover(null)
225
+ setGateResult(null)
226
+ setClarifyInfo(null)
227
+ setEvidenceSummary(null)
228
+
229
+ const url = `/argo/api/stream?q=${encodeURIComponent(q)}&mode=${encodeURIComponent(targetMode)}&refresh=${refresh ? '1' : '0'}`
230
+ const es = new EventSource(url)
231
+ esRef.current = es
232
+
233
+ const parse = (ev) => { try { return JSON.parse(ev.data) } catch { return {} } }
234
+ es.addEventListener('status', (ev) => { const d = parse(ev); if (d.message) setStageText(d.message) })
235
+ es.addEventListener('clarify', (ev) => { const d = parse(ev); if (d && (d.explanation || d.ambiguities?.length)) setClarifyInfo(d) })
236
+ es.addEventListener('evidence', (ev) => { const d = parse(ev); if (d && (d.crossValidation || d.summary)) setEvidenceSummary(d) })
237
+ es.addEventListener('cards', (ev) => { const d = parse(ev); if (Array.isArray(d.cards)) setCards(d.cards) })
238
+ es.addEventListener('gate', (ev) => { const d = parse(ev); if (typeof d.passed === 'boolean') setGateResult(d) })
239
+ es.addEventListener('verify-update', (ev) => {
240
+ const d = parse(ev)
241
+ if (d.card) setCards(prev => prev.map(c => c.id === d.card.id ? d.card : c))
242
+ })
243
+ es.addEventListener('answer', (ev) => {
244
+ const d = parse(ev)
245
+ if (!d.delta) return
246
+ setTurns(prev => {
247
+ const next = [...prev]
248
+ const last = next[next.length - 1]
249
+ if (last && last.role === 'assistant') next[next.length - 1] = { ...last, text: last.text + d.delta }
250
+ return next
251
+ })
252
+ })
253
+ es.addEventListener('answer-status', (ev) => { const d = parse(ev); if (d.message) setStageText(d.message) })
254
+ es.addEventListener('done', () => { setLoading(false); setStageText(''); es.close(); esRef.current = null })
255
+ es.addEventListener('failure', (ev) => { const d = parse(ev); setLoading(false); setStageText(`检索出错:${d.message || '未知错误'}`); es.close(); esRef.current = null })
256
+ es.onerror = () => { if (es.readyState === EventSource.CLOSED) setLoading(false) }
257
+ }
258
+
259
+ useEffect(() => {
260
+ const handler = (req) => {
261
+ if (!req) return
262
+ pendingExternal = null
263
+ startSearch(req.query, req.mode || mode)
264
+ }
265
+ listeners.add(handler)
266
+ if (pendingExternal) handler(pendingExternal)
267
+ return () => {
268
+ listeners.delete(handler)
269
+ if (esRef.current) esRef.current.close()
270
+ if (abortRef.current) abortRef.current.abort()
271
+ }
272
+ }, [])
273
+
274
+ const handleFollowup = async (e) => {
275
+ e.preventDefault()
276
+ const q = followup.trim()
277
+ if (!q || loading) return
278
+ setFollowup('')
279
+ setLoading(true)
280
+ setStageText('正在结合当前证据回答追问…')
281
+
282
+ const historySnapshot = [...turns]
283
+ setTurns(prev => [...prev, { role: 'user', text: q }, { role: 'assistant', text: '' }])
284
+
285
+ const ac = new AbortController()
286
+ abortRef.current = ac
287
+ try {
288
+ const res = await fetch('/argo/api/followup', {
289
+ method: 'POST',
290
+ headers: { 'Content-Type': 'application/json' },
291
+ body: JSON.stringify({ query: activeQuery, mode, cards, history: historySnapshot, question: q }),
292
+ signal: ac.signal,
293
+ })
294
+ const reader = res.body.getReader()
295
+ const dec = new TextDecoder()
296
+ let buf = ''
297
+ while (true) {
298
+ const { value, done } = await reader.read()
299
+ if (done) break
300
+ buf += dec.decode(value, { stream: true })
301
+ const parts = buf.split('\n\n')
302
+ buf = parts.pop() || ''
303
+ for (const chunk of parts) {
304
+ const evMatch = chunk.match(/^event:\s*(.+)$/m)
305
+ const dataMatch = chunk.match(/^data:\s*(.+)$/m)
306
+ if (!dataMatch) continue
307
+ const evName = evMatch ? evMatch[1].trim() : 'message'
308
+ const payload = JSON.parse(dataMatch[1])
309
+ if (evName === 'answer' && payload.delta) {
310
+ setTurns(prev => {
311
+ const next = [...prev]
312
+ const last = next[next.length - 1]
313
+ if (last && last.role === 'assistant') next[next.length - 1] = { ...last, text: last.text + payload.delta }
314
+ return next
315
+ })
316
+ }
317
+ }
318
+ }
319
+ } catch { /* ignore */ } finally {
320
+ setLoading(false)
321
+ setStageText('')
322
+ abortRef.current = null
323
+ }
324
+ }
325
+
326
+ const createWatch = async (qStr, targetMode = mode, mins = watchInterval) => {
327
+ const q = String(qStr || '').trim()
328
+ if (!q) return
329
+ try {
330
+ const res = await fetch('/argo/api/watches', {
331
+ method: 'POST',
332
+ headers: { 'Content-Type': 'application/json' },
333
+ body: JSON.stringify({ query: q, mode: targetMode, intervalMinutes: mins }),
334
+ })
335
+ const data = await res.json()
336
+ if (Array.isArray(data.items)) setWatches(data.items)
337
+ setWatchQuery('')
338
+ setWatchOpen(true)
339
+ } catch { /* ignore */ }
340
+ }
341
+
342
+ const runWatchNow = async (id) => {
343
+ setWatchBusyId(id)
344
+ try {
345
+ const res = await fetch('/argo/api/watches/run', {
346
+ method: 'POST',
347
+ headers: { 'Content-Type': 'application/json' },
348
+ body: JSON.stringify({ id }),
349
+ })
350
+ const data = await res.json()
351
+ if (Array.isArray(data.items)) setWatches(data.items)
352
+ } finally {
353
+ setWatchBusyId('')
354
+ }
355
+ }
356
+
357
+ const deleteWatch = async (id) => {
358
+ try {
359
+ const res = await fetch(`/argo/api/watches?id=${encodeURIComponent(id)}`, { method: 'DELETE' })
360
+ const data = await res.json()
361
+ if (Array.isArray(data.items)) setWatches(data.items)
362
+ } catch { /* ignore */ }
363
+ }
364
+
365
+ const openWatchResult = (w) => {
366
+ setView('result')
367
+ setActiveQuery(w.query)
368
+ setInput(w.query)
369
+ setMode(w.mode || 'general')
370
+ setCards(Array.isArray(w.lastCards) ? w.lastCards : [])
371
+ setTurns([{ role: 'assistant', text: w.lastSummary || '该定时任务尚未生成摘要,可点击「立即执行」或「强制刷新」。' }])
372
+ setWatchOpen(false)
373
+ }
374
+
375
+ const scrollToCard = (cardId) => {
376
+ const el = document.getElementById(`aw-${cardId}`)
377
+ if (el) {
378
+ el.scrollIntoView({ behavior: 'smooth', block: 'center' })
379
+ setFlashId(cardId)
380
+ setTimeout(() => setFlashId(''), 1400)
381
+ }
382
+ }
383
+
384
+ const refreshHealth = async () => {
385
+ try {
386
+ const res = await fetch('/argo/api/health')
387
+ const data = await res.json()
388
+ if (data?.ok) setHealthInfo(data)
389
+ } catch { /* ignore */ }
390
+ }
391
+
392
+ const openDebug = async () => {
393
+ const next = popover === 'debug' ? null : 'debug'
394
+ setPopover(next)
395
+ if (next === 'debug') {
396
+ refreshHealth()
397
+ try {
398
+ const res = await fetch('/argo/api/diagnostics')
399
+ const data = await res.json()
400
+ setDiagItems(data.items || [])
401
+ } catch { /* ignore */ }
402
+ }
403
+ }
404
+
405
+ const toggleWatchPanel = () => {
406
+ const next = popover === 'watch' ? null : 'watch'
407
+ setPopover(next)
408
+ if (next === 'watch') refreshWatches()
409
+ }
410
+
411
+ const toggleSettingsPanel = () => {
412
+ const next = popover === 'settings' ? null : 'settings'
413
+ setPopover(next)
414
+ if (next === 'settings') refreshHealth()
415
+ }
416
+
417
+ const toggleEgoSearch = async () => {
418
+ const current = Boolean(healthInfo?.egoSearch?.enabled)
419
+ try {
420
+ const res = await fetch('/argo/api/ego-search', {
421
+ method: 'POST',
422
+ headers: { 'Content-Type': 'application/json' },
423
+ body: JSON.stringify({ enabled: !current }),
424
+ })
425
+ const data = await res.json()
426
+ if (data?.ok) setHealthInfo(prev => ({ ...(prev || {}), egoSearch: data.egoSearch }))
427
+ } catch { /* ignore */ }
428
+ }
429
+
430
+ const toggleSelectionPref = () => {
431
+ const next = { ...prefs, selection: !prefs.selection }
432
+ setPrefs(next)
433
+ writeStorage(PREFS_KEY, next)
434
+ }
435
+
436
+ const currentModeObj = ALL_MODES.find(m => m.id === mode) || CORE_MODES[0]
437
+ const lockedTopic = TOPIC_CARDS.find(t => t.id === mode) || null
438
+ const verifiedCount = cards.filter(c => c.verified).length
439
+ const visibleCards = filter === 'verified'
440
+ ? cards.filter(c => c.verified)
441
+ : (filter === 'all' ? cards : cards.filter(c => c.source === filter))
442
+ const sources = [...new Set(cards.map(c => c.source))]
443
+
444
+ const renderWatchDrawer = () => popover !== 'watch' ? null : h('div', { className: 'aw-popover' },
445
+ h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '10px' } },
446
+ h('strong', null, '定时搜索与追踪'),
447
+ h('button', { type: 'button', className: 'aw-filter', onClick: () => setPopover(null) }, '关闭')),
448
+ h('form', {
449
+ style: { display: 'flex', gap: '6px', marginBottom: '10px' },
450
+ onSubmit: (e) => { e.preventDefault(); createWatch(watchQuery || activeQuery || input, mode, watchInterval) },
451
+ },
452
+ h('input', {
453
+ className: 'aw-top-input',
454
+ style: { border: '1px solid var(--aw-border)', borderRadius: '8px', padding: '5px 8px', background: 'var(--aw-sunken)' },
455
+ placeholder: '输入定时追踪关键词…',
456
+ value: watchQuery,
457
+ onChange: (e) => setWatchQuery(e.target.value),
458
+ }),
459
+ h('select', {
460
+ className: 'aw-select',
461
+ style: { height: '28px' },
462
+ value: watchInterval,
463
+ onChange: (e) => setWatchInterval(Number(e.target.value)),
464
+ },
465
+ h('option', { value: 1440 }, '每日一次'),
466
+ h('option', { value: 10080 }, '每周一次'),
467
+ h('option', { value: 43200 }, '每月一次')),
468
+ h('button', { type: 'submit', className: 'aw-filter active' }, '添加')),
469
+ watches.length === 0
470
+ ? h('div', { style: { color: 'var(--aw-text-3)', padding: '8px 0' } }, '暂无定时搜索任务')
471
+ : watches.map(w => h('div', { key: w.id, className: 'aw-watch-row' },
472
+ h('div', { style: { fontWeight: 600 } }, `[${w.modeLabel || w.mode}] ${w.query}`),
473
+ h('div', { style: { color: 'var(--aw-text-3)' } }, `${formatInterval(w.intervalMinutes)} · 上次:${formatTime(w.lastRunAt)} · 来源 ${w.lastCardCount || 0}`),
474
+ h('div', { className: 'aw-watch-actions' },
475
+ w.lastSummary ? h('button', { type: 'button', className: 'aw-filter active', onClick: () => openWatchResult(w) }, '查看结果') : null,
476
+ h('button', {
477
+ type: 'button',
478
+ className: 'aw-filter',
479
+ disabled: watchBusyId === w.id,
480
+ onClick: () => runWatchNow(w.id),
481
+ }, watchBusyId === w.id ? '执行中…' : '立即执行'),
482
+ h('button', { type: 'button', className: 'aw-filter', onClick: () => deleteWatch(w.id) }, '删除')))))
483
+
484
+ if (view === 'home') {
485
+ return h('div', { className: 'aw-root' },
486
+ h('div', { className: 'aw-hero' },
487
+ h('div', { className: 'aw-hero-top' },
488
+ h('button', { type: 'button', className: 'aw-icon-btn', onClick: toggleWatchPanel }, `定时搜索 (${watches.length})`)),
489
+ renderWatchDrawer(),
490
+ h('div', { className: 'aw-hero-inner' },
491
+ h('h1', { className: 'aw-slogan' }, lang === 'en' ? 'Search Wide, Verify Fast' : '搜得到,查得快'),
492
+ h('p', { className: 'aw-sub' }, lang === 'en' ? 'Multi-source search, hotspot brief, deep research & scheduled watch' : '全网搜索,热点分析,深度研究,定时搜索'),
493
+ h('form', {
494
+ className: 'aw-box',
495
+ onSubmit: (e) => { e.preventDefault(); startSearch(input, mode) },
496
+ },
497
+ h('textarea', {
498
+ ref: inputRef,
499
+ className: 'aw-textarea',
500
+ placeholder: currentModeObj.ph,
501
+ value: input,
502
+ onChange: (e) => setInput(e.target.value),
503
+ onKeyDown: (e) => {
504
+ if (e.key === 'Enter' && !e.shiftKey) {
505
+ e.preventDefault()
506
+ startSearch(input, mode)
507
+ }
508
+ },
509
+ }),
510
+ h('div', { className: 'aw-box-foot' },
511
+ h('div', { className: 'aw-modes' },
512
+ CORE_MODES.map(m => h('button', {
513
+ key: m.id,
514
+ type: 'button',
515
+ title: m.desc,
516
+ className: `aw-mode-btn ${mode === m.id ? 'active' : ''}`,
517
+ onClick: () => setMode(m.id),
518
+ }, m.label)),
519
+ lockedTopic ? h('span', { className: 'aw-topic-chip' },
520
+ `${lang === 'en' ? 'Topic' : '主题'}:${lockedTopic.label}`,
521
+ h('button', { type: 'button', title: '取消特定主题', onClick: () => setMode('general') }, '×')) : null),
522
+ h('button', {
523
+ type: 'submit',
524
+ className: 'aw-send',
525
+ disabled: !input.trim(),
526
+ title: '开始检索分析',
527
+ }, '→'))),
528
+ suggestions.length > 0 ? h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '8px', marginTop: '14px', alignItems: 'center' } },
529
+ suggestions.map((s, idx) => h('button', {
530
+ key: `${s.source}-${idx}`,
531
+ type: 'button',
532
+ className: 'aw-filter',
533
+ style: { display: 'inline-flex', alignItems: 'center', gap: '5px', fontSize: '12px', maxWidth: '100%' },
534
+ onClick: () => startSearch(s.query, mode),
535
+ },
536
+ h('span', { style: { opacity: 0.7, fontSize: '11px' } }, `[${s.tag}]`),
537
+ h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: '240px' } }, s.query))),
538
+ h('button', {
539
+ type: 'button',
540
+ className: 'aw-preset-try',
541
+ style: { color: 'var(--aw-text-3)', marginLeft: 'auto' },
542
+ onClick: () => refreshSuggestions(mode, lang, true),
543
+ }, lang === 'en' ? 'Shuffle' : '换一批')) : null,
544
+ h('div', { className: 'aw-sec-head' },
545
+ h('span', null, '特定主题'),
546
+ h('div', { style: { display: 'flex', gap: '10px', alignItems: 'center' } },
547
+ activeQuery && cards.length > 0 ? h('button', {
548
+ type: 'button',
549
+ className: 'aw-preset-try',
550
+ onClick: () => setView('result'),
551
+ }, `继续上次:${activeQuery.slice(0, 14)}${activeQuery.length > 14 ? '…' : ''} ↗`) : null,
552
+ h('button', {
553
+ type: 'button',
554
+ className: 'aw-preset-try',
555
+ style: { color: 'var(--aw-text-3)' },
556
+ onClick: () => setTopicSamples(Object.fromEntries(TOPIC_CARDS.map(t => [t.id, pickSample(t.samples)]))),
557
+ }, '换一批引导'))),
558
+ h('div', { className: 'aw-presets' },
559
+ TOPIC_CARDS.map(item => h('div', {
560
+ key: item.id,
561
+ className: `aw-preset ${mode === item.id ? 'selected' : ''}`,
562
+ onClick: () => { setMode(item.id); inputRef.current?.focus?.() },
563
+ },
564
+ h('div', null,
565
+ h('div', { className: 'aw-preset-tag' }, item.label),
566
+ h('div', { className: 'aw-preset-desc', style: { marginTop: '4px' } }, item.desc)),
567
+ h('button', {
568
+ type: 'button',
569
+ className: 'aw-preset-try',
570
+ onClick: (e) => { e.stopPropagation(); startSearch(topicSamples[item.id] || pickSample(item.samples), item.id) },
571
+ }, '试一试 ↗')))))))
572
+ }
573
+
574
+ return h('div', { className: 'aw-root' },
575
+ h('div', { className: 'aw-topbar' },
576
+ h('button', { type: 'button', className: 'aw-icon-btn', onClick: () => setView('home') }, '← 首页'),
577
+ h('select', {
578
+ className: 'aw-select',
579
+ value: mode,
580
+ onChange: (e) => {
581
+ const nextMode = e.target.value
582
+ setMode(nextMode)
583
+ if (activeQuery) startSearch(activeQuery, nextMode)
584
+ },
585
+ }, ALL_MODES.map(m => h('option', { key: m.id, value: m.id }, m.label))),
586
+ h('form', {
587
+ className: 'aw-top-form',
588
+ onSubmit: (e) => { e.preventDefault(); startSearch(input, mode) },
589
+ },
590
+ h('input', {
591
+ className: 'aw-top-input',
592
+ value: input,
593
+ onChange: (e) => setInput(e.target.value),
594
+ placeholder: '输入新的查询…',
595
+ }),
596
+ h('button', {
597
+ type: 'button',
598
+ className: 'aw-filter',
599
+ title: '跳过缓存重新检索',
600
+ onClick: () => startSearch(input || activeQuery, mode, true),
601
+ }, '强制刷新'),
602
+ h('button', {
603
+ type: 'submit',
604
+ className: 'aw-send',
605
+ style: { width: '28px', height: '28px' },
606
+ disabled: !input.trim(),
607
+ }, '→')),
608
+ h('div', { className: 'aw-stat-pill' }, `${cards.length} 条来源,${verifiedCount} 条已核验`),
609
+ h('button', {
610
+ type: 'button',
611
+ className: 'aw-icon-btn',
612
+ title: '把当前查询加入定时追踪',
613
+ onClick: () => createWatch(activeQuery, mode, watchInterval),
614
+ }, '定时追踪'),
615
+ h('button', { type: 'button', className: 'aw-icon-btn', onClick: toggleWatchPanel }, `定时 (${watches.length})`),
616
+ h('button', { type: 'button', className: 'aw-icon-btn', onClick: openDebug }, 'DEBUG'),
617
+ h('button', {
618
+ type: 'button',
619
+ className: 'aw-icon-btn',
620
+ onClick: toggleSettingsPanel,
621
+ }, '设置')),
622
+
623
+ renderWatchDrawer(),
624
+
625
+ popover === 'debug' ? h('div', { className: 'aw-popover' },
626
+ h('div', { style: { fontWeight: 600, marginBottom: '8px' } }, '最近 20 次工作台检索诊断'),
627
+ healthInfo?.breaker ? h('div', { style: { padding: '6px 8px', marginBottom: '8px', borderRadius: '8px', background: 'var(--aw-sunken)', fontSize: '12px' } },
628
+ `熔断器:${healthInfo.breaker.total} 源 · 非闭合 ${healthInfo.breaker.nonClosedCount} 源` +
629
+ (healthInfo.breaker.topTripped?.length ? `(${healthInfo.breaker.topTripped.slice(0, 3).map(t => `${t.engine}:${t.state}`).join(', ')})` : '')) : null,
630
+ diagItems.length === 0
631
+ ? h('div', { style: { color: 'var(--aw-text-3)' } }, '暂无记录')
632
+ : diagItems.map((it, idx) => h('div', {
633
+ key: idx,
634
+ style: { padding: '6px 0', borderBottom: '1px solid var(--aw-border)' },
635
+ },
636
+ h('div', { style: { fontWeight: 600 } }, `[${it.mode}] ${it.query}`),
637
+ h('div', { style: { color: 'var(--aw-text-3)' } }, `${it.durationMs}ms · 来源 ${it.cardCount} · 核验 ${it.verifiedCount ?? 0} · ${it.status}`)))) : null,
638
+
639
+ popover === 'settings' ? h('div', { className: 'aw-popover', style: { width: '280px' } },
640
+ h('div', { style: { fontWeight: 600, marginBottom: '10px' } }, '工作台偏好与能力'),
641
+ h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer', marginBottom: '8px' } },
642
+ h('span', null, '对话划词浮层(Argo 分析)'),
643
+ h('input', { type: 'checkbox', checked: Boolean(prefs.selection), onChange: toggleSelectionPref })),
644
+ h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer' } },
645
+ h('span', null, '登录态专业搜索(ego-search)'),
646
+ h('input', { type: 'checkbox', checked: Boolean(healthInfo?.egoSearch?.enabled), onChange: toggleEgoSearch })),
647
+ h('button', {
648
+ type: 'button',
649
+ className: 'aw-icon-btn',
650
+ style: { marginTop: '12px', width: '100%', justifyContent: 'center' },
651
+ onClick: () => {
652
+ window.localStorage.removeItem(STATE_KEY)
653
+ setActiveQuery(''); setCards([]); setTurns([]); setGateResult(null); setView('home'); setPopover(null)
654
+ },
655
+ }, '清空当前工作台记录')) : null,
656
+
657
+ h('div', { className: 'aw-main' },
658
+ h('div', null,
659
+ h('div', { className: 'aw-q-head' },
660
+ h('h2', { className: 'aw-q-title' }, activeQuery),
661
+ h('span', { className: 'aw-badge' }, currentModeObj.label),
662
+ evidenceSummary?.crossValidation ? h('span', {
663
+ className: 'aw-badge',
664
+ title: evidenceSummary.crossValidation.detail || '',
665
+ }, `交叉验证:${evidenceSummary.crossValidation.corroboration_level || 'unknown'}${evidenceSummary.summary ? ` · 高可信 ${evidenceSummary.summary.high_credibility || 0}` : ''}`) : null,
666
+ gateResult ? h('span', {
667
+ className: 'aw-badge',
668
+ title: (gateResult.warnings || []).join(';'),
669
+ style: { background: gateResult.passed ? 'var(--aw-sunken)' : '#fef2f2', color: gateResult.passed ? 'var(--aw-text-2)' : '#b91c1c' },
670
+ }, gateResult.passed ? '质量门禁通过' : '质量门禁未达标') : null),
671
+ clarifyInfo ? h('div', { style: { fontSize: '12px', color: 'var(--aw-text-2)', padding: '6px 10px', marginBottom: '10px', borderRadius: '8px', background: 'var(--aw-sunken)' } },
672
+ clarifyInfo.explanation || '',
673
+ Array.isArray(clarifyInfo.ambiguities) && clarifyInfo.ambiguities.length > 0
674
+ ? ` · 歧义提示:${clarifyInfo.ambiguities.slice(0, 2).map(a => a.term || a).join(' / ')}`
675
+ : '') : null,
676
+ loading || stageText ? h('div', { className: 'aw-progress' },
677
+ loading ? h('span', { className: 'aw-dot' }) : null,
678
+ h('span', null, stageText || '处理中…')) : null,
679
+ turns.map((turn, idx) => h('div', { key: idx, className: 'aw-turn' },
680
+ turn.role === 'user'
681
+ ? h('div', { className: 'aw-turn-q' }, turn.text)
682
+ : h('div', { className: 'aw-md' }, renderMarkdown(h, turn.text, cards, scrollToCard)))),
683
+ !loading && cards.length > 0 ? h('form', { className: 'aw-followup', onSubmit: handleFollowup },
684
+ h('input', {
685
+ value: followup,
686
+ onChange: (e) => setFollowup(e.target.value),
687
+ placeholder: '基于当前检索证据继续追问细节…',
688
+ }),
689
+ h('button', { type: 'submit', className: 'aw-send', disabled: !followup.trim() }, '→')) : null),
690
+
691
+ h('div', null,
692
+ h('div', { className: 'aw-right-head' },
693
+ h('strong', { style: { fontSize: '13px' } }, '证据与原文出处'),
694
+ h('div', { className: 'aw-filters' },
695
+ h('button', {
696
+ type: 'button',
697
+ className: `aw-filter ${filter === 'all' ? 'active' : ''}`,
698
+ onClick: () => setFilter('all'),
699
+ }, `全部 (${cards.length})`),
700
+ verifiedCount > 0 ? h('button', {
701
+ type: 'button',
702
+ className: `aw-filter ${filter === 'verified' ? 'active' : ''}`,
703
+ onClick: () => setFilter('verified'),
704
+ }, `已核验 (${verifiedCount})`) : null,
705
+ sources.slice(0, 4).map(src => h('button', {
706
+ key: src,
707
+ type: 'button',
708
+ className: `aw-filter ${filter === src ? 'active' : ''}`,
709
+ onClick: () => setFilter(src),
710
+ }, src)))),
711
+ h('div', { className: 'aw-cards' },
712
+ visibleCards.length === 0
713
+ ? h('div', { style: { color: 'var(--aw-text-3)', fontSize: '13px', padding: '12px' } }, loading ? '正在拉取多源证据…' : '暂无匹配卡片')
714
+ : visibleCards.map(c => h('div', {
715
+ key: c.id,
716
+ id: `aw-${c.id}`,
717
+ className: `aw-card ${flashId === c.id ? 'flash' : ''}`,
718
+ },
719
+ h('div', { className: 'aw-card-top' },
720
+ h('span', { className: 'aw-card-src' },
721
+ h('span', { className: 'aw-idx' }, String(c.index)),
722
+ h('span', null, `${c.source}${c.domain ? ` · ${c.domain}` : ''}`)),
723
+ c.verified ? h('span', { className: 'aw-verified' }, '已核验原文') : null),
724
+ h('p', { className: 'aw-card-quote' }, (c.verifiedText || c.snippet || '暂无摘录').slice(0, 220)),
725
+ h('a', {
726
+ className: 'aw-card-link',
727
+ href: c.url,
728
+ target: '_blank',
729
+ rel: 'noopener noreferrer',
730
+ },
731
+ h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, c.title),
732
+ h('span', { style: { flexShrink: 0 } }, '↗'))))))))
733
+ }
734
+
735
+ function SelectionPill() {
736
+ const [hit, setHit] = useState(null)
737
+
738
+ useEffect(() => {
739
+ const checkSelection = () => {
740
+ const prefs = readStorage(PREFS_KEY, { selection: true })
741
+ if (!prefs.selection) { setHit(null); return }
742
+ const sel = window.getSelection?.()
743
+ const text = sel ? String(sel.toString() || '').trim() : ''
744
+ if (text.length < 4 || text.length > 200) { setHit(null); return }
745
+ const range = sel.rangeCount > 0 ? sel.getRangeAt(0) : null
746
+ if (!range) { setHit(null); return }
747
+ const rect = range.getBoundingClientRect()
748
+ if (!rect || (rect.width === 0 && rect.height === 0)) { setHit(null); return }
749
+ setHit({ text, top: Math.max(12, rect.top - 38), left: Math.min(window.innerWidth - 130, Math.max(12, rect.left)) })
750
+ }
751
+ const onUp = () => setTimeout(checkSelection, 20)
752
+ document.addEventListener('mouseup', onUp)
753
+ document.addEventListener('keyup', onUp)
754
+ return () => {
755
+ document.removeEventListener('mouseup', onUp)
756
+ document.removeEventListener('keyup', onUp)
757
+ }
758
+ }, [])
759
+
760
+ if (!hit) return null
761
+ return h('button', {
762
+ type: 'button',
763
+ className: 'aw-sel-pill',
764
+ style: { top: `${hit.top}px`, left: `${hit.left}px` },
765
+ onMouseDown: (e) => {
766
+ e.preventDefault()
767
+ const text = hit.text
768
+ setHit(null)
769
+ requestSearch(text, 'general')
770
+ try {
771
+ ctx.get?.('layout')?.selectPanel?.('argo-workbench')
772
+ } catch { /* ignore */ }
773
+ },
774
+ }, 'Argo 分析')
775
+ }
776
+
777
+ const offs = [
778
+ ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: 'argo-workbench' }, WorkbenchApp)),
779
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register(
780
+ { name: 'sidebar.panellist', id: 'argo-workbench', order: 5, label: 'Argo 搜索' },
781
+ ({ size = 20, active }) => h('svg', {
782
+ width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
783
+ stroke: active ? '#ea580c' : 'currentColor', strokeWidth: 1.8,
784
+ strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
785
+ },
786
+ h('circle', { cx: 11, cy: 11, r: 7 }),
787
+ h('path', { d: 'M16.5 16.5 21 21' }),
788
+ h('path', { d: 'M11 7.2 13.8 13.8 11 12.3 8.2 13.8 11 7.2Z', fill: '#ea580c', stroke: 'none' })),
789
+ )),
790
+ ctx.slots.inject('global', () => ctx.slots.register({ name: 'global', key: 'argo-workbench-pill' }, SelectionPill)),
791
+ ]
792
+
793
+ return () => {
794
+ for (const off of offs) if (typeof off === 'function') off()
795
+ }
796
+ }