trouteai
AGENTS.md36 starsChanged 19 days agoMITView on GitHub
TRouteAI is a self-hosted AI router. A user adds AI providers in a web dashboard, creates API keys, and points any client at one OpenAI- and Anthropic-compatible endpoint (<host>/v1). A combo is one model name that tries several provider models with a routing strategy and falls back on errors and usage limits. It runs as one Node.js app on one port, with SQLite, and depends on no external TRouteAI service. Product priorities, in this order: secure, light (near-zero CPU and…
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,196 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository5 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- add-dashboard-pageSkill
- add-migrationSkill
- add-providerSkill
- verifySkill
The file
We split this AGENTS.md into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 75
Do not add or refer to these unless asked: an MCP server, agent-to-agent protocols, cloud agents, a plugin marketplace, gamification, …
- Very specific: line 91
Every user-visible text goes in src/i18n/messages/en.json
- Very specific: line 96
Never commit secrets. They come from .env or DATA_DIR/server.env (see .env.example)
- Distinctive: line 127
Database migrations only add: Never drop or rename a table or column: during an update the old and the new version share one database file, …
- Distinctive: line 135
An answer that fails inside a stream stays an error: Never turn it into a normal finish: a coding agent would end its turn on half an …
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
TRouteAI: guide for AI coding agents
TRouteAI is a self-hosted AI router. A user adds AI providers in a web dashboard, creates API
keys, and points any client at one OpenAI- and Anthropic-compatible endpoint (<host>/v1). A
combo is one model name that tries several provider models with a routing strategy and falls
back on errors and usage limits. It runs as one Node.js app on one port, with SQLite, and depends
on no external TRouteAI service.
Product priorities, in this order: secure, light (near-zero CPU and memory when idle), very easy for non-technical users, fully white-label.
Stack
- Next.js 16 (App Router, Turbopack), React 19, TypeScript 6 in
src/; the routing engine is the workspace package@trouteai/open-sseinopen-sse/ - Node.js 26 recommended; 22.22.2+ and 24+ supported (
enginesinpackage.json); ES modules - SQLite through better-sqlite3, then the built-in
node:sqlite, then sql.js (src/lib/db/adapters/driverFactory.ts) - Tailwind CSS v4, next-intl (English only:
config/i18n.json), Zod v4 for input validation
Commands
| Command | What it does |
npm install | Install; creates or completes .env from .env.example |
npm run dev | Dev server, port 20017 (data folder ~/.trouteai unless set) |
npm run build | Production build into .build/next (1 to 3 minutes) |
npm start / node app.cjs | Production server (app.cjs is the file hosting panels start) |
npm run lint | ESLint; the baseline is config/quality/eslint-suppressions.json |
npm run typecheck:baseline | tsc; fails only when the error count rises above the baseline |
npm test | Smoke test and offline checks against the build |
npm run test:all | Every offline suite |
npm pack | Release build (prepack) and the npm tarball |
Verify every change
npm run lint.npm run build, thennpm run typecheck:baseline(it reads type files the build generates). The build itself ignores type errors, so this step is the only type gate. Never add a type error; the old ones are a counted baseline, not a licence.npm test; for routing, context size or usage limits alsonpm run test:all.- Say what you ran and what it printed, and what you could not test.
Tests and manual runs always use a throwaway data folder and a spare port
(DATA_DIR=$(mktemp -d) PORT=20018 …). Never run against ~/.trouteai: it can hold a person's
real provider credentials, and server.env in it is the key that decrypts them. Never call
routes that read credential files from the host (for example /api/oauth/kiro/auto-import) in a
test. Details: tests/README.md.
Layout
src/app/(dashboard)/dashboard/*: dashboard pages. Sidebar entries are insrc/shared/constants/sidebarVisibility/sections.ts(ids intypes.ts); the default simple menu is theminimalpreset insrc/shared/constants/sidebarVisibility.tssrc/app/api/v1/*: client API (chat/completions,messages,responses,models, embeddings, images, audio)./v1/*is rewritten to/api/v1/*innext.config.mjssrc/app/api/*: management API for the dashboard (providers, keys, combos, settings, logs)src/proxy.ts→src/server/authz/pipeline.ts: authentication for every requestsrc/instrumentation-node.ts: boot sequence (database, secrets, schedulers)src/server/ws/liveServer.ts: live dashboard WebSocket at/live-wson the main portopen-sse/handlers/chatCore.ts: request pipeline.open-sse/services/combo.ts: combo routing.open-sse/executors/: per-provider upstream calls.open-sse/translator/: format conversion between OpenAI, Anthropic and provider formatssrc/shared/constants/providers/: provider catalog, validated with Zod at load.open-sse/config/providers/registry/<id>/: per-provider endpoints and modelssrc/lib/db/*: SQLite modules; migrations insrc/lib/db/migrations/.src/lib/localDb.tsis a re-export layer onlybin/trouteai.mjs: thetrouteaicommand.scripts/build/,scripts/dev/: build and starttests/: offline test suite (fake providers, no account, no network)
How to add a provider, a database change or a dashboard page: CONTRIBUTING.md.
Not part of TRouteAI
Do not add or refer to these unless asked: an MCP server, agent-to-agent protocols, cloud
agents, a plugin marketplace, gamification, evals, webhooks UI, tunnels, a traffic inspector, a
desktop app, a full terminal UI beyond bin/trouteai.mjs, a docs site, cloud sync, an
in-dashboard updater, sponsor or affiliate content, and telemetry of any kind.
Prompt compression and plugin hooks exist inside the request pipeline but are off by default and
have no dashboard page. Of the old skills code only the built-in web search and web fetch
interception in src/lib/skills remains.
Code style
- Prettier: 2 spaces, semicolons, double quotes, 100 columns, es5 trailing commas
- Imports: external, then internal (
@/,@trouteai/open-sse), then relative. Import database code from the specificsrc/lib/db/<module>.ts, not fromlocalDb.ts - Path aliases:
@/*→src/*,@trouteai/open-sse/*→open-sse/* - Environment variables of this app use the
TROUTEAI_prefix - Every user-visible text goes in
src/i18n/messages/en.json - Comments explain why, in plain words. No issue numbers, dates or names in comments
Security rules
- Never commit secrets. They come from
.envorDATA_DIR/server.env(see.env.example) - Validate every API input with Zod; no SQL in routes (use
src/lib/db/modules) - Error responses use
buildErrorBody()/sanitizeErrorMessage()fromopen-sse/utils/error.ts; never return a rawerr.messageorerr.stack - Public OAuth client identifiers of provider CLIs are read with
resolvePublicCred()fromopen-sse/utils/publicCreds.ts, never written as string literals exec()/spawn()with runtime values: pass them throughenv, never build a command stringREQUIRE_API_KEYdefaults to true; never ship an open/v1- "Is this request from the machine itself?" is answered only by
isTrustedLoopbackRequest()(src/shared/utils/apiAuth.ts, a TCP-peer stamp), never by the Host header - Outbound requests on a user's behalf go through
safeOutboundFetch(public addresses only) - Pages get a per-request nonce content security policy from
src/proxy.ts; both policies are built insrc/server/security/csp.mjs. An inline<script>needsnonce={readCspNonce(await headers())}. Never add a third-party script origin - The app never runs without an admin password:
ensureInitialAdminPassword()insrc/instrumentation-node.tscreates a random one on the first start
Things that break easily
- Masked identifiers.
open-sse/utils/publicCreds.tsstores values XOR-masked with a fixed mask. Changing the mask, or a project-wide search-and-replace of the brand name, corrupts every one of them. - Runtime dependencies are pinned exactly. The build output only works with the exact
nextversion that built it. Only what the server needs at runtime is independencies; everything else is bundled at build time and lives indevDependencies. - Server-external packages. A package added to
serverExternalPackagesinnext.config.mjsmust also be independencies; then rebuild and check.build/next/trouteai-externals.json(scripts/build/buildExternals.mjsrecreates the links npm does not pack). NEXT_PUBLIC_*is compiled in at build time and is empty in the npm package. At runtime the server readsTROUTEAI_PUBLIC_BASE_URL, whichscripts/build/bootstrap-env.mjsfills fromNEXT_PUBLIC_BASE_URL.- Database migrations only add. Never drop or rename a table or column: during an update the old and the new version share one database file, and a rollback runs old code on the new schema.
- Startup chain.
bin/trouteai.mjs(orapp.cjs/npm start) →scripts/dev/run-next.mjs→scripts/build/bootstrap-env.mjs. Change one, check all three ways of starting. - The combo test runs each step in-process (
src/app/api/combos/test/route.ts); calling/v1over HTTP from inside the app answers 401 because an API key is required. - Never delete
.buildwhile a dev server may be running, and do not run clean-up commands next to a build or a type check. - An answer that fails inside a stream stays an error. Never turn it into a normal finish: a coding agent would end its turn on half an answer.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

