Fix in-place SSH execution across supported Cloud harnesses

Use the shared remote execution capability registry for durable SSH task
admission. Keep controller workspace checks and transfers off authoritative
remote paths across all eight SSH-capable adapters. Preserve connection
identity in their session codecs, stabilize managed ACP skill-home identity,
and stage Grok project assets through the SSH target.

Expand the real SSH heartbeat matrix to every direct harness, including
compatible managed accounts, task-file persistence, and follow-up turns.
Verify previous-release conversation handling, runtime cleanup, local and
copied workspaces, and native Runner contracts.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Devin FoleyandPaperclip committed 2026-11-17 15:00:38 -08:00
1 parent 206a675a49
commit 586c6aa091
33 files changed
+437 -76

No files matched your search

+20 -6
View File
@@ -64,12 +64,17 @@ and Tailscale connections.
## SSH on a volume-free Cloud stack
Cloud SSH execution uses the same durable task workspace storage as Cloud
sandboxes. Claude Code and Codex use their existing SSH adapters. With an
agent-selected Paperclip AI account, the default ACP engine runs directly in the
remote task directory and stages only private runtime assets. The CLI engine
also supports this directory. ACP requires its server command, such as
`claude-agent-acp`, on the SSH login PATH. Selecting SSH does not change the
agent's engine or permission settings.
sandboxes. All built-in SSH-capable harnesses use their existing adapters:
Claude Code, Codex, Cursor, Gemini, Grok, Kimi, OpenCode, and Pi. The native
Paperclip Runner also retains its SSH execution path. Cloud API and gateway
adapters keep their provider-managed execution rather than selecting an SSH host.
With a compatible agent-selected Paperclip AI account, ACP can run directly in
the remote task directory and stage only private runtime assets. Claude Code,
Codex, Gemini, and Kimi expose this ACP path. The CLI engines support the same
remote directory. ACP requires its server command, such as `claude-agent-acp`,
on the SSH login PATH. Selecting SSH does not change the agent's engine,
account compatibility, or permission settings.
An in-place SSH workspace exists on the SSH computer. Neither engine creates
that workspace path on the controller. ACP keeps its local relay and state files
@@ -82,6 +87,15 @@ The SSH account supplies the installed harness; the agent's Paperclip AI account
supplies authentication unless the remote authentication option is enabled.
Host authentication remains supported by the CLI engine.
Saved CLI sessions retain the SSH connection identity through persistence, so a
follow-up cannot attach to a different host. Disposable managed account-home
paths do not reset new ACP conversations. A configuration identity change is
reported as `acpx_session_identity_changed`; older Codex or Gemini ACP sessions
that used the former home identity can reset once at upgrade. Task files remain
in their durable SSH workspace. Older CLI sessions without a saved SSH identity
remain unresumable; Core does not guess their source host.
Each task receives a private directory below the configured SSH workspace path,
inside `.paperclip-workspaces`. The task runs in that remote directory. Core
keeps the workspace binding and saved file versions in its database and object
@@ -2181,11 +2181,11 @@ describe("shared ACPX engine runtime behavior", () => {
);
const changedEnv = await runExecutor(
{ ...baseConfig, env: { OPENROUTER_API_KEY: "value-2" } },
{ context: { taskId: "issue-1", wakeReason: "issue_assigned" } },
{ context: { taskId: "issue-1", wakeReason: "issue_assigned" }, runtime: { sessionParams: first.result.sessionParams } },
);
const sameEnvNewWake = await runExecutor(
{ ...baseConfig, env: { OPENROUTER_API_KEY: "value-1" } },
{ context: { taskId: "issue-1", wakeReason: "comment", wakeCommentId: "c-9" } },
{ context: { taskId: "issue-1", wakeReason: "comment", wakeCommentId: "c-9" }, runtime: { sessionParams: first.result.sessionParams } },
);
const fp = (r: { result: { sessionParams?: unknown } }) =>
@@ -2195,9 +2195,11 @@ describe("shared ACPX engine runtime behavior", () => {
// the next launch sources the latest env.
expect(fp(first)).toBeDefined();
expect(fp(changedEnv)).not.toBe(fp(first));
expect(changedEnv.result.resultJson?.sessionReset).toMatchObject({ code: "acpx_session_identity_changed" });
// A new heartbeat with the same config env keeps the fingerprint stable, so
// per-wake PAPERCLIP_* churn does not needlessly reset the session.
expect(fp(sameEnvNewWake)).toBe(fp(first));
expect(sameEnvNewWake.result.resultJson?.sessionReset).toBeUndefined();
});
it("keeps rotated run scratch paths out of session identity while retaining user temp overrides", async () => {
@@ -4563,7 +4565,7 @@ describe("ACPX engine remote managed-home seam (PR 2: per-adapter home seed)", (
return { root, stateDir, localCwd, remoteCwd, executionTarget };
}
it.each(["custom", "claude"].flatMap(agent => ["turn", "bridge"].flatMap(failure => [
it.each(["custom", "claude", "codex", "gemini"].flatMap(agent => ["turn", "bridge"].flatMap(failure => [
{ inPlace: false, legacySettings: false }, { inPlace: true, legacySettings: false },
...(agent === "claude" ? [{ inPlace: true, legacySettings: true }] : []),
].map(workspace => ({ agent, failure, ...workspace })))))(
@@ -4723,6 +4725,27 @@ describe("ACPX engine remote managed-home seam (PR 2: per-adapter home seed)", (
expect(restore).toHaveBeenCalledTimes(4);
expect(dispose).toHaveBeenCalledTimes(2);
expect(stagedRuntimes.size).toBe(0);
if (inPlace && failure === "turn" && ["codex", "gemini"].includes(agent)) {
const canonical = (value: unknown): unknown => Array.isArray(value) ? value.map(canonical)
: value && typeof value === "object" ? Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => [key, canonical(entry)])) : value;
const legacyHash = (value: unknown) => createHash("sha256").update(JSON.stringify(canonical(value))).digest("hex").slice(0, 16);
const { commandNotes: _notes, ...legacySkills } = result.result.sessionParams!.skills as Record<string, unknown>;
const legacyFingerprint = buildSessionFingerprint({ acpxAgent: agent, agentCommand: "fixture-acp-client", cwd: remoteCwd,
mode: "persistent", permissionMode: "approve-all", nonInteractivePermissions: "deny", requestedModel: "", requestedThinkingEffort: "", fastMode: false,
remoteExecutionIdentity: result.result.sessionParams!.remoteExecution as Record<string, unknown>,
additionalSourcesIdentity: [] as unknown as Record<string, unknown>, skillsIdentity: legacySkills, skillPromptInstructions: "",
paperclipClaudeSettings: null, mcpServers: [], secretManifestHash: legacyHash([]),
adapterEnvHash: legacyHash(managedAiSessionFingerprintConfig({ env: config.env, managedAiConnection: config.managedAiConnection }, config.env.HOME)) });
expect(legacyFingerprint).not.toBe(result.result.sessionParams!.configFingerprint);
const stored = sessionCodec.serialize({ ...result.result.sessionParams, configFingerprint: legacyFingerprint,
sessionKey: buildSessionKey({ companyId: "company-1", agentId: "agent-1", taskKey: "default" }, legacyFingerprint) });
failTurn = false;
const upgraded = await runExecutor(configForTurn(1), { ...options, runId: "run-upgrade",
runtime: { sessionParams: sessionCodec.deserialize(JSON.parse(JSON.stringify(stored))) } });
expect(upgraded.sessionInputs[0]?.resumeSessionId).toBeUndefined();
expect(upgraded.result.resultJson?.sessionReset).toMatchObject({ code: "acpx_session_identity_changed" });
await expect(fs.readFile(remoteMount, "utf8")).resolves.toBe("This path is not a directory on the controller.");
}
} finally {
vi.mocked(prepareAdapterExecutionTargetRuntime).mockReset().mockImplementation(actual.prepareAdapterExecutionTargetRuntime);
vi.mocked(startAdapterExecutionTargetPaperclipBridge).mockReset().mockImplementation(actual.startAdapterExecutionTargetPaperclipBridge);
@@ -30,6 +30,7 @@ import {
adapterExecutionTargetEnablesSandboxDuplexBridge,
formatAdapterExecutionTimeoutErrorMessage,
formatAdapterExecutionTimeoutStartLogLine,
ensureAdapterExecutionTargetLocalWorkspace,
prepareAdapterExecutionTargetRuntime,
readAdapterExecutionTarget,
resolveAdapterExecutionTargetTimeout,
@@ -75,7 +76,6 @@ import {
asString,
buildInvocationEnvForLogs,
buildPaperclipEnv,
ensureAbsoluteDirectory,
ensurePathInEnv,
ensurePaperclipSkillSymlink,
isForbiddenConfigEnvKey,
@@ -2001,9 +2001,8 @@ async function buildRuntime(input: {
});
// Step 1 — workspace.resolve: the workspace resolution/fallback chain closes
// here on the awaited directory materialization.
await measureStartupStep(input.ctx, nowMs, "workspace.resolve", async () => {
if (!sshWorkspaceInPlace) await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
},
await measureStartupStep(input.ctx, nowMs, "workspace.resolve", () =>
ensureAdapterExecutionTargetLocalWorkspace(executionTarget, cwd),
stepMetrics,
);
@@ -2354,6 +2353,14 @@ async function buildRuntime(input: {
: resolvedAdapterEnv,
),
};
if (useRemoteProcessSession && executionTarget?.kind === "remote" && executionTarget.transport === "ssh" && config.managedAiConnection && env.HOME) {
const managedHome = path.resolve(env.HOME);
const skills = Object.fromEntries(Object.entries(skillsIdentity).map(([key, value]) => [key,
typeof value === "string" && path.isAbsolute(value) && (value === managedHome || value.startsWith(managedHome + path.sep))
? path.join("<managed-ai-home>", path.relative(managedHome, value)) : value,
]));
fingerprintIdentity = { ...fingerprintIdentity, skillsIdentity: skills };
}
const taskKey = asString(input.ctx.runtime.taskKey, "") || wakeTaskId || workspaceId || "default";
const sshWorkspaceRunId = useRemoteProcessSession && executionTarget?.kind === "remote" && executionTarget.transport === "ssh"
? shortHash({ companyId: agent.companyId, agentId: agent.id, taskKey, fingerprintIdentity })
@@ -6007,7 +6014,15 @@ export function createAcpxEngineExecutor(deps: AcpxEngineExecutorOptions = {}) {
};
},
};
return await runAttempt(plan);
const result = await runAttempt(plan);
const previousSession = parseObject(ctx.runtime.sessionParams);
if (asString(previousSession.acpSessionId, "") && result.sessionParams?.configFingerprint
&& previousSession.configFingerprint !== result.sessionParams.configFingerprint) {
return { ...result, resultJson: { ...result.resultJson,
sessionReset: { code: "acpx_session_identity_changed", reason: "The agent configuration or execution identity changed." },
} };
}
return result;
} finally {
// Record the in-memory evidence synchronously, but never let diagnostic
// persistence hold the staging lease or delay the completed run's return.
@@ -1,5 +1,7 @@
import os from "node:os";
import path from "node:path";
import { randomUUID } from "node:crypto";
import { access, readFile } from "node:fs/promises";
import { access, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { afterEach, describe, expect, it, vi } from "vitest";
import * as ssh from "./ssh.js";
import * as serverUtils from "./server-utils.js";
@@ -11,6 +13,7 @@ import {
normalizeAdapterExecutionTargetSessionIdentity,
ensureAdapterExecutionTargetRuntimeCommandInstalled,
ensureAdapterExecutionTargetDirectory,
ensureAdapterExecutionTargetLocalWorkspace,
ensureAdapterExecutionTargetCommandResolvable,
isAdapterExecutionTargetUnavailableError,
resolveAdapterExecutionTargetCwd,
@@ -471,3 +474,21 @@ describe("GitHub launcher lifecycle", () => {
expect(runner.execute).toHaveBeenCalledTimes(1);
});
});
describe("controller workspace preparation", () => {
it.each(["local", "copy", "in_place"] as const)("keeps %s workspace access on its owning filesystem", async mode => {
const root = await mkdtemp(path.join(os.tmpdir(), "paperclip-remote-path-"));
try {
const mount = path.join(root, "remote-filesystem");
await writeFile(mount, "Not a controller directory");
const cwd = path.join(mount, "workspace");
const target = mode === "local" ? null : { ...sshExecutionTarget(), remoteCwd: cwd,
workspaceRealization: { mode, authoritativeRoot: cwd, pathAliases: [], outboundRestorePaths: [] } };
const prepare = ensureAdapterExecutionTargetLocalWorkspace(target, cwd);
if (mode === "in_place") await expect(prepare).resolves.toBeUndefined();
else await expect(prepare).rejects.toMatchObject({ code: "ENOTDIR" });
expect(await readFile(mount, "utf8")).toBe("Not a controller directory");
} finally { await rm(root, { recursive: true, force: true }); }
});
});
@@ -77,6 +77,7 @@ import {
} from "./duplex-observability.js";
import { createSshCommandManagedRuntimeRunner, parseSshRemoteExecutionSpec, runSshCommand, shellQuote } from "./ssh.js";
import {
ensureAbsoluteDirectory,
ensureCommandResolvable,
resolveCommandForLogs,
runChildProcess,
@@ -1313,6 +1314,11 @@ export async function ensureAdapterExecutionTargetFile(
);
}
export async function ensureAdapterExecutionTargetLocalWorkspace(target: AdapterExecutionTarget | null | undefined, cwd: string): Promise<void> {
if (target?.kind === "remote" && target.workspaceRealization?.mode === "in_place") return;
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
}
/**
* Ensure a working directory exists (and is a directory) on the execution target.
*
@@ -1566,6 +1572,7 @@ export async function prepareAdapterExecutionTargetRuntime(input: {
};
}
const syncWorkspace = input.syncWorkspace ?? target.workspaceRealization?.mode !== "in_place";
if (target.transport === "ssh") {
const prepared = await prepareRemoteManagedRuntime({
spec: target.spec,
@@ -1573,7 +1580,7 @@ export async function prepareAdapterExecutionTargetRuntime(input: {
adapterKey: input.adapterKey,
workspaceLocalDir: input.workspaceLocalDir,
workspaceRemoteDir: input.workspaceRemoteDir,
syncWorkspace: input.syncWorkspace,
syncWorkspace,
privateRuntime: input.privateRuntime,
retainRuntime: input.retainRuntime,
workspaceFileMode: input.workspaceFileMode,
@@ -1613,7 +1620,7 @@ export async function prepareAdapterExecutionTargetRuntime(input: {
workspaceLocalDir: input.workspaceLocalDir,
workspaceRemoteDir: input.workspaceRemoteDir,
runtimeRootDir: input.runtimeRootDir,
syncWorkspace: input.syncWorkspace,
syncWorkspace,
workspaceInboundMode: input.workspaceInboundMode,
workspaceSnapshotIsolation: input.workspaceSnapshotIsolation,
workspaceGitIndexRefresh: input.workspaceGitIndexRefresh,
@@ -19,6 +19,7 @@ import {
adapterExecutionTargetUsesPaperclipBridge,
describeAdapterExecutionTarget,
ensureAdapterExecutionTargetCommandResolvable,
ensureAdapterExecutionTargetLocalWorkspace,
ensureAdapterExecutionTargetRuntimeCommandInstalled,
prepareAdapterExecutionTargetRuntime,
adapterExecutionTargetDuplexObservabilityRecorder,
@@ -44,7 +45,6 @@ import {
readPaperclipIssueWorkModeFromContext,
joinPromptSections,
buildInvocationEnvForLogs,
ensureAbsoluteDirectory,
ensurePathInEnv,
isForbiddenConfigEnvKey,
isPaperclipRuntimeEnvKey,
@@ -222,9 +222,7 @@ async function buildClaudeRuntimeConfig(input: ClaudeExecutionInput): Promise<Cl
executionTargetIsRemote,
executionCwd: effectiveExecutionCwd,
});
if (!executionTargetIsRemote || executionTarget?.workspaceRealization?.mode !== "in_place") {
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
}
await ensureAdapterExecutionTargetLocalWorkspace(executionTarget, cwd);
const envConfig = parseObject(config.env);
const env: Record<string, string> = { ...buildPaperclipEnv(agent, input.agentIdentity) };
@@ -16,6 +16,7 @@ import {
adapterExecutionTargetUsesPaperclipBridge,
describeAdapterExecutionTarget,
ensureAdapterExecutionTargetCommandResolvable,
ensureAdapterExecutionTargetLocalWorkspace,
ensureAdapterExecutionTargetRuntimeCommandInstalled,
prepareAdapterExecutionTargetRuntime,
adapterExecutionTargetDuplexObservabilityRecorder,
@@ -36,7 +37,6 @@ import {
buildPaperclipEnv,
buildRuntimeToolsEnv,
buildInvocationEnvForLogs,
ensureAbsoluteDirectory,
ensurePaperclipSkillSymlink,
ensurePathInEnv,
refreshPaperclipWorkspaceEnvForExecution,
@@ -228,7 +228,7 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
const effectiveWorkspaceCwd = useConfiguredInsteadOfAgentHome ? "" : workspaceCwd;
const cwd = effectiveWorkspaceCwd || configuredCwd || process.cwd();
let effectiveExecutionCwd = adapterExecutionTargetRemoteCwd(executionTarget, cwd);
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
await ensureAdapterExecutionTargetLocalWorkspace(executionTarget, cwd);
const cursorSkillEntries = await readPaperclipRuntimeSkillEntries(config, __moduleDir);
const desiredCursorSkillNames = resolveLegacyPaperclipDesiredSkillNames(config, cursorSkillEntries);
if (!executionTargetIsRemote) {
@@ -1,3 +1,4 @@
import { normalizeAdapterExecutionTargetSessionIdentity } from "@paperclipai/adapter-utils/execution-target";
export { execute, ensureCursorSkillsInjected } from "./execute.js";
export { listCursorSkills, syncCursorSkills } from "./skills.js";
export { testEnvironment } from "./test.js";
@@ -24,8 +25,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(record.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -46,8 +49,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(params.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -311,7 +311,7 @@ describe("gemini_local ACP lane", () => {
).resolves.toMatchObject({ engine: "acp", explicit: true, unavailableReason: expect.stringContaining("Node") });
});
it("reports unavailable ACP for non-sandbox remote auto runs", async () => {
it("reports unavailable ACP for SSH runs without a managed account", async () => {
setNodeVersion("v24.11.0");
await expect(
resolveGeminiExecutionEngineForRun({
@@ -335,7 +335,7 @@ describe("gemini_local ACP lane", () => {
).resolves.toMatchObject({
engine: "acp",
explicit: false,
unavailableReason: expect.stringContaining("sandbox remote targets only"),
unavailableReason: expect.stringContaining("agent-managed SSH account"),
});
});
@@ -329,7 +329,7 @@ async function commandIsResolvable(
token,
target,
resolveAdapterExecutionTargetCwd(target, asString(input?.config.cwd, ""), process.cwd()),
process.env,
target.transport === "ssh" ? { PATH: process.env.PATH } : {},
);
return true;
} catch {
@@ -360,11 +360,13 @@ async function geminiAcpUnavailableReason(
executionTarget: input.executionTarget,
legacyRemoteExecution: input.executionTransport?.remoteExecution,
});
if (target?.kind === "remote" && !sandboxTargetHasProcessSessionBridge(target)) {
const managedSsh = target?.kind === "remote" && target.transport === "ssh"
&& target.spec.useHostAuth === false && Boolean(input.config.managedAiConnection);
if (target?.kind === "remote" && !sandboxTargetHasProcessSessionBridge(target) && !managedSsh) {
if (target.transport === "sandbox") {
return "Gemini ACP requires a bidirectional remote process target; this sandbox exposes only one-shot command execution.";
}
return "Gemini ACP supports sandbox remote targets only; this run targets a non-sandbox remote environment.";
return "Gemini ACP requires an agent-managed SSH account; host authentication is supported by the CLI engine.";
}
if (!nodeVersionMeetsGeminiAcpMinimum()) {
return `Node ${process.version} (${process.execPath}) does not satisfy Gemini ACP's Node >=${MIN_ACP_NODE_VERSION} prerequisite.`;
@@ -3,6 +3,12 @@ import { resolveGeminiExecutionEngineForRun } from "./acp.js";
import { execute } from "./execute.js";
import { testEnvironment } from "./test.js";
const remoteCommandProbe = vi.hoisted(() => vi.fn(async (..._args: unknown[]) => undefined));
vi.mock("@paperclipai/adapter-utils/execution-target", async importOriginal => ({
...await importOriginal<typeof import("@paperclipai/adapter-utils/execution-target")>(),
ensureAdapterExecutionTargetCommandResolvable: remoteCommandProbe,
}));
const originalVersion = process.version;
afterEach(() => Object.defineProperty(process, "version", { value: originalVersion }));
@@ -42,3 +48,24 @@ describe("gemini engine availability", () => {
expect(result.unavailableReason).toContain("not available");
});
});
describe("managed SSH ACP selection", () => {
afterEach(() => remoteCommandProbe.mockReset().mockResolvedValue(undefined));
it.each(["account", "host auth", "missing account", "missing command"])("checks the selected %s setup", async reason => {
Object.defineProperty(process, "version", { value: "v24.11.0" });
const config = { managedAiConnection: reason === "missing account" ? undefined : { identity: "fixture-account" } };
const target = { kind: "remote" as const, transport: "ssh" as const, remoteCwd: "/remote/workspace",
workspaceRealization: { mode: "in_place" as const, authoritativeRoot: "/remote/workspace", pathAliases: [], outboundRestorePaths: [] },
spec: { useHostAuth: reason === "host auth", host: "ssh.example.test", port: 22, username: "fixture",
remoteCwd: "/remote/workspace", remoteWorkspacePath: "/remote/workspace", privateKey: null, knownHosts: null, strictHostKeyChecking: true } };
if (reason === "missing command") remoteCommandProbe.mockRejectedValueOnce(new Error("missing command"));
const result = await resolveGeminiExecutionEngineForRun({ config, executionTarget: target });
expect(result.engine).toBe("acp");
if (reason === "account") {
expect(result.unavailableReason).toBeUndefined();
expect(remoteCommandProbe).toHaveBeenCalledOnce();
expect(remoteCommandProbe.mock.calls[0]![3]).toEqual({ PATH: process.env.PATH });
} else expect(result.unavailableReason).toBeTruthy();
});
});
@@ -17,6 +17,7 @@ import {
adapterExecutionTargetUsesPaperclipBridge,
describeAdapterExecutionTarget,
ensureAdapterExecutionTargetCommandResolvable,
ensureAdapterExecutionTargetLocalWorkspace,
ensureAdapterExecutionTargetRuntimeCommandInstalled,
prepareAdapterExecutionTargetRuntime,
adapterExecutionTargetDuplexObservabilityRecorder,
@@ -37,7 +38,6 @@ import {
buildPaperclipEnv,
buildRuntimeToolsEnv,
buildInvocationEnvForLogs,
ensureAbsoluteDirectory,
ensurePaperclipSkillSymlink,
joinPromptSections,
ensurePathInEnv,
@@ -261,7 +261,7 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
const effectiveWorkspaceCwd = useConfiguredInsteadOfAgentHome ? "" : workspaceCwd;
const cwd = effectiveWorkspaceCwd || configuredCwd || process.cwd();
let effectiveExecutionCwd = adapterExecutionTargetRemoteCwd(executionTarget, cwd);
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
await ensureAdapterExecutionTargetLocalWorkspace(executionTarget, cwd);
const geminiSkillEntries = await readPaperclipRuntimeSkillEntries(config, __moduleDir);
const desiredGeminiSkillNames = resolveLegacyPaperclipDesiredSkillNames(config, geminiSkillEntries);
if (!executionTargetIsRemote) {
@@ -1,3 +1,4 @@
import { normalizeAdapterExecutionTargetSessionIdentity } from "@paperclipai/adapter-utils/execution-target";
export { execute } from "./execute.js";
export * from "./acp.js";
export { getConfigSchema } from "./config-schema.js";
@@ -35,8 +36,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(record.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -57,8 +60,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(params.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -49,7 +49,8 @@ const {
prepareRuntimeMock,
} = mocks;
vi.mock("@paperclipai/adapter-utils/execution-target", () => ({
vi.mock("@paperclipai/adapter-utils/execution-target", async (importOriginal) => ({
...await importOriginal<typeof import("@paperclipai/adapter-utils/execution-target")>(),
adapterExecutionTargetIsRemote: () => mocks.state.isRemote,
adapterExecutionTargetRemoteCwd: (_target: unknown, cwd: string) =>
mocks.state.isRemote ? "/remote/workspace" : cwd,
@@ -3,9 +3,12 @@ import { withWorkspaceRestore } from "@paperclipai/adapter-utils/workspace-resto
import { cancellableSandboxStartup } from "@paperclipai/adapter-utils/acpx-engine/startup-cancellation";
import fs from "node:fs/promises";
import path from "node:path";
import os from "node:os";
import { prepareGrokRemoteProjectAssets } from "./remote-project-assets.js";
import { fileURLToPath } from "node:url";
import type { AdapterExecutionContext, AdapterExecutionResult } from "@paperclipai/adapter-utils";
import {
type AdapterManagedRuntimeAsset,
managedRemoteHomeEnvironment,
adapterExecutionTargetIsRemote,
adapterExecutionTargetRemoteCwd,
@@ -13,6 +16,7 @@ import {
adapterExecutionTargetSessionMatches,
describeAdapterExecutionTarget,
ensureAdapterExecutionTargetCommandResolvable,
ensureAdapterExecutionTargetLocalWorkspace,
ensureAdapterExecutionTargetRuntimeCommandInstalled,
overrideAdapterExecutionTargetRemoteCwd,
prepareAdapterExecutionTargetRuntime,
@@ -29,7 +33,6 @@ import {
buildInvocationEnvForLogs,
buildPaperclipEnv,
buildRuntimeToolsEnv,
ensureAbsoluteDirectory,
ensurePathInEnv,
joinPromptSections,
materializePaperclipSkillCopy,
@@ -292,18 +295,21 @@ async function executeTurn(ctx: AdapterExecutionContext): Promise<AdapterExecuti
const effectiveWorkspaceCwd = useConfiguredInsteadOfAgentHome ? "" : workspaceCwd;
const cwd = effectiveWorkspaceCwd || configuredCwd || process.cwd();
let effectiveExecutionCwd = adapterExecutionTargetRemoteCwd(executionTarget, cwd);
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
await ensureAdapterExecutionTargetLocalWorkspace(executionTarget, cwd);
const grokSkillEntries = await readPaperclipRuntimeSkillEntries(config, __moduleDir);
const desiredGrokSkillNames = resolveLegacyPaperclipDesiredSkillNames(config, grokSkillEntries);
const instructionsFilePath = asString(config.instructionsFilePath, "").trim();
const projectAssetsDir = executionTargetIsRemote && executionTarget?.workspaceRealization?.mode === "in_place"
? await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-grok-assets-")) : null;
const stagedAssets = await stageGrokProjectAssets({
cwd,
cwd: projectAssetsDir ?? cwd,
instructionsFilePath,
skillEntries: grokSkillEntries,
desiredSkillNames: desiredGrokSkillNames,
onLog,
});
}).catch(async error => { if (projectAssetsDir) await fs.rm(projectAssetsDir, { recursive: true, force: true }); throw error; });
let remoteProjectAssets: Awaited<ReturnType<typeof prepareGrokRemoteProjectAssets>> | null = null;
let restoreRemoteWorkspace: (() => Promise<void>) | null = null;
// Declared here (not inside the try) so the outer `finally` can remove it on
// every exit path (teardown and setup failure alike), mirroring the Codex
@@ -429,7 +435,9 @@ async function executeTurn(ctx: AdapterExecutionContext): Promise<AdapterExecuti
detectCommand: ctx.runtimeCommandSpec?.detectCommand ?? command,
onProgress: (line) => onLog("stdout", line),
onRuntimeProgress: ctx.onRuntimeProgress,
assets: stagedGrokHomeDir
assets: projectAssetsDir || stagedGrokHomeDir ? [
...(projectAssetsDir ? [{ key: "project", localDir: projectAssetsDir, followSymlinks: false }] : []),
...(stagedGrokHomeDir
? [
{
key: "home",
@@ -444,7 +452,7 @@ async function executeTurn(ctx: AdapterExecutionContext): Promise<AdapterExecuti
// value read from `env.GROK_HOME`. A copy-out failure never
// fails the run: `copyBackGrokAuth` logs the errno code and
// rethrows, and this callback swallows that rejection.
restore: async ({ assetDir, readFile }) =>
restore: async ({ assetDir, readFile }: Parameters<NonNullable<AdapterManagedRuntimeAsset["restore"]>>[0]) =>
void (await copyBackGrokAuth({
readSandboxAuth: () => readFile(path.posix.join(assetDir, "auth.json")),
hostHomeDir: hostGrokHome,
@@ -453,10 +461,15 @@ async function executeTurn(ctx: AdapterExecutionContext): Promise<AdapterExecuti
}).catch(() => undefined)),
},
]
: undefined,
: []),
] : undefined,
});
restoreRemoteWorkspace = () =>
preparedExecutionTargetRuntime.restoreWorkspace((line) => onLog("stdout", line));
restoreRemoteWorkspace = async () => {
try { await remoteProjectAssets?.cleanup(); }
finally { await preparedExecutionTargetRuntime.restoreWorkspace((line) => onLog("stdout", line)); }
};
if (projectAssetsDir) remoteProjectAssets = await prepareGrokRemoteProjectAssets({ runId, target: executionTarget!,
cwd: preparedExecutionTargetRuntime.workspaceRemoteDir ?? effectiveExecutionCwd, assets: preparedExecutionTargetRuntime.assetDirs.project! });
effectiveExecutionCwd = preparedExecutionTargetRuntime.workspaceRemoteDir ?? effectiveExecutionCwd;
refreshPaperclipWorkspaceEnvForExecution({
env,
@@ -564,7 +577,8 @@ async function executeTurn(ctx: AdapterExecutionContext): Promise<AdapterExecuti
if (permissionMode) args.push("--permission-mode", permissionMode);
if (alwaysApprove) args.push("--always-approve");
if (disableWebSearch) args.push("--disable-web-search");
if (stagedAssets.rulesFilePath) args.push("--rules", `@${stagedAssets.rulesFilePath}`);
const rulesFilePath = remoteProjectAssets?.rulesFilePath ?? stagedAssets.rulesFilePath;
if (rulesFilePath) args.push("--rules", `@${rulesFilePath}`);
const extraArgs = (() => {
const fromExtraArgs = asStringArray(config.extraArgs);
if (fromExtraArgs.length > 0) return fromExtraArgs;
@@ -775,5 +789,6 @@ async function executeTurn(ctx: AdapterExecutionContext): Promise<AdapterExecuti
});
}
await stagedAssets.cleanup();
if (projectAssetsDir) await fs.rm(projectAssetsDir, { recursive: true, force: true });
}
}
@@ -1,3 +1,4 @@
import { normalizeAdapterExecutionTargetSessionIdentity } from "@paperclipai/adapter-utils/execution-target";
import type { AdapterSessionCodec } from "@paperclipai/adapter-utils";
function readNonEmptyString(value: unknown): string | null {
@@ -20,8 +21,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(record.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -42,8 +45,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(params.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -0,0 +1,44 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { expect, it } from "vitest";
import { prepareGrokRemoteProjectAssets } from "./remote-project-assets.js";
it.each(["existing", "new", "unsafe", "changed"])("keeps %s project files safe while staging Grok runtime assets", async scenario => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), "grok-project-assets-"));
try {
const cwd = path.join(root, "workspace"), assets = path.join(root, "assets"), outside = path.join(root, "outside");
await fs.mkdir(cwd); await fs.mkdir(outside);
await fs.writeFile(path.join(outside, "keep.txt"), "outside");
const stagedSkill = path.join(assets, ".claude/skills/selected");
await fs.mkdir(stagedSkill, { recursive: true });
await fs.writeFile(path.join(stagedSkill, "SKILL.md"), "selected skill");
await fs.writeFile(path.join(assets, "Agents.md"), "agent instructions");
if (scenario === "existing") {
await fs.mkdir(path.join(cwd, ".claude/skills/own"), { recursive: true });
await fs.writeFile(path.join(cwd, ".claude/skills/own/keep.txt"), "user skill");
}
if (scenario === "unsafe") await fs.symlink(outside, path.join(cwd, ".claude"));
const input = { runId: "fixture", target: { kind: "local" as const }, cwd, assets };
if (scenario === "unsafe") {
await expect(prepareGrokRemoteProjectAssets(input)).rejects.toThrow("Could not prepare Grok SSH runtime assets");
expect(await fs.readdir(outside)).toEqual(["keep.txt"]);
return;
}
const prepared = await prepareGrokRemoteProjectAssets(input);
expect(prepared.rulesFilePath).toBe(path.join(assets, "Agents.md"));
expect(await fs.readFile(path.join(cwd, ".claude/skills/selected/SKILL.md"), "utf8")).toBe("selected skill");
if (scenario === "changed") {
await fs.rename(path.join(cwd, ".claude"), path.join(cwd, ".claude-original"));
await fs.symlink(outside, path.join(cwd, ".claude"));
await expect(prepared.cleanup()).rejects.toThrow("Could not prepare Grok SSH runtime assets");
expect(await fs.readdir(outside)).toEqual(["keep.txt"]);
} else {
await fs.writeFile(path.join(cwd, ".claude/user.txt"), "user work");
await prepared.cleanup();
expect(await fs.readFile(path.join(cwd, ".claude/user.txt"), "utf8")).toBe("user work");
await expect(fs.stat(path.join(cwd, ".claude/skills/selected"))).rejects.toMatchObject({ code: "ENOENT" });
if (scenario === "existing") expect(await fs.readFile(path.join(cwd, ".claude/skills/own/keep.txt"), "utf8")).toBe("user skill");
}
} finally { await fs.rm(root, { recursive: true, force: true }); }
});
@@ -0,0 +1,61 @@
import type { AdapterExecutionTarget } from "@paperclipai/adapter-utils/execution-target";
import { runAdapterExecutionTargetShellCommand } from "@paperclipai/adapter-utils/execution-target";
import { shellQuote } from "@paperclipai/adapter-utils/ssh";
const program = `
const fs = require('fs'), path = require('path');
const [operation, assets, cwd, encoded] = process.argv.slice(1);
const created = [];
const cleanup = entries => { for (const entry of [...entries].reverse()) {
const file = path.resolve(cwd, entry.path);
if (!file.startsWith(path.resolve(cwd) + path.sep) || !entry.path.startsWith('.claude')) throw Error('Invalid runtime asset path');
try {
for (const relative of ['.claude', '.claude/skills']) {
const parent = path.join(cwd, relative);
if (file.startsWith(parent + path.sep) && fs.lstatSync(parent).isSymbolicLink()) throw Error('Unsafe runtime asset parent');
}
if (entry.kind === 'skill') fs.rmSync(file, {recursive:true, force:true}); else fs.rmdirSync(file);
}
catch (error) { if (!['ENOENT', 'ENOTEMPTY'].includes(error.code)) throw error; }
} };
if (operation === 'cleanup') { cleanup(JSON.parse(encoded)); process.exit(0); }
try {
const source = path.join(assets, '.claude', 'skills');
if (fs.existsSync(source)) {
for (const relative of ['.claude', '.claude/skills']) {
const target = path.join(cwd, relative);
if (fs.existsSync(target)) { const st = fs.lstatSync(target); if (st.isSymbolicLink() || !st.isDirectory()) throw Error('Unsafe Grok skills directory'); }
else { fs.mkdirSync(target); created.push({path:relative,kind:'directory'}); }
}
for (const name of fs.readdirSync(source)) {
if (path.basename(name) !== name) throw Error('Invalid skill name');
const relative = path.join('.claude', 'skills', name), target = path.join(cwd, relative);
if (fs.existsSync(target)) continue;
fs.mkdirSync(target);
created.push({path:relative,kind:'skill'});
fs.cpSync(path.join(source,name),target,{recursive:true,force:false,errorOnExist:true});
}
}
const rules = fs.existsSync(path.join(assets,'Agents.md')) ? path.join(assets,'Agents.md')
: !fs.existsSync(path.join(cwd,'Agents.md')) && fs.existsSync(path.join(cwd,'AGENTS.md')) ? path.join(cwd,'AGENTS.md') : null;
console.log(JSON.stringify({created,rules}));
} catch (error) { cleanup(created); throw error; }
`;
export async function prepareGrokRemoteProjectAssets(input: {
runId: string; target: AdapterExecutionTarget; cwd: string; assets: string;
}): Promise<{ rulesFilePath: string | null; cleanup: () => Promise<void> }> {
const execute = async (operation: string, entries: unknown[]) => {
const result = await runAdapterExecutionTargetShellCommand(input.runId, input.target,
["node", "-e", program, operation, input.assets, input.cwd, JSON.stringify(entries)].map(shellQuote).join(" "),
{ cwd: input.cwd, env: {}, timeoutSec: 15 });
if (result.exitCode !== 0 || result.timedOut || result.signal) throw new Error("Could not prepare Grok SSH runtime assets");
return result.stdout;
};
const result = JSON.parse(await execute("stage", [])) as { created: Array<{ path: string; kind: string }>; rules: string | null };
if (!Array.isArray(result.created) || result.created.some(entry => !entry || typeof entry !== "object" || typeof entry.path !== "string" || (entry.kind === "directory" ? ![".claude", ".claude/skills"].includes(entry.path)
: entry.kind !== "skill" || !/^\.claude\/skills\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(entry.path)))) throw new Error("Invalid Grok SSH runtime asset receipt");
const allowedRules = [input.assets + "/Agents.md", input.cwd + "/AGENTS.md"];
if (result.rules !== null && !allowedRules.includes(result.rules)) throw new Error("Invalid Grok SSH instructions path");
return { rulesFilePath: result.rules, cleanup: async () => { await execute("cleanup", result.created); } };
}
@@ -219,7 +219,7 @@ async function commandIsResolvable(
token,
target,
resolveAdapterExecutionTargetCwd(target, asString(input?.config.cwd, ""), process.cwd()),
process.env,
target.transport === "ssh" ? { PATH: process.env.PATH } : {},
);
return true;
} catch {
@@ -250,11 +250,13 @@ async function kimiAcpUnavailableReason(
executionTarget: input.executionTarget,
legacyRemoteExecution: input.executionTransport?.remoteExecution,
});
if (target?.kind === "remote" && !sandboxTargetHasProcessSessionBridge(target)) {
const managedSsh = target?.kind === "remote" && target.transport === "ssh"
&& target.spec.useHostAuth === false && Boolean(input.config.managedAiConnection);
if (target?.kind === "remote" && !sandboxTargetHasProcessSessionBridge(target) && !managedSsh) {
if (target.transport === "sandbox") {
return "Kimi ACP requires a bidirectional remote process target; this sandbox exposes only one-shot command execution.";
}
return "Kimi ACP supports sandbox remote targets only; this run targets a non-sandbox remote environment.";
return "Kimi ACP requires an agent-managed SSH account; host authentication is supported by the CLI engine.";
}
if (!nodeVersionMeetsKimiAcpMinimum()) {
return `Node ${process.version} (${process.execPath}) does not satisfy Kimi ACP's Node >=${MIN_ACP_NODE_VERSION} prerequisite.`;
@@ -3,6 +3,12 @@ import { resolveKimiExecutionEngineForRun } from "./acp.js";
import { execute } from "./execute.js";
import { testEnvironment } from "./test.js";
const remoteCommandProbe = vi.hoisted(() => vi.fn(async (..._args: unknown[]) => undefined));
vi.mock("@paperclipai/adapter-utils/execution-target", async importOriginal => ({
...await importOriginal<typeof import("@paperclipai/adapter-utils/execution-target")>(),
ensureAdapterExecutionTargetCommandResolvable: remoteCommandProbe,
}));
const originalVersion = process.version;
afterEach(() => Object.defineProperty(process, "version", { value: originalVersion }));
@@ -42,3 +48,24 @@ describe("kimi engine availability", () => {
expect(result.unavailableReason).toContain("not available");
});
});
describe("managed SSH ACP selection", () => {
afterEach(() => remoteCommandProbe.mockReset().mockResolvedValue(undefined));
it.each(["account", "host auth", "missing account", "missing command"])("checks the selected %s setup", async reason => {
Object.defineProperty(process, "version", { value: "v24.11.0" });
const config = { managedAiConnection: reason === "missing account" ? undefined : { identity: "fixture-account" } };
const target = { kind: "remote" as const, transport: "ssh" as const, remoteCwd: "/remote/workspace",
workspaceRealization: { mode: "in_place" as const, authoritativeRoot: "/remote/workspace", pathAliases: [], outboundRestorePaths: [] },
spec: { useHostAuth: reason === "host auth", host: "ssh.example.test", port: 22, username: "fixture",
remoteCwd: "/remote/workspace", remoteWorkspacePath: "/remote/workspace", privateKey: null, knownHosts: null, strictHostKeyChecking: true } };
if (reason === "missing command") remoteCommandProbe.mockRejectedValueOnce(new Error("missing command"));
const result = await resolveKimiExecutionEngineForRun({ config, executionTarget: target });
expect(result.engine).toBe("acp");
if (reason === "account") {
expect(result.unavailableReason).toBeUndefined();
expect(remoteCommandProbe).toHaveBeenCalledOnce();
expect(remoteCommandProbe.mock.calls[0]![3]).toEqual({ PATH: process.env.PATH });
} else expect(result.unavailableReason).toBeTruthy();
});
});
@@ -14,7 +14,8 @@ const prepareRuntimeMock = vi.hoisted(() => vi.fn(async () => ({
const resolveCommandForLogsMock = vi.hoisted(() => vi.fn(async () => "kimi"));
const runProcessMock = vi.hoisted(() => vi.fn());
vi.mock("@paperclipai/adapter-utils/execution-target", () => ({
vi.mock("@paperclipai/adapter-utils/execution-target", async (importOriginal) => ({
...await importOriginal<typeof import("@paperclipai/adapter-utils/execution-target")>(),
adapterExecutionTargetIsRemote: () => false,
adapterExecutionTargetRemoteCwd: (_target: unknown, cwd: string) => cwd,
overrideAdapterExecutionTargetRemoteCwd: (target: unknown, _cwd: string) => target,
@@ -15,6 +15,7 @@ import {
adapterExecutionTargetUsesPaperclipBridge,
describeAdapterExecutionTarget,
ensureAdapterExecutionTargetCommandResolvable,
ensureAdapterExecutionTargetLocalWorkspace,
ensureAdapterExecutionTargetRuntimeCommandInstalled,
prepareAdapterExecutionTargetRuntime,
readAdapterExecutionTarget,
@@ -30,7 +31,6 @@ import {
buildPaperclipEnv,
buildRuntimeToolsEnv,
buildInvocationEnvForLogs,
ensureAbsoluteDirectory,
joinPromptSections,
ensurePathInEnv,
refreshPaperclipWorkspaceEnvForExecution,
@@ -239,7 +239,7 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
const effectiveWorkspaceCwd = useConfiguredInsteadOfAgentHome ? "" : workspaceCwd;
const cwd = effectiveWorkspaceCwd || configuredCwd || process.cwd();
let effectiveExecutionCwd = adapterExecutionTargetRemoteCwd(executionTarget, cwd);
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
await ensureAdapterExecutionTargetLocalWorkspace(executionTarget, cwd);
const kimiSkillEntries = await readPaperclipRuntimeSkillEntries(config, __moduleDir);
const desiredKimiSkillNames = resolveLegacyPaperclipDesiredSkillNames(config, kimiSkillEntries);
const envConfig = parseObject(config.env);
@@ -1,3 +1,4 @@
import { normalizeAdapterExecutionTargetSessionIdentity } from "@paperclipai/adapter-utils/execution-target";
import type { AdapterSessionCodec } from "@paperclipai/adapter-utils";
import { sessionCodec as acpxSessionCodec } from "@paperclipai/adapter-utils/acpx-engine/session-codec";
@@ -21,8 +22,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(record.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -43,8 +46,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(params.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -16,6 +16,7 @@ import {
adapterExecutionTargetUsesPaperclipBridge,
describeAdapterExecutionTarget,
ensureAdapterExecutionTargetCommandResolvable,
ensureAdapterExecutionTargetLocalWorkspace,
ensureAdapterExecutionTargetRuntimeCommandInstalled,
prepareAdapterExecutionTargetRuntime,
adapterExecutionTargetDuplexObservabilityRecorder,
@@ -37,7 +38,6 @@ import {
buildRuntimeToolsEnv,
joinPromptSections,
buildInvocationEnvForLogs,
ensureAbsoluteDirectory,
ensurePaperclipSkillSymlink,
ensurePathInEnv,
refreshPaperclipWorkspaceEnvForExecution,
@@ -261,7 +261,7 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
const effectiveWorkspaceCwd = useConfiguredInsteadOfAgentHome ? "" : workspaceCwd;
const cwd = effectiveWorkspaceCwd || configuredCwd || process.cwd();
let effectiveExecutionCwd = adapterExecutionTargetRemoteCwd(executionTarget, cwd);
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
await ensureAdapterExecutionTargetLocalWorkspace(executionTarget, cwd);
const openCodeSkillEntries = await readPaperclipRuntimeSkillEntries(config, __moduleDir);
const desiredOpenCodeSkillNames = resolveLegacyPaperclipDesiredSkillNames(config, openCodeSkillEntries);
if (!executionTargetIsRemote) {
@@ -1,3 +1,4 @@
import { normalizeAdapterExecutionTargetSessionIdentity } from "@paperclipai/adapter-utils/execution-target";
import type { AdapterSessionCodec } from "@paperclipai/adapter-utils";
function readNonEmptyString(value: unknown): string | null {
@@ -20,8 +21,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(record.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -42,8 +45,10 @@ export const sessionCodec: AdapterSessionCodec = {
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);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(params.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
...(workspaceId ? { workspaceId } : {}),
...(repoUrl ? { repoUrl } : {}),
@@ -16,6 +16,7 @@ import {
adapterExecutionTargetUsesPaperclipBridge,
describeAdapterExecutionTarget,
ensureAdapterExecutionTargetCommandResolvable,
ensureAdapterExecutionTargetLocalWorkspace,
ensureAdapterExecutionTargetFile,
ensureAdapterExecutionTargetRuntimeCommandInstalled,
prepareAdapterExecutionTargetRuntime,
@@ -37,7 +38,6 @@ import {
buildRuntimeToolsEnv,
joinPromptSections,
buildInvocationEnvForLogs,
ensureAbsoluteDirectory,
ensurePaperclipSkillSymlink,
ensurePathInEnv,
refreshPaperclipWorkspaceEnvForExecution,
@@ -268,7 +268,7 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
const effectiveWorkspaceCwd = useConfiguredInsteadOfAgentHome ? "" : workspaceCwd;
const cwd = effectiveWorkspaceCwd || configuredCwd || process.cwd();
let effectiveExecutionCwd = adapterExecutionTargetRemoteCwd(executionTarget, cwd);
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
await ensureAdapterExecutionTargetLocalWorkspace(executionTarget, cwd);
if (!executionTargetIsRemote) {
await ensureSessionsDir();
@@ -1,3 +1,4 @@
import { normalizeAdapterExecutionTargetSessionIdentity } from "@paperclipai/adapter-utils/execution-target";
import type { AdapterSessionCodec } from "@paperclipai/adapter-utils";
function readNonEmptyString(value: unknown): string | null {
@@ -17,8 +18,10 @@ export const sessionCodec: AdapterSessionCodec = {
readNonEmptyString(record.cwd) ??
readNonEmptyString(record.workdir) ??
readNonEmptyString(record.folder);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(record.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
};
},
@@ -33,8 +36,10 @@ export const sessionCodec: AdapterSessionCodec = {
readNonEmptyString(params.cwd) ??
readNonEmptyString(params.workdir) ??
readNonEmptyString(params.folder);
const remoteExecution = normalizeAdapterExecutionTargetSessionIdentity(params.remoteExecution);
return {
sessionId,
...(remoteExecution ? { remoteExecution } : {}),
...(cwd ? { cwd } : {}),
};
},
@@ -42,7 +42,7 @@ it("requires remote workspace authority and native execution independently of pr
expect(() => assertEphemeralNativeRuntime(false)).not.toThrow();
});
it.each(["claude_local", "codex_local"])("admits %s over SSH only with durable remote workspace authority", adapterType => {
it.each(["claude_local", "codex_local", "cursor", "gemini_local", "grok_local", "kimi_local", "opencode_local", "pi_local"])("admits %s over SSH only with durable remote workspace authority", adapterType => {
vi.stubEnv("PAPERCLIP_EPHEMERAL_SERVER", "true");
vi.stubEnv("DATABASE_URL", config.databaseUrl);
vi.stubEnv("PAPERCLIP_STORAGE_PROVIDER", "s3");
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { adapterExecutionTargetSessionIdentity, adapterExecutionTargetSessionMatches, type AdapterSshExecutionTarget } from "@paperclipai/adapter-utils/execution-target";
import { getServerAdapter } from "../adapters/index.js";
describe("SSH adapter saved session identity", () => {
it.each(["claude_local", "codex_local", "cursor", "gemini_local", "grok_local", "kimi_local", "opencode_local", "pi_local"])("keeps %s connection guards through persistence", adapterType => {
const target: AdapterSshExecutionTarget = { kind: "remote", transport: "ssh", remoteCwd: "/remote/task",
spec: { host: "ssh.example.test", port: 22, username: "fixture", remoteCwd: "/remote/task", remoteWorkspacePath: "/remote",
useHostAuth: false, privateKey: null, knownHosts: null, strictHostKeyChecking: true } };
const identity = adapterExecutionTargetSessionIdentity(target)!;
const codec = getServerAdapter(adapterType).sessionCodec!;
const stored = codec.serialize({ sessionId: "session-fixture", cwd: target.remoteCwd,
remoteExecution: { ...identity, privateKey: "credential-canary", tailscaleSocket: "/private/socket" } });
const restored = codec.deserialize(JSON.parse(JSON.stringify(stored)))!;
expect(restored.remoteExecution).toEqual(identity);
expect(adapterExecutionTargetSessionMatches(restored.remoteExecution, target)).toBe(true);
expect(adapterExecutionTargetSessionMatches(restored.remoteExecution, { ...target, spec: { ...target.spec, host: "other.example.test" } })).toBe(false);
const legacy = codec.deserialize({ sessionId: "session-fixture", cwd: target.remoteCwd })!;
expect(legacy.remoteExecution).toBeUndefined();
expect(adapterExecutionTargetSessionMatches(legacy.remoteExecution, target)).toBe(false);
});
});
@@ -942,7 +942,7 @@ describe.skipIf(!support.supported)("heartbeat runtime selection boundary", () =
expect(prepareNativeWorkspaceSync).not.toHaveBeenCalled();
});
it.each(["claude_local", "codex_local"])("keeps %s SSH runtime and its durable workspace receipt on a volume-free server", async adapterType => {
it.each(["claude_local", "codex_local", "cursor", "gemini_local", "grok_local", "kimi_local", "opencode_local", "pi_local"])("keeps %s SSH runtime and its durable workspace receipt on a volume-free server", async adapterType => {
const { input, run, agent, issue } = await fixture(adapterType);
vi.stubEnv("PAPERCLIP_EPHEMERAL_SERVER", "true");
const environmentId = randomUUID(), leaseId = randomUUID(), workspaceId = randomUUID();
@@ -590,7 +590,7 @@ describe.skipIf(!support.supported && !externalDatabaseUrl)("heartbeat workspace
expect(await db.select().from(executionWorkspaces)).toHaveLength(0);
});
it.each(["claude_local", "codex_local"])("reserves remote storage for volume-free %s SSH tasks before acquiring the machine", async adapterType => {
it.each(["claude_local", "codex_local", "cursor", "gemini_local", "grok_local", "kimi_local", "opencode_local", "pi_local"])("reserves remote storage for volume-free %s SSH tasks before acquiring the machine", async adapterType => {
const { input, issue, envOrchestrator } = await fixture();
configureRemotePersistence();
process.env.PAPERCLIP_EPHEMERAL_SERVER = "true";
+2 -2
View File
@@ -14,7 +14,7 @@ import {
companies, environmentLeases, executionWorkspaces, executionWorkspaceSnapshots, heartbeatRuns, issues, workspaceOperations, type Db,
} from "@paperclipai/db";
import {
readRemoteWorkspaceAuthority, remoteWorkspaceSourceSchema,
adapterSupportsRemoteManagedEnvironments, readRemoteWorkspaceAuthority, remoteWorkspaceSourceSchema,
type RemoteWorkspaceAuthority, type RemoteWorkspaceRunReference, type RemoteWorkspaceSource,
type EnvironmentLease,
} from "@paperclipai/shared";
@@ -95,7 +95,7 @@ function sameExportLocation(value: unknown, location: NonNullable<RemoteWorkspac
}
export function supportsSshRemoteWorkspace(adapterType: string, environmentDriver: string | null | undefined) {
return environmentDriver === "ssh" && ["claude_local", "codex_local", "paperclip_runner"].includes(adapterType);
return environmentDriver === "ssh" && adapterSupportsRemoteManagedEnvironments(adapterType);
}
export function shouldUseRemoteWorkspaces(input: {
@@ -1,3 +1,4 @@
import fs from "node:fs/promises";
import { randomUUID } from "node:crypto";
import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
import os from "node:os";
@@ -9,7 +10,7 @@ import { agents, authUsers, companyMemberships, closeRegisteredClients, companie
import type { AdapterSshExecutionTarget } from "@paperclipai/adapter-utils/execution-target";
import { buildSshEnvLabFixtureConfig, getSshEnvLabSupport, shellQuote, startSshEnvLabFixture,
stopSshEnvLabFixture, type SshEnvLabFixtureState } from "@paperclipai/adapter-utils/ssh";
import type { EnvironmentLease } from "@paperclipai/shared";
import type { AiProvider, EnvironmentLease } from "@paperclipai/shared";
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "../__tests__/helpers/embedded-postgres.js";
import { createLocalDiskStorageProvider } from "../storage/local-disk-provider.js";
import { createStorageService } from "../storage/service.js";
@@ -195,27 +196,40 @@ describe.skipIf(!postgres.supported || !ssh.supported)("Cloud SSH durable worksp
} finally { extract.mockRestore(); }
}, 60_000);
it.each(["cli", "acp"])("runs an assigned Claude %s task through heartbeat with the configured Paperclip account", async engine => {
const harnesses = [
{ adapterType: "claude_local", provider: "anthropic", authEnv: "ANTHROPIC_API_KEY", model: "claude-sonnet-4-6", engines: ["cli", "acp"] },
{ adapterType: "codex_local", provider: "openai", authEnv: "OPENAI_API_KEY", model: "gpt-5.4-mini", engines: ["cli", "acp"] },
{ adapterType: "gemini_local", provider: "google", authEnv: "GEMINI_API_KEY", model: "gemini-2.5-pro", engines: ["cli", "acp"] },
{ adapterType: "grok_local", provider: "xai", authEnv: "XAI_API_KEY", model: "grok-4", engines: ["cli"] },
{ adapterType: "opencode_local", provider: "openrouter", authEnv: "OPENROUTER_API_KEY", model: "openrouter/openai/gpt-4.1", engines: ["cli"] },
{ adapterType: "pi_local", provider: "openai", authEnv: "OPENAI_API_KEY", model: "openai/gpt-5.4-mini", engines: ["cli"] },
{ adapterType: "cursor", provider: null, authEnv: "PAPERCLIP_SSH_FIXTURE_AUTH", model: "auto", engines: ["cli"] },
{ adapterType: "kimi_local", provider: null, authEnv: "PAPERCLIP_SSH_FIXTURE_AUTH", model: "kimi-k2.5", engines: ["cli"] },
];
const runs = harnesses.flatMap(harness => harness.engines.map(engine => ({ ...harness, engine, key: `${harness.adapterType}-${engine}` })));
it.each(runs)("runs an assigned $key task through heartbeat over SSH", async ({ adapterType, provider, authEnv, model, engine, key }) => {
vi.stubEnv("PAPERCLIP_EPHEMERAL_SERVER", "true");
vi.stubEnv("PAPERCLIP_STORAGE_PROVIDER", "s3");
vi.stubEnv("PAPERCLIP_AGENT_JWT_SECRET", "synthetic-cloud-ssh-jwt-secret");
vi.stubEnv("AWS_EC2_METADATA_DISABLED", "true");
const storage = { ...createStorageService(createLocalDiskStorageProvider(path.join(root, `heartbeat-${engine}-objects`))), provider: "s3" as const };
const storage = { ...createStorageService(createLocalDiskStorageProvider(path.join(root, `heartbeat-${key}-objects`))), provider: "s3" as const };
vi.spyOn(storageModule, "getStorageService").mockReturnValue(storage);
vi.spyOn(runLogModule, "getRunLogStore").mockReturnValue(objectLogFixture());
const companyId = randomUUID(), agentId = randomUUID(), issueId = randomUUID(), userId = `ssh-user-${randomUUID()}`;
await db.insert(authUsers).values({ id: userId, name: "SSH test user", email: `${userId}@example.test`, createdAt: new Date(), updatedAt: new Date() });
await db.insert(companies).values({ id: companyId, name: "Cloud SSH task", issuePrefix: engine === "cli" ? "HCLI" : "HACP", defaultResponsibleUserId: userId });
await db.insert(companies).values({ id: companyId, name: "Cloud SSH task", issuePrefix: `SSH${runs.findIndex(run => run.key === key)}`, defaultResponsibleUserId: userId });
await db.insert(companyMemberships).values({ companyId, principalId: userId, principalType: "user", status: "active", membershipRole: "member" });
const account = await aiConnectionService(db).save(companyId, userId, { provider: "anthropic", method: "api_key",
ownership: "personal", name: "Selected test account", apiKey: "synthetic-selected-ssh-key", agentIds: [], allAgents: true }, "synthetic-selected-ssh-key");
const account = provider ? await aiConnectionService(db).save(companyId, userId, { provider: provider as AiProvider, method: "api_key",
ownership: "personal", name: "Selected test account", apiKey: "synthetic-selected-ssh-key", agentIds: [], allAgents: true }, "synthetic-selected-ssh-key") : null;
const config = await buildSshEnvLabFixtureConfig(sshd!);
const command = path.join(root, `fake-claude-${engine}`);
const command = path.join(root, `fake-${key}`);
await writeFile(command, `#!${process.execPath}
if (process.argv.includes('--version')) { console.log('2.1.0'); process.exit(0); }
if (process.env.ANTHROPIC_API_KEY !== 'synthetic-selected-ssh-key') process.exit(91);
if (process.argv.includes('models')) { console.log(${JSON.stringify(model)}); process.exit(0); }
if (process.env[${JSON.stringify(authEnv)}] !== 'synthetic-selected-ssh-key') process.exit(91);
const fs = require('fs'), path = require('path');
const history = path.join(process.env.CLAUDE_CONFIG_DIR, 'projects', 'fixture-history');
const harness = ${JSON.stringify(adapterType)};
const history = harness === 'claude_local' ? path.join(process.env.CLAUDE_CONFIG_DIR, 'projects', 'fixture-history') : path.join(process.cwd(), '.fixture-provider-history');
const runTask = (resumed) => {
if (resumed && !fs.existsSync(history)) throw Error('Missing provider conversation history');
fs.mkdirSync(path.dirname(history), {recursive:true}); fs.writeFileSync(history, 'provider conversation state');
@@ -246,26 +260,63 @@ if (process.argv.includes('--acp-fixture')) {
} catch (error) { send({jsonrpc:'2.0',id:request.id,error:{code:-32603,message:error.message}}); }
});
} else {
runTask(process.argv.includes('--resume'));
console.log(JSON.stringify({type:'result',subtype:'success',is_error:false,result:'Created hello_world.txt',session_id:'12345678-1234-4abc-9def-123456789012',total_cost_usd:0,usage:{input_tokens:1,output_tokens:1}}));
const id = '12345678-1234-4abc-9def-123456789012';
const resumed = ['--resume', 'resume', '-r'].some(arg => process.argv.includes(arg))
|| (harness === 'opencode_local' && process.argv.includes('--session'))
|| (harness === 'pi_local' && fs.existsSync('hello_world.txt'));
runTask(resumed);
const emit = value => console.log(JSON.stringify(value));
if (harness === 'codex_local') {
emit({type:'thread.started',thread_id:id}); emit({type:'item.completed',item:{type:'agent_message',text:'Created hello_world.txt'}});
emit({type:'turn.completed',usage:{input_tokens:1,output_tokens:1}});
} else if (harness === 'gemini_local') {
emit({type:'system',subtype:'init',session_id:id}); emit({type:'message',role:'assistant',content:'Created hello_world.txt'});
emit({type:'result',status:'success',session_id:id,stats:{input_tokens:1,output_tokens:1}});
} else if (harness === 'kimi_local') {
emit({role:'assistant',content:'Created hello_world.txt'}); emit({role:'meta',type:'session.resume_hint',session_id:id});
} else if (harness === 'opencode_local') {
emit({type:'text',sessionID:id,part:{text:'Created hello_world.txt'}});
emit({type:'step_finish',sessionID:id,part:{cost:0,tokens:{input:1,output:1,cache:{read:0,write:0}}}});
} else if (harness === 'pi_local') {
emit({type:'turn_end',message:{role:'assistant',content:'Created hello_world.txt',usage:{input:1,output:1}},toolResults:[]});
} else if (harness === 'grok_local') {
emit({type:'message',data:'Created hello_world.txt'}); emit({type:'end',sessionId:id,stopReason:'EndTurn',usage:{input_tokens:1,output_tokens:1}});
} else emit({type:'result',subtype:'success',is_error:false,result:'Created hello_world.txt',session_id:id,total_cost_usd:0,usage:{input_tokens:1,output_tokens:1}});
}
`, { mode: 0o700 });
const storedConfig = await normalizeEnvironmentConfigForPersistence({ db, companyId, environmentName: `Heartbeat SSH ${engine}`,
driver: "ssh", secretProvider: "local_encrypted", config: { ...config, useHostAuth: false } });
const [environment] = await db.insert(environments).values({ driver: "ssh", name: `Heartbeat SSH ${engine}`, config: storedConfig }).returning();
const storedConfig = await normalizeEnvironmentConfigForPersistence({ db, companyId, environmentName: `Heartbeat SSH ${key}`,
driver: "ssh", secretProvider: "local_encrypted", config: { ...config, useHostAuth: !provider } });
const [environment] = await db.insert(environments).values({ driver: "ssh", name: `Heartbeat SSH ${key}`, config: storedConfig }).returning();
await secretService(db).replaceSecretRefsForInstanceTarget({ targetType: "environment", targetId: environment.id },
await collectEnvironmentSecretRefs({ db, environment: { id: environment.id, driver: "ssh", config: storedConfig } }));
const adapterConfig = { command, ...(engine === "cli" ? { engine: "cli" } : { agentCommand: `${shellQuote(command)} --acp-fixture`, acpWarmHandleIdleMs: 60_000 }),
model: "claude-sonnet-4-6", timeoutSec: 20 };
await db.insert(agents).values({ id: agentId, companyId, name: "Claude SSH task", adapterType: "claude_local", status: "idle",
model, timeoutSec: 20, ...(!provider ? { env: { [authEnv]: "synthetic-selected-ssh-key" } } : {}) };
await db.insert(agents).values({ id: agentId, companyId, name: `${adapterType} SSH task`, adapterType, status: "idle",
defaultEnvironmentId: environment.id, adapterConfig,
runtimeConfig: { aiConnection: { provider: "anthropic", method: "api_key", mode: "delegated", connectionId: account.connectionId, grantId: account.grantId } } });
runtimeConfig: account ? { aiConnection: { provider, method: "api_key", mode: "delegated", connectionId: account.connectionId, grantId: account.grantId } } : {} });
await db.insert(issues).values({ id: issueId, companyId, title: "Create hello_world.txt", status: "todo", assigneeAgentId: agentId,
responsibleUserId: userId, issueNumber: 1 });
const adapter = getServerAdapter("claude_local"), execute = adapter.execute;
expect(adapter.type).toBe("claude_local");
const adapter = getServerAdapter(adapterType), execute = adapter.execute;
expect(adapter.type).toBe(adapterType);
const executing = vi.spyOn(adapter, "execute").mockImplementation(async input => {
const result = await execute(input);
const target = input.executionTarget;
expect(target).toMatchObject({ kind: "remote", transport: "ssh", workspaceRealization: { mode: "in_place" } });
const remoteCwd = target!.kind === "remote" ? target!.remoteCwd : "";
const localAccesses: string[] = [];
const guards = (["stat", "mkdir"] as const).map(method => {
const original = fs[method].bind(fs);
return vi.spyOn(fs, method).mockImplementation(((candidate: unknown, ...args: unknown[]) => {
if (typeof candidate === "string" && (candidate === remoteCwd || candidate.startsWith(remoteCwd + path.sep))) {
localAccesses.push(method);
return Promise.reject(Object.assign(new Error("SSH workspace is unavailable on the controller"), { code: "EACCES" }));
}
return (original as (...args: unknown[]) => unknown)(candidate, ...args);
}) as never);
});
let result;
try { result = await execute(input); }
finally { for (const guard of guards) guard.mockRestore(); }
expect(localAccesses).toEqual([]);
// The synthetic provider stands in for the final task update too.
if (result.exitCode === 0) await db.update(issues).set({ status: "in_review" }).where(eq(issues.id, issueId));
return result;