earshot-cli 0.4.0__tar.gz → 0.5.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.4.0 → earshot_cli-0.5.0}/PKG-INFO +9 -1
  2. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/README.md +8 -0
  3. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/pyproject.toml +1 -1
  4. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/auth.py +23 -0
  5. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/cli.py +56 -1
  6. earshot_cli-0.5.0/tests/test_credential_lifecycle.py +118 -0
  7. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/.github/workflows/ci.yml +0 -0
  8. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/.github/workflows/publish.yml +0 -0
  9. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/.gitignore +0 -0
  10. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/LICENSE +0 -0
  11. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/scripts/download_models.sh +0 -0
  12. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/__init__.py +0 -0
  13. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/capture.py +0 -0
  14. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/compose.py +0 -0
  15. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/config.py +0 -0
  16. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/deliver.py +0 -0
  17. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/extract.py +0 -0
  18. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/live.py +0 -0
  19. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/models.py +0 -0
  20. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/subtitle.py +0 -0
  21. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/transcribe.py +0 -0
  22. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/src/earshot/transcribe_cloud.py +0 -0
  23. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/conftest.py +0 -0
  24. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_auth.py +0 -0
  25. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_compose.py +0 -0
  26. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_config.py +0 -0
  27. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_deliver.py +0 -0
  28. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_deliver_api.py +0 -0
  29. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_do_deliver.py +0 -0
  30. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_extract.py +0 -0
  31. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_live.py +0 -0
  32. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_me.py +0 -0
  33. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_subtitle.py +0 -0
  34. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_ua.py +0 -0
  35. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/tests/test_wizard.py +0 -0
  36. {earshot_cli-0.4.0 → earshot_cli-0.5.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: earshot-cli
3
- Version: 0.4.0
3
+ Version: 0.5.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
@@ -137,6 +137,14 @@ earshot login # 浏览器打开授权页,点「授权登录」即完成(已
137
137
  earshot me # 显示凭据状态与服务连通性(「凭据状态:有效」即就绪)
138
138
  ```
139
139
 
140
+ 凭据生命周期闭环(login → me → update → logout):
141
+
142
+ ```bash
143
+ earshot update --api-key <新key> # 替换 API Key(新 key 从 exomind 管理端复制;缺省交互粘贴)
144
+ earshot logout # 清除本地凭据(保留服务器地址;exomind-cli/fireCut 共用该配置会一并失效)
145
+ earshot help [命令] # 查看帮助(如 earshot help listen)
146
+ ```
147
+
140
148
  没有 ExoMind 账号?投递可换任意 webhook(`--deliver webhook --webhook <url>`),或 `--deliver none` 只本地存档,两者都不需要登录。
141
149
 
142
150
  `earshot` 与 `earshot-cli` 两个命令名等价可用;`earshot doctor` 可做完整环境自检。
@@ -104,6 +104,14 @@ earshot login # 浏览器打开授权页,点「授权登录」即完成(已
104
104
  earshot me # 显示凭据状态与服务连通性(「凭据状态:有效」即就绪)
105
105
  ```
106
106
 
107
+ 凭据生命周期闭环(login → me → update → logout):
108
+
109
+ ```bash
110
+ earshot update --api-key <新key> # 替换 API Key(新 key 从 exomind 管理端复制;缺省交互粘贴)
111
+ earshot logout # 清除本地凭据(保留服务器地址;exomind-cli/fireCut 共用该配置会一并失效)
112
+ earshot help [命令] # 查看帮助(如 earshot help listen)
113
+ ```
114
+
107
115
  没有 ExoMind 账号?投递可换任意 webhook(`--deliver webhook --webhook <url>`),或 `--deliver none` 只本地存档,两者都不需要登录。
108
116
 
109
117
  `earshot` 与 `earshot-cli` 两个命令名等价可用;`earshot doctor` 可做完整环境自检。
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "earshot-cli"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  description = "旁听剪藏:跨平台桌面端系统声录制 → 本地转写 → 投递知识库(默认 ExoMind,可插拔)"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -148,3 +148,26 @@ def save_credentials(
148
148
  path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
149
149
  path.chmod(0o600)
150
150
  return path
151
+
152
+
153
+ def clear_credentials(config_path: Path | None = None) -> Path | None:
154
+ """清除配置里的 api_key(置空,保留 base_url 等其他字段)——登出只清本地。
155
+
156
+ Args:
157
+ config_path: 配置文件路径,测试注入;缺省 ``~/.exomind/config.json``。
158
+
159
+ Returns:
160
+ 实际写入的配置文件路径;文件不存在或本就没有凭据时返回 None(无事可做)。
161
+ """
162
+ path = config_path if config_path is not None else Path.home() / EXOMIND_CONFIG_FILENAME
163
+ try:
164
+ raw = json.loads(path.read_text(encoding="utf-8"))
165
+ except (OSError, ValueError):
166
+ return None
167
+ if not isinstance(raw, dict) or not raw.get("api_key"):
168
+ return None
169
+ data = {k: v for k, v in raw.items() if isinstance(v, str)}
170
+ data["api_key"] = ""
171
+ path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
172
+ path.chmod(0o600)
173
+ return path
@@ -13,7 +13,7 @@ from pathlib import Path
13
13
  import numpy as np
14
14
 
15
15
  from earshot import __version__
16
- from earshot.auth import device_login, save_credentials, verify_key
16
+ from earshot.auth import clear_credentials, device_login, save_credentials, verify_key
17
17
  from earshot.capture import blackhole_missing_hint, list_capture_devices, pick_device, record_to_wav
18
18
  from earshot.compose import NoteMeta, add_punctuation, derive_title, group_paragraphs, outbox_path, render_markdown
19
19
  from earshot.config import DEFAULT_EXOMIND_BASE_URL, Settings, load_settings
@@ -84,6 +84,14 @@ def build_parser() -> argparse.ArgumentParser:
84
84
  p_login.add_argument("--base-url", default=DEFAULT_EXOMIND_BASE_URL, help="exomind API 地址")
85
85
  p_login.add_argument("--force", action="store_true", help="跳过「凭据仍有效」检查,无条件重新登录")
86
86
 
87
+ p_update = sub.add_parser("update", help="替换 API Key(新 key 从 exomind 管理端复制;获取凭据用 login)")
88
+ p_update.add_argument("--api-key", default=None, help="新 API Key(不填则交互粘贴)")
89
+
90
+ sub.add_parser("logout", help="清除本地凭据(保留服务器地址;exomind-cli/fireCut 共用该配置,会一并失效)")
91
+
92
+ p_help = sub.add_parser("help", help="显示帮助:earshot help [命令]")
93
+ p_help.add_argument("topic", nargs="?", default=None, help="要查看帮助的命令名")
94
+
87
95
  sub.add_parser("devices", help="列出可用采集设备")
88
96
  sub.add_parser("doctor", help="环境自检")
89
97
  p_clean = sub.add_parser("clean", help="清理过期留档(outbox+tmp)")
@@ -553,6 +561,42 @@ def cmd_login(args: argparse.Namespace, settings: Settings) -> int:
553
561
  return EXIT_OK
554
562
 
555
563
 
564
+ def cmd_update(args: argparse.Namespace, settings: Settings) -> int:
565
+ """替换 API Key:已拿到新 key(exomind 管理端复制)时本地换上。
566
+
567
+ 只管替换,不管新 key 怎么来——获取凭据走 login 的设备流。探活不通过不写入
568
+ (与 cmd_login 同款纪律,避免无效 key 覆盖现有有效配置)。
569
+ """
570
+ key = args.api_key
571
+ if not key:
572
+ key = _prompt("新 API Key(回车取消)")
573
+ if not key:
574
+ print("未提供凭据,未改动。")
575
+ return EXIT_OK
576
+ base_url = settings.exomind_base_url or DEFAULT_EXOMIND_BASE_URL
577
+ if not verify_key(base_url, key):
578
+ print(f"✗ 凭据探活失败({base_url}),未写入;确认 key 有效后重试")
579
+ return EXIT_FAIL
580
+ path = save_credentials(base_url, key)
581
+ masked = f"{key[:8]}…{key[-4:]}" if len(key) > 12 else key
582
+ print(f"✓ 凭据已替换:{masked}")
583
+ print(f" 已写入 {path}")
584
+ return EXIT_OK
585
+
586
+
587
+ def cmd_logout(_args: argparse.Namespace, _settings: Settings) -> int:
588
+ """清除本地凭据(保留 base_url);~/.exomind/config.json 三家共用,登出影响一并说清。"""
589
+ path = clear_credentials()
590
+ if path is None:
591
+ print("未登录(本地无凭据),无需登出。")
592
+ return EXIT_OK
593
+ print(f"✓ 已登出,本地凭据已清除({path})")
594
+ print(" 服务器地址保留;重新登录: earshot login")
595
+ print(" 注意: ~/.exomind/config.json 由 earshot/exomind-cli/fireCut 共享,它们的调用也会失效")
596
+ print(" 服务端吊销该 key 请到 exomind 管理端(account 页)操作")
597
+ return EXIT_OK
598
+
599
+
556
600
  def main(argv: list[str] | None = None) -> int:
557
601
  parser = build_parser()
558
602
  args = parser.parse_args(argv)
@@ -563,11 +607,22 @@ def main(argv: list[str] | None = None) -> int:
563
607
  "video": cmd_video,
564
608
  "deliver": cmd_deliver,
565
609
  "login": cmd_login,
610
+ "update": cmd_update,
611
+ "logout": cmd_logout,
566
612
  "me": cmd_me,
567
613
  "devices": cmd_devices,
568
614
  "doctor": cmd_doctor,
569
615
  "clean": cmd_clean,
570
616
  }
617
+ if args.command == "help":
618
+ if args.topic:
619
+ # 复用 argparse 自己的 -h 渲染:earshot help listen ≡ earshot listen --help
620
+ try:
621
+ parser.parse_args([args.topic, "--help"])
622
+ except SystemExit as exc:
623
+ return int(exc.code or 0)
624
+ parser.print_help()
625
+ return EXIT_OK
571
626
  if args.command is None:
572
627
  if not _interactive():
573
628
  parser.print_help()
@@ -0,0 +1,118 @@
1
+ """凭据生命周期测试:update(替换)/logout(清除)/help(子命令帮助)。
2
+
3
+ update/logout 与 emcli/wxpub 同款语义——update 只管替换(新 key 从管理端复制,
4
+ 获取凭据走 login 设备流),logout 只清本地(保留 base_url,三家共用文件的影响要说清)。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import argparse
10
+ import json
11
+ from pathlib import Path
12
+
13
+ import pytest
14
+
15
+ from earshot.auth import clear_credentials
16
+ from earshot.cli import main
17
+ from earshot.config import Settings
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://exomind.example",
25
+ exomind_api_key="",
26
+ )
27
+
28
+
29
+ def _write_config(path: Path, api_key: str = "sk_live_old_key") -> None:
30
+ path.write_text(json.dumps({"base_url": "https://exomind.example", "api_key": api_key}), encoding="utf-8")
31
+
32
+
33
+ class TestClearCredentials:
34
+ def test_清除_api_key_保留_base_url(self, tmp_path: Path) -> None:
35
+ cfg = tmp_path / "config.json"
36
+ _write_config(cfg)
37
+ assert clear_credentials(cfg) == cfg
38
+ data = json.loads(cfg.read_text(encoding="utf-8"))
39
+ assert data["api_key"] == ""
40
+ assert data["base_url"] == "https://exomind.example"
41
+
42
+ def test_无配置文件或本就无凭据_返回_none(self, tmp_path: Path) -> None:
43
+ assert clear_credentials(tmp_path / "absent.json") is None
44
+ empty = tmp_path / "empty.json"
45
+ _write_config(empty, api_key="")
46
+ assert clear_credentials(empty) is None
47
+
48
+
49
+ class TestCmdUpdate:
50
+ def test_新_key_探活通过_替换落盘(
51
+ self,
52
+ monkeypatch: pytest.MonkeyPatch,
53
+ capsys: pytest.CaptureFixture[str],
54
+ tmp_path: Path,
55
+ ) -> None:
56
+ monkeypatch.setattr("earshot.cli.verify_key", lambda base, key: True)
57
+ saved: dict[str, str] = {}
58
+
59
+ def fake_save(base_url: str, api_key: str) -> Path:
60
+ saved["base_url"], saved["key"] = base_url, api_key
61
+ return tmp_path / "config.json"
62
+
63
+ monkeypatch.setattr("earshot.cli.save_credentials", fake_save)
64
+ args = argparse.Namespace(api_key="sk_live_new_key")
65
+ from earshot.cli import cmd_update
66
+
67
+ code = cmd_update(args, _settings())
68
+ assert code == 0
69
+ assert saved == {"base_url": "https://exomind.example", "key": "sk_live_new_key"}
70
+ assert "凭据已替换" in capsys.readouterr().out
71
+
72
+ def test_探活失败_不写入(self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
73
+ monkeypatch.setattr("earshot.cli.verify_key", lambda base, key: False)
74
+ monkeypatch.setattr("earshot.cli.save_credentials", lambda *a, **k: pytest.fail("探活失败不得落盘"))
75
+ args = argparse.Namespace(api_key="sk_live_bad")
76
+ from earshot.cli import cmd_update
77
+
78
+ code = cmd_update(args, _settings())
79
+ assert code == 1
80
+ assert "未写入" in capsys.readouterr().out
81
+
82
+
83
+ class TestCmdLogout:
84
+ def test_有凭据_清除并提示共用影响(
85
+ self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
86
+ ) -> None:
87
+ monkeypatch.setattr("earshot.cli.clear_credentials", lambda: tmp_path / "config.json")
88
+ from earshot.cli import cmd_logout
89
+
90
+ code = cmd_logout(argparse.Namespace(), _settings())
91
+ out = capsys.readouterr().out
92
+ assert code == 0
93
+ assert "已登出" in out
94
+ assert "fireCut" in out, "三家共用 config.json 的影响必须说清"
95
+
96
+ def test_无凭据_无事可做(self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
97
+ monkeypatch.setattr("earshot.cli.clear_credentials", lambda: None)
98
+ from earshot.cli import cmd_logout
99
+
100
+ code = cmd_logout(argparse.Namespace(), _settings())
101
+ assert code == 0
102
+ assert "无需登出" in capsys.readouterr().out
103
+
104
+
105
+ class TestHelpCommand:
106
+ def test_help_无参数_打印总览(self, capsys: pytest.CaptureFixture[str]) -> None:
107
+ assert main(["help"]) == 0
108
+ out = capsys.readouterr().out
109
+ assert "usage: earshot" in out
110
+ assert "update" in out and "logout" in out, "新命令要在帮助里可见"
111
+
112
+ def test_help_带命令名_打印该命令帮助(self, capsys: pytest.CaptureFixture[str]) -> None:
113
+ assert main(["help", "login"]) == 0
114
+ assert "--force" in capsys.readouterr().out
115
+
116
+ def test_help_未知命令_报错不崩(self, capsys: pytest.CaptureFixture[str]) -> None:
117
+ # argparse 对无效 choice 打错误 + 退出码 2,main 收敛为返回值
118
+ assert main(["help", "no-such-cmd"]) == 2
File without changes
File without changes
File without changes