Audit — P0.9.2 ν Claude API Wrappers
1. Surface inventory
1.1 Relevant spec files
| File | Zone | Notes |
|---|---|---|
docs/guides/implementation/task-breakdown.md lines 415–426 |
CANON | Defines acceptance criteria |
docs/reference/extractions/nu-integrations-extraction.md |
CANON | Donor Claude API architecture (§ 24 sub-modules) |
docs/reference/extractions/nu-integrations-extraction.md |
CANON | Retry + webhook delivery algorithms |
1.2 Existing ν domain files (Phase 0)
| Path | Purpose |
|---|---|
src/domains/integrations/index.ts |
Barrel — re-exports notifications.ts |
src/domains/integrations/notifications.ts |
P0.9.3 — three-channel notifier (log/mcp/webhook) |
src/config.ts |
Zod env schema; COLIBRI_WEBHOOK_URL already present |
1.3 Test precedent
| Path | Notes |
|---|---|
src/__tests__/domains/integrations/notifications.test.ts |
P0.9.3 test — injection-seam pattern for fetch/logger/env |
1.4 Dependency check — @anthropic-ai/sdk
package.json does NOT list @anthropic-ai/sdk. Per dispatcher: use global fetch (Node ≥ 20) against the Anthropic REST API directly. No new runtime dependency needed.
1.5 Env schema baseline
src/config.ts schema currently declares:
NODE_ENV— requiredCOLIBRI_DB_PATH— optional with defaultCOLIBRI_LOG_LEVEL— optional with defaultCOLIBRI_WEBHOOK_URL— optional URL (P0.9.3)COLIBRI_STARTUP_TIMEOUT_MS— optional integer
P0.9.2 additions required:
ANTHROPIC_API_KEY— optional in schema (server must boot without it); validated at call-time bycreateCompletion/createCompletionWithTools.COLIBRI_ANTHROPIC_MODEL— optional string (default:claude-sonnet-4-5or similar).COLIBRI_ANTHROPIC_TIMEOUT_MS— optional integer (default: 30 000).
1.6 Donor algorithm surface (retryable logic)
From nu-integrations-extraction.md §Core Sub-Module Architecture:
retry.js(482 lines): exponential backoff, jitter, retryable error classification.- HTTP 429 → retryable. HTTP 5xx → retryable. HTTP 4xx (other) → terminal.
- Base delay: 100 ms, backoff factor: 2×, max retries: 3 (per spec for P0.9.2).
- Spec says max 3 retries (tighter than donor’s 5).
1.7 Logging surface
Spec says “All API calls logged with: model, prompt_tokens, completion_tokens, latency_ms”. No DB table required — console.error (stderr) suffices per P0.9.3 precedent.
1.8 Migration assessment
Dispatcher explicitly states: prefer no migration. Logging to stderr is sufficient. Decision: no migration (no 008_nu_anthropic.sql). Justified: spec says “logged”, not “stored”; P0.9.3 precedent logged to stderr only.
1.9 AMS donor namespace
ANTHROPIC_API_KEY is the vendor’s canonical name — kept as-is per dispatcher. Not renamed to COLIBRI_ANTHROPIC_KEY. The assertNoDonorNamespace guard in src/config.ts only rejects AMS_* keys — ANTHROPIC_* are vendor keys, not donor namespace.
2. Gaps identified
| Gap | Resolution |
|---|---|
@anthropic-ai/sdk not in package.json |
Use fetch against REST API directly |
ANTHROPIC_API_KEY not in Zod schema |
Add as .optional() to src/config.ts |
No src/domains/integrations/claude.ts |
Create in Step 4 |
| No test file for Claude API | Create in Step 4 |
src/domains/integrations/index.ts does not export claude.ts |
Add export in Step 4 |
3. Dependencies
- P0.1.4 (Zod env schema) — complete.
src/config.tsis the integration point. - P0.9.1 (MCP bridge, parallel sub-agent) — no overlap. Files:
src/domains/integrations/mcp-bridge.tsand007_nu_broker.sqlare out-of-scope for this task.
4. Risk register
| Risk | Severity | Mitigation |
|---|---|---|
| Real network calls in tests | HIGH | Inject fetchFn seam (same pattern as P0.9.3) |
ANTHROPIC_API_KEY committed |
HIGH | Only dummy values in tests; .env gitignored |
assertNoDonorNamespace rejects ANTHROPIC_API_KEY |
MED | Guard checks AMS_* prefix only — not an issue |
| Parallel sub-agent (P0.9.1) writes to same migration slot | MED | Dispatcher pre-assigned 008 to P0.9.2; no migration taken anyway |
| Retry jitter causes flaky timing in tests | LOW | Inject delayFn seam for deterministic tests |
| CI startup-subprocess smoke test flakiness (pre-existing) | LOW | Note in PR body if hit |