@arki/env for agents
For @arki/[email protected] · source docs/agent-guide.md
The long form of llms.txt. When they disagree, src/index.ts wins.
The model
defineEnv({ server, client, shared, runtimeEnv })returns a typed object. It validates on the first read.- A schema is any Standard Schema. Each value is typed as the schema's output, so defaults and coercions apply.
contractsholds ready-made shapes: ports, URLs, comma lists and JSON.secret(schema)makes aRedactedvalue. It prints as[redacted].reveal(value)returns the raw string.@arki/env/dotturns the same options into a Dot plugin that validates at boot.- The package reads no environment at import and does not need
process.
Task map
Define the environment of an app
- Create one
env.ts. - Declare each variable with a contract or your own schema.
- Import
envwhere you need a value.
import { contracts } from '@arki/env/contracts';
import { defineEnv } from '@arki/env/core';
export const env = defineEnv({
server: {
PORT: contracts.port(3000),
DATABASE_URL: contracts.databaseUrl(),
},
});Keep a secret out of logs
import { z } from 'zod';
import { defineEnv, reveal, secret } from '@arki/env/core';
const env = defineEnv({ server: { API_KEY: secret(z.string().min(1)) } });
export const apiKey = (): string => reveal(env.API_KEY);Build a Docker image without secrets
Set SKIP_ENV_VALIDATION=1 in the build stage only. Do not set it in the run stage.
Validate at boot in a Dot app
import { z } from 'zod';
import { defineApp } from '@arki/dot';
import { env } from '@arki/env/dot';
const app = await defineApp('my-app')
.use(env({ schema: { PORT: z.coerce.number().default(3000) } }))
.build();Rules that bite
SKIP_ENV_VALIDATION=truedoes not skip. Only exactly1does.CI,lintandNODE_ENVnever skip validation.- With validation skipped, schemas do not run. Values are raw strings.
- Do not call
.parseon asecret()result. Use['~standard'].validate(value). - Pass
runtimeEnvon engines with noprocess. - Client keys need the
clientPrefix.
Errors
| Code or error | Meaning | What to do |
|---|---|---|
Error from defineEnv | A variable failed its schema on first read. | Read the path: message lines. Fix the variables. |
ARKI_ENV_PLUGIN_E001 | The Dot plugin found a bad env at boot. | Set the listed variables before booting. Do not skip validation. |
Verify
bun run test
bun run test:docs
dot explain --json | jq '.data.services' # in a Dot app: env is listed, nothing is validated
dot doctor --json | jq '.data' # boots the app: a bad env fails here with ARKI_ENV_PLUGIN_E001