Coach: the Claude provider, and an AI runtime you only carry if you ask
The Agent SDK adapter, its dependency, and the packaging that keeps both out of the image an owner gets when they never wanted the Coach. api/Dockerfile builds two targets. The default one runs `npm ci --omit=optional` and ships no AI runtime at all (~158 MB); `--target coach` drops that flag and adds @anthropic-ai/claude-agent-sdk (~455 MB). The SDK's runtime ships as a per-platform package, so on this Alpine base the lockfile resolves the musl build — the kind of thing that only fails on somebody else's machine, which is why the new api-image CI job builds *and runs* both targets rather than merely building them. Both targets now create the unprivileged `coach` user. That is not a Claude detail: canDropPrivileges() fails closed, so without it every job is refused — including the fixture provider that exists so the loop can be walked before an account is connected. The shipped image could not run one. The adapter imports the SDK lazily, so an absent runtime stays an ordinary reportable state rather than a boot crash: check() says so, isConnected() goes false, and /api/config carries no coach key. Four SDK options are what make this safe next to ./data — tools: [] (no Read, no Bash, no Grep), settingSources: [], skills: [], strictMcpConfig. They are one frozen exported object, asserted by value, so re-enabling one is a red build rather than a quiet capability grant. Verified against the SDK's own type definitions rather than from memory. Two things the fork's draft had wrong: SDKResultError carries no `errors` field, so `message.errors?.join()` was dead code and the failure reason now comes from `subtype` and `stop_reason`; and the client-app version string was hardcoded at 1.2.3 two releases after it stopped being true, so it is read from package.json. The credential connect/disconnect routes land here as promised in 2/6 — they serve a credential, and until this PR there was no provider that had one. authMode and the per-profile pair still wait for the side that consumes them. api 72/72 on macOS and on Linux as uid 65534 with the SDK absent; both image targets built and run; library in sync at 1324. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2c76da270b
commit
49be4e0626
12 files changed
+1933
-16
No files matched your search
@@ -0,0 +1,52 @@
|
||||
/* The provider adapters, and the four options that make the Claude one safe.
|
||||
*
|
||||
* These assertions are deliberately about the object the adapter passes to the SDK rather than
|
||||
* about observed model behaviour: the point is that re-enabling a tool is a red build, and a
|
||||
* test that needed a real account to run would never guard anything in CI.
|
||||
*/
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { tempData } from './helpers.mjs';
|
||||
|
||||
tempData();
|
||||
const { adapterFor, default: ADAPTERS } = await import('../coach/adapters/index.js');
|
||||
const { LOCKDOWN } = await import('../coach/adapters/claude.js');
|
||||
const cfg = await import('../coach/config.js');
|
||||
|
||||
test('every provider the config offers has an adapter, and vice versa', () => {
|
||||
assert.deepEqual(Object.keys(ADAPTERS).sort(), Object.keys(cfg.PROVIDERS).sort());
|
||||
for (const id of Object.keys(cfg.PROVIDERS)) assert.ok(adapterFor(id), `no adapter for "${id}"`);
|
||||
assert.equal(adapterFor('not-a-provider'), null);
|
||||
});
|
||||
|
||||
test('the Claude adapter is locked out of every tool the SDK could give it', () => {
|
||||
// `tools: []` is the SDK's documented "disable all built-in tools" — no Read, no Bash, no
|
||||
// Grep — and the other three stop anything on the host widening that afterwards. If one of
|
||||
// these ever has to change, it should be a decision with a diff, not a default that drifted.
|
||||
assert.deepEqual(LOCKDOWN.tools, [], 'no built-in tools');
|
||||
assert.deepEqual(LOCKDOWN.settingSources, [], 'no settings files may be loaded');
|
||||
assert.deepEqual(LOCKDOWN.skills, [], 'no skills may be loaded');
|
||||
assert.equal(LOCKDOWN.strictMcpConfig, true, 'no MCP server may arrive from ambient config');
|
||||
assert.equal(LOCKDOWN.persistSession, false, 'no session history is written anywhere');
|
||||
assert.equal(LOCKDOWN.maxTurns, 1, 'one turn: a job is a question, not a conversation');
|
||||
});
|
||||
|
||||
test('an image built without the AI runtime reports it rather than crashing', async () => {
|
||||
// The default build target has no SDK. check() is what the admin card renders, and it has to
|
||||
// answer honestly on both targets — this asserts the shape either way, so the test is not
|
||||
// hostage to which target the suite happens to run on.
|
||||
const r = await adapterFor('claude').check();
|
||||
assert.equal(typeof r.ok, 'boolean');
|
||||
if (r.ok) assert.match(r.version, /Claude Agent SDK/);
|
||||
else assert.match(r.error, /not installed/);
|
||||
});
|
||||
|
||||
test('the fixture provider needs no credential and the Claude one names both it accepts', () => {
|
||||
assert.equal(cfg.PROVIDERS.fixture.apiKeyEnv, null);
|
||||
assert.equal(cfg.PROVIDERS.fixture.oauthEnv, null);
|
||||
// The two variables the runtime reads. jobEnv() injects the credential under one of them and
|
||||
// nothing else, which is what makes the sanitised environment the only channel it travels.
|
||||
assert.equal(cfg.PROVIDERS.claude.oauthEnv, 'CLAUDE_CODE_OAUTH_TOKEN');
|
||||
assert.equal(cfg.PROVIDERS.claude.apiKeyEnv, 'ANTHROPIC_API_KEY');
|
||||
assert.equal(cfg.PROVIDERS.claude.setupToken, true);
|
||||
});
|
||||
Reference in new issue
Block a user