Skip to content

nanocoai/nanoclaw / .claude/skills/add-opencode

add-opencode

Verified

Use OpenCode as an agent provider. OpenRouter, OpenAI, Google, DeepSeek, etc. via OpenCode config — not the Anthropic Agent SDK. Per group via `ncl groups config update --provider opencode`; host passes OPENCODE_* and XDG mount when spawning containers.

FileKindSize
ARCHITECTURE.mdmarkdown8.0 KB
REMOVE.mdmarkdown3.4 KB
SKILL.mdskill md19.8 KB
apply-fixtures.jsonconfig303 B
payload/container/agent-runner/src/provider-contracts/opencode.tsscript866 B
payload/container/agent-runner/src/providers/mcp-to-opencode.test.tsscript2.7 KB
payload/container/agent-runner/src/providers/mcp-to-opencode.tsscript1.6 KB
payload/container/agent-runner/src/providers/opencode-auth.test.tsscript3.1 KB
payload/container/agent-runner/src/providers/opencode-auth.tsscript1.7 KB
payload/container/agent-runner/src/providers/opencode-config.tsscript10.0 KB
payload/container/agent-runner/src/providers/opencode-memory.tsscript4.4 KB
payload/container/agent-runner/src/providers/opencode-registration.test.tsscript625 B
payload/container/agent-runner/src/providers/opencode-turn.tsscript14.1 KB
payload/container/agent-runner/src/providers/opencode.config.test.tsscript16.2 KB
payload/container/agent-runner/src/providers/opencode.conformance.test.tsscript253 B
payload/container/agent-runner/src/providers/opencode.empty-resume.test.tsscript14.7 KB
payload/container/agent-runner/src/providers/opencode.factory.test.tsscript331 B
payload/container/agent-runner/src/providers/opencode.memory.test.tsscript6.9 KB
payload/container/agent-runner/src/providers/opencode.native.test.tsscript17.6 KB
payload/container/agent-runner/src/providers/opencode.question.test.tsscript7.6 KB
payload/container/agent-runner/src/providers/opencode.shared-runtime.test.tsscript30.9 KB
payload/container/agent-runner/src/providers/opencode.sse-cleanup.test.tsscript6.4 KB
payload/container/agent-runner/src/providers/opencode.tsscript24.9 KB
payload/scripts/opencode-auth-config.test.tsscript27.1 KB
payload/scripts/opencode-auth.test.tsscript19.7 KB
payload/scripts/opencode-auth.tsscript21.4 KB
payload/scripts/opencode-gateway.test.tsscript7.1 KB
payload/scripts/opencode-host.test.tsscript13.4 KB
payload/scripts/opencode-host.tsscript8.9 KB
payload/scripts/opencode-model-config.tsscript8.6 KB
payload/scripts/opencode-models.test.tsscript10.6 KB
payload/scripts/opencode-models.tsscript4.0 KB
payload/scripts/opencode-vault.test.tsscript3.3 KB
payload/scripts/opencode-vault.tsscript2.7 KB
payload/scripts/tsconfig.opencode-auth.jsonconfig171 B
payload/setup/providers/opencode.test.tsscript1.2 KB
payload/setup/providers/opencode.tsscript806 B
payload/src/provider-contracts/opencode.tsscript2.9 KB
payload/src/providers/opencode-auth-stub.tsscript909 B
payload/src/providers/opencode-registration.test.tsscript8.5 KB
payload/src/providers/opencode.tsscript2.7 KB

payload/scripts/opencode-models.ts

View on GitHub
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import * as p from '@clack/prompts';
import { readEnvFile } from '../src/env.js';
import { upsertEnvVar } from '../setup/set-env.js';
import {
  chooseOpenCodeModel,
  discoverLocalModelIds,
  discoverRuntimeModels,
  validateModel,
} from './opencode-model-config.js';

export async function runModelSelection(args: string[]): Promise<void> {
  let list = false,
    refresh = false,
    requested: string | undefined;
  for (let i = 0; i < args.length; i++) {
    if (args[i] === '--list') list = true;
    else if (args[i] === '--refresh') refresh = true;
    else if (args[i] === '--model' && args[i + 1] && !args[i + 1].startsWith('--')) requested = args[++i];
    else throw new Error('Usage: opencode-models.ts [--list] [--refresh] [--model provider/model-id]');
  }
  if (list && requested) throw new Error('--list cannot be combined with --model.');
  const saved = readEnvFile([
    'OPENCODE_PROVIDER',
    'OPENCODE_MODEL',
    'OPENCODE_AUTH_MODE',
    'OPENCODE_BASE_URL',
    'ANTHROPIC_BASE_URL',
  ]);
  const provider = process.env.OPENCODE_PROVIDER ?? saved.OPENCODE_PROVIDER;
  const current = process.env.OPENCODE_MODEL ?? saved.OPENCODE_MODEL;
  const configuredEndpoint = process.env.OPENCODE_BASE_URL ?? saved.OPENCODE_BASE_URL;
  const baseUrl = configuredEndpoint || (process.env.ANTHROPIC_BASE_URL ?? saved.ANTHROPIC_BASE_URL);
  if (!provider) throw new Error('Configure an OpenCode backend first: pnpm exec tsx scripts/opencode-auth.ts');
  if (!/^[a-z0-9][a-z0-9_-]*$/.test(provider)) throw new Error('Invalid configured OpenCode provider id.');
  if (requested && validateModel(requested, provider)) throw new Error(validateModel(requested, provider));
  let models: string[] = [];
  if (!requested || refresh) {
    try {
      if (baseUrl && baseUrl !== 'native') {
        if (provider !== 'openai') throw new Error('Custom endpoint requires a manual model ID.');
        models = (await discoverLocalModelIds(baseUrl)).map((id) => `${provider}/${id}`);
        if (!models.length) throw new Error('The configured endpoint returned no models.');
      } else {
        models = discoverRuntimeModels(
          provider,
          refresh,
          (process.env.OPENCODE_AUTH_MODE ?? saved.OPENCODE_AUTH_MODE) === 'chatgpt',
        );
      }
    } catch {
      if (list)
        throw new Error(
          'Could not read models for the configured backend. Check the endpoint, image and network; settings unchanged.',
        );
      p.log.warn('Could not read models for the configured backend. Keep the current model or enter an id manually.');
    }
  }
  if (list) {
    console.log(models.join('\n'));
    return;
  }
  const selected = requested ?? (await chooseOpenCodeModel(provider, models, current));
  const invalid = validateModel(selected, provider);
  if (invalid) throw new Error(invalid);
  if (process.env.OPENCODE_MODEL !== undefined && process.env.OPENCODE_MODEL !== selected) {
    throw new Error(
      'An exported OPENCODE_MODEL overrides .env. Unset it before changing the saved default; settings unchanged.',
    );
  }
  if (process.env.OPENCODE_PROVIDER !== undefined && process.env.OPENCODE_PROVIDER !== saved.OPENCODE_PROVIDER) {
    throw new Error(
      'An exported OPENCODE_PROVIDER differs from .env. Update the backend configuration first; settings unchanged.',
    );
  }
  if (selected === current) {
    p.log.info(`Keeping ${selected}; settings unchanged.`);
    return;
  }
  upsertEnvVar('OPENCODE_MODEL', selected);
  p.log.success(
    `Default model set to ${selected}. Authentication, backend, small model, and group overrides are unchanged.`,
  );
  p.log.info(
    'Restart the NanoClaw host and affected groups to use the new default. Per-group model overrides still win.',
  );
}

if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
  runModelSelection(process.argv.slice(2)).catch((error: unknown) => {
    console.error(error instanceof Error ? error.message : 'Model selection failed');
    process.exitCode = 1;
  });
}
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 469kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 321kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 321kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 321kUpdated Claude CodeCodexVerifiedInstall