nanocoai/nanoclaw / .claude/skills/add-onecli
add-onecli
FlaggedInstall 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.
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' };
}
}
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: 471k | 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: 322k | 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: 322k | 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: 322k | Updated | Claude CodeCodex | Verified | Install |