/** * Copyright 2026 aphrody-code * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * `bxc` — CLI router. * * Dispatches subcommands to the appropriate module via dynamic import so * that FFI libraries (rust-bridge, curl-impersonate) are not loaded unless * actually needed. */ // Self-healing trampoline: Bun's native HTTP fetch does not support socks5h proxy. // If an unhandled socks proxy is present in env, re-spawn cleanly. if ( !process.env.__BXC_UNSET_SOCKS_PROXY__ && (process.env.https_proxy?.includes("socks") || process.env.HTTPS_PROXY?.includes("socks") || process.env.ALL_PROXY?.includes("socks") || process.env.all_proxy?.includes("socks")) ) { const env: Record = { ...process.env, __BXC_UNSET_SOCKS_PROXY__: "1" }; const savedProxy = process.env.https_proxy || process.env.HTTPS_PROXY || process.env.all_proxy || process.env.ALL_PROXY || process.env.http_proxy || process.env.HTTP_PROXY; if (savedProxy) { env.BXC_PROXY = savedProxy; } delete env.https_proxy; delete env.HTTPS_PROXY; delete env.http_proxy; delete env.HTTP_PROXY; delete env.all_proxy; delete env.ALL_PROXY; const argvToPass = process.argv[1]?.includes("$bunfs") ? process.argv.slice(2) : process.argv.slice(1); const proc = Bun.spawnSync([process.execPath, ...argvToPass], { env, stdio: ["inherit", "inherit", "inherit"], }); process.exit(proc.exitCode); } import { join } from "node:path"; import { ROOT, parseCommonArgs, logger, EXIT } from "./shared.ts"; // --------------------------------------------------------------------------- // Version resolution // --------------------------------------------------------------------------- declare const __BXC_VERSION__: string; declare const __BXC_BUILD_TIME__: string; let _pkgVersion = typeof __BXC_VERSION__ !== "undefined" ? __BXC_VERSION__ : "0.0.0-dev"; // --------------------------------------------------------------------------- // Usage // --------------------------------------------------------------------------- function printUsage(): void { Bun.stdout.write( `bxc v${_pkgVersion} — Bun-native browser engine Usage: bxc [options] Subcommands: serve Start a CDP server; --agent: API + MCP/HTTP + crawler daemon in one process install Install runtime assets; use --full for all native dependencies self-update Update the bxc binary from the latest GitHub release (--check) chrome Native Chromium management recon One-shot URL → recon doc (Markdown by default) detect Framework / CMS / library detection via multi-signal scrape Extract textContent from CSS-matched elements wiki Read a MediaWiki site through its API (Fandom, Wikipedia, Miraheze, wiki.gg) search Google Web Search → clean results (text/JSON/Markdown) api Run Bxc as an HTTP JSON API cookies Cookie jar tools har HAR (HTTP Archive) recorder/replayer mirror Download a full site (HTML+CSS+JS+assets) fut FIFA Ultimate Team (FUTGG/FUTBin) player price & stats scraper voiranime VoirAnime streaming site catalog search & resolver (e.g. "inazuma") animesama anime-sama.to catalogue, seasons/episodes & player resolver archive Internet Archive metadata, files, advanced search & Wayback CDX client dragonball Dragon Ball multi-source scraping (Official portal, Toei lineups, Jajanken, Toriyama archives) frames Frame-by-frame anime index (local ColorLayout) + trace.moe lookup assets Attributed image and GIF provider search doctor Validate the production runtime and optional integrations capabilities List every CLI, MCP, API and package capability mcp Serve the CLI capabilities over MCP stdio google Google properties auditor & client gemini Unified Gemini Toolchain (Aphrody x AGY x Rust x Python x Web) aphrody Sovereign Aphrody ecosystem bridge (PostgreSQL, Redis, Axum API, MCP) xcom X.com profile scraper x Native X/Twitter client (profile, tweets, search, news, rank, foryou) via cookie auth + local x-algorithm ranking grok xAI Grok API (chat, models, tts, stt) — OIDC ~/.grok/auth.json or XAI_API_KEY actor Manage and run Bxc crawler Actors crawl High-throughput web crawler & continuous indexer (--massive, --workers, --daemon) revalidate Refresh indexed pages with conditional requests (ETag / Last-Modified) crawl-worker Run the autonomous recursive crawler worker daemon 24/7 worker Join a sharded crawl cluster (Redis streams + leases); seed / stats export Export dataset items to SQLite, PostgreSQL, JSON, CSV, or HTML extract Typed JSON records from pages via learned selectors (--schema) Global Options: --insecure, -k Bypass TLS certificate validation --proxy Use HTTP/SOCKS5 proxy --quiet, -q Suppress non-essential output --json Emit JSON output where applicable --timeout Global timeout (default 30000ms) --version, -V Print version --help, -h Print this help Examples: bxc serve --cdp-port 9222 bxc recon https://google.com --insecure bxc detect https://design.google --json bxc is a high-performance browser engine optimized for VPS and Google-grade stealth. It combines In-Process FFI (Rust/V8) with a native Rust-driven Chromium core. `, ); } // --------------------------------------------------------------------------- // Router // --------------------------------------------------------------------------- async function main() { if (_pkgVersion === "0.0.0-dev") { try { const pkgPath = join(ROOT, "package.json"); const text = await Bun.file(pkgPath).text(); const pkg = JSON.parse(text) as { version?: string }; if (typeof pkg.version === "string") { _pkgVersion = pkg.version; } } catch { // Keep "0.0.0-dev". } } const { opts, remaining } = parseCommonArgs(process.argv.slice(2)); const subcommand = remaining[0]; const args = remaining.slice(1); if (opts.json) { // Might want to suppress logger if JSON is requested } switch (subcommand) { case "serve": { const mod = await import("./serve.ts"); await mod.main(args, opts); break; } case "install": { const mod = await import("./install.ts"); await mod.main(args, opts); break; } case "self-update": case "upgrade": { const mod = await import("./self-update.ts"); await mod.main(args, opts); break; } case "chrome": { const mod = await import("./chrome.ts"); await mod.main(args, opts); break; } case "recon": case "docs": { const mod = await import("./recon.ts"); await mod.main(args, opts); break; } case "detect": { const mod = await import("./detect.ts"); await mod.main(args, opts); break; } case "scrape": { const mod = await import("./scrape.ts"); await mod.main(args, opts); break; } case "wiki": { const mod = await import("./wiki.ts"); await mod.main(args, opts); break; } case "search": { const mod = await import("./search.ts"); await mod.main(args, opts); break; } case "cookies": { const mod = await import("./cookies.ts"); await mod.main(args, opts); break; } case "har": { const mod = await import("./har.ts"); await mod.main(args, opts); break; } case "mirror": { const mod = await import("./mirror.ts"); await mod.main(args, opts); break; } case "fut": { const mod = await import("./fut.ts"); await mod.main(args, opts); break; } case "voiranime": { const mod = await import("./voiranime.ts"); await mod.main(args, opts); break; } case "frames": { const mod = await import("./frames.ts"); await mod.main(args, opts); break; } case "assets": { const mod = await import("./assets.ts"); await mod.main(args, opts); break; } case "doctor": { const mod = await import("./doctor.ts"); await mod.main(args, opts); break; } case "mcp": { const mod = await import("../mcp/server.ts"); await mod.main(); break; } case "capabilities": { const mod = await import("./capabilities.ts"); await mod.main(args, opts); break; } case "animesama": { const mod = await import("./animesama.ts"); await mod.main(args, opts); break; } case "archive": { const mod = await import("./archive.ts"); await mod.main(args, opts); break; } case "dragonball": { const mod = await import("./dragonball.ts"); await mod.main(args, opts); break; } case "gemini": { const mod = await import("./gemini.ts"); await mod.runGeminiCli(args, opts); break; } case "google": { const mod = await import("./google.ts"); await mod.main(args, opts); break; } case "xcom": { const mod = await import("./xcom.ts"); await mod.main(args, opts); break; } case "x": { const mod = await import("./x.ts"); await mod.main(args, opts); break; } case "grok": { const mod = await import("./grok.ts"); await mod.main(args, opts); break; } case "api": { const mod = await import("./api.ts"); await mod.main(args, opts); break; } case "actor": { const mod = await import("./actor.ts"); await mod.main(args, opts); break; } case "crawl": { const mod = await import("./crawl.ts"); await mod.main(args, opts); break; } case "revalidate": { const mod = await import("./revalidate.ts"); await mod.main(args, opts); break; } case "crawl-worker": { const mod = await import("./crawl-worker.ts"); await mod.main(args, opts); break; } case "worker": { const mod = await import("./worker.ts"); await mod.main(args, opts); break; } case "export": { const mod = await import("./export.ts"); await mod.main(args, opts); break; } case "extract": { const mod = await import("./extract.ts"); await mod.main(args, opts); break; } case "aphrody": { const mod = await import("./aphrody.ts"); await mod.main(args, opts); break; } case "--version": case "-V": { Bun.stdout.write(`bxc ${_pkgVersion}\n`); break; } case "--help": case "-h": case undefined: { printUsage(); if ( subcommand !== undefined && subcommand !== "--help" && subcommand !== "-h" ) { logger.error(`Unknown subcommand: ${subcommand}`); process.exit(EXIT.MISUSE); } break; } default: { printUsage(); logger.error(`Unknown subcommand: ${subcommand}`); process.exit(EXIT.MISUSE); } } } main().catch((err) => { logger.error(err instanceof Error ? (err.stack ?? err.message) : String(err)); process.exit(EXIT.SOFTWARE); });