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.
- {token_tracker-0.4.4/src/token_tracker.egg-info → token_tracker-0.4.5}/PKG-INFO +1 -1
- {token_tracker-0.4.4 → token_tracker-0.4.5}/pyproject.toml +1 -1
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/hooks.py +13 -5
- {token_tracker-0.4.4 → token_tracker-0.4.5/src/token_tracker.egg-info}/PKG-INFO +1 -1
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_hooks.py +16 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/LICENSE +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/README.md +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/setup.cfg +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/__init__.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/__init__.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/claude.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/codex.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/rate_limits.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/registry.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/types.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/adapters/util.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/analyzer/__init__.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/analyzer/aggregator.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/analyzer/blocks.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/analyzer/cost.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/cli.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/config.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/i18n.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/__init__.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/console.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/format.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/heatmap.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/panels.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/status.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/tables.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/theme.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/ui/themes.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker/wizard.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/SOURCES.txt +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/dependency_links.txt +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/entry_points.txt +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/requires.txt +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/src/token_tracker.egg-info/top_level.txt +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_aggregator.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_blocks.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_cli.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_codex.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_cost.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_heatmap.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_status.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_tables.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_theme.py +0 -0
- {token_tracker-0.4.4 → token_tracker-0.4.5}/tests/test_util.py +0 -0
|
@@ -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
|
-
|
|
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"
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|