Fix scheduled tasks and improve task scheduling UX

- Fix Apple Container mount issue: move groups/CLAUDE.md to groups/global/
  directory (Apple Container only supports directory mounts, not file mounts)
- Fix scheduled tasks for main group: properly detect isMain based on
  group_folder instead of always setting false
- Add isScheduledTask flag so agent knows when running as scheduled task
- Improve schedule_task tool description with clear format examples for
  cron, interval, and once schedule types
- Update global CLAUDE.md with instructions for scheduled tasks to use
  mcp__nanoclaw__send_message when needed

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Gavriel
2026-02-01 16:34:30 +02:00
parent f25e0f9a10
commit 2dedd18491
7 changed files with 38 additions and 13 deletions

View File

@@ -26,6 +26,7 @@ export interface ContainerInput {
groupFolder: string;
chatJid: string;
isMain: boolean;
isScheduledTask?: boolean;
}
export interface ContainerOutput {
@@ -68,12 +69,13 @@ function buildVolumeMounts(group: RegisteredGroup, isMain: boolean): VolumeMount
readonly: false
});
// Global CLAUDE.md (read-only for non-main)
const globalClaudeMd = path.join(GROUPS_DIR, 'CLAUDE.md');
if (fs.existsSync(globalClaudeMd)) {
// Global memory directory (read-only for non-main)
// Apple Container only supports directory mounts, not file mounts
const globalDir = path.join(GROUPS_DIR, 'global');
if (fs.existsSync(globalDir)) {
mounts.push({
hostPath: globalClaudeMd,
containerPath: '/workspace/global/CLAUDE.md',
hostPath: globalDir,
containerPath: '/workspace/global',
readonly: true
});
}

View File

@@ -4,7 +4,7 @@ import pino from 'pino';
import { CronExpressionParser } from 'cron-parser';
import { getDueTasks, updateTaskAfterRun, logTaskRun, getTaskById, getAllTasks } from './db.js';
import { ScheduledTask, RegisteredGroup } from './types.js';
import { GROUPS_DIR, SCHEDULER_POLL_INTERVAL, DATA_DIR } from './config.js';
import { GROUPS_DIR, SCHEDULER_POLL_INTERVAL, DATA_DIR, MAIN_GROUP_FOLDER } from './config.js';
import { runContainerAgent, writeTasksSnapshot } from './container-runner.js';
const logger = pino({
@@ -56,11 +56,13 @@ async function runTask(task: ScheduledTask, deps: SchedulerDependencies): Promis
let error: string | null = null;
try {
const isMain = task.group_folder === MAIN_GROUP_FOLDER;
const output = await runContainerAgent(group, {
prompt: task.prompt,
groupFolder: task.group_folder,
chatJid: task.chat_jid,
isMain: false // Scheduled tasks run in their group's context
isMain,
isScheduledTask: true
});
if (output.status === 'error') {