From 4367038a95a8ae96e0fdfbb37b5488cd9a9fbe49 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Wed, 18 Feb 2026 13:32:06 -0600 Subject: [PATCH] fix: make cron run command actually execute the agent Wire up an AgentLoop with an on_job callback in the cron_run CLI command so the job's message is sent to the agent and the response is printed. Previously, CronService was created with no on_job callback, causing _execute_job to skip execution silently and always report success. Co-Authored-By: Claude Sonnet 4.6 --- nanobot/cli/commands.py | 44 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.py index 2f4ba7b..a45b4a7 100644 --- a/nanobot/cli/commands.py +++ b/nanobot/cli/commands.py @@ -860,17 +860,51 @@ def cron_run( force: bool = typer.Option(False, "--force", "-f", help="Run even if disabled"), ): """Manually run a job.""" - from nanobot.config.loader import get_data_dir + from nanobot.config.loader import load_config, get_data_dir from nanobot.cron.service import CronService - + from nanobot.bus.queue import MessageBus + from nanobot.agent.loop import AgentLoop + from loguru import logger + logger.disable("nanobot") + + config = load_config() + provider = _make_provider(config) + bus = MessageBus() + agent_loop = AgentLoop( + bus=bus, + provider=provider, + workspace=config.workspace_path, + model=config.agents.defaults.model, + max_iterations=config.agents.defaults.max_tool_iterations, + memory_window=config.agents.defaults.memory_window, + exec_config=config.tools.exec, + restrict_to_workspace=config.tools.restrict_to_workspace, + ) + store_path = get_data_dir() / "cron" / "jobs.json" service = CronService(store_path) - + + result_holder = [] + + async def on_job(job): + response = await agent_loop.process_direct( + job.payload.message, + session_key=f"cron:{job.id}", + channel=job.payload.channel or "cli", + chat_id=job.payload.to or "direct", + ) + result_holder.append(response) + return response + + service.on_job = on_job + async def run(): return await service.run_job(job_id, force=force) - + if asyncio.run(run()): - console.print(f"[green]✓[/green] Job executed") + console.print("[green]✓[/green] Job executed") + if result_holder: + _print_agent_response(result_holder[0], render_markdown=True) else: console.print(f"[red]Failed to run job {job_id}[/red]")