Skip to content

Commit 34e1a3c

Browse files
committed
docs: rewrite SKILLS.md as libCacheSim capability guide for agents
Documents what agents can actually do in this repo: build, simulate, analyze traces, profile MRCs, plot results, use the C API, add algorithms, write plugins, and run tests. https://claude.ai/code/session_01KTsbYTi2RdaKZTR6HKd7KF
1 parent ef4570a commit 34e1a3c

1 file changed

Lines changed: 164 additions & 84 deletions

File tree

SKILLS.md

Lines changed: 164 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,225 @@
1-
# Claude Code Skills for libCacheSim
1+
# libCacheSim Skills for Agents
22

3-
This file documents the Claude Code slash-command skills available to agents working in this repository. Skills are pre-built behaviors that extend Claude Code; invoke them with the `/skill-name` syntax in any Claude Code session.
3+
What you can do in this repository. Each section maps to a concrete capability, the tool or API that provides it, and the commands to invoke it.
44

5-
## Quick Reference
5+
---
6+
7+
## Build
8+
9+
```bash
10+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
11+
cmake --build build -j$(nproc)
12+
```
13+
14+
Produces three binaries in `build/bin/`: `cachesim`, `traceAnalyzer`, `mrcProfiler`.
15+
Optional features require XGBoost/LightGBM; omit them unless the algorithm specifically needs it.
616

7-
| Skill | Command | Purpose |
8-
|---|---|---|
9-
| `update-config` | `/update-config` | Configure the Claude Code harness via `settings.json` |
10-
| `session-start-hook` | `/session-start-hook` | Set up `SessionStart` hooks (build checks, linters) |
11-
| `simplify` | `/simplify` | Review changed code for quality, reuse, and efficiency |
12-
| `loop` | `/loop [interval] [cmd]` | Run a command repeatedly on a timed interval |
13-
| `schedule` | `/schedule` | Create scheduled remote agents on a cron schedule |
14-
| `claude-api` | `/claude-api` | Build tools or integrations using the Anthropic SDK |
15-
| `keybindings-help` | `/keybindings-help` | Customize keyboard shortcuts |
17+
Install dependencies first if not present:
18+
19+
```bash
20+
bash scripts/install_dependency.sh
21+
```
1622

1723
---
1824

19-
## Skills
25+
## Simulate a cache
26+
27+
`cachesim` runs one or more eviction algorithms against a trace file and reports hit/miss ratios.
2028

21-
### `update-config` — Configure the harness
29+
```bash
30+
# Single algorithm, one cache size
31+
./build/bin/cachesim trace.oracleGeneral oracleGeneral 1073741824 LRU
2232

23-
Use this when you want to add automated behaviors: "before every commit run the linter", "after each edit rebuild", etc. Automated behaviors are executed by the **harness** (not by Claude at prompt time), so they must be registered in `settings.json` via hooks—asking Claude to remember something is not sufficient.
33+
# Multiple algorithms in parallel
34+
./build/bin/cachesim trace.oracleGeneral oracleGeneral 1073741824 LRU,S3-FIFO,Sieve
2435

25-
```
26-
/update-config
36+
# Auto-detect working set, sweep a range of sizes
37+
./build/bin/cachesim trace.oracleGeneral oracleGeneral 0 LRU --num-thread 4
38+
39+
# CSV trace with custom column mapping
40+
./build/bin/cachesim trace.csv csv 1073741824 LRU \
41+
-t "time-col=0, obj-id-col=1, obj-size-col=2, delimiter=,"
2742
```
2843

29-
**When to use:**
30-
- Setting up pre/post-tool hooks (e.g., run `cmake --build` after file edits)
31-
- Storing project-level defaults or allowed tool lists
32-
- Enabling or disabling specific capabilities for automated sessions
44+
**Supported eviction algorithms** (pass by name):
45+
FIFO, LRU, Clock, SLRU, LFU, LFUDA, ARC, TwoQ, CLOCK-PRO, Belady, BeladySize, GDSF,
46+
Hyperbolic, LeCaR, Cacheus, LHD, LRB, GLCache, WTinyLFU, 3LCache, QD-LP, S3-FIFO, Sieve
3347

34-
---
48+
**Admission algorithms** (combine with `-a`): Adaptsize, Bloomfilter, Prob, Size
3549

36-
### `session-start-hook` — Ensure the project is ready at session start
50+
Full parameter reference: `./build/bin/cachesim --help`
3751

38-
Sets up a `SessionStart` hook so every new Claude Code session begins by verifying the project is in a known-good state: dependencies installed, build passing, tests green.
52+
---
3953

40-
```
41-
/session-start-hook
42-
```
54+
## Analyze a trace
4355

44-
**When to use:**
45-
- First-time setup of a repo for Claude Code on the web
46-
- Ensuring `cmake` configuration and build succeed before an agent starts editing C code
47-
- Running `ctest` at session start to confirm no pre-existing failures
56+
`traceAnalyzer` extracts statistics and generates plot-ready data from a trace.
4857

49-
**libCacheSim example hook:**
5058
```bash
51-
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build -j$(nproc)
52-
```
59+
# Overall statistics
60+
./build/bin/traceAnalyzer trace.oracleGeneral oracleGeneral --task stat
5361

54-
---
62+
# Request rate over time (window = 300 s)
63+
./build/bin/traceAnalyzer trace.oracleGeneral oracleGeneral --task reqRate -w 300
5564

56-
### `simplify` — Code review after changes
65+
# Object size distribution
66+
./build/bin/traceAnalyzer trace.oracleGeneral oracleGeneral --task size
5767

58-
After making edits, invoke this skill to review the changed code for redundancy, reuse opportunities, and inefficiencies. The skill finds issues and fixes them in place.
68+
# Reuse distance / reuse time distribution
69+
./build/bin/traceAnalyzer trace.oracleGeneral oracleGeneral --task reuse
5970

60-
```
61-
/simplify
71+
# Popularity (frequency distribution)
72+
./build/bin/traceAnalyzer trace.oracleGeneral oracleGeneral --task popularity
73+
74+
# Run all analysis tasks and write output files for plotting
75+
./build/bin/traceAnalyzer trace.oracleGeneral oracleGeneral --task all
6276
```
6377

64-
**When to use:**
65-
- After adding a new eviction algorithm to check for duplicated logic
66-
- After editing `CMakeLists.txt` to verify build targets aren't redundant
67-
- As a final pass before committing
78+
Output files are written to the current directory and consumed by scripts in `scripts/traceAnalysis/`.
6879

6980
---
7081

71-
### `loop` — Recurring tasks
82+
## Profile a miss ratio curve (MRC)
7283

73-
Runs a prompt or slash command on a repeating interval. Defaults to every 10 minutes if no interval is specified.
84+
`mrcProfiler` builds an MRC without simulating every cache size from scratch.
7485

75-
```
76-
/loop [interval] [command or prompt]
77-
```
86+
```bash
87+
# SHARDS sampler — fast, LRU only
88+
./build/bin/mrcProfiler trace.oracleGeneral oracleGeneral SHARDS
7889

79-
**Examples:**
80-
```
81-
/loop 5m /simplify
82-
/loop 2m check if the cmake build is still passing and report any errors
90+
# MINISIM sampler — supports any algorithm, multi-threaded
91+
./build/bin/mrcProfiler trace.oracleGeneral oracleGeneral MINISIM --num-thread 8
92+
93+
# MRC relative to working set size
94+
./build/bin/mrcProfiler trace.oracleGeneral oracleGeneral SHARDS --use-wss
8395
```
8496

85-
**When to use:**
86-
- Watching a long `ctest` run and summarizing new failures as they appear
87-
- Periodically re-running the trace analyzer on a data file and diffing results
97+
SHARDS achieves ~23× speedup over full replay at <0.1% MAE.
98+
MINISIM supports all algorithms that `cachesim` supports.
8899

89100
---
90101

91-
### `schedule` — Cron-based remote agents
102+
## Plot results
103+
104+
Python scripts in `scripts/` consume output from `traceAnalyzer` and `mrcProfiler`.
105+
106+
```bash
107+
# Miss ratio curve vs cache size
108+
python3 scripts/plot_mrc_size.py --input result.mrc
109+
110+
# MRC over time
111+
python3 scripts/plot_mrc_time.py --input result.mrc
92112

93-
Creates, updates, lists, or runs scheduled remote agents that execute on a cron schedule. Unlike `/loop` (which runs in the current session), scheduled agents persist and run independently.
113+
# Approximate MRC (SHARDS / MINISIM output)
114+
python3 scripts/plot_appr_mrc.py --input result.mrc
94115

116+
# Trace-level plots (run after traceAnalyzer --task all)
117+
python3 scripts/traceAnalysis/access_pattern.py
118+
python3 scripts/traceAnalysis/req_rate.py
119+
python3 scripts/traceAnalysis/popularity.py
120+
python3 scripts/traceAnalysis/reuse.py
95121
```
96-
/schedule
122+
123+
---
124+
125+
## Generate a synthetic trace
126+
127+
```bash
128+
# Zipf workload: 1M requests, 100K objects, alpha=1.0
129+
python3 scripts/data_gen.py --num-req 1000000 --num-obj 100000 --alpha 1.0 \
130+
--output synthetic.oracleGeneral
97131
```
98132

99-
**When to use:**
100-
- Nightly performance regression checks against reference traces in `data/`
101-
- Weekly sweeps to ensure all example projects still build cleanly
102-
- Automated benchmark runs on a fixed schedule
133+
---
134+
135+
## Inspect or convert a trace
136+
137+
```bash
138+
# Print trace as human-readable text
139+
./build/bin/tracePrint trace.oracleGeneral oracleGeneral | head -20
140+
141+
# Convert between trace formats
142+
./build/bin/traceConv trace.csv csv trace.oracleGeneral oracleGeneral
143+
```
103144

104145
---
105146

106-
### `claude-api` — Build tools with the Anthropic SDK
147+
## Use the C API in code
148+
149+
The library API lets you build custom simulators. See `example/` for complete working programs.
150+
151+
```c
152+
#include "libCacheSim.h"
153+
154+
// Open a trace
155+
reader_t *reader = open_trace("trace.oracleGeneral", ORACLE_GENERAL_TRACE, NULL);
156+
157+
// Create a cache (e.g. 1 GiB LRU)
158+
common_cache_params_t params = default_common_cache_params();
159+
params.cache_size = 1 * GiB;
160+
cache_t *cache = LRU_init(params, NULL);
107161

108-
Triggered automatically when code imports `anthropic` or `@anthropic-ai/sdk`. Also invoke manually when you want to build a script or integration that calls Claude programmatically.
162+
// Simulate
163+
request_t *req = new_request();
164+
while (read_one_req(reader, req) == 0) {
165+
cache->get(cache, req); // returns true on hit
166+
}
109167

168+
free_request(req);
169+
free_cache(cache);
170+
close_trace(reader);
110171
```
111-
/claude-api
172+
173+
**Multi-size simulation** (runs N cache sizes in one pass):
174+
175+
```c
176+
simulate_at_multi_sizes(reader, cache, n_sizes, cache_sizes, NULL, 0, 4 /*threads*/);
112177
```
113178

114-
**When to use in libCacheSim context:**
115-
- Writing a Python script that uses Claude to analyze cache trace output and suggest algorithm tuning
116-
- Building a Node.js tool on top of `libcachesim-node` that calls Claude to interpret miss-ratio curves
117-
- Generating synthetic trace files with LLM assistance
179+
See `example/cacheSimulator/` for a minimal single-cache example and
180+
`example/cacheSimulatorConcurrent/` for multi-size and CSV trace usage.
118181

119182
---
120183

121-
### `keybindings-help` — Customize keyboard shortcuts
184+
## Add a new eviction algorithm
122185

123-
Modifies `~/.claude/keybindings.json` to rebind keys, add chord shortcuts, or change the submit key.
186+
1. Create `libCacheSim/cache/eviction/MyAlgo.c` — implement `init`, `get`, `find`, `insert`, `evict`, `remove`, `free`.
187+
2. Register it in `libCacheSim/cache/cacheObj.c` and the algo name map.
188+
3. Add it to `CMakeLists.txt`.
189+
4. Rebuild and verify with `cachesim`.
124190

125-
```
126-
/keybindings-help
191+
See `doc/advanced_lib_extend.md` for the full walkthrough and `doc/advanced_lib.md` for internal data structures.
192+
193+
---
194+
195+
## Write a plugin (without modifying core)
196+
197+
The plugin system lets you implement an algorithm as a shared library loaded at runtime.
198+
199+
```bash
200+
cd example/plugin_v2
201+
cmake -S . -B build && cmake --build build
202+
./build/test_plugin trace.oracleGeneral oracleGeneral 1073741824
127203
```
128204

129-
**When to use:**
130-
- Rebinding a key that conflicts with your terminal emulator
131-
- Adding a chord shortcut for a frequently used command like `/simplify`
205+
Implement the six hooks in your plugin: `plugin_init`, `plugin_hit`, `plugin_miss`, `plugin_eviction`, `plugin_remove`, `plugin_free`. See `example/plugin_v2/myPlugin.cpp`.
132206

133207
---
134208

135-
## Hooks vs. Asking Claude
209+
## Run tests
136210

137-
A common confusion: asking Claude "always run the linter after you edit a file" does **not** persist beyond the current session. To make a behavior automatic and durable, it must be registered as a hook in `settings.json`. Use `/update-config` or `/session-start-hook` to set this up correctly.
211+
```bash
212+
cd build && ctest --output-on-failure
213+
```
138214

139-
| Goal | Right approach |
215+
---
216+
217+
## Trace formats
218+
219+
| Format | Description |
140220
|---|---|
141-
| Run `cmake --build` after every file edit | `/update-config` → PostToolUse hook |
142-
| Verify build at the start of every session | `/session-start-hook` |
143-
| One-off code review | `/simplify` |
144-
| Recurring check during a session | `/loop` |
145-
| Persistent scheduled agent | `/schedule` |
221+
| `oracleGeneral` | Binary struct: `{uint32 timestamp, uint64 obj_id, uint32 obj_size, int64 next_access_vtime}`. Supports `.zst` compression. |
222+
| `csv` | Plain text; column mapping required via `-t` flag. |
223+
| `binary` | Raw fixed-width binary records. |
224+
225+
Object IDs in oracleGeneral are hashed values. `next_access_vtime` is logical time (request count, not wall clock).

0 commit comments

Comments
 (0)