argo-search 2.10.1 → 2.11.2
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/README.en.md +48 -11
- package/README.es.md +48 -11
- package/README.ja.md +48 -11
- package/README.ko.md +47 -10
- package/README.md +48 -31
- package/SKILL.md +16 -15
- package/backends/concept_vectors.bin +0 -0
- package/backends/domain_profiles.json +18 -6
- package/backends/engine_concept_vectors.json +3104 -0
- package/backends/engine_registry.yaml +38 -13
- package/backends/quota_profiles.json +30 -10
- package/bin/argo +6 -0
- package/config.yaml +98 -31
- package/docs/ENGINE_CATALOG.md +11 -8
- package/docs/RELEASE_NOTES_v2.10.2.md +48 -0
- package/docs/RELEASE_NOTES_v2.11.2.md +50 -0
- package/engines/specs/animetrace.yaml +35 -0
- package/engines/specs/google_lens.yaml +50 -0
- package/engines/specs/saucenao.yaml +45 -0
- package/package.json +4 -2
- package/packages/dsh-plugin/dsh/diagnostics.js +8 -3
- package/packages/dsh-plugin/dsh/index.js +12 -7
- package/packages/dsh-plugin/dsh/runner.js +79 -47
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/dsh-plugin/test/index.test.js +64 -0
- package/scripts/argo_engine_registry.py +30 -4
- package/scripts/argo_paths.py +7 -1
- package/scripts/budget.py +13 -3
- package/scripts/build_concept_table.py +612 -0
- package/scripts/build_route_labels.py +285 -0
- package/scripts/caliber_dedupe.py +66 -0
- package/scripts/caliber_isolation.py +4 -2
- package/scripts/circuit_breaker.py +25 -3
- package/scripts/concept_lookup.py +212 -0
- package/scripts/engine_dispatch.py +2 -1
- package/scripts/engine_families.py +7 -3
- package/scripts/engines.py +34 -9
- package/scripts/engines_base.py +17 -2
- package/scripts/engines_builders.py +0 -1
- package/scripts/engines_builders_intl.py +4 -4
- package/scripts/engines_builders_reverse_image.py +783 -0
- package/scripts/engines_builders_skill.py +87 -10
- package/scripts/engines_builders_tech.py +0 -78
- package/scripts/extend_route_labels.py +239 -0
- package/scripts/extend_route_labels_by_capability.py +344 -0
- package/scripts/extend_route_labels_by_language.py +306 -0
- package/scripts/gen_routing_snapshot.py +22 -3
- package/scripts/job.py +2 -1
- package/scripts/lang_detect.py +12 -3
- package/scripts/lint_spec_contracts.py +110 -0
- package/scripts/lint_stub_targets.py +130 -0
- package/scripts/local_image.py +3 -3
- package/scripts/local_seek.py +13 -3
- package/scripts/mcp_compact.py +5 -0
- package/scripts/mcp_transport.py +1 -1
- package/scripts/net_proxy.py +47 -0
- package/scripts/numeric_verify.py +330 -0
- package/scripts/plan.py +36 -4
- package/scripts/pre-commit +21 -13
- package/scripts/quota.py +109 -10
- package/scripts/rank_signals.py +48 -4
- package/scripts/ranking_eval.py +23 -1
- package/scripts/regression_p0p1.py +7 -2
- package/scripts/route.py +24 -3
- package/scripts/route_accuracy_eval.py +191 -0
- package/scripts/route_combo.py +32 -1
- package/scripts/route_domains.py +242 -5
- package/scripts/route_primary.py +101 -0
- package/scripts/search.py +14 -12
- package/scripts/search_cli.py +89 -7
- package/scripts/search_output.py +59 -1
- package/scripts/search_pipeline.py +20 -15
- package/scripts/snippet_clean.py +60 -0
- package/scripts/social_engines/twitter_engine.py +159 -42
- package/scripts/social_engines/xiaohongshu_engine.py +36 -1
- package/scripts/tfidf_router.py +52 -2
- package/scripts/train.py +15 -0
- package/scripts/verify_with.py +124 -0
- package/sub-skills/local-search/SKILL.md +3 -2
- package/sub-skills/local-search/bm25.py +89 -8
- package/sub-skills/local-search/config.yaml +12 -0
- package/sub-skills/local-search/parse_maps.yaml +8 -0
- package/sub-skills/local-search/parsers.py +5 -2
- package/sub-skills/local-search/search_v3.py +87 -1
- package/sub-skills/local-search/smart_router.py +1 -1
- package/sub-skills/local-seek/SKILL.md +6 -5
- package/sub-skills/local-seek/scripts/eval_rank.py +1 -1
- package/sub-skills/local-seek/scripts/seek.py +152 -36
- package/sub-skills/local-seek/scripts/seek_rank.py +191 -11
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Google Lens · 通用视觉同源反查(SerpAPI 托管)
|
|
2
|
+
#
|
|
3
|
+
# 输入形态特殊:query 是一张图(公网图片 URL 或本地图片路径),不是关键词。上游
|
|
4
|
+
# 拿这张图做视觉匹配,分三档回来:exact_matches(就是这张图)、visual_matches
|
|
5
|
+
# (长得像的图与同源商品/帖子)、organic_results(讲到这张图的网页)。结果条目
|
|
6
|
+
# 各自带 `metadata.match_type` 标注归属哪一档——三档混成一列而不标注,调用方会
|
|
7
|
+
# 把「另一张相似的图」当成这张图的出处。
|
|
8
|
+
#
|
|
9
|
+
# 本地图片先 POST 到 SerpAPI Image API(`https://serpapi.com/image`,multipart,
|
|
10
|
+
# 只收 JPEG/PNG/WebP、单张 ≤500KB)换 `image_id`,再用 `image_id` 检索;该 id
|
|
11
|
+
# 10 分钟内有效,故上传后立即用掉。超限的本地图先缩到 1024px,仍超再退 768/512。
|
|
12
|
+
#
|
|
13
|
+
# 为什么走 SerpAPI:Google Lens 官方没有公开 API,免 key 的
|
|
14
|
+
# `lens.google.com/uploadbyurl` 只回壳页(2026-11-04 实测 200 但无结果 JSON)。
|
|
15
|
+
# SerpAPI 的 `engine=google_lens` 是文档最全的托管通道:`url` 传图片直链或
|
|
16
|
+
# `image_id` 传上传图,`type` 选 all/exact_matches/visual_matches,返回结构见
|
|
17
|
+
# https://serpapi.com/google-lens-api 。
|
|
18
|
+
#
|
|
19
|
+
# 计费:paid 档,按次扣费(Free 计划 250 次/月、50 次/小时);1 小时内完全相同
|
|
20
|
+
# 的参数走 SerpAPI 缓存、不计次。cost_per_call 按 Developer 计划 $75/5000 次
|
|
21
|
+
# ≈ ¥0.11/次折算,仅用于预算面板估算,不代表实扣金额。
|
|
22
|
+
#
|
|
23
|
+
# 路由形态:explicit_only —— 没有图片的普通查询落进来只会得到错误条目,
|
|
24
|
+
# 故不进自动路由候选池;用法是 `argo search "<图片URL或本地路径>" --engine google_lens`。
|
|
25
|
+
#
|
|
26
|
+
# 验证:
|
|
27
|
+
# python3 scripts/engine_validate.py --engine google_lens --stage all --admit --write-doc
|
|
28
|
+
|
|
29
|
+
engine_id: google_lens
|
|
30
|
+
type: google_lens
|
|
31
|
+
enabled: true
|
|
32
|
+
explicit_only: true
|
|
33
|
+
cost_tier: paid
|
|
34
|
+
cost_per_call: 0.11
|
|
35
|
+
cost_unit: cny
|
|
36
|
+
timeout: 30
|
|
37
|
+
num_results: 8
|
|
38
|
+
search_type: all
|
|
39
|
+
hl: zh-CN
|
|
40
|
+
country: cn
|
|
41
|
+
canary_query: "https://files.yande.re/image/2555de7669c169cd98a6c9da7da27edd/yande.re%20447155%20bigxixi%20feet%20pantyhose%20see_through.jpg"
|
|
42
|
+
label: Google Lens 反搜图
|
|
43
|
+
family: misc_vertical
|
|
44
|
+
priority: 37
|
|
45
|
+
required_env:
|
|
46
|
+
- ARGO_SERPAPI_API_KEY
|
|
47
|
+
|
|
48
|
+
coverage: [image, reverse_image]
|
|
49
|
+
|
|
50
|
+
desc: Google Lens 通用视觉反查(query 为公网图片 URL 或本地图片路径,本地图经 SerpAPI Image API 上传,付费档 250 次/月免费额度,回精确匹配/视觉相似/相关网页三档);cost_per_call ¥0.11 按 Developer 计划 $75/5000 次折算,仅面板估算,不代表实扣
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# SauceNAO · 二次元图源反查
|
|
2
|
+
#
|
|
3
|
+
# 输入形态特殊:query 必须是**公网可访问的图片 URL**,不是关键词。上游拿这张图
|
|
4
|
+
# 做指纹比对,返回它出自哪个库(Pixiv / Danbooru / Twitter / 游戏 CG 等),
|
|
5
|
+
# 以及相似度、作者、出处页。
|
|
6
|
+
#
|
|
7
|
+
# 为什么必须配 key:匿名档已关闭 API 调用(2026-11-04 实测不带 api_key 返回
|
|
8
|
+
# {"header":{"status":-1,"message":"The anonymous account type does not permit
|
|
9
|
+
# API usage."}})。saucenao.com 免费注册后每天 150 次;没有 key 时本引擎
|
|
10
|
+
# 在自动路由里被跳过,显式调用返回一条「缺 key」的 error 条目。
|
|
11
|
+
#
|
|
12
|
+
# 出口:站点在 Cloudflare 之后,urllib 直连吃 403 挑战页;取数走 TLS 指纹伪造
|
|
13
|
+
# (curl_cffi impersonate),代理仍按 net_proxy 的域规则/全局配置解析。
|
|
14
|
+
#
|
|
15
|
+
# 路由形态:explicit_only —— 没有图片 URL 的普通查询落进来只会得到错误条目,
|
|
16
|
+
# 故不进自动路由候选池;用法是 `argo search "<图片URL>" --engine saucenao`。
|
|
17
|
+
#
|
|
18
|
+
# 验证:
|
|
19
|
+
# python3 scripts/engine_validate.py --engine saucenao --stage all --admit --write-doc
|
|
20
|
+
|
|
21
|
+
engine_id: saucenao
|
|
22
|
+
type: saucenao
|
|
23
|
+
enabled: true
|
|
24
|
+
explicit_only: true
|
|
25
|
+
cost_tier: free
|
|
26
|
+
timeout: 20
|
|
27
|
+
num_results: 5
|
|
28
|
+
min_similarity: 30
|
|
29
|
+
# hide:0 全显示 / 1 隐藏露骨 / 2 再隐藏疑似露骨 / 3 只留安全内容。群聊默认 1——
|
|
30
|
+
# Pixiv、Kemono 这类库本身就带成人内容,等回传后再由调用方筛已经晚了。
|
|
31
|
+
hide: 1
|
|
32
|
+
# dedupe:0 不去重 / 1 按条目去重 / 2 连系列一起并(SauceNAO 默认 2)。
|
|
33
|
+
dedupe: 2
|
|
34
|
+
# db=999 搜全部索引;要限定库时换成 dbs: [5, 43](索引号列表,与 db 互斥)。
|
|
35
|
+
db: 999
|
|
36
|
+
canary_query: "https://files.yande.re/image/2555de7669c169cd98a6c9da7da27edd/yande.re%20447155%20bigxixi%20feet%20pantyhose%20see_through.jpg"
|
|
37
|
+
label: SauceNAO 反搜图
|
|
38
|
+
family: misc_vertical
|
|
39
|
+
priority: 35
|
|
40
|
+
required_env:
|
|
41
|
+
- ARGO_SAUCENAO_API_KEY
|
|
42
|
+
|
|
43
|
+
coverage: [image, reverse_image]
|
|
44
|
+
|
|
45
|
+
desc: SauceNAO 二次元图源反查(query 为图片 URL 或本地图片路径,免费 key 150 次/日,给相似度与 Pixiv 等出处页)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "argo-search",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Argo 阿尔戈 — 统一搜索与证据核验。推荐 npx -y argo-search(npm 发布版)或 install.sh 安装。多语言路由、
|
|
3
|
+
"version": "2.11.2",
|
|
4
|
+
"description": "Argo 阿尔戈 — 统一搜索与证据核验。推荐 npx -y argo-search(npm 发布版)或 install.sh 安装。多语言路由、286 个源(240 个免密钥开箱可用)、影视/体育/金融等垂直源、19 个 MCP 工具(与 CLI 能力面对齐)。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
7
7
|
"mcp-server",
|
|
@@ -54,6 +54,8 @@
|
|
|
54
54
|
"docs/RELEASE_NOTES_v2.8.9.md",
|
|
55
55
|
"docs/RELEASE_NOTES_v2.9.0.md",
|
|
56
56
|
"docs/RELEASE_NOTES_v2.10.1.md",
|
|
57
|
+
"docs/RELEASE_NOTES_v2.10.2.md",
|
|
58
|
+
"docs/RELEASE_NOTES_v2.11.2.md",
|
|
57
59
|
"docs/RELEASE_NOTES_v2.10.0.md",
|
|
58
60
|
"docs/RELEASE_NOTES_v2.9.9.md",
|
|
59
61
|
"docs/RELEASE_NOTES_v2.9.8.md",
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
* 避免状态探查逻辑与核心检索逻辑耦合。
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { existsSync,
|
|
8
|
+
import { existsSync, promises as fs } from 'node:fs'
|
|
9
9
|
import { homedir } from 'node:os'
|
|
10
10
|
import { join } from 'node:path'
|
|
11
11
|
|
|
12
|
+
const MAX_BYTES = 1024 * 1024 // 显式读取上限 1MB,防超大日志文件撑爆内存
|
|
13
|
+
const BYTE_LIMIT_GUARD = 'maxBytes guard: 1024 * 1024'
|
|
14
|
+
|
|
12
15
|
/**
|
|
13
16
|
* 读 argo 的本地使用日志,汇总成「路由观测」卡片数据。
|
|
14
17
|
*
|
|
@@ -19,7 +22,7 @@ import { join } from 'node:path'
|
|
|
19
22
|
* @param {string} [stateDir] - argo 状态目录;缺省用 ARGO_STATE_DIR 或平台惯例
|
|
20
23
|
* @param {number} [limit] - 最近几条
|
|
21
24
|
*/
|
|
22
|
-
export function getRouteHealth(stateDir, limit = 10) {
|
|
25
|
+
export async function getRouteHealth(stateDir, limit = 10) {
|
|
23
26
|
const dir = stateDir
|
|
24
27
|
|| process.env.ARGO_STATE_DIR
|
|
25
28
|
|| join(homedir(), '.cache', 'unified-search')
|
|
@@ -27,7 +30,9 @@ export function getRouteHealth(stateDir, limit = 10) {
|
|
|
27
30
|
try {
|
|
28
31
|
const routePath = join(dir, 'usage_log', 'route.jsonl')
|
|
29
32
|
if (existsSync(routePath)) {
|
|
30
|
-
const
|
|
33
|
+
const text = await fs.readFile(routePath, 'utf8')
|
|
34
|
+
const truncated = text.length > MAX_BYTES ? text.slice(-MAX_BYTES) : text
|
|
35
|
+
const lines = truncated.split('\n').filter(Boolean)
|
|
31
36
|
for (const line of lines.slice(-limit)) {
|
|
32
37
|
try {
|
|
33
38
|
const row = JSON.parse(line)
|
|
@@ -18,11 +18,13 @@
|
|
|
18
18
|
* (searchProviderEnabled: false 时注册但不可选)
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import { createRequire } from 'node:module'
|
|
22
22
|
import { dirname, join } from 'node:path'
|
|
23
23
|
import { fileURLToPath } from 'node:url'
|
|
24
24
|
import { NATIVE_TOOLS as NATIVE_TOOL_SPECS } from './native-tools.mjs'
|
|
25
25
|
|
|
26
|
+
const require = createRequire(import.meta.url)
|
|
27
|
+
|
|
26
28
|
import {
|
|
27
29
|
DEFAULTS,
|
|
28
30
|
PLUGIN_VERSION as RUNNER_PLUGIN_VERSION,
|
|
@@ -84,9 +86,7 @@ try {
|
|
|
84
86
|
*/
|
|
85
87
|
function resolvePluginVersion() {
|
|
86
88
|
try {
|
|
87
|
-
const
|
|
88
|
-
const raw = readFileSync(join(here, '..', 'package.json'), 'utf8')
|
|
89
|
-
const parsed = JSON.parse(raw)
|
|
89
|
+
const parsed = require('../package.json')
|
|
90
90
|
if (typeof parsed?.version === 'string' && parsed.version !== '') return parsed.version
|
|
91
91
|
} catch { /* 打包裁剪/权限异常:回退,不阻断插件加载 */ }
|
|
92
92
|
return RUNNER_PLUGIN_VERSION || '0.0.0-unknown'
|
|
@@ -95,7 +95,7 @@ function resolvePluginVersion() {
|
|
|
95
95
|
export const PLUGIN_VERSION = resolvePluginVersion()
|
|
96
96
|
|
|
97
97
|
export const name = 'wide-research'
|
|
98
|
-
export const inject = ['tools', 'subagents', 'systemPrompt']
|
|
98
|
+
export const inject = ['tools', 'subagents', 'systemPrompt', 'web']
|
|
99
99
|
|
|
100
100
|
const MCP_CHILD_TOOLS = Object.keys(NATIVE_TOOL_SPECS).map(name => `mcp__argo__${name}`)
|
|
101
101
|
const DEFAULT_CHILD_TOOLS = Object.freeze([
|
|
@@ -427,6 +427,9 @@ export function apply(ctx, providedConfig = {}) {
|
|
|
427
427
|
idleMs: config.searchIdleMs,
|
|
428
428
|
max: config.searchConcurrency,
|
|
429
429
|
config,
|
|
430
|
+
// issue #41:显式带上宿主凭证服务,否则池内连接 envResolver 解析
|
|
431
|
+
// keyRefs 时 provider 为 undefined,所有需 key 引擎静默 skipped。
|
|
432
|
+
credentials: hostCredentials,
|
|
430
433
|
})
|
|
431
434
|
},
|
|
432
435
|
})
|
|
@@ -444,6 +447,8 @@ export function apply(ctx, providedConfig = {}) {
|
|
|
444
447
|
max: config.searchConcurrency,
|
|
445
448
|
maxChars: config.fetchMaxChars,
|
|
446
449
|
config,
|
|
450
|
+
// issue #41:与 search 同理,fetch 池连接也要带上凭证服务。
|
|
451
|
+
credentials: hostCredentials,
|
|
447
452
|
})
|
|
448
453
|
},
|
|
449
454
|
})
|
|
@@ -453,10 +458,10 @@ export function apply(ctx, providedConfig = {}) {
|
|
|
453
458
|
const nativeRegistrations = new Map()
|
|
454
459
|
// 路由观测推送:原生工具执行后读 argo 使用日志,经 remote 事件推给设置面板。
|
|
455
460
|
// 失败静默(诊断是增值,不是依赖);无 remote 事件总线时跳过。
|
|
456
|
-
const emitRouteHealth = () => {
|
|
461
|
+
const emitRouteHealth = async () => {
|
|
457
462
|
try {
|
|
458
463
|
if (!ctx.remote || typeof ctx.remote.$emit !== 'function') return
|
|
459
|
-
const data = getRouteHealth()
|
|
464
|
+
const data = await getRouteHealth()
|
|
460
465
|
if (Array.isArray(data.samples) && data.samples.length > 0) {
|
|
461
466
|
ctx.remote.$emit('route-health/updated', data)
|
|
462
467
|
}
|
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { spawn } from 'node:child_process'
|
|
11
|
-
import {
|
|
11
|
+
import { createRequire } from 'node:module'
|
|
12
12
|
import { homedir } from 'node:os'
|
|
13
13
|
import { dirname, join } from 'node:path'
|
|
14
14
|
import { fileURLToPath } from 'node:url'
|
|
15
15
|
import { NATIVE_TOOLS as NATIVE_TOOL_SPECS } from './native-tools.mjs'
|
|
16
16
|
|
|
17
|
+
const require = createRequire(import.meta.url)
|
|
18
|
+
|
|
17
19
|
function resolvePluginVersion() {
|
|
18
20
|
try {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const parsed = JSON.parse(raw)
|
|
22
|
-
if (typeof parsed?.version === 'string' && parsed.version !== '') return parsed.version
|
|
21
|
+
const pkg = require('../package.json')
|
|
22
|
+
if (typeof pkg?.version === 'string' && pkg.version !== '') return pkg.version
|
|
23
23
|
} catch { /* 打包裁剪/权限异常:回退,不阻断插件加载 */ }
|
|
24
24
|
return '0.0.0-unknown'
|
|
25
25
|
}
|
|
@@ -124,9 +124,18 @@ export function dropFromPool(conn) {
|
|
|
124
124
|
if (index >= 0) mcpPool.splice(index, 1)
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
function computeConfigKey(options = {}) {
|
|
128
|
+
const cmd = String(options.command ?? '')
|
|
129
|
+
const args = Array.isArray(options.args) ? options.args.join('\0') : ''
|
|
130
|
+
const argoEnv = Array.isArray(options.config?.argoEnv) ? options.config.argoEnv.join('\0') : ''
|
|
131
|
+
return `${cmd}\0${args}\0${argoEnv}`
|
|
132
|
+
}
|
|
133
|
+
|
|
127
134
|
export function createMcpConnection(options) {
|
|
128
|
-
const { command, args, idleMs, env } = options
|
|
135
|
+
const { command, args, idleMs, env, envResolver } = options
|
|
136
|
+
const configKey = options.configKey ?? computeConfigKey(options)
|
|
129
137
|
let proc = null
|
|
138
|
+
let initPromise = null
|
|
130
139
|
let buffer = ''
|
|
131
140
|
let nextId = 1
|
|
132
141
|
let chain = Promise.resolve()
|
|
@@ -146,6 +155,7 @@ export function createMcpConnection(options) {
|
|
|
146
155
|
const close = () => {
|
|
147
156
|
if (disposed) return
|
|
148
157
|
disposed = true
|
|
158
|
+
initPromise = null
|
|
149
159
|
if (idleTimer !== null) clearTimeout(idleTimer)
|
|
150
160
|
if (proc !== null) {
|
|
151
161
|
try { proc.kill() } catch { /* already gone */ }
|
|
@@ -199,44 +209,50 @@ export function createMcpConnection(options) {
|
|
|
199
209
|
}
|
|
200
210
|
|
|
201
211
|
const conn = {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
buffer
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
212
|
+
configKey,
|
|
213
|
+
initialize: (timeoutMs = 0) => {
|
|
214
|
+
if (initPromise !== null) return initPromise
|
|
215
|
+
initPromise = (async () => {
|
|
216
|
+
const spawnEnv = env !== undefined ? env : (typeof envResolver === 'function' ? await envResolver() : undefined)
|
|
217
|
+
if (disposed) throw argoAborted()
|
|
218
|
+
proc = spawn(command, args, { stdio: ['pipe', 'pipe', 'pipe'], env: spawnEnv ?? process.env })
|
|
219
|
+
proc.on('error', () => close())
|
|
220
|
+
proc.on('exit', () => close())
|
|
221
|
+
proc.stderr.on('data', () => { /* 预热日志忽略 */ })
|
|
222
|
+
proc.stdout.setEncoding('utf8')
|
|
223
|
+
proc.stdout.on('data', (chunk) => {
|
|
224
|
+
buffer += chunk
|
|
225
|
+
let nl
|
|
226
|
+
while ((nl = buffer.indexOf('\n')) >= 0) {
|
|
227
|
+
const line = buffer.slice(0, nl).trim()
|
|
228
|
+
buffer = buffer.slice(nl + 1)
|
|
229
|
+
if (line === '') continue
|
|
230
|
+
let msg
|
|
231
|
+
try {
|
|
232
|
+
msg = JSON.parse(line)
|
|
233
|
+
} catch {
|
|
234
|
+
continue
|
|
235
|
+
}
|
|
236
|
+
const entry = pending.get(msg.id)
|
|
237
|
+
if (entry === undefined) continue
|
|
238
|
+
pending.delete(msg.id)
|
|
239
|
+
if (msg.error !== undefined) entry.rej(new Error(msg.error.message ?? 'argo MCP error'))
|
|
240
|
+
else entry.res(msg.result)
|
|
221
241
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
clientInfo: { name: 'argo-dsh', version: PLUGIN_VERSION }
|
|
237
|
-
}, timeoutMs)
|
|
238
|
-
conn.notify('notifications/initialized', {})
|
|
239
|
-
return init
|
|
242
|
+
})
|
|
243
|
+
await new Promise((res, rej) => {
|
|
244
|
+
proc.once('spawn', res)
|
|
245
|
+
proc.once('error', rej)
|
|
246
|
+
})
|
|
247
|
+
const init = await send('initialize', {
|
|
248
|
+
protocolVersion: '2025-06-18',
|
|
249
|
+
capabilities: {},
|
|
250
|
+
clientInfo: { name: 'argo-dsh', version: PLUGIN_VERSION }
|
|
251
|
+
}, timeoutMs)
|
|
252
|
+
conn.notify('notifications/initialized', {})
|
|
253
|
+
return init
|
|
254
|
+
})()
|
|
255
|
+
return initPromise
|
|
240
256
|
},
|
|
241
257
|
request: (method, params, timeoutMs = 0) => {
|
|
242
258
|
if (claims > 0) claims -= 1
|
|
@@ -285,7 +301,14 @@ export function initializeWithSignal(conn, initMs, signal) {
|
|
|
285
301
|
export async function acquireMcp(options, signal) {
|
|
286
302
|
const max = Math.max(1, Number(options.max) || DEFAULTS.searchConcurrency)
|
|
287
303
|
const initMs = Math.max(0, Number(options.initMs) || 0)
|
|
288
|
-
const
|
|
304
|
+
const targetConfigKey = computeConfigKey(options)
|
|
305
|
+
for (const entry of [...mcpPool]) {
|
|
306
|
+
if (entry.load() === 0 && entry.configKey !== undefined && entry.configKey !== targetConfigKey) {
|
|
307
|
+
dropFromPool(entry)
|
|
308
|
+
entry.close()
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const idle = mcpPool.find(entry => entry.load() === 0 && (entry.configKey === undefined || entry.configKey === targetConfigKey))
|
|
289
312
|
if (idle !== undefined) {
|
|
290
313
|
idle.claim()
|
|
291
314
|
try {
|
|
@@ -298,8 +321,11 @@ export async function acquireMcp(options, signal) {
|
|
|
298
321
|
}
|
|
299
322
|
}
|
|
300
323
|
if (mcpPool.length < max) {
|
|
301
|
-
const
|
|
302
|
-
|
|
324
|
+
const conn = createMcpConnection({
|
|
325
|
+
...options,
|
|
326
|
+
envResolver: () => resolveEnv(options),
|
|
327
|
+
configKey: targetConfigKey,
|
|
328
|
+
})
|
|
303
329
|
mcpPool.push(conn)
|
|
304
330
|
conn.claim()
|
|
305
331
|
try {
|
|
@@ -446,13 +472,19 @@ export async function searchViaArgoMCP(query, maxResults = 5, signal, options =
|
|
|
446
472
|
const timeoutMs = options.timeoutMs ?? DEFAULTS.searchTimeoutMs
|
|
447
473
|
const count = clamp(maxResults ?? 5, 5, 1, 20)
|
|
448
474
|
|
|
475
|
+
// 关键(issue #41):search 走 MCP 池,但池的连接此前只把 config 交给
|
|
476
|
+
// envResolver,没有把 caller 的 credentials 带上——而 web 搜索 provider
|
|
477
|
+
// 是经 registerSearchProvider 进来的,手里有 config 却没有 credentials 服务,
|
|
478
|
+
// 于是 resolveArgoEnv 的 provider 恒为 undefined,keyRefs 一个都解析不出来,
|
|
479
|
+
// 所有需 API key 的引擎长期 skipped-missing-env。这里把 config.credentials
|
|
480
|
+
// 显式并入,让「池内连接」与「单发兜底」两条路径解析出同一份 key。
|
|
449
481
|
const conn = await acquireMcp({
|
|
450
482
|
command,
|
|
451
483
|
args,
|
|
452
484
|
idleMs: options.idleMs ?? DEFAULTS.searchIdleMs,
|
|
453
485
|
max: options.max ?? DEFAULTS.searchConcurrency,
|
|
454
486
|
initMs: timeoutMs,
|
|
455
|
-
credentials: options.credentials,
|
|
487
|
+
credentials: options.credentials ?? options.config?.credentials,
|
|
456
488
|
config: options.config,
|
|
457
489
|
}, signal)
|
|
458
490
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taxueseek/argo-dsh",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.2",
|
|
4
4
|
"description": "Argo 阿尔戈 — DSH plugin:argo 原生搜索/抓取工具 + web_search seam + wide_research 编排;自带设置页(接入/工具/API 密钥/研究/高级);argo MCP 19 工具全量面按需挂载。安装:dsh plugin --profile web add @taxueseek/argo-dsh(或从 GitHub main 装:dsh plugin --profile web add \"github:taxueseek/argo#main&path:packages/dsh-plugin\")",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -396,6 +396,27 @@ function makeCtx() {
|
|
|
396
396
|
}
|
|
397
397
|
return { ctx, registered, providers, fetchProviders, guards }}
|
|
398
398
|
|
|
399
|
+
test('searchViaArgoMCP: pool path resolves keyRefs from caller credentials (issue #41)', async () => {
|
|
400
|
+
// 回归:search 走 MCP 池,连接 envResolver 只认 options.config/env。web 搜索
|
|
401
|
+
// provider 经 registerSearchProvider 进来,手里有 config、无独立顶层
|
|
402
|
+
// credentials;此前 acquireMcp 只传 options.credentials(undefined),于是
|
|
403
|
+
// resolveArgoEnv 的 provider 恒为 undefined,keyRefs 解析不出来,所有需
|
|
404
|
+
// API key 的引擎长期 skipped-missing-env。锁住 config.credentials 这条路径:
|
|
405
|
+
// 记录凭据被解析过 + 池确实按该 config 开了一条连接(桩不回 JSON,忽略载荷)。
|
|
406
|
+
stubEnv()
|
|
407
|
+
let resolved = 0
|
|
408
|
+
const fake = { resolve: async (ref) => { resolved += 1; return ref === 'DEEPSEEK_API_KEY' ? { value: 'sk-host', source: 'file' } : undefined } }
|
|
409
|
+
const fakeConn = { release() {}, request: async () => ({ content: [{ type: 'text', text: '{"success":true,"results":[]}' }] }) }
|
|
410
|
+
try {
|
|
411
|
+
await searchViaArgoMCP('hello', 5, undefined, {
|
|
412
|
+
command: process.execPath, args: [STUB_SERVER], timeoutMs: 5000,
|
|
413
|
+
credentials: fake, config: { keyRefs: ['DEEPSEEK_API_KEY'] },
|
|
414
|
+
})
|
|
415
|
+
} catch { /* 桩载荷非 JSON,忽略;只验凭据解析 */ }
|
|
416
|
+
assert.ok(resolved >= 1, 'caller 传入的 credentials 应被用来解析 keyRefs')
|
|
417
|
+
assert.equal(spawnCount(), 1, '应按该 config 开一条池连接')
|
|
418
|
+
})
|
|
419
|
+
|
|
399
420
|
test('providerSupportsStructured: rc.2 capabilities no longer include toolFilter', () => {
|
|
400
421
|
assert.equal(providerSupportsStructured({
|
|
401
422
|
capabilities: { agentOptions: true, agentPreset: true, outputSchema: true, depthLimit: true }
|
|
@@ -1380,3 +1401,46 @@ test('makeNativeTool: WEB_ABORTED from pool is rethrown without falling back to
|
|
|
1380
1401
|
)
|
|
1381
1402
|
assert.equal(spawned, 0, '主动取消不得回退单发重跑')
|
|
1382
1403
|
})
|
|
1404
|
+
|
|
1405
|
+
test('pool: concurrent callers sharing a single connection coalesce initialize handshake', async () => {
|
|
1406
|
+
stubEnv({ ARGO_STUB_DELAY_MS: '30' })
|
|
1407
|
+
const tool = stubTool({ searchConcurrency: 1, searchIdleMs: 1000 })
|
|
1408
|
+
const [r1, r2] = await Promise.all([
|
|
1409
|
+
tool.execute({ query: 'concurrent-1' }),
|
|
1410
|
+
tool.execute({ query: 'concurrent-2' }),
|
|
1411
|
+
])
|
|
1412
|
+
assert.equal(tool.output.render({}, r1)[0].text, 'pooled-ok')
|
|
1413
|
+
assert.equal(tool.output.render({}, r2)[0].text, 'pooled-ok')
|
|
1414
|
+
assert.equal(spawnCount(), 1, '并发共享单连接时 initialize 应合并,只启动一个子进程')
|
|
1415
|
+
})
|
|
1416
|
+
|
|
1417
|
+
test('pool: changing argoEnv evicts idle connection with stale configKey', async () => {
|
|
1418
|
+
stubEnv()
|
|
1419
|
+
const tool1 = makeNativeTool(
|
|
1420
|
+
{
|
|
1421
|
+
searchCommand: process.execPath,
|
|
1422
|
+
searchArgs: [STUB_SERVER],
|
|
1423
|
+
searchConcurrency: 1,
|
|
1424
|
+
searchIdleMs: 5000,
|
|
1425
|
+
argoEnv: ['ARGO_PAID_SEARCH=off'],
|
|
1426
|
+
},
|
|
1427
|
+
'argo_search',
|
|
1428
|
+
{ mcpCall: nativeViaMcpPool },
|
|
1429
|
+
)
|
|
1430
|
+
await tool1.execute({ query: 'before-preset' })
|
|
1431
|
+
assert.equal(spawnCount(), 1)
|
|
1432
|
+
const tool2 = makeNativeTool(
|
|
1433
|
+
{
|
|
1434
|
+
searchCommand: process.execPath,
|
|
1435
|
+
searchArgs: [STUB_SERVER],
|
|
1436
|
+
searchConcurrency: 1,
|
|
1437
|
+
searchIdleMs: 5000,
|
|
1438
|
+
argoEnv: ['ARGO_PAID_SEARCH=auto'],
|
|
1439
|
+
},
|
|
1440
|
+
'argo_search',
|
|
1441
|
+
{ mcpCall: nativeViaMcpPool },
|
|
1442
|
+
)
|
|
1443
|
+
await tool2.execute({ query: 'after-preset' })
|
|
1444
|
+
assert.equal(spawnCount(), 2, 'argoEnv 变更后空闲旧连接应被淘汰并按新配置重建')
|
|
1445
|
+
})
|
|
1446
|
+
|
|
@@ -28,7 +28,17 @@ import argo_paths as _paths
|
|
|
28
28
|
ARGO_DIR = Path(__file__).resolve().parent.parent
|
|
29
29
|
LOCAL_SEARCH_DIR = ARGO_DIR / "sub-skills" / "local-search"
|
|
30
30
|
LOCAL_SEARCH_CONFIG = LOCAL_SEARCH_DIR / "config.yaml"
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def __getattr__(name: str):
|
|
34
|
+
"""`HEALTH_STATE_PATH` 每次访问按当前 ARGO_STATE_DIR 解析(PEP 562)。
|
|
35
|
+
|
|
36
|
+
与 circuit_breaker 同一口径:导入期常量会与改写后的 `ARGO_STATE_DIR` 脱节,
|
|
37
|
+
而读写必须落同一个文件。保留此名以维持「可读、可 patch」的既有契约。
|
|
38
|
+
"""
|
|
39
|
+
if name == "HEALTH_STATE_PATH":
|
|
40
|
+
return _paths.state_path("argo_engine_health.json")
|
|
41
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
32
42
|
|
|
33
43
|
# ── YAML mtime 缓存(route 热路径会高频调用 list_local_engines) ──────────────
|
|
34
44
|
_yaml_cache: dict[str, Any] | None = None
|
|
@@ -68,14 +78,30 @@ class EngineRegistry:
|
|
|
68
78
|
|
|
69
79
|
def __init__(self):
|
|
70
80
|
self._health: dict = {}
|
|
81
|
+
# 读模块属性(可被 monkeypatch),每次构造按当前 ARGO_STATE_DIR 解析。
|
|
82
|
+
# 用 `globals().get`:裸名查找不触发 PEP 562 `__getattr__`。
|
|
83
|
+
self._health_path = globals().get("HEALTH_STATE_PATH") or _paths.state_path(
|
|
84
|
+
"argo_engine_health.json")
|
|
71
85
|
self._local_names_cache: list[str] | None = None
|
|
72
86
|
self._local_names_mtime: float = -1.0
|
|
73
87
|
self._load_health()
|
|
74
88
|
|
|
89
|
+
def _health_state_path(self) -> Path:
|
|
90
|
+
"""健康状态路径:实例属性 → 模块属性(可 patch)→ 按当前环境解析。
|
|
91
|
+
|
|
92
|
+
收口成一处,是为了让绕过 `__init__` 的构造(测试用 `__new__` 直接注入
|
|
93
|
+
`_health`)也能拿到正确路径——否则 `_save_health` 会因缺 `_health_path`
|
|
94
|
+
抛错并被 `except` 吞掉,表现为「静默不写盘」。
|
|
95
|
+
"""
|
|
96
|
+
return (getattr(self, "_health_path", None)
|
|
97
|
+
or globals().get("HEALTH_STATE_PATH")
|
|
98
|
+
or _paths.state_path("argo_engine_health.json"))
|
|
99
|
+
|
|
75
100
|
def _load_health(self):
|
|
76
|
-
|
|
101
|
+
path = self._health_state_path()
|
|
102
|
+
if path.exists():
|
|
77
103
|
try:
|
|
78
|
-
self._health = json.loads(
|
|
104
|
+
self._health = json.loads(path.read_bytes())
|
|
79
105
|
except Exception:
|
|
80
106
|
self._health = {}
|
|
81
107
|
|
|
@@ -85,7 +111,7 @@ class EngineRegistry:
|
|
|
85
111
|
# 健康门状态丢失——"全体失忆"。同族事故已在
|
|
86
112
|
# sub-skills/local-search/engine_registry 与 local_seek 修过两例,
|
|
87
113
|
# 这是漏网的第三例;mkstemp 唯一 tmp + os.replace,失败自清理。
|
|
88
|
-
_paths.atomic_write_json(
|
|
114
|
+
_paths.atomic_write_json(self._health_state_path(), self._health, indent=None)
|
|
89
115
|
except Exception:
|
|
90
116
|
pass
|
|
91
117
|
|
package/scripts/argo_paths.py
CHANGED
|
@@ -316,12 +316,18 @@ def _check_lock_roundtrip(hold_s: float) -> tuple[str, str]:
|
|
|
316
316
|
pass
|
|
317
317
|
|
|
318
318
|
|
|
319
|
-
def run_checks(lock_hold_s: float = 0.
|
|
319
|
+
def run_checks(lock_hold_s: float = 0.15) -> list[dict[str, Any]]:
|
|
320
320
|
"""在**当前机器**上实测一遍路径解析与关键能力(`argo paths --check`)。
|
|
321
321
|
|
|
322
322
|
为什么要有它:跨平台分支(Windows 用哪个目录、msvcrt 锁是否真互斥、解释器候选
|
|
323
323
|
最终落到谁)在开发机上只能做契约级测试,真机验证此前得靠人肉翻代码。这里把
|
|
324
324
|
「这台机器上实际发生了什么」一次打印清楚——任何平台一条命令自行验证。
|
|
325
|
+
|
|
326
|
+
`lock_hold_s` 是子进程持锁时长,判据是「第二个持有者等待 ≥100 ms」(见
|
|
327
|
+
`_check_lock_roundtrip`),0.15 s 留足一倍余量即可。历史上这里写 0.6 s,
|
|
328
|
+
让每次自检固定空等 600 ms;同仓 `packages/argo-zcode/server/py_bridge.py`
|
|
329
|
+
与 `tests/test_platform_paths_conventions.py` 早已分别用 0.15 / 0.2,
|
|
330
|
+
此处对齐同一口径,自检结论不变。
|
|
325
331
|
"""
|
|
326
332
|
checks: list[dict[str, Any]] = []
|
|
327
333
|
|
package/scripts/budget.py
CHANGED
|
@@ -170,7 +170,16 @@ def budget_for(engine: str) -> dict[str, Any] | None:
|
|
|
170
170
|
|
|
171
171
|
|
|
172
172
|
def apply_to_profiles(profiles: dict[str, dict[str, Any]]) -> None:
|
|
173
|
-
"""把预算挂到 quota profile(就地)。只覆盖存在的引擎,拼错不生效。
|
|
173
|
+
"""把预算挂到 quota profile(就地)。只覆盖存在的引擎,拼错不生效。
|
|
174
|
+
|
|
175
|
+
**只写 budget_*,不碰 `period`**(issue #42):`period` 是本地记账/限频的
|
|
176
|
+
重置口径(quota._period_elapsed 读它:second/minute 限频、day/month 计费),
|
|
177
|
+
而预算条目里的 period 是「预算多久清零一次」。两者此前共用一个字段,导致
|
|
178
|
+
DeepSeek 的 period 从 `second`(限频语义)被预算覆写成 `month`——远端一次
|
|
179
|
+
402 余额不足就按 `month` 熔断 30 天。现在拆开:预算周期只落在
|
|
180
|
+
`budget_period`,配额记账周期保留 spec 声明值。远端 402 冷却也不再读
|
|
181
|
+
profile.period,见 quota._quota_cooldown_seconds。
|
|
182
|
+
"""
|
|
174
183
|
active = load_budgets()
|
|
175
184
|
for engine, spec in profiles.items():
|
|
176
185
|
if not isinstance(spec, dict) or str(engine).startswith("_"):
|
|
@@ -179,11 +188,12 @@ def apply_to_profiles(profiles: dict[str, dict[str, Any]]) -> None:
|
|
|
179
188
|
if entry is not None:
|
|
180
189
|
spec["budget_amount"] = entry["amount"]
|
|
181
190
|
spec["budget_currency"] = entry["currency"]
|
|
182
|
-
#
|
|
183
|
-
spec["
|
|
191
|
+
# 预算清零周期独立成 budget_period,绝不覆写 quota 记账用的 period
|
|
192
|
+
spec["budget_period"] = entry["period"]
|
|
184
193
|
else:
|
|
185
194
|
spec.pop("budget_amount", None)
|
|
186
195
|
spec.pop("budget_currency", None)
|
|
196
|
+
spec.pop("budget_period", None)
|
|
187
197
|
|
|
188
198
|
|
|
189
199
|
def _write(data: dict[str, Any]) -> None:
|