CLI runs on Node 20+: npx storebound (bunx keeps working)

- cli/lib/rt.ts: the runtime layer on node: modules (spawn / spawnSync with Bun's defaults, exit codes and
  "Executable not found", which with PATHEXT, sleep, serve, Glob, hasher, gunzip, stdin, SQLite, packageRoot,
  config imports with a type-stripping fallback for Node 20); every Bun.* use in cli/ goes through it
- tools/gen-embedded.ts -> cli/lib/embedded.ts: templates/, cli/shots/*.html and Play's Data safety form embedded
  (replaces Bun text imports; the bundle and the compiled sidecar carry them), checked fresh by bun run ci
- package.json: bin dist/storebound.mjs (Node ESM bundle, tools/build-node.ts, prepack), engines node >=20
- bun run ci: node bundle + node smoke (real node: --version, help, check same as Bun, scan, release plan --help,
  init, MCP handshake + tool call); Forgejo CI sets up Node 20; tests/node-compat.test.ts guards cli/
- install writes npx MCP commands when run with Node; bin/storebound falls back to Node
- docs: npx storebound init (Node 20+) or bunx storebound init
This commit is contained in:
CRTkafa 2026-10-13 04:03:09 +08:00
parent 614c32bcba
commit 36a8bf9625
73 changed files with 1195 additions and 251 deletions

View file

@ -3,16 +3,20 @@
// [--no-skills] [--no-mcp] [--command "bunx storebound"]
// Skills are copied to the tool's skills folder (our own skill folders are updated, nothing else is touched). The MCP
// entry "storebound" is added to the tool's config file; every other entry stays as it is. Re-running is safe.
// MCP command: `bunx storebound mcp` when the project has storebound in node_modules, else this toolchain's
// bin/storebound by absolute path (override with --command).
// MCP command: `bunx storebound mcp` (`npx storebound mcp` when run with Node) when the project has storebound in
// node_modules; else, under Bun, this toolchain's bin/storebound by absolute path, under Node (`npx storebound
// install`: the toolchain sits in npx's cache, which can be cleared) `npx -y storebound@<this version> mcp`
// (override with --command).
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { homedir } from 'node:os';
import { dirname, join, resolve } from 'node:path';
import type { Args } from './lib/args';
import { AGENTS, type AgentId, isAgent, type McpCommand, mergeCodexToml, mergeJsonServer } from './lib/agents';
import { log, warn } from './lib/log';
import * as rt from './lib/rt';
import pkg from '../package.json' with { type: 'json' };
const TOOLCHAIN = resolve(import.meta.dir, '..');
const TOOLCHAIN = rt.packageRoot();
/** Every file of a folder, relative path -> content, for comparing skill folders. */
function snapshot(dir: string, base = dir, out = new Map<string, string>()): Map<string, string> {
@ -25,9 +29,10 @@ function snapshot(dir: string, base = dir, out = new Map<string, string>()): Map
}
const same = (a: Map<string, string>, b: Map<string, string>) => a.size === b.size && [...a].every(([k, v]) => b.get(k) === v);
export function mcpCommand(project: string, override?: string): McpCommand {
export function mcpCommand(project: string, override?: string, runtime: 'bun' | 'node' = rt.runtime.name, version = pkg.version): McpCommand {
if (override) { const [command, ...args] = override.split(/\s+/).filter(Boolean); return { command: command!, args: [...args, 'mcp'] }; }
if (existsSync(join(project, 'node_modules', 'storebound', 'package.json'))) return { command: 'bunx', args: ['storebound', 'mcp'] };
if (existsSync(join(project, 'node_modules', 'storebound', 'package.json'))) return { command: runtime === 'bun' ? 'bunx' : 'npx', args: ['storebound', 'mcp'] };
if (runtime === 'node') return { command: 'npx', args: ['-y', `storebound@${version}`, 'mcp'] };
return { command: join(TOOLCHAIN, 'bin', 'storebound'), args: ['mcp'] };
}