nanocoai/nanoclaw / .claude/skills/add-opencode
add-opencode
VerifiedUse 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.
payload/src/providers/opencode-registration.test.ts
View on GitHubimport 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();
});
});
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 469k | Updated | Claude CodeCodex | Verified | Install |
| 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: 321k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| 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 available | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |