AGENTS.md@packages/config · git:20260908.c351bb0 · 2026-09-08 · sha256 5027eb51d9ba3147

AGENTS.md@packages/config git:20260908.c351bb0A

Immutable. This exact content is served forever at /api/v1/blob/5027eb51d9ba3147.

# config

## Purpose

Typed environment parsing and the managed-sweeps flag schema. `loadConfig()` and
`saveConfigPatch()` live in `packages/canonry/src/config.ts`; `loadConfig()`
validates only `dashboard.managedSweeps` with this package's scalar schema.

## Key Files

| File | Role |
|------|------|
| `src/index.ts` | `dashboardManagedSweepsSchema`, `getPlatformEnv()`, `getBootstrapEnv()` |

## Patterns

- **Config source priority**: Environment variables override `config.yaml` values.
- **`loadConfig()`**: Loads config for CLI commands (via `createApiClient()`) and the server. Preserve legacy dashboard fields and their key order; never replace the block with schema parse output. An invalid `managedSweeps` raises a path-qualified `CliError` (exit 1). Missing or blank values leave the opt-in unset.
- **`saveConfigPatch()`**: Merges partial updates into `~/.canonry/config.yaml`.
- **Base path**: `CANONRY_BASE_PATH` env var and `basePath` in config.yaml are merged into `apiUrl`.

## Common Mistakes

- **Reading env vars directly instead of using `loadConfig()`** — the config module handles validation and defaults.
- **Storing secrets in the database** — credentials belong in `~/.canonry/config.yaml`.

## See Also

- `packages/contracts/src/config-schema.ts` — Zod schemas for config validation
- `packages/canonry/src/client.ts` — `createApiClient()` uses `loadConfig()`