fix: fail to run agent or gateway without config

This commit is contained in:
Joe Fleming
2026-03-13 20:11:21 -06:00
parent 1dd953d17a
commit 47c4db53af
4 changed files with 8 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ import pc from 'picocolors';
import { AgentLoop } from '../agent/loop.ts';
import { MessageBus } from '../bus/queue.ts';
import { makeProvider } from '../provider/index.ts';
import { ensureWorkspace } from './utils.ts';
import type { Config } from '../config/types.ts';
export function agentCommand(program: Command, config: Config, workspace: string): void {
@@ -14,6 +15,7 @@ export function agentCommand(program: Command, config: Config, workspace: string
.option('-m, --message <text>', 'Single message to process (non-interactive)')
.option('-M, --model <model>', 'Model override')
.action(async (opts: { config?: string; message?: string; model?: string }) => {
ensureWorkspace(workspace);
console.info(pc.magenta(`workspace path: ${workspace}`));
const model = opts.model ?? config.agent.model;

View File

@@ -3,23 +3,18 @@ import { loadConfig, resolveWorkspacePath } from '../config/loader.ts';
import { agentCommand } from './agent.ts';
import { gatewayCommand } from './gateway.ts';
import { onboardCommand } from './onboard.ts';
import { ensureWorkspace } from './utils.ts';
export function createCli(): Command {
const program = new Command('nanobot')
.description('nanobot — personal AI assistant')
.version('1.0.0');
// Register onboard command first (doesn't need config/workspace)
onboardCommand(program);
// load config and get workspace
const globalOpts = program.opts();
const config = loadConfig(globalOpts.config);
const workspace = resolveWorkspacePath(config.agent.workspacePath);
ensureWorkspace(workspace);
gatewayCommand(program, config, workspace);
agentCommand(program, config, workspace);

View File

@@ -7,6 +7,7 @@ import { MattermostChannel } from '../channels/mattermost.ts';
import { CronService } from '../cron/service.ts';
import { HeartbeatService } from '../heartbeat/service.ts';
import { makeProvider } from '../provider/index.ts';
import { ensureWorkspace } from './utils.ts';
import type { Config } from '../config/types.ts';
@@ -16,6 +17,7 @@ export function gatewayCommand(program: Command, config: Config, workspace: stri
.option('-c, --config <path>', 'Path to config.json')
.description('Start the full gateway: Mattermost channel, agent loop, cron, and heartbeat.')
.action(async (_opts: { config?: string }) => {
ensureWorkspace(workspace);
console.info(pc.magenta(`workspace path: ${workspace}`));
const provider = makeProvider(

View File

@@ -11,15 +11,14 @@ export function resolvePath(raw: string): string {
return resolve(raw);
}
export function ensureWorkspace(rawPath: string, createIfMissing = true): string {
export function ensureWorkspace(rawPath: string, createIfMissing = false): string {
const path = resolvePath(rawPath);
if (!existsSync(path)) {
if (createIfMissing) {
mkdirSync(path, { recursive: true });
} else {
throw new Error(
`Workspace does not exist: ${path}\nRun 'nanobot onboard' to initialize.`,
);
console.error(pc.red(`Workspace does not exist: ${path}\nRun 'nanobot onboard' to initialize.`))
process.exit(1)
}
}
return path;