mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 20:29:18 +01:00
Preserve managed SSH sessions and probe refreshes
Normalize managed ACP session identity through the shared account-home contract so fresh credential directories and token refreshes do not discard conversations. Keep account changes and other configured environment changes in the identity. Restore refreshed Codex probe credentials through the existing same-account merge before deleting the private runtime. Report managed copyback errors and keep local cleanup in a finally block. Verified both findings red-green with six regression cases. The focused run passed 352 tests, and adapter-utils, Codex, and server typechecks passed. Local verify requests broader CI (exit 2). Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
d59f9bbcee
commit
ace218fedc
7 files changed
+184
-54
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { managedAiHomeEnvironment } from "@paperclipai/adapter-utils/managed-ai-runtime-env";
|
||||
export { managedAiSessionFingerprintConfig } from "@paperclipai/adapter-utils/managed-ai-runtime-env";
|
||||
import { environmentTaskResultSchema } from "@paperclipai/plugin-sdk";
|
||||
import type { ManagedAiCredentialWritebackBinding } from "./managed-ai-credential-writeback.js";
|
||||
import { OPENROUTER_ATTRIBUTION_HEADERS, openRouterClaudeHeaders } from "@paperclipai/shared/openrouter-attribution";
|
||||
@@ -208,40 +210,6 @@ done`,
|
||||
}
|
||||
}
|
||||
|
||||
function managedAiHomeEnvironment(home: string): Record<string, string> {
|
||||
const providerHome = path.join(home, "provider");
|
||||
return {
|
||||
HOME: home,
|
||||
XDG_CONFIG_HOME: path.join(home, "config"),
|
||||
XDG_DATA_HOME: path.join(home, "data"),
|
||||
CODEX_HOME: providerHome,
|
||||
GROK_HOME: providerHome,
|
||||
CLAUDE_CONFIG_DIR: providerHome,
|
||||
HERMES_HOME: providerHome,
|
||||
};
|
||||
}
|
||||
|
||||
/** Only the server-created credential home is volatile; retain all other config. */
|
||||
export function managedAiSessionFingerprintConfig(
|
||||
config: Record<string, unknown>,
|
||||
managedHome: string | undefined,
|
||||
): Record<string, unknown> {
|
||||
if (!managedHome) return config;
|
||||
const env = { ...(config.env as Record<string, unknown> | undefined) };
|
||||
const stable = managedAiHomeEnvironment("<managed-ai-home>");
|
||||
for (const [key, value] of Object.entries(managedAiHomeEnvironment(managedHome))) {
|
||||
if (env[key] === value) env[key] = stable[key];
|
||||
}
|
||||
if (env.GEMINI_HOME === path.join(managedHome, "provider")) env.GEMINI_HOME = path.join("<managed-ai-home>", "provider");
|
||||
const managed = config.managedAiConnection as Record<string, unknown> | undefined;
|
||||
if (managed?.sessionIdentity) {
|
||||
for (const key of ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN", "OPENAI_API_KEY", "CODEX_API_KEY", "OPENROUTER_API_KEY", "XAI_API_KEY", "GROK_API_KEY", "GEMINI_API_KEY", "GOOGLE_API_KEY", "OPENCODE_AUTH_JSON", "OPENCODE_CONFIG_CONTENT"]) {
|
||||
if (env[key]) env[key] = "<managed-ai-credential>";
|
||||
}
|
||||
}
|
||||
return { ...config, env, ...(managed?.sessionIdentity ? { managedAiConnection: { ...managed, identity: managed.sessionIdentity } } : {}) };
|
||||
}
|
||||
|
||||
export async function prepareManagedAiRuntime(
|
||||
db: Db,
|
||||
input: {
|
||||
|
||||
Reference in new issue
Block a user