Collector reference
The collector's CLI surface, file formats, environment and outputs. The complete operational
reference, including the security reasoning behind every rule, is apps/collector/README.md.
Commands
# Build (also builds packages/db)
pnpm --filter @env-sync-viewer/collector... build
# Collect. The default inventory is apps/collector/inventory.json
node apps/collector/dist/main.js [path/to/inventory.json]
# Same thing through turbo, as CI runs it. Args after `--` reach only the collect task
pnpm exec turbo run collect --filter=@env-sync-viewer/collector -- <path>
# Pre-flight: check an inventory against the allowlist, write the filtered inventory
pnpm --filter @env-sync-viewer/collector exec tsx scripts/preflight.ts [inventory.json] [inventory.allow.json]
# Fetch manifests: one Contents API call per repo (needs GH_TOKEN)
bash apps/collector/scripts/fetch-manifests.sh [repo ...]
# Tests (Docker for the Postgres-backed suite)
pnpm --filter @env-sync-viewer/collector test:unit
env-sync invocation
The collector depends on exactly one contract: env-sync diff --format json, schemaVersion: 1.
Per selector it runs, with the entry's manifestDir as the working directory:
env-sync diff --service <name> --env <env> --format json # one per listed service
env-sync diff --all --env <env> --format json # when `services` is omitted
Exit 0 means the document is trusted. Any other exit means stdout is ignored. For everything
else env-sync can do, see catesworks/env-sync (currently a private repo).
inventory.json
A JSON array. Each entry is one (manifest, env) pair that is expected to exist.
[
{ "manifestDir": "../../manifests/orders", "env": "prod", "services": ["api", "worker"] },
{ "manifestDir": "/srv/manifests/billing", "env": "prod" }
]
| Field | Required | Meaning |
|---|---|---|
manifestDir | yes | Directory holding secrets.manifest.yml. A relative path resolves against the inventory file's directory |
env | yes | The --env value. Non-empty, must not start with - |
services | no | One --service invocation per name. Omit for one --all invocation, only if every service is deployed to env |
platforms | output | Written only by the pre-flight. The pre-flight rejects an input that carries it, so a credential scope can't be forged |
inventory.allow.json
A JSON array of records, exactly these six keys, one per (repo, service):
{
"repo": "orders",
"service": "api",
"platforms": ["caprover"],
"captainDomain": "captain.example.com",
"source": "app-secrets/orders/api",
"appName": "orders-api"
}
repo is the basename of the entry's manifestDir. A duplicate repo/service is an error.
platforms may only name platforms with a credential rule, which today means caprover only.
Pre-flight
A service passes only if it exists in the manifest, its source matches the record exactly, it
has no unknown service-level fields, and every target passes, in this order:
dotenvtargets are always rejected.- The
platformmust have a credential rule (src/platform-rules.ts). - The
platformmust be in the record'splatforms. - No target field outside the platform's known set. For CapRover:
platform,captainDomain,appName,read_only,non_diffable. - The identity check: for CapRover,
captainDomainandappNameequal the record's.
The manifest is parsed with a verbatim copy of env-sync's own YAML parser, so both read the same text the same way.
| Output | Content |
|---|---|
$RUNNER_TEMP/inventory.filtered.json | one entry per kept selector, absolute manifestDir, plus platforms |
$RUNNER_TEMP/preflight.dropped | one dropped name per line (<repo>/<service> or <repo>/--all) |
| stdout | one ::error::pre-flight dropped ... per drop, then an N entries kept summary |
$GITHUB_OUTPUT | dropped=<N>, when that variable is set |
Without RUNNER_TEMP it writes to the OS temp directory. An --all entry is all-or-nothing:
every service in the manifest must pass or the entry is dropped.
Environment
The collector process reads:
| Variable | Purpose |
|---|---|
DATABASE_URL | login role that is a member of collector. Never passed to env-sync |
CI | when set, enables the exit-2 guards |
PATH | must find env-sync (also used by the probes) |
OP_SERVICE_ACCOUNT_TOKEN, ENV_SYNC_CONNECT_HOST/_TOKEN/_VAULTS | forwarded to every child |
CAPROVER_ADMIN_PASSWORD, CAPROVER_ALLOWED_DOMAINS | forwarded only to children scoped to caprover |
Each env-sync child gets an explicit environment. Nothing is inherited:
- Base floor:
PATH,LANG,LC_ALL,TZ(each only if set),OP_SERVICE_ACCOUNT_TOKEN,ENV_SYNC_CONNECT_HOST,ENV_SYNC_CONNECT_TOKEN,ENV_SYNC_CONNECT_VAULTS. - Platform credentials for the entry's
platformsonly. HOME,XDG_CONFIG_HOME,TMPDIR: a fresh, empty,0700temp directory, removed afterwards.ENV_SYNC_ALLOWED_PLATFORMS: the comma-joined scope, set last so nothing can override it. An unscoped entry (a local run that skipped the pre-flight) gets it empty, whichenv-synctreats as "allow nothing".- Never:
DATABASE_*,NODE_OPTIONS,GITHUB_*,RUNNER_*,CI,DEBUG,OP_CONNECT_*,AWS_*,ENV_SYNC_AWS_*,USER/USERNAME, or anything else unlisted.
Outputs
Everything lives in the env_sync schema.
| Table | One row per | Key columns |
|---|---|---|
collector_runs | env-sync invocation | id, started_at, completed_at, outcome, error_summary |
drift_snapshots | (run, service, env, target) | collector_run_id, service, env, target_platform, target_descriptor, diff_mode, status, target_error |
drift_snapshot_keys | key in a target snapshot | snapshot_id, key, key_status, expected_fingerprint, actual_fingerprint |
Constraints: outcome is success/partial/failed; diff_mode is fingerprint/presence;
status is ok/error; key_status is one of MATCH, DRIFT, MISSING_FROM_1PASSWORD,
PRESENCE_PRESENT, PRESENCE_MISSING, NON_DIFFABLE. Fingerprints are 12 lowercase hex
characters, or null for presence-mode keys.
Outcomes
| CLI result | outcome | Snapshot rows |
|---|---|---|
| exit 0, no service or target errors | success | one per target, one key row per key |
exit 0, some services[].error or target error | partial | same, with errors in error_summary/target_error |
non-zero exit, invalid JSON, or schemaVersion ≠ 1 | failed | none |
an ENV_SYNC_ALLOWED_PLATFORMS refusal anywhere in the output | failed | none. error_summary starts ENV_SYNC_ALLOWED_PLATFORMS guard refused: |
| exit 0 but the database rejects the document | failed | none (rolled back, then the failed run is written) |
dotenv targets are dropped before classification: a central collector cannot observe a file on
someone's laptop. Error strings are capped at 2000 characters. That cap is not redaction; the CLI
redacts before the collector ever sees the text.