argo-search 2.17.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/AGENTS.md +3 -3
  2. package/README.es.md +10 -5
  3. package/README.ja.md +10 -5
  4. package/README.ko.md +10 -5
  5. package/README.md +11 -6
  6. package/README.zh.md +11 -6
  7. package/SKILL.md +12 -11
  8. package/assets/readme/counts.json +1 -1
  9. package/assets/readme/hero.svg +3 -3
  10. package/backends/domain_profiles.json +6 -0
  11. package/backends/engine_registry.yaml +12 -0
  12. package/backends/quota_profiles.json +10 -0
  13. package/bin/argo +78 -12
  14. package/docs/CHANGELOG.md +19 -1
  15. package/docs/COMMIT_STANDARD.md +2 -2
  16. package/docs/ENGINE_CATALOG.md +7 -6
  17. package/docs/RELEASE_NOTES_v2.17.0.md +4 -2
  18. package/docs/RELEASE_NOTES_v2.18.0.md +87 -0
  19. package/docs/RELEASING.md +1 -1
  20. package/engines/specs/twitter_cli.yaml +17 -0
  21. package/engines/specs/twitter_syndication.yaml +2 -3
  22. package/package.json +2 -1
  23. package/packages/dsh-plugin/dsh/native-tools.mjs +10 -0
  24. package/packages/dsh-plugin/dsh/workbench-io.js +34 -15
  25. package/packages/dsh-plugin/dsh/workbench-search.js +66 -6
  26. package/packages/dsh-plugin/dsh/workbench.js +43 -0
  27. package/packages/dsh-plugin/package.json +1 -1
  28. package/packages/dsh-plugin/test/workbench-concurrency.test.js +9 -11
  29. package/packages/dsh-plugin/test/workbench.test.js +85 -0
  30. package/scripts/affected_tests.py +324 -0
  31. package/scripts/badcase_ledger.py +93 -2
  32. package/scripts/check_commit_report.py +13 -9
  33. package/scripts/cli_io.py +8 -3
  34. package/scripts/engine_families.py +1 -0
  35. package/scripts/engine_states.py +4 -4
  36. package/scripts/engines.py +2 -0
  37. package/scripts/engines_base.py +12 -28
  38. package/scripts/engines_builders_intl.py +20 -94
  39. package/scripts/engines_twitter_cli.py +182 -0
  40. package/scripts/fetch_cli_output.py +75 -0
  41. package/scripts/fetch_dispatch.py +248 -0
  42. package/scripts/fetch_quality.py +11 -0
  43. package/scripts/fetch_v3.py +48 -114
  44. package/scripts/intent_router.py +224 -0
  45. package/scripts/mcp_compact.py +3 -0
  46. package/scripts/mcp_handlers.py +24 -4
  47. package/scripts/mcp_tools.py +2 -0
  48. package/scripts/mcp_transport.py +1 -1
  49. package/scripts/mcp_warm.py +15 -11
  50. package/scripts/output_transparency.py +10 -0
  51. package/scripts/pre-commit +9 -1
  52. package/scripts/release_check.py +1 -2
  53. package/scripts/research_notes.py +52 -5
  54. package/scripts/retry_policy.py +17 -3
  55. package/scripts/route_combo.py +8 -3
  56. package/scripts/search.py +29 -29
  57. package/scripts/search_cli.py +104 -8
  58. package/scripts/search_output.py +4 -1
  59. package/scripts/social_research.py +8 -6
  60. package/scripts/time_utils.py +28 -0
  61. package/scripts/twitter_single_read.py +107 -0
  62. package/scripts/x_keyword_route.py +138 -0
  63. package/scripts/x_search.py +24 -33
  64. package/scripts/zhihu_answer_body.py +96 -0
  65. package/scripts/zhihu_answer_fetch.py +66 -0
  66. package/scripts/zhihu_answer_lookup.py +138 -0
  67. package/sub-skills/local-seek/SKILL.md +3 -1
  68. package/sub-skills/local-seek/scripts/seek.py +80 -109
  69. package/sub-skills/local-seek/scripts/seek_git.py +65 -0
  70. package/sub-skills/local-seek/scripts/seek_inspect.py +242 -0
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env python3
2
+ """seek_git.py — local-seek 历史层(文件提交历史与单行 blame)。
3
+
4
+ 从 seek.py 拆出:独立封装 git 只读查询,runner 支持注入以兼容既有单测 monkeypatch。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import subprocess
10
+ from pathlib import Path
11
+ from typing import Any, Callable
12
+
13
+
14
+ def _default_run(cmd: list[str], timeout: float | None = 30) -> Any:
15
+ try:
16
+ return subprocess.run(
17
+ cmd, capture_output=True, text=True,
18
+ encoding="utf-8", errors="replace", timeout=timeout or 30,
19
+ )
20
+ except (OSError, subprocess.TimeoutExpired):
21
+ return None
22
+
23
+
24
+ def git_log(
25
+ path: str | Path,
26
+ n: int = 10,
27
+ timeout: float | None = None,
28
+ *,
29
+ runner: Callable[..., Any] | None = None,
30
+ ) -> tuple[str, int]:
31
+ """输出文件的最近提交历史(git log --oneline)。"""
32
+ run_fn = runner or _default_run
33
+ p = Path(path).expanduser()
34
+ if not p.is_file():
35
+ return f"local-seek: {path} 不是文件", 1
36
+ proc = run_fn(["git", "-C", str(p.parent), "log", "--oneline", f"-{n}", "--", p.name],
37
+ timeout=timeout)
38
+ if proc is None:
39
+ return "local-seek: git 执行失败", 1
40
+ if proc.returncode == 128 or (proc.returncode == 0 and not proc.stdout.strip()):
41
+ inside = run_fn(["git", "-C", str(p.parent), "rev-parse", "--is-inside-work-tree"])
42
+ if inside is None or inside.returncode != 0:
43
+ return f"local-seek: {p.name} 不在 git 仓库中", 1
44
+ return f"local-seek: {p.name} 无提交历史", 0
45
+ lines = proc.stdout.splitlines()
46
+ return "\n".join([f"local-seek: {p.name} 最近 {len(lines)} 条提交"] + lines), 0
47
+
48
+
49
+ def git_blame(
50
+ path: str | Path,
51
+ line: str | int,
52
+ timeout: float | None = None,
53
+ *,
54
+ runner: Callable[..., Any] | None = None,
55
+ ) -> tuple[str, int]:
56
+ """输出文件第 N 行的 blame 信息(谁在哪个提交改的)。"""
57
+ run_fn = runner or _default_run
58
+ p = Path(path).expanduser()
59
+ if not p.is_file():
60
+ return f"local-seek: {path} 不是文件", 1
61
+ proc = run_fn(["git", "-C", str(p.parent), "blame", "-L", f"{line},{line}", "--", p.name],
62
+ timeout=timeout)
63
+ if proc is None or proc.returncode != 0:
64
+ return f"local-seek: git blame 失败({p.name} 可能在 git 仓库外或行号无效)", 1
65
+ return f"local-seek: {p.name} 第 {line} 行\n{proc.stdout.strip()}", 0
@@ -0,0 +1,242 @@
1
+ #!/usr/bin/env python3
2
+ """seek_inspect.py — local-seek 精读层(文件结构大纲、符号体一跳直读、流式按行读取)。
3
+
4
+ 从 seek.py 拆出:纯标准库实现,职责严格限定在「已知单文件后的局部结构与源码读取」。
5
+ 支持文本与结构化 JSON 双形态输出(供 --agent / DSH 工作台直接消费)。
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import re
12
+ from pathlib import Path
13
+ from typing import Any
14
+
15
+ _OUTLINE_RULES: dict[str, list[re.Pattern[str]]] = {
16
+ ".py": [re.compile(r"^\s*(async\s+)?(def|class)\s+\w+")],
17
+ ".pyi": [re.compile(r"^\s*(async\s+)?(def|class)\s+\w+")],
18
+ ".js": [
19
+ re.compile(r"^\s*(export\s+)?(async\s+)?(function|class)\s+\w+"),
20
+ re.compile(r"^\s*(export\s+)?(const|let|var)\s+\w+"),
21
+ ],
22
+ ".jsx": [
23
+ re.compile(r"^\s*(export\s+)?(async\s+)?(function|class)\s+\w+"),
24
+ re.compile(r"^\s*(export\s+)?(const|let|var)\s+\w+"),
25
+ ],
26
+ ".ts": [
27
+ re.compile(r"^\s*(export\s+)?(async\s+)?(function|class|interface|type|enum)\s+\w+"),
28
+ re.compile(r"^\s*(export\s+)?(const|let|var)\s+\w+"),
29
+ ],
30
+ ".tsx": [
31
+ re.compile(r"^\s*(export\s+)?(async\s+)?(function|class|interface|type|enum)\s+\w+"),
32
+ re.compile(r"^\s*(export\s+)?(const|let|var)\s+\w+"),
33
+ ],
34
+ ".go": [
35
+ re.compile(r"^\s*func\s+\w+"),
36
+ re.compile(r"^\s*type\s+\w+\s+(struct|interface)\b"),
37
+ ],
38
+ ".rs": [re.compile(r"^\s*(pub\s+)?(fn|struct|enum|impl|trait|mod|type)\s+\w+")],
39
+ ".java": [
40
+ re.compile(r"^\s*(public|private|protected|static|\s)*(class|interface|enum)\s+\w+"),
41
+ re.compile(r"^\s*(public|private|protected|static|\s)*[\w<>,\[\] ]+\s+\w+\s*\("),
42
+ ],
43
+ ".sh": [
44
+ re.compile(r"^\s*function\s+\w+"),
45
+ re.compile(r"^\s*[a-zA-Z_]\w*\s*\(\)\s*\{?"),
46
+ ],
47
+ ".bash": [
48
+ re.compile(r"^\s*function\s+\w+"),
49
+ re.compile(r"^\s*[a-zA-Z_]\w*\s*\(\)\s*\{?"),
50
+ ],
51
+ ".zsh": [
52
+ re.compile(r"^\s*function\s+\w+"),
53
+ re.compile(r"^\s*[a-zA-Z_]\w*\s*\(\)\s*\{?"),
54
+ ],
55
+ ".md": [re.compile(r"^#{1,6}\s+")],
56
+ ".mdx": [re.compile(r"^#{1,6}\s+")],
57
+ ".json": [re.compile(r'^\s*"[^"]+"\s*:')],
58
+ ".yaml": [re.compile(r"^[a-zA-Z_][\w.-]*\s*:")],
59
+ ".yml": [re.compile(r"^[a-zA-Z_][\w.-]*\s*:")],
60
+ }
61
+
62
+
63
+ def _outline_level(line: str, suffix: str) -> int:
64
+ """返回结构行的层级:Markdown 按 # 数量,其余按前导空白长度。"""
65
+ if suffix in (".md", ".mdx"):
66
+ m = re.match(r"^(#{1,6})\s+", line)
67
+ return len(m.group(1)) if m else 99
68
+ return len(line) - len(line.lstrip(" \t"))
69
+
70
+
71
+ def _compute_outline_entries(
72
+ lines: list[str], rules: list[re.Pattern[str]], suffix: str
73
+ ) -> list[tuple[int, int, int, str]]:
74
+ """计算文件结构项及其精确起止行 [(start, end, span, text), ...]。"""
75
+ raw_hits = []
76
+ for i, ln in enumerate(lines, 1):
77
+ if any(r.match(ln) for r in rules):
78
+ raw_hits.append((i, _outline_level(ln, suffix), ln.strip()))
79
+ total = len(lines)
80
+ entries = []
81
+ for idx, (start, lvl, text) in enumerate(raw_hits):
82
+ end = total
83
+ for nxt_start, nxt_lvl, _ in raw_hits[idx + 1:]:
84
+ if nxt_lvl <= lvl:
85
+ end = nxt_start - 1
86
+ break
87
+ while end > start and not lines[end - 1].strip():
88
+ end -= 1
89
+ entries.append((start, end, end - start + 1, text))
90
+ return entries
91
+
92
+
93
+ def outline_file(path: str | Path, *, as_json: bool = False) -> tuple[str, int]:
94
+ """输出代码/文档文件结构(含精确起止行跨度),替代整文件读取。返回 (输出文本, 退出码)。"""
95
+ p = Path(path)
96
+ if not p.is_file():
97
+ msg = f"local-seek: {path} 不是文件"
98
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
99
+ try:
100
+ lines = p.read_text(encoding="utf-8", errors="replace").splitlines()
101
+ except OSError as e:
102
+ msg = f"local-seek: 读取失败 {e}"
103
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
104
+ suffix = p.suffix.lower()
105
+ rules = _OUTLINE_RULES.get(suffix)
106
+ if not rules:
107
+ if as_json:
108
+ return json.dumps({
109
+ "ok": True, "path": str(p), "total_lines": len(lines),
110
+ "entries": [], "note": f"{p.suffix or '无扩展名'} 暂无结构规则",
111
+ }, ensure_ascii=False), 0
112
+ return (f"local-seek: {p.name} 共 {len(lines)} 行"
113
+ f"({p.suffix or '无扩展名'} 暂无结构规则)"), 0
114
+ entries = _compute_outline_entries(lines, rules, suffix)
115
+ if as_json:
116
+ return json.dumps({
117
+ "ok": True,
118
+ "path": str(p),
119
+ "total_lines": len(lines),
120
+ "count": len(entries),
121
+ "entries": [
122
+ {"start": s, "end": e, "span": span, "signature": txt[:120]}
123
+ for s, e, span, txt in entries
124
+ ],
125
+ }, ensure_ascii=False), 0
126
+ hits = [f"{s}-{e} ({span}L): {txt[:100]}" for s, e, span, txt in entries]
127
+ head = f"local-seek: {p.name} 结构 {len(hits)} 处 / 共 {len(lines)} 行"
128
+ return "\n".join([head] + hits), 0
129
+
130
+
131
+ def read_symbol_body(
132
+ path: str | Path,
133
+ symbol_name: str,
134
+ max_lines: int = 200,
135
+ *,
136
+ as_json: bool = False,
137
+ ) -> tuple[str, int]:
138
+ """按符号名一跳读取定义区间源码(带真实行号,默认 ≤ 200 行封顶)。返回 (输出文本, 退出码)。"""
139
+ symbol_name = (symbol_name or "").strip()
140
+ if not symbol_name:
141
+ msg = "local-seek: --symbol-body 需要指定符号名"
142
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
143
+ p = Path(path)
144
+ if not p.is_file():
145
+ msg = f"local-seek: {path} 不是文件"
146
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
147
+ try:
148
+ lines = p.read_text(encoding="utf-8", errors="replace").splitlines()
149
+ except OSError as e:
150
+ msg = f"local-seek: 读取失败 {e}"
151
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
152
+ suffix = p.suffix.lower()
153
+ rules = _OUTLINE_RULES.get(suffix)
154
+ if not rules:
155
+ msg = f"local-seek: {p.name} 暂无结构规则({p.suffix or '无扩展名'}),请改用 --lines"
156
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
157
+ entries = _compute_outline_entries(lines, rules, suffix)
158
+ pat = re.compile(r"(?<!\w)" + re.escape(symbol_name) + r"(?!\w)")
159
+ matched = [item for item in entries if pat.search(item[3])]
160
+ if not matched:
161
+ low = symbol_name.lower()
162
+ matched = [item for item in entries if low in item[3].lower()]
163
+ if not matched:
164
+ msg = f"local-seek: {p.name} 中未找到符号 {symbol_name!r}(可先运行 --outline 查看结构)"
165
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
166
+
167
+ start, end, span, sig = matched[0]
168
+ cap = max(1, int(max_lines))
169
+ shown_end = min(end, start + cap - 1)
170
+ body = [f"{i}: {lines[i - 1]}" for i in range(start, shown_end + 1)]
171
+ if as_json:
172
+ payload: dict[str, Any] = {
173
+ "ok": True,
174
+ "path": str(p),
175
+ "symbol": symbol_name,
176
+ "signature": sig[:160],
177
+ "start": start,
178
+ "end": shown_end,
179
+ "symbol_end": end,
180
+ "span": span,
181
+ "total_lines": len(lines),
182
+ "truncated": shown_end < end,
183
+ "content": "\n".join(body),
184
+ }
185
+ if shown_end < end:
186
+ payload["next_range"] = f"{shown_end + 1}-{end}"
187
+ return json.dumps(payload, ensure_ascii=False), 0
188
+
189
+ extra = ""
190
+ if len(matched) > 1:
191
+ others = ", ".join(f"{s}-{e}" for s, e, _, _ in matched[1:5])
192
+ extra = f";另有 {len(matched) - 1} 处同名: {others}"
193
+ head = (
194
+ f"local-seek: {p.name} 符号 {symbol_name} 第 {start}-{shown_end} 行"
195
+ f"(共 {span} 行 / 文件 {len(lines)} 行{extra})"
196
+ )
197
+ if shown_end < end:
198
+ body.append(
199
+ f"... 已截断(上限 {cap} 行),继续读取:argo seek --lines {shown_end + 1}-{end} {path}"
200
+ )
201
+ return "\n".join([head] + body), 0
202
+
203
+
204
+ def read_lines(path: str | Path, spec: str, *, as_json: bool = False) -> tuple[str, int]:
205
+ """按行读取文件(单遍流式,不加载全文)。返回 (输出文本, 退出码)。"""
206
+ m = re.fullmatch(r"(\d+)-(\d+)", spec)
207
+ if not m:
208
+ msg = "local-seek: --lines 格式应为 N-M(如 10-20)"
209
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
210
+ a, b = int(m.group(1)), int(m.group(2))
211
+ if a < 1 or b < a:
212
+ msg = f"local-seek: 行范围无效 {spec}"
213
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
214
+ p = Path(path)
215
+ if not p.is_file():
216
+ msg = f"local-seek: {path} 不是文件"
217
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
218
+ picked, total = [], 0
219
+ try:
220
+ with open(p, encoding="utf-8", errors="replace") as f:
221
+ for i, ln in enumerate(f, 1):
222
+ total = i
223
+ if a <= i <= b:
224
+ picked.append(f"{i}: {ln.rstrip()}")
225
+ except OSError as e:
226
+ msg = f"local-seek: 读取失败 {e}"
227
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
228
+ if a > total:
229
+ msg = f"local-seek: {p.name} 只有 {total} 行,请求从 {a} 行开始"
230
+ return (json.dumps({"ok": False, "error": msg}, ensure_ascii=False) if as_json else msg), 1
231
+ end = min(b, total)
232
+ if as_json:
233
+ return json.dumps({
234
+ "ok": True,
235
+ "path": str(p),
236
+ "start": a,
237
+ "end": end,
238
+ "total_lines": total,
239
+ "content": "\n".join(picked),
240
+ }, ensure_ascii=False), 0
241
+ out = [f"local-seek: {p.name} 第 {a}-{end} 行 / 共 {total} 行"]
242
+ return "\n".join(out + picked), 0