argo-search 2.16.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/AGENTS.md +4 -2
  2. package/README.es.md +15 -5
  3. package/README.ja.md +15 -5
  4. package/README.ko.md +15 -5
  5. package/README.md +16 -6
  6. package/README.zh.md +16 -6
  7. package/SKILL.md +12 -11
  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 +121 -18
  13. package/backends/engine_registry.yaml +23 -0
  14. package/backends/env_passthrough.txt +2 -0
  15. package/backends/quota_profiles.json +20 -0
  16. package/bin/argo +78 -12
  17. package/docs/CHANGELOG.md +35 -1
  18. package/docs/COMMIT_STANDARD.md +12 -2
  19. package/docs/ENGINE_CATALOG.md +36 -33
  20. package/docs/RELEASE_NOTES_v2.17.0.md +66 -0
  21. package/docs/RELEASE_NOTES_v2.18.0.md +87 -0
  22. package/docs/RELEASING.md +2 -2
  23. package/engines/specs/crossref.yaml +2 -0
  24. package/engines/specs/hackernews.yaml +2 -0
  25. package/engines/specs/helve.yaml +49 -0
  26. package/engines/specs/hf_papers.yaml +2 -0
  27. package/engines/specs/openalex.yaml +9 -2
  28. package/engines/specs/twitter_cli.yaml +17 -0
  29. package/engines/specs/twitter_syndication.yaml +2 -3
  30. package/package.json +3 -1
  31. package/packages/dsh-plugin/README.md +5 -2
  32. package/packages/dsh-plugin/cordis.patch.yml +4 -1
  33. package/packages/dsh-plugin/dsh/client.js +57 -63
  34. package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
  35. package/packages/dsh-plugin/dsh/index.js +109 -21
  36. package/packages/dsh-plugin/dsh/native-tools.mjs +10 -0
  37. package/packages/dsh-plugin/dsh/route-guard.js +95 -0
  38. package/packages/dsh-plugin/dsh/runner.js +49 -6
  39. package/packages/dsh-plugin/dsh/wide-research.js +20 -18
  40. package/packages/dsh-plugin/dsh/workbench-client.js +119 -20
  41. package/packages/dsh-plugin/dsh/workbench-io.js +182 -0
  42. package/packages/dsh-plugin/dsh/workbench-search.js +445 -0
  43. package/packages/dsh-plugin/dsh/workbench-suggestions.js +387 -75
  44. package/packages/dsh-plugin/dsh/workbench.js +277 -497
  45. package/packages/dsh-plugin/package.json +4 -3
  46. package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
  47. package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
  48. package/packages/dsh-plugin/test/client.test.js +26 -0
  49. package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
  50. package/packages/dsh-plugin/test/index.test.js +150 -1
  51. package/packages/dsh-plugin/test/workbench-concurrency.test.js +96 -0
  52. package/packages/dsh-plugin/test/workbench.test.js +422 -9
  53. package/scripts/adaptive.py +13 -11
  54. package/scripts/affected_tests.py +324 -0
  55. package/scripts/badcase_ledger.py +93 -2
  56. package/scripts/browser_auth.py +178 -4
  57. package/scripts/cache.py +68 -69
  58. package/scripts/check_commit_report.py +59 -9
  59. package/scripts/chrome_cdp.py +71 -0
  60. package/scripts/circuit_breaker.py +77 -12
  61. package/scripts/cli_io.py +8 -3
  62. package/scripts/config_cache.py +4 -3
  63. package/scripts/daemon.py +9 -2
  64. package/scripts/engine_add.py +45 -0
  65. package/scripts/engine_dispatch.py +27 -47
  66. package/scripts/engine_failure.py +33 -0
  67. package/scripts/engine_families.py +1 -0
  68. package/scripts/engine_fingerprint.py +114 -0
  69. package/scripts/engine_health.py +130 -0
  70. package/scripts/engine_states.py +54 -4
  71. package/scripts/engines.py +2 -0
  72. package/scripts/engines_base.py +19 -44
  73. package/scripts/engines_builders_intl.py +20 -94
  74. package/scripts/engines_builders_search.py +19 -8
  75. package/scripts/engines_builders_tech.py +16 -16
  76. package/scripts/engines_fields.py +23 -0
  77. package/scripts/engines_twitter_cli.py +182 -0
  78. package/scripts/evidence_grounding.py +182 -0
  79. package/scripts/fetch_browser.py +25 -10
  80. package/scripts/fetch_cli_output.py +75 -0
  81. package/scripts/fetch_dispatch.py +248 -0
  82. package/scripts/fetch_quality.py +11 -0
  83. package/scripts/fetch_v3.py +48 -114
  84. package/scripts/gate_manifest_check.py +75 -0
  85. package/scripts/gen_readme_art.py +264 -0
  86. package/scripts/intent_router.py +224 -0
  87. package/scripts/mcp_compact.py +3 -0
  88. package/scripts/mcp_handlers.py +24 -4
  89. package/scripts/mcp_tools.py +2 -0
  90. package/scripts/mcp_transport.py +24 -5
  91. package/scripts/mcp_warm.py +15 -11
  92. package/scripts/numeric_verify.py +9 -0
  93. package/scripts/output_transparency.py +10 -0
  94. package/scripts/pre-commit +65 -8
  95. package/scripts/query_operators.py +229 -1
  96. package/scripts/quota.py +19 -37
  97. package/scripts/release.py +16 -1
  98. package/scripts/release_check.py +1 -2
  99. package/scripts/research_gates.py +85 -1
  100. package/scripts/research_notes.py +52 -5
  101. package/scripts/retry_policy.py +17 -3
  102. package/scripts/route_combo.py +21 -4
  103. package/scripts/search.py +29 -29
  104. package/scripts/search_cli.py +104 -8
  105. package/scripts/search_output.py +4 -1
  106. package/scripts/social_research.py +8 -6
  107. package/scripts/source_discovery.py +611 -0
  108. package/scripts/sync_backends.py +45 -0
  109. package/scripts/time_utils.py +28 -0
  110. package/scripts/twitter_single_read.py +107 -0
  111. package/scripts/x_keyword_route.py +138 -0
  112. package/scripts/x_search.py +24 -33
  113. package/scripts/zhihu_answer_body.py +96 -0
  114. package/scripts/zhihu_answer_fetch.py +66 -0
  115. package/scripts/zhihu_answer_lookup.py +138 -0
  116. package/sub-skills/ego-search/README.md +9 -0
  117. package/sub-skills/ego-search/scripts/ego_search.py +182 -15
  118. package/sub-skills/ego-search/scripts/pacing.py +291 -0
  119. package/sub-skills/ego-search/scripts/quality.py +262 -6
  120. package/sub-skills/ego-search/scripts/runtime.py +7 -1
  121. package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
  122. package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
  123. package/sub-skills/local-seek/SKILL.md +3 -1
  124. package/sub-skills/local-seek/scripts/seek.py +80 -109
  125. package/sub-skills/local-seek/scripts/seek_git.py +65 -0
  126. package/sub-skills/local-seek/scripts/seek_inspect.py +242 -0
@@ -704,16 +704,21 @@ export function createWideResearchTool(ctx, config, options = {}) {
704
704
  const localSources = buildLocalSources(fileInputs)
705
705
  let recomputedValues = []
706
706
  let recomputeExpected = false
707
+ let recomputeWarning = null
707
708
  if (recomputeSpec && recomputeSpec.script) {
708
709
  recomputeExpected = true
709
- recomputedValues = await runRecomputeForResearch(recomputeSpec, fileInputs, {
710
- command: config.searchCommand,
711
- args: config.searchArgs,
712
- timeoutMs: config.searchTimeoutMs,
713
- idleMs: config.searchIdleMs,
714
- max: config.searchConcurrency,
715
- config,
716
- }, exec.signal)
710
+ try {
711
+ recomputedValues = await runRecomputeForResearch(recomputeSpec, fileInputs, {
712
+ command: config.searchCommand,
713
+ args: config.searchArgs,
714
+ timeoutMs: config.searchTimeoutMs,
715
+ idleMs: config.searchIdleMs,
716
+ max: config.searchConcurrency,
717
+ config,
718
+ }, exec.signal)
719
+ } catch (err) {
720
+ recomputeWarning = `recompute_skipped: ${clip(String(err?.message || err), 200)}`
721
+ }
717
722
  }
718
723
 
719
724
  const planPrompt = [
@@ -768,12 +773,16 @@ export function createWideResearchTool(ctx, config, options = {}) {
768
773
 
769
774
  const completed = outcomes.filter(outcome => outcome.result)
770
775
  const failed = outcomes.filter(outcome => outcome.error)
771
- const warnings = [...stageWarnings, ...failed.map(outcome => `${outcome.track.title}: ${outcome.error}`)]
776
+ const warnings = [
777
+ ...(recomputeWarning ? [recomputeWarning] : []),
778
+ ...stageWarnings,
779
+ ...failed.map(outcome => `${outcome.track.title}: ${outcome.error}`),
780
+ ]
772
781
  if (!completed.length) throw new Error(`wide_research could not complete any research tracks: ${warnings.join('; ')}`)
773
782
 
774
783
  const sources = []
775
784
  const seenUrls = new Set()
776
- completed.map(outcome => {
785
+ const researchLedger = completed.map(outcome => {
777
786
  const sourceKeys = []
778
787
  for (const source of outcome.result.sources) {
779
788
  const normalizedUrl = normalizeSourceUrl(source.url)
@@ -797,14 +806,7 @@ export function createWideResearchTool(ctx, config, options = {}) {
797
806
  question,
798
807
  scope,
799
808
  responseLanguage: language,
800
- researchLedger: completed.map(outcome => ({
801
- track: outcome.track,
802
- summary: outcome.result.summary,
803
- findings: outcome.result.findings,
804
- sourceKeys: outcome.result.sources.map(s => s.key).filter(Boolean),
805
- disagreements: outcome.result.disagreements,
806
- gaps: outcome.result.gaps,
807
- })),
809
+ researchLedger,
808
810
  sources,
809
811
  localSources,
810
812
  recomputedValues,
@@ -11,6 +11,10 @@ import { CSS, renderMarkdown } from '/argo/workbench-md.js'
11
11
 
12
12
  const STATE_KEY = 'argo-workbench:state.v1'
13
13
  const PREFS_KEY = 'argo-workbench:prefs.v1'
14
+ // 每日热点刷新时间选项与默认值(此前两处下拉手抄同一数组,2026-11-20 审计单源化;
15
+ // 默认值须与 workbench-suggestions.js 的 DEFAULT_REFRESH_TIME 保持一致)
16
+ const REFRESH_TIME_OPTIONS = ['07:00', '08:00', '08:30', '09:00', '12:00', '18:00', '20:00', '22:00']
17
+ const DEFAULT_REFRESH_TIME = '08:30'
14
18
 
15
19
  const CORE_MODES = [
16
20
  { id: 'general', label: '全网搜索', desc: '多源快查,先给结论再列出处', ph: '搜任何问题、概念、报错或资料(Enter 发送,Shift+Enter 换行)…' },
@@ -144,17 +148,20 @@ export function mountArgoWorkbench(ctx, react) {
144
148
  }
145
149
 
146
150
  function WorkbenchApp() {
147
- const saved = readStorage(STATE_KEY, null)
151
+ const [initialSaved] = useState(() => readStorage(STATE_KEY, null))
148
152
  const [prefs, setPrefs] = useState(() => readStorage(PREFS_KEY, { selection: true }))
149
153
  const [lang, setLang] = useState(resolveLang)
150
154
  const [view, setView] = useState('home')
151
155
  const [input, setInput] = useState('')
152
- const [activeQuery, setActiveQuery] = useState(saved?.query || '')
156
+ const [activeQuery, setActiveQuery] = useState(() => initialSaved?.query || '')
153
157
  const [mode, setMode] = useState('general')
154
158
  const [topicSamples, setTopicSamples] = useState(() => Object.fromEntries(TOPIC_CARDS.map(t => [t.id, pickSample(t.samples)])))
155
159
  const [suggestions, setSuggestions] = useState([])
156
- const [cards, setCards] = useState(saved?.cards || [])
157
- const [turns, setTurns] = useState(saved?.turns || [])
160
+ const [hotspotMeta, setHotspotMeta] = useState({ refreshTime: '08:30', lastRefreshedAt: '' })
161
+ const [hotspotBusy, setHotspotBusy] = useState(false)
162
+ const [hotspotNote, setHotspotNote] = useState('')
163
+ const [cards, setCards] = useState(() => initialSaved?.cards || [])
164
+ const [turns, setTurns] = useState(() => initialSaved?.turns || [])
158
165
  const [stageText, setStageText] = useState('')
159
166
  const [loading, setLoading] = useState(false)
160
167
  const [filter, setFilter] = useState('all')
@@ -173,10 +180,18 @@ export function mountArgoWorkbench(ctx, react) {
173
180
  const inputRef = useRef(null)
174
181
  const esRef = useRef(null)
175
182
  const abortRef = useRef(null)
183
+ const modeRef = useRef(mode)
184
+ const startSearchRef = useRef(null)
185
+ const suggestSeqRef = useRef(0)
186
+ modeRef.current = mode
176
187
 
177
188
  useEffect(() => {
178
- writeStorage(STATE_KEY, { query: activeQuery, mode, cards, turns })
179
- }, [activeQuery, mode, cards, turns])
189
+ if (loading) return undefined
190
+ const t = setTimeout(() => {
191
+ writeStorage(STATE_KEY, { query: activeQuery, mode, cards, turns })
192
+ }, 400)
193
+ return () => clearTimeout(t)
194
+ }, [activeQuery, mode, cards, turns, loading])
180
195
 
181
196
  const refreshWatches = async () => {
182
197
  try {
@@ -187,10 +202,14 @@ export function mountArgoWorkbench(ctx, react) {
187
202
  }
188
203
 
189
204
  const refreshSuggestions = async (targetMode = mode, targetLang = lang, shuffle = false) => {
205
+ const seq = ++suggestSeqRef.current
190
206
  try {
191
207
  const res = await fetch(`/argo/api/suggestions?mode=${encodeURIComponent(targetMode)}&lang=${encodeURIComponent(targetLang)}&shuffle=${shuffle ? '1' : '0'}`)
192
208
  const data = await res.json()
193
- if (Array.isArray(data?.items)) setSuggestions(data.items)
209
+ if (seq === suggestSeqRef.current && Array.isArray(data?.items)) {
210
+ setSuggestions(data.items)
211
+ if (data.meta) setHotspotMeta(prev => ({ ...prev, ...data.meta }))
212
+ }
194
213
  } catch { /* ignore */ }
195
214
  }
196
215
 
@@ -236,10 +255,6 @@ export function mountArgoWorkbench(ctx, react) {
236
255
  es.addEventListener('evidence', (ev) => { const d = parse(ev); if (d && (d.crossValidation || d.summary)) setEvidenceSummary(d) })
237
256
  es.addEventListener('cards', (ev) => { const d = parse(ev); if (Array.isArray(d.cards)) setCards(d.cards) })
238
257
  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
258
  es.addEventListener('answer', (ev) => {
244
259
  const d = parse(ev)
245
260
  if (!d.delta) return
@@ -253,14 +268,19 @@ export function mountArgoWorkbench(ctx, react) {
253
268
  es.addEventListener('answer-status', (ev) => { const d = parse(ev); if (d.message) setStageText(d.message) })
254
269
  es.addEventListener('done', () => { setLoading(false); setStageText(''); es.close(); esRef.current = null })
255
270
  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) }
271
+ es.onerror = () => {
272
+ es.close()
273
+ if (esRef.current === es) esRef.current = null
274
+ setLoading(false)
275
+ }
257
276
  }
277
+ startSearchRef.current = startSearch
258
278
 
259
279
  useEffect(() => {
260
280
  const handler = (req) => {
261
281
  if (!req) return
262
282
  pendingExternal = null
263
- startSearch(req.query, req.mode || mode)
283
+ startSearchRef.current?.(req.query, req.mode || modeRef.current)
264
284
  }
265
285
  listeners.add(handler)
266
286
  if (pendingExternal) handler(pendingExternal)
@@ -291,6 +311,10 @@ export function mountArgoWorkbench(ctx, react) {
291
311
  body: JSON.stringify({ query: activeQuery, mode, cards, history: historySnapshot, question: q }),
292
312
  signal: ac.signal,
293
313
  })
314
+ if (!res.ok || !res.body) {
315
+ setStageText(`追问失败(HTTP ${res.status})`)
316
+ return
317
+ }
294
318
  const reader = res.body.getReader()
295
319
  const dec = new TextDecoder()
296
320
  let buf = ''
@@ -305,7 +329,8 @@ export function mountArgoWorkbench(ctx, react) {
305
329
  const dataMatch = chunk.match(/^data:\s*(.+)$/m)
306
330
  if (!dataMatch) continue
307
331
  const evName = evMatch ? evMatch[1].trim() : 'message'
308
- const payload = JSON.parse(dataMatch[1])
332
+ let payload
333
+ try { payload = JSON.parse(dataMatch[1]) } catch { continue }
309
334
  if (evName === 'answer' && payload.delta) {
310
335
  setTurns(prev => {
311
336
  const next = [...prev]
@@ -313,6 +338,8 @@ export function mountArgoWorkbench(ctx, react) {
313
338
  if (last && last.role === 'assistant') next[next.length - 1] = { ...last, text: last.text + payload.delta }
314
339
  return next
315
340
  })
341
+ } else if (evName === 'failure' && payload.message) {
342
+ setStageText(`追问出错:${payload.message}`)
316
343
  }
317
344
  }
318
345
  }
@@ -335,7 +362,7 @@ export function mountArgoWorkbench(ctx, react) {
335
362
  const data = await res.json()
336
363
  if (Array.isArray(data.items)) setWatches(data.items)
337
364
  setWatchQuery('')
338
- setWatchOpen(true)
365
+ setPopover('watch') // 抽屉可见性由 popover 状态管(此前引用未定义的 setWatchOpen)
339
366
  } catch { /* ignore */ }
340
367
  }
341
368
 
@@ -369,7 +396,7 @@ export function mountArgoWorkbench(ctx, react) {
369
396
  setMode(w.mode || 'general')
370
397
  setCards(Array.isArray(w.lastCards) ? w.lastCards : [])
371
398
  setTurns([{ role: 'assistant', text: w.lastSummary || '该定时任务尚未生成摘要,可点击「立即执行」或「强制刷新」。' }])
372
- setWatchOpen(false)
399
+ setPopover(null)
373
400
  }
374
401
 
375
402
  const scrollToCard = (cardId) => {
@@ -414,6 +441,49 @@ export function mountArgoWorkbench(ctx, react) {
414
441
  if (next === 'settings') refreshHealth()
415
442
  }
416
443
 
444
+ const updateHotspotRefreshTime = async (refreshTime) => {
445
+ setHotspotMeta(prev => ({ ...prev, refreshTime }))
446
+ try {
447
+ const res = await fetch('/argo/api/suggestions/config', {
448
+ method: 'POST',
449
+ headers: { 'Content-Type': 'application/json' },
450
+ body: JSON.stringify({ refreshTime }),
451
+ })
452
+ const data = await res.json()
453
+ if (data?.ok) {
454
+ const sched = { refreshTime: data.refreshTime, lastRefreshedAt: data.lastRefreshedAt }
455
+ setHotspotMeta(sched)
456
+ setHealthInfo(prev => ({ ...(prev || {}), hotspotSchedule: sched }))
457
+ }
458
+ } catch { /* ignore */ }
459
+ }
460
+
461
+ const refreshHotspotsNow = async () => {
462
+ if (hotspotBusy) return
463
+ setHotspotBusy(true)
464
+ try {
465
+ const res = await fetch('/argo/api/suggestions/config', {
466
+ method: 'POST',
467
+ headers: { 'Content-Type': 'application/json' },
468
+ body: JSON.stringify({ refreshNow: true }),
469
+ })
470
+ const data = await res.json()
471
+ if (data?.skipped === 'lock_busy') {
472
+ // 锁被另一宿主占着:如实提示,不拿旧 lastRefreshedAt 冒充刚刷过
473
+ setHotspotNote(lang === 'en' ? 'Another host is refreshing…' : '另一宿主刷新中…')
474
+ window.setTimeout(() => setHotspotNote(''), 8000)
475
+ } else if (data?.ok) {
476
+ setHotspotNote('')
477
+ const sched = { refreshTime: data.refreshTime, lastRefreshedAt: data.lastRefreshedAt }
478
+ setHotspotMeta(sched)
479
+ setHealthInfo(prev => ({ ...(prev || {}), hotspotSchedule: sched }))
480
+ }
481
+ await refreshSuggestions(modeRef.current, lang, false)
482
+ } catch { /* ignore */ } finally {
483
+ setHotspotBusy(false)
484
+ }
485
+ }
486
+
417
487
  const toggleEgoSearch = async () => {
418
488
  const current = Boolean(healthInfo?.egoSearch?.enabled)
419
489
  try {
@@ -484,7 +554,22 @@ export function mountArgoWorkbench(ctx, react) {
484
554
  if (view === 'home') {
485
555
  return h('div', { className: 'aw-root' },
486
556
  h('div', { className: 'aw-hero' },
487
- h('div', { className: 'aw-hero-top' },
557
+ h('div', { className: 'aw-hero-top', style: { gap: '8px' } },
558
+ h('label', { style: { display: 'inline-flex', alignItems: 'center', gap: '5px', fontSize: '12px', color: 'var(--aw-text-2)' } },
559
+ h('span', null, lang === 'en' ? 'Daily refresh' : '每日热点'),
560
+ h('select', {
561
+ value: hotspotMeta.refreshTime || DEFAULT_REFRESH_TIME,
562
+ onChange: (e) => updateHotspotRefreshTime(e.target.value),
563
+ style: { fontSize: '12px', padding: '2px 6px', borderRadius: '6px', border: '1px solid var(--aw-border)', background: 'var(--aw-sunken)', color: 'inherit' },
564
+ }, REFRESH_TIME_OPTIONS.map(t => h('option', { key: t, value: t }, t)))),
565
+ h('button', {
566
+ type: 'button',
567
+ className: 'aw-icon-btn',
568
+ disabled: hotspotBusy,
569
+ onClick: refreshHotspotsNow,
570
+ }, hotspotBusy
571
+ ? (lang === 'en' ? 'Refreshing…' : '刷新中…')
572
+ : (hotspotNote || (lang === 'en' ? 'Refresh Hotspots' : '刷新热点'))),
488
573
  h('button', { type: 'button', className: 'aw-icon-btn', onClick: toggleWatchPanel }, `定时搜索 (${watches.length})`)),
489
574
  renderWatchDrawer(),
490
575
  h('div', { className: 'aw-hero-inner' },
@@ -641,9 +726,18 @@ export function mountArgoWorkbench(ctx, react) {
641
726
  h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer', marginBottom: '8px' } },
642
727
  h('span', null, '对话划词浮层(Argo 分析)'),
643
728
  h('input', { type: 'checkbox', checked: Boolean(prefs.selection), onChange: toggleSelectionPref })),
644
- h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer' } },
729
+ h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer', marginBottom: '8px' } },
645
730
  h('span', null, '登录态专业搜索(ego-search)'),
646
731
  h('input', { type: 'checkbox', checked: Boolean(healthInfo?.egoSearch?.enabled), onChange: toggleEgoSearch })),
732
+ h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px', marginTop: '8px' } },
733
+ h('span', null, '每日热点更新'),
734
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: '6px' } },
735
+ h('select', {
736
+ value: hotspotMeta.refreshTime || healthInfo?.hotspotSchedule?.refreshTime || DEFAULT_REFRESH_TIME,
737
+ onChange: (e) => updateHotspotRefreshTime(e.target.value),
738
+ style: { fontSize: '12px', padding: '2px 6px', borderRadius: '6px', border: '1px solid var(--aw-border)', background: 'var(--aw-sunken)', color: 'inherit' },
739
+ }, REFRESH_TIME_OPTIONS.map(t => h('option', { key: t, value: t }, t))),
740
+ h('button', { type: 'button', className: 'aw-pill-btn', disabled: hotspotBusy, onClick: refreshHotspotsNow, style: { fontSize: '11px', padding: '2px 8px' } }, hotspotBusy ? '刷新中…' : (hotspotNote || '刷新')))),
647
741
  h('button', {
648
742
  type: 'button',
649
743
  className: 'aw-icon-btn',
@@ -665,7 +759,7 @@ export function mountArgoWorkbench(ctx, react) {
665
759
  }, `交叉验证:${evidenceSummary.crossValidation.corroboration_level || 'unknown'}${evidenceSummary.summary ? ` · 高可信 ${evidenceSummary.summary.high_credibility || 0}` : ''}`) : null,
666
760
  gateResult ? h('span', {
667
761
  className: 'aw-badge',
668
- title: (gateResult.warnings || []).join(';'),
762
+ title: (gateResult.warnings || []).map(w => (typeof w === 'string' ? w : (w?.detail || w?.id || ''))).filter(Boolean).join(';'),
669
763
  style: { background: gateResult.passed ? 'var(--aw-sunken)' : '#fef2f2', color: gateResult.passed ? 'var(--aw-text-2)' : '#b91c1c' },
670
764
  }, gateResult.passed ? '质量门禁通过' : '质量门禁未达标') : null),
671
765
  clarifyInfo ? h('div', { style: { fontSize: '12px', color: 'var(--aw-text-2)', padding: '6px 10px', marginBottom: '10px', borderRadius: '8px', background: 'var(--aw-sunken)' } },
@@ -736,6 +830,7 @@ export function mountArgoWorkbench(ctx, react) {
736
830
  const [hit, setHit] = useState(null)
737
831
 
738
832
  useEffect(() => {
833
+ let timerId = null
739
834
  const checkSelection = () => {
740
835
  const prefs = readStorage(PREFS_KEY, { selection: true })
741
836
  if (!prefs.selection) { setHit(null); return }
@@ -748,10 +843,14 @@ export function mountArgoWorkbench(ctx, react) {
748
843
  if (!rect || (rect.width === 0 && rect.height === 0)) { setHit(null); return }
749
844
  setHit({ text, top: Math.max(12, rect.top - 38), left: Math.min(window.innerWidth - 130, Math.max(12, rect.left)) })
750
845
  }
751
- const onUp = () => setTimeout(checkSelection, 20)
846
+ const onUp = () => {
847
+ if (timerId) clearTimeout(timerId)
848
+ timerId = setTimeout(checkSelection, 20)
849
+ }
752
850
  document.addEventListener('mouseup', onUp)
753
851
  document.addEventListener('keyup', onUp)
754
852
  return () => {
853
+ if (timerId) clearTimeout(timerId)
755
854
  document.removeEventListener('mouseup', onUp)
756
855
  document.removeEventListener('keyup', onUp)
757
856
  }
@@ -0,0 +1,182 @@
1
+ /*
2
+ * @taxueseek/argo-dsh — 工作台 I/O 与进程执行辅助(CLI 定位、静态资源缓存、定时监控持久化)
3
+ */
4
+
5
+ import { spawn } from 'node:child_process'
6
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
7
+ import { homedir } from 'node:os'
8
+ import { dirname, join } from 'node:path'
9
+ import { fileURLToPath } from 'node:url'
10
+ import { resolveStateDir } from './diagnostics.js'
11
+
12
+ const HERE = dirname(fileURLToPath(import.meta.url))
13
+ const MONOREPO_ARGO_BIN = join(HERE, '..', '..', '..', 'bin', 'argo')
14
+ // install.sh 默认安装根(ARGO_HOME 可改,此处只探测默认路径——探测不到就走
15
+ // console script 的 PATH 兜底,不猜 site-packages 里的 wheel _data 布局)
16
+ const INSTALL_VENV_ARGO_BIN = join(homedir(), '.local', 'share', 'argo', '.venv', 'bin', 'argo')
17
+ const INSTALL_VENV_ARGO_BIN_WIN = join(
18
+ process.env.LOCALAPPDATA || join(homedir(), 'AppData', 'Local'),
19
+ 'argo', '.venv', 'Scripts', 'argo.exe',
20
+ )
21
+ export const WATCH_STORE_FILE = join(homedir(), '.config', 'argo', 'workbench-watches.json')
22
+
23
+ export function mergedLaunchdPath(env = {}, platform = process.platform) {
24
+ const basePath = env.PATH || env.Path || process.env.PATH || process.env.Path || ''
25
+ if (platform === 'win32') return basePath
26
+ const extraPath = ['/opt/homebrew/bin', '/usr/local/bin', join(homedir(), '.local', 'bin')].join(':')
27
+ return basePath ? `${extraPath}:${basePath}` : extraPath
28
+ }
29
+
30
+ // 2026-11-20 审计:npm 发布版插件装在 DSH 缓存目录时 MONOREPO_ARGO_BIN 不存在,
31
+ // 裸名 'argo' 又依赖 PATH——launchd/受限 PATH 下 venv console script 可能不可达。
32
+ // 修法加候选不重排:显式 ARGO_BIN 最优先(用户指路零猜测),其次 monorepo、
33
+ // install.sh 默认 venv,最后裸名走 PATH。
34
+ export function resolveArgoBin(env = {}, platform = process.platform) {
35
+ const explicit = env.ARGO_BIN || process.env.ARGO_BIN
36
+ if (explicit) return explicit
37
+ if (existsSync(MONOREPO_ARGO_BIN)) return MONOREPO_ARGO_BIN
38
+ if (platform === 'win32' && existsSync(INSTALL_VENV_ARGO_BIN_WIN)) return INSTALL_VENV_ARGO_BIN_WIN
39
+ if (existsSync(INSTALL_VENV_ARGO_BIN)) return INSTALL_VENV_ARGO_BIN
40
+ return 'argo'
41
+ }
42
+
43
+ // Windows CreateProcess 不识别 shebang:若解析到无后缀 bin/argo 或 .py 脚本,自动用 Python 解释器包装
44
+ export function resolveSpawnCommand(bin, args = [], env = {}, platform = process.platform) {
45
+ if (platform === 'win32' && (/[\\/]bin[\\/]argo$/i.test(bin) || /\.py$/i.test(bin))) {
46
+ const py = env.ARGO_PYTHON || process.env.ARGO_PYTHON || 'python'
47
+ return { cmd: py, argv: [bin, ...args] }
48
+ }
49
+ return { cmd: bin, argv: args }
50
+ }
51
+
52
+ export function runArgoCli(args, { env = {}, stdin = null, timeoutMs = 30000, signal = null } = {}) {
53
+ const mergedPath = mergedLaunchdPath(env)
54
+ return new Promise((resolve, reject) => {
55
+ if (signal?.aborted) { reject(new Error('aborted')); return }
56
+ const bin = resolveArgoBin({ ...env, PATH: mergedPath })
57
+ const { cmd, argv } = resolveSpawnCommand(bin, args, env)
58
+ const child = spawn(cmd, argv, {
59
+ env: { ...process.env, ...env, PATH: mergedPath },
60
+ stdio: ['pipe', 'pipe', 'pipe'],
61
+ })
62
+ const out = []
63
+ const err = []
64
+ const timer = setTimeout(() => {
65
+ // 超时路径也要摘掉 abort 监听器:长生命周期 AbortSignal 下残留会累积
66
+ signal?.removeEventListener('abort', onAbort)
67
+ child.kill('SIGTERM')
68
+ reject(new Error(`argo ${args[0] || ''} timeout (${timeoutMs}ms)`))
69
+ }, timeoutMs)
70
+ if (typeof timer.unref === 'function') timer.unref()
71
+ const onAbort = () => {
72
+ clearTimeout(timer)
73
+ child.kill('SIGTERM')
74
+ reject(new Error('aborted'))
75
+ }
76
+ signal?.addEventListener('abort', onAbort, { once: true })
77
+ child.stdout.on('data', d => out.push(d))
78
+ child.stderr.on('data', d => err.push(d))
79
+ child.on('error', (e) => {
80
+ clearTimeout(timer)
81
+ signal?.removeEventListener('abort', onAbort)
82
+ reject(e)
83
+ })
84
+ child.on('close', (code) => {
85
+ clearTimeout(timer)
86
+ signal?.removeEventListener('abort', onAbort)
87
+ const text = Buffer.concat(out).toString('utf8').trim()
88
+ if (code !== 0 && !text) {
89
+ reject(new Error(Buffer.concat(err).toString('utf8').trim() || `argo exit ${code}`))
90
+ return
91
+ }
92
+ try {
93
+ resolve(JSON.parse(text || '{}'))
94
+ } catch {
95
+ reject(new Error(`invalid json from argo ${args[0] || ''}`))
96
+ }
97
+ })
98
+ child.stdin.on('error', () => {})
99
+ if (stdin !== null && stdin !== undefined) {
100
+ child.stdin.end(typeof stdin === 'string' ? stdin : JSON.stringify(stdin))
101
+ } else {
102
+ child.stdin.end()
103
+ }
104
+ })
105
+ }
106
+
107
+ const staticAssetCache = new Map()
108
+
109
+ export function readStaticAssetCached(filePath) {
110
+ const st = statSync(filePath)
111
+ const hit = staticAssetCache.get(filePath)
112
+ if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size) {
113
+ return hit.text
114
+ }
115
+ const text = readFileSync(filePath, 'utf8')
116
+ staticAssetCache.set(filePath, { mtimeMs: st.mtimeMs, size: st.size, text })
117
+ return text
118
+ }
119
+
120
+ export function loadWatches(file = WATCH_STORE_FILE) {
121
+ try {
122
+ const raw = readFileSync(file, 'utf8')
123
+ const parsed = JSON.parse(raw)
124
+ return Array.isArray(parsed) ? parsed : []
125
+ } catch {
126
+ return []
127
+ }
128
+ }
129
+
130
+ export function saveWatches(items, file = WATCH_STORE_FILE) {
131
+ try {
132
+ mkdirSync(dirname(file), { recursive: true })
133
+ const uniq = `${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2, 6)}`
134
+ const tmp = `${file}.tmp.${uniq}`
135
+ writeFileSync(tmp, JSON.stringify(items, null, 2), 'utf8')
136
+ renameSync(tmp, file)
137
+ } catch { /* ignore */ }
138
+ }
139
+
140
+ // 跨进程状态文件互斥(wx 独占创建,语义对齐 scripts/pacing.py 的非阻塞文件锁):
141
+ // 抢不到返回 null 让调用方让路;崩溃残留超 staleMs 强取自愈。
142
+ // 热榜与 watches 共用同一实现,消灭各自手抄(2026-11-21 审计:锁方案四家并存)。
143
+ export function acquireStateFileLock(file, staleMs = 5 * 60 * 1000) {
144
+ try {
145
+ mkdirSync(dirname(file), { recursive: true })
146
+ return { fd: openSync(file, 'wx'), lockFile: file }
147
+ } catch (err) {
148
+ if (err?.code !== 'EEXIST') return null
149
+ try {
150
+ if (Date.now() - statSync(file).mtimeMs > staleMs) {
151
+ unlinkSync(file)
152
+ return { fd: openSync(file, 'wx'), lockFile: file }
153
+ }
154
+ } catch { /* 对方刚释放或刚重建,本轮回让路 */ }
155
+ return null
156
+ }
157
+ }
158
+
159
+ export function releaseStateFileLock(lock) {
160
+ if (!lock) return
161
+ try { closeSync(lock.fd) } catch { /* ignore */ }
162
+ try { unlinkSync(lock.lockFile) } catch { /* ignore */ }
163
+ }
164
+
165
+ // watches 唯一真源是磁盘文件:读-改-写全程持锁,内存副本只作缓存。
166
+ // 旧「内存快照 + 全量覆盖写」在多宿主下互相抹改(2026-11-21 审计 P1)。
167
+ // 返回 null 表示锁被占(另一宿主写盘中),调用方按忙处理。
168
+ export function mutateWatches(mutator, file = WATCH_STORE_FILE) {
169
+ const lock = acquireStateFileLock(`${file}.lock`)
170
+ if (!lock) return null
171
+ try {
172
+ const next = mutator(loadWatches(file))
173
+ if (Array.isArray(next)) saveWatches(next, file)
174
+ return Array.isArray(next) ? next : loadWatches(file)
175
+ } finally {
176
+ releaseStateFileLock(lock)
177
+ }
178
+ }
179
+
180
+ export function breakerFilePath() {
181
+ return join(resolveStateDir(), 'circuit_breaker.json')
182
+ }