Skip to content

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

add-onecli

Flagged

Install or refresh OneCLI as NanoClaw's gateway provider. Use when setup selects OneCLI, an existing OneCLI-backed install is migrated to the gateway seam, or its runtime, approval bridge, setup, and agent guidance must be restored from the in-tree package.

FileKindSize
REMOVE.mdmarkdown576 B
SKILL.mdskill md10.4 KB
apply-fixtures.jsonconfig1.9 KB
gateway.jsonconfig123 B
payload/docs/onecli-upgrades.mdmarkdown28.0 KB
payload/src/gateway-providers/onecli-chatgpt-stub.test.tsscript4.9 KB
payload/src/gateway-providers/onecli-chatgpt-stub.tsscript3.9 KB
payload/src/gateway-providers/onecli-files.test.tsscript4.4 KB
payload/src/gateway-providers/onecli-files.tsscript4.2 KB
payload/src/gateway-providers/onecli-install.test.tsscript1.1 KB
payload/src/gateway-providers/onecli-provider-credentials.test.tsscript7.6 KB
payload/src/gateway-providers/onecli-provider-credentials.tsscript9.6 KB
payload/src/gateway-providers/onecli.test.tsscript44.6 KB
payload/src/gateway-providers/onecli.tsscript18.2 KB
references/chatgpt-oauth-refresh.mdmarkdown1.1 KB
scripts/auth.test.tsscript10.1 KB
scripts/auth.tsscript7.5 KB
scripts/check-grants-gateway.shexecutablescript3.5 KB
scripts/credential-store.test.tsscript6.4 KB
scripts/credential-store.tsscript2.9 KB
scripts/detect.tsscript873 B
scripts/dial-key-check.shexecutablescript11.1 KB
scripts/install-claude.shexecutablescript1.6 KB
scripts/no-proxy.test.tsscript1.6 KB
scripts/post-upgrade-check.shexecutablescript2.7 KB
scripts/postgres-check.tsscript222 B
scripts/postgres-password.test.tsscript29.2 KB
scripts/postgres-password.tsscript20.2 KB
scripts/pre-upgrade-check.shexecutablescript2.9 KB
scripts/provider-credentials.test.tsscript21.9 KB
scripts/provider-credentials.tsscript12.7 KB
scripts/proxy-check.tsscript213 B
scripts/readiness.test.tsscript1.1 KB
scripts/register-claude-token.shexecutablescript4.0 KB
scripts/remote-proxy.test.tsscript10.9 KB
scripts/remote-proxy.tsscript4.2 KB
scripts/secret-input.test.tsscript10.4 KB
scripts/secret-input.tsscript4.9 KB
scripts/setup.tsscript23.1 KB
versions.jsonconfig84 B

scripts/remote-proxy.test.ts

View on GitHub
import { execFileSync } from 'node:child_process';
import { mkdtempSync, readFileSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
import os, { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';

import { describe, expect, it, vi } from 'vitest';

import { applySkill, fullyApplied } from '../../../../scripts/skill-apply.js';
import { gatePolicy } from '../../../../scripts/skill-policy.js';
import { advertisedProxy, proxyCheck, remoteProxyHint } from './remote-proxy.js';

const GATEWAY = 'http://gw.example.com:10254';
const advertising = (env: Record<string, string> = { HTTPS_PROXY: 'http://x:t@host.docker.internal:10255' }) =>
  vi.fn(
    async (_url: string | URL | Request, _init?: RequestInit) => new Response(JSON.stringify({ env }), { status: 200 }),
  );

describe('remote gateway proxy hint', () => {
  // (gateway, proxy it hands agents) -> the line the hint names, or null for no hint.
  it.each([
    [GATEWAY, 'host.docker.internal:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, 'host.docker.internal.:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, '127.0.0.1:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, 'localhost:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, 'localhost.:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, '[::1]:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, '0.0.0.0:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, '[::]:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, '[::ffff:127.0.0.1]:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, '[::ffff:127.1.2.3]:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, '[::ffff:10.0.0.5]:10255', null],
    [GATEWAY, '[::ffff:0.0.0.0]:10255', 'GATEWAY_BASE_URL=gw.example.com:10255'],
    [GATEWAY, 'host.docker.internal:20255', 'GATEWAY_BASE_URL=gw.example.com:20255'],
    [GATEWAY, 'gw.example.com:10255', null],
    [GATEWAY, '10.0.0.5:10255', null],
    ['http://127.0.0.1:10254', 'host.docker.internal:10255', null],
    ['http://localhost:10254', 'host.docker.internal:10255', null],
    ['http://localhost.:10254', 'host.docker.internal:10255', null],
    ['http://[::1]:10254', 'host.docker.internal:10255', null],
    ['http://0.0.0.0:10254', 'host.docker.internal:10255', null],
    ['http://[::]:10254', 'host.docker.internal:10255', null],
    ['http://[::ffff:127.0.0.1]:10254', 'host.docker.internal:10255', null],
    ['http://[::ffff:0.0.0.0]:10254', 'host.docker.internal:10255', null],
    [GATEWAY, null, null],
  ])('gateway %s, proxy %s: %s', (gateway, advertised, line) => {
    const hint = remoteProxyHint(gateway, advertised ? new URL(`http://x:aoc_secret@${advertised}`) : null);
    if (line === null) {
      expect(hint).toBeNull();
      return;
    }
    expect(hint).toContain(line);
    expect(hint).toContain(`ONECLI_GATEWAY_PORT in place of ${line.split(':')[1]}`);
    expect(hint).toContain('Remote gateway');
    // The proxy URL carries the agent token.
    expect(hint).not.toContain('aoc_secret');
  });

  it("treats a gateway URL on one of this machine's own addresses as local", () => {
    const nic = { netmask: '', mac: '00:00:00:00:00:00', internal: false, cidr: null };
    const spy = vi.spyOn(os, 'networkInterfaces').mockReturnValue({
      en0: [
        { ...nic, address: '192.168.1.20', family: 'IPv4' },
        { ...nic, address: 'fd00::20', family: 'IPv6', scopeid: 0 },
      ],
    });
    try {
      const proxy = new URL('http://x:t@host.docker.internal:10255');
      expect(remoteProxyHint('http://192.168.1.20:10254', proxy)).toBeNull();
      expect(remoteProxyHint('http://[fd00::20]:10254', proxy)).toBeNull();
      expect(remoteProxyHint('http://192.168.1.21:10254', proxy)).toContain('GATEWAY_BASE_URL=192.168.1.21:10255');
    } finally {
      spy.mockRestore();
    }
  });

  // (gateway URL, line the hint names or null) with 192.168.1.20 as this machine's only IPv4 address.
  it.each([
    ['http://[::ffff:192.168.1.20]:10254', null],
    ['http://[0:0:0:0:0:ffff:c0a8:114]:10254', null],
    ['http://[::ffff:192.168.1.21]:10254', 'GATEWAY_BASE_URL=[::ffff:c0a8:115]:10255'],
    ['http://[::ffff:10.0.0.5]:10254', 'GATEWAY_BASE_URL=[::ffff:a00:5]:10255'],
  ])('mapped own address: gateway %s, hint %s', (gateway, line) => {
    const nic = { netmask: '', mac: '00:00:00:00:00:00', internal: false, cidr: null };
    const spy = vi.spyOn(os, 'networkInterfaces').mockReturnValue({
      en0: [{ ...nic, address: '192.168.1.20', family: 'IPv4' }],
    });
    try {
      const hint = remoteProxyHint(gateway, new URL('http://x:t@host.docker.internal:10255'));
      if (line === null) expect(hint).toBeNull();
      else expect(hint).toContain(line);
    } finally {
      spy.mockRestore();
    }
  });

  it("still warns for a remote gateway when this machine's addresses can't be listed", () => {
    const spy = vi.spyOn(os, 'networkInterfaces').mockImplementation(() => {
      throw new Error('uv_interface_addresses failed');
    });
    try {
      const proxy = new URL('http://x:t@host.docker.internal:10255');
      expect(remoteProxyHint(GATEWAY, proxy)).toContain('GATEWAY_BASE_URL=gw.example.com:10255');
      expect(remoteProxyHint('http://127.0.0.1:10254', proxy)).toBeNull();
    } finally {
      spy.mockRestore();
    }
  });

  // (this machine's host name, gateway URL) -> the line the hint names, or null for no hint.
  it.each([
    ['Maximus.home', 'http://maximus.home:10254', null],
    ['Maximus.home', 'http://MAXIMUS.HOME.:10254', null],
    ['Maximus.home.', 'http://maximus.home:10254', null],
    ['nc-host', 'http://nc-host:10254', null],
    // Other names can belong to another machine (a search domain, an mDNS rename), so they stay remote.
    ['Maximus.home', 'http://maximus:10254', 'GATEWAY_BASE_URL=maximus:10255'],
    ['Maximus.home', 'http://maximus.local:10254', 'GATEWAY_BASE_URL=maximus.local:10255'],
    ['nc-host', 'http://nc-host.example.com:10254', 'GATEWAY_BASE_URL=nc-host.example.com:10255'],
  ])('host name %s, gateway %s: %s', (name, gateway, line) => {
    const spy = vi.spyOn(os, 'hostname').mockReturnValue(name);
    try {
      const hint = remoteProxyHint(gateway, new URL('http://x:t@host.docker.internal:10255'));
      if (line === null) expect(hint).toBeNull();
      else expect(hint).toContain(line);
    } finally {
      spy.mockRestore();
    }
  });

  it("still warns for a remote gateway when this machine's host name can't be read", () => {
    const spy = vi.spyOn(os, 'hostname').mockImplementation(() => {
      throw new Error('uv_os_gethostname failed');
    });
    try {
      const proxy = new URL('http://x:t@host.docker.internal:10255');
      expect(remoteProxyHint(GATEWAY, proxy)).toContain('GATEWAY_BASE_URL=gw.example.com:10255');
    } finally {
      spy.mockRestore();
    }
  });
});

describe('advertised proxy', () => {
  it("reads the default agent's proxy", async () => {
    const fetchImpl = advertising();
    const got = await advertisedProxy(`${GATEWAY}/`, 'oc_key', fetchImpl as unknown as typeof fetch);
    expect(got?.host).toBe('host.docker.internal:10255');
    expect(fetchImpl.mock.calls[0][0]).toBe(`${GATEWAY}/v1/container-config?agent=default`);
  });

  it('gives null for an answer with no proxy', async () => {
    expect(await advertisedProxy(GATEWAY, undefined, advertising({}) as unknown as typeof fetch)).toBeNull();
  });
});

describe('proxy check after setup', () => {
  it('warns for a remote gateway that sends agents to their own machine, asking with the saved key', async () => {
    const dir = mkdtempSync(join(tmpdir(), 'nc-proxy-key-'));
    writeFileSync(join(dir, '.env'), 'ONECLI_API_KEY=oc_key\n');
    const cwd = vi.spyOn(process, 'cwd').mockReturnValue(dir);
    try {
      const fetchImpl = advertising();
      const got = await proxyCheck({ NANOCLAW_ONECLI_API_HOST: GATEWAY }, fetchImpl as unknown as typeof fetch);
      expect(got.warn).toBe('yes');
      expect(got.hint).toContain('GATEWAY_BASE_URL=gw.example.com:10255');
      expect((fetchImpl.mock.calls[0][1]?.headers as Record<string, string>).Authorization).toBe('Bearer oc_key');
    } finally {
      cwd.mockRestore();
      rmSync(dir, { recursive: true, force: true });
    }
  });

  it('asks nothing when setup was not pointed at a remote gateway', async () => {
    const fetchImpl = advertising();
    expect(await proxyCheck({}, fetchImpl as unknown as typeof fetch)).toEqual({ warn: 'no', hint: 'none' });
    expect(fetchImpl).not.toHaveBeenCalled();
  });

  // SKILL.md runs this file and binds its stdout as JSON; empty output fails the install.
  it('prints its verdict as JSON when the checkout path has a space', () => {
    const dir = mkdtempSync(join(tmpdir(), 'nc-proxy-'));
    const repo = join(dir, 'Nano Claw');
    const root = fileURLToPath(new URL('../../../../', import.meta.url));
    symlinkSync(root, repo);
    try {
      const env = { ...process.env, NANOCLAW_ONECLI_API_HOST: '' };
      const script = join(repo, '.claude/skills/add-onecli/scripts/proxy-check.ts');
      const loader = join(root, 'node_modules/tsx/dist/loader.mjs');
      const out = execFileSync(process.execPath, ['--import', loader, script], { cwd: dir, env, encoding: 'utf8' });
      expect(JSON.parse(out)).toEqual({ warn: 'no', hint: 'none' });
    } finally {
      unlinkSync(repo);
      rmSync(dir, { recursive: true, force: true });
    }
  }, 30_000);

  it('never fails, even when the gateway address is not a URL', async () => {
    const env = { NANOCLAW_ONECLI_API_HOST: 'not a url' };
    expect(await proxyCheck(env, advertising() as unknown as typeof fetch)).toEqual({ warn: 'no', hint: 'none' });
  });
});

// The wizard shows the skill's operator notes on screen; setup.ts output only reaches logs/setup.log.
describe('the skill shows the hint', () => {
  const md = readFileSync(new URL('../SKILL.md', import.meta.url), 'utf8');
  const hint = remoteProxyHint(GATEWAY, new URL('http://x:t@host.docker.internal:10255'))!;

  it.each([
    ['shows the hint when the check warns', { warn: 'yes', hint }, [hint]],
    ['shows nothing when it does not', { warn: 'no', hint: 'none' }, []],
  ])('%s', async (_case, verdict, notes) => {
    const dir = mkdtempSync(join(tmpdir(), 'nc-onecli-proxy-'));
    try {
      writeFileSync(join(dir, 'SKILL.md'), md.slice(md.indexOf('## Check the proxy address')));
      const exec = (cmd: string) => (cmd.includes('scripts/proxy-check.ts') ? JSON.stringify(verdict) : '');
      const res = await applySkill(dir, dir, { exec });
      expect(fullyApplied(res)).toBe(true);
      expect(res.operatorMessages).toEqual(notes);
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });

  it('shows the notes without holding the wizard for a confirm', () => {
    // The proxy note, then the database password note.
    expect([...gatePolicy(md).values()].map((gate) => gate.needsConfirm)).toEqual([false, false]);
  });
});
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: 471kUpdated 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: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated 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: 322kUpdated Claude CodeCodexVerifiedInstall