Coach: the Codex provider, and a credential that stays out of your backups

The Codex CLI adapter, its runtime and sandbox in the coach image only, and the
one placement decision this PR exists to get right.

Codex keeps a refreshable sign-in cache of its own rather than taking a token on
the environment, so it needs somewhere durable to write. That is ./coach-auth —
a sibling of ./data, never a folder inside it, mounted separately, owned by
`coach`, mode 0700.

The placement is the point. docs/SELF_HOSTING §5 tells owners to back up with
`tar czf … data/`, so anything under ./data lands in every archive people are
instructed to produce. Workout history belongs there; a live refresh token does
not — it keeps working after that archive is copied to a laptop or a cloud
drive. Keeping the cache outside ./data is what lets the backup instructions
stay true about what they capture, and §5 now says so explicitly rather than
leaving the reader to find out.

I got to define this rather than fix it: no Codex path was ever committed here,
so the nested layout the fork had never reached this repo. A test asserts the
sibling relationship directly, because "outside ./data" is the kind of invariant
a later refactor breaks by tidying.

bubblewrap and the Codex CLI are added in the coach target only — bubblewrap is
a Codex requirement, so an owner who never opted in carries neither. The image
job now asserts both directions: present and runnable in the coach image
(codex-cli 0.147.0, bubblewrap 0.11.2, /coach-auth as coach:0700), and absent
from the default one.

Codex is usable through the existing connect route with an API key, which needs
no new surface. Its ChatGPT device-code sign-in is not in this PR — see the PR
description for what that still needs.

api 73/73, frontend 404/404, both image targets built and inspected, 11 locales
in sync at 767, library in sync at 1324.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
AlexandClaude Opus 5 committed 2026-08-07 07:28:16 +01:00
1 parent 64fd67cfa8
commit ef61df50f2
9 files changed
+147 -2

No files matched your search

+22
View File
@@ -27,6 +27,17 @@ import path from 'node:path';
const DATA = process.env.DATA_DIR || '/data';
const FILE = path.join(DATA, 'coach.json');
/* Where a provider runtime that manages its own credential cache is allowed to keep it.
*
* A sibling of ./data, never inside it, and that placement is the whole point. docs/SELF_HOSTING
* tells people to back up with `tar czf … data/`; anything under ./data therefore ends up in
* every backup archive an owner is told to make. A refresh token is not workout history — it is
* a live credential that keeps working after the archive is copied to a laptop or a cloud drive.
*
* So the runtime gets its own mount, and the backup instructions stay true rather than being
* quietly wrong about what they capture. */
export const CREDENTIAL_HOME = process.env.COACH_CREDENTIAL_DIR || '/coach-auth';
export const COACH_DISABLED = /^(1|true|yes|on)$/i.test(process.env.COACH_DISABLED || '');
// Providers this build can drive. `runtime` is what the adapter runs. Adding one is an adapter
@@ -42,6 +53,13 @@ export const PROVIDERS = {
claude: {
label: 'Claude (Anthropic)', runtime: 'Claude Agent SDK',
apiKeyEnv: 'ANTHROPIC_API_KEY', oauthEnv: 'CLAUDE_CODE_OAUTH_TOKEN', setupToken: true
},
// Codex keeps a refreshable login cache in $CODEX_HOME rather than taking a token on the
// environment, so it is the one provider that needs somewhere durable to write. That
// somewhere is CREDENTIAL_HOME — outside ./data, so `tar czf … data/` cannot capture it.
codex: {
label: 'Codex (OpenAI)', runtime: 'Codex CLI',
apiKeyEnv: 'CODEX_API_KEY', oauthEnv: null, credentialHomeEnv: 'CODEX_HOME'
}
};
@@ -233,6 +251,10 @@ export function jobEnv(jobDir, resolved) {
: resolved.type === 'apikey' ? meta.apiKeyEnv : null;
if (name) env[name] = auth.token;
}
// A provider whose runtime keeps its own credential cache needs a home that survives the job,
// because HOME is a temp dir that dies with it. It is deliberately NOT under ./data — see
// CREDENTIAL_HOME — so the documented backup of ./data cannot pick up a live refresh token.
if (meta.credentialHomeEnv) env[meta.credentialHomeEnv] = CREDENTIAL_HOME;
return env;
}