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.
- package/AGENTS.md +4 -2
- package/README.es.md +15 -5
- package/README.ja.md +15 -5
- package/README.ko.md +15 -5
- package/README.md +16 -6
- package/README.zh.md +16 -6
- package/SKILL.md +12 -11
- 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 +121 -18
- package/backends/engine_registry.yaml +23 -0
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +20 -0
- package/bin/argo +78 -12
- package/docs/CHANGELOG.md +35 -1
- package/docs/COMMIT_STANDARD.md +12 -2
- package/docs/ENGINE_CATALOG.md +36 -33
- package/docs/RELEASE_NOTES_v2.17.0.md +66 -0
- package/docs/RELEASE_NOTES_v2.18.0.md +87 -0
- package/docs/RELEASING.md +2 -2
- package/engines/specs/crossref.yaml +2 -0
- package/engines/specs/hackernews.yaml +2 -0
- package/engines/specs/helve.yaml +49 -0
- package/engines/specs/hf_papers.yaml +2 -0
- package/engines/specs/openalex.yaml +9 -2
- package/engines/specs/twitter_cli.yaml +17 -0
- package/engines/specs/twitter_syndication.yaml +2 -3
- 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 +57 -63
- package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
- package/packages/dsh-plugin/dsh/index.js +109 -21
- package/packages/dsh-plugin/dsh/native-tools.mjs +10 -0
- package/packages/dsh-plugin/dsh/route-guard.js +95 -0
- package/packages/dsh-plugin/dsh/runner.js +49 -6
- package/packages/dsh-plugin/dsh/wide-research.js +20 -18
- package/packages/dsh-plugin/dsh/workbench-client.js +119 -20
- package/packages/dsh-plugin/dsh/workbench-io.js +182 -0
- package/packages/dsh-plugin/dsh/workbench-search.js +445 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +387 -75
- package/packages/dsh-plugin/dsh/workbench.js +277 -497
- package/packages/dsh-plugin/package.json +4 -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 +96 -0
- package/packages/dsh-plugin/test/workbench.test.js +422 -9
- package/scripts/adaptive.py +13 -11
- package/scripts/affected_tests.py +324 -0
- package/scripts/badcase_ledger.py +93 -2
- package/scripts/browser_auth.py +178 -4
- package/scripts/cache.py +68 -69
- package/scripts/check_commit_report.py +59 -9
- package/scripts/chrome_cdp.py +71 -0
- package/scripts/circuit_breaker.py +77 -12
- package/scripts/cli_io.py +8 -3
- package/scripts/config_cache.py +4 -3
- package/scripts/daemon.py +9 -2
- package/scripts/engine_add.py +45 -0
- package/scripts/engine_dispatch.py +27 -47
- package/scripts/engine_failure.py +33 -0
- package/scripts/engine_families.py +1 -0
- package/scripts/engine_fingerprint.py +114 -0
- package/scripts/engine_health.py +130 -0
- package/scripts/engine_states.py +54 -4
- package/scripts/engines.py +2 -0
- package/scripts/engines_base.py +19 -44
- package/scripts/engines_builders_intl.py +20 -94
- package/scripts/engines_builders_search.py +19 -8
- package/scripts/engines_builders_tech.py +16 -16
- package/scripts/engines_fields.py +23 -0
- package/scripts/engines_twitter_cli.py +182 -0
- package/scripts/evidence_grounding.py +182 -0
- package/scripts/fetch_browser.py +25 -10
- package/scripts/fetch_cli_output.py +75 -0
- package/scripts/fetch_dispatch.py +248 -0
- package/scripts/fetch_quality.py +11 -0
- package/scripts/fetch_v3.py +48 -114
- package/scripts/gate_manifest_check.py +75 -0
- package/scripts/gen_readme_art.py +264 -0
- package/scripts/intent_router.py +224 -0
- package/scripts/mcp_compact.py +3 -0
- package/scripts/mcp_handlers.py +24 -4
- package/scripts/mcp_tools.py +2 -0
- package/scripts/mcp_transport.py +24 -5
- package/scripts/mcp_warm.py +15 -11
- package/scripts/numeric_verify.py +9 -0
- package/scripts/output_transparency.py +10 -0
- package/scripts/pre-commit +65 -8
- package/scripts/query_operators.py +229 -1
- package/scripts/quota.py +19 -37
- package/scripts/release.py +16 -1
- package/scripts/release_check.py +1 -2
- package/scripts/research_gates.py +85 -1
- package/scripts/research_notes.py +52 -5
- package/scripts/retry_policy.py +17 -3
- package/scripts/route_combo.py +21 -4
- package/scripts/search.py +29 -29
- package/scripts/search_cli.py +104 -8
- package/scripts/search_output.py +4 -1
- package/scripts/social_research.py +8 -6
- package/scripts/source_discovery.py +611 -0
- package/scripts/sync_backends.py +45 -0
- package/scripts/time_utils.py +28 -0
- package/scripts/twitter_single_read.py +107 -0
- package/scripts/x_keyword_route.py +138 -0
- package/scripts/x_search.py +24 -33
- package/scripts/zhihu_answer_body.py +96 -0
- package/scripts/zhihu_answer_fetch.py +66 -0
- package/scripts/zhihu_answer_lookup.py +138 -0
- package/sub-skills/ego-search/README.md +9 -0
- package/sub-skills/ego-search/scripts/ego_search.py +182 -15
- 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/local-seek/SKILL.md +3 -1
- package/sub-skills/local-seek/scripts/seek.py +80 -109
- package/sub-skills/local-seek/scripts/seek_git.py +65 -0
- package/sub-skills/local-seek/scripts/seek_inspect.py +242 -0
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import test from 'node:test'
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
3
|
import { EventEmitter } from 'node:events'
|
|
4
|
-
import {
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { Readable } from 'node:stream'
|
|
6
|
+
import { buildSearchCliArgs, createWorkbenchHandler } from '../dsh/workbench.js'
|
|
5
7
|
|
|
6
8
|
function mockReq(method, url, bodyObj = null) {
|
|
7
|
-
const req = new EventEmitter()
|
|
9
|
+
const req = bodyObj !== null ? Readable.from([Buffer.from(JSON.stringify(bodyObj))]) : new EventEmitter()
|
|
8
10
|
req.method = method
|
|
9
11
|
req.url = url
|
|
10
12
|
req.headers = { host: '127.0.0.1:8080' }
|
|
11
|
-
queueMicrotask(() => {
|
|
12
|
-
if (bodyObj !== null) req.emit('data', Buffer.from(JSON.stringify(bodyObj)))
|
|
13
|
-
req.emit('end')
|
|
14
|
-
})
|
|
15
13
|
return req
|
|
16
14
|
}
|
|
17
15
|
|
|
@@ -22,7 +20,18 @@ function mockRes() {
|
|
|
22
20
|
statusCode: 200,
|
|
23
21
|
writableEnded: false,
|
|
24
22
|
destroyed: false,
|
|
25
|
-
|
|
23
|
+
headersSent: false,
|
|
24
|
+
// 保真 Node 语义:flushHeaders 后再 setHeader 抛 ERR_HTTP_HEADERS_SENT
|
|
25
|
+
flushHeaders() { this.headersSent = true },
|
|
26
|
+
setHeader(k, v) {
|
|
27
|
+
if (this.headersSent) throw new Error('ERR_HTTP_HEADERS_SENT')
|
|
28
|
+
headers[k.toLowerCase()] = v
|
|
29
|
+
},
|
|
30
|
+
writeHead(code, hdrs = {}) {
|
|
31
|
+
this.statusCode = code
|
|
32
|
+
for (const [k, v] of Object.entries(hdrs)) headers[k.toLowerCase()] = v
|
|
33
|
+
},
|
|
34
|
+
write(data = '') { chunks += String(data); return true },
|
|
26
35
|
end(data = '') {
|
|
27
36
|
chunks += String(data)
|
|
28
37
|
this.writableEnded = true
|
|
@@ -38,7 +47,7 @@ test('workbench /argo/api/health exposes local mode, egoSearch and breaker summa
|
|
|
38
47
|
try {
|
|
39
48
|
const res = mockRes()
|
|
40
49
|
await handler(mockReq('GET', '/argo/api/health'), res)
|
|
41
|
-
assert.equal(res.statusCode, 200)
|
|
50
|
+
assert.equal(res.statusCode, 200, res.text())
|
|
42
51
|
const data = res.json()
|
|
43
52
|
assert.equal(data.ok, true)
|
|
44
53
|
assert.ok(Array.isArray(data.modes))
|
|
@@ -85,8 +94,412 @@ test('workbench /argo/api/suggestions adapts to mode and DSH locale', async () =
|
|
|
85
94
|
const en = resEn.json()
|
|
86
95
|
assert.equal(en.ok, true)
|
|
87
96
|
assert.equal(en.lang, 'en')
|
|
88
|
-
assert.ok(en.items.
|
|
97
|
+
assert.ok(en.items.length > 0)
|
|
98
|
+
const enTags = new Set(['For You', 'Hot', 'Watch', 'Recent', 'Guide'])
|
|
99
|
+
assert.ok(en.items.every(it => enTags.has(it.tag)))
|
|
100
|
+
} finally {
|
|
101
|
+
handler.dispose()
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('workbench uses host default model without overriding maxTokens and surfaces real LLM failure', async () => {
|
|
106
|
+
let capturedOpts
|
|
107
|
+
const mockCtx = {
|
|
108
|
+
get(name) {
|
|
109
|
+
if (name === 'agentDefaultModel') return { currentSelection: () => ({ provider: 'commandcode', model: 'deepseek/deepseek-v4.1-flash' }) }
|
|
110
|
+
if (name === 'llm') {
|
|
111
|
+
return {
|
|
112
|
+
async *stream(opts) {
|
|
113
|
+
capturedOpts = opts
|
|
114
|
+
yield { type: 'finish', reason: { kind: 'error', failure: { message: 'finish_reason=length' } } }
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return undefined
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
const handler = createWorkbenchHandler(mockCtx, {}, () => ({}))
|
|
122
|
+
try {
|
|
123
|
+
const res = mockRes()
|
|
124
|
+
await handler(mockReq('POST', '/argo/api/followup', {
|
|
125
|
+
query: 'test',
|
|
126
|
+
mode: 'general',
|
|
127
|
+
question: 'why?',
|
|
128
|
+
cards: [{ index: 1, title: 'T', url: 'https://example.com', domain: 'example.com', snippet: 'S' }],
|
|
129
|
+
}), res)
|
|
130
|
+
assert.equal(res.statusCode, 200, res.text())
|
|
131
|
+
assert.equal(capturedOpts.provider, 'commandcode')
|
|
132
|
+
assert.equal(capturedOpts.model, 'deepseek/deepseek-v4.1-flash')
|
|
133
|
+
assert.equal(capturedOpts.maxTokens, undefined)
|
|
134
|
+
assert.equal(capturedOpts.reasoningEffort, undefined)
|
|
135
|
+
assert.ok(res.text().includes('commandcode/deepseek/deepseek-v4.1-flash'))
|
|
136
|
+
assert.ok(res.text().includes('finish_reason=length'))
|
|
137
|
+
assert.ok(!res.text().includes('未配置默认模型'))
|
|
138
|
+
} finally {
|
|
139
|
+
handler.dispose()
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('workbench followup tolerates null cards/history entries without hanging the SSE response', async () => {
|
|
144
|
+
// 2026-11-18 实跑复现:cards:[null] 在 flushHeaders 后于 buildEvidenceContext
|
|
145
|
+
// 抛 TypeError → catch 落 sendJson → setHeader 二次抛 ERR_HTTP_HEADERS_SENT
|
|
146
|
+
// → 响应永久悬挂。修复=入口元素过滤 + sendJson 判 headersSent 改发 SSE failure。
|
|
147
|
+
let capturedMessages
|
|
148
|
+
const mockCtx = {
|
|
149
|
+
get(name) {
|
|
150
|
+
if (name === 'agentDefaultModel') return { currentSelection: () => ({ provider: 'p', model: 'm' }) }
|
|
151
|
+
if (name === 'llm') {
|
|
152
|
+
return {
|
|
153
|
+
async *stream(opts) {
|
|
154
|
+
capturedMessages = opts.messages
|
|
155
|
+
yield { type: 'finish', reason: { kind: 'stop' } }
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return undefined
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
const handler = createWorkbenchHandler(mockCtx, {}, () => ({}))
|
|
163
|
+
try {
|
|
164
|
+
const res = mockRes()
|
|
165
|
+
await handler(mockReq('POST', '/argo/api/followup', {
|
|
166
|
+
query: 'test',
|
|
167
|
+
mode: 'general',
|
|
168
|
+
question: 'why?',
|
|
169
|
+
cards: [null, 'garbage', { index: 1, title: 'T', url: 'https://example.com', domain: 'example.com', snippet: 'S' }],
|
|
170
|
+
history: [null, { role: 'user', text: 'previous turn' }],
|
|
171
|
+
}), res)
|
|
172
|
+
assert.equal(res.statusCode, 200)
|
|
173
|
+
assert.equal(res.writableEnded, true, '响应必须干净收尾,不得悬挂')
|
|
174
|
+
assert.ok(res.text().includes('event: done'), `应以 done 事件收尾,实际: ${res.text().slice(-160)}`)
|
|
175
|
+
// 合法 history 条目应过滤后到达模型(null 条目被剔除、合法条目保留)
|
|
176
|
+
const flattened = JSON.stringify(capturedMessages)
|
|
177
|
+
assert.ok(flattened.includes('previous turn'), '合法 history 条目应到达模型')
|
|
178
|
+
assert.ok(!flattened.includes('null'), 'null 条目不得混入 messages')
|
|
179
|
+
} finally {
|
|
180
|
+
handler.dispose()
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
test('workbench CLI args keep every flag before `--` so dash-leading queries stay literal', () => {
|
|
185
|
+
const args = buildSearchCliArgs('--list-engines', 'general', true, { verify: 2 })
|
|
186
|
+
const sep = args.indexOf('--')
|
|
187
|
+
assert.ok(sep > 0, `必须存在 -- 分隔,实际 ${JSON.stringify(args)}`)
|
|
188
|
+
assert.equal(args[sep + 1], '--list-engines', 'query 必须紧跟 -- 之后')
|
|
189
|
+
assert.equal(args[args.length - 1], '--list-engines')
|
|
190
|
+
assert.ok(args.slice(0, sep).includes('--json'), 'flag 必须全部前置到 -- 之前')
|
|
191
|
+
assert.ok(args.slice(0, sep).includes('--no-cache'), 'refresh 的 --no-cache 也须前置')
|
|
192
|
+
assert.ok(!args.slice(0, sep).includes('--envelope'), '默认不附冗余 --envelope')
|
|
193
|
+
assert.ok(!args.slice(0, sep).includes('--list-engines'), 'query 不得混入 flag 区')
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
test('workbench modes map to --intent for real vertical engine boost', () => {
|
|
197
|
+
const acad = buildSearchCliArgs('transformer', 'academic')
|
|
198
|
+
assert.ok(acad.includes('--intent') && acad[acad.indexOf('--intent') + 1] === 'academic')
|
|
199
|
+
const hot = buildSearchCliArgs('AI 政策', 'hotspot')
|
|
200
|
+
assert.ok(hot.includes('--intent') && hot[hot.indexOf('--intent') + 1] === 'news')
|
|
201
|
+
const soc = buildSearchCliArgs('Claude Code', 'general', false, { intent: 'social' })
|
|
202
|
+
assert.ok(soc.includes('--intent') && soc[soc.indexOf('--intent') + 1] === 'social')
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
test('workbench /argo/api/local-inspect and /argo/api/note-study bridge local-seek and note study', async () => {
|
|
206
|
+
const calls = []
|
|
207
|
+
const handler = createWorkbenchHandler(
|
|
208
|
+
{ get: () => null },
|
|
209
|
+
{ localSearchPath: process.cwd() },
|
|
210
|
+
null,
|
|
211
|
+
{
|
|
212
|
+
runInspectCli: async (cliArgs) => {
|
|
213
|
+
calls.push(cliArgs)
|
|
214
|
+
return { ok: true, symbol: 'resolve_intent', start: 78, end: 193, content: '78: def resolve_intent(' }
|
|
215
|
+
},
|
|
216
|
+
runNoteCli: async (cliArgs, opts) => {
|
|
217
|
+
calls.push({ cliArgs, hasStdin: Boolean(opts?.stdin) })
|
|
218
|
+
return { kind: 'study', note: '/tmp/demo-note.md' }
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
const allowedFile = join(process.cwd(), 'scripts', 'intent_router.py')
|
|
224
|
+
const res1 = mockRes()
|
|
225
|
+
await handler(mockReq('POST', '/argo/api/local-inspect', {
|
|
226
|
+
path: `file://${allowedFile}`,
|
|
227
|
+
symbol: 'resolve_intent',
|
|
228
|
+
}), res1)
|
|
229
|
+
assert.equal(res1.statusCode, 200)
|
|
230
|
+
const b1 = res1.json()
|
|
231
|
+
assert.equal(b1.ok, true)
|
|
232
|
+
assert.equal(b1.symbol, 'resolve_intent')
|
|
233
|
+
assert.deepEqual(calls[0], ['seek', '--json', '--symbol-body', 'resolve_intent', '--', allowedFile])
|
|
234
|
+
|
|
235
|
+
// 路径边界防护:越界绝对路径与 ../ 穿越均返回 403 且绝不触发 CLI
|
|
236
|
+
const resEscapeAbs = mockRes()
|
|
237
|
+
await handler(mockReq('POST', '/argo/api/local-inspect', {
|
|
238
|
+
path: '/etc/passwd',
|
|
239
|
+
lines: '1-5',
|
|
240
|
+
}), resEscapeAbs)
|
|
241
|
+
assert.equal(resEscapeAbs.statusCode, 403)
|
|
242
|
+
assert.equal(resEscapeAbs.json().error, 'path_outside_root')
|
|
243
|
+
|
|
244
|
+
const resEscapeRel = mockRes()
|
|
245
|
+
await handler(mockReq('POST', '/argo/api/local-inspect', {
|
|
246
|
+
path: '../../../etc/passwd',
|
|
247
|
+
lines: '1-5',
|
|
248
|
+
}), resEscapeRel)
|
|
249
|
+
assert.equal(resEscapeRel.statusCode, 403)
|
|
250
|
+
assert.equal(resEscapeRel.json().error, 'path_outside_root')
|
|
251
|
+
assert.equal(calls.length, 1)
|
|
252
|
+
|
|
253
|
+
const res2 = mockRes()
|
|
254
|
+
await handler(mockReq('POST', '/argo/api/note-study', {
|
|
255
|
+
title: 'Test Note',
|
|
256
|
+
payload: { query: 'q', results: [{ title: 'T', url: 'https://example.org/1', snippet: 'S' }] },
|
|
257
|
+
}), res2)
|
|
258
|
+
assert.equal(res2.statusCode, 200)
|
|
259
|
+
const b2 = res2.json()
|
|
260
|
+
assert.equal(b2.ok, true)
|
|
261
|
+
assert.equal(b2.note, '/tmp/demo-note.md')
|
|
262
|
+
assert.equal(calls[1].hasStdin, true)
|
|
263
|
+
assert.ok(calls[1].cliArgs.includes('--from-json'))
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
test('workbench-io cross-platform helpers handle win32 PATH and shebang wrapping', async () => {
|
|
267
|
+
const { mergedLaunchdPath, resolveSpawnCommand } = await import('../dsh/workbench-io.js')
|
|
268
|
+
const winPath = mergedLaunchdPath({ Path: 'C:\\Windows\\System32;C:\\Python312' }, 'win32')
|
|
269
|
+
assert.equal(winPath, 'C:\\Windows\\System32;C:\\Python312')
|
|
270
|
+
assert.ok(!winPath.includes('/opt/homebrew/bin:'))
|
|
271
|
+
|
|
272
|
+
const wrapped = resolveSpawnCommand('C:\\repo\\bin\\argo', ['search', '--json'], { ARGO_PYTHON: 'py' }, 'win32')
|
|
273
|
+
assert.deepEqual(wrapped, { cmd: 'py', argv: ['C:\\repo\\bin\\argo', 'search', '--json'] })
|
|
274
|
+
|
|
275
|
+
const posix = resolveSpawnCommand('/repo/bin/argo', ['search', '--json'], {}, 'darwin')
|
|
276
|
+
assert.deepEqual(posix, { cmd: '/repo/bin/argo', argv: ['search', '--json'] })
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
test('workbench research gate passes when stats are supplied alongside valid citations', async () => {
|
|
280
|
+
const { evaluateGates } = await import('../dsh/wide-research.js')
|
|
281
|
+
const gate = evaluateGates({
|
|
282
|
+
answer: '核心结论基于多源证据 [1][2][3]。',
|
|
283
|
+
sources: [
|
|
284
|
+
{ url: 'https://a.example.com/1', title: 'A', domain: 'a.example.com' },
|
|
285
|
+
{ url: 'https://b.example.com/2', title: 'B', domain: 'b.example.com' },
|
|
286
|
+
{ url: 'https://c.example.com/3', title: 'C', domain: 'c.example.com' },
|
|
287
|
+
],
|
|
288
|
+
tracks: [{ id: 't1', title: 'T1' }],
|
|
289
|
+
warnings: [],
|
|
290
|
+
stats: { sourceCount: 3, completedTracks: 1, failedTracks: 0 },
|
|
291
|
+
})
|
|
292
|
+
assert.equal(gate.passed, true)
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test('index apply re-registers envResolver after dispose (HMR safe) and sets rc.5 provider metadata', async () => {
|
|
296
|
+
const { apply } = await import('../dsh/index.js')
|
|
297
|
+
const { resolveEnv } = await import('../dsh/runner.js')
|
|
298
|
+
const cleanups = []
|
|
299
|
+
const registered = []
|
|
300
|
+
const mkCtx = () => ({
|
|
301
|
+
effect: (fn) => { const off = fn(); if (typeof off === 'function') cleanups.push(off) },
|
|
302
|
+
tools: { register: () => () => {}, guard: () => () => {} },
|
|
303
|
+
subagents: {},
|
|
304
|
+
systemPrompt: { section: () => () => {} },
|
|
305
|
+
web: {
|
|
306
|
+
registerSearchProvider: (p) => { registered.push(p); return () => {} },
|
|
307
|
+
registerFetchProvider: (p) => { registered.push(p); return () => {} },
|
|
308
|
+
search: async () => ({ sources: [] }),
|
|
309
|
+
searchReady: async () => true,
|
|
310
|
+
},
|
|
311
|
+
get: () => undefined,
|
|
312
|
+
})
|
|
313
|
+
apply(mkCtx(), { nativeTools: [] })
|
|
314
|
+
while (cleanups.length) cleanups.pop()()
|
|
315
|
+
// 二次 apply 模拟同进程 HMR 重载
|
|
316
|
+
apply(mkCtx(), { nativeTools: [], argoEnv: ['ARGO_NO_CACHE=1'] })
|
|
317
|
+
const env = await resolveEnv({}, { argoEnv: ['ARGO_NO_CACHE=1'], keyRefs: [] })
|
|
318
|
+
assert.equal(env?.ARGO_NO_CACHE, '1')
|
|
319
|
+
const searchProv = registered.find(p => p.id === 'argo' && typeof p.search === 'function')
|
|
320
|
+
assert.ok(searchProv?.title)
|
|
321
|
+
assert.ok(searchProv?.description)
|
|
322
|
+
assert.equal(typeof searchProv?.ready, 'function')
|
|
323
|
+
while (cleanups.length) cleanups.pop()()
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
test('workbench /argo/api/* enforces TCP peer loopback fence against spoofed headers', async () => {
|
|
327
|
+
const handler = createWorkbenchHandler({}, {}, () => ({}))
|
|
328
|
+
try {
|
|
329
|
+
// 局域网对端即使伪造 Host: 127.0.0.1 + X-Forwarded-For: 127.0.0.1 且不带 Origin 也必须被拒
|
|
330
|
+
const lanReq = mockReq('GET', '/argo/api/health')
|
|
331
|
+
lanReq.socket = { remoteAddress: '192.168.1.50' }
|
|
332
|
+
lanReq.headers = { host: '127.0.0.1:8080', 'x-forwarded-for': '127.0.0.1' }
|
|
333
|
+
const lanRes = mockRes()
|
|
334
|
+
await handler(lanReq, lanRes)
|
|
335
|
+
assert.equal(lanRes.statusCode, 403)
|
|
336
|
+
assert.equal(lanRes.json().error, 'forbidden_origin')
|
|
337
|
+
|
|
338
|
+
// 本机 IPv4-mapped 回环放行,但跨站 Origin 仍被拦(防 DNS rebinding)
|
|
339
|
+
const okReq = mockReq('GET', '/argo/api/health')
|
|
340
|
+
okReq.socket = { remoteAddress: '::ffff:127.0.0.1' }
|
|
341
|
+
const okRes = mockRes()
|
|
342
|
+
await handler(okReq, okRes)
|
|
343
|
+
assert.equal(okRes.statusCode, 200)
|
|
344
|
+
|
|
345
|
+
const badOriginReq = mockReq('GET', '/argo/api/health')
|
|
346
|
+
badOriginReq.socket = { remoteAddress: '127.0.0.1' }
|
|
347
|
+
badOriginReq.headers = { host: '127.0.0.1:8080', origin: 'https://evil.example' }
|
|
348
|
+
const badOriginRes = mockRes()
|
|
349
|
+
await handler(badOriginReq, badOriginRes)
|
|
350
|
+
assert.equal(badOriginRes.statusCode, 403)
|
|
351
|
+
} finally {
|
|
352
|
+
handler.dispose()
|
|
353
|
+
}
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
test('workbench /argo/api/auth-status triggers background live verification once', async () => {
|
|
357
|
+
const verifyCalls = []
|
|
358
|
+
const handler = createWorkbenchHandler({}, {}, () => ({}), {
|
|
359
|
+
runAuthCli: async (cliArgs) => {
|
|
360
|
+
if (cliArgs[1] === 'status') return { profiles: [{ site: 'x.com', created: '2026-11-20' }] }
|
|
361
|
+
if (cliArgs[1] === 'verify') {
|
|
362
|
+
verifyCalls.push(cliArgs[2])
|
|
363
|
+
return { ok: true, site: cliArgs[2], state: 'ready' }
|
|
364
|
+
}
|
|
365
|
+
return {}
|
|
366
|
+
},
|
|
367
|
+
})
|
|
368
|
+
try {
|
|
369
|
+
const rAuth1 = mockRes()
|
|
370
|
+
await handler(mockReq('GET', '/argo/api/auth-status'), rAuth1)
|
|
371
|
+
assert.equal(rAuth1.statusCode, 200)
|
|
372
|
+
assert.equal(rAuth1.json().profiles[0].site, 'x.com')
|
|
373
|
+
await new Promise((r) => setTimeout(r, 10))
|
|
374
|
+
assert.deepEqual(verifyCalls, ['x.com'], '冷启动未核验站点应在后台静默触发一次活体复核')
|
|
375
|
+
|
|
376
|
+
const rAuth2 = mockRes()
|
|
377
|
+
await handler(mockReq('GET', '/argo/api/auth-status'), rAuth2)
|
|
378
|
+
assert.equal(rAuth2.json().profiles[0].verification.state, 'ready')
|
|
379
|
+
} finally {
|
|
380
|
+
handler.dispose()
|
|
381
|
+
}
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
test('workbench suggestions rank daily hotspots by user interest and enforce once-daily schedule', async () => {
|
|
385
|
+
const { buildSuggestions, isDailyRefreshDue } = await import('../dsh/workbench-suggestions.js')
|
|
386
|
+
const store = {
|
|
387
|
+
refreshTime: '09:00',
|
|
388
|
+
lastRefreshedDate: '2026-11-19',
|
|
389
|
+
lastRefreshedAt: '2026-11-19T01:00:00.000Z',
|
|
390
|
+
zh: ['某明星新剧官宣定档', 'DeepSeek 新一代推理模型架构解析', '今日全国天气降温预警'],
|
|
391
|
+
en: [],
|
|
392
|
+
}
|
|
393
|
+
const out = buildSuggestions('general', 'zh', false, {
|
|
394
|
+
hotspotStore: store,
|
|
395
|
+
watches: [{ query: 'DeepSeek 推理模型进展' }],
|
|
396
|
+
recentQueries: ['DeepSeek 成本对比'],
|
|
397
|
+
})
|
|
398
|
+
assert.equal(out.items[0].query, 'DeepSeek 新一代推理模型架构解析', '命中用户兴趣词的热点应置顶')
|
|
399
|
+
assert.equal(out.items[0].source, 'hotspot-matched')
|
|
400
|
+
assert.equal(out.items.some((x) => x.source === 'fallback'), false, '有真实信号时静态兜底模板不得抢位')
|
|
401
|
+
|
|
402
|
+
// 一天更新一次判据:未到点 false、到点且未刷 true、当天已刷 false
|
|
403
|
+
assert.equal(isDailyRefreshDue(store, new Date('2026-11-20T08:59:00')), false)
|
|
404
|
+
assert.equal(isDailyRefreshDue(store, new Date('2026-11-20T09:00:00')), true)
|
|
405
|
+
assert.equal(isDailyRefreshDue({ ...store, lastRefreshedDate: '2026-11-20' }, new Date('2026-11-20T18:00:00')), false)
|
|
406
|
+
|
|
407
|
+
// /argo/api/suggestions/config 校验非法时间并返回更新后的每日时间
|
|
408
|
+
const handler = createWorkbenchHandler({}, {}, () => ({}))
|
|
409
|
+
try {
|
|
410
|
+
const rBad = mockRes()
|
|
411
|
+
await handler(mockReq('POST', '/argo/api/suggestions/config', { refreshTime: '25:99' }), rBad)
|
|
412
|
+
assert.equal(rBad.statusCode, 400)
|
|
413
|
+
const rOk = mockRes()
|
|
414
|
+
await handler(mockReq('POST', '/argo/api/suggestions/config', { refreshTime: '09:00' }), rOk)
|
|
415
|
+
assert.equal(rOk.statusCode, 200)
|
|
416
|
+
assert.equal(rOk.json().refreshTime, '09:00')
|
|
89
417
|
} finally {
|
|
90
418
|
handler.dispose()
|
|
91
419
|
}
|
|
92
420
|
})
|
|
421
|
+
|
|
422
|
+
test('refreshDailyHotspots: 全失败不盖当日章并记 lastFailedAt,拿到新数据才盖章', async () => {
|
|
423
|
+
const { mkdtempSync } = await import('node:fs')
|
|
424
|
+
const { tmpdir } = await import('node:os')
|
|
425
|
+
const { join } = await import('node:path')
|
|
426
|
+
const prevState = process.env.ARGO_STATE_DIR
|
|
427
|
+
process.env.ARGO_STATE_DIR = mkdtempSync(join(tmpdir(), 'argo-wb-hotspot-'))
|
|
428
|
+
try {
|
|
429
|
+
const { refreshDailyHotspots } = await import('../dsh/workbench-suggestions.js')
|
|
430
|
+
const now = new Date('2026-11-20T09:00:00')
|
|
431
|
+
const emptyCli = async () => ({ results: [] })
|
|
432
|
+
|
|
433
|
+
// 全失败:保留旧章(当日仍 due,定时器可重试),写 lastFailedAt 供 1h 退避
|
|
434
|
+
const failed = await refreshDailyHotspots({
|
|
435
|
+
runCli: emptyCli, now,
|
|
436
|
+
})
|
|
437
|
+
assert.equal(failed.lastRefreshedDate, '', '全失败不得盖当日章')
|
|
438
|
+
assert.ok(failed.lastFailedAt, '全失败须记 lastFailedAt')
|
|
439
|
+
assert.equal(failed.lastRefreshedAt, '')
|
|
440
|
+
|
|
441
|
+
// 成功:盖当日章,清除 lastFailedAt
|
|
442
|
+
const okCli = async () => ({ results: [{ title: '今日全新热搜条目测试样例' }] })
|
|
443
|
+
const ok = await refreshDailyHotspots({ runCli: okCli, now })
|
|
444
|
+
assert.equal(ok.lastRefreshedDate, '2026-11-20')
|
|
445
|
+
assert.ok(ok.lastRefreshedAt)
|
|
446
|
+
assert.equal(ok.lastFailedAt, undefined, '成功后不得残留失败标记')
|
|
447
|
+
assert.equal(ok.zh.length, 1)
|
|
448
|
+
} finally {
|
|
449
|
+
process.env.ARGO_STATE_DIR = prevState
|
|
450
|
+
}
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
test('refreshDailyHotspots: 跨进程锁让路——他进程持锁时不重复抓取', async () => {
|
|
454
|
+
const { closeSync, mkdtempSync, openSync, unlinkSync } = await import('node:fs')
|
|
455
|
+
const { tmpdir } = await import('node:os')
|
|
456
|
+
const { join } = await import('node:path')
|
|
457
|
+
const prevState = process.env.ARGO_STATE_DIR
|
|
458
|
+
const stateDir = mkdtempSync(join(tmpdir(), 'argo-wb-lock-'))
|
|
459
|
+
process.env.ARGO_STATE_DIR = stateDir
|
|
460
|
+
try {
|
|
461
|
+
const { refreshDailyHotspots } = await import('../dsh/workbench-suggestions.js')
|
|
462
|
+
// 模拟另一宿主持锁:先造锁文件,再触发刷新
|
|
463
|
+
const lockPath = join(stateDir, 'workbench-hotspots.json.lock')
|
|
464
|
+
const lockFd = openSync(lockPath, 'wx')
|
|
465
|
+
try {
|
|
466
|
+
let cliCalls = 0
|
|
467
|
+
const out = await refreshDailyHotspots({
|
|
468
|
+
runCli: async () => { cliCalls += 1; return { results: [{ title: '不该被抓取的条目样例' }] } },
|
|
469
|
+
now: new Date('2026-11-21T09:00:00'),
|
|
470
|
+
})
|
|
471
|
+
assert.equal(cliCalls, 0, '持锁期间他进程不得发起 CLI 抓取')
|
|
472
|
+
assert.equal(out.zh.length, 0, '让路时返回现有 store')
|
|
473
|
+
} finally {
|
|
474
|
+
closeSync(lockFd)
|
|
475
|
+
unlinkSync(lockPath)
|
|
476
|
+
}
|
|
477
|
+
// 锁释放后正常抓取
|
|
478
|
+
const out2 = await refreshDailyHotspots({
|
|
479
|
+
runCli: async () => ({ results: [{ title: '锁释放后的真实热搜条目' }] }),
|
|
480
|
+
now: new Date('2026-11-21T09:01:00'),
|
|
481
|
+
})
|
|
482
|
+
assert.equal(out2.zh.length, 1)
|
|
483
|
+
} finally {
|
|
484
|
+
process.env.ARGO_STATE_DIR = prevState
|
|
485
|
+
}
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
test('resolveArgoBin: ARGO_BIN 显式覆盖 > monorepo > install venv > PATH 裸名', async () => {
|
|
489
|
+
const { existsSync } = await import('node:fs')
|
|
490
|
+
const { homedir } = await import('node:os')
|
|
491
|
+
const { dirname, join } = await import('node:path')
|
|
492
|
+
const { fileURLToPath } = await import('node:url')
|
|
493
|
+
const { resolveArgoBin } = await import('../dsh/workbench-io.js')
|
|
494
|
+
// 显式覆盖最优先(用户指路,零猜测)
|
|
495
|
+
assert.equal(resolveArgoBin({ ARGO_BIN: '/custom/argo' }), '/custom/argo')
|
|
496
|
+
// 无覆盖时按候选链取第一个存在的:monorepo > install.sh 默认 venv > 裸名走 PATH
|
|
497
|
+
const here = join(dirname(dirname(fileURLToPath(import.meta.url))), 'dsh')
|
|
498
|
+
const chain = [
|
|
499
|
+
join(here, '..', '..', '..', 'bin', 'argo'),
|
|
500
|
+
join(homedir(), '.local', 'share', 'argo', '.venv', 'bin', 'argo'),
|
|
501
|
+
'argo',
|
|
502
|
+
]
|
|
503
|
+
const expected = chain.find((p, i) => i === chain.length - 1 || existsSync(p))
|
|
504
|
+
assert.equal(resolveArgoBin({}), expected)
|
|
505
|
+
})
|
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)。
|