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.
- package/AGENTS.md +3 -1
- package/README.es.md +32 -5
- package/README.ja.md +32 -5
- package/README.ko.md +32 -5
- package/README.md +73 -19
- package/README.zh.md +73 -19
- package/SKILL.md +7 -7
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +3 -3
- package/assets/readme/hero.template.svg +121 -0
- package/assets/readme/proof-routes.svg +17 -16
- package/backends/domain_profiles.json +222 -24
- package/backends/engine_registry.yaml +26 -2
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +23 -3
- package/bin/argo +3 -0
- package/config.yaml +16 -0
- package/docs/CHANGELOG.md +31 -0
- package/docs/COMMIT_STANDARD.md +10 -0
- package/docs/ENGINE_CATALOG.md +40 -37
- package/docs/MCP_SETUP.md +9 -0
- package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
- package/docs/RELEASE_NOTES_v2.17.0.md +64 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/archive_org.yaml +1 -1
- package/engines/specs/carbon_intensity.yaml +1 -1
- package/engines/specs/crates.yaml +1 -1
- package/engines/specs/crossref.yaml +6 -2
- package/engines/specs/crt_sh.yaml +1 -1
- package/engines/specs/dblp.yaml +1 -1
- package/engines/specs/devto.yaml +1 -1
- package/engines/specs/docker_hub.yaml +1 -1
- package/engines/specs/europepmc.yaml +1 -1
- package/engines/specs/fxtwitter.yaml +1 -1
- package/engines/specs/gbfs_nyc.yaml +1 -1
- package/engines/specs/gleif.yaml +1 -1
- package/engines/specs/gov_regulations.yaml +1 -1
- package/engines/specs/hackernews.yaml +2 -0
- package/engines/specs/helve.yaml +49 -0
- package/engines/specs/hf_datasets.yaml +1 -1
- package/engines/specs/hf_papers.yaml +2 -0
- package/engines/specs/huggingface.yaml +1 -1
- package/engines/specs/keenable.yaml +7 -1
- package/engines/specs/linux_do.yaml +63 -0
- package/engines/specs/local_crossref.yaml +3 -1
- package/engines/specs/local_github.yaml +1 -1
- package/engines/specs/local_npm.yaml +6 -0
- package/engines/specs/local_openstreetmap.yaml +1 -1
- package/engines/specs/maven.yaml +1 -1
- package/engines/specs/mdn.yaml +1 -1
- package/engines/specs/musicbrainz.yaml +1 -1
- package/engines/specs/nasa_images.yaml +1 -1
- package/engines/specs/nhtsa_vpic.yaml +6 -3
- package/engines/specs/npm.yaml +1 -1
- package/engines/specs/nuget.yaml +1 -1
- package/engines/specs/nvd.yaml +1 -1
- package/engines/specs/openalex.yaml +13 -4
- package/engines/specs/openreview.yaml +1 -1
- package/engines/specs/polymarket.yaml +1 -1
- package/engines/specs/sec_edgar.yaml +1 -1
- package/engines/specs/steam.yaml +1 -1
- package/engines/specs/vam.yaml +1 -1
- package/engines/specs/wikidata.yaml +1 -1
- package/engines/specs/wikipedia.yaml +1 -1
- package/engines/specs/zhihu_hot_app.yaml +1 -1
- package/package.json +3 -1
- package/packages/dsh-plugin/README.md +5 -2
- package/packages/dsh-plugin/cordis.patch.yml +4 -1
- package/packages/dsh-plugin/dsh/client.js +69 -74
- package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
- package/packages/dsh-plugin/dsh/index.js +115 -21
- package/packages/dsh-plugin/dsh/route-guard.js +95 -0
- package/packages/dsh-plugin/dsh/runner.js +50 -7
- package/packages/dsh-plugin/dsh/wide-research.js +20 -18
- package/packages/dsh-plugin/dsh/workbench-client.js +895 -0
- package/packages/dsh-plugin/dsh/workbench-io.js +163 -0
- package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
- package/packages/dsh-plugin/dsh/workbench-search.js +385 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +460 -0
- package/packages/dsh-plugin/dsh/workbench.js +703 -0
- package/packages/dsh-plugin/icon.svg +23 -0
- package/packages/dsh-plugin/package.json +6 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
- package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
- package/packages/dsh-plugin/test/client.test.js +26 -0
- package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
- package/packages/dsh-plugin/test/index.test.js +150 -1
- package/packages/dsh-plugin/test/workbench-concurrency.test.js +98 -0
- package/packages/dsh-plugin/test/workbench.test.js +420 -0
- package/scripts/adaptive.py +13 -11
- package/scripts/argo_paths.py +2 -2
- package/scripts/badcase_ledger.py +9 -0
- package/scripts/browser_auth.py +178 -4
- package/scripts/cache.py +69 -70
- package/scripts/check_commit_report.py +46 -0
- package/scripts/chrome_cdp.py +71 -0
- package/scripts/circuit_breaker.py +91 -13
- package/scripts/config_cache.py +23 -10
- package/scripts/daemon.py +14 -2
- package/scripts/engine_add.py +45 -0
- package/scripts/engine_dispatch.py +32 -49
- package/scripts/engine_env.py +13 -4
- package/scripts/engine_failure.py +33 -0
- package/scripts/engine_fingerprint.py +114 -0
- package/scripts/engine_health.py +130 -0
- package/scripts/engine_states.py +50 -0
- package/scripts/engines_base.py +31 -19
- package/scripts/engines_builders_archive.py +4 -3
- package/scripts/engines_builders_batch11.py +2 -1
- package/scripts/engines_builders_batch13.py +4 -3
- package/scripts/engines_builders_batch14.py +2 -1
- package/scripts/engines_builders_batch15.py +2 -1
- package/scripts/engines_builders_batch9.py +2 -2
- package/scripts/engines_builders_cn.py +7 -7
- package/scripts/engines_builders_data.py +12 -11
- package/scripts/engines_builders_data_macro.py +5 -4
- package/scripts/engines_builders_dsh.py +2 -1
- package/scripts/engines_builders_feeds.py +34 -19
- package/scripts/engines_builders_finance.py +2 -1
- package/scripts/engines_builders_intl.py +3 -2
- package/scripts/engines_builders_media.py +59 -12
- package/scripts/engines_builders_science.py +8 -7
- package/scripts/engines_builders_search.py +19 -8
- package/scripts/engines_builders_skill.py +2 -1
- package/scripts/engines_builders_tech.py +19 -19
- package/scripts/engines_builders_weather.py +9 -4
- package/scripts/engines_fields.py +23 -0
- package/scripts/engines_http.py +50 -1
- package/scripts/engines_mcp.py +28 -6
- package/scripts/evidence_grounding.py +182 -0
- package/scripts/evidence_loop.py +15 -1
- package/scripts/extend_route_labels.py +6 -0
- package/scripts/fetch_browser.py +25 -10
- package/scripts/fetch_jina.py +98 -0
- package/scripts/fetch_v3.py +52 -93
- package/scripts/gate_manifest_check.py +75 -0
- package/scripts/gen_readme_art.py +264 -0
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/install.sh +2 -0
- package/scripts/matrix_search_eval.py +8 -10
- package/scripts/mcp_transport.py +33 -9
- package/scripts/numeric_verify.py +12 -2
- package/scripts/output_transparency.py +3 -0
- package/scripts/pre-commit +57 -8
- package/scripts/query_operators.py +229 -1
- package/scripts/quota.py +46 -63
- package/scripts/recovery.py +19 -16
- package/scripts/recovery_runner.py +29 -10
- package/scripts/redskill/redskill_engine.py +2 -1
- package/scripts/release.py +16 -1
- package/scripts/research_gates.py +85 -1
- package/scripts/route.py +8 -0
- package/scripts/route_combo.py +24 -3
- package/scripts/route_policy.py +1 -1
- package/scripts/search_attribution.py +20 -0
- package/scripts/search_entry.py +27 -0
- package/scripts/search_output.py +18 -7
- package/scripts/search_pipeline.py +3 -3
- package/scripts/semantic_evidence.py +20 -11
- package/scripts/serp_guard.py +13 -1
- package/scripts/settings_page.py +1 -0
- package/scripts/single_flight.py +1 -1
- package/scripts/social_engines/hackernews_engine.py +2 -1
- package/scripts/social_engines/reddit_engine.py +2 -1
- package/scripts/social_engines/zhihu_engine.py +2 -1
- package/scripts/source_audit.py +42 -7
- package/scripts/source_discovery.py +611 -0
- package/scripts/sync_backends.py +45 -0
- package/scripts/usage_log.py +24 -9
- package/scripts/watch.py +3 -3
- package/scripts/zhihu_quota.py +2 -1
- package/sub-skills/argo-wide-research/SKILL.md +7 -5
- package/sub-skills/ego-search/{SKILL.md → README.md} +24 -47
- package/sub-skills/ego-search/scripts/ego_search.py +195 -19
- package/sub-skills/ego-search/scripts/pacing.py +291 -0
- package/sub-skills/ego-search/scripts/quality.py +262 -6
- package/sub-skills/ego-search/scripts/runtime.py +7 -1
- package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
- package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
- package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
- package/sub-skills/local-search/engine_registry.py +32 -7
- package/sub-skills/local-seek/SKILL.md +20 -22
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { EventEmitter } from 'node:events'
|
|
4
|
+
import { Readable } from 'node:stream'
|
|
5
|
+
import { buildSearchCliArgs, createWorkbenchHandler } from '../dsh/workbench.js'
|
|
6
|
+
|
|
7
|
+
function mockReq(method, url, bodyObj = null) {
|
|
8
|
+
const req = bodyObj !== null ? Readable.from([Buffer.from(JSON.stringify(bodyObj))]) : new EventEmitter()
|
|
9
|
+
req.method = method
|
|
10
|
+
req.url = url
|
|
11
|
+
req.headers = { host: '127.0.0.1:8080' }
|
|
12
|
+
return req
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function mockRes() {
|
|
16
|
+
const headers = {}
|
|
17
|
+
let chunks = ''
|
|
18
|
+
return {
|
|
19
|
+
statusCode: 200,
|
|
20
|
+
writableEnded: false,
|
|
21
|
+
destroyed: false,
|
|
22
|
+
headersSent: false,
|
|
23
|
+
// 保真 Node 语义:flushHeaders 后再 setHeader 抛 ERR_HTTP_HEADERS_SENT
|
|
24
|
+
flushHeaders() { this.headersSent = true },
|
|
25
|
+
setHeader(k, v) {
|
|
26
|
+
if (this.headersSent) throw new Error('ERR_HTTP_HEADERS_SENT')
|
|
27
|
+
headers[k.toLowerCase()] = v
|
|
28
|
+
},
|
|
29
|
+
writeHead(code, hdrs = {}) {
|
|
30
|
+
this.statusCode = code
|
|
31
|
+
for (const [k, v] of Object.entries(hdrs)) headers[k.toLowerCase()] = v
|
|
32
|
+
},
|
|
33
|
+
write(data = '') { chunks += String(data); return true },
|
|
34
|
+
end(data = '') {
|
|
35
|
+
chunks += String(data)
|
|
36
|
+
this.writableEnded = true
|
|
37
|
+
},
|
|
38
|
+
json() { return JSON.parse(chunks || '{}') },
|
|
39
|
+
text() { return chunks },
|
|
40
|
+
headers,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
test('workbench /argo/api/health exposes local mode, egoSearch and breaker summary', async () => {
|
|
45
|
+
const handler = createWorkbenchHandler({}, {}, () => ({}))
|
|
46
|
+
try {
|
|
47
|
+
const res = mockRes()
|
|
48
|
+
await handler(mockReq('GET', '/argo/api/health'), res)
|
|
49
|
+
assert.equal(res.statusCode, 200, res.text())
|
|
50
|
+
const data = res.json()
|
|
51
|
+
assert.equal(data.ok, true)
|
|
52
|
+
assert.ok(Array.isArray(data.modes))
|
|
53
|
+
assert.ok(data.modes.some(m => m.id === 'local'))
|
|
54
|
+
assert.ok(data.modes.some(m => m.id === 'plugin'))
|
|
55
|
+
assert.equal(typeof data.egoSearch?.enabled, 'boolean')
|
|
56
|
+
assert.equal(typeof data.breaker?.total, 'number')
|
|
57
|
+
} finally {
|
|
58
|
+
handler.dispose()
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test('workbench serves workbench-client.js and rejects missing query on /argo/api/stream', async () => {
|
|
63
|
+
const handler = createWorkbenchHandler({}, {}, () => ({}))
|
|
64
|
+
try {
|
|
65
|
+
const resJs = mockRes()
|
|
66
|
+
await handler(mockReq('GET', '/argo/workbench-client.js'), resJs)
|
|
67
|
+
assert.equal(resJs.statusCode, 200)
|
|
68
|
+
assert.ok(resJs.text().includes('mountArgoWorkbench'))
|
|
69
|
+
|
|
70
|
+
const resErr = mockRes()
|
|
71
|
+
await handler(mockReq('GET', '/argo/api/stream?mode=plugin'), resErr)
|
|
72
|
+
assert.equal(resErr.statusCode, 400)
|
|
73
|
+
assert.equal(resErr.json().error, 'missing_query')
|
|
74
|
+
} finally {
|
|
75
|
+
handler.dispose()
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('workbench /argo/api/suggestions adapts to mode and DSH locale', async () => {
|
|
80
|
+
const handler = createWorkbenchHandler({}, {}, () => ({}))
|
|
81
|
+
try {
|
|
82
|
+
const resZh = mockRes()
|
|
83
|
+
await handler(mockReq('GET', '/argo/api/suggestions?mode=hotspot&lang=zh'), resZh)
|
|
84
|
+
assert.equal(resZh.statusCode, 200)
|
|
85
|
+
const zh = resZh.json()
|
|
86
|
+
assert.equal(zh.ok, true)
|
|
87
|
+
assert.equal(zh.lang, 'zh')
|
|
88
|
+
assert.ok(zh.items.length > 0)
|
|
89
|
+
|
|
90
|
+
const resEn = mockRes()
|
|
91
|
+
await handler(mockReq('GET', '/argo/api/suggestions?mode=plugin&lang=en'), resEn)
|
|
92
|
+
assert.equal(resEn.statusCode, 200)
|
|
93
|
+
const en = resEn.json()
|
|
94
|
+
assert.equal(en.ok, true)
|
|
95
|
+
assert.equal(en.lang, 'en')
|
|
96
|
+
assert.ok(en.items.length > 0)
|
|
97
|
+
const enTags = new Set(['For You', 'Hot', 'Watch', 'Recent', 'Guide'])
|
|
98
|
+
assert.ok(en.items.every(it => enTags.has(it.tag)))
|
|
99
|
+
} finally {
|
|
100
|
+
handler.dispose()
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('workbench uses host default model without overriding maxTokens and surfaces real LLM failure', async () => {
|
|
105
|
+
let capturedOpts
|
|
106
|
+
const mockCtx = {
|
|
107
|
+
get(name) {
|
|
108
|
+
if (name === 'agentDefaultModel') return { currentSelection: () => ({ provider: 'commandcode', model: 'deepseek/deepseek-v4.1-flash' }) }
|
|
109
|
+
if (name === 'llm') {
|
|
110
|
+
return {
|
|
111
|
+
async *stream(opts) {
|
|
112
|
+
capturedOpts = opts
|
|
113
|
+
yield { type: 'finish', reason: { kind: 'error', failure: { message: 'finish_reason=length' } } }
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return undefined
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
const handler = createWorkbenchHandler(mockCtx, {}, () => ({}))
|
|
121
|
+
try {
|
|
122
|
+
const res = mockRes()
|
|
123
|
+
await handler(mockReq('POST', '/argo/api/followup', {
|
|
124
|
+
query: 'test',
|
|
125
|
+
mode: 'general',
|
|
126
|
+
question: 'why?',
|
|
127
|
+
cards: [{ index: 1, title: 'T', url: 'https://example.com', domain: 'example.com', snippet: 'S' }],
|
|
128
|
+
}), res)
|
|
129
|
+
assert.equal(res.statusCode, 200, res.text())
|
|
130
|
+
assert.equal(capturedOpts.provider, 'commandcode')
|
|
131
|
+
assert.equal(capturedOpts.model, 'deepseek/deepseek-v4.1-flash')
|
|
132
|
+
assert.equal(capturedOpts.maxTokens, undefined)
|
|
133
|
+
assert.equal(capturedOpts.reasoningEffort, undefined)
|
|
134
|
+
assert.ok(res.text().includes('commandcode/deepseek/deepseek-v4.1-flash'))
|
|
135
|
+
assert.ok(res.text().includes('finish_reason=length'))
|
|
136
|
+
assert.ok(!res.text().includes('未配置默认模型'))
|
|
137
|
+
} finally {
|
|
138
|
+
handler.dispose()
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('workbench followup tolerates null cards/history entries without hanging the SSE response', async () => {
|
|
143
|
+
// 2026-11-18 实跑复现:cards:[null] 在 flushHeaders 后于 buildEvidenceContext
|
|
144
|
+
// 抛 TypeError → catch 落 sendJson → setHeader 二次抛 ERR_HTTP_HEADERS_SENT
|
|
145
|
+
// → 响应永久悬挂。修复=入口元素过滤 + sendJson 判 headersSent 改发 SSE failure。
|
|
146
|
+
let capturedMessages
|
|
147
|
+
const mockCtx = {
|
|
148
|
+
get(name) {
|
|
149
|
+
if (name === 'agentDefaultModel') return { currentSelection: () => ({ provider: 'p', model: 'm' }) }
|
|
150
|
+
if (name === 'llm') {
|
|
151
|
+
return {
|
|
152
|
+
async *stream(opts) {
|
|
153
|
+
capturedMessages = opts.messages
|
|
154
|
+
yield { type: 'finish', reason: { kind: 'stop' } }
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return undefined
|
|
159
|
+
},
|
|
160
|
+
}
|
|
161
|
+
const handler = createWorkbenchHandler(mockCtx, {}, () => ({}))
|
|
162
|
+
try {
|
|
163
|
+
const res = mockRes()
|
|
164
|
+
await handler(mockReq('POST', '/argo/api/followup', {
|
|
165
|
+
query: 'test',
|
|
166
|
+
mode: 'general',
|
|
167
|
+
question: 'why?',
|
|
168
|
+
cards: [null, 'garbage', { index: 1, title: 'T', url: 'https://example.com', domain: 'example.com', snippet: 'S' }],
|
|
169
|
+
history: [null, { role: 'user', text: 'previous turn' }],
|
|
170
|
+
}), res)
|
|
171
|
+
assert.equal(res.statusCode, 200)
|
|
172
|
+
assert.equal(res.writableEnded, true, '响应必须干净收尾,不得悬挂')
|
|
173
|
+
assert.ok(res.text().includes('event: done'), `应以 done 事件收尾,实际: ${res.text().slice(-160)}`)
|
|
174
|
+
// 合法 history 条目应过滤后到达模型(null 条目被剔除、合法条目保留)
|
|
175
|
+
const flattened = JSON.stringify(capturedMessages)
|
|
176
|
+
assert.ok(flattened.includes('previous turn'), '合法 history 条目应到达模型')
|
|
177
|
+
assert.ok(!flattened.includes('null'), 'null 条目不得混入 messages')
|
|
178
|
+
} finally {
|
|
179
|
+
handler.dispose()
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test('workbench CLI args keep every flag before `--` so dash-leading queries stay literal', () => {
|
|
184
|
+
const args = buildSearchCliArgs('--list-engines', 'general', true, { verify: 2 })
|
|
185
|
+
const sep = args.indexOf('--')
|
|
186
|
+
assert.ok(sep > 0, `必须存在 -- 分隔,实际 ${JSON.stringify(args)}`)
|
|
187
|
+
assert.equal(args[sep + 1], '--list-engines', 'query 必须紧跟 -- 之后')
|
|
188
|
+
assert.equal(args[args.length - 1], '--list-engines')
|
|
189
|
+
assert.ok(args.slice(0, sep).includes('--json'), 'flag 必须全部前置到 -- 之前')
|
|
190
|
+
assert.ok(args.slice(0, sep).includes('--no-cache'), 'refresh 的 --no-cache 也须前置')
|
|
191
|
+
assert.ok(!args.slice(0, sep).includes('--list-engines'), 'query 不得混入 flag 区')
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test('workbench research gate passes when stats are supplied alongside valid citations', async () => {
|
|
195
|
+
const { evaluateGates } = await import('../dsh/wide-research.js')
|
|
196
|
+
const gate = evaluateGates({
|
|
197
|
+
answer: '核心结论基于多源证据 [1][2][3]。',
|
|
198
|
+
sources: [
|
|
199
|
+
{ url: 'https://a.example.com/1', title: 'A', domain: 'a.example.com' },
|
|
200
|
+
{ url: 'https://b.example.com/2', title: 'B', domain: 'b.example.com' },
|
|
201
|
+
{ url: 'https://c.example.com/3', title: 'C', domain: 'c.example.com' },
|
|
202
|
+
],
|
|
203
|
+
tracks: [{ id: 't1', title: 'T1' }],
|
|
204
|
+
warnings: [],
|
|
205
|
+
stats: { sourceCount: 3, completedTracks: 1, failedTracks: 0 },
|
|
206
|
+
})
|
|
207
|
+
assert.equal(gate.passed, true)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test('index apply re-registers envResolver after dispose (HMR safe) and sets rc.5 provider metadata', async () => {
|
|
211
|
+
const { apply } = await import('../dsh/index.js')
|
|
212
|
+
const { resolveEnv } = await import('../dsh/runner.js')
|
|
213
|
+
const cleanups = []
|
|
214
|
+
const registered = []
|
|
215
|
+
const mkCtx = () => ({
|
|
216
|
+
effect: (fn) => { const off = fn(); if (typeof off === 'function') cleanups.push(off) },
|
|
217
|
+
tools: { register: () => () => {}, guard: () => () => {} },
|
|
218
|
+
subagents: {},
|
|
219
|
+
systemPrompt: { section: () => () => {} },
|
|
220
|
+
web: {
|
|
221
|
+
registerSearchProvider: (p) => { registered.push(p); return () => {} },
|
|
222
|
+
registerFetchProvider: (p) => { registered.push(p); return () => {} },
|
|
223
|
+
search: async () => ({ sources: [] }),
|
|
224
|
+
searchReady: async () => true,
|
|
225
|
+
},
|
|
226
|
+
get: () => undefined,
|
|
227
|
+
})
|
|
228
|
+
apply(mkCtx(), { nativeTools: [] })
|
|
229
|
+
while (cleanups.length) cleanups.pop()()
|
|
230
|
+
// 二次 apply 模拟同进程 HMR 重载
|
|
231
|
+
apply(mkCtx(), { nativeTools: [], argoEnv: ['ARGO_NO_CACHE=1'] })
|
|
232
|
+
const env = await resolveEnv({}, { argoEnv: ['ARGO_NO_CACHE=1'], keyRefs: [] })
|
|
233
|
+
assert.equal(env?.ARGO_NO_CACHE, '1')
|
|
234
|
+
const searchProv = registered.find(p => p.id === 'argo' && typeof p.search === 'function')
|
|
235
|
+
assert.ok(searchProv?.title)
|
|
236
|
+
assert.ok(searchProv?.description)
|
|
237
|
+
assert.equal(typeof searchProv?.ready, 'function')
|
|
238
|
+
while (cleanups.length) cleanups.pop()()
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
test('workbench /argo/api/* enforces TCP peer loopback fence against spoofed headers', async () => {
|
|
242
|
+
const handler = createWorkbenchHandler({}, {}, () => ({}))
|
|
243
|
+
try {
|
|
244
|
+
// 局域网对端即使伪造 Host: 127.0.0.1 + X-Forwarded-For: 127.0.0.1 且不带 Origin 也必须被拒
|
|
245
|
+
const lanReq = mockReq('GET', '/argo/api/health')
|
|
246
|
+
lanReq.socket = { remoteAddress: '192.168.1.50' }
|
|
247
|
+
lanReq.headers = { host: '127.0.0.1:8080', 'x-forwarded-for': '127.0.0.1' }
|
|
248
|
+
const lanRes = mockRes()
|
|
249
|
+
await handler(lanReq, lanRes)
|
|
250
|
+
assert.equal(lanRes.statusCode, 403)
|
|
251
|
+
assert.equal(lanRes.json().error, 'forbidden_origin')
|
|
252
|
+
|
|
253
|
+
// 本机 IPv4-mapped 回环放行,但跨站 Origin 仍被拦(防 DNS rebinding)
|
|
254
|
+
const okReq = mockReq('GET', '/argo/api/health')
|
|
255
|
+
okReq.socket = { remoteAddress: '::ffff:127.0.0.1' }
|
|
256
|
+
const okRes = mockRes()
|
|
257
|
+
await handler(okReq, okRes)
|
|
258
|
+
assert.equal(okRes.statusCode, 200)
|
|
259
|
+
|
|
260
|
+
const badOriginReq = mockReq('GET', '/argo/api/health')
|
|
261
|
+
badOriginReq.socket = { remoteAddress: '127.0.0.1' }
|
|
262
|
+
badOriginReq.headers = { host: '127.0.0.1:8080', origin: 'https://evil.example' }
|
|
263
|
+
const badOriginRes = mockRes()
|
|
264
|
+
await handler(badOriginReq, badOriginRes)
|
|
265
|
+
assert.equal(badOriginRes.statusCode, 403)
|
|
266
|
+
} finally {
|
|
267
|
+
handler.dispose()
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
test('workbench /argo/api/auth-status triggers background live verification once', async () => {
|
|
272
|
+
const verifyCalls = []
|
|
273
|
+
const handler = createWorkbenchHandler({}, {}, () => ({}), {
|
|
274
|
+
runAuthCli: async (cliArgs) => {
|
|
275
|
+
if (cliArgs[1] === 'status') return { profiles: [{ site: 'x.com', created: '2026-11-20' }] }
|
|
276
|
+
if (cliArgs[1] === 'verify') {
|
|
277
|
+
verifyCalls.push(cliArgs[2])
|
|
278
|
+
return { ok: true, site: cliArgs[2], state: 'ready' }
|
|
279
|
+
}
|
|
280
|
+
return {}
|
|
281
|
+
},
|
|
282
|
+
})
|
|
283
|
+
try {
|
|
284
|
+
const rAuth1 = mockRes()
|
|
285
|
+
await handler(mockReq('GET', '/argo/api/auth-status'), rAuth1)
|
|
286
|
+
assert.equal(rAuth1.statusCode, 200)
|
|
287
|
+
assert.equal(rAuth1.json().profiles[0].site, 'x.com')
|
|
288
|
+
await new Promise((r) => setTimeout(r, 10))
|
|
289
|
+
assert.deepEqual(verifyCalls, ['x.com'], '冷启动未核验站点应在后台静默触发一次活体复核')
|
|
290
|
+
|
|
291
|
+
const rAuth2 = mockRes()
|
|
292
|
+
await handler(mockReq('GET', '/argo/api/auth-status'), rAuth2)
|
|
293
|
+
assert.equal(rAuth2.json().profiles[0].verification.state, 'ready')
|
|
294
|
+
} finally {
|
|
295
|
+
handler.dispose()
|
|
296
|
+
}
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
test('workbench suggestions rank daily hotspots by user interest and enforce once-daily schedule', async () => {
|
|
300
|
+
const { buildSuggestions, isDailyRefreshDue } = await import('../dsh/workbench-suggestions.js')
|
|
301
|
+
const store = {
|
|
302
|
+
refreshTime: '09:00',
|
|
303
|
+
lastRefreshedDate: '2026-11-19',
|
|
304
|
+
lastRefreshedAt: '2026-11-19T01:00:00.000Z',
|
|
305
|
+
zh: ['某明星新剧官宣定档', 'DeepSeek 新一代推理模型架构解析', '今日全国天气降温预警'],
|
|
306
|
+
en: [],
|
|
307
|
+
}
|
|
308
|
+
const out = buildSuggestions('general', 'zh', false, {
|
|
309
|
+
hotspotStore: store,
|
|
310
|
+
watches: [{ query: 'DeepSeek 推理模型进展' }],
|
|
311
|
+
recentQueries: ['DeepSeek 成本对比'],
|
|
312
|
+
})
|
|
313
|
+
assert.equal(out.items[0].query, 'DeepSeek 新一代推理模型架构解析', '命中用户兴趣词的热点应置顶')
|
|
314
|
+
assert.equal(out.items[0].source, 'hotspot-matched')
|
|
315
|
+
assert.equal(out.items.some((x) => x.source === 'fallback'), false, '有真实信号时静态兜底模板不得抢位')
|
|
316
|
+
|
|
317
|
+
// 一天更新一次判据:未到点 false、到点且未刷 true、当天已刷 false
|
|
318
|
+
assert.equal(isDailyRefreshDue(store, new Date('2026-11-20T08:59:00')), false)
|
|
319
|
+
assert.equal(isDailyRefreshDue(store, new Date('2026-11-20T09:00:00')), true)
|
|
320
|
+
assert.equal(isDailyRefreshDue({ ...store, lastRefreshedDate: '2026-11-20' }, new Date('2026-11-20T18:00:00')), false)
|
|
321
|
+
|
|
322
|
+
// /argo/api/suggestions/config 校验非法时间并返回更新后的每日时间
|
|
323
|
+
const handler = createWorkbenchHandler({}, {}, () => ({}))
|
|
324
|
+
try {
|
|
325
|
+
const rBad = mockRes()
|
|
326
|
+
await handler(mockReq('POST', '/argo/api/suggestions/config', { refreshTime: '25:99' }), rBad)
|
|
327
|
+
assert.equal(rBad.statusCode, 400)
|
|
328
|
+
const rOk = mockRes()
|
|
329
|
+
await handler(mockReq('POST', '/argo/api/suggestions/config', { refreshTime: '09:00' }), rOk)
|
|
330
|
+
assert.equal(rOk.statusCode, 200)
|
|
331
|
+
assert.equal(rOk.json().refreshTime, '09:00')
|
|
332
|
+
} finally {
|
|
333
|
+
handler.dispose()
|
|
334
|
+
}
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
test('refreshDailyHotspots: 全失败不盖当日章并记 lastFailedAt,拿到新数据才盖章', async () => {
|
|
338
|
+
const { mkdtempSync } = await import('node:fs')
|
|
339
|
+
const { tmpdir } = await import('node:os')
|
|
340
|
+
const { join } = await import('node:path')
|
|
341
|
+
const prevState = process.env.ARGO_STATE_DIR
|
|
342
|
+
process.env.ARGO_STATE_DIR = mkdtempSync(join(tmpdir(), 'argo-wb-hotspot-'))
|
|
343
|
+
try {
|
|
344
|
+
const { refreshDailyHotspots } = await import('../dsh/workbench-suggestions.js')
|
|
345
|
+
const now = new Date('2026-11-20T09:00:00')
|
|
346
|
+
const emptyCli = async () => ({ results: [] })
|
|
347
|
+
|
|
348
|
+
// 全失败:保留旧章(当日仍 due,定时器可重试),写 lastFailedAt 供 1h 退避
|
|
349
|
+
const failed = await refreshDailyHotspots({
|
|
350
|
+
runCli: emptyCli, now,
|
|
351
|
+
})
|
|
352
|
+
assert.equal(failed.lastRefreshedDate, '', '全失败不得盖当日章')
|
|
353
|
+
assert.ok(failed.lastFailedAt, '全失败须记 lastFailedAt')
|
|
354
|
+
assert.equal(failed.lastRefreshedAt, '')
|
|
355
|
+
|
|
356
|
+
// 成功:盖当日章,清除 lastFailedAt
|
|
357
|
+
const okCli = async () => ({ results: [{ title: '今日全新热搜条目测试样例' }] })
|
|
358
|
+
const ok = await refreshDailyHotspots({ runCli: okCli, now })
|
|
359
|
+
assert.equal(ok.lastRefreshedDate, '2026-11-20')
|
|
360
|
+
assert.ok(ok.lastRefreshedAt)
|
|
361
|
+
assert.equal(ok.lastFailedAt, undefined, '成功后不得残留失败标记')
|
|
362
|
+
assert.equal(ok.zh.length, 1)
|
|
363
|
+
} finally {
|
|
364
|
+
process.env.ARGO_STATE_DIR = prevState
|
|
365
|
+
}
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
test('refreshDailyHotspots: 跨进程锁让路——他进程持锁时不重复抓取', async () => {
|
|
369
|
+
const { closeSync, mkdtempSync, openSync, unlinkSync } = await import('node:fs')
|
|
370
|
+
const { tmpdir } = await import('node:os')
|
|
371
|
+
const { join } = await import('node:path')
|
|
372
|
+
const prevState = process.env.ARGO_STATE_DIR
|
|
373
|
+
const stateDir = mkdtempSync(join(tmpdir(), 'argo-wb-lock-'))
|
|
374
|
+
process.env.ARGO_STATE_DIR = stateDir
|
|
375
|
+
try {
|
|
376
|
+
const { refreshDailyHotspots } = await import('../dsh/workbench-suggestions.js')
|
|
377
|
+
// 模拟另一宿主持锁:先造锁文件,再触发刷新
|
|
378
|
+
const lockPath = join(stateDir, 'workbench-hotspots.json.lock')
|
|
379
|
+
const lockFd = openSync(lockPath, 'wx')
|
|
380
|
+
try {
|
|
381
|
+
let cliCalls = 0
|
|
382
|
+
const out = await refreshDailyHotspots({
|
|
383
|
+
runCli: async () => { cliCalls += 1; return { results: [{ title: '不该被抓取的条目样例' }] } },
|
|
384
|
+
now: new Date('2026-11-21T09:00:00'),
|
|
385
|
+
})
|
|
386
|
+
assert.equal(cliCalls, 0, '持锁期间他进程不得发起 CLI 抓取')
|
|
387
|
+
assert.equal(out.zh.length, 0, '让路时返回现有 store')
|
|
388
|
+
} finally {
|
|
389
|
+
closeSync(lockFd)
|
|
390
|
+
unlinkSync(lockPath)
|
|
391
|
+
}
|
|
392
|
+
// 锁释放后正常抓取
|
|
393
|
+
const out2 = await refreshDailyHotspots({
|
|
394
|
+
runCli: async () => ({ results: [{ title: '锁释放后的真实热搜条目' }] }),
|
|
395
|
+
now: new Date('2026-11-21T09:01:00'),
|
|
396
|
+
})
|
|
397
|
+
assert.equal(out2.zh.length, 1)
|
|
398
|
+
} finally {
|
|
399
|
+
process.env.ARGO_STATE_DIR = prevState
|
|
400
|
+
}
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
test('resolveArgoBin: ARGO_BIN 显式覆盖 > monorepo > install venv > PATH 裸名', async () => {
|
|
404
|
+
const { existsSync } = await import('node:fs')
|
|
405
|
+
const { homedir } = await import('node:os')
|
|
406
|
+
const { dirname, join } = await import('node:path')
|
|
407
|
+
const { fileURLToPath } = await import('node:url')
|
|
408
|
+
const { resolveArgoBin } = await import('../dsh/workbench-io.js')
|
|
409
|
+
// 显式覆盖最优先(用户指路,零猜测)
|
|
410
|
+
assert.equal(resolveArgoBin({ ARGO_BIN: '/custom/argo' }), '/custom/argo')
|
|
411
|
+
// 无覆盖时按候选链取第一个存在的:monorepo > install.sh 默认 venv > 裸名走 PATH
|
|
412
|
+
const here = join(dirname(dirname(fileURLToPath(import.meta.url))), 'dsh')
|
|
413
|
+
const chain = [
|
|
414
|
+
join(here, '..', '..', '..', 'bin', 'argo'),
|
|
415
|
+
join(homedir(), '.local', 'share', 'argo', '.venv', 'bin', 'argo'),
|
|
416
|
+
'argo',
|
|
417
|
+
]
|
|
418
|
+
const expected = chain.find((p, i) => i === chain.length - 1 || existsSync(p))
|
|
419
|
+
assert.equal(resolveArgoBin({}), expected)
|
|
420
|
+
})
|
package/scripts/adaptive.py
CHANGED
|
@@ -176,19 +176,22 @@ class AdaptiveLearner:
|
|
|
176
176
|
|
|
177
177
|
@contextlib.contextmanager
|
|
178
178
|
def batch(self):
|
|
179
|
-
"""合并多次 record 为单次 SQLite commit,保持 record 调用面不变。
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
"""合并多次 record 为单次 SQLite commit,保持 record 调用面不变。
|
|
180
|
+
|
|
181
|
+
batch 状态跟随线程局部连接(self._local),避免线程 A 开启 batch 期间
|
|
182
|
+
线程 B 的独立连接跳过 commit 导致写事务悬空锁库。
|
|
183
|
+
"""
|
|
184
|
+
self._local.batch_depth = getattr(self._local, "batch_depth", 0) + 1
|
|
182
185
|
try:
|
|
183
186
|
yield
|
|
184
187
|
finally:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
self._local.batch_depth = max(0, getattr(self._local, "batch_depth", 1) - 1)
|
|
189
|
+
if self._local.batch_depth == 0 and getattr(self._local, "batch_dirty", False):
|
|
190
|
+
with self._lock:
|
|
188
191
|
conn = self._connect()
|
|
189
192
|
self._prune_foreign(conn)
|
|
190
193
|
conn.commit()
|
|
191
|
-
self.
|
|
194
|
+
self._local.batch_dirty = False
|
|
192
195
|
|
|
193
196
|
def _connect(self) -> sqlite3.Connection:
|
|
194
197
|
"""线程本地复用连接,避免 route 每次 open/close SQLite。"""
|
|
@@ -276,8 +279,8 @@ class AdaptiveLearner:
|
|
|
276
279
|
(engine, 1 if success else 0, latency_ms, cost, time.time(),
|
|
277
280
|
1 if empty else 0, q, dom, lg),
|
|
278
281
|
)
|
|
279
|
-
if getattr(self, "
|
|
280
|
-
self.
|
|
282
|
+
if getattr(self._local, "batch_depth", 0) > 0:
|
|
283
|
+
self._local.batch_dirty = True
|
|
281
284
|
else:
|
|
282
285
|
conn.commit()
|
|
283
286
|
# 清掉该引擎的全部缓存键(含场景分桶键),见 get_score 的缓存口径
|
|
@@ -393,8 +396,7 @@ class AdaptiveLearner:
|
|
|
393
396
|
score, samples = self._blend_bucket(
|
|
394
397
|
score, samples,
|
|
395
398
|
self._bucket_row(engine, domain or "", lang or ""), purpose)
|
|
396
|
-
|
|
397
|
-
self._score_cache[key] = (score, samples, now + self.SCORE_CACHE_TTL)
|
|
399
|
+
self._score_cache[key] = (score, samples, now + self.SCORE_CACHE_TTL)
|
|
398
400
|
return score, samples
|
|
399
401
|
|
|
400
402
|
# 场景桶向全局分收缩的先验强度:桶内有效观测 n 条时桶的权重为 n/(n+2)。
|
package/scripts/argo_paths.py
CHANGED
|
@@ -14,8 +14,8 @@ health.db 等文件,测试也难以整体隔离。
|
|
|
14
14
|
- 各模块只声明「文件名」,不再各自拼目录
|
|
15
15
|
- `python3 scripts/argo_paths.py [--json]` 可打印关键路径的实际来源
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
注意:历史 User-Agent 里的邮箱标识与状态目录命名无关,不在此处管理;
|
|
18
|
+
UA 已收敛到 engines_http.UA 单源(2026-11-18)。
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
21
|
from __future__ import annotations
|
|
@@ -14,6 +14,14 @@ lessons(把反复出现的根因导成 LESSONS.md 格式的清单)。
|
|
|
14
14
|
仲裁);本账本只收纳「真实发生的失败」并让它们可归因、可回归——对应评测
|
|
15
15
|
体系的 badcase 管理环节:发现 → 入账 → 归因 → 修复后 check 不复发。
|
|
16
16
|
|
|
17
|
+
## 运行方式注记(2026-11-18 审计澄清)
|
|
18
|
+
|
|
19
|
+
`ingest` 是**手动/定期维护动作**(`python3 scripts/badcase_ledger.py ingest`),
|
|
20
|
+
不在搜索热路径自动执行——badcase.db 的时间戳停在最后一次 ingest 的日期属
|
|
21
|
+
正常形态,勿据此判「写入路径已断、模块已死」(2026-11-17 审计曾误判)。
|
|
22
|
+
本文件同时是静默吞异常棘轮基线(BROAD_SILENT_CATCH_BASELINE)的真源,删除
|
|
23
|
+
模块会连棘轮一起丢。
|
|
24
|
+
|
|
17
25
|
## 2026-11-10 补的归因层:root_cause + Seen N×
|
|
18
26
|
|
|
19
27
|
原实现只到「发现 → 入账」:`check` 数近 N 天新增坏例的**条数**,不看**根因
|
|
@@ -188,6 +196,7 @@ _DETAIL_RULES: tuple[tuple[str, str], ...] = (
|
|
|
188
196
|
_KIND_CAUSE: dict[str, str] = {
|
|
189
197
|
"recovery": ROOT_CAUSE_RECOVERY,
|
|
190
198
|
"breaker": ROOT_CAUSE_BREAKER,
|
|
199
|
+
"empty_result": ROOT_CAUSE_PARSE_EMPTY,
|
|
191
200
|
}
|
|
192
201
|
|
|
193
202
|
|