mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-10 03:08:10 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agent runtimes are selected through adapters, and each adapter exposes the model IDs an operator can pick in the UI > - The `codex_local` and `opencode_local` adapters hardcode those lists, so a newly released model stays unreachable until it is added > - `gpt-5.4-mini` is available via both the Codex CLI and the OpenCode CLI, but neither adapter lists it; `openai/gpt-5.5` is likewise missing from `opencode_local` > - This pull request adds those entries, and deliberately keeps `gpt-5.4-mini` out of the Codex Fast mode allowlist because the model does not support Fast mode > - The benefit is that operators can select these models from the UI instead of falling back to a manual model ID, and Fast mode fails closed rather than sending unsupported overrides to the CLI ## Linked Issues or Issue Description No existing issue covers this. Describing it inline, following the feature request template: ### Problem or motivation `gpt-5.4-mini` is absent from the `models` list of both the `codex_local` and `opencode_local` adapters, and `openai/gpt-5.5` is absent from `opencode_local`. (`codex_local` already ships `gpt-5.5` — it is the default model on master.) Operators who want these models must type a manual model ID. For `codex_local` that has a real side effect. `isCodexLocalFastModeSupported` treats any *unknown* model as Fast-mode-capable and passes `service_tier="fast"` and `features.fast_mode=true` through to the CLI. Because `gpt-5.4-mini` does not support Codex Fast mode, an agent configured with a manual `gpt-5.4-mini` model ID and `fastMode` enabled silently sends overrides the CLI cannot honor. ### Proposed solution Add the three missing entries to the two `models` lists, and leave `CODEX_LOCAL_FAST_MODE_SUPPORTED_MODELS` untouched. Listing `gpt-5.4-mini` in `models` is precisely what makes it a *known* model, so `isCodexLocalFastModeSupported` returns `false`, `buildCodexExecArgs` omits the Fast mode overrides, and `fastModeIgnoredReason` is surfaced to the operator. ### Alternatives considered Adding `gpt-5.4-mini` to `CODEX_LOCAL_FAST_MODE_SUPPORTED_MODELS` as well — rejected, because the model does not support Fast mode and the overrides would be rejected at run time. Leaving the models unlisted so operators keep using manual IDs — rejected, because that is the path that silently enables Fast mode for a model that cannot use it. ### Roadmap alignment Not core roadmap work. `ROADMAP.md` does not plan adapter model-list maintenance; this is routine upkeep as upstream CLIs ship new models. ## What Changed - Add `gpt-5.4-mini` to the `codex_local` adapter's `models` list, positioned after `gpt-5.4` (newest-first ordering). - Add `openai/gpt-5.5` and `openai/gpt-5.4-mini` to the `opencode_local` adapter's `models` list. - Add a `buildCodexExecArgs` test asserting Fast mode is ignored for `gpt-5.4-mini`. `CODEX_LOCAL_FAST_MODE_SUPPORTED_MODELS` is intentionally unchanged. No behavior changes to existing models or adapter logic. ## Verification ``` pnpm --filter @paperclipai/adapter-codex-local --filter @paperclipai/adapter-opencode-local typecheck npx vitest run packages/adapters/codex-local packages/adapters/opencode-local ``` Both pass: typecheck clean on both packages, and 22 test files / 133 tests green, including the new `ignores fast mode for gpt-5.4-mini` case. ## Risks Low risk. The change is additive: three entries appended to two model-selection lists, plus one test. No default model changes, no adapter logic changes, no migrations. One behavioral shift is intended. An operator who had `gpt-5.4-mini` configured as a *manual* model ID with `fastMode` enabled was getting Fast mode overrides passed through to the Codex CLI. After this change `gpt-5.4-mini` is a known model, so those overrides are dropped and `fastModeIgnoredReason` explains why. ## Model Used - OpenAI Codex CLI with GPT-5 / GPT-5.5-assisted code editing (the original commits on this branch). - Anthropic Claude Opus 4.8 (`claude-opus-4-8`, 1M context, extended thinking, tool use) for the master merge, conflict resolution, and the scope reduction in the latest commit. ## 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 the GitHub PR list for similar or duplicate PRs and confirmed this one is not a duplicate - [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 (N/A; the adapter docs describe Fast mode support, which is unchanged) - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] 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: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Andrew Aymeloglu <aaymeloglu@gmail.com>
143 lines
7.5 KiB
TypeScript
143 lines
7.5 KiB
TypeScript
import type { AdapterModelProfileDefinition } from "@paperclipai/adapter-utils";
|
|
|
|
export const type = "opencode_local";
|
|
export const label = "OpenCode";
|
|
|
|
// Use OpenCode's official installer instead of `npm install -g opencode-ai`.
|
|
// The npm package reifies four large Linux x64 prebuilt-binary subpackages
|
|
// (linux-x64, linux-x64-musl, linux-x64-baseline, linux-x64-baseline-musl) in
|
|
// parallel even though only one matches the sandbox; on bandwidth-constrained
|
|
// sandboxes (e.g. Cloudflare) that exceeded the 240s install budget. The
|
|
// official installer fetches a single arch-specific binary into
|
|
// `$HOME/.opencode/bin` and tries to add it to PATH via `~/.bashrc`. That
|
|
// rc-file path is only sourced by interactive/login shells, so non-login
|
|
// `sh -c` probe invocations (used by the runtime PATH check) cannot find the
|
|
// binary. We fix that by symlinking the installed binary into a directory on
|
|
// the non-login `sh -c` PATH: prefer `/usr/local/bin` (universally on the
|
|
// default PATH on Linux distros) when root or passwordless sudo is available,
|
|
// otherwise fall back to `$HOME/.local/bin` (which is on the default PATH on
|
|
// the exe.dev sandbox image and most modern home-managed Linux images).
|
|
//
|
|
// Security tradeoff: this is `curl | bash` without a SHA-256 verification of
|
|
// the install script. We accept this because:
|
|
// 1. The install runs inside an isolated, ephemeral sandbox — blast radius
|
|
// is bounded to that sandbox's secrets and disk.
|
|
// 2. The prior `npm install -g opencode-ai` is also unverified code
|
|
// execution from a third-party registry; this is not strictly worse.
|
|
// 3. OpenCode does not publish per-release SHA-256 checksums in a stable
|
|
// location, and pinning a version + hash here would require manual
|
|
// version bumps on every OpenCode release.
|
|
// The `set -e` (implied by Bash's default with `-fsSL` upstream of a piped
|
|
// shell) and `curl -fsSL` give us fail-fast behavior on HTTP errors. If
|
|
// OpenCode starts publishing a stable checksum/signature, switch to fetching
|
|
// a versioned tarball + verifying the digest before exec.
|
|
export const SANDBOX_INSTALL_COMMAND =
|
|
'curl -fsSL https://opencode.ai/install | bash && ' +
|
|
'if [ -x "$HOME/.opencode/bin/opencode" ]; then ' +
|
|
'if [ "$(id -u)" -eq 0 ]; then ' +
|
|
'ln -sf "$HOME/.opencode/bin/opencode" /usr/local/bin/opencode; ' +
|
|
'elif command -v sudo >/dev/null 2>&1 && sudo -n true >/dev/null 2>&1; then ' +
|
|
'sudo ln -sf "$HOME/.opencode/bin/opencode" /usr/local/bin/opencode; ' +
|
|
'else ' +
|
|
'mkdir -p "$HOME/.local/bin" && ' +
|
|
'ln -sf "$HOME/.opencode/bin/opencode" "$HOME/.local/bin/opencode"; ' +
|
|
'fi; ' +
|
|
'fi';
|
|
|
|
export const DEFAULT_OPENCODE_LOCAL_MODEL = "openai/gpt-5.2-codex";
|
|
|
|
export function isValidOpenCodeModelId(value: unknown): value is string {
|
|
if (typeof value !== "string") return false;
|
|
const trimmed = value.trim();
|
|
const slashIndex = trimmed.indexOf("/");
|
|
return Boolean(trimmed) && slashIndex > 0 && slashIndex !== trimmed.length - 1;
|
|
}
|
|
|
|
export const models: Array<{ id: string; label: string }> = [
|
|
{ id: DEFAULT_OPENCODE_LOCAL_MODEL, label: DEFAULT_OPENCODE_LOCAL_MODEL },
|
|
{ id: "openai/gpt-5.5", label: "openai/gpt-5.5" },
|
|
{ id: "openai/gpt-5.4", label: "openai/gpt-5.4" },
|
|
{ id: "openai/gpt-5.4-mini", label: "openai/gpt-5.4-mini" },
|
|
{ id: "openai/gpt-5.2", label: "openai/gpt-5.2" },
|
|
{ id: "openai/gpt-5.1-codex-max", label: "openai/gpt-5.1-codex-max" },
|
|
{ id: "openai/gpt-5.1-codex-mini", label: "openai/gpt-5.1-codex-mini" },
|
|
];
|
|
|
|
export const DEFAULT_OPENCODE_CHEAP_MODEL = "openai/gpt-5.1-codex-mini";
|
|
|
|
// The "cheap" budget profile (used for recovery retries and other low-cost lanes).
|
|
// Defaults to OpenCode's known Codex mini model, but is overridable so a deployment
|
|
// routing through a gateway that does not serve that model (e.g. an EU LLM gateway)
|
|
// can point the budget lane at a gateway-served model instead -- otherwise recovery
|
|
// retries fail with "model not found". PAPERCLIP_OPENCODE_CHEAP_MODEL takes priority;
|
|
// PAPERCLIP_OPENCODE_SMALL_MODEL (the auxiliary/title model) is reused as a sensible
|
|
// fallback so a single setting covers both budget lanes. The default keeps the
|
|
// upstream behaviour (with the Codex `variant: "low"`).
|
|
//
|
|
// This module is shared client/server code (the UI imports it for
|
|
// DEFAULT_OPENCODE_LOCAL_MODEL etc.), so it must not touch the global `process`
|
|
// unguarded: in the browser (Vite dev middleware serves it untransformed)
|
|
// a bare `process.env` throws ReferenceError at module load and takes the whole
|
|
// app down. Guard with `typeof process` and fall back to an empty env.
|
|
export function buildOpenCodeModelProfiles(
|
|
env: NodeJS.ProcessEnv = typeof process === "undefined" ? {} : process.env,
|
|
): AdapterModelProfileDefinition[] {
|
|
const override = (env.PAPERCLIP_OPENCODE_CHEAP_MODEL ?? env.PAPERCLIP_OPENCODE_SMALL_MODEL)?.trim();
|
|
return [
|
|
{
|
|
key: "cheap",
|
|
label: "Cheap",
|
|
description: "Budget lane model for recovery retries and other low-cost tasks.",
|
|
adapterConfig: override
|
|
? { model: override }
|
|
: { model: DEFAULT_OPENCODE_CHEAP_MODEL, variant: "low" },
|
|
source: "adapter_default",
|
|
},
|
|
];
|
|
}
|
|
|
|
export const modelProfiles: AdapterModelProfileDefinition[] = buildOpenCodeModelProfiles();
|
|
|
|
export const agentConfigurationDoc = `# opencode_local agent configuration
|
|
|
|
Adapter: opencode_local
|
|
|
|
Use when:
|
|
- You want Paperclip to run OpenCode locally as the agent runtime
|
|
- You want provider/model routing in OpenCode format (provider/model)
|
|
- You want OpenCode session resume across heartbeats via --session
|
|
|
|
Don't use when:
|
|
- You need webhook-style external invocation (use openclaw_gateway or http)
|
|
- You only need one-shot shell commands (use process)
|
|
- OpenCode CLI is not installed on the machine
|
|
|
|
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 the run prompt
|
|
- model (string, required): OpenCode model id in provider/model format (for example anthropic/claude-sonnet-4-5)
|
|
- variant (string, optional): provider-specific reasoning/profile variant passed as --variant (for example minimal|low|medium|high|xhigh|max)
|
|
- dangerouslySkipPermissions (boolean, optional): inject a runtime OpenCode config that allows \`external_directory\` access without interactive prompts; defaults to true for unattended Paperclip runs
|
|
- promptTemplate (string, optional): run prompt template
|
|
- command (string, optional): defaults to "opencode"
|
|
- extraArgs (string[], optional): additional CLI args
|
|
- env (object, optional): KEY=VALUE environment variables
|
|
|
|
Operational fields:
|
|
- timeoutSec (number, optional): run timeout in seconds
|
|
- graceSec (number, optional): SIGTERM grace period in seconds
|
|
|
|
Notes:
|
|
- OpenCode supports multiple providers and models. Use \
|
|
\`opencode models\` to list available options in provider/model format.
|
|
- Paperclip requires an explicit \`model\` value for \`opencode_local\` agents.
|
|
- Runs are executed with: opencode run --format json ...
|
|
- Sessions are resumed with --session when stored session cwd matches current cwd.
|
|
- The adapter sets OPENCODE_DISABLE_PROJECT_CONFIG=true to prevent OpenCode from \
|
|
writing an opencode.json config file into the project working directory. Model \
|
|
selection is passed via the --model CLI flag instead.
|
|
- When \`dangerouslySkipPermissions\` is enabled, Paperclip injects a temporary \
|
|
runtime config with \`permission.external_directory=allow\` so headless runs do \
|
|
not stall on approval prompts.
|
|
`;
|