token-tracker 0.4.4__tar.gz → 0.4.5__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 (48) hide show
  1. {token_tracker-0.4.4/src/token_tracker.egg-info → token_tracker-0.4.5}/PKG-INFO +1 -1
  2. {token_tracker-0.4.4 → token_tracker-0.4.5}/pyproject.toml +1 -1
  3. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/hooks.py +13 -5
  4. {token_tracker-0.4.4 → token_tracker-0.4.5/src/token_tracker.egg-info}/PKG-INFO +1 -1
  5. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_hooks.py +16 -0
  6. {token_tracker-0.4.4 → token_tracker-0.4.5}/LICENSE +0 -0
  7. {token_tracker-0.4.4 → token_tracker-0.4.5}/README.md +0 -0
  8. {token_tracker-0.4.4 → token_tracker-0.4.5}/setup.cfg +0 -0
  9. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/__init__.py +0 -0
  10. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/__init__.py +0 -0
  11. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/claude.py +0 -0
  12. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/codex.py +0 -0
  13. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/rate_limits.py +0 -0
  14. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/registry.py +0 -0
  15. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/types.py +0 -0
  16. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/util.py +0 -0
  17. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/analyzer/__init__.py +0 -0
  18. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/analyzer/aggregator.py +0 -0
  19. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/analyzer/blocks.py +0 -0
  20. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/analyzer/cost.py +0 -0
  21. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/cli.py +0 -0
  22. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/config.py +0 -0
  23. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/i18n.py +0 -0
  24. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/__init__.py +0 -0
  25. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/console.py +0 -0
  26. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/format.py +0 -0
  27. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/heatmap.py +0 -0
  28. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/panels.py +0 -0
  29. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/status.py +0 -0
  30. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/tables.py +0 -0
  31. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/theme.py +0 -0
  32. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/themes.py +0 -0
  33. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/wizard.py +0 -0
  34. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/SOURCES.txt +0 -0
  35. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/dependency_links.txt +0 -0
  36. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/entry_points.txt +0 -0
  37. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/requires.txt +0 -0
  38. {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/top_level.txt +0 -0
  39. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_aggregator.py +0 -0
  40. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_blocks.py +0 -0
  41. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_cli.py +0 -0
  42. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_codex.py +0 -0
  43. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_cost.py +0 -0
  44. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_heatmap.py +0 -0
  45. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_status.py +0 -0
  46. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_tables.py +0 -0
  47. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_theme.py +0 -0
  48. {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: token-tracker
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: Track token usage across local AI agents (Claude Code, Codex)
5
5
  Author-email: stormzhang <stormzhang.dev@gmail.com>
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "token-tracker"
7
- version = "0.4.4"
7
+ version = "0.4.5"
8
8
  description = "Track token usage across local AI agents (Claude Code, Codex)"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -702,13 +702,21 @@ def _has_tt_codex_statusline(content: str) -> bool:
702
702
 
703
703
  def _install_codex_statusline(content: str, python: str) -> str:
704
704
  """落盘 Codex statusline 脚本 + 在 config.toml 末尾追加 Stop hook 段。
705
- 新名(codex-statusline)已存在幂等返回;只存在旧名(tt-statusline)→ 清掉后追加(迁移)。"""
705
+ - 新名 codex-statusline 段已存在 + python 路径一致 幂等返回;
706
+ - 已存在但 python 路径不一致(用户升级 Python / 切换 conda/venv / 卸载某环境后跑 tt setup)→ 删旧装新,
707
+ 避免 command 指向已死 python(症状:脚本 import token_tracker 失败被 try/except 吞掉,状态栏只剩项目名);
708
+ - 只存在旧名 tt-statusline → 清掉后追加新路径段(老用户迁移)。"""
706
709
  _write_codex_statusline_script()
707
- if "codex-statusline" in content:
708
- return content
709
- if "tt-statusline" in content: # 旧路径残留 → 清掉,下面追加新路径段
710
- content = _CODEX_STATUSLINE_REGEX.sub("\n", content)
711
710
  cmd = f"{python} {CODEX_STATUSLINE_HOOK_PATH}"
711
+ if "codex-statusline" in content or "tt-statusline" in content:
712
+ # 从已有的 command 行提取 python 路径(兼容 basic / literal string 包裹)
713
+ m = re.search(
714
+ r"command = [\"']([^ ]+) [^\"']*(?:codex-statusline|tt-statusline)[^\"']*[\"']",
715
+ content,
716
+ )
717
+ if m and m.group(1) == python and "codex-statusline" in content:
718
+ return content # python 一致 + 已是新名 → 幂等
719
+ content = _CODEX_STATUSLINE_REGEX.sub("\n", content) # 路径不一致或老名残留 → 删旧段
712
720
  return content.rstrip() + (
713
721
  "\n\n[[hooks.Stop]]\n\n"
714
722
  "[[hooks.Stop.hooks]]\n"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: token-tracker
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: Track token usage across local AI agents (Claude Code, Codex)
5
5
  Author-email: stormzhang <stormzhang.dev@gmail.com>
6
6
  License: MIT License
@@ -80,12 +80,28 @@ def test_codex_statusline_install_uninstall_roundtrip(tmp_path, monkeypatch):
80
80
  assert "tt-statusline" not in removed and 'command = "mine"' in removed
81
81
 
82
82
 
83
+ def test_codex_statusline_install_updates_stale_python(tmp_path, monkeypatch):
84
+ # 回归:用户升级 Python / 切换 conda/venv 后再跑 tt setup,
85
+ # 老的 codex-statusline 段被无脑幂等保留 → command 指向已死 python → 状态栏半残(issue 用户反馈)。
86
+ monkeypatch.setattr(hooks, "CODEX_STATUSLINE_HOOK_PATH", str(tmp_path / "codex-statusline.py"))
87
+ first = hooks._install_codex_statusline("", "/old/python")
88
+ assert "/old/python" in first
89
+ # 同 python 再装 → 幂等保持
90
+ assert hooks._install_codex_statusline(first, "/old/python") == first
91
+ # 换 python(用户升级了 Python / 切了环境)→ 必须重写、删旧段、装新段
92
+ second = hooks._install_codex_statusline(first, "/new/python")
93
+ assert "/new/python" in second
94
+ assert "/old/python" not in second # 死路径清干净
95
+ assert second.count("[[hooks.Stop]]") == 1 # 没残留两段
96
+
97
+
83
98
  def test_codex_statusline_windows_path_toml_parses(tmp_path, monkeypatch):
84
99
  # 回归:Windows 路径含 \U \A \P 等被 TOML basic string 当 unicode 转义起始符(issue 用户反馈)
85
100
  # —— 写入的 command 必须用 literal string(单引号)包裹,写出来后能被 tomllib 原样解析回来。
86
101
  import tomllib
87
102
  monkeypatch.setattr(hooks, "CODEX_STATUSLINE_HOOK_PATH",
88
103
  r"C:\Users\test\.config\token-tracker\codex-statusline.py")
104
+ monkeypatch.setattr(hooks, "_write_codex_statusline_script", lambda: None) # 别在 macOS 上真写 Windows 路径
89
105
  py = r"C:\Users\test\AppData\Local\Programs\Python\Python313\python.exe"
90
106
  content = hooks._install_codex_statusline("", py)
91
107
  parsed = tomllib.loads(content) # 旧 bug:basic string 下 \U 等触发 TOML 解析错误
File without changes
File without changes
File without changes