claude-token-saver 1.3.1__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 (138) hide show
  1. claude_token_saver-1.3.1/BENCHMARKING.md +245 -0
  2. claude_token_saver-1.3.1/CHANGELOG.md +1395 -0
  3. claude_token_saver-1.3.1/INTEGRATIONS.md +35 -0
  4. claude_token_saver-1.3.1/LICENSE +21 -0
  5. claude_token_saver-1.3.1/MANIFEST.in +3 -0
  6. claude_token_saver-1.3.1/PKG-INFO +660 -0
  7. claude_token_saver-1.3.1/README.md +632 -0
  8. claude_token_saver-1.3.1/VALIDATION.md +240 -0
  9. claude_token_saver-1.3.1/benchmarks/agent-runs.example.json +24 -0
  10. claude_token_saver-1.3.1/benchmarks/context-quality.json +27 -0
  11. claude_token_saver-1.3.1/benchmarks/holdout-external-10.json +910 -0
  12. claude_token_saver-1.3.1/benchmarks/holdout-external-10.result.json +665 -0
  13. claude_token_saver-1.3.1/benchmarks/holdout-external-11.json +1134 -0
  14. claude_token_saver-1.3.1/benchmarks/holdout-external-11.result.json +827 -0
  15. claude_token_saver-1.3.1/benchmarks/holdout-external-2.json +510 -0
  16. claude_token_saver-1.3.1/benchmarks/holdout-external-2.result.json +431 -0
  17. claude_token_saver-1.3.1/benchmarks/holdout-external-3.json +382 -0
  18. claude_token_saver-1.3.1/benchmarks/holdout-external-3.result.json +320 -0
  19. claude_token_saver-1.3.1/benchmarks/holdout-external-4.json +488 -0
  20. claude_token_saver-1.3.1/benchmarks/holdout-external-4.result.json +422 -0
  21. claude_token_saver-1.3.1/benchmarks/holdout-external-5.json +368 -0
  22. claude_token_saver-1.3.1/benchmarks/holdout-external-5.result.json +320 -0
  23. claude_token_saver-1.3.1/benchmarks/holdout-external-6.json +470 -0
  24. claude_token_saver-1.3.1/benchmarks/holdout-external-6.result.json +328 -0
  25. claude_token_saver-1.3.1/benchmarks/holdout-external-7.json +910 -0
  26. claude_token_saver-1.3.1/benchmarks/holdout-external-7.result.json +608 -0
  27. claude_token_saver-1.3.1/benchmarks/holdout-external-8.json +910 -0
  28. claude_token_saver-1.3.1/benchmarks/holdout-external-8.result.json +608 -0
  29. claude_token_saver-1.3.1/benchmarks/holdout-external-9.json +910 -0
  30. claude_token_saver-1.3.1/benchmarks/holdout-external-9.result.json +665 -0
  31. claude_token_saver-1.3.1/benchmarks/holdout-external.floor.json +45 -0
  32. claude_token_saver-1.3.1/benchmarks/holdout-external.json +63 -0
  33. claude_token_saver-1.3.1/benchmarks/holdout-external.result.json +80 -0
  34. claude_token_saver-1.3.1/benchmarks/holdout.example.json +44 -0
  35. claude_token_saver-1.3.1/integrations/claude-code.mcp.json +8 -0
  36. claude_token_saver-1.3.1/integrations/codex.config.toml +3 -0
  37. claude_token_saver-1.3.1/integrations/cursor.mcp.json +8 -0
  38. claude_token_saver-1.3.1/integrations/github-actions.yml +18 -0
  39. claude_token_saver-1.3.1/pyproject.toml +55 -0
  40. claude_token_saver-1.3.1/setup.cfg +4 -0
  41. claude_token_saver-1.3.1/src/claude_token_saver.egg-info/PKG-INFO +660 -0
  42. claude_token_saver-1.3.1/src/claude_token_saver.egg-info/SOURCES.txt +136 -0
  43. claude_token_saver-1.3.1/src/claude_token_saver.egg-info/dependency_links.txt +1 -0
  44. claude_token_saver-1.3.1/src/claude_token_saver.egg-info/entry_points.txt +3 -0
  45. claude_token_saver-1.3.1/src/claude_token_saver.egg-info/requires.txt +22 -0
  46. claude_token_saver-1.3.1/src/claude_token_saver.egg-info/top_level.txt +1 -0
  47. claude_token_saver-1.3.1/src/token_saver/__init__.py +3 -0
  48. claude_token_saver-1.3.1/src/token_saver/agent_eval.py +64 -0
  49. claude_token_saver-1.3.1/src/token_saver/audit.py +234 -0
  50. claude_token_saver-1.3.1/src/token_saver/benchmark.py +60 -0
  51. claude_token_saver-1.3.1/src/token_saver/budget.py +70 -0
  52. claude_token_saver-1.3.1/src/token_saver/cli.py +664 -0
  53. claude_token_saver-1.3.1/src/token_saver/closure.py +180 -0
  54. claude_token_saver-1.3.1/src/token_saver/commands.py +452 -0
  55. claude_token_saver-1.3.1/src/token_saver/config.py +23 -0
  56. claude_token_saver-1.3.1/src/token_saver/context_browser.py +93 -0
  57. claude_token_saver-1.3.1/src/token_saver/cost_report.py +434 -0
  58. claude_token_saver-1.3.1/src/token_saver/entry.py +54 -0
  59. claude_token_saver-1.3.1/src/token_saver/estimate.py +190 -0
  60. claude_token_saver-1.3.1/src/token_saver/evaluate.py +316 -0
  61. claude_token_saver-1.3.1/src/token_saver/feedback.py +44 -0
  62. claude_token_saver-1.3.1/src/token_saver/filter_output.py +231 -0
  63. claude_token_saver-1.3.1/src/token_saver/guard.py +175 -0
  64. claude_token_saver-1.3.1/src/token_saver/hook.py +197 -0
  65. claude_token_saver-1.3.1/src/token_saver/host_validate.py +173 -0
  66. claude_token_saver-1.3.1/src/token_saver/ignore.py +79 -0
  67. claude_token_saver-1.3.1/src/token_saver/images.py +129 -0
  68. claude_token_saver-1.3.1/src/token_saver/impact.py +109 -0
  69. claude_token_saver-1.3.1/src/token_saver/install.py +63 -0
  70. claude_token_saver-1.3.1/src/token_saver/lexical.py +199 -0
  71. claude_token_saver-1.3.1/src/token_saver/mapstat.py +33 -0
  72. claude_token_saver-1.3.1/src/token_saver/mcp.py +150 -0
  73. claude_token_saver-1.3.1/src/token_saver/output_benchmark.py +87 -0
  74. claude_token_saver-1.3.1/src/token_saver/output_saver.py +288 -0
  75. claude_token_saver-1.3.1/src/token_saver/output_store.py +34 -0
  76. claude_token_saver-1.3.1/src/token_saver/pack.py +1712 -0
  77. claude_token_saver-1.3.1/src/token_saver/pack_cli.py +129 -0
  78. claude_token_saver-1.3.1/src/token_saver/patch_context.py +322 -0
  79. claude_token_saver-1.3.1/src/token_saver/policy.py +211 -0
  80. claude_token_saver-1.3.1/src/token_saver/pricing.py +38 -0
  81. claude_token_saver-1.3.1/src/token_saver/prune.py +44 -0
  82. claude_token_saver-1.3.1/src/token_saver/repo_index.py +613 -0
  83. claude_token_saver-1.3.1/src/token_saver/security.py +73 -0
  84. claude_token_saver-1.3.1/src/token_saver/semantic_ts.py +380 -0
  85. claude_token_saver-1.3.1/src/token_saver/serve.py +249 -0
  86. claude_token_saver-1.3.1/src/token_saver/sessions.py +326 -0
  87. claude_token_saver-1.3.1/src/token_saver/skeleton.py +687 -0
  88. claude_token_saver-1.3.1/src/token_saver/snippet.py +92 -0
  89. claude_token_saver-1.3.1/src/token_saver/state.py +101 -0
  90. claude_token_saver-1.3.1/src/token_saver/syntax.py +896 -0
  91. claude_token_saver-1.3.1/src/token_saver/working_set.py +42 -0
  92. claude_token_saver-1.3.1/tests/test_adaptive_budget.py +93 -0
  93. claude_token_saver-1.3.1/tests/test_audit.py +171 -0
  94. claude_token_saver-1.3.1/tests/test_budget_map.py +106 -0
  95. claude_token_saver-1.3.1/tests/test_callable_identity_v5.py +264 -0
  96. claude_token_saver-1.3.1/tests/test_callable_symbol_ranking_v3.py +166 -0
  97. claude_token_saver-1.3.1/tests/test_check_holdout.py +67 -0
  98. claude_token_saver-1.3.1/tests/test_cli.py +231 -0
  99. claude_token_saver-1.3.1/tests/test_context_browser_mcp.py +26 -0
  100. claude_token_saver-1.3.1/tests/test_cost_report.py +298 -0
  101. claude_token_saver-1.3.1/tests/test_csharp14_extension_blocks.py +154 -0
  102. claude_token_saver-1.3.1/tests/test_entry.py +118 -0
  103. claude_token_saver-1.3.1/tests/test_estimate.py +122 -0
  104. claude_token_saver-1.3.1/tests/test_evaluate_holdout.py +135 -0
  105. claude_token_saver-1.3.1/tests/test_evaluate_scoped_recall.py +66 -0
  106. claude_token_saver-1.3.1/tests/test_evidence.py +210 -0
  107. claude_token_saver-1.3.1/tests/test_filter.py +110 -0
  108. claude_token_saver-1.3.1/tests/test_filter_dedupe.py +20 -0
  109. claude_token_saver-1.3.1/tests/test_fuzzy_symbol.py +71 -0
  110. claude_token_saver-1.3.1/tests/test_guard.py +124 -0
  111. claude_token_saver-1.3.1/tests/test_holdout11_failure_classes.py +250 -0
  112. claude_token_saver-1.3.1/tests/test_hook.py +165 -0
  113. claude_token_saver-1.3.1/tests/test_images.py +90 -0
  114. claude_token_saver-1.3.1/tests/test_index_robustness.py +83 -0
  115. claude_token_saver-1.3.1/tests/test_lexical.py +69 -0
  116. claude_token_saver-1.3.1/tests/test_mapstat.py +21 -0
  117. claude_token_saver-1.3.1/tests/test_mcp.py +91 -0
  118. claude_token_saver-1.3.1/tests/test_multilang_syntax.py +246 -0
  119. claude_token_saver-1.3.1/tests/test_output_benchmark.py +67 -0
  120. claude_token_saver-1.3.1/tests/test_output_saver.py +97 -0
  121. claude_token_saver-1.3.1/tests/test_output_saver_mcp.py +32 -0
  122. claude_token_saver-1.3.1/tests/test_overload_resolution_v4.py +203 -0
  123. claude_token_saver-1.3.1/tests/test_pack.py +700 -0
  124. claude_token_saver-1.3.1/tests/test_policy.py +61 -0
  125. claude_token_saver-1.3.1/tests/test_prune.py +13 -0
  126. claude_token_saver-1.3.1/tests/test_ranking_stages.py +203 -0
  127. claude_token_saver-1.3.1/tests/test_release_regressions.py +251 -0
  128. claude_token_saver-1.3.1/tests/test_repo_index.py +174 -0
  129. claude_token_saver-1.3.1/tests/test_semantic_ref_closure.py +167 -0
  130. claude_token_saver-1.3.1/tests/test_semantic_ts.py +140 -0
  131. claude_token_saver-1.3.1/tests/test_sessions.py +257 -0
  132. claude_token_saver-1.3.1/tests/test_skeleton.py +305 -0
  133. claude_token_saver-1.3.1/tests/test_snippet.py +36 -0
  134. claude_token_saver-1.3.1/tests/test_structural_authority.py +100 -0
  135. claude_token_saver-1.3.1/tests/test_structural_symbol_identity.py +128 -0
  136. claude_token_saver-1.3.1/tests/test_v09.py +225 -0
  137. claude_token_saver-1.3.1/tests/test_v1.py +274 -0
  138. claude_token_saver-1.3.1/tests/test_v12_ports.py +93 -0
@@ -0,0 +1,245 @@
1
+ # Verify integration, then benchmark successful work
2
+
3
+ ## Deterministic context-quality benchmark
4
+
5
+ Before paid paired-agent trials, run the included 25-task ground-truth selector
6
+ benchmark. It measures relevant-file recall, relevant-symbol recall, and context
7
+ reduction; selection metrics alone do not prove agent success.
8
+
9
+ ```bash
10
+ token-saver evaluate benchmarks/context-quality.json --path . --max-tokens 6000
11
+ ```
12
+
13
+ Each item also reports `symbol_recall_in_expected_files`, which counts a
14
+ symbol only when it was selected from one of the task's expected files. Bare
15
+ `symbol_recall` can be satisfied by a same-named symbol in an unrelated file;
16
+ prefer the scoped figure (or `qualified_symbols` / `symbol_identities`) when
17
+ names are common.
18
+
19
+ Add project-specific tasks using `query`, `files`, and `symbols`. Keep the
20
+ manifest under version control so ranking changes can be compared reproducibly.
21
+
22
+ ## Multi-repository holdout benchmark
23
+
24
+ The repository-local selector benchmark is useful for regressions, but because
25
+ Token Saver is developed against this codebase it is not independent evidence of
26
+ generalization. For unseen evaluation, define ground truth before running the
27
+ tool and point one manifest at repositories that were excluded from ranking
28
+ work/tuning. `benchmarks/holdout.example.json` contains the full schema.
29
+
30
+ Repository paths are resolved relative to the manifest. Pin exact Git commits so
31
+ the corpus cannot move between runs. A publishable holdout also records a freeze
32
+ timestamp and a SHA-256 of the task/repository ground-truth definition:
33
+
34
+ ```json
35
+ {
36
+ "suite_version": 1,
37
+ "protocol": {
38
+ "ground_truth_frozen": true,
39
+ "development_excluded": true,
40
+ "frozen_at": "2026-09-17T12:00:00Z",
41
+ "ground_truth_sha256": "HASH_FROM_COMMAND_BELOW"
42
+ },
43
+ "repositories": {
44
+ "app-a": {"path": "../app-a", "revision": "ACTUAL_COMMIT_SHA"},
45
+ "app-b": {"path": "../app-b", "revision": "ACTUAL_COMMIT_SHA"}
46
+ },
47
+ "tasks": [
48
+ {
49
+ "id": "auth-refresh",
50
+ "repository": "app-a",
51
+ "query": "session refresh after logout",
52
+ "files": ["src/auth/session.ts"],
53
+ "symbols": ["refreshSession"]
54
+ }
55
+ ]
56
+ }
57
+ ```
58
+
59
+ After the tasks, expected evidence, and revision pins are final, calculate the
60
+ freeze hash without running retrieval:
61
+
62
+ ```bash
63
+ token-saver evaluate benchmarks/holdout.json --print-ground-truth-hash
64
+ ```
65
+
66
+ Put that value in `protocol.ground_truth_sha256`, commit the manifest, then run:
67
+
68
+ ```bash
69
+ token-saver evaluate benchmarks/holdout.json --require-holdout --max-tokens 6000
70
+ ```
71
+
72
+ `--require-holdout` rejects a manifest unless both protocol flags are true,
73
+ `frozen_at` is present, the SHA-256 still matches the frozen task definition,
74
+ and every pinned repository `HEAD` matches its declared revision. Filesystem
75
+ paths are excluded from the freeze hash so the same manifest can be replicated
76
+ on another machine without changing the benchmark identity. The output includes
77
+ aggregate metrics, per-repository summaries, and the verified hash.
78
+
79
+ A valid hash proves the evaluated definition did not change after it was frozen;
80
+ it does not by itself prove the labels were independently authored before tuning.
81
+ Preserve manifest history and the task-definition process as audit evidence.
82
+
83
+ ## Paired agent outcomes
84
+
85
+ Record independently validated baseline and Token Saver runs using the schema in
86
+ `benchmarks/agent-runs.example.json`, then run:
87
+
88
+ ```bash
89
+ token-saver agent-evaluate benchmarks/agent-runs.json
90
+ ```
91
+
92
+ The evaluator requires exactly one run per condition and task. It reports input
93
+ and output tokens, retries, elapsed time, context failures, success rate, and
94
+ tokens per success. It suppresses the reduction headline whenever Token Saver's
95
+ success rate is below baseline.
96
+
97
+ ## Live host validation (not yet executed for this release)
98
+
99
+ Token Saver can verify installation and its local hook/recovery transport before
100
+ a live host trial:
101
+
102
+ ```bash
103
+ token-saver host-check . --require-ready
104
+ ```
105
+
106
+ This checks project/user hook configuration, probes the host executable version,
107
+ runs a synthetic 500-line Bash response through the real PostToolUse hook, and
108
+ retrieves an omitted middle line from Token Saver's saved original output. That
109
+ is a local transport test; it does **not** prove the host actually feeds
110
+ `hookSpecificOutput.updatedToolOutput` back to the model.
111
+
112
+ For that final gate, capture a real host debug transcript and supply it explicitly:
113
+
114
+ ```bash
115
+ token-saver host-check . \
116
+ --live-evidence /path/to/claude-debug.log \
117
+ --require-live
118
+ ```
119
+
120
+ `live_verified=true` is reported only when the supplied evidence contains both
121
+ the host replacement field and Token Saver's filtered-output recovery marker.
122
+ The manual validation protocol remains:
123
+
124
+ 1. Record `claude --version`, model ID, configuration, and Token Saver version.
125
+ 2. Use a disposable project. Install the package and its project hooks. Check
126
+ that inherited user hooks do not run Token Saver a second time.
127
+ 3. Start Claude Code with debugging enabled. Ask it to run a harmless command
128
+ that prints 500 distinct progress lines. Do not use a command with side effects.
129
+ 4. Verify the host accepts `hookSpecificOutput.updatedToolOutput` without a
130
+ validation error. The model-visible result should include the recovery note,
131
+ show the shortened head/tail, and preserve the structured Bash fields.
132
+ Hook stdout alone is not sufficient evidence of host acceptance.
133
+ 5. Ask it to retrieve a known omitted middle line using the supplied
134
+ `token-saver output` command. Verify the exact line without rerunning the
135
+ original command. Test stderr independently and test a failing Jest-style
136
+ output containing a test name, stack location and multiline assertion diff.
137
+ 6. Test a >220-line source read. A bounded Read must return actual bytes, and a
138
+ subsequent Edit must succeed. Repeat after `/compact`; prior full-read state
139
+ must not block access to needed source. Test two independent sessions.
140
+ 7. Save the version, debug evidence and outcomes. If the installed host does not
141
+ support structured replacement, use manual `filter` until upgraded. Do not
142
+ claim automatic savings based on an ignored hook field.
143
+
144
+ No paid model call or live Claude Code session was executed in the repair
145
+ workspace. Automated tests cover the documented contract, subprocess transport,
146
+ state isolation, retrieval, and accounting. Live behavior remains a separate gate.
147
+
148
+ ## Paired task protocol
149
+
150
+ - Choose representative tasks before measuring: bug fixes, refactors, unfamiliar
151
+ repo navigation, noisy passing tests, and failures requiring deep diagnostics.
152
+ - Use independent fresh worktrees at the same commit and the same exact prompt,
153
+ model, effort, tools, system instructions, and approval configuration.
154
+ - In baseline, disable all Token Saver hooks (including user-scope hooks). In
155
+ enabled runs, use the release's hooks. Do not add orientation maps to only one
156
+ arm unless that is the specific intervention being tested.
157
+ - Randomize condition order and run multiple trials per task. Record cache
158
+ policy and cold/warm conditions rather than assuming a five-minute TTL.
159
+ - Keep tests/evaluation independent of the agent. Record success, regression
160
+ checks, elapsed time, retries and any manual intervention. A smaller context
161
+ that fails the task is not a win.
162
+ - Preserve each run's complete transcripts, including nested subagent
163
+ transcripts where applicable. Do not reuse a transcript across runs.
164
+ - Keep raw transcripts local; they may contain code or secrets.
165
+
166
+ `token-saver benchmark` analyzes recorded runs; it does not execute coding agents
167
+ or certify evaluator outcomes. It verifies paired task/trial identity, revision,
168
+ model and prompt metadata, requires measured usage and explicit prices, and
169
+ rejects incomplete or duplicate runs. Metadata must be recorded honestly by the
170
+ runner; the evaluator does not independently attest your checkout or prompt.
171
+
172
+ ## Run manifest
173
+
174
+ Paths are relative to the manifest file. `success` is determined by independent
175
+ validation, not by the agent's own assertion. Use the actual SHA-256 of the prompt.
176
+
177
+ ```json
178
+ {
179
+ "runs": [
180
+ {
181
+ "task": "fix-user-lookup",
182
+ "trial": 1,
183
+ "condition": "baseline",
184
+ "revision": "ACTUAL_COMMIT",
185
+ "model": "EXACT_MODEL_ID",
186
+ "prompt_sha256": "ACTUAL_PROMPT_SHA256",
187
+ "success": true,
188
+ "validation": "Independent tests passed; no regressions in required suite",
189
+ "seconds": 120.5,
190
+ "transcripts": ["runs/baseline.jsonl"]
191
+ },
192
+ {
193
+ "task": "fix-user-lookup",
194
+ "trial": 1,
195
+ "condition": "enabled",
196
+ "revision": "ACTUAL_COMMIT",
197
+ "model": "EXACT_MODEL_ID",
198
+ "prompt_sha256": "ACTUAL_PROMPT_SHA256",
199
+ "success": true,
200
+ "validation": "Same independent checks passed",
201
+ "seconds": 118.2,
202
+ "transcripts": ["runs/enabled.jsonl"]
203
+ }
204
+ ]
205
+ }
206
+ ```
207
+
208
+ The times above demonstrate the schema; they are not measured results.
209
+
210
+ ## Rate file
211
+
212
+ Create a JSON object mapping each exact model ID to numeric USD-per-million
213
+ rates: `input`, `cache_write_5m`, `cache_write_1h`, `cache_read`, `output`.
214
+ For example, this object is syntactically valid but deliberately uses a fictitious
215
+ model and synthetic prices. **It must not be used to price actual models.**
216
+
217
+ ```json
218
+ {
219
+ "synthetic-test-model": {
220
+ "input": 1,
221
+ "cache_write_5m": 1.25,
222
+ "cache_write_1h": 2,
223
+ "cache_read": 0.1,
224
+ "output": 5
225
+ }
226
+ }
227
+ ```
228
+
229
+ Only add `cache_write_unknown` when the run's actual cache configuration permits
230
+ an explicit rate for missing TTL details. Missing prices or unexplained cache
231
+ creation prevent a complete cost result.
232
+
233
+ ```bash
234
+ token-saver benchmark runs.json --rates rates.json
235
+ ```
236
+
237
+ The output includes per-condition success rates, total tokens by usage type,
238
+ tool-result counts, repeated reads, elapsed time, total cost, and cost per success.
239
+ Costs from failed attempts are included. A reduced success rate suppresses the
240
+ headline cost-per-success reduction. Inspect per-task outcomes too: aggregate
241
+ success parity does not prove each task retained the same quality.
242
+
243
+ No confidence interval or statistical significance is claimed. Before publishing
244
+ savings, retain task definitions, repeated trials, model versions, host versions,
245
+ prices, independent checks, and raw results needed to reproduce the claim.