fix: fail to run agent or gateway without config
This commit is contained in:
@@ -4,6 +4,7 @@ import pc from 'picocolors';
|
|||||||
import { AgentLoop } from '../agent/loop.ts';
|
import { AgentLoop } from '../agent/loop.ts';
|
||||||
import { MessageBus } from '../bus/queue.ts';
|
import { MessageBus } from '../bus/queue.ts';
|
||||||
import { makeProvider } from '../provider/index.ts';
|
import { makeProvider } from '../provider/index.ts';
|
||||||
|
import { ensureWorkspace } from './utils.ts';
|
||||||
import type { Config } from '../config/types.ts';
|
import type { Config } from '../config/types.ts';
|
||||||
|
|
||||||
export function agentCommand(program: Command, config: Config, workspace: string): void {
|
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, --message <text>', 'Single message to process (non-interactive)')
|
||||||
.option('-M, --model <model>', 'Model override')
|
.option('-M, --model <model>', 'Model override')
|
||||||
.action(async (opts: { config?: string; message?: string; model?: string }) => {
|
.action(async (opts: { config?: string; message?: string; model?: string }) => {
|
||||||
|
ensureWorkspace(workspace);
|
||||||
console.info(pc.magenta(`workspace path: ${workspace}`));
|
console.info(pc.magenta(`workspace path: ${workspace}`));
|
||||||
|
|
||||||
const model = opts.model ?? config.agent.model;
|
const model = opts.model ?? config.agent.model;
|
||||||
|
|||||||
@@ -3,23 +3,18 @@ import { loadConfig, resolveWorkspacePath } from '../config/loader.ts';
|
|||||||
import { agentCommand } from './agent.ts';
|
import { agentCommand } from './agent.ts';
|
||||||
import { gatewayCommand } from './gateway.ts';
|
import { gatewayCommand } from './gateway.ts';
|
||||||
import { onboardCommand } from './onboard.ts';
|
import { onboardCommand } from './onboard.ts';
|
||||||
import { ensureWorkspace } from './utils.ts';
|
|
||||||
|
|
||||||
export function createCli(): Command {
|
export function createCli(): Command {
|
||||||
const program = new Command('nanobot')
|
const program = new Command('nanobot')
|
||||||
.description('nanobot — personal AI assistant')
|
.description('nanobot — personal AI assistant')
|
||||||
.version('1.0.0');
|
.version('1.0.0');
|
||||||
|
|
||||||
// Register onboard command first (doesn't need config/workspace)
|
|
||||||
onboardCommand(program);
|
onboardCommand(program);
|
||||||
|
|
||||||
// load config and get workspace
|
|
||||||
const globalOpts = program.opts();
|
const globalOpts = program.opts();
|
||||||
const config = loadConfig(globalOpts.config);
|
const config = loadConfig(globalOpts.config);
|
||||||
const workspace = resolveWorkspacePath(config.agent.workspacePath);
|
const workspace = resolveWorkspacePath(config.agent.workspacePath);
|
||||||
|
|
||||||
ensureWorkspace(workspace);
|
|
||||||
|
|
||||||
gatewayCommand(program, config, workspace);
|
gatewayCommand(program, config, workspace);
|
||||||
agentCommand(program, config, workspace);
|
agentCommand(program, config, workspace);
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { MattermostChannel } from '../channels/mattermost.ts';
|
|||||||
import { CronService } from '../cron/service.ts';
|
import { CronService } from '../cron/service.ts';
|
||||||
import { HeartbeatService } from '../heartbeat/service.ts';
|
import { HeartbeatService } from '../heartbeat/service.ts';
|
||||||
import { makeProvider } from '../provider/index.ts';
|
import { makeProvider } from '../provider/index.ts';
|
||||||
|
import { ensureWorkspace } from './utils.ts';
|
||||||
|
|
||||||
import type { Config } from '../config/types.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')
|
.option('-c, --config <path>', 'Path to config.json')
|
||||||
.description('Start the full gateway: Mattermost channel, agent loop, cron, and heartbeat.')
|
.description('Start the full gateway: Mattermost channel, agent loop, cron, and heartbeat.')
|
||||||
.action(async (_opts: { config?: string }) => {
|
.action(async (_opts: { config?: string }) => {
|
||||||
|
ensureWorkspace(workspace);
|
||||||
console.info(pc.magenta(`workspace path: ${workspace}`));
|
console.info(pc.magenta(`workspace path: ${workspace}`));
|
||||||
|
|
||||||
const provider = makeProvider(
|
const provider = makeProvider(
|
||||||
|
|||||||
@@ -11,15 +11,14 @@ export function resolvePath(raw: string): string {
|
|||||||
return resolve(raw);
|
return resolve(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ensureWorkspace(rawPath: string, createIfMissing = true): string {
|
export function ensureWorkspace(rawPath: string, createIfMissing = false): string {
|
||||||
const path = resolvePath(rawPath);
|
const path = resolvePath(rawPath);
|
||||||
if (!existsSync(path)) {
|
if (!existsSync(path)) {
|
||||||
if (createIfMissing) {
|
if (createIfMissing) {
|
||||||
mkdirSync(path, { recursive: true });
|
mkdirSync(path, { recursive: true });
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
console.error(pc.red(`Workspace does not exist: ${path}\nRun 'nanobot onboard' to initialize.`))
|
||||||
`Workspace does not exist: ${path}\nRun 'nanobot onboard' to initialize.`,
|
process.exit(1)
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
|
|||||||
Reference in New Issue
Block a user