tokentrace 0.8.4 → 0.10.0

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 (64) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/CONTRIBUTING.md +18 -0
  3. package/README.md +77 -0
  4. package/TOKENTRACE_AGENT.md +83 -0
  5. package/app/api/agent/route.ts +7 -0
  6. package/app/api/capabilities/route.ts +7 -0
  7. package/app/api/roadmap/route.ts +13 -0
  8. package/app/api/saved-views/[id]/route.ts +16 -0
  9. package/app/api/saved-views/route.ts +35 -0
  10. package/app/guide/page.tsx +596 -0
  11. package/app/page.tsx +173 -23
  12. package/app/sessions/[id]/page.tsx +202 -0
  13. package/app/sessions/page.tsx +13 -0
  14. package/bin/tokentrace.js +44 -0
  15. package/components/charts/trend-chart.tsx +116 -19
  16. package/components/charts/trend-section.tsx +77 -0
  17. package/components/period-filter.tsx +5 -4
  18. package/components/session-explorer.tsx +139 -7
  19. package/components/sidebar.tsx +2 -0
  20. package/dist/runtime/agent.mjs +390 -0
  21. package/dist/runtime/db-migrate.mjs +23 -0
  22. package/dist/runtime/db-seed.mjs +23 -0
  23. package/dist/runtime/digest.mjs +164 -21
  24. package/dist/runtime/doctor.mjs +79 -8
  25. package/dist/runtime/evidence.mjs +23 -0
  26. package/dist/runtime/insights.mjs +79 -8
  27. package/dist/runtime/pricing-refresh.mjs +24 -1
  28. package/dist/runtime/repair.mjs +23 -0
  29. package/dist/runtime/report.mjs +3115 -0
  30. package/dist/runtime/reset.mjs +23 -0
  31. package/dist/runtime/review.mjs +2794 -0
  32. package/dist/runtime/roadmap.mjs +196 -0
  33. package/dist/runtime/scan.mjs +24 -1
  34. package/dist/runtime/status.mjs +50 -19
  35. package/docs/agent-discovery.schema.json +222 -0
  36. package/docs/assets/claude-statusline.svg +2 -2
  37. package/llms.txt +42 -0
  38. package/package.json +6 -1
  39. package/scripts/agent.ts +50 -0
  40. package/scripts/build-cli-runtime.mjs +4 -0
  41. package/scripts/digest.ts +15 -8
  42. package/scripts/package-inspect.mjs +33 -1
  43. package/scripts/report.ts +102 -0
  44. package/scripts/review.ts +46 -0
  45. package/scripts/roadmap.ts +49 -0
  46. package/scripts/smoke-cli.mjs +24 -0
  47. package/scripts/smoke-packed-install.mjs +74 -2
  48. package/src/db/migrate-core.ts +9 -0
  49. package/src/db/schema.ts +19 -0
  50. package/src/lib/accounting-invariants.ts +171 -0
  51. package/src/lib/agent-discovery-api.ts +11 -0
  52. package/src/lib/agent-discovery.ts +417 -0
  53. package/src/lib/analytics.ts +70 -6
  54. package/src/lib/claude-statusline.ts +26 -18
  55. package/src/lib/daily-digest.ts +4 -0
  56. package/src/lib/date-range.ts +5 -4
  57. package/src/lib/first-run-status.ts +71 -5
  58. package/src/lib/markdown-report.ts +71 -0
  59. package/src/lib/post-session-review.ts +146 -0
  60. package/src/lib/report-cli.ts +100 -0
  61. package/src/lib/roadmap-status.ts +185 -0
  62. package/src/lib/saved-views.ts +218 -0
  63. package/src/lib/session-timeline.ts +322 -0
  64. package/src/lib/since-filter.ts +60 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,52 @@
2
2
 
3
3
  All notable changes to TokenTrace are documented here.
4
4
 
5
+ ## Unreleased
6
+
7
+ ## [0.10.0] - 2026-05-18
8
+
9
+ ### Added
10
+
11
+ - In-app Guide page covering first scan setup, Claude Code status-line installation, status-line label meanings, page workflows, privacy, and troubleshooting.
12
+ - `tokentrace agent --json` and `tokentrace capabilities --json` for a read-only machine-readable discovery manifest that coding agents can use before scanning or opening the dashboard.
13
+ - Local dashboard discovery endpoints at `/api/agent` and `/api/capabilities` returning the same manifest.
14
+ - `tokentrace roadmap --json` and `/api/roadmap` for machine-readable 0.10.0 implementation status, evidence paths, verification gates, and release status.
15
+ - Package-level agent discovery references: `TOKENTRACE_AGENT.md`, `llms.txt`, and `docs/agent-discovery.schema.json`.
16
+ - Repo-level agent instructions for Codex and Claude Code requiring Superpowers, ProjScan, changelog discipline, and explicit maintainer approval before releases.
17
+ - 0.10.0 Guided Operator roadmap for in-app guidance, status-line clarity, trend continuity, release-safe agent workflow, and verification gates.
18
+ - First-run guided setup in Overview and Guide so new users can move from scan roots to first useful evidence without a separate tutorial mode.
19
+ - Guide release-readiness and empty-state sections covering roadmap gates, release status, no data, missing logs, unknown pricing, parser warnings, and sandbox smoke skips.
20
+
21
+ ### Changed
22
+
23
+ - Guide now shows live local setup status for latest scan, imported records, unknown costs, and priced model coverage.
24
+ - Agent discovery follow-up commands are now structured as command arrays instead of shell strings.
25
+ - Claude Code status-line output now leads with live context and cost, then labels transcript totals as processed and cache usage to avoid confusing cumulative processed tokens with current context size.
26
+ - Package inspection and packed-install smoke now enforce the agent discovery docs, schema, executable CLI bin, and 0.10.0 release-status contract.
27
+ - Overview metric cards now show inline trust annotations explaining processed, non-cache, cached, cost, and session counts near the numbers.
28
+ - Overview Period defaults to All time again, while token and cost trend charts share one control bar that defaults chart history to the latest 60 days with 30-day, 90-day, and All options.
29
+ - Usage Pulse now suppresses extreme percentage labels when the previous comparison baseline is too small to be useful.
30
+
31
+ ### Fixed
32
+
33
+ - Token and cost trend charts now include explicit zero-value calendar days between imported usage days instead of visually skipping idle periods.
34
+
35
+ ## [0.9.0] - 2026-05-13
36
+
37
+ ### Added
38
+
39
+ - Session Timeline pages for inspecting one imported CLI session as ordered interactions, model changes, token spikes, cache activity, tool calls, parser confidence, and unknown-cost events without exposing raw message bodies.
40
+ - Saved Local Views on Sessions, with built-in local filters for unknown cost, high-cost sessions, Claude/Codex this month, estimated tokens, guardrail review, and parser review, plus user-created SQLite-backed views.
41
+ - `tokentrace digest --since <last-scan|yesterday|YYYY-MM-DD>` for scoped local usage digests.
42
+ - `tokentrace report --markdown` and `tokentrace review --json` for deterministic local summaries covering digest data, post-session movement, accounting state, parser warnings, and expensive sessions.
43
+ - Overview Post-Session Review panel showing latest scan movement, unknown costs, parser follow-up, guardrail state, and expensive sessions.
44
+ - Accounting invariant checks that verify processed tokens balance against fresh input, output, reasoning, and cache buckets.
45
+
46
+ ### Changed
47
+
48
+ - Claude status line output now includes context-window usage when Claude provides it and distinguishes priced sessions from pricing-repair states.
49
+ - Overview Data Readiness now includes token-bucket balance and keeps readiness tiles readable at normal desktop widths.
50
+
5
51
  ## [0.8.4] - 2026-05-13
6
52
 
7
53
  ### Changed
package/CONTRIBUTING.md CHANGED
@@ -22,12 +22,30 @@ npm run dev
22
22
 
23
23
  Open `http://localhost:3000`.
24
24
 
25
+ ## Agentic Coding Workflow
26
+
27
+ TokenTrace coding work uses the Superpowers methodology from
28
+ <https://github.com/obra/superpowers>: clarify intent, plan, use TDD for
29
+ behavior changes, review, and verify before completion claims.
30
+
31
+ ProjScan is a required code-intelligence and quality tool. Use the npm package
32
+ from <https://www.npmjs.com/package/projscan> through the local script:
33
+
34
+ ```bash
35
+ npm run projscan:doctor
36
+ ```
37
+
38
+ Run ProjScan after substantial changes and before release readiness claims. It
39
+ does not replace tests, typecheck, lint, build, package inspection, or smoke
40
+ checks.
41
+
25
42
  Useful checks:
26
43
 
27
44
  ```bash
28
45
  npm run verify
29
46
  npm run build
30
47
  npm run scan
48
+ npm run projscan:doctor
31
49
  ```
32
50
 
33
51
  ## Parser Contributions
package/README.md CHANGED
@@ -34,6 +34,11 @@ tokentrace # Start local dashboard
34
34
  tokentrace serve # Start local dashboard
35
35
  tokentrace serve --port 3210 --no-open
36
36
  # Start on a fixed port without opening a browser
37
+ tokentrace agent --json # Print machine-readable agent discovery manifest
38
+ tokentrace capabilities --json
39
+ # Alias for agent discovery manifest
40
+ tokentrace roadmap --json
41
+ # Print 0.10.0 release implementation status
37
42
  tokentrace scan # Scan local AI CLI usage logs
38
43
  tokentrace doctor --json
39
44
  # Inspect scan health and repair recommendations
@@ -43,6 +48,12 @@ tokentrace repair --json
43
48
  # Print unknown-cost repair groups as JSON
44
49
  tokentrace digest --json
45
50
  # Print current-month local usage digest
51
+ tokentrace digest --since yesterday
52
+ # Print a scoped local usage digest
53
+ tokentrace report --markdown
54
+ # Print a deterministic Markdown report
55
+ tokentrace review --json
56
+ # Print post-session scan and review movement
46
57
  tokentrace insights --json
47
58
  # Print local recommendations as JSON
48
59
  tokentrace status --json
@@ -66,6 +77,48 @@ tokentrace --help # Print help
66
77
  tokentrace --version # Print version
67
78
  ```
68
79
 
80
+ ## For Coding Agents
81
+
82
+ Agents should start with the read-only discovery manifest:
83
+
84
+ ```bash
85
+ tokentrace agent --json
86
+ ```
87
+
88
+ The alias below returns the same manifest:
89
+
90
+ ```bash
91
+ tokentrace capabilities --json
92
+ ```
93
+
94
+ The manifest describes TokenTrace's local-first privacy model, safe JSON commands,
95
+ common workflows, Claude Code status-line setup, Codex sidecar fallback, and
96
+ guardrails such as never running `tokentrace reset` without explicit human
97
+ approval. The discovery command does not scan files, initialize the database, or
98
+ start the dashboard.
99
+
100
+ Package-level agent references are included for agents that inspect repository
101
+ or npm package contents before invoking commands:
102
+
103
+ - [TOKENTRACE_AGENT.md](TOKENTRACE_AGENT.md)
104
+ - [llms.txt](llms.txt)
105
+ - [docs/agent-discovery.schema.json](docs/agent-discovery.schema.json)
106
+
107
+ When the local dashboard is already running, agents can fetch the same manifest
108
+ over localhost:
109
+
110
+ ```bash
111
+ curl http://127.0.0.1:3030/api/agent
112
+ curl http://127.0.0.1:3030/api/capabilities
113
+ ```
114
+
115
+ The 0.10.0 release status is also machine-readable:
116
+
117
+ ```bash
118
+ tokentrace roadmap --json
119
+ curl http://127.0.0.1:3030/api/roadmap
120
+ ```
121
+
69
122
  ## Run From Source
70
123
 
71
124
  ```bash
@@ -92,6 +145,10 @@ npm run verify # Run Vitest, TypeScript, and ESLint checks
92
145
  npm run package:test # Verify, build, and dry-run the npm package
93
146
  npm run package:inspect
94
147
  # Check package transparency guardrails
148
+ npm run smoke:packed
149
+ # Inspect packed tarball and smoke test packed CLI
150
+ tokentrace roadmap --json
151
+ # Inspect 0.10.0 evidence gates and release status
95
152
  ```
96
153
 
97
154
  Release work uses internal milestone commits until the next public minor
@@ -139,6 +196,13 @@ Settings also supports optional local monthly usage guardrails. Set a cost
139
196
  limit, token limit, or both, and Overview will show month-to-date progress from
140
197
  imported local CLI usage.
141
198
 
199
+ Sessions includes built-in and local saved views for recurring review paths:
200
+ unknown cost, high-cost sessions, Claude/Codex this month, estimated tokens,
201
+ guardrail review, and parser review. Open a session's **Timeline** link to see
202
+ ordered interactions, model changes, token spikes, cache activity, tool calls,
203
+ parser confidence, and unknown-cost events. Raw prompts and message bodies stay
204
+ hidden by default.
205
+
142
206
  ## Ingestion Architecture
143
207
 
144
208
  TokenTrace's primary ingestion architecture is direct local filesystem ingestion:
@@ -188,6 +252,10 @@ tokentrace statusline claude
188
252
 
189
253
  Claude Code sends session JSON to the command on stdin. TokenTrace reads the transcript path, model, context usage, and session cost, then prints one compact local line:
190
254
 
255
+ ```text
256
+ TokenTrace | Opus | ctx 7% | cost $0.1235 | processed 3.3K tokens | cache 2.0K | priced
257
+ ```
258
+
191
259
  Do not set the Claude Code `statusLine.command` to plain `tokentrace`. Plain `tokentrace` starts the dashboard, while `tokentrace statusline claude` prints exactly one status-line response.
192
260
 
193
261
  ![TokenTrace Claude Code status line](docs/assets/claude-statusline.svg)
@@ -199,6 +267,15 @@ tokentrace status --json
199
267
  tokentrace watch --session
200
268
  ```
201
269
 
270
+ Daily reporting commands stay deterministic and local:
271
+
272
+ ```bash
273
+ tokentrace digest --since last-scan
274
+ tokentrace digest --since 2026-05-01 --json
275
+ tokentrace report --markdown --since yesterday
276
+ tokentrace review --json
277
+ ```
278
+
202
279
  Codex CLI status-line integration is intentionally deferred until its status-line and hook contracts are stable enough to support without fragile terminal output parsing. Use `tokentrace watch --session --compact` in a terminal split or tmux pane as the current fallback. See [docs/CODEX_INTEGRATION_SPIKE.md](docs/CODEX_INTEGRATION_SPIKE.md) for the current decision.
203
280
 
204
281
  ## Screenshots
@@ -0,0 +1,83 @@
1
+ # TokenTrace Agent Guide
2
+
3
+ TokenTrace is a local-first CLI and dashboard for AI coding-agent token, cost,
4
+ session, parser, and evidence analytics.
5
+
6
+ ## Start Here
7
+
8
+ Use the read-only discovery manifest before running any other TokenTrace command:
9
+
10
+ ```bash
11
+ tokentrace agent --json
12
+ ```
13
+
14
+ This alias returns the same manifest:
15
+
16
+ ```bash
17
+ tokentrace capabilities --json
18
+ ```
19
+
20
+ The manifest follows the schema in `docs/agent-discovery.schema.json`.
21
+
22
+ If the local dashboard is already running, the same manifest is available from:
23
+
24
+ ```bash
25
+ curl http://127.0.0.1:3030/api/agent
26
+ curl http://127.0.0.1:3030/api/capabilities
27
+ ```
28
+
29
+ ## Roadmap Status
30
+
31
+ Inspect the current 0.10.0 implementation pipeline and release blockers:
32
+
33
+ ```bash
34
+ tokentrace roadmap --json
35
+ curl http://127.0.0.1:3030/api/roadmap
36
+ ```
37
+
38
+ ## Safe Automation Loop
39
+
40
+ 1. Discover capabilities:
41
+
42
+ ```bash
43
+ tokentrace agent --json
44
+ ```
45
+
46
+ 2. Refresh local data when the human expects current usage:
47
+
48
+ ```bash
49
+ tokentrace scan --json
50
+ ```
51
+
52
+ 3. Check trust before making claims:
53
+
54
+ ```bash
55
+ tokentrace doctor --json
56
+ ```
57
+
58
+ 4. Explain totals with evidence:
59
+
60
+ ```bash
61
+ tokentrace evidence --json
62
+ ```
63
+
64
+ ## Guardrails
65
+
66
+ - Do not run `tokentrace reset` unless the human explicitly asks to clear imported local data.
67
+ - Do not call processed tokens current context size. Use `ctx` for live context-window pressure.
68
+ - Treat database paths, source file paths, prompts, and raw transcript settings as local sensitive data.
69
+ - Discovery is read-only: it does not scan files, initialize the dashboard database, start a server, or make a network request.
70
+
71
+ ## Integrations
72
+
73
+ Claude Code status line:
74
+
75
+ ```bash
76
+ tokentrace statusline setup claude
77
+ ```
78
+
79
+ Codex fallback while native status-line hooks remain unstable:
80
+
81
+ ```bash
82
+ tokentrace watch --session --compact
83
+ ```
@@ -0,0 +1,7 @@
1
+ import { agentDiscoveryResponse } from "@/src/lib/agent-discovery-api";
2
+
3
+ export const dynamic = "force-dynamic";
4
+
5
+ export async function GET() {
6
+ return agentDiscoveryResponse();
7
+ }
@@ -0,0 +1,7 @@
1
+ import { agentDiscoveryResponse } from "@/src/lib/agent-discovery-api";
2
+
3
+ export const dynamic = "force-dynamic";
4
+
5
+ export async function GET() {
6
+ return agentDiscoveryResponse();
7
+ }
@@ -0,0 +1,13 @@
1
+ import { NextResponse } from "next/server";
2
+ import { getAppVersion } from "@/src/lib/app-version";
3
+ import { buildRoadmapStatus } from "@/src/lib/roadmap-status";
4
+
5
+ export const dynamic = "force-dynamic";
6
+
7
+ export async function GET() {
8
+ return NextResponse.json(buildRoadmapStatus({ packageVersion: getAppVersion() }), {
9
+ headers: {
10
+ "cache-control": "no-store"
11
+ }
12
+ });
13
+ }
@@ -0,0 +1,16 @@
1
+ import { NextResponse } from "next/server";
2
+ import { deleteSavedView } from "@/src/lib/saved-views";
3
+
4
+ export const dynamic = "force-dynamic";
5
+
6
+ export async function DELETE(
7
+ _request: Request,
8
+ {
9
+ params
10
+ }: {
11
+ params: Promise<{ id: string }>;
12
+ }
13
+ ) {
14
+ const { id } = await params;
15
+ return NextResponse.json({ deleted: deleteSavedView(decodeURIComponent(id)) });
16
+ }
@@ -0,0 +1,35 @@
1
+ import { NextResponse } from "next/server";
2
+ import { readJsonObject } from "@/src/lib/api-json";
3
+ import { getSavedViews, saveSavedView } from "@/src/lib/saved-views";
4
+
5
+ export const dynamic = "force-dynamic";
6
+
7
+ function object(value: unknown): Record<string, unknown> {
8
+ return value && typeof value === "object" && !Array.isArray(value)
9
+ ? (value as Record<string, unknown>)
10
+ : {};
11
+ }
12
+
13
+ export async function GET() {
14
+ return NextResponse.json(getSavedViews());
15
+ }
16
+
17
+ export async function POST(request: Request) {
18
+ const parsed = await readJsonObject(request);
19
+ if (!parsed.ok) {
20
+ return NextResponse.json({ error: parsed.error }, { status: 400 });
21
+ }
22
+
23
+ try {
24
+ const view = saveSavedView({
25
+ name: typeof parsed.body.name === "string" ? parsed.body.name : "",
26
+ filters: object(parsed.body.filters)
27
+ });
28
+ return NextResponse.json({ view });
29
+ } catch (error) {
30
+ return NextResponse.json(
31
+ { error: error instanceof Error ? error.message : "could not save view" },
32
+ { status: 400 }
33
+ );
34
+ }
35
+ }