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/src/providers/opencode-registration.test.ts

View on GitHub
import fs from 'fs';
import path from 'path';
import { afterAll, describe, expect, it, vi } from 'vitest';

const fixture = vi.hoisted(() => ({ root: '' }));
vi.mock('../config.js', async (original) => {
  const fs = await import('fs');
  const os = await import('os');
  const path = await import('path');
  fixture.root = fs.mkdtempSync(path.join(os.tmpdir(), 'opencode-host-'));
  return {
    ...(await original<typeof import('../config.js')>()),
    DATA_DIR: fixture.root,
    GROUPS_DIR: path.join(fixture.root, 'groups'),
  };
});
vi.mock('../env.js', () => ({ readEnvFile: () => ({}) }));
import './index.js';
import '../provider-contracts/index.js';
import { getProviderContainerConfig } from './provider-container-registry.js';
import { getProviderHostContract } from '../provider-contracts/registry.js';
import { buildMounts } from '../container-runner.js';
import { closeDb, createAgentGroup, initTestDb, runMigrations } from '../db/index.js';
import { ensureContainerConfig } from '../db/container-configs.js';
import { initGroupFilesystem } from '../group-init.js';
import type { AgentGroup, Session } from '../types.js';

afterAll(() => fs.rmSync(fixture.root, { recursive: true, force: true }));
function context(hostEnv: NodeJS.ProcessEnv = {}) {
  return {
    sessionDir: path.join(fixture.root, 'session'),
    groupDir: path.join(fixture.root, 'group'),
    agentGroupId: 'test',
    selectedSkills: [],
    hostEnv,
    coreOwnsProviderSurfaces: true as const,
  };
}
describe('OpenCode host payload', () => {
  it('keeps the installed CLI and SDK on the same supported exact pin', () => {
    const tools = JSON.parse(fs.readFileSync(new URL('../../container/cli-tools.json', import.meta.url), 'utf8'));
    const runner = JSON.parse(
      fs.readFileSync(new URL('../../container/agent-runner/package.json', import.meta.url), 'utf8'),
    );
    expect(tools.find((entry: { name: string }) => entry.name === 'opencode-ai')).toMatchObject({
      version: '1.18.25',
      onlyBuilt: true,
    });
    expect(runner.dependencies['@opencode-ai/sdk']).toBe('1.18.25');
  });
  it('registers the implementation and version 1 surfaces through the actual barrels', () => {
    expect(getProviderContainerConfig('opencode')).toBeTypeOf('function');
    expect(getProviderHostContract('opencode')).toMatchObject({
      seamVersion: 1,
    });
  });
  it('passes backend defaults and preserves proxy exclusions without doing core filesystem work', async () => {
    const contribution = await getProviderContainerConfig('opencode')!(
      context({
        OPENCODE_PROVIDER: 'openai',
        OPENCODE_MODEL: 'openai/test-model',
        NO_PROXY: 'internal.example',
        no_proxy: 'lower.example',
        ANTHROPIC_BASE_URL: 'http://localhost:8891/v1',
      }),
    );
    expect(contribution.env).toMatchObject({
      OPENCODE_MODEL: 'openai/test-model',
      NO_PROXY: 'internal.example,127.0.0.1,localhost',
      no_proxy: 'lower.example,127.0.0.1,localhost',
    });
    expect(contribution.mounts).toEqual([]);
    expect(fs.existsSync(context().sessionDir)).toBe(false);
  });
  it('realizes each declared document and state mount exactly once through core', async () => {
    const group = {
      id: 'mount-test',
      name: 'OpenCode',
      folder: 'mount-test',
      agent_provider: 'opencode',
      created_at: new Date().toISOString(),
    } as AgentGroup;
    const session = { id: 'mount-session', agent_group_id: group.id } as Session;
    const groupDir = path.join(fixture.root, 'groups', group.folder);
    const sessionDir = path.join(fixture.root, 'v2-sessions', group.id, session.id);
    await runMigrations(await initTestDb());
    try {
      await createAgentGroup(group);
      await ensureContainerConfig(group.id, 'opencode');
      await initGroupFilesystem(group, { provider: 'opencode' });
      const contribution = await getProviderContainerConfig('opencode')!({
        ...context(),
        agentGroupId: group.id,
        groupDir,
        sessionDir,
      });
      expect(contribution.mounts).toEqual([]);
      expect(fs.existsSync(path.join(sessionDir, 'opencode-xdg'))).toBe(false);
      const mounts = await buildMounts(
        group,
        session,
        { provider: 'opencode', mcpServers: {}, packages: { apt: [], npm: [] }, additionalMounts: [], skills: [] },
        'opencode',
        contribution,
      );
      const surfacePaths = ['/workspace/agent/CLAUDE.md', '/home/node/.claude', '/opencode-xdg'];
      expect(
        mounts
          .filter((mount) => surfacePaths.includes(mount.containerPath))
          .map(({ hostPath, containerPath, readonly }) => ({ hostPath, containerPath, readonly })),
      ).toEqual([
        { hostPath: path.join(groupDir, 'CLAUDE.md'), containerPath: '/workspace/agent/CLAUDE.md', readonly: true },
        {
          hostPath: path.join(fixture.root, 'v2-sessions', group.id, '.claude-shared'),
          containerPath: '/home/node/.claude',
          readonly: false,
        },
        { hostPath: path.join(sessionDir, 'opencode-xdg'), containerPath: '/opencode-xdg', readonly: false },
      ]);
      expect(fs.existsSync(path.join(sessionDir, 'opencode-xdg'))).toBe(true);
      expect(fs.existsSync(path.join(fixture.root, 'v2-sessions', group.id, '.claude-shared', 'settings.json'))).toBe(
        true,
      );
    } finally {
      await closeDb();
    }
  });
  it('selects ChatGPT mode without requiring or mounting any host auth file', async () => {
    const contribution = await getProviderContainerConfig('opencode')!(context({ OPENCODE_AUTH_MODE: 'chatgpt' }));
    expect(contribution.env).toMatchObject({ OPENCODE_AUTH_MODE: 'chatgpt' });
    expect(contribution.mounts).toEqual([]);
    expect(fs.existsSync(context().sessionDir)).toBe(false);
    const api = await getProviderContainerConfig('opencode')!(context());
    expect(api.env).toMatchObject({ OPENCODE_AUTH_MODE: 'api-key' });
  });
});

describe('OpenCode model gateway destinations', () => {
  it('declares native backends and only the configured custom HTTPS hostname', async () => {
    const { openCodeModelDomains } = await import('../provider-contracts/opencode.js');
    expect(openCodeModelDomains('https://models.example.test/v1')).toEqual(
      expect.arrayContaining([
        'chatgpt.com',
        'api.openai.com',
        'openrouter.ai',
        'api.deepseek.com',
        'generativelanguage.googleapis.com',
        'api.anthropic.com',
        'models.example.test',
      ]),
    );
    expect(openCodeModelDomains('native')).not.toContain('models.example.test');
  });
  it.each([
    'http://models.example.test/v1',
    'https://models.example.test:8443/v1',
    'https://user:pass@models.example.test/v1',
  ])('does not declare an unsupported endpoint %s for model approval', async (endpoint) => {
    const { openCodeModelDomains } = await import('../provider-contracts/opencode.js');
    expect(openCodeModelDomains(endpoint)).not.toContain('models.example.test');
  });
  it.each([
    ['http://host.docker.internal:8000/v1', ['host.docker.internal:8000']],
    ['http://HOST.docker.internal:11434/v1', ['host.docker.internal:11434']],
    ['https://models.example.test:8443/v1', ['models.example.test:8443']],
    ['https://models.example.test/v1', []],
    ['http://host.docker.internal/v1', []],
    ['http://192.168.1.20:8000/v1', []],
    ['http://user:pw@host.docker.internal:8000/v1', []],
    ['native', []],
    ['not a url', []],
  ])('declares %s as the exact model authorities %j', async (endpoint, expected) => {
    const { openCodeModelAuthorities } = await import('../provider-contracts/opencode.js');
    expect(openCodeModelAuthorities(endpoint)).toEqual(expected);
  });
  it('reads the saved endpoint each time, so a changed port is what the next host start declares', async () => {
    const { openCodeModelAuthorities } = await import('../provider-contracts/opencode.js');
    vi.stubEnv('OPENCODE_BASE_URL', 'http://host.docker.internal:11434/v1');
    expect(openCodeModelAuthorities()).toEqual(['host.docker.internal:11434']);
    vi.stubEnv('OPENCODE_BASE_URL', 'http://host.docker.internal:8080/v1');
    expect(openCodeModelAuthorities()).toEqual(['host.docker.internal:8080']);
    vi.unstubAllEnvs();
  });
  it('never declares an authority from the shared ANTHROPIC_BASE_URL', async () => {
    const { openCodeModelAuthorities } = await import('../provider-contracts/opencode.js');
    vi.stubEnv('OPENCODE_BASE_URL', undefined);
    vi.stubEnv('ANTHROPIC_BASE_URL', 'http://host.docker.internal:8000/v1');
    expect(openCodeModelAuthorities()).toEqual([]);
    vi.unstubAllEnvs();
  });
});
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