mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 02:30:43 +01:00
fix(runner): start native OpenCode without postinstall (#15702)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Paperclip Runner starts a qualified OpenCode runtime for native tasks. > - The default launch path uses a file populated by OpenCode's postinstall script. > - Package managers can skip that script and leave a text placeholder. Native task startup then fails with `spawn ENOEXEC` before the model request. > - This pull request resolves the declared platform package directly and includes the pinned runtime in the published server dependency graph. > - Users can run native OpenCode tasks after a normal install without global commands or manual dependency repair. ## Linked Issues or Issue Description **What happened?** Native OpenCode tasks fail at session startup when dependency postinstall is skipped. The Runner selects `opencode-ai/bin/opencode.exe`, which contains a text placeholder. The published server also lacks the OpenCode runtime dependency used by its vendored Runner. **Expected behavior** Paperclip starts the qualified platform binary installed by the package manager. macOS uses a Mac binary. No manual postinstall command is needed. **Steps to reproduce** 1. Install dependencies with lifecycle scripts disabled. 2. Configure a native OpenCode agent with an OpenRouter model and valid credentials. 3. Assign a task. The previous default fails before any model request. Related work: #15682 fixes HTTP transport registration. #15422 includes compatible OpenCode resolution in a broader agent setup change. This PR isolates the runtime repair for current users. ## What Changed - Resolve pinned OpenCode platform packages through the module dependency graph in source, standalone, and vendored server layouts. - Check package identity, version, platform, executable containment, and execute permission. Preserve verified executable launch profiles. - Use the resolver for new and resumed native sessions. Reject missing remote pack executables before controller dependency lookup. - Declare `opencode-ai@1.18.34` as a published server dependency. Leave platform selection to the consumer's package manager. - Check remote paths for the selected provider only. An unused OpenCode path must not reject a Pi run on macOS. - Add skipped-postinstall and invalid artifact regressions. Document automatic runtime selection. ## Verification - Regression tests fail with the previous default path and pass with platform resolution. - Source, standalone, and vendored layout fixtures cover Apple Silicon, Intel Mac, and Linux x64 baseline packages. - A fresh npm install with `--ignore-scripts` resolves the macOS executable and reports `1.18.34`. The placeholder remains unchanged. - Live browser test on Apple Silicon: a native OpenCode/OpenRouter/DeepSeek task ran shell arithmetic, created and uploaded a verified 23-byte file, and completed. A follow-up ran shell arithmetic and completed using the same session. Both runs committed successfully while the wrapper remained broken. - `pnpm -r typecheck` and `pnpm build` passed. All 269 affected Runner tests and 8 server packaging tests passed. `pnpm test:run` encountered 15 initial database-heavy failures; all 15 passed on an isolated group rerun. The redundant local run was then stopped after the matching server and workspace CI suites passed. All final-head checks passed (56 passed, 2 skipped); its unrelated chat-retry browser assertion passed on one rerun. An additional local repeat could not start its temporary server within the startup timeout. Greptile reviewed the final head at 5/5 with no open findings. ## Risks - Native runtime resolution requires the pinned optional platform package. Installations that omit optional dependencies fail with an explicit runtime error. - Supported native targets remain Apple Silicon, Intel Mac, and Linux x64. This change does not qualify another platform. - Published server installations now install the OpenCode dependency. Remote provider packs retain their verified executable paths and digests. - No schema changes or agent configuration migration. - Repository policy assigns `pnpm-lock.yaml` to CI. PR CI refreshes dependency resolution before frozen installs, and the master workflow updates the tracked lockfile. This PR leaves the tracked lockfile unchanged. ## Model Used - OpenAI GPT-6 through Codex, with reasoning, tool use, and code execution. The session does not expose the exact GPT-6 variant or context window. - Live verification used OpenRouter `deepseek/deepseek-v4-flash-0731`; it did not author this patch. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
2bc88ca1c5
commit
6080daf262
7 files changed
+171
-9
No files matched your search
@@ -548,6 +548,15 @@ Activity-only reorderings wait for one second without further activity changes;
|
||||
new and removed tasks appear immediately. Titles, status, and live indicators stay
|
||||
current during that delay.
|
||||
|
||||
### OpenCode native runtime
|
||||
|
||||
Paperclip Runner resolves the pinned OpenCode platform package installed with
|
||||
Paperclip. On Apple Silicon and Intel Macs it runs the matching macOS binary;
|
||||
on Linux x64 it runs the qualified baseline binary. No global OpenCode command
|
||||
or dependency postinstall script is required. This also works when installation
|
||||
scripts are disabled. The published server declares the same pinned dependency
|
||||
as the source Runner package.
|
||||
|
||||
## One-Command Local Run
|
||||
|
||||
For a first-time local install, you can bootstrap and run in one command:
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { chmod, mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { resolvePinnedOpenCodeCommand } from "./opencode-server-driver.js";
|
||||
|
||||
const roots: string[] = [];
|
||||
afterEach(async () => { await Promise.all(roots.splice(0).map(root => rm(root, { recursive: true, force: true }))); });
|
||||
|
||||
async function installed(layout: "source" | "standalone" | "vendored", platform: string, architecture: string, name: string) {
|
||||
const root = await realpath(await mkdtemp(join(tmpdir(), "paperclip-opencode-install-")));
|
||||
roots.push(root);
|
||||
const issuer = join(root, layout === "vendored" ? "dist/vendor/paperclip-runner/drivers/opencode/driver.js"
|
||||
: layout === "source" ? "src/drivers/opencode/driver.ts" : "dist/drivers/opencode/driver.js");
|
||||
const wrapper = join(root, "node_modules/opencode-ai");
|
||||
const artifact = join(root, "node_modules", name);
|
||||
const executable = join(artifact, "bin/opencode");
|
||||
await mkdir(dirname(issuer), { recursive: true });
|
||||
await mkdir(join(wrapper, "bin"), { recursive: true });
|
||||
await mkdir(dirname(executable), { recursive: true });
|
||||
await writeFile(join(wrapper, "package.json"), JSON.stringify({ name: "opencode-ai", version: "1.18.34", optionalDependencies: { [name]: "1.18.34" } }));
|
||||
const placeholder = 'echo "postinstall was not run" >&2\nexit 1\n';
|
||||
await writeFile(join(wrapper, "bin/opencode.exe"), placeholder, { mode: 0o755 });
|
||||
await writeFile(join(artifact, "package.json"), JSON.stringify({ name, version: "1.18.34", os: [platform], cpu: [architecture] }));
|
||||
await writeFile(executable, "#!/bin/sh\necho 1.18.34\n", { mode: 0o755 });
|
||||
return { issuer: pathToFileURL(issuer), wrapper, artifact, executable, root, placeholder };
|
||||
}
|
||||
|
||||
it.each(["source", "standalone", "vendored"] as const)("resolves the platform binary in a %s install with postinstall skipped", async layout => {
|
||||
for (const [platform, architecture, name] of [
|
||||
["darwin", "arm64", "opencode-darwin-arm64"],
|
||||
["darwin", "x64", "opencode-darwin-x64-baseline"],
|
||||
["linux", "x64", "opencode-linux-x64-baseline"],
|
||||
] as const) {
|
||||
const install = await installed(layout, platform, architecture, name);
|
||||
expect(resolvePinnedOpenCodeCommand(install.issuer, { platform, architecture })).toBe(install.executable);
|
||||
expect(await readFile(join(install.wrapper, "bin/opencode.exe"), "utf8")).toBe(install.placeholder);
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects missing or mismatched qualified dependencies", async () => {
|
||||
const install = await installed("vendored", "darwin", "arm64", "opencode-darwin-arm64");
|
||||
await writeFile(join(install.artifact, "package.json"), JSON.stringify({ name: "opencode-darwin-arm64", version: "1.18.17", os: ["darwin"], cpu: ["arm64"] }));
|
||||
expect(() => resolvePinnedOpenCodeCommand(install.issuer, { platform: "darwin", architecture: "arm64" })).toThrow("identity mismatch");
|
||||
await rm(install.artifact, { recursive: true });
|
||||
expect(() => resolvePinnedOpenCodeCommand(install.issuer, { platform: "darwin", architecture: "arm64" })).toThrow("qualified platform dependency is missing");
|
||||
expect(() => resolvePinnedOpenCodeCommand(install.issuer, { platform: "win32", architecture: "x64" })).toThrow("not qualified");
|
||||
});
|
||||
|
||||
it("rejects executables outside the platform package or without execute permission", async () => {
|
||||
const install = await installed("source", "darwin", "arm64", "opencode-darwin-arm64");
|
||||
await chmod(install.executable, 0o644);
|
||||
expect(() => resolvePinnedOpenCodeCommand(install.issuer, { platform: "darwin", architecture: "arm64" })).toThrow("Pinned OpenCode runtime unavailable");
|
||||
await rm(install.executable);
|
||||
const outside = join(install.root, "outside");
|
||||
await writeFile(outside, "#!/bin/sh\n", { mode: 0o755 });
|
||||
await symlink(outside, install.executable);
|
||||
expect(() => resolvePinnedOpenCodeCommand(install.issuer, { platform: "darwin", architecture: "arm64" })).toThrow("escapes its qualified platform package");
|
||||
});
|
||||
@@ -1,5 +1,7 @@
|
||||
import { spawn, type ChildProcess } from "node:child_process";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { accessSync, constants, readFileSync, realpathSync, statSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import {
|
||||
chmod,
|
||||
mkdir,
|
||||
@@ -15,7 +17,7 @@ import { Agent as HttpAgent, createServer as createHttpServer, request as reques
|
||||
import { Agent as HttpsAgent, request as requestHttps } from "node:https";
|
||||
import { getCACertificates } from "node:tls";
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
||||
|
||||
import {
|
||||
CODEX_SKILLLESS_BASE_INSTRUCTIONS,
|
||||
@@ -83,6 +85,69 @@ export const QUALIFIED_OPENCODE_VERSION = "1.18.34" as const;
|
||||
export const QUALIFIED_OPENCODE_MODEL =
|
||||
"openrouter/deepseek/deepseek-v4-flash-0731" as const;
|
||||
|
||||
/** Resolve a declared, pinned native dependency without PATH or install fallback. */
|
||||
export function resolvePinnedOpenCodeCommand(
|
||||
issuer: string | URL = import.meta.url,
|
||||
target: { platform?: string; architecture?: string } = {},
|
||||
): string {
|
||||
try {
|
||||
const platform = target.platform ?? process.platform;
|
||||
const architecture = target.architecture ?? process.arch;
|
||||
const packageNames: Record<string, string[]> = {
|
||||
"linux-x64": ["opencode-linux-x64-baseline"],
|
||||
"darwin-arm64": ["opencode-darwin-arm64"],
|
||||
"darwin-x64": ["opencode-darwin-x64-baseline"],
|
||||
};
|
||||
const candidates = packageNames[`${platform}-${architecture}`];
|
||||
if (!candidates) {
|
||||
throw new Error("OpenCode native target is not qualified");
|
||||
}
|
||||
const manifestPath = realpathSync(createRequire(issuer).resolve("opencode-ai/package.json"));
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
||||
if (manifest.name !== "opencode-ai" || manifest.version !== QUALIFIED_OPENCODE_VERSION) {
|
||||
throw new Error(`OpenCode package version mismatch: expected opencode-ai@${QUALIFIED_OPENCODE_VERSION}`);
|
||||
}
|
||||
const dependencyRequire = createRequire(manifestPath);
|
||||
for (const name of candidates) {
|
||||
if (manifest.optionalDependencies?.[name] !== QUALIFIED_OPENCODE_VERSION) {
|
||||
throw new Error("OpenCode platform dependency does not match its qualified version");
|
||||
}
|
||||
let platformManifest: string;
|
||||
try {
|
||||
platformManifest = realpathSync(dependencyRequire.resolve(`${name}/package.json`));
|
||||
} catch (error) {
|
||||
if (["MODULE_NOT_FOUND", "ENOENT"].includes((error as NodeJS.ErrnoException).code ?? "")) {
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
const metadata = JSON.parse(readFileSync(platformManifest, "utf8"));
|
||||
if (metadata.name !== name || metadata.version !== QUALIFIED_OPENCODE_VERSION
|
||||
|| !Array.isArray(metadata.os) || !metadata.os.includes(platform)
|
||||
|| !Array.isArray(metadata.cpu) || !metadata.cpu.includes(architecture)) {
|
||||
throw new Error("OpenCode installed platform artifact identity mismatch");
|
||||
}
|
||||
const root = dirname(platformManifest);
|
||||
const executable = realpathSync(resolve(root, "bin/opencode"));
|
||||
const inside = relative(root, executable);
|
||||
if (!inside || inside === ".." || inside.startsWith(`..${sep}`) || isAbsolute(inside)) {
|
||||
throw new Error("OpenCode executable escapes its qualified platform package");
|
||||
}
|
||||
if (!statSync(executable).isFile()) {
|
||||
throw new Error("OpenCode executable is not a regular file");
|
||||
}
|
||||
accessSync(executable, constants.X_OK);
|
||||
return executable;
|
||||
}
|
||||
throw new Error("OpenCode qualified platform dependency is missing");
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Pinned OpenCode runtime unavailable: ${(error as Error).message}. Restore Paperclip's runtime dependencies.`,
|
||||
{ cause: error },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
type DynamicToolHandler = (call: {
|
||||
tool: string;
|
||||
callId: string;
|
||||
@@ -2255,7 +2320,7 @@ async function startRuntime(input: {
|
||||
}
|
||||
input.options.commandLifecycle?.beforeSpawn();
|
||||
child = spawn(
|
||||
input.options.command ?? "opencode",
|
||||
input.options.command ?? resolvePinnedOpenCodeCommand(),
|
||||
["serve", "--hostname", "127.0.0.1", "--port", String(port)],
|
||||
{
|
||||
cwd: input.cwd,
|
||||
|
||||
@@ -1587,6 +1587,15 @@ it.each(["acpx-runtime-sidecar.cjs", "opencode-app-server-proxy.cjs"] as const)(
|
||||
},
|
||||
);
|
||||
|
||||
it("requires a remote OpenCode executable before resolving controller dependencies", () => {
|
||||
expect(() => runnerdLaunchProfileInternals.resolveRunnerOpenCodeExecutable({
|
||||
runnerFilesystemRoot: "/provider-pack",
|
||||
})).toThrow("OpenCode executable is missing from the provider pack");
|
||||
expect(runnerdLaunchProfileInternals.resolveRunnerOpenCodeExecutable({
|
||||
runnerFilesystemRoot: "/provider-pack", opencodeCommand: "/provider-pack/opencode",
|
||||
})).toBe("/provider-pack/opencode");
|
||||
});
|
||||
|
||||
it("derives the ACPX package authority only from the verified dist/cli layout", () => {
|
||||
const runnerPackageRoot = fileURLToPath(new URL("../..", import.meta.url));
|
||||
expect(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { resolvePinnedOpenCodeCommand } from "../drivers/opencode/opencode-server-driver.js";
|
||||
import { ACPX_CAPABILITY_PROFILES } from "../drivers/acpx/capability-profiles.js";
|
||||
import { admittedPiThinkingLevel, resolvePiThinkingLevel } from "../drivers/acpx/pi-thinking.js";
|
||||
import { configuredEnvironment } from "../configured-environment.js";
|
||||
@@ -3182,6 +3183,14 @@ function opencodeRunnerLaunchProfile(
|
||||
};
|
||||
}
|
||||
|
||||
function resolveRunnerOpenCodeExecutable(options: RunnerdCodexTransportOptions): string {
|
||||
if (options.opencodeCommand !== undefined) return options.opencodeCommand;
|
||||
if (options.runnerFilesystemRoot) {
|
||||
throw new Error("runner_remote_provider_artifact_incompatible: OpenCode executable is missing from the provider pack");
|
||||
}
|
||||
return resolvePinnedOpenCodeCommand();
|
||||
}
|
||||
|
||||
function authorizedToolSet(
|
||||
tools: readonly Readonly<Record<string, unknown>>[],
|
||||
): Record<string, unknown> {
|
||||
@@ -4731,8 +4740,7 @@ class DurablePrpCodexTransport implements CodexAppServerTransport {
|
||||
: undefined;
|
||||
const opencodeExecutable =
|
||||
provider === "opencode"
|
||||
? (this.options.opencodeCommand ??
|
||||
resolve(packageRoot, "node_modules/opencode-ai/bin/opencode.exe"))
|
||||
? resolveRunnerOpenCodeExecutable(this.options)
|
||||
: null;
|
||||
const runnerAcpxLaunchProfile =
|
||||
provider === "acpx"
|
||||
@@ -4757,9 +4765,9 @@ class DurablePrpCodexTransport implements CodexAppServerTransport {
|
||||
) {
|
||||
const providerPaths = [
|
||||
["provider Node", providerNodeCommand],
|
||||
["OpenCode proxy", opencodeProxyPath],
|
||||
["ACPX sidecar", acpxSidecarPath],
|
||||
["OpenCode executable", opencodeExecutable ?? "opencode"],
|
||||
...(provider === "opencode"
|
||||
? [["OpenCode proxy", opencodeProxyPath], ["OpenCode executable", opencodeExecutable!]] as const
|
||||
: [["ACPX sidecar", acpxSidecarPath]] as const),
|
||||
] as const;
|
||||
for (const [label, candidate] of providerPaths) {
|
||||
if (
|
||||
@@ -5358,8 +5366,7 @@ class DurablePrpCodexTransport implements CodexAppServerTransport {
|
||||
this.options.providerNodeCommand ?? process.execPath;
|
||||
const opencodeExecutable =
|
||||
provider === "opencode"
|
||||
? (this.options.opencodeCommand ??
|
||||
resolve(packageRoot, "node_modules/opencode-ai/bin/opencode.exe"))
|
||||
? resolveRunnerOpenCodeExecutable(this.options)
|
||||
: null;
|
||||
const runnerAcpxLaunchProfile =
|
||||
provider === "acpx"
|
||||
@@ -7040,6 +7047,7 @@ export const runnerdLaunchProfileInternals = Object.freeze({
|
||||
acpxProviderPackageAuthority,
|
||||
acpxRunnerLaunchProfile,
|
||||
resolveBuildOwnedCliArtifact,
|
||||
resolveRunnerOpenCodeExecutable,
|
||||
maxOutboxBytes: RUNNERD_MAX_OUTBOX_BYTES,
|
||||
p0ReserveBytes: RUNNERD_P0_RESERVE_BYTES,
|
||||
});
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
"nice-grpc": "2.1.17",
|
||||
"nice-grpc-common": "2.0.4",
|
||||
"open": "^11.0.4",
|
||||
"opencode-ai": "1.18.34",
|
||||
"pino": "^10.0.0",
|
||||
"pino-http": "^11.0.0",
|
||||
"pino-pretty": "^13.1.3",
|
||||
|
||||
@@ -103,6 +103,16 @@ describe("server package build script", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("ships the pinned OpenCode dependency resolved by the vendored Runner", () => {
|
||||
const server = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
||||
const runner = JSON.parse(readFileSync(new URL(
|
||||
"../../../packages/paperclip-runner/package.json", import.meta.url,
|
||||
), "utf8"));
|
||||
// createRequire resolution is dynamic and is not covered by the import scan.
|
||||
expect(server.dependencies["opencode-ai"]).toBe("1.18.34");
|
||||
expect(server.dependencies["opencode-ai"]).toBe(runner.dependencies["opencode-ai"]);
|
||||
});
|
||||
|
||||
it("loads runner source when the source server starts before workspace builds", () => {
|
||||
const shim = readFileSync(runnerShimPath, "utf8");
|
||||
|
||||
|
||||
Reference in new issue
Block a user