mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-31 06:04:11 +01:00
## Thinking Path > - Paperclip lets people manage AI agents and their work. > - Legacy adapters launch provider CLIs and expose connected tools. > - Existing defaults did not consistently grant full automatic permission. > - Remote Claude used a fixed tool list that omitted MCP tools and future tools. > - Direct Codex launches and OpenCode configuration also used narrower defaults. > - This change gives all these paths the same full-auto default as native runners. > - Explicit restrictive settings continue to work. ## Linked Issues or Issue Description Refs #13686. This PR is stacked on that native-runner and task-reassignment PR. Merge #13686 first. Related: #831 (constructed Claude agents), #1935 (adapter-switching permission defaults). ## What Changed - Use actual Claude permission bypass for local and remote runs and probes. Remove the fixed tool list so MCP and future provider tools are included. - Identify actual managed sandbox targets to Claude with `IS_SANDBOX=1`. Do not mark ordinary host execution as a sandbox. - Default direct Codex execution to approval and sandbox bypass, matching agent creation. Preserve explicit false, CLI profiles, sandbox modes, approval policy, and network restrictions. - Set OpenCode's full-auto runtime permission to `allow` for every tool and connection. Preserve the existing explicit opt-out. - Default Gemini probes to the same YOLO mode as execution. Make the legacy ACP `default` alias use `approve-all` for fresh and resumed sessions. - Add default, opt-out, remote, probe, connected-tool, and resume regression tests. Update adapter configuration documentation. - Other adapter paths already request full automatic permission or have no provider approval gate. ## Verification - Full workspace `pnpm -r typecheck` and `pnpm build` passed locally after rebasing onto current master. Targeted adapter/server and legacy ACP tests passed, including defaults, explicit opt-outs, remote launches, connected tools, and fresh/resumed sessions. - Greptile reviewed current head `8ca135eaffcf9cfdba6f1368e896a781a0891d50` at **5/5**. The security reviewer acknowledged the documented full-auto requirement. Acknowledged discussions are resolved. - Current head has **54 passing checks**. [PR checks](https://github.com/paperclipai/paperclip/pull/13693/checks). The process-adapter signoff browser shard passed on one retry after its first attempt exceeded a three-second issue-run wait. - **Six native Claude/Codex real-provider cases passed on their first attempt, with cleanup passing**, against the combined branch: plans, reassignment, and backlog creation/status. [Campaign and downloadable evidence](https://github.com/paperclipai/paperclip/actions/runs/35469926548). This does not claim a real-provider run of every legacy adapter. - The live-tested revision is `a37881c824dcd7170380fc4b788732fc743e5da7`. The current head differs only in the corrected heartbeat test expectation; application code is identical. - The campaign result-enforcement job passed. The separate report publisher failed during frozen dependency installation because the trusted workflow's patched-dependency configuration does not match its lockfile. Passing case evidence remains downloadable from the workflow. - Full-suite coverage comes from CI partitions. The separate unsharded local run was stopped after the corresponding CI partitions passed; it is not counted as a completed local run. ## Risks - Missing permission settings now grant all provider operations, including connected tools. OpenCode full-auto also overrides ambient provider permission rules. An explicit Paperclip permission opt-out preserves restrictive behavior. - Claude refuses full bypass as root outside an identified sandbox. Ordinary host deployments must run Claude as a non-root user. Managed sandbox launches include the required marker. - These defaults do not grant additional Paperclip roles, connections, or company access. Existing controller authorization and governance still apply. - This PR depends on #13686. Retarget it to master after that PR merges. ## Model Used OpenAI Codex, based on GPT-6, with code execution and repository tools. The exact deployment model ID and context-window size are not exposed in this session. ## 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>
324 lines
13 KiB
TypeScript
324 lines
13 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { prepareOpenCodeRuntimeConfig } from "./runtime-config.js";
|
|
|
|
const cleanupPaths = new Set<string>();
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
[...cleanupPaths].map(async (filepath) => {
|
|
await fs.rm(filepath, { recursive: true, force: true });
|
|
cleanupPaths.delete(filepath);
|
|
}),
|
|
);
|
|
});
|
|
|
|
async function makeConfigHome(initialConfig?: Record<string, unknown>) {
|
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-opencode-test-"));
|
|
cleanupPaths.add(root);
|
|
const configDir = path.join(root, "opencode");
|
|
await fs.mkdir(configDir, { recursive: true });
|
|
if (initialConfig) {
|
|
await fs.writeFile(
|
|
path.join(configDir, "opencode.json"),
|
|
`${JSON.stringify(initialConfig, null, 2)}\n`,
|
|
"utf8",
|
|
);
|
|
}
|
|
return root;
|
|
}
|
|
|
|
describe("prepareOpenCodeRuntimeConfig", () => {
|
|
it("allows all tools and connected tools by default", async () => {
|
|
const configHome = await makeConfigHome({
|
|
permission: {
|
|
read: "allow",
|
|
bash: "ask",
|
|
"mcp__example__write": "deny",
|
|
},
|
|
theme: "system",
|
|
});
|
|
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome },
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
|
|
expect(prepared.env.XDG_CONFIG_HOME).not.toBe(configHome);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(
|
|
path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"),
|
|
"utf8",
|
|
),
|
|
) as Record<string, unknown>;
|
|
expect(runtimeConfig).toMatchObject({
|
|
theme: "system",
|
|
permission: "allow",
|
|
});
|
|
|
|
await prepared.cleanup();
|
|
cleanupPaths.delete(prepared.env.XDG_CONFIG_HOME);
|
|
await expect(fs.access(prepared.env.XDG_CONFIG_HOME)).rejects.toThrow();
|
|
});
|
|
|
|
it("merges custom providers from PAPERCLIP_OPENCODE_PROVIDERS into the config", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const providers = {
|
|
bifrost: {
|
|
npm: "@ai-sdk/openai-compatible",
|
|
name: "Bifrost EU",
|
|
options: {
|
|
baseURL: "http://gateway.example.svc.cluster.local:8080/v1",
|
|
apiKey: "{env:ANTHROPIC_API_KEY}",
|
|
},
|
|
models: { "example/model-a": { name: "Model A" } },
|
|
},
|
|
};
|
|
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: {
|
|
XDG_CONFIG_HOME: configHome,
|
|
PAPERCLIP_OPENCODE_PROVIDERS: JSON.stringify(providers),
|
|
},
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as Record<string, unknown>;
|
|
expect(runtimeConfig).toMatchObject({
|
|
permission: "allow",
|
|
provider: providers,
|
|
});
|
|
expect(prepared.notes.some((n) => n.includes("bifrost"))).toBe(true);
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("reads PAPERCLIP_OPENCODE_PROVIDERS from process.env when absent from the run env", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const providers = { bifrost: { npm: "@ai-sdk/openai-compatible", models: { "example/model-a": {} } } };
|
|
process.env.PAPERCLIP_OPENCODE_PROVIDERS = JSON.stringify(providers);
|
|
try {
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome },
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as Record<string, unknown>;
|
|
expect(runtimeConfig).toMatchObject({ provider: providers });
|
|
await prepared.cleanup();
|
|
} finally {
|
|
delete process.env.PAPERCLIP_OPENCODE_PROVIDERS;
|
|
}
|
|
});
|
|
|
|
it("expands {env:VAR} placeholders in custom providers using the run/process env (bakes the literal vk)", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const providers = {
|
|
bifrost: {
|
|
npm: "@ai-sdk/openai-compatible",
|
|
options: { baseURL: "http://bifrost/v1", apiKey: "{env:ANTHROPIC_API_KEY}" },
|
|
models: { "example/model-a": {} },
|
|
},
|
|
};
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome, PAPERCLIP_OPENCODE_PROVIDERS: JSON.stringify(providers), ANTHROPIC_API_KEY: "sk-bf-REALVK" },
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as { provider: { bifrost: { options: { apiKey: string } } } };
|
|
// The {env:...} placeholder must be replaced with the literal value, so OpenCode
|
|
// does not depend on its sandboxed process env carrying the key.
|
|
expect(runtimeConfig.provider.bifrost.options.apiKey).toBe("sk-bf-REALVK");
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("leaves an unresolvable {env:VAR} placeholder intact", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const providers = { bifrost: { options: { apiKey: "{env:DEFINITELY_UNSET_VAR_XYZ}" }, models: { "x/y": {} } } };
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome, PAPERCLIP_OPENCODE_PROVIDERS: JSON.stringify(providers) },
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as { provider: { bifrost: { options: { apiKey: string } } } };
|
|
expect(runtimeConfig.provider.bifrost.options.apiKey).toBe("{env:DEFINITELY_UNSET_VAR_XYZ}");
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("pins small_model from PAPERCLIP_OPENCODE_SMALL_MODEL", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome, PAPERCLIP_OPENCODE_SMALL_MODEL: "example/model-a" },
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as { small_model?: string };
|
|
expect(runtimeConfig.small_model).toBe("example/model-a");
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("ignores malformed PAPERCLIP_OPENCODE_PROVIDERS without writing a provider block and surfaces a note", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome, PAPERCLIP_OPENCODE_PROVIDERS: "not json" },
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as Record<string, unknown>;
|
|
expect(runtimeConfig.provider).toBeUndefined();
|
|
expect(prepared.notes).toContain(
|
|
"PAPERCLIP_OPENCODE_PROVIDERS contains invalid JSON; custom providers ignored.",
|
|
);
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("surfaces a note when PAPERCLIP_OPENCODE_PROVIDERS is valid JSON but not an object", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome, PAPERCLIP_OPENCODE_PROVIDERS: "[1,2,3]" },
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as Record<string, unknown>;
|
|
expect(runtimeConfig.provider).toBeUndefined();
|
|
expect(prepared.notes).toContain(
|
|
"PAPERCLIP_OPENCODE_PROVIDERS is set but is not a JSON object; custom providers ignored.",
|
|
);
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("surfaces skipped provider entries with non-object values and keeps the usable ones", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: {
|
|
XDG_CONFIG_HOME: configHome,
|
|
PAPERCLIP_OPENCODE_PROVIDERS: JSON.stringify({
|
|
bifrost: "http://gateway.example/v1",
|
|
usable: { options: { baseURL: "http://gateway.example/v1" } },
|
|
}),
|
|
},
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as { provider?: Record<string, unknown> };
|
|
expect(runtimeConfig.provider?.usable).toBeDefined();
|
|
expect(runtimeConfig.provider?.bifrost).toBeUndefined();
|
|
expect(prepared.notes).toContain(
|
|
"PAPERCLIP_OPENCODE_PROVIDERS: skipped provider(s) with non-object values: bifrost.",
|
|
);
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("surfaces skipped provider entries when no usable entries remain", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: {
|
|
XDG_CONFIG_HOME: configHome,
|
|
PAPERCLIP_OPENCODE_PROVIDERS: JSON.stringify({ bifrost: "http://gateway.example/v1" }),
|
|
},
|
|
config: {},
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as Record<string, unknown>;
|
|
expect(runtimeConfig.provider).toBeUndefined();
|
|
expect(prepared.notes).toContain(
|
|
"PAPERCLIP_OPENCODE_PROVIDERS: skipped provider(s) with non-object values: bifrost.",
|
|
);
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("registers a configured model missing from the catalog on its provider", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome },
|
|
config: { model: "openrouter/openai/gpt-oss-120b:nitro" },
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as { provider?: Record<string, { models?: Record<string, unknown> }> };
|
|
expect(runtimeConfig.provider?.openrouter?.models).toEqual({
|
|
"openai/gpt-oss-120b:nitro": {},
|
|
});
|
|
expect(prepared.notes).toContain(
|
|
"Registered configured model openrouter/openai/gpt-oss-120b:nitro in the runtime OpenCode config.",
|
|
);
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("does not clobber an explicit model definition when registering the configured model", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const providers = {
|
|
openrouter: {
|
|
models: {
|
|
"openai/gpt-oss-120b:nitro": { name: "GPT-OSS 120B (nitro)" },
|
|
"example/other": {},
|
|
},
|
|
},
|
|
};
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: {
|
|
XDG_CONFIG_HOME: configHome,
|
|
PAPERCLIP_OPENCODE_PROVIDERS: JSON.stringify(providers),
|
|
},
|
|
config: { model: "openrouter/openai/gpt-oss-120b:nitro" },
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as { provider?: Record<string, { models?: Record<string, unknown> }> };
|
|
expect(runtimeConfig.provider?.openrouter?.models).toEqual(providers.openrouter.models);
|
|
expect(
|
|
prepared.notes.some((note) => note.startsWith("Registered configured model")),
|
|
).toBe(false);
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("skips model registration when the configured model is not provider/model shaped", async () => {
|
|
const configHome = await makeConfigHome({ permission: { read: "allow" } });
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome },
|
|
config: { model: "not-a-provider-model" },
|
|
});
|
|
cleanupPaths.add(prepared.env.XDG_CONFIG_HOME);
|
|
const runtimeConfig = JSON.parse(
|
|
await fs.readFile(path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8"),
|
|
) as Record<string, unknown>;
|
|
expect(runtimeConfig.provider).toBeUndefined();
|
|
await prepared.cleanup();
|
|
});
|
|
|
|
it("respects explicit opt-out", async () => {
|
|
const configHome = await makeConfigHome();
|
|
const prepared = await prepareOpenCodeRuntimeConfig({
|
|
env: { XDG_CONFIG_HOME: configHome },
|
|
config: { dangerouslySkipPermissions: false },
|
|
});
|
|
|
|
expect(prepared.env).toEqual({ XDG_CONFIG_HOME: configHome });
|
|
expect(prepared.notes).toEqual([]);
|
|
await prepared.cleanup();
|
|
});
|
|
});
|