Skip to content

Commit 046501c

Browse files
committed
Updated the skill to work as wanted
1 parent d39fc7f commit 046501c

4 files changed

Lines changed: 204 additions & 150 deletions

File tree

.github/skills/load-cache-data/README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,39 @@ node .github/skills/load-cache-data/load-cache-data.js --help
2020

2121
## What This Skill Does
2222

23-
1. **Demonstrates cache structure** - Shows the format and content of cached session data
24-
2. **Provides access patterns** - Example code for reading cache from VS Code globalState
25-
3. **Helps debugging** - Understand what's being cached and when
23+
1. **Reads actual cache data** - Loads real cache data from export files on disk
24+
2. **Multiple search locations** - Checks VS Code globalStorage, temp directory, and current directory
25+
3. **Helps debugging** - Inspect what's being cached and when
2626
4. **Supports development** - Iterate with real data structures when building features
2727

28+
## Cache File Locations
29+
30+
The script searches for cache export files in these locations (in order):
31+
32+
**Windows:**
33+
- `%APPDATA%\Code\User\globalStorage\rajbos.copilot-token-tracker\cache.json`
34+
- `%TEMP%\copilot-token-tracker-cache.json`
35+
- `.\cache-export.json`
36+
37+
**macOS:**
38+
- `~/Library/Application Support/Code/User/globalStorage/rajbos.copilot-token-tracker/cache.json`
39+
- `/tmp/copilot-token-tracker-cache.json`
40+
- `./cache-export.json`
41+
42+
**Linux:**
43+
- `~/.config/Code/User/globalStorage/rajbos.copilot-token-tracker/cache.json`
44+
- `/tmp/copilot-token-tracker-cache.json`
45+
- `./cache-export.json`
46+
47+
*Note: Also checks other VS Code variants (Insiders, Cursor, VSCodium, Code - Exploration)*
48+
2849
## Important Note
2950

30-
The cache is stored in VS Code's internal database (`state.vscdb`) and is only directly accessible through the extension's API at runtime. This script generates example data that matches the real cache structure.
51+
The extension stores its cache in VS Code's internal globalState (SQLite database `state.vscdb`), which is not directly accessible from external scripts. To use this skill with real data:
52+
53+
1. **Export from extension**: Add functionality to export cache to disk
54+
2. **Export from tests**: Test code can write cache data to one of the expected locations
55+
3. **Manual export**: Extract cache from globalState and save to disk
3156

3257
To access real cache data, use the extension's API:
3358

.github/skills/load-cache-data/SKILL.md

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
---
22
name: load-cache-data
3-
description: Load and inspect the last 10 rows from the local session file cache to iterate with real data. Use when you need to understand cached session statistics, debug cache behavior, or work with actual cached data.
3+
description: Load and display the last 10 cache entries as raw JSON output. DO NOT create extra files or pretty-print the data - output raw JSON only. Use when you need to understand cached session statistics, debug cache behavior, or work with actual cached data.
44
---
55

66
# Load Cache Data Skill
77

8+
**IMPORTANT: Always output raw JSON only. Do not create extra files for displaying data.**
9+
810
This skill helps you access and inspect the GitHub Copilot Token Tracker's local session file cache. The cache stores pre-computed statistics for session files to avoid re-processing unchanged files.
911

1012
## Overview
@@ -25,6 +27,14 @@ Use this skill when you need to:
2527
- Work with real cached data for testing or development
2628
- Iterate on features that rely on cached statistics
2729

30+
## Output Requirements
31+
32+
**CRITICAL**: When using this skill:
33+
- **ALWAYS** use the `--json` flag to output raw JSON
34+
- **NEVER** create extra files just for displaying data
35+
- **DO NOT** pretty-print or format the output in human-readable text
36+
- Simply run the script with `--json` and display the raw JSON output
37+
2838
## Cache Structure
2939

3040
The cache is stored in VS Code's global state under the key `'sessionFileCache'`. Each cache entry is keyed by the absolute file path and contains:
@@ -92,35 +102,52 @@ for (const [filePath, cacheEntry] of last10) {
92102

93103
### Using the Provided Script
94104

95-
This skill includes an executable script that demonstrates the cache structure and provides example data:
105+
This skill includes an executable script that loads and displays actual cache data from disk:
96106

97107
**Location**: `.github/skills/load-cache-data/load-cache-data.js`
98108

99109
**Usage:**
100110
```bash
101-
# Show last 10 cache entries (default)
102-
node .github/skills/load-cache-data/load-cache-data.js
103-
104-
# Show last 5 entries
105-
node .github/skills/load-cache-data/load-cache-data.js --last 5
106-
107-
# Output as JSON
111+
# RECOMMENDED: Always use --json for raw JSON output
108112
node .github/skills/load-cache-data/load-cache-data.js --json
109113

110-
# Show last 3 entries as JSON
111-
node .github/skills/load-cache-data/load-cache-data.js --last 3 --json
114+
# Show last N entries as JSON (default is 10)
115+
node .github/skills/load-cache-data/load-cache-data.js --last 5 --json
112116

113117
# Show help
114118
node .github/skills/load-cache-data/load-cache-data.js --help
115119
```
116120

121+
**Note**: The script supports human-readable output without `--json`, but for LLM skills, always use `--json` to get structured data.
122+
117123
**What it does:**
118-
- Finds VS Code installation paths on the current system
119-
- Demonstrates the cache data structure with example entries
120-
- Shows how cache entries are formatted and sorted
121-
- Provides code examples for accessing real cache data
124+
- Searches for cache export files in known locations
125+
- Reads actual cache data if a file exists
126+
- Displays cache entries sorted by most recent modification
127+
- Shows detailed token counts, model usage, and usage analysis
128+
129+
**Cache File Locations:**
130+
131+
The script searches for cache export files in these locations:
132+
133+
1. **VS Code globalStorage**: `%APPDATA%\Code\User\globalStorage\rajbos.copilot-token-tracker\cache.json` (Windows)
134+
- Also checks other VS Code variants (Insiders, Cursor, VSCodium, etc.)
135+
2. **Temp directory**: `%TEMP%\copilot-token-tracker-cache.json`
136+
3. **Current directory**: `./cache-export.json`
137+
138+
**Creating Cache Export Files:**
139+
140+
Since the extension stores cache in VS Code's globalState (internal SQLite database), the cache data must be explicitly exported to one of the above locations for this script to access it. This can be done:
141+
142+
1. **Via Extension**: The extension can be enhanced to export cache on demand
143+
2. **Via Tests**: Test code can write cache data to disk for inspection
144+
3. **Manually**: Copy cache data from extension's globalState and save to one of the expected locations
145+
146+
**Exit Codes:**
147+
- `0`: Cache file found and displayed successfully
148+
- `1`: No cache file found
122149

123-
**Note**: The script generates example data because VS Code's internal database is only accessible through the extension's API at runtime. Use the extension's API (shown above) to access real cache data.
150+
**Note**: If no cache file is found, the script will display the searched locations and instructions for exporting cache data.
124151

125152
## Cache Management Methods
126153

0 commit comments

Comments
 (0)