@certalis/agent-smith 0.0.0-stage → 0.1.1

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,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 snipeship
4
+ Copyright (c) 2026 Certalis
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,337 @@
1
- # Temporary Holding Version
1
+ # agent-smith
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
+ **A proof-of-concept local proxy and provider pool for Claude Code and Codex.**
4
+
5
+ > [!WARNING]
6
+ > **This is a proof of concept for ideation, not a product.** It exists to
7
+ > explore an idea and start conversations.
8
+ >
9
+ > - **No warranty, no support, no stability.** It may change or disappear at any
10
+ > time.
11
+ > - **Subscription sign-ins are off by default.** Anthropic's and OpenAI's terms
12
+ > restrict using Claude or ChatGPT plan credentials through a tool like this:
13
+ > read [Subscription sign-ins and provider terms](#subscription-sign-ins-and-provider-terms)
14
+ > before enabling one. You alone are responsible for complying with your
15
+ > providers' terms.
16
+ > - Not affiliated with, endorsed by or sponsored by Anthropic or OpenAI.
17
+
18
+ Claude Code and Codex keep talking their own protocol. agent-smith sits on
19
+ localhost between them and the provider: it chooses a provider from the pool you
20
+ configure, then an account inside that provider, watches the quota each
21
+ provider reports, and fails over when one cannot serve.
22
+
23
+ ## How it works
24
+
25
+ - **A pool of providers per client protocol.** Claude Code speaks
26
+ `anthropic-messages`; Codex speaks `openai-responses`. Each protocol gets an
27
+ ordered list of providers.
28
+ - **Each provider is a built-in strategy** (`anthropic-api`, `openai-api`,
29
+ `claude-code`, `codex`). It knows how to authenticate, how to read its quota
30
+ signals, and how to choose between its own accounts.
31
+ - **Each provider holds its accounts**: API keys, or subscription sign-ins once
32
+ you enable them.
33
+
34
+ Nothing is translated between protocols: a provider only serves clients that
35
+ speak its protocol.
36
+
37
+ ## Install
38
+
39
+ You need [Bun](https://bun.sh) 1.2.8 or newer on your `PATH` and a macOS or Linux
40
+ shell.
41
+
42
+ ```bash
43
+ bun add -g @certalis/agent-smith # or: npm install -g @certalis/agent-smith
44
+ agent-smith
45
+ ```
46
+
47
+ Or run it once without installing: `bunx @certalis/agent-smith`. To work from
48
+ source, clone this repository, then run `bun install && bun run ccflare`.
49
+
50
+ A host that supervises agent-smith itself can start the server in its own Bun
51
+ process, without the dashboard and with a private Unix socket beside the TCP port:
52
+
53
+ ```js
54
+ import startServer from "@certalis/agent-smith/server";
55
+
56
+ startServer({
57
+ port: 8081,
58
+ withDashboard: false,
59
+ additionalUnixSocket: "/absolute/path/control.sock",
60
+ });
61
+ ```
62
+
63
+ ## Quick start: Claude Code with an Anthropic API key
64
+
65
+ 1. Create the config file (see [Configuration](#configuration)) with a pool for
66
+ Claude Code's protocol:
67
+
68
+ ```json
69
+ {
70
+ "provider_pools": {
71
+ "anthropic-messages": ["anthropic"]
72
+ }
73
+ }
74
+ ```
75
+
76
+ 2. Run `agent-smith`. The terminal screen, **Local Pool**, opens; keep it
77
+ running while you use the pool.
78
+ 3. Press `a`, name the account, and add your Anthropic API key. From a script:
79
+ `agent-smith --add-account work --provider anthropic`.
80
+ 4. Press `e` and confirm **Enable local client routing**. agent-smith writes small
81
+ wrappers in its own config directory and adds one marked `PATH` entry to your
82
+ shell profile; your real `claude` and `codex` programs are untouched.
83
+ 5. Open a **new terminal** and run `claude` as usual. Press `e` again to remove
84
+ the wrappers and the `PATH` entry.
85
+
86
+ Codex works the same way with an OpenAI API key and an `openai-responses` pool.
87
+
88
+ ## Configuration
89
+
90
+ The config file is JSON, read at startup from:
91
+
92
+ - `~/.config/ccflare/ccflare.json` (or `$XDG_CONFIG_HOME/ccflare/ccflare.json`)
93
+ on macOS and Linux,
94
+ - or the path in `ccflare_CONFIG_PATH`.
95
+
96
+ Restart agent-smith after changing `providers` or `provider_pools`.
97
+
98
+ | Key | What it does |
99
+ |---|---|
100
+ | `providers.<name>.enabled` | Turns a provider's routes on or off. By default `anthropic` and `openai` are on, and `claude-code` and `codex` are off. |
101
+ | `providers.<name>.strategy` | The built-in strategy: `anthropic-api`, `openai-api`, `claude-code` or `codex`. Required for a provider name you add yourself. |
102
+ | `providers.<name>.base_url` | The upstream URL, for an endpoint compatible with one of the strategies. |
103
+ | `providers.<name>.models` | The models a provider serves, as `"client model": "provider model"`. A trailing `*` matches a prefix. Without it, the provider serves every model name unchanged. |
104
+ | `provider_pools.<protocol>` | The ordered providers for `anthropic-messages` or `openai-responses`. Clients reach it at `/v1/pool/<protocol>/*`, and the local wrappers use it automatically. |
105
+ | `team_routing` | Which subscription accounts may share a pool, and their usage caps. See the [configuration guide](docs/configuration.md#team-routing). |
106
+
107
+ Every key, the environment variables and the HTTP API are in the
108
+ [configuration guide](docs/configuration.md).
109
+
110
+ ### Examples
111
+
112
+ Each example is a complete config file, also in [`examples/config/`](examples/config/).
113
+
114
+ **Claude Code with an Anthropic API key**
115
+ ([`anthropic-api-key.json`](examples/config/anthropic-api-key.json)):
116
+
117
+ ```json
118
+ {
119
+ "provider_pools": {
120
+ "anthropic-messages": ["anthropic"]
121
+ }
122
+ }
123
+ ```
124
+
125
+ **Codex with an OpenAI API key**
126
+ ([`openai-api-key.json`](examples/config/openai-api-key.json)):
127
+
128
+ ```json
129
+ {
130
+ "provider_pools": {
131
+ "openai-responses": ["openai"]
132
+ }
133
+ }
134
+ ```
135
+
136
+ **An Anthropic-compatible endpoint as fallback**
137
+ ([`compatible-endpoint-fallback.json`](examples/config/compatible-endpoint-fallback.json)).
138
+ Requests go to Anthropic first. When Anthropic cannot serve, Sonnet requests move
139
+ to `acme` and are sent as `acme-large`. `acme` serves no other model.
140
+
141
+ ```json
142
+ {
143
+ "providers": {
144
+ "acme": {
145
+ "enabled": true,
146
+ "strategy": "anthropic-api",
147
+ "base_url": "https://api.acme.example",
148
+ "models": { "claude-sonnet-*": "acme-large" }
149
+ }
150
+ },
151
+ "provider_pools": {
152
+ "anthropic-messages": ["anthropic", "acme"]
153
+ }
154
+ }
155
+ ```
156
+
157
+ The Claude Code and Codex subscription examples are in
158
+ [Subscription sign-ins and provider terms](#subscription-sign-ins-and-provider-terms).
159
+
160
+ ## How usage is watched
161
+
162
+ Each provider reads its own quota signals from the responses it gets:
163
+
164
+ - **Subscription providers** read the 5-hour and weekly windows.
165
+ - **API-key providers** read the provider's rate-limit headers and its 429
166
+ answers.
167
+
168
+ The Local Pool screen and the dashboard show the latest values. A new account
169
+ shows `limits not observed yet` until a response carries quota headers;
170
+ agent-smith never invents a zero limit. Several API keys from one organisation
171
+ share that organisation's limits, so adding them adds no capacity.
172
+
173
+ ## How failover works
174
+
175
+ - **Inside a provider**, an account at its quota threshold is skipped. A
176
+ server error before any output may take one hop to another eligible account.
177
+ - **Across providers**, a pool moves to its next provider only when the current
178
+ one has no eligible account, or has no eligible account left for that one
179
+ server-error hop. It moves at most once per request.
180
+ - A per-minute rate limit never moves a request to another provider, and
181
+ nothing moves once output has started reaching the client.
182
+ - A conversation stays on its account while that account is eligible. Moving
183
+ provider loses the prompt cache and can change model behaviour and cost.
184
+ - If no provider in the pool serves the requested model, agent-smith returns
185
+ `400` naming `provider_pools.<protocol>`.
186
+ - Direct routes, `/v1/<provider>/*`, never use a pool.
187
+
188
+ Details: [load balancing](docs/load-balancing.md).
189
+
190
+ ## Subscription sign-ins and provider terms
191
+
192
+ > [!CAUTION]
193
+ > `claude-code` signs in to a Claude subscription and `codex` signs in to a
194
+ > ChatGPT account. agent-smith then **stores the resulting tokens and routes
195
+ > requests through them**. Both are **disabled by default**. The provider terms
196
+ > below restrict this use. agent-smith makes **no claim that it is allowed**,
197
+ > and the two configs further down are **examples only**, not recommendations.
198
+ > If you enable either sign-in, that is your decision and your responsibility.
199
+
200
+ These are quoted word for word, as read on **30–31 October 2026**. Check the
201
+ current versions before acting on them.
202
+
203
+ **Anthropic, [Claude Code legal and compliance](https://code.claude.com/docs/en/legal-and-compliance),
204
+ "Authentication and credential use":**
205
+
206
+ > OAuth authentication is intended exclusively for purchasers of Claude Free,
207
+ > Pro, Max, Ultra, Team, and Enterprise subscription plans and is designed to
208
+ > support ordinary use of Claude Code and other native Anthropic applications.
209
+
210
+ > Anthropic does not permit third-party developers to offer Claude.ai login into
211
+ > their own applications, or to route requests through Free, Pro, Max, or Ultra
212
+ > plan credentials on behalf of their users. Moreover, developers may not
213
+ > collect, store, or intermediate Claude.ai credentials or session tokens —
214
+ > sign-in to a Claude account must complete through Anthropic’s own flow.
215
+
216
+ > Anthropic reserves the right to take measures to enforce these restrictions
217
+ > and may do so without prior notice.
218
+
219
+ **Anthropic, [Consumer Terms of Service](https://www.anthropic.com/legal/consumer-terms)
220
+ (effective 8 October 2025):**
221
+
222
+ > You may not share your Account login information, Anthropic API key, or
223
+ > Account credentials with anyone else or make your Account available to anyone
224
+ > else.
225
+
226
+ > You may not access or use, or help another person to access or use, our
227
+ > Services in the following ways: […] Except when you are accessing our
228
+ > Services via an Anthropic API Key or where we otherwise explicitly permit it,
229
+ > to access the Services through automated or non-human means, whether through a
230
+ > bot, script, or otherwise.
231
+
232
+ **OpenAI, [Terms of Use](https://openai.com/policies/terms-of-use/)
233
+ (effective 1 January 2026):**
234
+
235
+ > You may not share your account credentials or make your account available to
236
+ > anyone else and are responsible for all activities that occur under your
237
+ > account.
238
+
239
+ > What you cannot do. You may not use our Services for any illegal, harmful, or
240
+ > abusive activity. For example, you may not: […] Automatically or
241
+ > programmatically extract data or Output (defined below). […] Interfere with or
242
+ > disrupt our Services, including circumvent any rate limits or restrictions or
243
+ > bypass any protective measures or safety mitigations we put on our Services.
244
+
245
+ API keys are covered by each provider's business terms and usage policies:
246
+ Anthropic's [Commercial Terms](https://www.anthropic.com/legal/commercial-terms)
247
+ and [Usage Policy](https://www.anthropic.com/legal/aup), and OpenAI's
248
+ [Services Agreement](https://openai.com/policies/services-agreement/) and
249
+ [Usage Policies](https://openai.com/policies/usage-policies/).
250
+
251
+ ### Example only: Claude Code subscription
252
+
253
+ > [!WARNING]
254
+ > **Example only.** This config shows the shape of the setting and nothing more.
255
+ > Anthropic's terms quoted above do not permit third-party tools to store or
256
+ > route requests through Claude plan credentials. Do not use it unless you have
257
+ > read those terms and accept the consequences.
258
+
259
+ [`example-only-claude-code-subscription.json`](examples/config/example-only-claude-code-subscription.json):
260
+
261
+ ```json
262
+ {
263
+ "providers": {
264
+ "claude-code": { "enabled": true }
265
+ }
266
+ }
267
+ ```
268
+
269
+ ### Example only: Codex subscription
270
+
271
+ > [!WARNING]
272
+ > **Example only.** This config shows the shape of the setting and nothing more.
273
+ > OpenAI's terms quoted above forbid making an account available to anyone else
274
+ > and circumventing rate limits. Do not use it unless you have read those terms
275
+ > and accept the consequences.
276
+
277
+ [`example-only-codex-subscription.json`](examples/config/example-only-codex-subscription.json):
278
+
279
+ ```json
280
+ {
281
+ "providers": {
282
+ "codex": { "enabled": true }
283
+ }
284
+ }
285
+ ```
286
+
287
+ Both examples enable a single sign-in. Putting several sign-ins in one pool
288
+ with `team_routing.allowlisted_account_uuids` is the use the quoted terms most
289
+ clearly forbid.
290
+
291
+ ## Advanced use
292
+
293
+ The server also exposes the routes directly:
294
+
295
+ - `http://localhost:8080/v1/<provider>/*`: one enabled provider, no pool.
296
+ - `http://localhost:8080/v1/pool/<protocol>/*`: a configured pool.
297
+
298
+ Run only the server with `agent-smith --serve`. Management writes need an
299
+ explicit `CF_ADMIN_KEY` sent as the `x-api-key` header. Read the
300
+ [configuration guide](docs/configuration.md) and the
301
+ [HTTP API reference](docs/api-http.md) before exposing anything beyond
302
+ localhost.
303
+
304
+ ## Development
305
+
306
+ ```bash
307
+ bun install
308
+ bun run tui # Start the terminal screen from source
309
+ bun run server # Start only the local proxy and dashboard
310
+ bun run verify # Run tests, type checks, and linting
311
+ ```
312
+
313
+ More detail lives in [docs/](docs/): [architecture](docs/architecture.md),
314
+ [configuration](docs/configuration.md), [provider behaviour](docs/providers.md)
315
+ and [load balancing](docs/load-balancing.md).
316
+
317
+ ## Credits
318
+
319
+ agent-smith is a fork of [ccflare](https://github.com/snipeship/ccflare) by
320
+ snipeship. Routing behaviour is checked against
321
+ [TeamClaude](https://github.com/KarpelesLab/teamclaude) as reference data. Both
322
+ are MIT licensed.
323
+
324
+ ## Disclaimer
325
+
326
+ agent-smith is an experimental proof of concept for ideation. It is not intended
327
+ for production use or for anyone else's accounts. It is not affiliated with,
328
+ endorsed by or sponsored by Anthropic or OpenAI. Claude, Claude Code, Codex,
329
+ ChatGPT and OpenAI are trademarks of their owners. Each provider's terms and
330
+ usage policies decide what you may do with your accounts, and checking them is
331
+ your job. The authors accept no liability for account actions, costs or other
332
+ consequences of running it.
333
+
334
+ ## License
335
+
336
+ MIT, see [LICENSE](LICENSE). The software is provided "as is", without warranty
337
+ of any kind.