mirror of
https://github.com/qwibitai/nanoclaw.git
synced 2026-06-04 10:14:47 +08:00
712a0e1e01
Adds three allowlist-friendly setup helpers so /new-setup and /new-setup-2 don't hit unmatchable commands during a fresh install: - setup/install-node.sh — idempotent Node 22 install wrapper (macOS via brew, Linux via NodeSource + apt). Replaces the raw `curl | sudo -E bash -` flow whose stdin-consuming `bash -` segment can't be pre-approved. - setup/install-docker.sh — same pattern for Docker (brew --cask on macOS, get.docker.com on Linux + usermod). - setup/set-env.ts — generic `--step set-env` that writes KEY=VALUE to .env (and optionally syncs to data/env/env) so channel-install flows don't invent `grep && sed && rm` pipelines, which split at each && and can't be tightly allowlisted. new-setup-2's Telegram path now uses set-env for TELEGRAM_BOT_TOKEN and explicitly skips /add-telegram's Credentials section. new-setup step 1 and step 2 now call the install wrappers; the raw curl/apt entries are gone from the allowed-tools list. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
/**
|
|
* Setup CLI entry point.
|
|
* Usage: pnpm exec tsx setup/index.ts --step <name> [args...]
|
|
*/
|
|
import { log } from '../src/log.js';
|
|
import { emitStatus } from './status.js';
|
|
|
|
const STEPS: Record<
|
|
string,
|
|
() => Promise<{ run: (args: string[]) => Promise<void> }>
|
|
> = {
|
|
timezone: () => import('./timezone.js'),
|
|
'set-env': () => import('./set-env.js'),
|
|
environment: () => import('./environment.js'),
|
|
container: () => import('./container.js'),
|
|
register: () => import('./register.js'),
|
|
mounts: () => import('./mounts.js'),
|
|
service: () => import('./service.js'),
|
|
verify: () => import('./verify.js'),
|
|
onecli: () => import('./onecli.js'),
|
|
auth: () => import('./auth.js'),
|
|
'cli-agent': () => import('./cli-agent.js'),
|
|
};
|
|
|
|
async function main(): Promise<void> {
|
|
const args = process.argv.slice(2);
|
|
const stepIdx = args.indexOf('--step');
|
|
|
|
if (stepIdx === -1 || !args[stepIdx + 1]) {
|
|
console.error(
|
|
`Usage: pnpm exec tsx setup/index.ts --step <${Object.keys(STEPS).join('|')}> [args...]`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const stepName = args[stepIdx + 1];
|
|
const stepArgs = args.filter(
|
|
(a, i) => i !== stepIdx && i !== stepIdx + 1 && a !== '--',
|
|
);
|
|
|
|
const loader = STEPS[stepName];
|
|
if (!loader) {
|
|
console.error(`Unknown step: ${stepName}`);
|
|
console.error(`Available steps: ${Object.keys(STEPS).join(', ')}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
try {
|
|
const mod = await loader();
|
|
await mod.run(stepArgs);
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
log.error('Setup step failed', { err, step: stepName });
|
|
emitStatus(stepName.toUpperCase(), {
|
|
STATUS: 'failed',
|
|
ERROR: message,
|
|
});
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|