diff --git a/src/cli/agent.ts b/src/cli/agent.ts index 8aa8dac..9cba001 100644 --- a/src/cli/agent.ts +++ b/src/cli/agent.ts @@ -4,10 +4,10 @@ import pc from 'picocolors'; import { AgentLoop } from '../agent/loop.ts'; import { MessageBus } from '../bus/queue.ts'; import { makeProvider } from '../provider/index.ts'; +import { loadConfig } from '../config/loader.ts'; import { ensureWorkspace } from './utils.ts'; -import type { Config } from '../config/types.ts'; -export function agentCommand(program: Command, config: Config, workspace: string): void { +export function agentCommand(program: Command): void { program .command('agent') .description('Run the agent interactively or send a single message.') @@ -15,7 +15,10 @@ 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 }) => { + const config = loadConfig(opts.config); + const workspace = config.agent.workspacePath; 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 b42511e..faf83f1 100644 --- a/src/cli/commands.ts +++ b/src/cli/commands.ts @@ -1,5 +1,4 @@ import { Command } from 'commander'; -import { loadConfig, resolveWorkspacePath } from '../config/loader.ts'; import { agentCommand } from './agent.ts'; import { gatewayCommand } from './gateway.ts'; import { onboardCommand } from './onboard.ts'; @@ -10,13 +9,8 @@ export function createCli(): Command { .version('1.0.0'); onboardCommand(program); - - const globalOpts = program.opts(); - const config = loadConfig(globalOpts.config); - const workspace = resolveWorkspacePath(config.agent.workspacePath); - - gatewayCommand(program, config, workspace); - agentCommand(program, config, workspace); + gatewayCommand(program); + agentCommand(program); return program; } diff --git a/src/cli/gateway.ts b/src/cli/gateway.ts index af26b4c..f528d5e 100644 --- a/src/cli/gateway.ts +++ b/src/cli/gateway.ts @@ -7,17 +7,19 @@ 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 { loadConfig } from '../config/loader.ts'; import { ensureWorkspace } from './utils.ts'; -import type { Config } from '../config/types.ts'; - -export function gatewayCommand(program: Command, config: Config, workspace: string): void { +export function gatewayCommand(program: Command): void { program .command('gateway') .option('-c, --config ', 'Path to config.json') .description('Start the full gateway: Mattermost channel, agent loop, cron, and heartbeat.') - .action(async (_opts: { config?: string }) => { + .action(async (opts: { config?: string }) => { + const config = loadConfig(opts.config); + const workspace = config.agent.workspacePath; ensureWorkspace(workspace); + console.info(pc.magenta(`workspace path: ${workspace}`)); const provider = makeProvider( diff --git a/src/config/loader.ts b/src/config/loader.ts index 6ce3406..d491290 100644 --- a/src/config/loader.ts +++ b/src/config/loader.ts @@ -1,6 +1,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { homedir } from 'node:os'; import { dirname, resolve } from 'node:path'; +import pc from 'picocolors' import { type Config, ConfigSchema } from './types.ts'; const DEFAULT_CONFIG_PATH = resolve(homedir(), '.config', 'nanobot', 'config.json'); @@ -13,7 +14,8 @@ export function loadConfig(configPath?: string): Config { const path = getConfigPath(configPath); if (!existsSync(path)) { - return ConfigSchema.parse({}); + console.error(pc.red(`Failed to load config from ${configPath}`)); + process.exit(1); } const raw = readFileSync(path, 'utf8');