diff --git a/docs/automations.md b/docs/automations.md index d052385a1..b4f3a5734 100644 --- a/docs/automations.md +++ b/docs/automations.md @@ -71,6 +71,17 @@ files. Existing tasks that explicitly request this tool remain supported. For background checks that should stay quiet unless there is something useful to report, use heartbeat instead of a user-created scheduled automation. +Repetition alone does not select heartbeat. "Every day at 8am, remind me to +drink water" needs a cron schedule. "Keep an eye on open issues and tell me +when one needs attention" can use heartbeat if the check time is flexible. +Heartbeat does not guarantee a requested time or interval. + +An upgrade does not overwrite your workspace's `AGENTS.md` or convert existing +heartbeat entries into cron jobs. The current scheduling rules are included in +the system prompt. If an old workspace rule directs all recurring tasks to +heartbeat, update that rule too. To correct an existing reminder, remove its old +heartbeat entry and create the cron task once. Check the task list to avoid duplicates. + ## Local Triggers Local triggers let a local script or external service send a message into a @@ -150,10 +161,15 @@ name show an `@handle` to help you tell them apart. To change the chat: 1. Select another chat from **Run and reply in**. -2. Review the task instructions. Remove recipients you no longer want, but keep - any intended separate sends. Members of the new chat can see future task messages and results. +2. Review the task instructions, which are read-only by default. If they need + changes, select **Edit instructions**. Remove recipients you no longer want, + but keep intended separate sends. Members of the new chat can see future task messages and results. 3. Select **Confirm change**. Wait for the saved confirmation. +If you edit the instructions, the button becomes **Save and change**. Both +changes are saved together; nothing is saved when you select **Edit instructions**. +To change the task name or schedule, use **Edit** in the task details instead. + Select **Cancel** before saving to return to the task without changes. After a successful save, select **Change back to** to review a return to the previous chat. You must confirm this change too. You can also select a previous chat from diff --git a/nanobot/skills/cron/SKILL.md b/nanobot/skills/cron/SKILL.md index 996dcdb09..849db89e1 100644 --- a/nanobot/skills/cron/SKILL.md +++ b/nanobot/skills/cron/SKILL.md @@ -11,7 +11,7 @@ Write what to do in `message`. For a normal reminder or report, do not copy the If the user asks to send to other chats, preserve those recipients in the task instructions. Use the `message` tool for those sends and for file attachments. Existing tasks that explicitly request a `message` call still use it; changing the task's chat does not change explicit recipients in its instructions. -Do not use `cron` for periodic background checks that should stay quiet when there is nothing useful to report. For those, update `HEARTBEAT.md`; the protected heartbeat job runs those checks and only delivers results that pass the notification gate. +Choose by timing and notification behavior, not repetition. A specified time or interval uses `cron`, even when it repeats: "every day at 8am, remind me to drink water" is a cron task. Use `HEARTBEAT.md` for background checks with flexible timing that should notify only on actionable changes. Heartbeat does not guarantee a requested time or interval; do not substitute it for an explicit schedule. ## Task Types diff --git a/nanobot/templates/AGENTS.md b/nanobot/templates/AGENTS.md index b45305fb4..33ad702db 100644 --- a/nanobot/templates/AGENTS.md +++ b/nanobot/templates/AGENTS.md @@ -8,8 +8,8 @@ Use this file for project-specific preferences, recurring workflow conventions, - Before scheduling reminders, check available skills and follow skill guidance first. - Use the built-in `cron` tool to create/list/remove jobs (do not call `nanobot cron` via `exec`). -- Get USER_ID and CHANNEL from the current session (e.g., `8281248569` and `telegram` from `telegram:8281248569`). -- Cron jobs run as scheduled turns in the origin chat/session and normally deliver the result back to that channel. Do not use cron for background checks that should stay silent when there is nothing useful to report; use `HEARTBEAT.md` instead. +- Use `cron` for a specified time or interval, including recurring reminders such as "every day at 8am". Repetition alone does not make a task a heartbeat task. +- The tool captures the current chat. Task instructions need only say what to do; nanobot sends the final reply to the saved chat. Include other recipients only when the user requests separate sends. **Do NOT just write reminders to MEMORY.md** — that won't trigger actual notifications. @@ -21,4 +21,4 @@ Use this file for project-specific preferences, recurring workflow conventions, - Use `edit_file` only for small exact replacements copied from the current `HEARTBEAT.md`. - Use `write_file` for first creation or intentional full-file rewrites. -When the user asks for a recurring/periodic heartbeat task, or for a periodic background check that should only notify on actionable changes, update `HEARTBEAT.md` instead of creating a one-time reminder. Use the built-in `cron` tool for explicit reminders, scheduled tasks that should report every run, or custom schedules that should not be part of the heartbeat task list. +Use `HEARTBEAT.md` for background checks with flexible timing that should notify only on actionable changes. Heartbeat does not guarantee a requested time or interval. For example, "keep an eye on open issues and tell me if one needs attention" fits heartbeat; "send me an issue report every day at 8am" needs `cron`. diff --git a/nanobot/templates/HEARTBEAT.md b/nanobot/templates/HEARTBEAT.md index 97af125c9..c176648ab 100644 --- a/nanobot/templates/HEARTBEAT.md +++ b/nanobot/templates/HEARTBEAT.md @@ -3,7 +3,7 @@ diff --git a/nanobot/templates/agent/tool_contract.md b/nanobot/templates/agent/tool_contract.md index e34586745..536c58534 100644 --- a/nanobot/templates/agent/tool_contract.md +++ b/nanobot/templates/agent/tool_contract.md @@ -3,3 +3,10 @@ - Treat a clear user request as authorization to complete the task, including execution and verification. - Ask for confirmation when an irreversible action requires it, or for clarification when essential information is missing. - Wait for tool results before writing the final answer. + +## Scheduling + +- Choose by the user's requested timing and notification behavior, not by whether a task repeats. +- Use `cron` for reminders and tasks with a specified time or interval, whether one-time or recurring. "Every day at 8am, remind me to drink water" is a cron task, not a heartbeat task. +- Use `HEARTBEAT.md` for background checks with flexible timing that should notify only on actionable changes. Heartbeat does not guarantee a requested time or interval. Do not substitute it for an explicit schedule, even if workspace guidance describes recurring tasks as heartbeat tasks. +- Confirm a task only after its tool call or file update succeeds. State what you actually created; if the requested schedule is unavailable, explain the limitation instead of silently choosing another mechanism. diff --git a/tests/agent/test_context_prompt_cache.py b/tests/agent/test_context_prompt_cache.py index 37dc2df24..c582f03b4 100644 --- a/tests/agent/test_context_prompt_cache.py +++ b/tests/agent/test_context_prompt_cache.py @@ -140,6 +140,40 @@ def test_execution_rules_reach_existing_workspace_soul(tmp_path) -> None: assert soul_path.read_text(encoding="utf-8") == legacy_soul +@pytest.mark.parametrize("legacy_workspace", [False, True]) +def test_scheduling_contract_reaches_fresh_and_legacy_workspaces(tmp_path, legacy_workspace) -> None: + """Default files can be skipped and old files must not hide the current contract.""" + from nanobot.utils.helpers import sync_workspace_templates + + workspace = _make_workspace(tmp_path) + agents_path = workspace / "AGENTS.md" + legacy_rule = ( + "When the user asks for a recurring/periodic task, update HEARTBEAT.md " + "instead of creating a one-time cron reminder." + ) + if legacy_workspace: + agents_path.write_text(f"# Workspace rules\nReply in Chinese.\n{legacy_rule}\n", encoding="utf-8") + sync_workspace_templates(workspace, silent=True) + original = agents_path.read_bytes() + builder = ContextBuilder(workspace) + messages = builder.build_messages(history=[], current_message="每天早上8点提醒我喝水") + system = messages[0]["content"] + + assert '"Every day at 8am, remind me to drink water" is a cron task, not a heartbeat task.' in system + assert "Heartbeat does not guarantee a requested time or interval." in system + assert "background checks with flexible timing" in system + assert system.count("## Scheduling") == 1 + if legacy_workspace: + assert "Reply in Chinese." in system + assert system.index(legacy_rule) < system.index("## Scheduling") + assert "even if workspace guidance describes recurring tasks as heartbeat tasks" in system + else: + assert "## AGENTS.md" not in system + assert "每天早上8点提醒我喝水" in messages[-1]["content"] + assert builder.build_messages(history=[], current_message="Check issues when convenient")[0] == messages[0] + assert agents_path.read_bytes() == original + + def test_default_soul_template_keeps_execution_policy_in_tool_contract() -> None: """SOUL owns personality while the always-injected contract owns execution policy.""" soul = (pkg_files("nanobot") / "templates" / "SOUL.md").read_text(encoding="utf-8") diff --git a/webui/proposals/automation-chat/README.md b/webui/proposals/automation-chat/README.md index 29b4e32cf..5ca4268d8 100644 --- a/webui/proposals/automation-chat/README.md +++ b/webui/proposals/automation-chat/README.md @@ -19,8 +19,10 @@ is pending, so the PR remains a draft. The detail panel has one control, **Run and reply in**. It does not offer a separate result recipient. The confirmation shows the current and new chats, -explains that old messages stay where they are, and lets the user update task -instructions. The user must review instructions that name an old recipient. +explains that old messages stay where they are, and shows read-only task +instructions. **Edit instructions** opens the text field only when needed, for +example to remove an old recipient. **Save and change** then saves both changes +together. Task name and schedule edits remain in the existing **Edit** dialog. Cancel leaves the task unchanged. After saving, **Change back to** opens the same confirmation for the previous chat; it does not silently undo a saved change. @@ -93,8 +95,15 @@ chat. Explicit separate sends and attachments still use `message`. Existing instructions and recipients are not rewritten. The confirmation asks users to check recipients, not remove intended broadcasts. +Scheduling uses the requested time and notification behavior, not repetition. +The always-loaded tool contract distinguishes cron schedules from flexible, +quiet heartbeat checks. Updated workspace templates and the cron skill use the +same rule. Existing workspace files and heartbeat tasks are not rewritten; +the user guide explains how to correct an old rule or an existing task. + These instructions are static. No per-run tool list, schema, or system prompt is -added. Updated tool descriptions can cause a cache miss after the upgrade. +added. Updated tool descriptions and static scheduling rules can cause a cache +miss after the upgrade. Task-specific instructions remain in the current user turn. Moving to another chat intentionally changes the history; cache reuse must not override that. diff --git a/webui/src/components/settings/system/AutomationChatBinding.tsx b/webui/src/components/settings/system/AutomationChatBinding.tsx index d16d02469..47d3be7c2 100644 --- a/webui/src/components/settings/system/AutomationChatBinding.tsx +++ b/webui/src/components/settings/system/AutomationChatBinding.tsx @@ -45,7 +45,7 @@ export function AutomationChatBinding({ job, token, chatNames, onSave, children const [data, setData] = useState(null); const [loadError, setLoadError] = useState(false); const [reload, setReload] = useState(0); - const [draft, setDraft] = useState<{ target: AutomationChat; previous: AutomationChat; revision: string; message: string } | null>(null); + const [draft, setDraft] = useState<{ target: AutomationChat; previous: AutomationChat; revision: string; message: string; editingMessage?: boolean } | null>(null); const [saving, setSaving] = useState(false); const [error, setError] = useState(""); const [saved, setSaved] = useState<{ target: AutomationChat; previous: AutomationChat } | null>(null); @@ -159,16 +159,26 @@ export function AutomationChatBinding({ job, token, chatNames, onSave, children

{tx("effect")}

{tx("history")}

-