@drod915/kvdiff 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +126 -3
- package/dist/cli.js +1849 -0
- package/dist/cli.js.map +1 -0
- package/dist/ui/assets/index-6zpHKv0K.css +1 -0
- package/dist/ui/assets/index-B2iXBreS.js +1 -0
- package/dist/ui/index.html +13 -0
- package/package.json +57 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kvdiff contributors
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# kvdiff
|
|
2
|
+
|
|
3
|
+
**Zero-code local proxy that pinpoints the exact UTF-8 byte breaking your LLM prompt cache (Anthropic, OpenAI, Google Gemini / Antigravity, `llama.cpp`/vLLM), tallies wasted dollars, and optionally auto-heals prefixes live.**
|
|
4
|
+
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
[](https://nodejs.org)
|
|
7
|
+
[-informational.svg)](#architecture)
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
**Try the demo:** `npx @drod915/kvdiff --demo` | [Poster preview](./docs/kvdiff-poster.png)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## See a Prompt-Cache Bust in 5 Seconds (Zero API Keys Required)
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx @drod915/kvdiff --demo
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Opens `http://127.0.0.1:4318` pre-seeded with two realistic sessions:
|
|
22
|
+
1. **Claude Code + 15 MCP Tools (16 turns):** Turn 1 warms the prompt cache at 0%, and Turns 2-13 run at 94% cache hit. On **Turn 14**, `mcp-github` reconnects and reorders tool schemas: `kvdiff` highlights the exact red byte offset (`$.tools[9].name`, byte 1,670), calculates the wasted cost ($0.38), and shows **Turn 15** snapping back to **97% cache hit** under `--heal`.
|
|
23
|
+
2. **Antigravity / Gemini 2.5 Pro (5 turns):** Catches a volatile timestamp injected into `$.systemInstruction.parts[0].text` on Turn 4.
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
> Record the demo in a terminal with `vhs demo/kvdiff.tape`.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
Wrap any coding agent CLI with zero code changes:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Claude Code (Anthropic Messages API)
|
|
37
|
+
npx @drod915/kvdiff -- claude
|
|
38
|
+
|
|
39
|
+
# Codex CLI / OpenCode (OpenAI Responses & Chat APIs)
|
|
40
|
+
npx @drod915/kvdiff -- codex
|
|
41
|
+
|
|
42
|
+
# Gemini CLI / Antigravity API workflows (Google Gemini API)
|
|
43
|
+
npx @drod915/kvdiff -- gemini
|
|
44
|
+
|
|
45
|
+
# Opt-in deterministic tool-schema healing
|
|
46
|
+
npx @drod915/kvdiff --heal -- claude
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or run as a persistent local proxy for Antigravity, Cursor, IDE plugins, or local `llama.cpp`/vLLM:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Cloud providers (Anthropic, OpenAI, Google Gemini / Antigravity)
|
|
53
|
+
npx @drod915/kvdiff serve --port 4318
|
|
54
|
+
|
|
55
|
+
# Local llama.cpp / vLLM KV-cache prefix reuse debugging
|
|
56
|
+
npx @drod915/kvdiff serve --port 4318 --upstream-local http://127.0.0.1:8080
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Then point your client base URL:
|
|
60
|
+
- `ANTHROPIC_BASE_URL=http://127.0.0.1:4318`
|
|
61
|
+
- `OPENAI_BASE_URL=http://127.0.0.1:4318/v1`
|
|
62
|
+
- `GOOGLE_GEMINI_BASE_URL=http://127.0.0.1:4318`
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## What `kvdiff` Catches
|
|
67
|
+
|
|
68
|
+
| Break Kind | What Happened on the Wire | Fix |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| `TOOL_REORDER` | MCP servers reconnected or registered tools in non-deterministic order | Pass `--heal` to sort `tools[]` (and Gemini `functionDeclarations[]`) deterministically |
|
|
71
|
+
| `TOOL_MUTATED` | A dynamic tool description or schema field changed mid-session | Pin static tool descriptions outside the cached prefix |
|
|
72
|
+
| `VOLATILE_SYSTEM` | A timestamp, UUID, or mutable status string landed inside `$.system` / `$.systemInstruction` | Move dynamic metadata into the trailing user turn |
|
|
73
|
+
| `TTL_EXPIRED` | Bytes matched 100%, but `>5m` elapsed between turns | Keep interactive sessions warm or opt into extended TTL |
|
|
74
|
+
| `MODEL_CHANGED` | Model name switched mid-session | Keep one model per cache prefix |
|
|
75
|
+
| `PREFIX_TOO_SHORT` | Prompt fell under OpenAI (`1,024`) or Gemini (`1,024`/`2,048`) implicit-cache floor | Expected until context grows past threshold |
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Honest Comparison
|
|
80
|
+
|
|
81
|
+
| Feature | `kvdiff` | `ccusage` / `codexbar` | `ContextSpy` | Langfuse / Phoenix |
|
|
82
|
+
|---|---|---|---|---|
|
|
83
|
+
| **Install & Infra** | 1 cmd (`npx`), built-in `node:sqlite` | 1 cmd (`npx`/binary) | 1 cmd (`npx`) | Docker + Postgres/ClickHouse |
|
|
84
|
+
| **Wire-level UTF-8 byte LCP + JSONPath diff** | **Yes** | No (reads post-hoc logs) | No (token category pies) | No |
|
|
85
|
+
| **Opt-in live prefix healing (`--heal`)** | **Yes** | No | No | No |
|
|
86
|
+
| **Multi-provider (Anthropic + OpenAI + Gemini/Antigravity + `llama.cpp`)** | **Yes** | Single-provider focus | Anthropic/OpenAI | Yes |
|
|
87
|
+
| **Zero-mutation default passthrough** | **Yes** (OAuth/beta headers intact) | N/A (offline log reader) | Yes | SDK instrumentation |
|
|
88
|
+
| **Where competitors win** | - | Zero proxy setup; great historical billing totals across past months | High-level token breakdown visualizations | Production team evals, prompt versioning, multi-user cloud traces |
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Architecture
|
|
93
|
+
|
|
94
|
+
```mermaid
|
|
95
|
+
flowchart LR
|
|
96
|
+
Agent["Coding Agent / IDE\n(Claude Code · Codex · Antigravity · Gemini · llama.cpp)"] -->|"HTTP (127.0.0.1:4318)"| Proxy["kvdiff Proxy\nZero-mutation default\n(opt-in --heal)"]
|
|
97
|
+
Proxy -->|"Immediate chunked SSE flush"| Upstream["Upstream Provider\nAnthropic · OpenAI · Gemini · Local"]
|
|
98
|
+
Proxy -.->|"Non-blocking SSE tee"| Engine["UTF-8 Byte LCP +\nJSONPath Mapper +\nBreak Classifier"]
|
|
99
|
+
Engine --> DB[("~/.kvdiff/kvdiff.db\nNode 24 node:sqlite WAL")]
|
|
100
|
+
DB --> UI["Localhost Waterfall UI\n127.0.0.1:4318"]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Safety & Privacy Guarantees
|
|
104
|
+
- **100% Local:** Binds to `127.0.0.1` by default. Stores traffic only in `~/.kvdiff/kvdiff.db`. Zero telemetry, zero cloud accounts.
|
|
105
|
+
- **Strict Zero-Mutation Default:** Without `--heal`, `kvdiff` forwards your exact raw request bytes and every non-hop-by-hop header (`Authorization`, `x-api-key`, `x-goog-api-key`, `anthropic-beta`, `openai-beta`) unmodified.
|
|
106
|
+
- **Zero-Buffering SSE:** Streaming responses flush downstream chunk-by-chunk as they arrive from upstream.
|
|
107
|
+
- **Safe `--heal` Invariant:** `--heal` sorts tools and tool-definition keys, normalizes JSON formatting, and keeps the trailing Anthropic cache breakpoint on the final tool after sorting. It **never** reorders `messages[]`, `contents[]`, `parts[]`, `content[]`, `input[]`, or JSON Schema `enum[]`.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Development
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
git clone https://github.com/flipcyde101/kvdiff.git
|
|
115
|
+
cd kvdiff
|
|
116
|
+
npm install
|
|
117
|
+
npm run typecheck
|
|
118
|
+
npm run build
|
|
119
|
+
npm test
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Found a cache-break pattern or provider edge case? Open an issue at [github.com/flipcyde101/kvdiff/issues](https://github.com/flipcyde101/kvdiff/issues).
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
[MIT](./LICENSE)
|