fix: correctly load config path from args

log error and exit if config can not be loaded, don't use defaults
This commit is contained in:
Joe Fleming
2026-03-13 20:29:02 -06:00
parent 47c4db53af
commit 14aa1c1e7f
4 changed files with 16 additions and 15 deletions

View File

@@ -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 <text>', 'Single message to process (non-interactive)')
.option('-M, --model <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;

View File

@@ -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;
}

View File

@@ -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>', '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(

View File

@@ -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');