loopcap 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LoopCap 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,111 @@
1
- # Temporary Holding Version
1
+ # LoopCap
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Stop runaway AI agents before they burn your budget.** LoopCap is a local proxy between your agent and Anthropic or OpenAI. It meters token spend live and trips a circuit breaker when an agent loops on the same tool call or passes its spend cap.
4
+
5
+ ![LoopCap dashboard: an agent repeats the same bash call three times, the breaker trips, and the fourth request is blocked](docs/demo.gif)
6
+
7
+ <sub>Recorded from <code>npx loopcap demo</code>: a simulated agent loops on <code>npm test</code> and LoopCap blocks the 4th call.</sub>
8
+
9
+ ```bash
10
+ npx loopcap start # proxy on :4000, dashboard on http://localhost:4001
11
+ export ANTHROPIC_BASE_URL=http://localhost:4000 # in your agent's terminal
12
+ claude # Claude Code, or any Anthropic SDK client
13
+ ```
14
+
15
+ For OpenAI clients, set `OPENAI_BASE_URL=http://localhost:4000/v1` instead.
16
+
17
+ No agent handy? `npx loopcap demo` runs a simulated runaway loop and trips the breaker in a few seconds, without calling any provider.
18
+
19
+ > **Status: v0.1, early release.** Requires Node.js 24 LTS or later. **Only tested with Claude Code so far.** OpenAI Chat Completions support is implemented and checked against the official OpenAI SDK, but has not yet been tested with real OpenAI traffic. Reports from other agents are welcome.
20
+
21
+ ## Configuration
22
+
23
+ LoopCap runs with sensible defaults (see [Circuit breakers](#circuit-breakers)). To change them, run `npx loopcap init` to write `loopcap.config.yaml` in the current directory, then edit it. To install the command permanently, run `npm install -g loopcap`.
24
+
25
+ ## Point your agent at LoopCap
26
+
27
+ Set the variable for your provider in the terminal where the agent runs. Your API key stays where it is.
28
+
29
+ ```bash
30
+ # Anthropic Messages API (Claude Code, Anthropic SDKs). No /v1 suffix.
31
+ export ANTHROPIC_BASE_URL=http://localhost:4000
32
+
33
+ # OpenAI Chat Completions API (OpenAI SDKs, LangGraph, scripts). Needs /v1.
34
+ export OPENAI_BASE_URL=http://localhost:4000/v1
35
+ ```
36
+
37
+ Only `POST /v1/messages` and `POST /v1/chat/completions` are in scope for v0.1. Tools that send requests from their own servers cannot reach a proxy on your `localhost`; check this for Cursor and other hosted editors.
38
+
39
+ ## Circuit breakers
40
+
41
+ | Breaker | Trips when | Default |
42
+ |---|---|---|
43
+ | Identical loop | The same tool calls and arguments (or output) repeat in a row | 3 times |
44
+ | Session cap | One session's spend passes the cap | $2.00 |
45
+ | Burn rate | Spend per minute passes the limit | $0.75 |
46
+
47
+ Loop detection compares tool calls by name and arguments, ignoring key order and free-text fields listed in `ignoreArgKeys` (default: `description`). Requests are grouped by the tools they offer, so an agent's side requests (titles, summaries) don't interrupt a streak.
48
+
49
+ A tripped breaker answers in the provider's own response format (SSE or JSON) with a message explaining why, so the client ends its turn cleanly. You can also trip or reset it from the dashboard. Dollar figures for "saved" spend are estimates.
50
+
51
+ Settings live in [`loopcap.config.yaml`](loopcap.config.yaml). Prices live in [`pricing.json`](pricing.json); a model that isn't listed is metered as $0, and LoopCap warns about it.
52
+
53
+ To give each agent its own budget and loop history, send an `x-loopcap-session` header. Without one, all traffic shares a `default` session.
54
+
55
+ ## Architecture
56
+
57
+ Every request passes the breakers first. If they allow it, the response streams through while LoopCap meters usage, records it and updates the dashboard.
58
+
59
+ ```mermaid
60
+ flowchart LR
61
+ A[Agent] -->|"/v1/messages, /v1/chat/completions"| P
62
+ subgraph LoopCap
63
+ P["Proxy :4000"] --> B{Breakers}
64
+ B -->|open| T[Trip response]
65
+ T --> P
66
+ P --> U["Usage and cost meter"]
67
+ U --> S[("Memory window + SQLite")]
68
+ S --> B
69
+ U --> E[Event bus]
70
+ E --> D["Dashboard :4001"]
71
+ D -->|trip / reset| B
72
+ end
73
+ B -->|closed| L[Anthropic / OpenAI]
74
+ L -->|SSE stream| P
75
+ P -->|streamed through| A
76
+ ```
77
+
78
+ ## Privacy and security
79
+
80
+ LoopCap runs entirely on your machine.
81
+
82
+ - **Local only.** The proxy and dashboard listen on `127.0.0.1`, so other machines on your network can't reach them. LoopCap warns at startup if you change this.
83
+ - **Keys are passed through, never kept.** `x-api-key` and `Authorization` headers go to the provider unchanged. They are never logged, stored or shown on the dashboard.
84
+ - **What's stored.** `~/.loopcap/loopcap.db` (owner-only folder) holds token counts, costs, models, timings and fingerprints of tool calls. It never holds prompts, responses or keys. Change the location with `storage.path`.
85
+ - **What the dashboard shows.** The live view includes short previews of tool calls and responses, so you can see a loop. These stay in memory and are never written to disk.
86
+ - **Browser protection.** The dashboard only answers to `localhost` and `127.0.0.1`, which blocks DNS-rebinding attacks. Trip and reset also require a request from the dashboard itself.
87
+
88
+ To report a vulnerability, see [SECURITY.md](SECURITY.md).
89
+
90
+ ## Development
91
+
92
+ To run from source:
93
+
94
+ ```bash
95
+ git clone https://github.com/Loopcap/loopcap.git
96
+ cd loopcap
97
+ ```
98
+
99
+ ```bash
100
+ nvm use # optional: picks the Node version in .nvmrc
101
+ npm install # install dependencies
102
+ npm run typecheck # type-check src/ and test/
103
+ npm test # run unit tests
104
+ npm run build # build the CLI and dashboard into dist/
105
+ ```
106
+
107
+ `npm start` and `npm run demo` run straight from source. To release, bump the version in `package.json`, merge it, then push a matching tag (`git tag v0.1.1 && git push origin v0.1.1`); the release workflow publishes to npm with provenance and creates the GitHub release. The shared types for the proxy and dashboard live in [`src/types/events.ts`](src/types/events.ts). Work happens on short-lived branches that merge into `main` through pull requests.
108
+
109
+ ## License
110
+
111
+ [MIT](LICENSE)