tokencast 0.1.0__py3-none-any.whl
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.
tokencast/__init__.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tokencast
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Pre-execution cost estimation for LLM agent workflows with calibration learning
|
|
5
|
+
Project-URL: Homepage, https://github.com/krulewis/tokencast
|
|
6
|
+
Project-URL: Documentation, https://github.com/krulewis/tokencast/wiki
|
|
7
|
+
Project-URL: Repository, https://github.com/krulewis/tokencast
|
|
8
|
+
Project-URL: Issues, https://github.com/krulewis/tokencast/issues
|
|
9
|
+
Author-email: Kelly Lewis <krulewis@users.noreply.github.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agent,calibration,cost-estimation,llm,mcp,token-cost
|
|
13
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
22
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
<p align="center">
|
|
27
|
+
<img src="assets/tokencast-logo.svg" alt="tokencast logo" width="150">
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
# tokencast
|
|
31
|
+
|
|
32
|
+
A Claude Code skill that estimates Anthropic API cost for planned agent tasks, then **learns from actual usage** to improve estimates over time.
|
|
33
|
+
|
|
34
|
+
Install once per project. It auto-estimates after plans are created and auto-learns at session end. Zero ongoing friction.
|
|
35
|
+
|
|
36
|
+
## Setup (one time per project)
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Clone the repo (anywhere — it doesn't need to live inside your project)
|
|
40
|
+
git clone https://github.com/krulewis/tokencast.git
|
|
41
|
+
|
|
42
|
+
# Install into your project (quote paths with spaces)
|
|
43
|
+
bash tokencast/scripts/install-hooks.sh "/path/to/your-project"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> **Paths with spaces:** Always wrap the project path in quotes. Without them the install script will fail on paths like `/Volumes/Macintosh HD2/...`.
|
|
47
|
+
|
|
48
|
+
This does three things:
|
|
49
|
+
1. Symlinks the skill into `<project>/.claude/skills/tokencast/`
|
|
50
|
+
2. Adds a `Stop` hook for auto-learning at session end
|
|
51
|
+
3. Adds a `PostToolUse` hook to nudge estimation after planning agents
|
|
52
|
+
|
|
53
|
+
Every Claude Code session in that project now has tokencast active.
|
|
54
|
+
|
|
55
|
+
## What Happens Automatically
|
|
56
|
+
|
|
57
|
+
### After a plan is created
|
|
58
|
+
tokencast detects the plan in conversation context, infers size, files, complexity, project type, and language, then outputs a cost table:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
## tokencast estimate
|
|
62
|
+
|
|
63
|
+
Change: size=M, files=5, complexity=medium
|
|
64
|
+
Calibration: 1.12x from 8 prior runs
|
|
65
|
+
|
|
66
|
+
| Step | Model | Optimistic | Expected | Pessimistic |
|
|
67
|
+
|-----------------------|--------|------------|----------|-------------|
|
|
68
|
+
| Research Agent | Sonnet | $0.60 | $1.17 | $4.47 |
|
|
69
|
+
| Architect Agent | Opus | $0.67 | $1.18 | $3.97 |
|
|
70
|
+
| ... | ... | ... | ... | ... |
|
|
71
|
+
| TOTAL | | $3.37 | $6.26 | $22.64 |
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### At session end
|
|
75
|
+
The learning hook silently:
|
|
76
|
+
1. Reads the session's JSONL log
|
|
77
|
+
2. Computes actual token cost (including cache write tokens)
|
|
78
|
+
3. Compares to the estimate
|
|
79
|
+
4. Updates calibration factors
|
|
80
|
+
|
|
81
|
+
### Next session
|
|
82
|
+
Future estimates use learned correction factors. More sessions = better accuracy.
|
|
83
|
+
|
|
84
|
+
## Manual Invocation
|
|
85
|
+
|
|
86
|
+
You can also invoke explicitly with overrides:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
/tokencast size=L files=12 complexity=high
|
|
90
|
+
/tokencast steps=implement,test,qa
|
|
91
|
+
/tokencast review_cycles=3
|
|
92
|
+
/tokencast review_cycles=0
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Use `review_cycles=N` to set the number of expected PR review cycles. Use `review_cycles=0` to suppress the PR Review Loop row.
|
|
96
|
+
|
|
97
|
+
## How It Works
|
|
98
|
+
|
|
99
|
+
1. Infers size, file count, complexity from the plan in conversation
|
|
100
|
+
2. Reads reference files for pricing and token heuristics
|
|
101
|
+
3. Loads learned calibration factors (if any exist)
|
|
102
|
+
4. Computes per-step token estimates using activity decomposition
|
|
103
|
+
5. Applies complexity multiplier, context accumulation `(K+1)/2`, and cache rates
|
|
104
|
+
6. Splits into Optimistic / Expected / Pessimistic bands
|
|
105
|
+
7. If PR Review Loop is in scope, computes loop cost using geometric decay across N review cycles (Optimistic=1, Expected=N, Pessimistic=N×2)
|
|
106
|
+
8. Applies calibration correction to Expected band (individual steps re-anchor; PR Review Loop scales each band independently)
|
|
107
|
+
9. Records the estimate for later comparison with actuals
|
|
108
|
+
|
|
109
|
+
## Overrides
|
|
110
|
+
|
|
111
|
+
| Override | Effect |
|
|
112
|
+
|----------|--------|
|
|
113
|
+
| `size=M` | Set size class explicitly |
|
|
114
|
+
| `files=5` | Set file count explicitly |
|
|
115
|
+
| `complexity=high` | Set complexity explicitly |
|
|
116
|
+
| `steps=implement,test,qa` | Estimate only those pipeline steps |
|
|
117
|
+
| `project_type=migration` | Set project type explicitly |
|
|
118
|
+
| `language=go` | Set primary language explicitly |
|
|
119
|
+
| `review_cycles=3` | Set PR review cycle count (0 = disable) |
|
|
120
|
+
|
|
121
|
+
## Confidence Bands
|
|
122
|
+
|
|
123
|
+
| Band | Cache Hit | Multiplier | Meaning |
|
|
124
|
+
|-------------|-----------|------------|----------------------------------------|
|
|
125
|
+
| Optimistic | 60% | 0.6x | Best case — focused agent work |
|
|
126
|
+
| Expected | 50% | 1.0x | Typical run |
|
|
127
|
+
| Pessimistic | 30% | 3.0x | With rework loops, debugging, retries |
|
|
128
|
+
|
|
129
|
+
## Calibration
|
|
130
|
+
|
|
131
|
+
Calibration is fully automatic:
|
|
132
|
+
- **0-2 sessions:** No correction applied. "Collecting data" status.
|
|
133
|
+
- **3-10 sessions:** Global correction factor via trimmed mean of actual/expected ratios (trim_fraction=0.1).
|
|
134
|
+
- **10+ sessions:** EWMA with recency weighting. Per-size-class factors activate when a class has 3+ samples.
|
|
135
|
+
- **Outlier filtering:** Sessions with actual/expected ratio >3.0x or <0.2x are excluded from calibration and logged for inspection.
|
|
136
|
+
|
|
137
|
+
Calibration data lives in `calibration/` (gitignored, local to each user).
|
|
138
|
+
|
|
139
|
+
## Disabling
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
bash /path/to/tokencast/scripts/disable.sh /path/to/your-project
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Removes the skill and hooks. Preserves calibration data for reuse.
|
|
146
|
+
|
|
147
|
+
## Files
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
SKILL.md — Skill definition (auto-trigger, algorithm)
|
|
151
|
+
references/pricing.md — Model prices, cache rates, step→model map
|
|
152
|
+
references/heuristics.md — Token budgets, pipeline decompositions, multipliers
|
|
153
|
+
references/examples.md — Worked examples with arithmetic
|
|
154
|
+
references/calibration-algorithm.md — Detailed calibration algorithm reference
|
|
155
|
+
commands/
|
|
156
|
+
tokencast-version.md — /tokencast-version slash command
|
|
157
|
+
scripts/
|
|
158
|
+
install-hooks.sh — One-time project setup
|
|
159
|
+
disable.sh — Remove from project
|
|
160
|
+
tokencast-learn.sh — Stop hook: auto-captures actuals
|
|
161
|
+
tokencast-track.sh — PostToolUse hook: nudges estimation after plans
|
|
162
|
+
sum-session-tokens.py — Parses session JSONL for actual costs
|
|
163
|
+
update-factors.py — Computes calibration factors from history
|
|
164
|
+
calibration/ — Per-user local data (gitignored)
|
|
165
|
+
history.jsonl — Estimate vs actual records
|
|
166
|
+
factors.json — Learned correction factors
|
|
167
|
+
active-estimate.json — Transient marker for current estimate
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## v1.1 Changes
|
|
171
|
+
|
|
172
|
+
- **Trimmed mean** replaces median for faster convergence with small samples
|
|
173
|
+
- **Outlier flagging** — extreme ratios (>3.0x or <0.2x) excluded from calibration, logged for inspection
|
|
174
|
+
- **Richer data** — project type, language, pipeline signature, and step count captured per session
|
|
175
|
+
- **Baseline subtraction** — tokens spent before the estimate are excluded from actuals
|
|
176
|
+
- **Security hardening** — path injection fixes, consolidated parsing, safe handling of paths with spaces
|
|
177
|
+
- **Version markers** — `version: 1.1.0` in SKILL.md, `--version` flag on learn script
|
|
178
|
+
|
|
179
|
+
## v1.2 Changes
|
|
180
|
+
|
|
181
|
+
- **PR Review Loop modeling** — geometric-decay cost model for review-fix-re-review cycles
|
|
182
|
+
- **New override** — `review_cycles=N` to set expected cycle count (0 = disable)
|
|
183
|
+
- **Per-band calibration** — PR Review Loop applies calibration independently per band (not re-anchored)
|
|
184
|
+
- **New schema fields** — `review_cycles_estimated` and `review_cycles_actual` in active-estimate.json
|
|
185
|
+
|
|
186
|
+
## Limitations
|
|
187
|
+
|
|
188
|
+
- Pipeline step names reflect a default workflow — map your own steps to the closest defaults. Formulas are pipeline-agnostic (see `references/heuristics.md`)
|
|
189
|
+
- Heuristics assume typical 150-300 line source files
|
|
190
|
+
- Does not model parallel agent execution
|
|
191
|
+
- Calibration requires 3+ completed sessions before corrections activate
|
|
192
|
+
- Pricing data embedded; check `last_updated` in references/pricing.md
|
|
193
|
+
- Multi-session tasks only capture the session containing the estimate
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
tokencast/__init__.py,sha256=0jzkVDSSFzmt5udYTWuCZLQeZXOQsQcw1yt0_uD9_SU,98
|
|
2
|
+
tokencast-0.1.0.dist-info/METADATA,sha256=ZCa8CMyYuzQYbdFe5IsaPcFyKkk7optq-Ssn8lb7-3Y,8637
|
|
3
|
+
tokencast-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
+
tokencast-0.1.0.dist-info/licenses/LICENSE,sha256=BRpVorPXnNn_0agY7SJJNESzSLfUm3Ul7d0KKMc6sic,1068
|
|
5
|
+
tokencast-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kelly Lewis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|