From 54a6937df872e86d63085dff5ccd3045d95425cb Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Sat, 14 Nov 2026 14:40:45 +0000 Subject: [PATCH] rea: REA (morluto/rea) as a command, installed on first use Launcher for npm rea-agents in the codeburn shape: private prefix under ~/.local/share/cli-tools/vendor/rea, --self-update/--self-where, REA_BIN, hands through to an upstream ~/.local/bin/rea when one is already there. Node check matches upstream's three-range engine (^22.23.4 || ^24.22.1 || >=26.12.1). Bumps to v0.74.0. Co-Authored-By: Claude Opus 5.5 --- README.md | 27 +++++++ bin/rea.ts | 89 +++++++++++++++++++++++ package.json | 2 +- src/rea.ts | 182 +++++++++++++++++++++++++++++++++++++++++++++++ src/registry.ts | 1 + test/rea.test.ts | 54 ++++++++++++++ 6 files changed, 354 insertions(+), 1 deletion(-) create mode 100644 bin/rea.ts create mode 100644 src/rea.ts create mode 100644 test/rea.test.ts diff --git a/README.md b/README.md index ad4ac74..524b668 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ TypeScript, installed as executables on `PATH`. | [`dl`](#dl) | Download a video, or just its audio, through yt-dlp | | [`torrent`](#torrent) | Make a torrent out of a directory, and get it seeded | | [`codeburn`](#codeburn) | See where your AI spend goes, by task, tool, model and project | +| [`rea`](#rea) | Reverse engineer anything with agents (REA): apps, web bundles, APKs, native binaries; CLI + MCP | | [`agenticjobs`](#agenticjobs) | Search, apply, post and hire on an agent-friendly job board | | [`alchemy`](#alchemy) | Alchemy onchain data from the terminal: balances, gas, transactions, apps, wallets, x402 | | [`ngc`](#ngc) | NVIDIA's NGC CLI: the model and container catalog, installed and verified on first use | @@ -97,6 +98,8 @@ Two things here are not `PATH` commands and do not need Node: - **Node 22.13+ and `pnpm` or `npm`** — `codeburn` only: it is somebody else's npm package, installed on first use, and upstream's engine floor is higher than this repo's +- **Node ^22.23.4, ^24.22.1 or 26.12.1+** — `rea` only: upstream's engine range + (Node 23 and 25 are excluded); it warns and tries anyway outside it - **[`logicsrc`](https://logicsrc.com)**, logged in to the team — `users-dump` only, which reads database locations out of the team vaults - **[TronBrowser](https://tronbrowser.dev) with `browser_upload`** — `jobhunt apply` @@ -2072,6 +2075,30 @@ before every launch, which is fine for a one-shot and wrong for a dashboard you open twenty times a day. Upstream wants **Node 22.13+**; on an older one it says so and tries anyway, since that floor is theirs to move. +### `rea` + +[REA](https://rea.tools) ([morluto/rea](https://github.com/morluto/rea), MIT): +reverse engineer anything with agents, from app behaviour (browser, Electron, +Android over adb) down to native binaries through Hopper, Ghidra, Rizin or GDB. +One CLI, and the same commands as an MCP server. + +```sh +rea setup # agents, skills and optional providers (Hopper etc.) +rea doctor # what is ready and what is missing +rea analyze ./SomeApp # an overview of an app +rea mcp add # register REA as an MCP server for your agent +rea --help # it is upstream's CLI: upstream's flags +rea --self-update # ours: reinstall rea-agents@latest +rea --self-where # ours: which copy runs, and from where +``` + +The `codeburn` shape: upstream's one-liner +(`curl -fsSL https://raw.githubusercontent.com/morluto/rea/main/install.sh | bash`) +is replaced by an install of `rea-agents@latest` on first use into +`~/.local/share/cli-tools/vendor/rea`, so the `rea` on `PATH` is this launcher. +If upstream's installer already put a `rea` in `~/.local/bin`, the linker leaves +it there and the launcher hands through to it. `REA_BIN` points at another copy. + ### `agenticjobs` The job board where the applying is done by agents, from the terminal: diff --git a/bin/rea.ts b/bin/rea.ts new file mode 100644 index 0000000..10466f7 --- /dev/null +++ b/bin/rea.ts @@ -0,0 +1,89 @@ +#!/usr/bin/env node +/** + * rea — reverse engineer anything with agents (REA, github.com/morluto/rea). + * + * A launcher for the `rea-agents` npm package, not a reimplementation of it. + * Everything you type is handed through untouched: `rea setup`, `rea doctor`, + * `rea analyze `, `rea mcp add`, `rea --help` for the rest. + * + * Ours, and therefore NOT passed through: + * --self-update reinstall the latest release + * --self-where say which copy would run, and from where + * + * src/rea.ts says why it is shaped like this. + */ + +import { isMain } from '../src/is-main.ts'; +import { + NODE_RANGE, + PACKAGE, + install, + installFailureMessage, + meetsNodeRange, + nodeRangeMessage, + resolveRunner, + spawnInherit, + vendorRoot, +} from '../src/rea.ts'; + +const DESCRIBE: Record = { + env: 'REA_BIN', + vendor: 'installed by cli-tools', + path: 'already on PATH', + missing: 'not installed yet', +}; + +async function main(argv: string[]): Promise { + const runner = resolveRunner(); + + if (argv[0] === '--self-where') { + process.stdout.write( + [ + `${runner.file ?? '(none)'} — ${DESCRIBE[runner.kind]}`, + `prefix: ${vendorRoot()}`, + `node: ${process.version}${meetsNodeRange(process.version) ? '' : ` (outside ${NODE_RANGE})`}`, + '', + ].join('\n'), + ); + return 0; + } + + const refreshing = argv[0] === '--self-update'; + const args = refreshing ? argv.slice(1) : argv; + + if (!meetsNodeRange(process.version)) { + process.stderr.write(`${nodeRangeMessage(process.version)}\n`); + } + + let file = runner.file; + + if (refreshing || runner.kind === 'missing') { + process.stderr.write(refreshing ? `rea: updating ${PACKAGE}…\n` : `rea: installing ${PACKAGE}…\n`); + const result = await install(); + if (!result.ok) { + process.stderr.write(`${installFailureMessage(result.manager, vendorRoot())}\n`); + return 1; + } + file = result.bin; + if (refreshing && args.length === 0) { + process.stderr.write(`rea: up to date (${result.manager}) at ${result.bin}\n`); + return 0; + } + } + + if (!file) { + process.stderr.write(`${installFailureMessage('npm', vendorRoot())}\n`); + return 1; + } + + const code = await spawnInherit(file, args); + if (code === null) { + process.stderr.write(`rea: could not start ${file}\n rea --self-update # reinstall it\n`); + return 1; + } + return code; +} + +if (isMain(import.meta.url)) { + process.exit(await main(process.argv.slice(2))); +} diff --git a/package.json b/package.json index f54b908..3019ee5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@profullstack/cli-tools", - "version": "0.73.0", + "version": "0.74.0", "private": true, "description": "Local command-line tools, in TypeScript, exposed on PATH.", "type": "module", diff --git a/src/rea.ts b/src/rea.ts new file mode 100644 index 0000000..6d88543 --- /dev/null +++ b/src/rea.ts @@ -0,0 +1,182 @@ +/** + * rea — REA (morluto/rea), reverse engineer anything with agents. + * + * Upstream ships `curl -fsSL https://raw.githubusercontent.com/morluto/rea/main/install.sh | bash`, + * which is `npm install --global --prefix ~/.local rea-agents@` + * followed by an interactive `rea setup`. This is the codeburn shape instead + * (src/codeburn.ts has the long version of why): installed on first use into a + * private prefix under ~/.local/share/cli-tools/vendor, so the name `rea` on + * PATH is this launcher and nothing races it, and every argument is handed + * through untouched so upstream's docs are the docs. + * + * Two things differ from codeburn: + * + * The package and the executable have different names (`rea-agents` installs + * `rea`), so PACKAGE and BIN are separate constants. + * + * REA's Node floor is three ranges, not one minimum: ^22.23.4, ^24.22.1 or + * >=26.12.1. Node 23 and 25 are excluded on purpose upstream, so a single + * "at least X" comparison would wave them through. Like codeburn it is a + * warning, not a refusal. + * + * If upstream's own installer already put a `rea` in ~/.local/bin, the linker + * leaves it alone (see cli-tools-agenticjobs) and this launcher still works: + * resolveRunner sees a `rea` on PATH that is not us and hands through to it. + */ + +import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { dataHome, managers, spawnInherit, type PackageManager } from './codeburn.ts'; +import { resolveCommand } from './registry.ts'; + +export { spawnInherit }; + +/** The published package, and the executable it installs. */ +export const PACKAGE = 'rea-agents'; +export const BIN = 'rea'; + +/** Upstream's package.json#engines.node, kept in words for messages. */ +export const NODE_RANGE = '^22.23.4 || ^24.22.1 || >=26.12.1'; + +/** The private prefix: a directory whose entire job is to hold one package. */ +export function vendorRoot(env: NodeJS.ProcessEnv = process.env): string { + return join(dataHome(env), 'cli-tools', 'vendor', BIN); +} + +/** The installed executable, whether or not it exists yet. */ +export function vendorBin(env: NodeJS.ProcessEnv = process.env): string { + return join(vendorRoot(env), 'node_modules', '.bin', BIN); +} + +function parse(v: string): [number, number, number] { + const [a = 0, b = 0, c = 0] = v + .replace(/^v/, '') + .split(/[-+]/)[0]! + .split('.') + .map((part) => Number.parseInt(part, 10) || 0); + return [a, b, c]; +} + +function atLeast(got: [number, number, number], want: [number, number, number]): boolean { + for (let i = 0; i < 3; i += 1) { + if (got[i] !== want[i]) return got[i]! > want[i]!; + } + return true; +} + +/** Does this Node satisfy ^22.23.4 || ^24.22.1 || >=26.12.1? */ +export function meetsNodeRange(version: string): boolean { + const v = parse(version); + if (v[0] === 22) return atLeast(v, [22, 23, 4]); + if (v[0] === 24) return atLeast(v, [24, 22, 1]); + return atLeast(v, [26, 12, 1]); +} + +export interface InstallPlan { + file: string; + args: string[]; +} + +/** Same flags as codeburn's, for the same reasons (see there). */ +export function installPlan(manager: PackageManager, spec = `${PACKAGE}@latest`): InstallPlan { + if (manager === 'pnpm') { + return { file: 'pnpm', args: ['add', '--ignore-workspace', '--reporter=silent', spec] }; + } + return { file: 'npm', args: ['install', '--no-audit', '--no-fund', '--silent', spec] }; +} + +export type RunnerKind = 'env' | 'vendor' | 'path' | 'missing'; + +export interface Runner { + kind: RunnerKind; + file: string | null; +} + +export interface ResolveDeps { + env?: NodeJS.ProcessEnv; + exists?: (path: string) => boolean; + onPathStatus?: () => 'ours' | 'other' | 'missing'; + onPathTarget?: () => string | null; +} + +/** + * Which rea to run: REA_BIN, then our private copy, then a `rea` on PATH that + * is NOT this launcher (running ourselves would loop), else nothing yet. + */ +export function resolveRunner(deps: ResolveDeps = {}): Runner { + const env = deps.env ?? process.env; + const exists = deps.exists ?? existsSync; + const status = deps.onPathStatus ?? (() => resolveCommand(BIN, undefined, env).status); + const target = deps.onPathTarget ?? (() => resolveCommand(BIN, undefined, env).target); + + if (env.REA_BIN) return { kind: 'env', file: env.REA_BIN }; + + const vendored = vendorBin(env); + if (exists(vendored)) return { kind: 'vendor', file: vendored }; + + if (status() === 'other') return { kind: 'path', file: target() }; + + return { kind: 'missing', file: null }; +} + +function prepareVendorDir(root: string): void { + mkdirSync(root, { recursive: true }); + const manifest = join(root, 'package.json'); + if (existsSync(manifest)) return; + writeFileSync( + manifest, + `${JSON.stringify( + { + name: 'cli-tools-vendor-rea', + version: '0.0.0', + private: true, + description: 'Prefix owned by profullstack/cli-tools. Managed by the rea command.', + }, + null, + 2, + )}\n`, + ); +} + +export interface InstallResult { + ok: boolean; + manager: PackageManager; + bin: string; +} + +/** Install (or refresh) rea-agents@latest into the private prefix, pnpm then npm. */ +export async function install(env: NodeJS.ProcessEnv = process.env): Promise { + const root = vendorRoot(env); + prepareVendorDir(root); + + const tried = managers(env); + let last: PackageManager = tried[tried.length - 1] ?? 'npm'; + + for (const manager of tried) { + last = manager; + const plan = installPlan(manager); + const code = await spawnInherit(plan.file, plan.args, root); + if (code === 0 && existsSync(vendorBin(env))) { + return { ok: true, manager, bin: vendorBin(env) }; + } + } + + return { ok: false, manager: last, bin: vendorBin(env) }; +} + +export function installFailureMessage(manager: PackageManager, root: string): string { + return [ + `rea: could not install ${PACKAGE} with ${manager}.`, + ` cd ${root} && npm install ${PACKAGE}@latest # by hand, to see the error`, + ' curl -fsSL https://raw.githubusercontent.com/morluto/rea/main/install.sh | bash # upstream installer', + ' REA_BIN=/path/to/rea rea … # or point at a copy you have', + ].join('\n'); +} + +export function nodeRangeMessage(version: string): string { + return [ + `rea: REA needs Node ${NODE_RANGE}, and this is ${version}.`, + ' mise use -g node@24 # then re-run', + 'Continuing anyway — the failure below, if any, is that.', + ].join('\n'); +} diff --git a/src/registry.ts b/src/registry.ts index bbaf593..b5ea292 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -69,6 +69,7 @@ const SUMMARIES: Record = { 'gh-pulse': 'What moved on GitHub, last hour to all time, ranked, with traffic: by email, TUI or JSON', hqtui: 'Every vital of this box, in the terminal: sockets, HTTP, sessions, services', porkbun: 'Read and change DNS at Porkbun, and un-park a domain', + rea: 'Reverse engineer anything with agents (REA): apps, web bundles, APKs, native binaries; CLI + MCP', explee: 'Add more of your own leads to an Explee project: a CSV becomes a campaign with the same brief', fe: 'Forward Email aliases without the dashboard: list, ensure (idempotent), remove', dealsubs: 'Subscribe an inbox to coupon and deal newsletters, throttled, through TronBrowser', diff --git a/test/rea.test.ts b/test/rea.test.ts new file mode 100644 index 0000000..24fabd8 --- /dev/null +++ b/test/rea.test.ts @@ -0,0 +1,54 @@ +import { describe, expect, it } from 'vitest'; +import { BIN, PACKAGE, installPlan, meetsNodeRange, resolveRunner, vendorBin, vendorRoot } from '../src/rea.ts'; + +describe('rea prefix', () => { + it('installs rea-agents but runs rea', () => { + expect(PACKAGE).toBe('rea-agents'); + expect(BIN).toBe('rea'); + expect(vendorRoot({ XDG_DATA_HOME: '/data' })).toBe('/data/cli-tools/vendor/rea'); + expect(vendorBin({ HOME: '/home/x' })).toBe('/home/x/.local/share/cli-tools/vendor/rea/node_modules/.bin/rea'); + }); + + it('installs the latest release of the package, not of the bin name', () => { + expect(installPlan('npm').args.at(-1)).toBe('rea-agents@latest'); + expect(installPlan('pnpm').args).toContain('--ignore-workspace'); + }); +}); + +describe('meetsNodeRange (^22.23.4 || ^24.22.1 || >=26.12.1)', () => { + it('accepts each range from its floor', () => { + for (const v of ['v22.23.4', 'v22.30.0', 'v24.22.1', 'v24.40.0', 'v26.12.1', 'v27.0.0']) { + expect(meetsNodeRange(v), v).toBe(true); + } + }); + + it('rejects below each floor, and the odd majors upstream skips', () => { + for (const v of ['v20.19.0', 'v22.23.3', 'v22.13.0', 'v23.11.0', 'v24.22.0', 'v25.9.0', 'v26.12.0']) { + expect(meetsNodeRange(v), v).toBe(false); + } + }); +}); + +describe('resolveRunner', () => { + const none = { exists: () => false, onPathStatus: () => 'missing' as const, onPathTarget: () => null }; + + it('prefers REA_BIN', () => { + expect(resolveRunner({ ...none, env: { REA_BIN: '/opt/rea' } })).toEqual({ kind: 'env', file: '/opt/rea' }); + }); + + it('then the private copy', () => { + const env = { HOME: '/h' }; + expect(resolveRunner({ ...none, env, exists: (p) => p === vendorBin(env) })).toEqual({ + kind: 'vendor', + file: vendorBin(env), + }); + }); + + it('then an upstream install on PATH, but never itself', () => { + const env = { HOME: '/h' }; + expect( + resolveRunner({ ...none, env, onPathStatus: () => 'other', onPathTarget: () => '/h/.local/bin/rea' }), + ).toEqual({ kind: 'path', file: '/h/.local/bin/rea' }); + expect(resolveRunner({ ...none, env, onPathStatus: () => 'ours' })).toEqual({ kind: 'missing', file: null }); + }); +});