earshot-cli 0.3.1__tar.gz → 0.4.0__tar.gz

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 (36) hide show
  1. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/PKG-INFO +1 -1
  2. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/pyproject.toml +1 -1
  3. earshot_cli-0.4.0/src/earshot/__init__.py +25 -0
  4. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/auth.py +3 -2
  5. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/deliver.py +2 -1
  6. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/transcribe_cloud.py +2 -1
  7. earshot_cli-0.4.0/tests/test_ua.py +63 -0
  8. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/uv.lock +1 -1
  9. earshot_cli-0.3.1/src/earshot/__init__.py +0 -7
  10. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/.github/workflows/ci.yml +0 -0
  11. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/.github/workflows/publish.yml +0 -0
  12. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/.gitignore +0 -0
  13. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/LICENSE +0 -0
  14. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/README.md +0 -0
  15. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/scripts/download_models.sh +0 -0
  16. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/capture.py +0 -0
  17. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/cli.py +0 -0
  18. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/compose.py +0 -0
  19. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/config.py +0 -0
  20. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/extract.py +0 -0
  21. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/live.py +0 -0
  22. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/models.py +0 -0
  23. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/subtitle.py +0 -0
  24. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/src/earshot/transcribe.py +0 -0
  25. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/conftest.py +0 -0
  26. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_auth.py +0 -0
  27. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_compose.py +0 -0
  28. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_config.py +0 -0
  29. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_deliver.py +0 -0
  30. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_deliver_api.py +0 -0
  31. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_do_deliver.py +0 -0
  32. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_extract.py +0 -0
  33. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_live.py +0 -0
  34. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_me.py +0 -0
  35. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_subtitle.py +0 -0
  36. {earshot_cli-0.3.1 → earshot_cli-0.4.0}/tests/test_wizard.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: earshot-cli
3
- Version: 0.3.1
3
+ Version: 0.4.0
4
4
  Summary: 旁听剪藏:跨平台桌面端系统声录制 → 本地转写 → 投递知识库(默认 ExoMind,可插拔)
5
5
  Project-URL: Homepage, https://github.com/helloworldtang/earshot
6
6
  Project-URL: Repository, https://github.com/helloworldtang/earshot
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "earshot-cli"
3
- version = "0.3.1"
3
+ version = "0.4.0"
4
4
  description = "旁听剪藏:跨平台桌面端系统声录制 → 本地转写 → 投递知识库(默认 ExoMind,可插拔)"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -0,0 +1,25 @@
1
+ """earshot:旁听剪藏 —— 听到的都能进知识库。
2
+
3
+ 跨平台桌面端:系统声环回录制(macOS 需 BlackHole)→ 端侧 VAD+ASR 转写
4
+ → 组装 Markdown → 投递(默认 exomind CLI,可插拔 webhook)。
5
+ """
6
+
7
+ from importlib import metadata as _metadata
8
+
9
+ try:
10
+ # 单一版本源:pyproject.toml(已安装发行版的元数据);源码 checkout 未安装时回退。
11
+ # 旧写法在此手写 "0.1.1",与 pyproject 的 0.3.x 漂移两月无人察觉——UA 带版本
12
+ # 后漂移会直接暴露在服务端日志里,先根治版本源。
13
+ # 注意发行版名是 earshot-cli(import 名才是 earshot),两个键都试。
14
+ __version__ = _metadata.version("earshot-cli")
15
+ except _metadata.PackageNotFoundError: # pragma: no cover - 仅源码运行路径
16
+ __version__ = "0.0.dev0"
17
+
18
+
19
+ def ua_headers(**extra: str) -> dict[str, str]:
20
+ """自有服务(exomind)请求头:显式 UA(可观测性标配)+ 附加头(Authorization 等)。
21
+
22
+ 全仓唯一注入点——deliver/auth/transcribe_cloud 旁路端点一律复用,不写两遍;
23
+ 第三方 webhook(deliver_webhook)不经过这里(无自有服务端可分桶,不值得改)。
24
+ """
25
+ return {"User-Agent": f"earshot/{__version__}", **extra}
@@ -17,6 +17,7 @@ from typing import Any
17
17
 
18
18
  import httpx
19
19
 
20
+ from earshot import ua_headers
20
21
  from earshot.config import EXOMIND_CONFIG_FILENAME
21
22
 
22
23
  Poster = Callable[[str, dict[str, Any]], dict[str, Any]]
@@ -26,13 +27,13 @@ Sleeper = Callable[[float], None]
26
27
 
27
28
 
28
29
  def _post_json(url: str, payload: dict[str, Any]) -> dict[str, Any]:
29
- resp = httpx.post(url, json=payload, timeout=30.0)
30
+ resp = httpx.post(url, json=payload, headers=ua_headers(), timeout=30.0)
30
31
  resp.raise_for_status()
31
32
  return dict(resp.json())
32
33
 
33
34
 
34
35
  def _get_status(url: str, headers: dict[str, str]) -> int:
35
- return int(httpx.get(url, headers=headers, timeout=30.0).status_code)
36
+ return int(httpx.get(url, headers=ua_headers(**headers), timeout=30.0).status_code)
36
37
 
37
38
 
38
39
  def _open_browser(url: str) -> bool:
@@ -12,6 +12,7 @@ from typing import Any
12
12
 
13
13
  import httpx
14
14
 
15
+ from earshot import ua_headers
15
16
  from earshot.config import Settings
16
17
 
17
18
  EXOMIND_ORIGIN = "earshot"
@@ -178,7 +179,7 @@ def deliver_exomind_api(
178
179
  post = poster or _post
179
180
  get = getter or _get
180
181
  base = settings.exomind_base_url
181
- headers = {"Authorization": f"Bearer {settings.exomind_api_key}"}
182
+ headers = ua_headers(Authorization=f"Bearer {settings.exomind_api_key}")
182
183
 
183
184
  content = md_path.read_text(encoding="utf-8")
184
185
  payload: dict[str, Any] = {"content": content, "origin": EXOMIND_ORIGIN, "client_key": client_key_for(content)}
@@ -7,6 +7,7 @@ from pathlib import Path
7
7
 
8
8
  import httpx
9
9
 
10
+ from earshot import ua_headers
10
11
  from earshot.config import Settings
11
12
 
12
13
  POLL_INTERVAL_S = 3.0
@@ -36,7 +37,7 @@ def transcribe_cloud(wav: Path, settings: Settings, timeout_s: float = DEFAULT_T
36
37
  msg = "未配置 exomind 凭据(先 `exomind login` 生成 ~/.exomind/config.json,或设 EXOMIND_API_KEY)"
37
38
  raise CloudTranscribeError(msg)
38
39
  base = settings.exomind_base_url
39
- headers = {"Authorization": f"Bearer {settings.exomind_api_key}"}
40
+ headers = ua_headers(Authorization=f"Bearer {settings.exomind_api_key}")
40
41
 
41
42
  try:
42
43
  with wav.open("rb") as f:
@@ -0,0 +1,63 @@
1
+ """显式 UA 护栏(可观测性标配,2026-11-09):自有服务(exomind)流量必须带
2
+ earshot/<version>,默认 python-httpx/x 即未收编。
3
+
4
+ 质量点:①ua_headers 单一注入点格式与合并;②deliver_exomind_api 的 wire 头
5
+ 真实携带(经注入 poster 捕获);③webhook(第三方)不经 ua_headers——无自有
6
+ 服务端可分桶,不乱标。
7
+ """
8
+
9
+ from pathlib import Path
10
+ from typing import Any
11
+
12
+ import httpx
13
+ import pytest
14
+
15
+ from earshot import __version__, ua_headers
16
+ from earshot.config import Settings
17
+ from earshot.deliver import deliver_exomind_api, deliver_webhook
18
+
19
+
20
+ def _settings() -> Settings:
21
+ return Settings(
22
+ home=Path("/tmp/earshot-test"),
23
+ model_root=Path("/tmp/earshot-test/models"),
24
+ exomind_base_url="https://api.example.com",
25
+ exomind_api_key="key-1",
26
+ )
27
+
28
+
29
+ def test_ua_headers_format_and_merge() -> None:
30
+ h = ua_headers(Authorization="Bearer k")
31
+ assert h["User-Agent"] == f"earshot/{__version__}"
32
+ assert h["Authorization"] == "Bearer k"
33
+ assert __version__ not in ("", "0.0.dev0"), "安装态下版本必须来自包元数据,不再是漂移的手写常量"
34
+
35
+
36
+ def test_deliver_api_carries_ua_on_wire(tmp_path: Path) -> None:
37
+ md = tmp_path / "n.md"
38
+ md.write_text("内容", encoding="utf-8")
39
+ seen: dict[str, str] = {}
40
+
41
+ def poster(_u: str, _p: dict[str, Any], h: dict[str, str]) -> dict[str, Any]:
42
+ seen.update(h)
43
+ return {"job_id": "j"}
44
+
45
+ def getter(_u: str, _p: dict[str, str], _h: dict[str, str]) -> dict[str, Any]:
46
+ return {"status": "done", "entities": 1}
47
+
48
+ deliver_exomind_api(md, "t", [], _settings(), poster=poster, getter=getter, poll_interval_s=0)
49
+ assert seen["User-Agent"].startswith("earshot/")
50
+ assert seen["Authorization"].startswith("Bearer ")
51
+
52
+
53
+ def test_webhook_does_not_claim_earshot_ua(monkeypatch: pytest.MonkeyPatch) -> None:
54
+ """第三方 webhook 不打 earshot UA——收编范围=自有服务,乱标反而污染对方统计。"""
55
+ sent: list[Any] = []
56
+
57
+ def fake_post(url: str, **kw: Any) -> httpx.Response:
58
+ sent.append(kw.get("headers")) # None = 未传头
59
+ return httpx.Response(200)
60
+
61
+ monkeypatch.setattr(httpx, "post", fake_post)
62
+ deliver_webhook("https://example.org/hook", "t", "c", ["a"])
63
+ assert sent == [None]
@@ -188,7 +188,7 @@ wheels = [
188
188
 
189
189
  [[package]]
190
190
  name = "earshot-cli"
191
- version = "0.1.1"
191
+ version = "0.4.0"
192
192
  source = { editable = "." }
193
193
  dependencies = [
194
194
  { name = "httpx" },
@@ -1,7 +0,0 @@
1
- """earshot:旁听剪藏 —— 听到的都能进知识库。
2
-
3
- 跨平台桌面端:系统声环回录制(macOS 需 BlackHole)→ 端侧 VAD+ASR 转写
4
- → 组装 Markdown → 投递(默认 exomind CLI,可插拔 webhook)。
5
- """
6
-
7
- __version__ = "0.1.1"
File without changes
File without changes
File without changes