mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-20 18:26:40 +01:00
Use the agent-selected AI account for new SSH environments. Preserve
remote-machine authentication for existing environments and expose it as
an advanced option. Keep managed credentials private while preserving
supported conversation state and credential refreshes across turns.
Validated with focused route, adapter, lifecycle, and real-process tests;
final CI passed on d634944df1.
Greptile Apex reviewed that revision at 5/5 with no unresolved threads.
External neutral security reports remain documented in the pull request.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
141 lines
5.5 KiB
TypeScript
141 lines
5.5 KiB
TypeScript
export { execute, ensureCodexSkillsInjected } from "./execute.js";
|
|
export {
|
|
resolveCodexAuthPrecedence,
|
|
CODEX_SANDBOX_AUTH_PRECEDENCE_WARNING,
|
|
CODEX_SANDBOX_AUTH_PRECEDENCE_WARNING_LOG_LINE,
|
|
CODEX_SANDBOX_AUTH_EXISTS_COMMAND,
|
|
type CodexAuthPrecedenceInput,
|
|
type CodexAuthPrecedenceResolution,
|
|
type CodexAuthPrecedenceWinner,
|
|
} from "./auth-precedence.js";
|
|
export * from "./acp.js";
|
|
export { getConfigSchema } from "./config-schema.js";
|
|
export {
|
|
reconcileManagedCodexHome,
|
|
isManagedCodexHomePath,
|
|
resolveManagedCodexHomeDir,
|
|
evaluateCodexCredentialReadiness,
|
|
type ReconcileManagedCodexHomeInput,
|
|
type ReconcileManagedCodexHomeResult,
|
|
type ReconcileManagedCodexHomeStatus,
|
|
type CodexCredentialReadiness,
|
|
type CodexCredentialReadinessInput,
|
|
type CodexCredentialAuthMode,
|
|
} from "./codex-home.js";
|
|
export { listCodexSkills, syncCodexSkills } from "./skills.js";
|
|
export { testEnvironment } from "./test.js";
|
|
export {
|
|
runDeviceLogin,
|
|
CODEX_DEVICE_LOGIN_COMMAND,
|
|
type SandboxLoginDriver,
|
|
type DeviceLoginPromptSink,
|
|
type DeviceLoginOutcome,
|
|
type DeviceLoginResult,
|
|
type RunDeviceLoginOptions,
|
|
} from "./device-login-runner.js";
|
|
export { DEVICE_LOGIN_URL, parseDeviceLoginPrompt, type DeviceLoginPrompt } from "./device-login-parse.js";
|
|
export {
|
|
promoteDeviceLoginCredential,
|
|
checkStagedCredentialReadiness,
|
|
DeviceLoginReadinessError,
|
|
type CredentialReadinessResult,
|
|
type PromoteDeviceLoginCredentialInput,
|
|
type PromoteDeviceLoginCredentialOutcome,
|
|
type PromoteDeviceLoginCredentialResult,
|
|
} from "./adapter-auth-promotion.js";
|
|
export {
|
|
withCodexAccountHomePromotionLock,
|
|
withAccountHomeSecretMutationLock,
|
|
assertAccountHomeCacheDirStillValid,
|
|
resolveCodexAuthCacheDir,
|
|
isCodexAuthCachePath,
|
|
readSubscriptionAccountId,
|
|
} from "./codex-auth-cache.js";
|
|
export { parseCodexJsonl, isCodexHarnessCrash, isCodexProviderQuotaError, isCodexTransientUpstreamError, isCodexUnknownSessionError } from "./parse.js";
|
|
export {
|
|
getQuotaWindows,
|
|
readCodexAuthInfo,
|
|
readCodexToken,
|
|
fetchCodexQuota,
|
|
fetchCodexRpcQuota,
|
|
mapCodexRpcQuota,
|
|
secondsToWindowLabel,
|
|
fetchWithTimeout,
|
|
codexHomeDir,
|
|
} from "./quota.js";
|
|
import type { AdapterSessionCodec } from "@paperclipai/adapter-utils";
|
|
import { sessionCodec as acpxSessionCodec } from "@paperclipai/adapter-utils/acpx-engine/session-codec";
|
|
import { normalizeAdapterExecutionTargetSessionIdentity } from "@paperclipai/adapter-utils/execution-target";
|
|
|
|
function readNonEmptyString(value: unknown): string | null {
|
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
}
|
|
|
|
function remoteSessionMetadata(record: Record<string, unknown>): Record<string, unknown> {
|
|
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(record.remoteExecution);
|
|
const conversationId = readNonEmptyString(record.sshCodexConversationId);
|
|
const scope = readNonEmptyString(record.sshCodexAccountScope);
|
|
return {
|
|
...(remoteExecution ? { remoteExecution } : {}),
|
|
...(conversationId && scope && /^[a-f0-9]{64}$/.test(conversationId) && /^[a-f0-9]{64}$/.test(scope)
|
|
? { sshCodexConversationId: conversationId, sshCodexAccountScope: scope } : {}),
|
|
};
|
|
}
|
|
|
|
export const sessionCodec: AdapterSessionCodec = {
|
|
deserialize(raw: unknown) {
|
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return null;
|
|
const record = raw as Record<string, unknown>;
|
|
const sessionId = readNonEmptyString(record.sessionId) ?? readNonEmptyString(record.session_id);
|
|
if (!sessionId) return acpxSessionCodec.deserialize(raw);
|
|
const cwd =
|
|
readNonEmptyString(record.cwd) ??
|
|
readNonEmptyString(record.workdir) ??
|
|
readNonEmptyString(record.folder);
|
|
const workspaceId = readNonEmptyString(record.workspaceId) ?? readNonEmptyString(record.workspace_id);
|
|
const repoUrl = readNonEmptyString(record.repoUrl) ?? readNonEmptyString(record.repo_url);
|
|
const repoRef = readNonEmptyString(record.repoRef) ?? readNonEmptyString(record.repo_ref);
|
|
return {
|
|
sessionId,
|
|
...remoteSessionMetadata(record),
|
|
...(cwd ? { cwd } : {}),
|
|
...(workspaceId ? { workspaceId } : {}),
|
|
...(repoUrl ? { repoUrl } : {}),
|
|
...(repoRef ? { repoRef } : {}),
|
|
};
|
|
},
|
|
serialize(params: Record<string, unknown> | null) {
|
|
if (!params) return null;
|
|
const sessionId = readNonEmptyString(params.sessionId) ?? readNonEmptyString(params.session_id);
|
|
if (!sessionId) return acpxSessionCodec.serialize(params);
|
|
const cwd =
|
|
readNonEmptyString(params.cwd) ??
|
|
readNonEmptyString(params.workdir) ??
|
|
readNonEmptyString(params.folder);
|
|
const workspaceId = readNonEmptyString(params.workspaceId) ?? readNonEmptyString(params.workspace_id);
|
|
const repoUrl = readNonEmptyString(params.repoUrl) ?? readNonEmptyString(params.repo_url);
|
|
const repoRef = readNonEmptyString(params.repoRef) ?? readNonEmptyString(params.repo_ref);
|
|
return {
|
|
sessionId,
|
|
...remoteSessionMetadata(params),
|
|
...(cwd ? { cwd } : {}),
|
|
...(workspaceId ? { workspaceId } : {}),
|
|
...(repoUrl ? { repoUrl } : {}),
|
|
...(repoRef ? { repoRef } : {}),
|
|
};
|
|
},
|
|
getDisplayId(params: Record<string, unknown> | null) {
|
|
if (!params) return null;
|
|
return (
|
|
readNonEmptyString(params.sessionId) ??
|
|
readNonEmptyString(params.session_id) ??
|
|
acpxSessionCodec.getDisplayId?.(params) ??
|
|
null
|
|
);
|
|
},
|
|
};
|
|
|
|
export { decideCodexAuthMerge } from "./codex-auth-merge-decision.js";
|
|
|
|
export { copyBackCodexAuth } from "./codex-auth-copyback.js";
|