Erick Shaffer 4182b9e0b3 Fix token tracking to show accurate usage and add empirical warnings
This PR fixes critical issues with token tracking and provides users with
actionable warnings based on real failure data.

1. **Incorrect token counting**: The system was adding cache tokens
   (cache_creation_input_tokens, cache_read_input_tokens) as if they were
   new tokens, causing inflated counts like 28125% usage. Cache tokens are
   cumulative state, not incremental additions.

2. **No user guidance**: Users had no warning when approaching context limits,
   leading to unexpected "Prompt is too long" errors.

- Show only raw token counts from Claude API (input + output)
- Remove percentage calculations and context window estimates
- Display running totals that users can trust

Based on analysis of 29 failed sessions, implemented three warning levels:
- ✅ Safe: < 80K tokens
- ⚠️ Caution: 80K-95K tokens (yellow warning)
- 🚨 Danger: > 95K tokens (red alert)

The lowest observed failure was at 96,800 tokens, so warnings start at 80K
to give users ample time to start a new session.

- Styled clickable popover (replacing poor native tooltips)
- Token breakdown (input/output/total)
- Clear warning messages with context
- Dark mode support

- Fixed `extractTokenUsage()` to only count actual input/output tokens
- Removed hardcoded system overhead calculations
- Added contextWindowTokens tracking for future use
- Updated UI to show raw truth instead of estimates

This gives users the information they need without confusing calculations
or impossible percentages.
2025-07-20 15:12:41 -06:00
..
2025-06-19 09:44:15 -04:00
2025-06-16 15:38:34 -04:00
2025-06-16 15:22:30 -04:00
2025-06-16 15:22:30 -04:00

Scripts Directory

This directory contains build and maintenance scripts for the Crystal application.

generate-notices.js

Generates a NOTICES file containing all third-party licenses for dependencies included in the Crystal distribution.

Usage

# Generate NOTICES file
pnpm run generate-notices

# Or run directly
node scripts/generate-notices.js

How it works

  1. Scans all node_modules directories in the workspace
  2. Collects license information from LICENSE files and package.json
  3. Excludes development-only dependencies that aren't distributed
  4. Creates a NOTICES file in the project root

When to run

  • Automatically runs during pnpm run build:mac and pnpm run release:mac
  • Should be run whenever dependencies change
  • CI/CD runs this in the license-compliance workflow

License compliance

The script helps ensure Crystal complies with open source license requirements by:

  • Including all third-party license texts in distributions
  • Identifying packages with missing license information
  • Supporting the license-compliance GitHub workflow