Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(scheduled): allow hourly updates without calendar fields

yuxinof965986acb69
diff --git a/crates/host-core/src/rpc/scheduled_tools.rs b/crates/host-core/src/rpc/scheduled_tools.rs
index 075f449a5..73f398eca 100644
--- a/crates/host-core/src/rpc/scheduled_tools.rs
+++ b/crates/host-core/src/rpc/scheduled_tools.rs
@@ -123,12 +123,19 @@ fn execute_inner(st: &AppState, p: &ToolsExecuteParams) -> Result<Value, JsonRpc
if !args.contains_key("cadence") {
return Err(invalid("cadence required"));
}
- if cadence == "hourly" && !args.contains_key("schedule") {
- input["schedule"] = json!({"hour":0,"minute":0,"weekday":0});
- } else if cadence == "manual" {
+ if cadence == "manual" {
input["schedule"] = Value::Null;
}
}
+ if args.get("cadence").and_then(Value::as_str) == Some("hourly")
+ && !args.contains_key("schedule")
+ && existing
+ .as_ref()
+ .and_then(|task| task.schedule.as_ref())
+ .is_none()
+ {
+ input["schedule"] = json!({"hour":0,"minute":0,"weekday":0});
+ }
if p.tool_name != "ScheduledTaskDelete"
&& cadence != "manual"
&& input.get("schedule").is_none()
@@ -309,6 +316,81 @@ mod tests {
);
}
+ #[tokio::test]
+ async fn manual_to_hourly_update_needs_no_calendar_schedule() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut st = AppState::open(dir.path()).unwrap();
+ st.handshook = true;
+ st.db
+ .set_setting("app", &json!({"defaultPermissionMode":"auto"}))
+ .unwrap();
+ let session =
+ sessions::create_session(&st.db, None, Some("agent".into()), None, None, None).unwrap();
+ let state = Arc::new(Mutex::new(st));
+ let created = call(
+ &state,
+ &session.id,
+ "ScheduledTaskCreate",
+ json!({
+ "title":"Review", "prompt":"Review project", "cadence":"manual", "enabled":false
+ }),
+ )
+ .await;
+ assert_eq!(created["ok"], true, "{created}");
+ let id = created["content"]["task"]["id"].as_str().unwrap();
+ for cadence in ["daily", "weekly"] {
+ let rejected = call(
+ &state,
+ &session.id,
+ "ScheduledTaskUpdate",
+ json!({"id":id,"cadence":cadence}),
+ )
+ .await;
+ assert_eq!(rejected["errorCode"], "INVALID_PARAMS");
+ }
+ let before = crate::db::now_ms();
+ let updated = call(
+ &state,
+ &session.id,
+ "ScheduledTaskUpdate",
+ json!({"id":id,"cadence":"hourly"}),
+ )
+ .await;
+ let after = crate::db::now_ms();
+ assert_eq!(updated["ok"], true, "{updated}");
+ let task = &updated["content"]["task"];
+ assert_eq!(task["cadence"], "hourly");
+ assert_eq!(task["enabled"], false);
+ assert_eq!(task["prompt"], "Review project");
+ let next = crate::db::ts_to_ms(task["nextRunAt"].as_str().unwrap());
+ assert!((before + 3_600_000..=after + 3_600_000).contains(&next));
+ let renamed = call(
+ &state,
+ &session.id,
+ "ScheduledTaskUpdate",
+ json!({"id":id,"title":"Renamed"}),
+ )
+ .await;
+ assert_eq!(renamed["content"]["task"]["nextRunAt"], task["nextRunAt"]);
+ let custom = json!({"hour":15,"minute":30,"weekday":2,"weekdays":[2,4]});
+ let configured = call(
+ &state,
+ &session.id,
+ "ScheduledTaskUpdate",
+ json!({"id":id,"cadence":"weekly","schedule":custom}),
+ )
+ .await;
+ assert_eq!(configured["ok"], true, "{configured}");
+ let hourly = call(
+ &state,
+ &session.id,
+ "ScheduledTaskUpdate",
+ json!({"id":id,"cadence":"hourly"}),
+ )
+ .await;
+ assert_eq!(hourly["content"]["task"]["schedule"], custom);
+ }
+
#[test]
fn scheduled_mutations_require_approval_outside_auto_mode() {
use crate::permissions::{PermissionDecision, PermissionManager};
diff --git a/docs/spec/04-ux/01-ui-ia.md b/docs/spec/04-ux/01-ui-ia.md
index 813d808d3..9bd23fd15 100644
--- a/docs/spec/04-ux/01-ui-ia.md
+++ b/docs/spec/04-ux/01-ui-ia.md
@@ -275,6 +275,11 @@ auto-approve a contract.
The user must explicitly switch it to Agent before enabling unattended
execution.
+Agent tools can change a Manual task to Hourly by supplying only its id and
+`cadence: "hourly"`; no calendar time is required. Preserve existing schedule
+fields and paused state. Daily and Weekly still require a valid saved or supplied
+schedule. Renaming an Hourly task does not restart its interval.
+
### 3.5 Extensions
The Extensions destination is a focused plugin surface with a compact header and
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 996981fdb..25e85f5ab 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -7929,6 +7929,7 @@ identify the platform validation still needed.
| Acceptance | Scenarios |
|---|---|
+| C / F — Hourly task updates | E2E-SCHEDULED-manual-to-hourly |
| C / F / Quality — Desktop automations | E2E-SCHEDULED-desktop-automation-lifecycle |
| A / C — Unicode stdio framing | E2E-RPC-unicode-separators |
| C / G / Quality — Plugins navigation | E2E-NAV-plugins-button-goes-back |
@@ -14286,3 +14287,18 @@ the latest destination. These assertions measure work counts, not device FPS.
- **Expected**: The complete URL, including `(software)`, opens the React software article. The outer prose closing parenthesis and sentence-ending punctuation after the URL parenthesis are not part of the link. Adjacent references remain independently clickable. Nested parentheses, query/fragment parentheses and percent-encoded parentheses remain intact.
- **Coverage**: `chat-links.test.mjs`; native desktop click-through with the normal browser destination.
- **Specs linked**: `04-ux/08-component-spec.md` §8.3.
+
+### E2E-SCHEDULED-manual-to-hourly
+
+- **Preconditions:** Built host candidate, isolated data directory, no provider.
+- **Steps:** Through `tools.execute`, create a paused Manual task, update only
+ its id and cadence to Hourly, rename it, restart, and list tasks again.
+- **Expected:** Update succeeds without calendar fields; the next occurrence is
+ one hour away. Prompt, paused state and saved configuration survive. Rename
+ does not reset the interval. RPC tests also cover required Daily/Weekly times
+ and retention of an existing custom schedule.
+- **Specs:** 04-ux/01-ui-ia §3.4.
+- **Acceptance:** C / F — task configuration and persistence.
+- **Milestone:** Maintenance.
+- **Status:** `node scripts/e2e-scheduled-hourly-update.mjs` exercises the real
+ Rust host, permission path, stdio and SQLite; no model inference or desktop UI.
diff --git a/docs/zh-CN/spec/04-ux/01-ui-ia.md b/docs/zh-CN/spec/04-ux/01-ui-ia.md
index 304fd1fad..ce52a596e 100644
--- a/docs/zh-CN/spec/04-ux/01-ui-ia.md
+++ b/docs/zh-CN/spec/04-ux/01-ui-ia.md
@@ -225,6 +225,11 @@
用户必须在启用无人值守之前显式将其切换到 Agent
执行。
+Agent tools can change a Manual task to Hourly by supplying only its id and
+`cadence: "hourly"`; no calendar time is required. Preserve existing schedule
+fields and paused state. Daily and Weekly still require a valid saved or supplied
+schedule. Renaming an Hourly task does not restart its interval.
+
### 3. 5 扩展
扩展目标是专注于插件的页面,使用紧凑标头并且只保留两个选项卡:
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 9a68c4ab5..30d58c0ad 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -5184,6 +5184,7 @@ eleven-tool-round desktop paths are verified by
| 验收 | 应用场景 |
|---|---|
+| C / F — Hourly task updates | E2E-SCHEDULED-manual-to-hourly |
| C / F / Quality — 桌面定时任务 | E2E-SCHEDULED-desktop-automation-lifecycle |
| A / C — Unicode stdio 成帧 | E2E-RPC-unicode-separators |
| C / G / Quality — Plugins navigation | E2E-NAV-plugins-button-goes-back |
@@ -8457,3 +8458,18 @@ the latest destination. These assertions measure work counts, not device FPS.
- **预期**:打开包含 `(software)` 的完整网址,进入 React 软件词条;正文外层的右括号和紧跟 URL 右括号的句末标点不属于链接,相邻引用仍能独立点击。嵌套圆括号、查询和片段内的圆括号、百分号编码的圆括号均保持完整。
- **覆盖**:`chat-links.test.mjs`;桌面端通过正常浏览器目标实际点击验证。
- **链接规格**:`04-ux/08-component-spec.md` §8.3。
+
+### E2E-SCHEDULED-manual-to-hourly
+
+- **Preconditions:** Built host candidate, isolated data directory, no provider.
+- **Steps:** Through `tools.execute`, create a paused Manual task, update only
+ its id and cadence to Hourly, rename it, restart, and list tasks again.
+- **Expected:** Update succeeds without calendar fields; the next occurrence is
+ one hour away. Prompt, paused state and saved configuration survive. Rename
+ does not reset the interval. RPC tests also cover required Daily/Weekly times
+ and retention of an existing custom schedule.
+- **Specs:** 04-ux/01-ui-ia §3.4.
+- **Acceptance:** C / F — task configuration and persistence.
+- **Milestone:** Maintenance.
+- **Status:** `node scripts/e2e-scheduled-hourly-update.mjs` exercises the real
+ Rust host, permission path, stdio and SQLite; no model inference or desktop UI.
diff --git a/scripts/e2e-scheduled-hourly-update.mjs b/scripts/e2e-scheduled-hourly-update.mjs
new file mode 100644
index 000000000..8a07f7fcd
--- /dev/null
+++ b/scripts/e2e-scheduled-hourly-update.mjs
@@ -0,0 +1,46 @@
+#!/usr/bin/env node
+// Exercise the public tool path through a real host and SQLite, without a model.
+import assert from "node:assert/strict";
+import { randomUUID } from "node:crypto";
+import { mkdtemp } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { Host, resolveHostBinary } from "./e2e/host.mjs";
+
+const host = new Host(resolveHostBinary(), await mkdtemp(join(tmpdir(), "pi-hourly-update-")));
+try {
+ await host.start();
+ await host.call("settings.set", { defaultPermissionMode: "auto" });
+ const { session } = await host.call("session.create", { mode: "agent", title: "Hourly update" });
+ const tool = (toolName, args) => host.call("tools.execute", {
+ sessionId: session.id, toolCallId: randomUUID(), toolName, args, mode: "agent",
+ });
+ const created = await tool("ScheduledTaskCreate", {
+ title: "Review", prompt: "Reply OK", cadence: "manual", enabled: false,
+ });
+ assert.equal(created.ok, true);
+ const id = created.content.task.id;
+ console.log("Created a paused Manual task.");
+ const before = Date.now();
+ const updated = await tool("ScheduledTaskUpdate", { id, cadence: "hourly" });
+ console.log("Update with only cadence=hourly:", JSON.stringify(updated.content));
+ assert.equal(updated.ok, true);
+ const task = updated.content.task;
+ assert.equal(task.enabled, false);
+ assert.equal(task.cadence, "hourly");
+ assert.equal(task.prompt, "Reply OK");
+ assert.ok(Date.parse(task.nextRunAt) >= before + 3_600_000);
+ assert.ok(Date.parse(task.nextRunAt) <= Date.now() + 3_600_000);
+ const renamed = await tool("ScheduledTaskUpdate", { id, title: "Renamed" });
+ assert.equal(renamed.content.task.nextRunAt, task.nextRunAt);
+ await host.stop();
+ await host.start();
+ const listed = await tool("ScheduledTaskList", {});
+ const restored = listed.content.tasks.find((item) => item.id === id);
+ assert.equal(restored.cadence, "hourly");
+ assert.equal(restored.enabled, false);
+ assert.equal(restored.title, "Renamed");
+ console.log("PASS: hourly conversion, one-hour interval, pause preservation, rename and restart.");
+} finally {
+ await host.stop();
+}