/** * Credentials-file helpers used by `serve.ts` for Claude Code subscription * credentials. Extracted so other modules (e.g. AI 401 mediation) can reuse * the atomic rewrite without importing from the much larger `serve.ts`. * * @category Credentials * @since 3.3.0 */ /** * Well-known platform key for the Claude Code OAuth credentials JSON blob * forwarded by `provision_secrets`. The runner writes it to * `/.claude/.credentials.json` instead of the secret provider since * the SDK reads it as a file. * * @docLink packages/runner/dev-guide#environment-variables */ export declare const CLAUDE_CODE_CREDENTIALS_KEY = "CLAUDE_CODE_CREDENTIALS_JSON"; /** * Writes the Claude Code credentials JSON blob to the Claude user config dir * at the current canonical Linux path, `~/.claude/.credentials.json`, with * mode `0600`. Creates the parent directory with mode `0700` if needed. * * Atomic via tmp-file + rename within the same directory. * * Exported for unit tests + the AI 401 mediation helper. * * @docLink packages/runner/dev-guide#environment-variables */ export declare function writeClaudeCodeCredentialsFile(home: string, json: string): Promise; /** * Ensure `/.claude/settings.json` carries `disableClaudeAiConnectors: true`. * * With a claude.ai subscription credential on disk, Claude Code fetches every * connector of the seat owner's claude.ai account and advertises it to the * session as `mcp__claude_ai___*` tools. The key is honored from any * settings scope with any-source-true semantics, so writing it into the user * scope switches the fetch off regardless of project settings or SDK options. * * Claude Code honors the key from Agent SDK 0.3.258 on; older CLIs ignore it * (their settings schema passes unknown keys through), which is why the driver * also sets `ENABLE_CLAUDEAI_MCP_SERVERS=false` — that flag every CLI honors. * * Writes `/.claude/settings.json`, the same directory the credentials * file goes to. That is the CLI's user scope only while `CLAUDE_CONFIG_DIR` is * unset or equal to it — an image that moves the config dir must move both * writes, or the CLI never reads this file and the success log lies. * * Read-merge-write: every other key of an existing file survives (in * production `~/.claude` is a persistent per-session bind mount, never a * scratch dir). A missing or unparseable file starts from `{}` and is * replaced; genuine fs errors (EACCES, EROFS, …) propagate so the caller * decides. Idempotent — already-`true` files are left untouched. Atomic via * tmp-file + rename like {@link writeClaudeCodeCredentialsFile}. * * @returns The path to the settings file. */ export declare function ensureClaudeSettingsDisablesConnectors(home: string): Promise; /** * Atomically merge a fresh `accessToken` into the credentials JSON at * `/.claude/.credentials.json`, preserving any other top-level fields * and the nested `claudeAiOauth` shape the platform writes at provision time. * * Read-modify-write under {@link writeClaudeCodeCredentialsFile}'s atomic- * rename semantics. Used by the runner's `onAuthError` callback (in * `serve.ts`) when the bridge driver asks for a credential refresh after * a 401 from the underlying agent. * * @param home - The home directory under which `.claude/.credentials.json` * lives. * @param accessToken - The fresh access token to persist. * @param expiresAt - Optional ISO timestamp for the rotated token. * @returns The path to the rewritten credentials file. * * Spec: `_devlog/specs/2026-05-07-unified-credential-mediation.md` * § "Runner-side handling on 401" (now bridge-side). */ export declare function mergeAndRewriteCredentialsFile(home: string, accessToken: string, expiresAt?: string | null): Promise; /** * Extract the access-token expiry from a raw Claude Code credentials JSON * blob. Supports both the nested `claudeAiOauth.expiresAt` shape the * platform writes at provision time and an optional top-level `expiresAt` * field used by some SDK builds. * * Returns `null` when the field is missing, empty, or not a parseable * date — callers treat `null` as "static token, don't schedule a * proactive refresh". Tolerates both ISO-8601 strings and millisecond * epochs (some Claude Code builds emit the epoch; normalise to ISO so * downstream code has one format to reason about). * * Used by the runner's proactive AI-credential refresh scheduler in * `serve.ts` to compute the next refresh fire time after a fresh * credential lands (initial provision OR `host.refresh_credential` * response). The runner never mutates the credentials blob; this is a * pure read. * * @docLink packages/runner/dev-guide#ai-credential-mediation */ export declare function extractClaudeAiOauthExpiresAt(json: string): string | null; /** * Read the current access token from the on-disk credentials file at * `/.claude/.credentials.json`. Supports both the nested * `claudeAiOauth.accessToken` shape the platform writes and the flat * top-level `accessToken` some SDK builds use. * * Used by the 401-mediation path to fingerprint the just-rejected token (the * one currently on disk) before asking the platform to rotate it, so the * platform can coalesce concurrent rotations of the same dead token. Returns * `null` when the file is absent, unreadable, or carries no token. * * @docLink packages/runner/dev-guide#ai-credential-mediation */ export declare function readCurrentClaudeAccessToken(home: string): string | null; //# sourceMappingURL=serve-credentials.d.ts.map