Coding Style
TypeScript, ESLint, and Prettier rules enforced in Anvio's CI, pulled directly from the repo's config files.
5 min read
Anvio enforces style mechanically — pnpm lint, pnpm typecheck, and pnpm format:check all run in CI (see Pull Requests). This page documents the actual rules from eslint.config.js, prettier.config.js, and tsconfig.base.json, not general conventions.
ESLint
eslint.config.js is a flat config built on typescript-eslint:
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ['**/dist/**', '**/node_modules/**', '**/.turbo/**'],
},
{
rules: {
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-explicit-any': 'warn',
},
},
);Key points:
- Base rule sets:
eslint.configs.recommended+typescript-eslint'srecommendedconfig. dist/,node_modules/, and.turbo/are excluded from linting entirely.@typescript-eslint/no-unused-varsis an error, but unused function arguments prefixed with_are explicitly allowed (argsIgnorePattern: '^_') — use_reqor_unusedfor a parameter you must declare but don't use.@typescript-eslint/no-explicit-anyis a warning, not an error.anyis discouraged but won't fail CI on its own — preferunknownwith narrowing, or a proper type, but don't block a PR solely to eliminate a warning-levelanyif the alternative is a larger unrelated refactor.
Prettier
prettier.config.js:
export default {
semi: true,
singleQuote: true,
trailingComma: 'all',
printWidth: 100,
tabWidth: 2,
};| Rule | Value |
|---|---|
| Semicolons | Always (semi: true) |
| Quotes | Single quotes (singleQuote: true) |
| Trailing commas | Everywhere valid, including function args (trailingComma: 'all') |
| Line width | 100 characters |
| Indentation | 2 spaces |
Run pnpm format to apply these automatically, or pnpm format:check to verify without writing (this is what CI would want you to have already run — CI itself runs lint/typecheck/test/build, so a Prettier drift shows up as an ESLint/format diff in review, not a separate CI job).
TypeScript
tsconfig.base.json is the shared base every package and app extends:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"composite": true,
"incremental": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"exclude": ["node_modules", "dist"]
}Notable settings:
strict: true— full strict mode (strictNullChecks,noImplicitAny, etc.) across the whole monorepo.module/moduleResolution: NodeNext— packages use native ESM Node resolution; import paths must be extension-correct in emitted output (.jsin relative imports from.tssource, per NodeNext convention). The rootpackage.jsonalso sets"type": "module".noUnusedLocals/noUnusedParameters— enforced at the compiler level in addition to ESLint'sno-unused-vars, so an unused local variable failspnpm typecheckeven if ESLint were disabled.composite: true+declaration/declarationMap— packages build as TypeScript project references, which is whypnpm build(Turborepo) must resolveapps → platform → packages → corein order rather than compiling everything independently.target: ES2022— modern syntax (top-level await, class fields, etc.) is fine to use.
pnpm typecheck runs turbo run typecheck, which is effectively tsc --noEmit per package against this base config.
The dependency rule: apps → platform → packages → core
Anvio's monorepo has a strict, one-directional dependency graph:
apps/ (cli, api, worker, gateway, desktop)
↓
@anvio/platform (composition factory — createPlatform())
↓
packages/* (agents, tools, models, memory, channels, runtimes, harness, …)
↓
@anvio/core (Zod schemas, ports, shared types — no dependencies on anything above)In practice:
@anvio/coredefines schemas and ports (interfaces) only. It must not import from any other Anvio package.- Domain packages (
@anvio/agents,@anvio/tools,@anvio/models,@anvio/memory,@anvio/channels,@anvio/runtimes,@anvio/harness, and the ~30 others underpackages/) depend on@anvio/corefor types/ports but implement concrete behavior behind those ports. @anvio/platformis the composition root —createPlatform()wires concrete providers into ports based onworkspace/anvio.yaml. This is the only place that should know about all the packages at once.apps/*(CLI, API, worker, gateway) are thin entry points. They call into@anvio/platform; they should not contain domain logic directly, and should not reach pastplatforminto individual packages unless there's a good reason (e.g. a CLI subcommand that needs a package-specific type).
When adding a feature, put the port/schema in @anvio/core, the implementation in the relevant packages/* package, and the wiring in @anvio/platform. Avoid importing "sideways" between unrelated packages — go through core's ports instead so providers stay swappable (this is what makes storage, memory, auth, and MCP integrations pluggable).
Naming conventions observed in the codebase
- Packages are scoped
@anvio/<name>(e.g.@anvio/core,@anvio/platform,@anvio/tools), matching the directory underpackages/<name>. - CLI commands are
anvio <noun> <verb>(anvio soul list,anvio goal create,anvio runtime test), grouped by subsystem. - Gateway tool names are namespaced with a double underscore:
anvio_tools__web_fetch,anvio_channel__reply,anvio_mcp__{server}__{tool}. - Config files are YAML for infrastructure (
anvio.yaml,tools/gateway.yaml,providers/routing.yaml,mcp/servers.yaml) and Markdown with frontmatter for anything agent-authored (agents/*.md,personas/*.md,souls/*/SOUL.md,workflows/*.md) — see the file-first principle in Overview. - Environment variables are
ANVIO_*for platform-level config (ANVIO_WORKSPACE,ANVIO_CONNECTION_ENCRYPTION_KEY) and<VENDOR>_API_KEY/<VENDOR>_TOKENfor provider credentials (ANTHROPIC_API_KEY,CLAUDE_CODE_OAUTH_TOKEN).
TODO: No standalone style guide document (e.g. a CONTRIBUTING-style naming reference) exists in
docs/beyond what's inferable from the config files and directory structure above — if the team formalizes one, link it here instead of inferring from source.
Last updated on