mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 18:30:39 +09:00
> **Stacked PR.** Sits on top of the e2b sandbox chain — #5278 (stdin staging) and #5279 (honest-resolvability + login-profiles). The cumulative diff against `master` includes both of those PRs' content; the files touched by *this* PR's commit are the new `maybeRunSandboxInstallCommand` helper in `packages/adapter-utils/src/execution-target.ts` and the per-adapter `index.ts`/`server/test.ts`/`server/execute.ts` wiring under `packages/adapters/{claude,codex,cursor,gemini,opencode,pi}-local/`. The honest resolvability check from #5279 is what gives this PR's install command a meaningful "did it actually land on PATH" follow-up. ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - Sandbox execution targets are ephemeral — each fresh lease starts from a template image that may or may not have the agent CLIs preinstalled > - When a CLI isn't preinstalled, the resolvability probe fails at `command -v` and the hello probe never runs > - There's no shared mechanism for "before you probe or provision, install the CLI on this sandbox" > - This pull request adds a `SANDBOX_INSTALL_COMMAND` constant per adapter and a `maybeRunSandboxInstallCommand` helper that runs it via the existing sandbox login shell, captures structured output, and never throws (so the resolvability + hello probe still run after); each adapter's `test()` and `execute()` share the constant so the two callsites can't drift > - The benefit is a fresh sandbox lease without a preinstalled CLI now installs it once via `sh -lc` before the resolvability probe and before managed-runtime provisioning, with a uniform `<adapter>_install_command_run` check on the test report ## What Changed - `packages/adapter-utils/src/execution-target.ts`: add `AdapterSandboxInstallCommandCheck` and `maybeRunSandboxInstallCommand` (runs the install via existing sandbox shell, captures exit/stdout/stderr, returns a structured info/warn check, never throws) - Add `SANDBOX_INSTALL_COMMAND` to each adapter's `index.ts` so `test()` and `execute()` share a single source of truth - Wire each of the 6 affected adapter `testEnvironment()`s to call `maybeRunSandboxInstallCommand` before `ensureAdapterExecutionTargetCommandResolvable` - Pass `installCommand: SANDBOX_INSTALL_COMMAND` through `prepareAdapterExecutionTargetRuntime` in each adapter's `execute()` - Per-adapter install commands use npm globals where possible so binaries land on a PATH segment the template already exports: - claude → `npm install -g @anthropic-ai/claude-code` - codex → `npm install -g @openai/codex` - cursor → `curl https://cursor.com/install -fsS | bash` - gemini → `npm install -g @google/gemini-cli` - opencode → `npm install -g opencode-ai` - pi → `npm install -g @mariozechner/pi-coding-agent` SSH and local targets ignore `installCommand` (SSH runtime takes no such param; local short-circuits before runtime prep), so this is a no-op for non-sandbox environments. ## Verification - `pnpm typecheck` clean - `pnpm vitest run --no-coverage --project @paperclipai/adapter-utils` and per-adapter projects pass - Manual sandbox matrix (claude, codex, cursor, gemini, opencode, pi) — each goes `install_command_run → resolvable → hello_probe_passed` (Codex and Pi land on `hello_probe_auth_required`, which is the configured-credentials problem, not an install issue) - SSH no-regression: SSH Claude still passes; the helper short-circuits on non-sandbox targets ## Risks Medium — adds a network/CPU cost (npm install / curl) on every fresh sandbox lease. Cost is bounded (one-time per lease, typically tens of seconds for npm globals), and the helper never throws so a failing install still lets the report run resolvability and hello probes. If a sandbox image already has the CLI, the install is an idempotent reinstall. ## Model Used Claude Opus 4.7 (1M context) ## 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 run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots — N/A (no UI) - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge
93 lines
5.1 KiB
TypeScript
93 lines
5.1 KiB
TypeScript
import type { AdapterModelProfileDefinition } from "@paperclipai/adapter-utils";
|
|
|
|
export const type = "codex_local";
|
|
export const label = "Codex (local)";
|
|
|
|
export const SANDBOX_INSTALL_COMMAND = "npm install -g @openai/codex";
|
|
|
|
export const DEFAULT_CODEX_LOCAL_MODEL = "gpt-5.3-codex";
|
|
export const DEFAULT_CODEX_LOCAL_BYPASS_APPROVALS_AND_SANDBOX = true;
|
|
export const CODEX_LOCAL_FAST_MODE_SUPPORTED_MODELS = ["gpt-5.4"] as const;
|
|
|
|
function normalizeModelId(model: string | null | undefined): string {
|
|
return typeof model === "string" ? model.trim() : "";
|
|
}
|
|
|
|
export function isCodexLocalKnownModel(model: string | null | undefined): boolean {
|
|
const normalizedModel = normalizeModelId(model);
|
|
if (!normalizedModel) return false;
|
|
return models.some((entry) => entry.id === normalizedModel);
|
|
}
|
|
|
|
export function isCodexLocalManualModel(model: string | null | undefined): boolean {
|
|
const normalizedModel = normalizeModelId(model);
|
|
return Boolean(normalizedModel) && !isCodexLocalKnownModel(normalizedModel);
|
|
}
|
|
|
|
export function isCodexLocalFastModeSupported(model: string | null | undefined): boolean {
|
|
if (isCodexLocalManualModel(model)) return true;
|
|
const normalizedModel = typeof model === "string" ? model.trim() : "";
|
|
return CODEX_LOCAL_FAST_MODE_SUPPORTED_MODELS.includes(
|
|
normalizedModel as (typeof CODEX_LOCAL_FAST_MODE_SUPPORTED_MODELS)[number],
|
|
);
|
|
}
|
|
|
|
export const models = [
|
|
{ id: "gpt-5.4", label: "gpt-5.4" },
|
|
{ id: DEFAULT_CODEX_LOCAL_MODEL, label: DEFAULT_CODEX_LOCAL_MODEL },
|
|
{ id: "gpt-5.3-codex-spark", label: "gpt-5.3-codex-spark" },
|
|
{ id: "gpt-5", label: "gpt-5" },
|
|
{ id: "o3", label: "o3" },
|
|
{ id: "o4-mini", label: "o4-mini" },
|
|
{ id: "gpt-5-mini", label: "gpt-5-mini" },
|
|
{ id: "gpt-5-nano", label: "gpt-5-nano" },
|
|
{ id: "o3-mini", label: "o3-mini" },
|
|
{ id: "codex-mini-latest", label: "Codex Mini" },
|
|
];
|
|
|
|
export const modelProfiles: AdapterModelProfileDefinition[] = [
|
|
{
|
|
key: "cheap",
|
|
label: "Cheap",
|
|
description: "Use the lowest-cost known Codex local model lane without changing the primary model.",
|
|
adapterConfig: {
|
|
model: "gpt-5.3-codex-spark",
|
|
modelReasoningEffort: "low",
|
|
},
|
|
source: "adapter_default",
|
|
},
|
|
];
|
|
|
|
export const agentConfigurationDoc = `# codex_local agent configuration
|
|
|
|
Adapter: codex_local
|
|
|
|
Core fields:
|
|
- cwd (string, optional): default absolute working directory fallback for the agent process (created if missing when possible)
|
|
- instructionsFilePath (string, optional): absolute path to a markdown instructions file prepended to stdin prompt at runtime
|
|
- model (string, optional): Codex model id
|
|
- modelReasoningEffort (string, optional): reasoning effort override (minimal|low|medium|high|xhigh) passed via -c model_reasoning_effort=...
|
|
- promptTemplate (string, optional): run prompt template
|
|
- search (boolean, optional): run codex with --search
|
|
- fastMode (boolean, optional): enable Codex Fast mode; supported on GPT-5.4 and passed through for manual model IDs
|
|
- dangerouslyBypassApprovalsAndSandbox (boolean, optional): run with bypass flag
|
|
- command (string, optional): defaults to "codex"
|
|
- extraArgs (string[], optional): additional CLI args
|
|
- env (object, optional): KEY=VALUE environment variables
|
|
- workspaceStrategy (object, optional): execution workspace strategy; currently supports { type: "git_worktree", baseRef?, branchTemplate?, worktreeParentDir? }
|
|
- workspaceRuntime (object, optional): reserved for workspace runtime metadata; workspace runtime services are manually controlled from the workspace UI and are not auto-started by heartbeats
|
|
|
|
Operational fields:
|
|
- timeoutSec (number, optional): run timeout in seconds
|
|
- graceSec (number, optional): SIGTERM grace period in seconds
|
|
|
|
Notes:
|
|
- Prompts are piped via stdin (Codex receives "-" prompt argument).
|
|
- If instructionsFilePath is configured, Paperclip prepends that file's contents to the stdin prompt on every run.
|
|
- Codex exec automatically applies repo-scoped AGENTS.md instructions from the active workspace. Paperclip cannot suppress that discovery in exec mode, so repo AGENTS.md files may still apply even when you only configured an explicit instructionsFilePath.
|
|
- Paperclip injects desired local skills into the effective CODEX_HOME/skills/ directory at execution time so Codex can discover "$paperclip" and related skills without polluting the project working directory. In managed-home mode (the default) this is ~/.paperclip/instances/<id>/companies/<companyId>/codex-home/skills/; when CODEX_HOME is explicitly overridden in adapter config, that override is used instead.
|
|
- Unless explicitly overridden in adapter config, Paperclip runs Codex with a per-company managed CODEX_HOME under the active Paperclip instance and seeds auth/config from the shared Codex home (the CODEX_HOME env var, when set, or ~/.codex).
|
|
- Some model/tool combinations reject certain effort levels (for example minimal with web search enabled).
|
|
- Fast mode is supported on GPT-5.4 and manual model IDs. When enabled for those models, Paperclip applies \`service_tier="fast"\` and \`features.fast_mode=true\`.
|
|
- When Paperclip realizes a workspace/runtime for a run, it injects PAPERCLIP_WORKSPACE_* and PAPERCLIP_RUNTIME_* env vars for agent-side tooling.
|
|
`;
|