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): keep run transcripts out of every session list
Hanawada6a883a2002
diff --git a/apps/desktop/electron/main/tray-sessions.ts b/apps/desktop/electron/main/tray-sessions.tsindex 2403d7f3e..7304b6544 100644--- a/apps/desktop/electron/main/tray-sessions.ts+++ b/apps/desktop/electron/main/tray-sessions.ts@@ -26,6 +26,19 @@ const REFRESH_AFTER_INVOKE = new Set<string>([]);/** Main owns native presentation; durable records still come exclusively from Host. */+/**+ * Scheduled-task run transcripts are entered from the Scheduled page, so the+ * tray never offers one as a recent conversation — or as a running session it+ * could switch to (issue #1291). Ownership is reported by the host as+ * `scheduledRun` on each summary; this is the main-process twin of the+ * renderer's `isAutomationSession`.+ */+export function trayVisibleSessions(+ sessions: readonly SessionSummary[],+): SessionSummary[] {+ return sessions.filter((session) => session.scheduledRun !== true);+}+export function createTraySessions({getHost,getRunningSessionIds,@@ -86,7 +99,7 @@ export function createTraySessions({continue;}if (observed !== revision) continue;- sessions = listed.sessions;+ sessions = trayVisibleSessions(listed.sessions);const running = new Set(agentAvailable ? getRunningSessionIds() : []);if (agentAvailable) {for (const [id, active] of runningOverrides) {diff --git a/apps/desktop/src/components/SearchDialog.tsx b/apps/desktop/src/components/SearchDialog.tsxindex 217f93c0c..df806ccdd 100644--- a/apps/desktop/src/components/SearchDialog.tsx+++ b/apps/desktop/src/components/SearchDialog.tsx@@ -1,6 +1,7 @@import { useEffect, useMemo, useRef, useState } from "react";import { useTranslation } from "react-i18next";import { api } from "../lib/api";+import { listableSessions } from "../lib/session-origin";import { runPaletteCommand } from "../lib/commands";import { isDefaultSessionTitle, useAppStore } from "../stores/app-store";import { normalizeProjectPath } from "../lib/sidebar-session-groups";@@ -145,7 +146,10 @@ export function SearchDialog({ open, onClose }: { open: boolean; onClose: () =>const rows = useMemo<SearchRow[]>(() => {const q = query.trim().toLowerCase();const candidates: Omit<SearchRow, "optionIndex">[] = [];- const source = q ? search.hits.map((hit) => hit.session) : sessions;+ // Recents come from the store, so the same ownership rule applies here:+ // a scheduled run's transcript is entered from the Scheduled page, never+ // offered as a conversation to switch to (issue #1291).+ const source = listableSessions(q ? search.hits.map((hit) => hit.session) : sessions);const hits = new Map(search.hits.map((hit) => [hit.session.id, hit]));for (const session of source) {// Untitled drafts carry no searchable signal; they stay sidebar-only.diff --git a/apps/desktop/src/components/Sidebar.tsx b/apps/desktop/src/components/Sidebar.tsxindex c0c332a23..1e5cfb1a9 100644--- a/apps/desktop/src/components/Sidebar.tsx+++ b/apps/desktop/src/components/Sidebar.tsx@@ -28,7 +28,7 @@ import {sessionArchived,sessionPinned,} from "../lib/sidebar-session-groups";-import { isAutomationSession } from "../lib/session-origin";+import { listableSessions } from "../lib/session-origin";import {composerDropItems,hasComposerFileDrag,@@ -637,8 +637,7 @@ export function Sidebar({// point (issue #1291). The session stays in the store so the chat surface// can still resolve its title, source, and capabilities when it is opened// from there.- const candidates = sessions- .filter((session) => !isAutomationSession(session))+ const candidates = listableSessions(sessions).filter((session) => showArchived || !sessionArchived(session, sessionMeta[session.id]));// Empty sessions are durable sidebar rows now. Their message count, not// their title, controls New Task reuse, so a manual rename never changesdiff --git a/apps/desktop/src/lib/session-origin.ts b/apps/desktop/src/lib/session-origin.tsindex 942e7a586..240dc2bc0 100644--- a/apps/desktop/src/lib/session-origin.ts+++ b/apps/desktop/src/lib/session-origin.ts@@ -20,3 +20,15 @@ export function isAutomationSession(): boolean {return session?.scheduledRun === true;}++/**+ * The conversations a session list may offer to enter. Automation transcripts+ * are entered from the Scheduled page — that task's run history reads them in+ * place — so the SessionList's groups, search's recents view, and the tray drop+ * them before they can be listed or switched to.+ */+export function listableSessions<T extends Pick<SessionSummary, "scheduledRun">>(+ sessions: readonly T[],+): T[] {+ return sessions.filter((session) => !isAutomationSession(session));+}diff --git a/apps/desktop/test/scheduled-workspace.test.mjs b/apps/desktop/test/scheduled-workspace.test.mjsindex cb7c20070..96b65cfe0 100644--- a/apps/desktop/test/scheduled-workspace.test.mjs+++ b/apps/desktop/test/scheduled-workspace.test.mjs@@ -299,13 +299,13 @@ test("automation ownership keeps run transcripts out of the lists", async () =>});});-test("the session list and search both consume the automation predicate", async () => {+test("the session list and search both consume the ownership rule", async () => {const { readFile } = await import("node:fs/promises");const sidebar = await readFile(new URL("../src/components/Sidebar.tsx", import.meta.url), "utf8");- assert.match(sidebar, /import \{ isAutomationSession \} from "\.\.\/lib\/session-origin";/);+ assert.match(sidebar, /import \{ listableSessions \} from "\.\.\/lib\/session-origin";/);assert.match(sidebar,- /\.filter\(\(session\) => !isAutomationSession\(session\)\)/,+ /listableSessions\(sessions\)/,"the sidebar drops automation transcripts before grouping",);const search = await readFile(new URL("../src/hooks/use-session-search.ts", import.meta.url), "utf8");@@ -314,6 +314,15 @@ test("the session list and search both consume the automation predicate", async/state\.hits\.filter\(\(hit\) => !isAutomationSession\(hit\.session\)\)/,"search never offers one as a conversation to open",);+ const palette = await readFile(+ new URL("../src/components/SearchDialog.tsx", import.meta.url),+ "utf8",+ );+ assert.match(+ palette,+ /listableSessions\(q \? search\.hits\.map/,+ "and its empty-query recents list applies the same rule",+ );});test("a run's transcript follows the run, not just its session", async () => {@@ -458,3 +467,29 @@ test("the task column reads one newest run per task, not a global window", asyncconst api = await readFile(new URL("../src/lib/api.ts", import.meta.url), "utf8");assert.match(api, /latestPerTask\?: boolean/);});++test("every session list the user can enter drops a run's transcript", async () => {+ await withVite(async (server) => {+ const origin = await server.ssrLoadModule("/src/lib/session-origin.ts");+ const listed = [+ { id: "plain" },+ { id: "automation", scheduledRun: true },+ { id: "legacy" },+ { id: "explicit-false", scheduledRun: false },+ ];+ assert.deepEqual(+ origin.listableSessions(listed).map((session) => session.id),+ ["plain", "legacy", "explicit-false"],+ "only a run's transcript leaves the list",+ );+ assert.deepEqual(origin.listableSessions([]), []);++ // The tray applies the same rule in the main process, where the renderer's+ // helper cannot be imported; its own test exercises that filter.+ const tray = await readFile(+ new URL("../electron/main/tray-sessions.ts", import.meta.url),+ "utf8",+ );+ assert.match(tray, /trayVisibleSessions\(listed\.sessions\)/);+ });+});diff --git a/apps/desktop/test/tray-session-visibility.test.mjs b/apps/desktop/test/tray-session-visibility.test.mjsnew file mode 100644index 000000000..f607bdc8e--- /dev/null+++ b/apps/desktop/test/tray-session-visibility.test.mjs@@ -0,0 +1,34 @@+import assert from "node:assert/strict";+import test from "node:test";+import { register } from "node:module";+import { dirname, join } from "node:path";+import { fileURLToPath, pathToFileURL } from "node:url";++const here = dirname(fileURLToPath(import.meta.url));+register(pathToFileURL(join(here, "helpers/ts-import-hooks.mjs")));++const { trayVisibleSessions } = await import("../electron/main/tray-sessions.ts");++/** Only the fields the tray reads; the host owns the real payload. */+const session = (id, scheduledRun) => ({+ id,+ title: id,+ mode: "agent",+ updatedAt: "2026-10-02T00:00:00Z",+ ...(scheduledRun === undefined ? {} : { scheduledRun }),+});++test("the tray never offers a scheduled run's transcript", () => {+ const listed = [session("plain"), session("automation", true), session("legacy")];++ assert.deepEqual(+ trayVisibleSessions(listed).map((item) => item.id),+ ["plain", "legacy"],+ "a run's transcript leaves the tray's recents, a legacy summary without the flag stays",+ );+ assert.deepEqual(trayVisibleSessions([]), []);+ assert.equal(+ trayVisibleSessions(listed).some((item) => item.scheduledRun === true),+ false,+ );+});diff --git a/crates/host-core/src/db/migrations.rs b/crates/host-core/src/db/migrations.rsindex ae5cf50b5..f48c2ae3b 100644--- a/crates/host-core/src/db/migrations.rs+++ b/crates/host-core/src/db/migrations.rs@@ -10,6 +10,13 @@ impl Database {"CREATE INDEX IF NOT EXISTS idx_turns_ended_at ON turns(ended_at DESC)",[],);+ // Session summaries and session search both ask whether a run owns a+ // session, so the probe wants an index of the sessions that have one.+ let _ = self.conn.execute(+ "CREATE INDEX IF NOT EXISTS idx_task_runs_session ON task_runs(session_id)+ WHERE session_id IS NOT NULL",+ [],+ );let tx = self.conn.unchecked_transaction()?;tx.execute("UPDATE turnsdiff --git a/docs/spec/03-runtime/04-data-storage.md b/docs/spec/03-runtime/04-data-storage.mdindex 9cca79a90..d43eee94c 100644--- a/docs/spec/03-runtime/04-data-storage.md+++ b/docs/spec/03-runtime/04-data-storage.md@@ -1139,6 +1139,16 @@ combined with `taskId`). The task column reads the second shape. A global windowover `task_runs` can be filled by one busy task — retention keeps the last 100runs *per task* — and would then report an idle task as never run, so the readthat feeds the column is per task rather than a shared window.+Retention keeps the newest 100 runs per task (`TASK_RUNS_KEEP`, applied on every+boot). Ownership is derived from those rows, so a pruned run takes two things+with it: the run leaves the task's history, and its session stops carrying+`scheduledRun`, which returns that transcript to the SessionList and to session+search. A task that runs faster than the kept window — an `interval` task from+five minutes up, an hourly task after roughly four days — reaches that boundary;+replacing the derived marker with a persistent origin is tracked with the rest+of issue #1291.+The task page also reads at most 200 runs per task, the bound+`scheduled.listRuns` enforces for a single task's history.The existing JSON extension stores `schedule: {hour, minute, weekday}`,`intervalMinutes` (5–1440; required by an `interval` cadence and read by no otherone, so a schedule that keeps the field keeps its value), `nextRunAt` (epochdiff --git a/docs/spec/04-ux/01-ui-ia.md b/docs/spec/04-ux/01-ui-ia.mdindex 003f925cf..ff739fa42 100644--- a/docs/spec/04-ux/01-ui-ia.md+++ b/docs/spec/04-ux/01-ui-ia.md@@ -264,8 +264,7 @@ so switching a task between a calendar and an interval loses neither. The columnreports each task's cadence and clock, the outcome of that task's own newest run— read per task from the host, so a task that has been idle while others ran isnever reported as never run — with its duration, and whether it is paused or-running.-whether it is paused or running. The task page shows that task's last run, next+running. The task page shows that task's last run, nextoccurrence, project, permission and model, its instruction behind a disclosure,its own run history newest first (status, start time, duration, stable errorcode), and the transcript of the selected run read in the page through a boundeddiff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex d44f696b3..df3c3076a 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -4144,6 +4144,10 @@ TASKS (2) │ Nightly dependency check [Enabled] [Run now]hours, stored as minutes, refused outside that range). The value rides alongwith every armed cadence, so switching between a calendar and an intervalloses neither, and the row reports the span instead of a clock.+- Ownership is derived, so the two windows are visible: the host keeps the newest+ 100 runs per task and the page reads at most 200, and a run older than either+ leaves both the task's history and its transcript's `scheduledRun` marker. See+ [data storage](../03-runtime/04-data-storage.md) §4.11.- Open conversation is the only action that leaves for the chat route. Ascheduled run's conversation then shows a back row in the chat top bar,labelled with the route and, when the row's own origin is known, the task itdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 210448c34..0a06aab01 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -416,15 +416,16 @@arrows, Home/End, Enter, Escape/Tab and outside dismissal; select hourly without timefields and verify its first occurrence is one hour away; pause/resume; Run nowselect an interval cadence, enter 30 minutes and verify the row states that- span instead of a clock, then switch to a weekly cadence and back to confirm- the value survived; open the edit form and verify the task column and the task- page step aside;- then let one task accumulate more runs than the shared window while another- stays idle, and verify the idle task still reports its own last outcome;- and read the admitted run's transcript inside the task page; open the result- conversation from that page and verify its top bar offers the way back to the- scheduled task; return and confirm the same task and run are still selected;- observe automatic completion; delete the settled task. In a normal Agent+ fields and verify its first occurrence is one hour away; pause/resume; Run now+ and read the admitted run's transcript inside the task page; select an interval+ cadence, enter 30 minutes and verify the row states that span instead of a+ clock, then switch to a weekly cadence and back to confirm the value survived;+ open the edit form and verify the task column and the task page step aside;+ let one task accumulate more runs than the shared window while another stays+ idle, and verify the idle task still reports its own last outcome; open the+ result conversation from that page and verify its top bar offers the way back+ to the scheduled task; return and confirm the same task and run are still+ selected;conversation, use model tool calls to discover, create, list, update to 15:30and delete a task. Verify the custom time appears in the form and survivesrenaming. The model is a local deterministic fixture, not a live provider.diff --git a/docs/zh-CN/spec/03-runtime/04-data-storage.md b/docs/zh-CN/spec/03-runtime/04-data-storage.mdindex edb67d488..80ae42971 100644--- a/docs/zh-CN/spec/03-runtime/04-data-storage.md+++ b/docs/zh-CN/spec/03-runtime/04-data-storage.md@@ -915,9 +915,9 @@ CREATE INDEX idx_task_runs ON task_runs(task_id, started_at DESC);生成会话的运行通过 `session_id` 免费获取其转录本。该转录本通过针对 `task_runs` 的 `EXISTS` 判断被识别为自动化产出,每个会话摘要与搜索命中都以 `scheduledRun` 返回这一归属。归属在读取时派生、不写入会话行:因此在该会话仍属于某次运行时,会话列表与会话搜索会隐藏它;删除任务后它会回到普通列表,而不会变得无法访问(issue #1291)。`scheduled.listRuns` 提供两种形状:单任务自己的历史(`taskId`,最多 200 条)与每任务最新一次运行(`latestPerTask`,每个任务一行,不能与 `taskId` 同时使用)。任务列读取后者:`task_runs` 的全局窗口可能被某个繁忙任务填满(保留策略是按任务各留最近 100 条),那样空闲任务会被误报为「尚未运行」,所以喂给任务列的读取按任务而不是共享窗口。+保留策略按任务各留最近 100 条运行(`TASK_RUNS_KEEP`,每次打开数据库时执行)。归属由这些行派生,因此一条被清理的运行会带走两件事:它从任务历史里消失,其会话也不再带 `scheduledRun`,于是那段转写回到会话列表与全局搜索。运行速度快于保留窗口的任务——`interval` 从 5 分钟起、每小时周期约四天后——会碰到这条边界;用持久化 origin 取代派生标记的改法与 issue #1291 的后续一起跟踪。任务页每次最多读取 200 条运行,这是 `scheduled.listRuns` 对单任务历史的上限。-`config_json` 保存 `schedule: {hour, minute, weekday}`-`workspacePath`、会话模式 `sessionMode`(`perRun` 或 `reuse`,缺失按 `perRun`),以及可选的任务级 `permissionMode` 与成对的 `providerId`/`modelId`。+`config_json` 保存 `schedule: {hour, minute, weekday}`、`intervalMinutes`(5–1440,只有 `interval` 周期读取,因此保留该字段的排程会保留它的值)、毫秒时间戳 `nextRunAt`、`workspacePath`、会话模式 `sessionMode`(`perRun` 或 `reuse`,缺失按 `perRun`),以及可选的任务级 `permissionMode` 与成对的 `providerId`/`modelId`。这些新增字段无需物理表迁移。缺少模型字段时仍在运行时读取应用默认值;缺少权限字段时,自动运行继续使用 Ask,立即运行继续继承全局权限。每天、每周按宿主本地时区计算;每小时与间隔按准入时刻起算的经过时间计算:每小时采用 `nextRunAt = now + 3_600_000`,间隔采用 `nextRunAt = now + intervalMinutes × 60_000`,两者都忽略日历时间字段。`interval` 任务的排程若缺少 `intervalMinutes`,写入会被拒绝,而不是保存成永不触发的任务。可选 `weekdays` 保存 1–7 个不重复的 0–6 整数,覆盖每周的旧 `weekday`;diff --git a/docs/zh-CN/spec/04-ux/01-ui-ia.md b/docs/zh-CN/spec/04-ux/01-ui-ia.mdindex 7f870884f..60917472a 100644--- a/docs/zh-CN/spec/04-ux/01-ui-ia.md+++ b/docs/zh-CN/spec/04-ux/01-ui-ia.md@@ -210,7 +210,7 @@选择及 Escape/外部点击关闭,选项具有选中状态语义。表单打开时独占本页:任务列与任务页面让位,不与草稿争夺空间;间隔值在切换到其他周期时保留,日历与间隔之间来回切换都不会丢失。每天、每周按电脑本地时区计算并显示下次执行时间。-任务列显示每个任务的周期与时间、该任务自己最新一次运行的结果与耗时(逐任务读取,不会因为其他任务的运行挤占窗口而误报「尚未运行」),以及暂停或运行中状态;+任务列显示每个任务的周期与时间、该任务自己最新一次运行的结果与耗时(逐任务读取,不会因为其他任务的运行挤占窗口而误报「尚未运行」),以及暂停或运行中状态;任务页面显示该任务的上次运行、下次执行、项目、权限与模型,指令默认折叠,运行记录只列本任务的运行(状态、开始时间、耗时与稳定错误码,最新在前),并在页内按有界读取展示所选运行的转写。运行的转写属于本页面:会话列表与全局搜索不再列出它,只有“打开会话”这个显式动作才会把它带入对话页,对话顶部栏随后为这段会话提供返回入口(入口标注它所属的任务;返回后仍选中同一个任务与同一次运行,若本页紧邻其后则直接复用导航历史)。侧边栏时钟与全局搜索均可进入。立即运行在后台执行并选中刚准入的那次运行,读者仍停留在本页。应用必须保持运行。每 30 秒检查一次,超过 90 秒的错过时段与重叠运行被跳过;重启只安排未来时段。旧任务需明确保存周期后才自动执行。新任务保存所选项目、Ask 权限和当前默认 provider/model;这些值只属于当前任务。任务文本标为“指令”,项目、权限和模型选择器嵌在指令框底部,并复用主 Composer 的容器、芯片和锚定菜单样式。两处直接共用权限选择组件和支持搜索、服务商分组、能力标记的模型列表。任务的模型按钮只显示模型名或别名,不拼接服务商名称;选择结果只更新任务草稿,不更改当前对话或应用默认设置。指令输入区域使用独立圆角边框及与底栏不同的底色,不显示原生缩放手柄,长文本在输入区内滚动。缺少模型字段的旧任务继续跟随应用默认值,已保存但不可用的模型保留显示且不会被静默替换。选择 Auto 时明确提示受限操作可能无需询问。没有显式选择时,首次设置仍保存当前项目,diff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.mdindex f8806901e..01e1cd469 100644--- a/docs/zh-CN/spec/04-ux/08-component-spec.md+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md@@ -2905,6 +2905,7 @@ Sidebar footer Popover (360px max)- 会话模式决定运行转写的归属:`perRun` 为每次运行新开一段会话;`reuse` 在该任务上一次会话仍存在、且仍属于同一项目时继续使用它。- 表单打开时独占本页:任务列与任务页面不再渲染,草稿不会与它来源的页面争夺空间。- 间隔任务给出数量加分钟或小时单位(5 分钟至 24 小时,以分钟存储,超出范围会被拒绝)。该值随每个已排程周期一并保存,日历与间隔之间来回切换都不会丢失;任务行显示跨度而不是时钟。+- 归属是派生的,因此两个窗口会显现出来:宿主按任务只保留最近 100 条运行,任务页最多读取 200 条;早于任一窗口的运行会同时离开任务历史及其转写的 `scheduledRun` 标记。见 data-storage §4.11。- 「打开会话」是唯一离开本页面进入对话页的动作。定时任务的会话随后在对话顶部栏显示返回行,行上标注目标页面(已知来源时还标注所属任务);返回后恢复同一个任务与同一次运行,若本页紧邻该会话之后则沿导航历史后退。- 宽度大于 900px 时任务列吸附在标题栏下方;更窄时任务列堆叠在页面上方。- 动画仅使用颜色与箭头过渡,并在 `prefers-reduced-motion` 下关闭,包括运行中圆点的脉冲。