Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions scripts/toolbox.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
// public/toolbox/engine.<hash>.js, and src/data/generated/toolbox.json tells
// the pages its file name and the library versions inside it.
//
// When the engine repo has the `bitanon` command (bin/bitanon.dart), its tool
// list is read from `bitanon mcp` (the MCP tools/list answer) into
// toolbox.json too, for the reference on /toolbox/cli/.
//
// The output is cached in .cache/toolbox/ by source, versions and SDK, so a
// rebuild without changes skips the work. Without a Dart SDK this is a
// warning locally (the Toolbox pages say the engine is missing) but a hard
Expand Down Expand Up @@ -90,7 +94,7 @@ const versions = Object.fromEntries(

// Cache key: engine sources + resolved versions + SDK.
const hash = createHash('sha256');
for (const dir of ['lib', 'web', 'test']) {
for (const dir of ['lib', 'web', 'test', 'bin'].filter((d) => fs.existsSync(path.join(pkg, d)))) {
for (const f of fs.readdirSync(path.join(pkg, dir), { recursive: true }).sort()) {
const p = path.join(pkg, dir, String(f));
if (fs.statSync(p).isFile()) hash.update(`${dir}/${f}\n`).update(fs.readFileSync(p));
Expand All @@ -99,6 +103,7 @@ for (const dir of ['lib', 'web', 'test']) {
hash.update(fs.readFileSync(path.join(pkg, 'pubspec.yaml'))).update(JSON.stringify(versions)).update(sdk);
const key = hash.digest('hex').slice(0, 12);
const cached = path.join(cacheDir, `engine.${key}.js`);
const cachedCli = path.join(cacheDir, `cli.${key}.json`);

if (fs.existsSync(cached)) {
log(`engine up to date (${key})`);
Expand Down Expand Up @@ -127,6 +132,26 @@ if (fs.existsSync(cached)) {
}
}

// The `bitanon` command's tools, as its MCP server lists them.
let cli = null;
if (fs.existsSync(path.join(pkg, 'bin', 'bitanon.dart'))) {
if (!fs.existsSync(cachedCli)) {
log('reading the bitanon command\'s tool list');
const input = [
{ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 'bitanon.dev', version: '1' } } },
{ jsonrpc: '2.0', id: 2, method: 'tools/list' },
].map((m) => JSON.stringify(m)).join('\n') + '\n';
try {
const out = dart(['run', 'bin/bitanon.dart', 'mcp'], { input, stdio: ['pipe', 'pipe', 'pipe'] });
const [init, list] = out.trim().split('\n').map((l) => JSON.parse(l));
fs.writeFileSync(cachedCli, JSON.stringify({ version: init.result.serverInfo.version, tools: list.result.tools }));
} catch (e) {
fail(`bitanon mcp failed:\n${e.stdout || ''}${e.stderr || e.message}`);
}
}
cli = JSON.parse(fs.readFileSync(cachedCli, 'utf8'));
}

// Publish under a content-addressed name, so browsers never mix an old engine
// with new pages.
fs.mkdirSync(publicDir, { recursive: true });
Expand All @@ -135,5 +160,5 @@ for (const f of fs.readdirSync(publicDir)) {
}
const engine = `engine.${key}.js`;
fs.copyFileSync(cached, path.join(publicDir, engine));
writeData({ engine, versions, sdk: sdk.replace(/^Dart SDK version: /, '').split(' ')[0] });
writeData({ engine, versions, sdk: sdk.replace(/^Dart SDK version: /, '').split(' ')[0], cli });
log(`wrote public/toolbox/${engine} (${Math.round(fs.statSync(cached).size / 1024)} KB)`);
19 changes: 18 additions & 1 deletion src/lib/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,22 @@ export const toolUrl = (t: Tool) => url(`toolbox/${t.id}/`);
/** The library's project entry (for its accent colour and page link). */
export const libraryProject = (l: Library) => projects.find((p) => p.slug === l);

export const engine = generated as { engine: string | null; versions: Partial<Record<Library, string | null>>; sdk?: string; error?: string };
/** A tool of the `bitanon` command, as its MCP server lists it. */
export interface CliTool {
name: string;
title?: string;
description: string;
inputSchema: {
properties: Record<string, { type: string; description: string; enum?: string[]; default?: unknown; items?: { enum?: string[] } }>;
required?: string[];
};
}

export const engine = generated as {
engine: string | null;
versions: Partial<Record<Library, string | null>>;
sdk?: string;
error?: string;
cli?: { version: string; tools: CliTool[] } | null;
};
export const workerUrl = engine.engine ? url(`toolbox/worker.js?engine=${engine.engine}`) : null;
178 changes: 178 additions & 0 deletions src/pages/toolbox/cli.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
---
// /toolbox/cli/: the `bitanon` command and its MCP server. The tool reference
// comes from the command itself (scripts/toolbox.mjs reads its MCP tool list
// into toolbox.json), so it follows the engine repo without edits here.
import { Code } from 'astro:components';
import Site from '../../layouts/Site.astro';
import '../../styles/toolbox.css';
import { engine, type CliTool } from '../../lib/toolbox';
import { url } from '../../lib/data';
import RfcText from '../../components/RfcText.astro';

const cli = engine.cli ?? null;
const repo = 'https://github.com/bitanon/toolbox';
const releases = `${repo}/releases/latest`;
const description =
'The Bitanon Toolbox on your machine: the bitanon command hashes, encodes, encrypts and generates from a terminal, and bitanon mcp offers the same tools to AI agents over MCP. Free, open source, and offline.';
const themes = { light: 'github-light-default', dark: 'github-dark-default' } as const;

const usage = `bitanon hash abc
# ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

bitanon hash --file archive.zip --algorithm sha256,blake2b256
echo -n "hello" | bitanon convert --to base64
bitanon argon2-hash "correct horse battery staple"
bitanon aead-encrypt "secret" --key $(bitanon random --length 32)
bitanon uuid --version 7 --count 3
bitanon totp --secret JBSWY3DPEHPK3PXP

bitanon help # every tool
bitanon help aes # one tool's options`;

const raw = 'https://raw.githubusercontent.com/bitanon/toolbox/main';
const installSh = `curl -fsSL ${raw}/install.sh | sh`;
const installPs = `irm ${raw}/install.ps1 | iex`;
const installDart = `dart pub global activate --source git ${repo}`;

const desktop = `{
"mcpServers": {
"bitanon": { "command": "/home/you/.local/bin/bitanon", "args": ["mcp"] }
}
}`;
const claudeCode = `claude mcp add bitanon -- ~/.local/bin/bitanon mcp`;


/** `inputFormat` -> `--input-format`. */
const flag = (name: string) => `--${name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`;
// The byte formats: the choice list of every *Format parameter.
const formats = cli?.tools.flatMap((t) => Object.entries(t.inputSchema.properties)).find(([n]) => n.endsWith('Format'))?.[1].enum;
const isFormats = (c: string[]) => !!formats && c.length === formats.length && c.every((x, i) => x === formats[i]);
const options = (t: CliTool) =>
Object.entries(t.inputSchema.properties).map(([name, p]) => {
const choices = p.enum ?? p.items?.enum;
const def = p.default === undefined ? null : Array.isArray(p.default) ? p.default.join(',') : String(p.default);
return {
flag: p.type === 'boolean' ? `${flag(name)}, --no-${flag(name).slice(2)}` : flag(name),
required: t.inputSchema.required?.includes(name) ?? false,
description: p.description,
def,
choices: choices && !isFormats(choices) ? choices : null,
anyFormat: !!choices && isFormats(choices),
};
});
---

<Site title="bitanon command and MCP server" {description} searchTitle="bitanon CLI and MCP server">
<div class="tb-line mx-auto max-w-4xl px-4 pt-8 pb-16 sm:px-6 lg:pt-10">
<nav aria-label="Breadcrumb" class="flex items-center gap-2 text-sm text-subtle">
<a href={url('toolbox/')} class="hover:text-fg">Toolbox</a>
<span aria-hidden="true">/</span>
<span>Command line and MCP</span>
</nav>
<h1 class="mt-3 text-3xl font-semibold tracking-tight text-fg sm:text-4xl">The Toolbox in your terminal and your AI agent</h1>
<p class="mt-3 max-w-3xl text-base leading-relaxed text-muted">
<code class="font-mono text-fg">bitanon</code> runs every <a href={url('toolbox/')} class="text-fg underline decoration-fg/30 underline-offset-2 hover:decoration-fg">Toolbox</a> tool from the command line, and{' '}
<code class="font-mono text-fg">bitanon mcp</code> offers them to AI agents as an MCP server. It is the same engine as the web pages, on the same{' '}
<a href={url('convertlib/')} class="text-fg underline decoration-fg/30 underline-offset-2 hover:decoration-fg">convertlib</a>,{' '}
<a href={url('hashlib/')} class="text-fg underline decoration-fg/30 underline-offset-2 hover:decoration-fg">hashlib</a> and{' '}
<a href={url('cipherlib/')} class="text-fg underline decoration-fg/30 underline-offset-2 hover:decoration-fg">cipherlib</a> libraries, compiled to a single native binary. It works offline and makes no network requests.
</p>

<section class="mt-10" aria-labelledby="install">
<h2 id="install" class="text-xl font-semibold text-fg">Install</h2>
<p class="mt-2 text-sm font-semibold text-fg">Linux and macOS</p>
<div class="tb-panel tb-code mt-2 overflow-hidden px-5 py-4 text-sm">
<Code code={installSh} lang="sh" themes={themes} defaultColor={false} wrap />
</div>
<p class="mt-4 text-sm font-semibold text-fg">Windows (PowerShell)</p>
<div class="tb-panel tb-code mt-2 overflow-hidden px-5 py-4 text-sm">
<Code code={installPs} lang="powershell" themes={themes} defaultColor={false} wrap />
</div>
<p class="mt-4 text-sm leading-relaxed text-muted">
The installer downloads the binary for your system (Linux x64 or arm64, macOS on Apple silicon or Intel, Windows x64) from the{' '}
<a href={releases} class="text-fg underline decoration-fg/30 underline-offset-2 hover:decoration-fg">latest release</a>, checks it against the release's SHA-256 checksums, and puts it in <code class="font-mono text-fg">~/.local/bin</code> (on Windows, <code class="font-mono text-fg">%LOCALAPPDATA%\bitanon\bin</code>, added to your PATH). You can also download a binary yourself, or install from source with the Dart SDK:
</p>
<div class="tb-panel tb-code mt-3 overflow-hidden px-5 py-4 text-sm">
<Code code={installDart} lang="sh" themes={themes} defaultColor={false} wrap />
</div>
</section>

<section class="mt-12" aria-labelledby="usage">
<h2 id="usage" class="text-xl font-semibold text-fg">Use it</h2>
<div class="tb-panel tb-code mt-4 overflow-hidden px-5 py-4 text-sm">
<Code code={usage} lang="sh" themes={themes} defaultColor={false} wrap />
</div>
<ul class="mt-4 grid gap-2 text-sm leading-relaxed text-muted">
<li>Data comes from the argument, <code class="font-mono text-fg">--file &lt;path&gt;</code> or standard input. Files and standard input are read byte for byte, so <code class="font-mono text-fg">bitanon hash &lt; file</code> gives the same answer as <code class="font-mono text-fg">sha256sum</code>. Set the format flag (for example <code class="font-mono text-fg">--from base64</code>) to read them as text instead.</li>
<li><code class="font-mono text-fg">--json</code> prints the full result as JSON, for scripts.</li>
<li>Exit codes: 0 on success, 1 when a tool fails or a password does not match, 2 for a usage mistake.</li>
</ul>
</section>

<section class="mt-12" aria-labelledby="mcp">
<h2 id="mcp" class="text-xl font-semibold text-fg">MCP server for AI agents</h2>
<p class="mt-2 text-sm leading-relaxed text-muted">
Language models are bad at computing hashes, encodings and keys in their heads. <code class="font-mono text-fg">bitanon mcp</code> speaks the{' '}
<a href="https://modelcontextprotocol.io" class="text-fg underline decoration-fg/30 underline-offset-2 hover:decoration-fg">Model Context Protocol</a> over standard input and output, so an agent can call the same tested code instead. Every tool is read-only: the server reads no files and makes no network requests.
</p>
<p class="mt-4 text-sm font-semibold text-fg">Claude Desktop, Cursor and other clients</p>
<p class="mt-1 text-sm text-muted">Add it to the client's MCP configuration (<code class="font-mono">claude_desktop_config.json</code> for Claude Desktop), with the path where you put the binary:</p>
<div class="tb-panel tb-code mt-3 overflow-hidden px-5 py-4 text-sm">
<Code code={desktop} lang="json" themes={themes} defaultColor={false} wrap />
</div>
<p class="mt-4 text-sm font-semibold text-fg">Claude Code</p>
<div class="tb-panel tb-code mt-3 overflow-hidden px-5 py-4 text-sm">
<Code code={claudeCode} lang="sh" themes={themes} defaultColor={false} wrap />
</div>
</section>

<section class="mt-12" aria-labelledby="tools">
<h2 id="tools" class="text-xl font-semibold text-fg">Tools{cli && <span class="ml-2 text-sm font-normal text-subtle">bitanon {cli.version}</span>}</h2>
{
cli ? (
<>
<p class="mt-2 text-sm text-muted">The same names work as commands and as MCP tools. Options are flags on the command line and arguments over MCP.</p>
<div class="mt-4 grid gap-3">
{cli.tools.map((t) => (
<details class="tb-panel group p-0" id={`tool-${t.name}`}>
<summary class="flex cursor-pointer list-none flex-wrap items-baseline gap-x-3 gap-y-1 px-5 py-4">
<code class="font-mono font-semibold text-fg">{t.name}</code>
<span class="min-w-0 flex-1 text-sm text-muted"><RfcText text={t.description} /></span>
<span class="text-faint transition group-open:rotate-90" aria-hidden="true">›</span>
</summary>
<dl class="grid gap-3 border-t border-line-6 px-5 py-4 text-sm">
{options(t).map((o) => (
<div class="grid gap-1 sm:grid-cols-[13rem_minmax(0,1fr)] sm:gap-4">
<dt class="font-mono text-xs break-words text-fg sm:pt-0.5">{o.flag}</dt>
<dd class="text-muted">
<RfcText text={o.description} />
{o.required && <span class="ml-1 text-fg">Required.</span>}
{o.def !== null && <span class="ml-1">Default: <code class="font-mono text-body">{o.def}</code>.</span>}
{o.choices && <span class="mt-1 block font-mono text-xs text-subtle">{o.choices.join(' · ')}</span>}
{o.anyFormat && <span class="mt-1 block text-xs text-subtle">Any of the formats below.</span>}
</dd>
</div>
))}
</dl>
</details>
))}
</div>
{formats && (
<p class="mt-6 text-sm leading-relaxed text-muted">
<span class="font-semibold text-fg">Formats:</span> <span class="font-mono text-xs">{formats.join(' · ')}</span>
</p>
)}
</>
) : (
<p class="mt-2 text-sm text-muted">
Run <code class="font-mono text-fg">bitanon help</code> for the list of tools, or see the <a href={repo} class="text-fg underline decoration-fg/30 underline-offset-2 hover:decoration-fg">README</a>.
</p>
)
}
</section>

<p class="mt-12 text-sm text-subtle">
Source: <a href={repo} class="text-body hover:text-fg">github.com/bitanon/toolbox</a>, BSD-3-Clause.
</p>
</div>
</Site>
8 changes: 8 additions & 0 deletions src/pages/toolbox/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ const versions = Object.entries(engine.versions).filter(([, v]) => v);
</ul>
<p id="tool-empty" class="mt-10 text-center text-muted" hidden>No tool matches that search.</p>

<a href={url('toolbox/cli/')} class="card group mt-12 flex flex-wrap items-center justify-between gap-3 p-5 transition hover:border-line-15">
<span>
<span class="block font-semibold text-fg">On the command line and for AI agents</span>
<span class="mt-1 block text-sm text-muted">The same tools as a native <code class="font-mono">bitanon</code> command, and as an MCP server with <code class="font-mono">bitanon mcp</code>.</span>
</span>
<span class="text-faint transition group-hover:translate-x-0.5 group-hover:text-fg" aria-hidden="true">→</span>
</a>

<div class="mt-16 grid gap-4 md:grid-cols-3">
<div class="card p-6">
<h2 class="font-semibold text-fg">Verified, not just tested</h2>
Expand Down