billion-context 0.0.1 → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ranxianglei
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 ADDED
@@ -0,0 +1,102 @@
1
+ # billion-context
2
+
3
+ Universal context-compression proxy for AI coding agents.
4
+
5
+ `billion-context` sits between **any** agent and its model API, rewriting Anthropic/OpenAI streams with [acp-kernel](https://github.com/ranxianglei/acp-kernel) compression. Any agent that can set a base URL works out of the box — **zero per-agent adapter code**.
6
+
7
+ ## Why
8
+
9
+ Long coding sessions blow up context. Each provider charges per token, and once you pass the context window the session degrades or dies. `billion-context` compresses consumed conversation into layered summaries so you can run a single session for days — billions of tokens through one context window.
10
+
11
+ Unlike a host's built-in summarizer, compression here is **incremental, reversible, and prefix-cache friendly**: summaries are written in small ranges, can be decompressed on demand, and the cache prefix stays intact.
12
+
13
+ ## How it works
14
+
15
+ ```
16
+ Agent (Claude Code / Codex / Cursor / Aider ...)
17
+ │ you point the agent's base URL at the proxy
18
+
19
+ ┌─────────────────┐
20
+ │ billion-context│ 1. parse the request (Anthropic or OpenAI shape)
21
+ │ proxy │ 2. run acp-kernel compression on the conversation
22
+ │ │ 3. inject a `compress` tool + compression philosophy
23
+ │ │ 4. forward to the real model API
24
+ │ │ 5. rewrite the streaming response
25
+ └─────────────────┘
26
+
27
+
28
+ real model API (Anthropic / OpenAI / compatible)
29
+ ```
30
+
31
+ The proxy injects four context-management tools (`compress`, `decompress`, `search_context`, `acp_status`) into the conversation. The model calls `compress` when the conversation grows, and the proxy executes it server-side — the compressed ranges are folded into the conversation history before the next turn.
32
+
33
+ ## Install
34
+
35
+ ```bash
36
+ npm install -g billion-context
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ Start the proxy (defaults to port 8787, upstream inferred from your API key):
42
+
43
+ ```bash
44
+ bili-proxy
45
+ # or: billion-context
46
+ ```
47
+
48
+ Point your agent at the proxy.
49
+
50
+ ### Claude Code
51
+
52
+ ```bash
53
+ export ANTHROPIC_BASE_URL=http://localhost:8787
54
+ export ANTHROPIC_API_KEY=sk-ant-...
55
+ claude
56
+ ```
57
+
58
+ ### Codex / any OpenAI-compatible agent
59
+
60
+ ```bash
61
+ export OPENAI_BASE_URL=http://localhost:8787/v1
62
+ export OPENAI_API_KEY=sk-...
63
+ codex
64
+ ```
65
+
66
+ ### Cursor / Aider / others
67
+
68
+ Set the base URL / API endpoint to `http://localhost:8787` (Anthropic) or `http://localhost:8787/v1` (OpenAI) in the agent's settings.
69
+
70
+ ## Configuration
71
+
72
+ All config is via environment variables:
73
+
74
+ | Variable | Default | Description |
75
+ |----------|---------|-------------|
76
+ | `PORT` | `8787` | Proxy listen port |
77
+ | `HOST` | `127.0.0.1` | Proxy listen host |
78
+ | `UPSTREAM` | *(from API key)* | Upstream model API URL |
79
+ | `MODEL_CONTEXT_LIMIT` | `200000` | Context window for compression triggering |
80
+ | `ACP_DEBUG` | `0` | Set `1` to enable debug logging |
81
+ | `ACP_LOG_FILE` | `stderr` | Log file path |
82
+ | `ACP_PASSTHROUGH` | `0` | Set `1` to forward without compression (for debugging) |
83
+
84
+ ### Multiple upstreams
85
+
86
+ Route to different providers by API key:
87
+
88
+ ```bash
89
+ ACP_ROUTES='{"sk-ant-key1":{"upstream":"https://api.anthropic.com","apiKey":"real-key"},"sk-openai-key2":{"upstream":"https://api.openai.com","apiKey":"real-key2"}}'
90
+ ```
91
+
92
+ The agent authenticates with the route key; the proxy swaps in the real key and forwards to that route's upstream.
93
+
94
+ ## Status
95
+
96
+ Early. Protocol handling and compression work against mock tests (67 passing). Real-model integration testing is the next milestone. Expect rough edges.
97
+
98
+ See [billion-context-pi](https://github.com/ranxianglei/billion-context-pi) for the pi-extension mode (in-process, tighter integration, the reference implementation).
99
+
100
+ ## License
101
+
102
+ MIT