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.ts

View on GitHub
/** A remote OneCLI gateway must hand agents its own address as their proxy, or every model call hangs. */
import os from 'os';

import { readEnvFile } from '../../../../src/env.js';

/** The proxy a gateway hands its default agent, or null when its answer has none. */
export async function advertisedProxy(
  gatewayUrl: string,
  apiKey: string | undefined,
  fetchImpl: typeof fetch = fetch,
): Promise<URL | null> {
  const headers: Record<string, string> = {};
  if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
  if (process.env.ONECLI_PROJECT_ID) headers['X-Project-Id'] = process.env.ONECLI_PROJECT_ID;
  // Named: without agent= OneCLI creates a default agent when none exists.
  const url = `${gatewayUrl.replace(/\/+$/, '')}/v1/container-config?agent=default`;
  const res = await fetchImpl(url, { headers, signal: AbortSignal.timeout(5000) });
  if (!res.ok) return null;
  const env = ((await res.json()) as { env?: Record<string, unknown> } | null)?.env;
  const raw = env?.HTTPS_PROXY ?? env?.HTTP_PROXY;
  return typeof raw === 'string' ? new URL(raw) : null;
}

/**
 * Loopback, localhost or a wildcard: whoever uses it reaches its own machine. URL writes IPv6 as [::1] and [::],
 * and IPv4-mapped 127.x and 0.0.0.0 as [::ffff:7fxx:yyyy] and [::ffff:0:0].
 */
function ownMachine(hostname: string): boolean {
  return /^(localhost\.?|127\.\d+\.\d+\.\d+|0\.0\.0\.0|\[::1?\]|\[::ffff:(7f[0-9a-f]{2}:[0-9a-f]{1,4}|0:0)\])$/.test(
    hostname,
  );
}

/**
 * This machine's host name as `os.hostname()` gives it. No short or `.local` form and no DNS lookup: those
 * can name another machine, and taking a remote gateway for this one hides the warning it needs.
 */
function ownName(): string | null {
  try {
    return os.hostname().toLowerCase().replace(/\.$/, '') || null;
  } catch {
    return null;
  }
}

/** A gateway URL that names this machine: loopback, a wildcard, its host name or one of its own addresses. */
function thisMachine(hostname: string): boolean {
  if (ownMachine(hostname) || hostname.replace(/\.$/, '') === ownName()) return true;
  let own: os.NetworkInterfaceInfo[];
  try {
    own = Object.values(os.networkInterfaces()).flatMap((nics) => nics ?? []);
  } catch {
    return false; // Some sandboxes can't list interfaces; the address checks above still hold.
  }
  // URL brackets IPv6 and writes an IPv4 address given in IPv6 form as [::ffff:hex:hex]; compare its spelling.
  return own.some((n) =>
    n.family === 'IPv6'
      ? hostname === `[${n.address}]`
      : hostname === n.address || hostname === new URL(`http://[::ffff:${n.address}]`).hostname,
  );
}

/** The hint naming the line to set, or null; host and port only, as the proxy URL carries the agent's token. */
export function remoteProxyHint(gatewayUrl: string, proxy: URL | null): string | null {
  if (!proxy || thisMachine(new URL(gatewayUrl).hostname)) return null;
  const host = proxy.hostname.toLowerCase();
  // URL keeps a trailing dot, and `host.docker.internal.` names the same host.
  if (host.replace(/\.$/, '') !== 'host.docker.internal' && !ownMachine(host)) return null;
  const port = proxy.port || (proxy.protocol === 'https:' ? '443' : '80');
  return (
    `The remote OneCLI gateway tells agents to use the proxy ${host}:${port}, their own machine, so model calls ` +
    `will hang with no reply. On the gateway host, set GATEWAY_BASE_URL=${new URL(gatewayUrl).hostname}:${port} ` +
    `in ~/.onecli/.env (with your ONECLI_GATEWAY_PORT in place of ${port} if you set one) and recreate the onecli ` +
    'container: see "Remote gateway" in docs/onecli-upgrades.md.'
  );
}

/** The skill's check as JSON for its capture: never throws, and the hint is never empty, so the capture binds. */
export async function proxyCheck(
  env: NodeJS.ProcessEnv = process.env,
  fetchImpl: typeof fetch = fetch,
): Promise<{ warn: 'yes' | 'no'; hint: string }> {
  const gatewayUrl = env.NANOCLAW_ONECLI_API_HOST?.trim();
  if (!gatewayUrl) return { warn: 'no', hint: 'none' };
  try {
    const apiKey = readEnvFile(['ONECLI_API_KEY']).ONECLI_API_KEY;
    const hint = remoteProxyHint(gatewayUrl, await advertisedProxy(gatewayUrl, apiKey, fetchImpl));
    return hint ? { warn: 'yes', hint } : { warn: 'no', hint: 'none' };
  } catch {
    return { warn: 'no', hint: 'none' };
  }
}
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