Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(scheduled): normalize scheduled workspace bindings
hui45536a6ab015974
diff --git a/crates/host-core/src/rpc/scheduled_rpc.rs b/crates/host-core/src/rpc/scheduled_rpc.rsindex 3b47a7fef..4114a6ead 100644--- a/crates/host-core/src/rpc/scheduled_rpc.rs+++ b/crates/host-core/src/rpc/scheduled_rpc.rs@@ -240,12 +240,7 @@ mod tests {let project_a = tempfile::tempdir().unwrap();let project_b = tempfile::tempdir().unwrap();let saved_path = project_bound.then(|| {- project_a- .path()- .canonicalize()- .unwrap()- .to_string_lossy()- .into_owned()+ crate::db::canonical_project_path(&project_a.path().to_string_lossy()).unwrap()});let state = AppState::open(dir.path()).unwrap();let task = handle_in_workspace(@@ -307,7 +302,8 @@ mod tests {.unwrap()["task"].clone();let id = task["id"].as_str().unwrap();- let path = state.workspace.set(project.path()).path;+ let path =+ crate::db::canonical_project_path(&state.workspace.set(project.path()).path).unwrap();let run = handle(&state, "scheduled.run", json!({"id":id})).unwrap();let session = sessions::get_session(&state.db, run["sessionId"].as_str().unwrap()).unwrap()@@ -362,7 +358,9 @@ mod tests {let mut state = AppState::open(dir.path()).unwrap();let original_project = tempfile::tempdir().unwrap();let different_project = tempfile::tempdir().unwrap();- let original_path = state.workspace.set(original_project.path()).path;+ let original_path =+ crate::db::canonical_project_path(&state.workspace.set(original_project.path()).path)+ .unwrap();let task = handle(&state,"scheduled.create",diff --git a/crates/host-core/src/rpc/scheduled_tools.rs b/crates/host-core/src/rpc/scheduled_tools.rsindex 73f398eca..e5870a16f 100644--- a/crates/host-core/src/rpc/scheduled_tools.rs+++ b/crates/host-core/src/rpc/scheduled_tools.rs@@ -191,6 +191,139 @@ mod tests {use std::sync::Arc;use tokio::sync::{mpsc, Mutex};+ #[cfg(windows)]+ #[tokio::test]+ async fn review_ui_task_is_visible_to_same_project_conversation() {+ let dir = tempfile::tempdir().unwrap();+ let project = tempfile::tempdir().unwrap();+ let mut st = AppState::open(dir.path()).unwrap();+ st.handshook = true;+ st.db+ .set_setting("app", &json!({"defaultPermissionMode":"auto"}))+ .unwrap();+ let path = st.workspace.set(project.path()).path;+ let task = scheduled_rpc::handle(+ &st,+ "scheduled.create",+ json!({+ "title":"UI task", "prompt":"Review", "cadence":"hourly",+ "schedule":{"hour":0,"minute":0,"weekday":0}+ }),+ )+ .unwrap()["task"]+ .clone();+ let session =+ sessions::create_session(&st.db, None, Some("agent".into()), None, None, Some(path))+ .unwrap();+ let state = Arc::new(Mutex::new(st));+ let listed = call(&state, &session.id, "ScheduledTaskList", json!({})).await;+ assert_eq!(listed["ok"], true, "{listed}");+ let edited = call(+ &state,+ &session.id,+ "ScheduledTaskUpdate",+ json!({"id":task["id"],"title":"Renamed"}),+ )+ .await;+ assert!(listed["content"]["tasks"].as_array().unwrap().iter().any(|item| item["id"] == task["id"]),+ "UI-created task must be visible in the same project: task={task}, list={listed}, update={edited}");+ assert_eq!(edited["ok"], true, "{edited}");+ }++ #[cfg(windows)]+ #[tokio::test]+ async fn stored_windows_aliases_remain_visible_after_restart_and_isolated() {+ let dir = tempfile::tempdir().unwrap();+ let project = tempfile::tempdir().unwrap();+ let other = tempfile::tempdir().unwrap();+ let st = AppState::open(dir.path()).unwrap();+ let path = crate::workspace::simple_canonicalize(project.path())+ .unwrap()+ .to_string_lossy()+ .into_owned();+ let same = sessions::create_session(+ &st.db,+ None,+ Some("agent".into()),+ None,+ None,+ Some(path.clone()),+ )+ .unwrap()+ .id;+ let foreign = sessions::create_session(+ &st.db,+ None,+ Some("agent".into()),+ None,+ None,+ Some(other.path().to_string_lossy().into_owned()),+ )+ .unwrap()+ .id;+ for (i, alias) in [+ path.clone(),+ path.replace('\\', "/"),+ path.to_lowercase(),+ format!("{path}\\"),+ format!("\\\\?\\{path}"),+ ]+ .iter()+ .enumerate()+ {+ assert_eq!(+ std::fs::canonicalize(alias).unwrap(),+ std::fs::canonicalize(&path).unwrap()+ );+ scheduled::import_tasks(&st.db,&[json!({"id":format!("alias-{i}"),"title":"Legacy","prompt":"Review","cadence":"manual","configJson":{"workspacePath":alias}})]).unwrap();+ }+ drop(st);+ let mut st = AppState::open(dir.path()).unwrap();+ st.handshook = true;+ st.db+ .set_setting("app", &json!({"defaultPermissionMode":"auto"}))+ .unwrap();+ let state = Arc::new(Mutex::new(st));+ let own = call(&state, &same, "ScheduledTaskList", json!({})).await;+ assert_eq!(own["content"]["tasks"].as_array().unwrap().len(), 5);+ assert!(+ call(&state, &foreign, "ScheduledTaskList", json!({})).await["content"]["tasks"]+ .as_array()+ .unwrap()+ .is_empty()+ );+ assert_eq!(+ call(+ &state,+ &foreign,+ "ScheduledTaskUpdate",+ json!({"id":"alias-0","title":"Wrong"})+ )+ .await["errorCode"],+ "NOT_FOUND"+ );+ assert_eq!(+ call(+ &state,+ &foreign,+ "ScheduledTaskDelete",+ json!({"id":"alias-0"})+ )+ .await["errorCode"],+ "NOT_FOUND"+ );+ assert_eq!(+ call(+ &state,+ &same,+ "ScheduledTaskDelete",+ json!({"id":"alias-0"})+ )+ .await["ok"],+ true+ );+ }+async fn call(state: &Arc<Mutex<AppState>>, session: &str, name: &str, args: Value) -> Value {super::super::handle_request(state.clone(),@@ -215,7 +348,8 @@ mod tests {st.db.set_setting("app", &json!({"defaultPermissionMode":"auto"})).unwrap();- let path = st.workspace.set(project.path()).path;+ let path =+ crate::db::canonical_project_path(&st.workspace.set(project.path()).path).unwrap();let session = sessions::create_session(&st.db,None,diff --git a/crates/host-core/src/scheduled.rs b/crates/host-core/src/scheduled.rsindex 2b83a446b..2ae938c57 100644--- a/crates/host-core/src/scheduled.rs+++ b/crates/host-core/src/scheduled.rs@@ -176,7 +176,7 @@ fn task_from_row(row: &rusqlite::Row<'_>) -> rusqlite::Result<ScheduledTask> {workspace_path: config.get("workspacePath").and_then(Value::as_str)- .map(str::to_string),+ .and_then(crate::db::canonical_project_path),})}diff --git a/crates/host-core/src/scheduled/automation.rs b/crates/host-core/src/scheduled/automation.rsindex c50a0d3ff..52f939e0b 100644--- a/crates/host-core/src/scheduled/automation.rs+++ b/crates/host-core/src/scheduled/automation.rs@@ -19,7 +19,9 @@ pub fn configure(config: &mut Value, input: &Value, cadence: &str, now: i64) ->if !workspace.is_null() && !workspace.is_string() {bail!("workspacePath must be a string or null");}- config["workspacePath"] = workspace.clone();+ config["workspacePath"] = json!(workspace+ .as_str()+ .and_then(crate::db::canonical_project_path));}if input.get("schedule").is_some()|| input.get("cadence").is_some()diff --git a/docs/spec/03-runtime/06-host-rpc-protocol.md b/docs/spec/03-runtime/06-host-rpc-protocol.mdindex 7be3e8e3a..51899cd58 100644--- a/docs/spec/03-runtime/06-host-rpc-protocol.md+++ b/docs/spec/03-runtime/06-host-rpc-protocol.md@@ -1211,3 +1211,7 @@ Create requires title, prompt and cadence; automatic daily/weekly tasks requirea schedule. Update takes an existing ID and partial fields, preserving allunspecified configuration. Exact local times remain supported despite theUI's four period presets. No new DB schema or transport is introduced.++### Scheduled tasks: workspace identity++Stored workspace bindings use the existing project canonicalization contract on both write and read. On Windows, slash direction, case, trailing separators and extended path prefixes do not hide a task from its own project's conversation. The distinction between missing legacy bindings and explicit null remains unchanged. Foreign-project tools cannot list or mutate bound tasks.diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex e6fbc9513..b16cdbaeb 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -14402,3 +14402,9 @@ the latest destination. These assertions measure work counts, not device FPS.`fork_preserves_referenced_pasted_files_independently` and `sessions::fork_files`cover ownership, deletion, repeated/bounded forks, retained checkpoint paths,expired inputs, rollback, and symlink rejection.++### E2E-SCHEDULED-paths++- **Scenario:** Workspace identity.+- **Expected:** Stored workspace bindings use the existing project canonicalization contract on both write and read. On Windows, slash direction, case, trailing separators and extended path prefixes do not hide a task from its own project's conversation. The distinction between missing legacy bindings and explicit null remains unchanged. Foreign-project tools cannot list or mutate bound tasks.+- **Automation:** `node --experimental-strip-types scripts/e2e-scheduled-paths.mjs` uses an isolated real Host and SQLite profile. Inference is not sent to a live provider.diff --git a/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md b/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.mdindex 9e2dc820d..429926cdb 100644--- a/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md+++ b/docs/zh-CN/spec/03-runtime/06-host-rpc-protocol.md@@ -986,3 +986,9 @@ Host 重新检查会话的持久化模式,按调用会话的项目限制访问提示词、非法时间和星期在写入前拒绝;不能删除运行中的任务。创建需 title、prompt、cadence;每天/每周自动任务需 schedule。修改使用已存在的 ID 并保留未指定字段。界面虽只提供四个时段,工具仍支持具体本地时间。不新增数据库 schema 或传输协议。++### 定时任务:工作区身份++保存和读取工作区绑定时统一使用现有项目路径规范化规则。在 Windows 上,+斜杠方向、大小写、末尾分隔符和扩展路径前缀的差异不会再让同项目会话看不到任务。+缺失的旧版绑定与显式 null 仍保持不同语义;其他项目的工具不能查询或修改绑定任务。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.mdindex 2f38aa1b0..9148ff9e7 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@@ -8563,3 +8563,12 @@ the latest destination. These assertions measure work counts, not device FPS.- **规格**:`04-ux/08-component-spec.md`、`04-ux/09-interaction-patterns.md`。- **验收 / 里程碑**:C、Quality / M6+。- **状态**:组件与状态层用户路径由 `queue-pending-actions.test.mjs` 覆盖。++### E2E-SCHEDULED-paths++- **场景**:工作区身份。+- **预期**:保存和读取工作区绑定时统一使用现有项目路径规范化规则。Windows+ 路径的斜杠方向、大小写、末尾分隔符和扩展路径前缀差异不影响同项目会话;+ 缺失的旧版绑定与显式 null 保持不同语义,其他项目不能查询或修改绑定任务。+- **自动化**:`node --experimental-strip-types scripts/e2e-scheduled-paths.mjs`+ 使用隔离的真实 Host 与 SQLite 配置,不向真实提供商发送推理请求。diff --git a/scripts/e2e-scheduled-paths.mjs b/scripts/e2e-scheduled-paths.mjsnew file mode 100644index 000000000..e731f522f--- /dev/null+++ b/scripts/e2e-scheduled-paths.mjs@@ -0,0 +1,31 @@+import assert from "node:assert/strict";+import { mkdtemp, mkdir } from "node:fs/promises";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { randomUUID } from "node:crypto";+import { Host, resolveHostBinary } from "./e2e/host.mjs";++const root=await mkdtemp(join(tmpdir(),"pi-scheduled-paths-"));+const a=join(root,"a"),b=join(root,"b");await Promise.all([mkdir(a),mkdir(b)]);+const host=new Host(resolveHostBinary(),join(root,"data"));+const tool=(sessionId,toolName,args)=>host.call("tools.execute",{sessionId,toolName,args,mode:"agent",toolCallId:randomUUID()});+try {+ await host.start();await host.call("settings.set",{defaultPermissionMode:"auto"});+ for(const cadence of ["manual","hourly","daily","weekly"]) {+ await host.call("workspace.set",{path:a});+ const {task}=await host.call("scheduled.create",{title:"UI task",prompt:"Review",cadence,schedule:cadence==="manual"?null:{hour:9,minute:15,weekday:0}});+ const {session:owner}=await host.call("session.create",{mode:"agent",projectPath:a});+ const {session:foreign}=await host.call("session.create",{mode:"agent",projectPath:b});+ await host.restart();await host.call("workspace.set",{path:b});+ const listed=await tool(owner.id,"ScheduledTaskList",{});+ assert.ok(listed.content.tasks.some(item=>item.id===task.id));+ const hidden=await tool(foreign.id,"ScheduledTaskList",{});assert.ok(!hidden.content.tasks.some(item=>item.id===task.id));+ assert.equal((await tool(foreign.id,"ScheduledTaskDelete",{id:task.id})).errorCode,"NOT_FOUND");+ const updated=await tool(owner.id,"ScheduledTaskUpdate",{id:task.id,title:"Renamed"});assert.equal(updated.ok,true);+ const run=await host.call("scheduled.run",{id:task.id});const {session}=await host.call("session.get",{id:run.sessionId});+ assert.equal(session.projectPath,task.workspacePath);+ await host.call("scheduled.finishRun",{runId:run.runId,status:"completed"});+ assert.equal((await tool(owner.id,"ScheduledTaskDelete",{id:task.id})).ok,true);+ console.log(`PASS ${cadence}: UI create, restart, same-project AI CRUD, foreign rejection and Run now`);+ }+} finally {await host.stop();}