From 47c4db53af1ea9c68753736d7760aafbe7d8c48b Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Fri, 13 Mar 2026 20:11:21 -0600 Subject: [PATCH] fix: fail to run agent or gateway without config --- src/cli/agent.ts | 2 ++ src/cli/commands.ts | 7 +------ src/cli/gateway.ts | 2 ++ src/cli/utils.ts | 7 +++---- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/cli/agent.ts b/src/cli/agent.ts index c40d63d..8aa8dac 100644 --- a/src/cli/agent.ts +++ b/src/cli/agent.ts @@ -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 ', 'Single message to process (non-interactive)') .option('-M, --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; diff --git a/src/cli/commands.ts b/src/cli/commands.ts index d22c504..b42511e 100644 --- a/src/cli/commands.ts +++ b/src/cli/commands.ts @@ -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); diff --git a/src/cli/gateway.ts b/src/cli/gateway.ts index e4cbd71..af26b4c 100644 --- a/src/cli/gateway.ts +++ b/src/cli/gateway.ts @@ -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 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( diff --git a/src/cli/utils.ts b/src/cli/utils.ts index e1e7415..4b3ce5a 100644 --- a/src/cli/utils.ts +++ b/src/cli/utils.ts @@ -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;