Files
PaperClipAI/packages/shared/src/environment-support.ts
T
Devin Foley 05973b2073 Enable sandbox environments for Grok local adapter (#9338)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Local CLI adapters can run against Paperclip-managed execution
environments instead of only the host filesystem.
> - The environment picker and environment capability API derive sandbox
support from shared adapter capability lists.
> - The Grok Build adapter is implemented as a local CLI adapter, but it
was missing from those shared environment capability lists.
> - That made Grok agents look local-only even when sandbox environments
were configured.
> - This pull request registers `grok_local` in the shared adapter
constants and remote-managed environment support path.
> - The benefit is that Grok Build agents can select the same local,
SSH, and sandbox environment overrides as other local CLI adapters.

## Linked Issues or Issue Description

No public GitHub issue exists for this bug. Inline bug report follows.

### Pre-submission checklist

- [x] I have searched existing open and closed issues and this is not a
duplicate.
- [x] I am on `master`.
- [x] I have confirmed the error originates in Paperclip itself, not in
the Grok adapter provider or local configuration.

### What happened?

When configuring a Grok Build local agent in the board UI, Paperclip did
not expose configured sandbox environments as selectable environment
overrides. The shared environment capability helper treated `grok_local`
as local-only because it was missing from the remote-managed local
adapter allowlist.

### Expected behavior

Grok Build should behave like other local CLI adapters: when
environments are enabled and a runnable sandbox environment exists, the
agent configuration form should show the environment override selector
and allow the sandbox to be selected.

### Steps to reproduce

1. Enable environments in instance experimental settings.
2. Configure at least one runnable sandbox environment.
3. Open the agent configuration form for a Grok Build local agent.
4. Observe that the sandbox environment is not offered as an override
before this fix.

### Paperclip version or commit

`master` before this PR.

### Deployment mode

Local dev (`pnpm dev`).

### Installation method

Built from source (`pnpm dev` / `pnpm build`).

### Agent adapter(s) involved

- Grok Build local adapter.
- Core bug in shared environment capability logic.

### Database mode

Not database-related.

### Access context

Board human operator.

### Relevant logs or output

No runtime error is emitted; the issue is a missing UI option caused by
shared capability metadata.

### Relevant config

No secret-bearing config required. Reproduction only needs environments
enabled and a runnable sandbox environment configured.

### Privacy checklist

- [x] I have reviewed all pasted output for PII, usernames, file paths,
API keys, tokens, company names, and redacted where necessary.

## What Changed

- Added `grok_local` to the shared built-in adapter type list.
- Added `grok_local` to the remote-managed adapter set used by
environment capability helpers.
- Added shared regression coverage for Grok local sandbox provider and
driver support.
- Added a UI render regression test that confirms Grok Build agents show
the environment override when a runnable sandbox exists.

## Verification

- `git diff --check`
- Changed-file secret scan with `rg` for common token/key patterns.
- `pnpm --filter @paperclipai/shared exec vitest run
src/environment-support.test.ts`
- `pnpm --dir ui exec vitest run
src/components/AgentConfigForm.render.test.tsx`

## Risks

- Low risk. This expands environment support for an existing local
adapter to match the local CLI adapter behavior already used by Claude,
Codex, Gemini, OpenCode, Cursor, and Pi.
- Operators still need at least one configured runnable sandbox
environment before a Grok agent has a sandbox option to select.
- This PR was created from a Paperclip execution workspace branch whose
name is runtime-provided; the PR body intentionally avoids internal
issue identifiers or instance-local links.

> 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

- OpenAI Codex, GPT-5 coding agent, tool-enabled terminal/code execution
environment.

## 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
2026-07-09 20:46:46 -07:00

166 lines
6.0 KiB
TypeScript

import type { AgentAdapterType, EnvironmentDriver } from "./constants.js";
import type { SandboxEnvironmentProvider } from "./types/environment.js";
import type { JsonSchema, PluginEnvironmentTemplateConfigBinding } from "./types/plugin.js";
export type EnvironmentSupportStatus = "supported" | "unsupported";
export interface AdapterEnvironmentSupport {
adapterType: AgentAdapterType;
drivers: Record<EnvironmentDriver, EnvironmentSupportStatus>;
sandboxProviders: Record<SandboxEnvironmentProvider, EnvironmentSupportStatus>;
}
export interface EnvironmentProviderCapability {
status: EnvironmentSupportStatus;
supportsSavedProbe: boolean;
supportsUnsavedProbe: boolean;
supportsRunExecution: boolean;
supportsReusableLeases: boolean;
supportsInteractiveSetup: boolean;
interactiveSetupConnectionTypes: string[];
supportsTemplateCapture: boolean;
templateRefKind?: string;
templateConfigBinding?: PluginEnvironmentTemplateConfigBinding;
supportsTemplateDelete: boolean;
displayName?: string;
description?: string;
source?: "builtin" | "plugin";
pluginKey?: string;
pluginId?: string;
configSchema?: JsonSchema;
}
export interface EnvironmentCapabilities {
adapters: AdapterEnvironmentSupport[];
drivers: Record<EnvironmentDriver, EnvironmentSupportStatus>;
sandboxProviders: Record<SandboxEnvironmentProvider, EnvironmentProviderCapability>;
}
const REMOTE_MANAGED_ADAPTERS = new Set<AgentAdapterType>([
"claude_local",
"codex_local",
"cursor",
"gemini_local",
"grok_local",
"opencode_local",
"pi_local",
]);
export function adapterSupportsRemoteManagedEnvironments(adapterType: string): boolean {
return REMOTE_MANAGED_ADAPTERS.has(adapterType as AgentAdapterType);
}
export function supportedEnvironmentDriversForAdapter(adapterType: string): EnvironmentDriver[] {
return adapterSupportsRemoteManagedEnvironments(adapterType)
? ["local", "ssh", "sandbox"]
: ["local"];
}
export function supportedSandboxProvidersForAdapter(
adapterType: string,
additionalProviders: readonly string[] = [],
): SandboxEnvironmentProvider[] {
return adapterSupportsRemoteManagedEnvironments(adapterType)
? Array.from(new Set(additionalProviders)) as SandboxEnvironmentProvider[]
: [];
}
export function isEnvironmentDriverSupportedForAdapter(
adapterType: string,
driver: string,
): boolean {
return supportedEnvironmentDriversForAdapter(adapterType).includes(driver as EnvironmentDriver);
}
export function isSandboxProviderSupportedForAdapter(
adapterType: string,
provider: string | null | undefined,
additionalProviders: readonly string[] = [],
): boolean {
if (!provider) return false;
return supportedSandboxProvidersForAdapter(adapterType, additionalProviders).includes(
provider as SandboxEnvironmentProvider,
);
}
export function getAdapterEnvironmentSupport(
adapterType: AgentAdapterType,
additionalSandboxProviders: readonly string[] = [],
): AdapterEnvironmentSupport {
const supportedDrivers = new Set(supportedEnvironmentDriversForAdapter(adapterType));
const supportedProviders = new Set(supportedSandboxProvidersForAdapter(adapterType, additionalSandboxProviders));
const sandboxProviders: Record<SandboxEnvironmentProvider, EnvironmentSupportStatus> = {
fake: "unsupported",
};
for (const provider of additionalSandboxProviders) {
sandboxProviders[provider as SandboxEnvironmentProvider] = supportedProviders.has(provider as SandboxEnvironmentProvider)
? "supported"
: "unsupported";
}
return {
adapterType,
drivers: {
local: supportedDrivers.has("local") ? "supported" : "unsupported",
ssh: supportedDrivers.has("ssh") ? "supported" : "unsupported",
sandbox: supportedDrivers.has("sandbox") ? "supported" : "unsupported",
plugin: supportedDrivers.has("plugin") ? "supported" : "unsupported",
},
sandboxProviders,
};
}
export function getEnvironmentCapabilities(
adapterTypes: readonly AgentAdapterType[],
options: {
sandboxProviders?: Record<string, Partial<EnvironmentProviderCapability>>;
} = {},
): EnvironmentCapabilities {
const pluginProviderKeys = Object.keys(options.sandboxProviders ?? {});
const sandboxProviders: Record<SandboxEnvironmentProvider, EnvironmentProviderCapability> = {
fake: {
status: "unsupported",
supportsSavedProbe: true,
supportsUnsavedProbe: true,
supportsRunExecution: false,
supportsReusableLeases: true,
supportsInteractiveSetup: false,
interactiveSetupConnectionTypes: [],
supportsTemplateCapture: false,
supportsTemplateDelete: false,
displayName: "Fake",
source: "builtin",
},
};
for (const [provider, capability] of Object.entries(options.sandboxProviders ?? {})) {
sandboxProviders[provider as SandboxEnvironmentProvider] = {
status: capability.status ?? "supported",
supportsSavedProbe: capability.supportsSavedProbe ?? true,
supportsUnsavedProbe: capability.supportsUnsavedProbe ?? true,
supportsRunExecution: capability.supportsRunExecution ?? true,
supportsReusableLeases: capability.supportsReusableLeases ?? true,
supportsInteractiveSetup: capability.supportsInteractiveSetup ?? false,
interactiveSetupConnectionTypes: capability.interactiveSetupConnectionTypes ?? [],
supportsTemplateCapture: capability.supportsTemplateCapture ?? false,
templateRefKind: capability.templateRefKind,
templateConfigBinding: capability.templateConfigBinding,
supportsTemplateDelete: capability.supportsTemplateDelete ?? false,
displayName: capability.displayName,
description: capability.description,
source: capability.source ?? "plugin",
pluginKey: capability.pluginKey,
pluginId: capability.pluginId,
configSchema: capability.configSchema,
};
}
return {
adapters: adapterTypes.map((adapterType) => getAdapterEnvironmentSupport(adapterType, pluginProviderKeys)),
drivers: {
local: "supported",
ssh: "supported",
sandbox: "supported",
plugin: "unsupported",
},
sandboxProviders,
};
}