mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-20 18:26:40 +01:00
feat(plugins): carry Grok, Copilot and OpenCode credentials to plugin Runners (#22359)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Environment-driver plugins can run `paperclip_runner` tasks on hosts
that the plugin owns
> - Core transfers the selected managed AI credential to the plugin as a
typed task credential
> - The credential contract has only two types: a Codex auth file and a
direct Claude credential
> - Grok, GitHub Copilot and OpenCode agents in a task-capable plugin
environment therefore fail closed, although the Runner already reads
their credentials from its environment
> - This pull request adds one generic, allowlisted environment
credential for these three harnesses and accepts the Runner's Grok
launch settings
> - The benefit is that plugin-provided Runner execution can run Grok,
Copilot and OpenCode agents with their selected connection
## Linked Issues or Issue Description
**Subsystem affected**
Plugin environment tasks (`packages/plugins/sdk` task contract) and
plugin-provided Runner execution in `server`.
**Problem or motivation**
An agent with the Grok, Copilot or OpenCode harness cannot run in a
plugin environment that runs Runner tasks. Core stops at credential
preparation with "Plugin Runner does not support the selected credential
provider". A Grok agent fails before that point too. The Runner emits
`grokEffort` and `grokDisableWebSearch` in its launch requirements (Core
turns off Grok web search by default), but the strict `settings` schema
of `environmentRunnerLaunchRequirementsSchema` rejects both keys.
**Proposed solution**
Core transfers the selected connection's credential variables for these
harnesses through one typed `provider-env` credential. Each provider has
a fixed allowlist of complete variable sets. The plugin sets the
variables in the Runner process environment.
**Alternatives considered**
One credential type per harness (`grok-env`, `copilot-env`,
`opencode-env`). This adds a type for each new harness. One generic type
with an exported allowlist keeps the same strictness with less surface.
**Roadmap alignment**
The roadmap lists Grok and OpenCode as supported harnesses. This change
lets plugin environments run them. It adds no new product concept.
**Additional context**
Grok subscription login (an auth file with refresh and writeback) is out
of scope. It still fails closed, with an error that names the xAI API
key as the supported option.
## What Changed
- `packages/plugins/sdk`: Added the `provider-env` task credential: `{
type: "provider-env", provider: "grok" | "copilot" | "opencode",
environment }`. The environment must contain exactly one complete
variable set for the provider and no other variable. Values are
non-empty, NUL-free and at most 65,536 characters, as for the other
credential types.
- `grok`: `XAI_API_KEY`
- `copilot`: `COPILOT_GITHUB_TOKEN`
- `opencode`: `OPENROUTER_API_KEY`, or `PAPERCLIP_AI_PROVIDER_URL` with
`PAPERCLIP_AI_PROVIDER_KEY`
- `packages/plugins/sdk`: Exported the allowlist as
`ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS` and the
`PluginEnvironmentTaskCredentialProvider` type. `claude-env` and
`codex-auth-json` do not change.
- `packages/plugins/sdk`: Added `grokEffort` (`minimal` to `xhigh`) and
`grokDisableWebSearch` (boolean) to the launch requirements `settings`,
with the types that the Runner uses.
- `server`: `preparePluginRunnerCredentials` now transfers the selected
connection's variables for the `grok`, `copilot` and `opencode`
harnesses, with the same account identity semantics as the Claude
branch. It refuses a Grok subscription, a Grok base URL override, and an
incomplete or ambiguous set. The error never contains a credential
value.
- `server`: The submit check now matches a `provider-env` credential to
the task harness. Before, it treated every non-Codex credential as
Anthropic.
- Drift test:
`server/src/__tests__/plugin-runner-credential-names.test.ts` checks the
SDK key sets against the Runner. The SDK list stays written by hand, and
the Runner keeps its own lists of forwarded names. For `grok` and
`copilot`, each name must be in `ACPX_CREDENTIAL_NAMES`, survive sidecar
admission with the session binding that the Runner mints, and reach the
agent process. The binding requirement must match the Rust sidecar's
candidate agents. For `opencode`, each name must be in the OpenCode
proxy environment set. Each name must also be in the Rust sidecar
credential keys or the Rust OpenCode provider keys. The test reads those
from the Runner source, as the Codex security test does. A provider
without a Runner route fails the test.
`OPEN_CODE_RUNNER_ENVIRONMENT_KEYS` is now exported for this test.
- Docs: Added a "Typed credentials" section to
`doc/plugins/PLUGIN_ENVIRONMENT_TASKS.md`. It also documents the ACPX
credential binding that the Runner requires with a Copilot token.
Updated `doc/plugins/PLUGIN_RUNNER_EXECUTION.md`.
## Verification
- `npx vitest run tests/environment-task-release-resume.test.ts
tests/environment-tasks.test.ts` in `packages/plugins/sdk`: 96 passed.
The tests accept each valid shape. They reject mixed sets, two sets,
extra variables, another provider's variable, empty values, NUL bytes,
oversized values, unknown providers and extra fields, on `submit` and on
`resume`. They also check that every published allowlist set parses.
- `npx vitest run
src/services/native-runtime/plugin-runner-credentials.test.ts
src/__tests__/environment-task-runtime.test.ts` in `server`: 79 passed.
The new tests cover each provider's transfer, Grok subscription refusal,
Grok routing refusal, the fail-closed cases without value leaks, harness
matching at submit, and Runner-built Grok requirements
(`runnerProviderLaunchRequirements`) that parse through the task
contract and produce a Grok launch.
- `npx vitest run src/__tests__/plugin-runner-credential-names.test.ts`
in `server`: 4 passed. I broke each list locally to confirm that the
test fails: a renamed SDK key, an SDK provider without a Runner route,
and a dropped name in the Rust sidecar keys, the Rust candidate agents,
the Rust OpenCode keys and the TypeScript OpenCode keys. Each change
failed the test.
- `node scripts/typecheck-layers.mjs` in `server` (includes
`src/__tests__`): no errors.
- `npx vitest run
server/src/services/native-runtime/plugin-runner-probe.test.ts` (from
the root): 15 passed.
`server/src/services/native-runtime/plugin-runner-task.test.ts`: passed.
- `tsc --noEmit` for `packages/plugins/sdk` and `server`: no errors.
- I did not run the full suite locally. CI supplies that coverage.
## Risks
- Low risk for existing plugins. The change only adds a credential type
and two optional settings. A plugin that does not handle `provider-env`
gets a typed value that it does not recognize. Before this change, Core
failed these runs before it called the plugin.
- A plugin must set `PAPERCLIP_ACPX_CREDENTIAL_BINDING` for a Copilot
task. Otherwise the Runner refuses the token. The new doc section shows
the value.
- An OpenCode gateway connection without a key (`auth: none`) still
fails closed, because every value must be non-empty.
> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`) by Anthropic, through Claude Code
with tool use (shell, file edits, test runs).
## 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
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a0fe90f24b
commit
dce4d47f60
13 files changed
+267
-13
No files matched your search
@@ -56,10 +56,29 @@ export const environmentTaskConfiguredEnvironmentSchema = z.record(
|
||||
});
|
||||
export type PluginEnvironmentTaskConfiguredEnvironment = z.infer<typeof environmentTaskConfiguredEnvironmentSchema>;
|
||||
|
||||
export const ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS = {
|
||||
grok: [["XAI_API_KEY"]],
|
||||
copilot: [["COPILOT_GITHUB_TOKEN"]],
|
||||
opencode: [["OPENROUTER_API_KEY"], ["PAPERCLIP_AI_PROVIDER_URL", "PAPERCLIP_AI_PROVIDER_KEY"]],
|
||||
} as const satisfies Record<string, readonly (readonly string[])[]>;
|
||||
export type PluginEnvironmentTaskCredentialProvider = keyof typeof ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS;
|
||||
const providerCredential = z.object({
|
||||
type: z.literal("provider-env"),
|
||||
provider: z.enum(["grok", "copilot", "opencode"]),
|
||||
environment: z.record(z.string(), credentialValue),
|
||||
}).strict().superRefine((credential, ctx) => {
|
||||
const names = Object.keys(credential.environment).sort();
|
||||
const sets: readonly (readonly string[])[] = ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS[credential.provider];
|
||||
if (!sets.some(set => set.length === names.length && [...set].sort().every((name, index) => name === names[index]))) {
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Select one complete credential for the provider", path: ["environment"] });
|
||||
}
|
||||
});
|
||||
|
||||
/** Only provider authentication is transferred. Paths and executable settings remain provider-owned. */
|
||||
export const environmentTaskCredentialSchema = z.discriminatedUnion("type", [
|
||||
z.object({ type: z.literal("codex-auth-json"), authJson: credentialValue }).strict(),
|
||||
z.object({ type: z.literal("claude-env"), environment: claudeCredentialEnvironment }).strict(),
|
||||
providerCredential,
|
||||
]);
|
||||
export type PluginEnvironmentTaskCredential = z.infer<typeof environmentTaskCredentialSchema>;
|
||||
|
||||
@@ -74,6 +93,8 @@ export const environmentRunnerLaunchRequirementsSchema = z.object({
|
||||
acpxPermissionMode: z.enum(["approve-all", "approve-paperclip", "approve-reads", "deny-all"]).optional(),
|
||||
acpxPermissionModePinned: z.boolean().optional(), piThinkingLevel: z.enum(["off", "low", "high", "max"]).optional(),
|
||||
claudeEffort: z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
||||
grokEffort: z.enum(["minimal", "low", "medium", "high", "xhigh"]).optional(),
|
||||
grokDisableWebSearch: z.boolean().optional(),
|
||||
opencodePermissionMode: z.enum(["allow", "ask", "deny"]).optional(),
|
||||
disableCodexWebSearch: z.literal(true).optional(),
|
||||
disableCodexProjectInstructions: z.literal(true).optional(),
|
||||
|
||||
@@ -498,8 +498,8 @@ export type { PluginEnvironmentTaskErrorDiagnostic } from "./environment-task-er
|
||||
|
||||
export type { AiConnectionPool, AiConnectionPoolConfig, AiConnectionPoolMember, AiConnectionRouterRequest, AiConnectionRouterResult, AiConnectionRouterSelection } from "@paperclipai/shared";
|
||||
|
||||
export { MAX_ENVIRONMENT_TASK_FILE_BYTES, environmentRunnerLaunchRequirementsSchema, environmentTaskOperationSchema, environmentTaskResultSchema, environmentTaskCredentialSchema, environmentTaskConfiguredEnvironmentSchema, MAX_CONFIGURED_ENVIRONMENT_KEYS, MAX_CONFIGURED_ENVIRONMENT_ENTRY_BYTES, MAX_CONFIGURED_ENVIRONMENT_BYTES, parseEnvironmentTaskResult } from "./environment-tasks.js";
|
||||
export type { PluginEnvironmentTaskOperation, PluginEnvironmentTaskParams, PluginEnvironmentTaskResult, PluginEnvironmentTaskCredential, PluginEnvironmentTaskConfiguredEnvironment, PluginEnvironmentTaskExecutionContext } from "./environment-tasks.js";
|
||||
export { MAX_ENVIRONMENT_TASK_FILE_BYTES, ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS, environmentRunnerLaunchRequirementsSchema, environmentTaskOperationSchema, environmentTaskResultSchema, environmentTaskCredentialSchema, environmentTaskConfiguredEnvironmentSchema, MAX_CONFIGURED_ENVIRONMENT_KEYS, MAX_CONFIGURED_ENVIRONMENT_ENTRY_BYTES, MAX_CONFIGURED_ENVIRONMENT_BYTES, parseEnvironmentTaskResult } from "./environment-tasks.js";
|
||||
export type { PluginEnvironmentTaskOperation, PluginEnvironmentTaskParams, PluginEnvironmentTaskResult, PluginEnvironmentTaskCredential, PluginEnvironmentTaskCredentialProvider, PluginEnvironmentTaskConfiguredEnvironment, PluginEnvironmentTaskExecutionContext } from "./environment-tasks.js";
|
||||
export type { AgentLifecycleRequest, AgentLifecycleResult } from "@paperclipai/shared";
|
||||
|
||||
export type { PluginEnvironmentRunnerLaunchRequirements, PluginEnvironmentPreparedLaunch } from "./environment-tasks.js";
|
||||
|
||||
@@ -36,6 +36,25 @@ const credentials: [string, unknown, boolean][] = [
|
||||
["an oversized value", { type: "codex-auth-json", authJson: "x".repeat(65_537) }, false],
|
||||
["an unknown type", { type: "gemini-env", environment: { GEMINI_API_KEY: "fixture" } }, false],
|
||||
["an extra field", { type: "codex-auth-json", authJson: "{}", path: "/home/agent/.codex" }, false],
|
||||
["an xAI API key for Grok", { type: "provider-env", provider: "grok", environment: { XAI_API_KEY: "fixture-xai" } }, true],
|
||||
["a Copilot token", { type: "provider-env", provider: "copilot", environment: { COPILOT_GITHUB_TOKEN: "fixture-copilot" } }, true],
|
||||
["an OpenRouter key for OpenCode", { type: "provider-env", provider: "opencode", environment: { OPENROUTER_API_KEY: "fixture-openrouter" } }, true],
|
||||
["an OpenCode gateway", { type: "provider-env", provider: "opencode",
|
||||
environment: { PAPERCLIP_AI_PROVIDER_URL: "https://gateway.example.test/v1", PAPERCLIP_AI_PROVIDER_KEY: "fixture-gateway" } }, true],
|
||||
["half of an OpenCode gateway", { type: "provider-env", provider: "opencode", environment: { PAPERCLIP_AI_PROVIDER_URL: "https://gateway.example.test/v1" } }, false],
|
||||
["a mixed OpenCode set", { type: "provider-env", provider: "opencode",
|
||||
environment: { OPENROUTER_API_KEY: "fixture-openrouter", PAPERCLIP_AI_PROVIDER_KEY: "fixture-gateway" } }, false],
|
||||
["two OpenCode sets", { type: "provider-env", provider: "opencode", environment: { OPENROUTER_API_KEY: "fixture-openrouter",
|
||||
PAPERCLIP_AI_PROVIDER_URL: "https://gateway.example.test/v1", PAPERCLIP_AI_PROVIDER_KEY: "fixture-gateway" } }, false],
|
||||
["another provider's variable", { type: "provider-env", provider: "grok", environment: { COPILOT_GITHUB_TOKEN: "fixture-copilot" } }, false],
|
||||
["an extra provider variable", { type: "provider-env", provider: "grok", environment: { XAI_API_KEY: "fixture-xai", XAI_BASE_URL: "https://router.example.test" } }, false],
|
||||
["no provider variable", { type: "provider-env", provider: "copilot", environment: {} }, false],
|
||||
["an empty provider value", { type: "provider-env", provider: "copilot", environment: { COPILOT_GITHUB_TOKEN: "" } }, false],
|
||||
["a NUL byte in a provider value", { type: "provider-env", provider: "grok", environment: { XAI_API_KEY: "a\0b" } }, false],
|
||||
["an oversized provider value", { type: "provider-env", provider: "grok", environment: { XAI_API_KEY: "x".repeat(65_537) } }, false],
|
||||
["an unsupported provider", { type: "provider-env", provider: "gemini", environment: { GEMINI_API_KEY: "fixture-gemini" } }, false],
|
||||
["a provider credential without a provider", { type: "provider-env", environment: { XAI_API_KEY: "fixture-xai" } }, false],
|
||||
["an extra provider credential field", { type: "provider-env", provider: "grok", environment: { XAI_API_KEY: "fixture-xai" }, home: "/home/agent" }, false],
|
||||
];
|
||||
|
||||
async function invoke(operation: unknown, handler: (params: PluginEnvironmentTaskParams) => Promise<PluginEnvironmentTaskResult>) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {describe,expect,it} from "vitest";
|
||||
import {environmentTaskOperationSchema,environmentTaskResultSchema} from "../src/environment-tasks.js";
|
||||
import {ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS,environmentTaskCredentialSchema,environmentTaskOperationSchema,environmentTaskResultSchema} from "../src/environment-tasks.js";
|
||||
const submit={kind:"submit",projectIds:[],bootstrapTicket:"synthetic",runner:{harness:"codex",protocolMin:1,protocolMax:3,runnerId:"runner",leaseId:"lease",runId:"run",sessionId:"session",turnId:"turn",itemId:"item"},
|
||||
launch:{runnerVersion:"fixture",runnerDigest:`sha256:${"a".repeat(64)}`,maxOutboxBytes:262144,p0ReserveBytes:65536,lifecyclePolicy:{mode:"warm",idleTimeoutMs:300000}}};
|
||||
describe("task lifecycle policy",()=>{
|
||||
@@ -124,3 +124,28 @@ describe("configured environment", () => {
|
||||
expect(environmentTaskResultSchema.safeParse({ ...description, configuredEnvironmentVersion: 2 }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Grok launch settings", () => {
|
||||
const grok = (settings: Record<string, unknown>) => ({ ...prepare, requirements: { ...prepare.requirements,
|
||||
provider: "acpx", settings: { acpxAgent: "grok", ...settings } } });
|
||||
it.each([{ grokDisableWebSearch: true }, { grokDisableWebSearch: false }, { grokEffort: "minimal", grokDisableWebSearch: true },
|
||||
{ grokEffort: "xhigh" }, {}])("accepts the Runner's Grok settings %j", settings => {
|
||||
expect(environmentTaskOperationSchema.parse(grok(settings))).toEqual(grok(settings));
|
||||
});
|
||||
it.each([{ grokEffort: "max" }, { grokEffort: "" }, { grokDisableWebSearch: "true" }, { grokDisableWebSearch: null }])("rejects invalid Grok settings %j", settings => {
|
||||
expect(environmentTaskOperationSchema.safeParse(grok(settings)).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("provider environment credential allowlist", () => {
|
||||
it("accepts every published set and nothing beyond it", () => {
|
||||
for (const [provider, sets] of Object.entries(ENVIRONMENT_TASK_PROVIDER_CREDENTIAL_KEY_SETS)) {
|
||||
for (const set of sets) {
|
||||
const environment = Object.fromEntries(set.map(name => [name, "fixture-value"]));
|
||||
expect(environmentTaskCredentialSchema.safeParse({ type: "provider-env", provider, environment }).success).toBe(true);
|
||||
expect(environmentTaskCredentialSchema.safeParse({ type: "provider-env", provider,
|
||||
environment: { ...environment, UNRELATED_SECRET: "fixture-value" } }).success).toBe(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user