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/container/agent-runner/src/providers/opencode.question.test.ts

View on GitHub
import { describe, it, expect } from 'bun:test';

import {
  autoAnswerQuestion,
  drainPendingQuestions,
  handleQuestionAsked,
  QUESTION_STEERING_TEXT,
  type QuestionClient,
} from './opencode.js';

/**
 * Fake `/v2` question client — captures every reply/list call so tests can
 * assert what OpenCodeProvider sends back without spawning a real server.
 * These unit tests check reply/list behavior for native request shapes.
 * opencode.shared-runtime.test.ts separately drives question.asked through
 * the production event pump and requires its reply before the turn completes.
 */
function createFakeQuestionClient(
  opts: {
    pending?: Array<{ id: string; sessionID?: string; questions?: unknown[] }>;
    replyError?: unknown;
  } = {},
): { client: QuestionClient; replyCalls: Array<{ requestID: string; answers: string[][] }> } {
  const replyCalls: Array<{ requestID: string; answers: string[][] }> = [];
  const client: QuestionClient = {
    question: {
      async reply(params) {
        replyCalls.push(params);
        if (opts.replyError) return { error: opts.replyError };
        return { data: true };
      },
      async list() {
        return { data: opts.pending ?? [] };
      },
    },
  };
  return { client, replyCalls };
}

describe('autoAnswerQuestion', () => {
  it('replies with one steering-text answer per sub-question — the wedge-path fix', async () => {
    const { client, replyCalls } = createFakeQuestionClient();

    // Simulates a `question.asked` event's properties for a two-part question.
    await autoAnswerQuestion(client, {
      id: 'que_f931faf310018jM9tBPKPMsezK',
      questions: [{ question: 'Proceed with deletion?' }, { question: 'Which target?' }],
    });

    expect(replyCalls).toEqual([
      {
        requestID: 'que_f931faf310018jM9tBPKPMsezK',
        answers: [[QUESTION_STEERING_TEXT], [QUESTION_STEERING_TEXT]],
      },
    ]);
  });

  it('answers with a single steering-text entry when the question count is unknown', async () => {
    const { client, replyCalls } = createFakeQuestionClient();

    await autoAnswerQuestion(client, { id: 'que_no_questions_array' });

    expect(replyCalls).toEqual([{ requestID: 'que_no_questions_array', answers: [[QUESTION_STEERING_TEXT]] }]);
  });

  it('steers the model toward autonomy or the real ask_user_question MCP tool', async () => {
    const { client, replyCalls } = createFakeQuestionClient();
    await autoAnswerQuestion(client, { id: 'que_1', questions: [{}] });
    const [{ answers }] = replyCalls;
    expect(answers[0][0]).toContain('ask_user_question');
    expect(answers[0][0].toLowerCase()).toContain('not available in this environment');
  });

  it('never throws — a failed reply must not take the session down with it', async () => {
    const { client } = createFakeQuestionClient({ replyError: { message: 'boom' } });
    await expect(autoAnswerQuestion(client, { id: 'que_err', questions: [{}] })).resolves.toBeUndefined();
  });

  it('is a no-op without a request id', async () => {
    const { client, replyCalls } = createFakeQuestionClient();
    await autoAnswerQuestion(client, {});
    expect(replyCalls).toEqual([]);
  });
});

describe('handleQuestionAsked', () => {
  it('answers a question.asked event whose sessionID differs from the active session', async () => {
    // This is the wedge fix: previously the `question.asked` case in
    // OpenCodeProvider's event loop skipped events where `req.sessionID` was
    // set and did not match the turn's own session. The server is shared, so
    // a skipped foreign-session question stayed wedged until the next
    // runtime creation ran drainPendingQuestions. handleQuestionAsked is what
    // that switch case now delegates to unconditionally — assert it answers
    // regardless of sessionID, simulating a question raised by some other,
    // unrelated session on the shared server.
    const { client, replyCalls } = createFakeQuestionClient();

    await handleQuestionAsked(client, {
      id: 'que_foreign_session',
      sessionID: 'ses_some_other_session',
      questions: [{}],
    });

    expect(replyCalls).toEqual([{ requestID: 'que_foreign_session', answers: [[QUESTION_STEERING_TEXT]] }]);
  });

  it('answers regardless of whether sessionID is present at all', async () => {
    const { client, replyCalls } = createFakeQuestionClient();
    await handleQuestionAsked(client, { id: 'que_no_session', questions: [{}] });
    expect(replyCalls.map((c) => c.requestID)).toEqual(['que_no_session']);
  });

  it('returns after its timeout and logs a never-resolving reply', async () => {
    // The event pump does not await this handler. Its own bounded wait
    // still reports a hung reply and returns without throwing. A short
    // budget avoids waiting out the real 10s production default.
    const client: QuestionClient = {
      question: {
        reply: () => new Promise(() => {}),
        list: async () => ({ data: [] }),
      },
    };

    const original = console.error;
    const messages: string[] = [];
    console.error = ((...args: unknown[]) => {
      messages.push(String(args[0]));
    }) as typeof console.error;

    try {
      await expect(handleQuestionAsked(client, { id: 'que_hung', questions: [{}] }, 20)).resolves.toBeUndefined();
    } finally {
      console.error = original;
    }

    expect(messages.some((m) => m.includes('Timed out') && m.includes('que_hung'))).toBe(true);
  });
});

describe('drainPendingQuestions', () => {
  it('answers every question already pending when the runtime starts', async () => {
    const { client, replyCalls } = createFakeQuestionClient({
      pending: [
        { id: 'que_a', sessionID: 'ses_1', questions: [{}] },
        { id: 'que_b', sessionID: 'ses_2', questions: [{}, {}] },
      ],
    });

    await drainPendingQuestions(client);

    expect(replyCalls.map((c) => c.requestID)).toEqual(['que_a', 'que_b']);
    expect(replyCalls[1].answers).toHaveLength(2);
  });

  it('does nothing when there are no pending questions', async () => {
    const { client, replyCalls } = createFakeQuestionClient({ pending: [] });
    await drainPendingQuestions(client);
    expect(replyCalls).toEqual([]);
  });

  it('never throws when listing itself fails', async () => {
    const client: QuestionClient = {
      question: {
        reply: async () => ({ data: true }),
        list: async () => {
          throw new Error('connection reset');
        },
      },
    };
    await expect(drainPendingQuestions(client)).resolves.toBeUndefined();
  });

  it('gives up after its timeout and logs, so a hung round-trip cannot block runtime startup', async () => {
    // The `.list()` call here never resolves — simulating a hung round-trip
    // to the OpenCode server. drainPendingQuestions is awaited inline in the
    // runtime-startup path, so it must return on its own timeout budget
    // rather than hang the caller forever. A short budget (well under bun
    // test's default timeout) keeps this deterministic and fast instead of
    // actually waiting out the real 10s production default.
    const client: QuestionClient = {
      question: {
        reply: async () => ({ data: true }),
        list: () => new Promise(() => {}),
      },
    };

    const original = console.error;
    const messages: string[] = [];
    console.error = ((...args: unknown[]) => {
      messages.push(String(args[0]));
    }) as typeof console.error;

    try {
      await expect(drainPendingQuestions(client, 20)).resolves.toBeUndefined();
    } finally {
      console.error = original;
    }

    expect(messages.some((m) => m.includes('Timed out') && m.includes('draining pending questions'))).toBe(true);
  });
});
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