Skip to content

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

chore: merge main and resolve PR 402 lifecycle conflicts

zszz3929c9256579a
diff --cc apps/desktop/electron/main/bootstrap/app-lifecycle.ts
index fa6302d1f,685ef4a99..349105fda
--- a/apps/desktop/electron/main/bootstrap/app-lifecycle.ts
+++ b/apps/desktop/electron/main/bootstrap/app-lifecycle.ts
@@@ -9,7 -6,7 +9,8 @@@ import
APP_NAME,
IPC,
isThemeColorScheme,
+ traySessionTitle,
+ migrateKeybindingOverrides,
type AppMenuCommand,
type CloseBehavior,
type KeybindingOverrides,
@@@ -17,9 -14,8 +18,9 @@@
} from "@pi-desktop/shared";
import { catalogs, resolveLocale } from "@pi-desktop/i18n";
import { installApplicationMenu } from "../application-menu";
+import { createTraySessions } from "../tray-sessions";
- import type { HostProcess } from "../host-process";
import { createWindow, type WindowLifecycleState } from "./window";
+ import { windowToggleAction } from "./window-visibility";
import type { BrowserPane } from "../browser-view";
import type { Logger } from "../logger";
import type { PluginRuntime } from "../plugin-runtime";
@@@ -68,10 -66,9 +71,10 @@@ export type ApplicationLifecycleDepende
logger: Pick<Logger, "app">;
refreshReleaseNotes: () => void;
applyPluginLauncherShortcut: (keybindings?: KeybindingOverrides) => void;
- applySummonWindowShortcut: (keybindings?: KeybindingOverrides) => void;
+ applyToggleWindowShortcut: (keybindings?: KeybindingOverrides) => void;
broadcastPluginPanelEvent: (event: string, payload: unknown) => void;
getHost: () => HostProcess | null;
+ getRunningSessionIds: () => Iterable<string>;
};
export function createApplicationLifecycle({
@@@ -102,19 -99,10 +105,19 @@@
logger,
refreshReleaseNotes,
applyPluginLauncherShortcut,
- applySummonWindowShortcut,
+ applyToggleWindowShortcut,
broadcastPluginPanelEvent,
getHost,
+ getRunningSessionIds,
}: ApplicationLifecycleDependencies) {
+ const traySessions = createTraySessions({
+ getHost,
+ getRunningSessionIds,
+ isQuitting: () => state.quitting,
+ onChanged: () => updateTrayMenu(),
+ logger,
+ });
+ let trayActivationGeneration = 0;
function applyDevelopmentBranding() {
if (process.platform !== "darwin" || !isDevelopmentBuild || !app.dock) return;
@@@ -167,56 -155,27 +170,71 @@@
});
}
+ async function activateTraySession(sessionId: string | null) {
+ const generation = ++trayActivationGeneration;
+ await ensureWindow();
+ const window = state.mainWindow;
+ if (!window || window.isDestroyed() || !(await waitForMenuRenderer(window))) return;
+ if (generation !== trayActivationGeneration) return;
+ if (window.isMinimized()) window.restore();
+ window.show();
+ window.focus();
+ if (sessionId) await traySessions.refresh();
+ if (
+ generation !== trayActivationGeneration ||
+ window !== state.mainWindow ||
+ window.isDestroyed()
+ ) return;
+ if (sessionId && !traySessions.canActivate(sessionId)) return;
+ sendToRenderer(IPC.event.traySessionActivated, { sessionId });
+ }
+
+ function dispatchTrayActivation(sessionId: string | null) {
+ void activateTraySession(sessionId).catch((error) => {
+ logger.app("diagnostics", "error", "tray session activation failed", {
+ data: String(error),
+ });
+ });
+ }
+
+ /**
+ * One press of the merged window shortcut (D438): hide the window the user is
+ * looking at, otherwise bring it back. Hiding is `Window.hide()` and never
+ * the close path, so it raises no close-behaviour prompt, destroys no window,
+ * and quits nothing — the tray (or the same key again) is the way back.
+ */
+ function toggleMainWindow() {
+ const window = state.mainWindow;
+ if (window && !window.isDestroyed() && windowToggleAction(window) === "hide") {
+ window.hide();
+ return;
+ }
+ restoreMainWindow();
+ }
+
- function updateTrayMenu(locale = app.getLocale()) {
+ function updateTrayMenu(locale = appearanceState.updaterLocale || app.getLocale()) {
if (!state.tray) return;
- const labels = catalogs[resolveLocale(locale)].tray;
+ const catalog = catalogs[resolveLocale(locale)];
+ const labels = catalog.tray;
+ const template: MenuItemConstructorOptions[] = [
+ { label: labels.open, click: restoreMainWindow },
+ ];
+ for (const group of traySessions.getGroups()) {
+ template.push({ type: "separator" }, { label: labels[group.kind], enabled: false });
+ for (const session of group.sessions) {
+ const title = traySessionTitle(session.title, catalog.chat.untitledTask);
+ template.push({
+ label: process.platform === "darwin" ? title : title.replace(/&/g, "&&"),
+ click: () => dispatchTrayActivation(session.id),
+ });
+ }
+ if (group.hasMore) {
+ template.push({ label: labels.viewMore, click: () => dispatchTrayActivation(null) });
+ }
+ }
state.tray.setContextMenu(
Menu.buildFromTemplate([
- { label: labels.open, click: restoreMainWindow },
+ ...template,
{ type: "separator" },
{ label: labels.quit, click: () => app.quit() },
]),
diff --cc apps/desktop/electron/main/index.ts
index 16f750ba3,36c9085e4..7ae905598
--- a/apps/desktop/electron/main/index.ts
+++ b/apps/desktop/electron/main/index.ts
@@@ -901,8 -901,6 +902,7 @@@ const applicationAppearanceState: Appli
};
applicationLifecycle = createApplicationLifecycle({
- getHost: () => host,
+ getRunningSessionIds: () => activeTurns.keys(),
state: windowLifecycleState,
appState: applicationLifecycleState,
appearanceState: applicationAppearanceState,
diff --cc docs/adr/README.md
index 9d1f2a894,27917774a..5a7d82569
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@@ -293,4 -293,9 +293,10 @@@ Each ADR includes
| session-content-search | [Discover sessions by indexed message text](session-content-search.md) | Accepted |
| transcript-reading-ownership | [Share renderer history and search views](transcript-reading-ownership.md) | Accepted |
| 0266 | [Plugin fs roots follow the calling session](0266-plugin-fs-root-follows-the-calling-session.md) | Accepted (D093) |
+| tray-session-shortcuts | [Bounded session navigation in the native tray](tray-session-shortcuts.md) | Accepted (amends ADR 0078; issue #293) |
+ | 0267 | [Plugin labels follow the app language](0267-plugin-labels-follow-the-app-language.md) | Accepted (amends 0160; ADR 0182) |
+ | 0270 | [Builtin subagents can be switched off](0270-builtin-subagents-can-be-disabled.md) | Accepted for implementation (amends ADR 0063; ADR 0112) |
+ | 0271 | [Rebuild the shared provider transport after repeated unanswered failures](0271-provider-transport-rebuild.md) | Accepted for implementation (issue #234) |
+ | 0269 | [Move capability documents between the global and project levels](0269-capability-level-transfer.md) | Accepted for implementation (amends ADR 0112) |
+ | 0268 | Remove quotes, annotations, and side chats | Accepted (supersedes message-quotes-and-side-chats / response-annotations / floating-annotation-index) |
+ | 0272 | [Judge a public-network address on the route the request will dial](0272-connection-time-public-network-route.md) | Accepted for implementation (amends ADR 0243; issue #419 / PR #473) |
diff --cc docs/spec/06-delivery/04-e2e-test-plan.md
index 2de5cc9b6,3f7b46de5..c9e4a9d87
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@@ -7649,13 -7432,12 +7432,13 @@@ identify the platform validation still
| C / G / Quality — Plugins navigation | E2E-NAV-plugins-button-goes-back |
| B / F / Security — Provider copy | E2E-PROVIDER-copy-config-without-credentials |
| A — App startup | E2E-001, E2E-002, E2E-003, E2E-004, E2E-067, E2E-076, E2E-079, E2E-092, E2E-097, E2E-143, E2E-150, E2E-168, E2E-204 |
+| A / C / F / Quality — Tray session navigation | E2E-TRAY-bounded-session-navigation |
| B — Model config | E2E-005, E2E-006, E2E-007, E2E-038, E2E-050, E2E-052, E2E-055, E2E-066, E2E-080, E2E-082, E2E-102c, E2E-102d, E2E-102e, E2E-151, E2E-154, E2E-163, E2E-166, E2E-172, E2E-174, E2E-197, E2E-005G, E2E-005J, E2E-199, E2E-201, E2E-202, E2E-203, E2E-205, E2E-206, E2E-209 |
- | C — Conversation & stream | E2E-008, E2E-008d, E2E-008a, E2E-009, E2E-010, E2E-011, E2E-011a, E2E-011b, E2E-011d, E2E-011e, E2E-011g, E2E-031, E2E-040, E2E-047, E2E-048, E2E-048A, E2E-049, E2E-052, E2E-053, E2E-054, E2E-055, E2E-059, E2E-059a, E2E-060c, E2E-060d, E2E-061, E2E-061a, E2E-062, E2E-064, E2E-065, E2E-068, E2E-071, E2E-073, E2E-074, E2E-075, E2E-081, E2E-083, E2E-084, E2E-086, E2E-087, E2E-088, E2E-088b, E2E-089, E2E-090, E2E-094, E2E-095, E2E-096, E2E-097, E2E-098, E2E-099, E2E-102, E2E-102a, E2E-102b, E2E-102c, E2E-102d, E2E-102g, E2E-106, E2E-109, E2E-111, E2E-114, E2E-116, E2E-117, E2E-118, E2E-119, E2E-120, E2E-121, E2E-218, E2E-219, E2E-AGENTS-001, E2E-142, E2E-144, E2E-145, E2E-146, E2E-146a, E2E-147, E2E-151, E2E-154, E2E-155, E2E-158, E2E-159, E2E-161, E2E-162, E2E-166, E2E-172, E2E-173, E2E-174, E2E-177, E2E-178, E2E-179, E2E-180, E2E-182, E2E-183, E2E-187, E2E-198, E2E-199, E2E-202, E2E-203, E2E-207, E2E-208, E2E-250, E2E-102i, E2E-PLUGIN-session-orchestrator-real-workers, E2E-SUBAGENT-settlement-updates-before-parent-poll, E2E-CHAT-quote-prefill, E2E-CHAT-side-chat-fork, E2E-CHAT-side-chat-stream, E2E-CHAT-side-chat-add-to-main, E2E-CHAT-side-chat-promote, E2E-CHAT-side-chat-close, E2E-CHAT-selection-markdown, E2E-CHAT-selection-side-chat, E2E-CHAT-annotation-attachments, E2E-CHAT-annotation-session-state, E2E-CHAT-annotation-source-index, E2E-CHAT-annotation-ack-and-steering |
+ | C — Conversation & stream | E2E-008, E2E-008d, E2E-008a, E2E-009, E2E-010, E2E-011, E2E-011a, E2E-011b, E2E-011d, E2E-011e, E2E-011g, E2E-031, E2E-040, E2E-047, E2E-048, E2E-048A, E2E-049, E2E-052, E2E-053, E2E-054, E2E-055, E2E-059, E2E-059a, E2E-060c, E2E-060d, E2E-061, E2E-061a, E2E-062, E2E-064, E2E-065, E2E-068, E2E-071, E2E-073, E2E-074, E2E-075, E2E-081, E2E-083, E2E-084, E2E-086, E2E-087, E2E-088, E2E-088b, E2E-089, E2E-090, E2E-094, E2E-095, E2E-096, E2E-097, E2E-098, E2E-099, E2E-102, E2E-102a, E2E-102b, E2E-102c, E2E-102d, E2E-102g, E2E-106, E2E-109, E2E-111, E2E-114, E2E-116, E2E-117, E2E-118, E2E-119, E2E-120, E2E-121, E2E-218, E2E-219, E2E-AGENTS-001, E2E-142, E2E-144, E2E-145, E2E-146, E2E-146a, E2E-147, E2E-151, E2E-154, E2E-155, E2E-158, E2E-159, E2E-161, E2E-162, E2E-166, E2E-172, E2E-173, E2E-174, E2E-177, E2E-178, E2E-179, E2E-180, E2E-182, E2E-183, E2E-187, E2E-198, E2E-199, E2E-202, E2E-203, E2E-207, E2E-208, E2E-250, E2E-102i, E2E-PLUGIN-session-orchestrator-real-workers, E2E-SUBAGENT-settlement-updates-before-parent-poll |
| D — Workspace | E2E-012, E2E-013, E2E-022B, E2E-024I, E2E-047, E2E-049, E2E-057, E2E-058, E2E-060, E2E-068, E2E-075, E2E-078, E2E-153, E2E-158, E2E-182, E2E-187, E2E-252 |
| D — Workspace (project ordering) | E2E-253 |
- | E — Tools & permissions | E2E-008a, E2E-014, E2E-015, E2E-016, E2E-017, E2E-018, E2E-019, E2E-024I, E2E-024K, E2E-040, E2E-049, E2E-074, E2E-093, E2E-097, E2E-099, E2E-100, E2E-101, E2E-102, E2E-102d, E2E-102e, E2E-102g, E2E-103, E2E-105, E2E-106, E2E-107, E2E-111, E2E-112, E2E-113, E2E-114, E2E-115, E2E-116, E2E-119, E2E-121, E2E-122, E2E-142, E2E-145, E2E-147, E2E-155, E2E-158, E2E-166, E2E-181, E2E-PLUGIN-imported-pi-package-skills, E2E-CHAT-side-chat-stream |
- | F — Persistence | E2E-020, E2E-021, E2E-021a, E2E-036, E2E-037, E2E-038, E2E-040, E2E-042, E2E-047, E2E-048, E2E-051, E2E-054, E2E-056, E2E-061, E2E-062, E2E-064, E2E-066, E2E-068, E2E-071, E2E-072, E2E-073, E2E-082, E2E-084, E2E-096, E2E-098, E2E-102, E2E-102b, E2E-102c, E2E-102d, E2E-102g, E2E-102i, E2E-103, E2E-AGENTS-001, E2E-061a, E2E-073a, E2E-104, E2E-106, E2E-107, E2E-108, E2E-109, E2E-110, E2E-112, E2E-118, E2E-119, E2E-120, E2E-121, E2E-123, E2E-142, E2E-146, E2E-146a, E2E-148, E2E-151, E2E-158, E2E-160, E2E-168, E2E-171, E2E-177, E2E-178, E2E-183, E2E-186, E2E-005J, E2E-PLUGIN-session-orchestrator-real-workers, E2E-CHAT-side-chat-fork, E2E-CHAT-side-chat-promote, E2E-CHAT-side-chat-close, E2E-CHAT-annotation-session-state |
+ | E — Tools & permissions | E2E-008a, E2E-014, E2E-015, E2E-016, E2E-017, E2E-018, E2E-019, E2E-024I, E2E-024K, E2E-040, E2E-049, E2E-074, E2E-093, E2E-097, E2E-099, E2E-100, E2E-101, E2E-102, E2E-102d, E2E-102e, E2E-102g, E2E-103, E2E-105, E2E-106, E2E-107, E2E-111, E2E-112, E2E-113, E2E-114, E2E-115, E2E-116, E2E-119, E2E-121, E2E-122, E2E-142, E2E-145, E2E-147, E2E-155, E2E-158, E2E-166, E2E-181, E2E-PLUGIN-imported-pi-package-skills |
+ | F — Persistence | E2E-020, E2E-021, E2E-021a, E2E-036, E2E-037, E2E-038, E2E-040, E2E-042, E2E-047, E2E-048, E2E-051, E2E-054, E2E-056, E2E-061, E2E-062, E2E-064, E2E-066, E2E-068, E2E-071, E2E-072, E2E-073, E2E-082, E2E-084, E2E-096, E2E-098, E2E-102, E2E-102b, E2E-102c, E2E-102d, E2E-102g, E2E-102i, E2E-103, E2E-AGENTS-001, E2E-061a, E2E-073a, E2E-104, E2E-106, E2E-107, E2E-108, E2E-109, E2E-110, E2E-112, E2E-118, E2E-119, E2E-120, E2E-121, E2E-123, E2E-142, E2E-146, E2E-146a, E2E-148, E2E-151, E2E-158, E2E-160, E2E-168, E2E-171, E2E-177, E2E-178, E2E-183, E2E-186, E2E-005J, E2E-PLUGIN-session-orchestrator-real-workers |
| F — Persistence (project ordering) | E2E-251 |
| G — Plugins | E2E-022, E2E-022A, E2E-022B, E2E-022C, E2E-023, E2E-024, E2E-024B, E2E-024C, E2E-024D, E2E-024E, E2E-024W, E2E-024F, E2E-024G, E2E-024H, E2E-024I, E2E-024J, E2E-024K, E2E-024L, E2E-024M, E2E-024N, E2E-024O, E2E-024P, E2E-025, E2E-026, E2E-105, E2E-117, E2E-120, E2E-122, E2E-123, E2E-024Q, E2E-148, E2E-152, E2E-153, E2E-PLUGIN-imported-pi-package-skills, E2E-PLUGIN-import-extension-installs-dependencies, E2E-PLUGIN-import-extension-reports-missing-dependency, E2E-PLUGIN-global-shortcut-owns-only-its-own-command, E2E-PLUGIN-permission-gate-for-real-time-capabilities, E2E-PLUGIN-background-audio-and-realtime-connection, E2E-PLUGIN-fs-root-follows-the-calling-session |
| H — Diagnostics | E2E-027, E2E-031, E2E-034, E2E-042, E2E-096, E2E-098, E2E-104, E2E-107, E2E-108, E2E-109, E2E-110, E2E-113, E2E-115, E2E-116, E2E-118, E2E-121, E2E-146, E2E-146a, E2E-155, E2E-159, E2E-176, E2E-194, E2E-195 |
diff --cc docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 16744d920,c606e27df..99c051f67
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@@ -7403,46 -7500,31 +7501,74 @@@ runner 会在运行时的隔离临时�
- **里程碑**:M6+
- **状态**:部分自动化(`apps/desktop/test/plugin-fs-session-root.test.mjs`):工具调用在发起会话的项目下写入与读取,面板调用与宿主未跟踪的会话回退到可见工作区,`userSelected` 模式保留选定的目录,窗口不显示任何项目时会话根依然生效。双活会话的桌面旅程与面板步骤为草稿(仅在此表面变化时于具备条件的环境中运行)
+#### E2E-TRAY-bounded-session-navigation
+
+- **Scope**: Native tray groups, hidden/recreated window activation, and unread
+ semantics (issue #293, ADR tray-session-shortcuts).
+- **Preconditions**: At least four running, four unread, and four pinned
+ sessions across two projects; include overlaps, read-latest/older-unread
+ notifications, archived/deleted sessions, an archived project, empty titles,
+ multiline titles, long CJK/emoji titles, and literal ampersands. Also cover
+ a single populated group of seven and one of more than nine, with the other
+ two groups empty, to exercise reclaimed share. Use an
+ isolated profile. Repeat native activation on macOS and Windows/Linux.
+- **Steps**: Hide the main window and open the tray menu. Inspect group order,
+ counts, duplicates, titles, and unchanged unread records. Choose the third
+ row from another project, then View more from Settings with a collapsed
+ sidebar and a retained search query. Finish/abort tasks while hidden;
+ read a result, pin/unpin, rename, archive/restore, and delete a session.
+ Close the macOS window while a task runs and let it finish, then activate
+ its tray row while the new renderer bootstraps a pending plan. Delay a Host
+ read while a newer preference update, delete, or Host restart arrives.
+ Retry a transient read failure by hovering/right-clicking the tray.
+ Repeat after clearing all group memberships and changing shipped locales.
+ Choose Quit then Cancel, then Quit and confirm.
+- **Expected**: Running → Unread → Pinned; at most nine rows in total. Each
+ non-empty group keeps up to three rows and overflowing groups reclaim the
+ share smaller groups leave unused, in priority order: seven running sessions
+ with no unread or pinned show all seven, and a single group holding more than
+ nine shows nine behind View more. Deduplicate before limits, so hidden
+ Running overflow cannot
+ appear as Unread/Pinned. Empty groups and stale shortcuts disappear. Unread
+ uses the latest terminal result per session, newest first. Titles remain
+ one line within the cap, including literal ampersands. Opening the macOS
+ menu leaves the window hidden and records unread. A row opens exactly that
+ session/project, acknowledges it normally, and wins over startup navigation.
+ View more returns from Settings, closes search, and expands session navigation. Hidden/closed windows receive fresh groups;
+ stale reads, archived/deleted targets, and a failed backend cannot restore
+ stale shortcuts. Open, localization, quit cancellation, and shutdown work.
+- **Specs linked**: `03-runtime/01-ipc-protocol.md` §13b,
+ `03-runtime/07-process-model.md`, `04-ux/08-component-spec.md`,
+ `04-ux/09-interaction-patterns.md`, ADR tray-session-shortcuts.
+- **Acceptance**: A (app/window lifecycle), C (conversation navigation),
+ F (unread persistence), Quality (bounded localized menu).
+- **Milestone**: Post-M6 desktop shell maintenance.
+- **Status**: Draft; native E2E requires an explicitly authorized run.
+ #### E2E-MODEL-catalog-window-correction-reaches-saved-bindings:目录修正回流已保存绑定,且不覆盖用户手改值
+
+ - **目标**:models.dev 修正某模型上限后回流到已保存的绑定(不必删除重建),
+ 而用户在设置里手改的数值永不被覆盖。
+ - **步骤**:
+ 1. 配置一个提供商,勾选 models.dev 已发布 `limit.context` 的模型并保存。展开该行的
+ 高级区,读取上下文窗口字段与其提示。
+ 2. 用修正后的目录记录(不同的发布上限)替换该模型记录,重新打开设置,读取该行、
+ 上下文检查器,以及新会话启动时使用的窗口。
+ 3. 在高级区输入窗口——先用预设档位,再手输 `128000`——保存,然后再喂一次目录修正,
+ 重新打开设置与检查器。
+ 4. 保存并重新打开一个绑定不带 `contextWindowSource` 的提供商行:一次使用通用
+ `128000` 种子,一次使用任意其它已存值。
+ - **预期**:步骤 1 显示发布值并带「跟随 models.dev」提示。步骤 2 在所有使用 effective
+ window 的地方(设置行、上下文检查器、会话启动)都显示修正后的值,无需删除重建。
+ 步骤 3 在设置行、检查器和实际请求中都保留用户输入的值,包括在目录窗口更大时手输的
+ `128000`,且提示消失。步骤 4 表现确定:`128000` 种子跟随目录,其它值保持原样。
+ 每一步中标记都能在提供商行的保存/读取往返后保留,早于该标记写出的配置仍可读。
+ - **关联规范**:`03-runtime/13-model-catalog-and-selection.md` §9.1、
+ `03-runtime/12-provider-config-schema.md` §2、
+ `03-runtime/11-provider-model-system.md` §2、`04-ux/06-settings-ia.md` §2
+ - **验收**:B(模型配置)、F(持久化)、Quality
+ - **里程碑**:M6+
+ - **状态**:部分自动化:`apps/desktop/test/model-binding-catalog-source.test.mjs` 驱动
+ 主进程解析(目录来源的修正会到达对外暴露的行、用户值不受修正影响、通用种子仍跟随
+ 目录、继承值保持 `catalog` 标记);`packages/shared/src/model-catalog.test.ts` 覆盖
+ 四条来源规则;`crates/host-core/src/providers/catalog.rs` 覆盖配置往返、无标记记录与
+ 被丢弃的未知标记。端到端的设置旅程与实际启动窗口断言为草稿。
diff --cc packages/shared/src/index.ts
index e8480a993,00916d22b..6382da77a
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@@ -52,6 -52,4 +52,7 @@@ export * from "./trusted-extensions.js"
export * from "./provider-retry.js";
export * from "./message-stream.js";
export * from "./session-collaboration.js";
+export * from "./session-presentation.js";
+export * from "./session-outcomes.js";
+export * from "./tray-sessions.js";
+ export * from "./window-chrome.js";