Skip to content

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

feat(work-panel): open plan and goal artifacts in the bundled file view

Tioit-Wang77767f73acab
diff --git a/apps/desktop/src/components/PlanApprovalBar.tsx b/apps/desktop/src/components/PlanApprovalBar.tsx
index 0e96dcf7c..391dac5a6 100644
--- a/apps/desktop/src/components/PlanApprovalBar.tsx
+++ b/apps/desktop/src/components/PlanApprovalBar.tsx
@@ -7,7 +7,7 @@ import type {
ProposalKind,
} from "@pi-desktop/shared";
import { useAppStore } from "../stores/app-store";
-import { fileWorkPanelTab } from "../lib/work-panel-tabs";
+import { preferredFileWorkPanelTab } from "../lib/work-panel-tabs";
import { PLAN_APPROVAL_DEFAULT_MODE } from "../lib/plan-mode-state";
import {
readPlanApprovalMode,
@@ -56,6 +56,7 @@ export function PlanApprovalBar({ proposal }: { proposal: PlanProposal }) {
const { t } = useTranslation();
const resolvePlan = useAppStore((state) => state.resolvePlan);
const showToast = useAppStore((state) => state.showToast);
+ const pluginViews = useAppStore((state) => state.pluginViews);
const openWorkPanelTabForSession = useAppStore(
(state) => state.openWorkPanelTabForSession,
);
@@ -129,7 +130,7 @@ export function PlanApprovalBar({ proposal }: { proposal: PlanProposal }) {
if (!artifactPath) return;
openWorkPanelTabForSession(
proposal.sessionId,
- fileWorkPanelTab(artifactPath),
+ preferredFileWorkPanelTab(artifactPath, pluginViews),
);
};
diff --git a/apps/desktop/src/hooks/use-preview-target.ts b/apps/desktop/src/hooks/use-preview-target.ts
index 16ea456f5..313487cd6 100644
--- a/apps/desktop/src/hooks/use-preview-target.ts
+++ b/apps/desktop/src/hooks/use-preview-target.ts
@@ -4,7 +4,11 @@ import { useAppStore } from "../stores/app-store";
import { api } from "../lib/api";
import { isHtmlFilePath, toWorkspaceRel, type ChatPreviewTarget } from "../lib/chat-links";
import { openHttpUrl } from "../lib/open-http-url";
-import { FILE_MANAGER_PLUGIN_TAB, fileManagerPluginTab } from "../lib/work-panel-tabs";
+import {
+ FILE_MANAGER_PLUGIN_TAB,
+ fileManagerPluginTab,
+ hasPluginView,
+} from "../lib/work-panel-tabs";
/**
* Open one target the transcript named.
@@ -62,12 +66,7 @@ export function useOpenChatFileRef() {
const showToast = useAppStore((s) => s.showToast);
const fileViewAvailable = useMemo(
- () =>
- pluginViews.some(
- (view) =>
- view.pluginId === FILE_MANAGER_PLUGIN_TAB.pluginId &&
- view.viewId === FILE_MANAGER_PLUGIN_TAB.viewId,
- ),
+ () => hasPluginView(pluginViews, FILE_MANAGER_PLUGIN_TAB),
[pluginViews],
);
diff --git a/apps/desktop/src/lib/work-panel-tabs.ts b/apps/desktop/src/lib/work-panel-tabs.ts
index 5f1266c23..d38e56d26 100644
--- a/apps/desktop/src/lib/work-panel-tabs.ts
+++ b/apps/desktop/src/lib/work-panel-tabs.ts
@@ -129,6 +129,35 @@ export function fileManagerPluginTab(location: string): WorkPanelTab {
};
}
+/** The identity of one plugin-contributed view, as tabs and manifests key it. */
+export type PluginViewRef = { pluginId: string; viewId: string };
+
+/** Whether that view is currently launchable in the work panel. */
+export function hasPluginView(
+ views: readonly PluginViewRef[],
+ target: PluginViewRef,
+): boolean {
+ return views.some(
+ (view) => view.pluginId === target.pluginId && view.viewId === target.viewId,
+ );
+}
+
+/**
+ * The tab the host opens a project file in when the host, not the user, chose
+ * the file: the bundled file view whenever it is launchable, and the host file
+ * tab otherwise — the same preference and fallback a chat file reference
+ * already uses, so a plan or goal artifact lands where the user's other file
+ * work lives. The bundle is never required: an absent view leaves the host tab.
+ */
+export function preferredFileWorkPanelTab(
+ path: string,
+ pluginViews: readonly PluginViewRef[],
+): WorkPanelTab {
+ return hasPluginView(pluginViews, FILE_MANAGER_PLUGIN_TAB)
+ ? fileManagerPluginTab(path)
+ : fileWorkPanelTab(path);
+}
+
export function parsePluginViewRef(
resource: string | undefined,
): { pluginId: string; viewId: string } | null {
diff --git a/apps/desktop/src/stores/app-store.ts b/apps/desktop/src/stores/app-store.ts
index 72fb489cf..e7965b6be 100644
--- a/apps/desktop/src/stores/app-store.ts
+++ b/apps/desktop/src/stores/app-store.ts
@@ -101,7 +101,7 @@ import {
import { settleStoppedAssistantMetrics } from "../lib/context-usage";
import { formatToolValue } from "../lib/tool-display";
import { withReviewChangeState } from "../lib/workspace-review";
-import { fileWorkPanelTab } from "../lib/work-panel-tabs";
+import { preferredFileWorkPanelTab } from "../lib/work-panel-tabs";
import {
clearSessionPermissions,
enqueuePermission,
@@ -312,12 +312,13 @@ export type AppState = import("./app-state").AppState;
function openPlanArtifact(
proposal: PlanProposal,
openWorkPanelTabForSession: AppState["openWorkPanelTabForSession"],
+ pluginViews: AppState["pluginViews"],
) {
const relativePath = proposal.artifact?.relativePath;
if (!relativePath) return;
openWorkPanelTabForSession(
proposal.sessionId,
- fileWorkPanelTab(relativePath),
+ preferredFileWorkPanelTab(relativePath, pluginViews),
);
}
@@ -672,7 +673,11 @@ export const useAppStore = create<AppState>((set, get) => {
sessionOutcomes: latestSessionOutcomes(notifications.notifications),
});
for (const proposal of activePendingPlans) {
- openPlanArtifact(proposal, get().openWorkPanelTabForSession);
+ openPlanArtifact(
+ proposal,
+ get().openWorkPanelTabForSession,
+ get().pluginViews,
+ );
}
saveSidebarPreferences(preferencesFromState(get()));
if (currentWorkspace?.path) {
diff --git a/apps/desktop/src/stores/slices/events-slice.ts b/apps/desktop/src/stores/slices/events-slice.ts
index 9a8d9bca3..45de6fd00 100644
--- a/apps/desktop/src/stores/slices/events-slice.ts
+++ b/apps/desktop/src/stores/slices/events-slice.ts
@@ -40,6 +40,7 @@ export type EventsSliceDependencies = StoreAccess & {
openPlanArtifact: (
proposal: NonNullable<AppState["pendingPlans"][string]>,
openWorkPanelTabForSession: AppState["openWorkPanelTabForSession"],
+ pluginViews: AppState["pluginViews"],
) => void;
notifyInteractivePrompt: (
sessionId: string,
@@ -133,7 +134,11 @@ export function createEventsSlice({
});
const checkpoint = get().planCheckpoints[event.sessionId];
if (event.state === "awaiting_approval" && isPendingPlan(checkpoint)) {
- openPlanArtifact(checkpoint, get().openWorkPanelTabForSession);
+ openPlanArtifact(
+ checkpoint,
+ get().openWorkPanelTabForSession,
+ get().pluginViews,
+ );
}
if (event.state === "awaiting_approval" && !event.proposal) {
void get().restorePendingPlan(event.sessionId);
@@ -327,7 +332,11 @@ export function createEventsSlice({
if (event.state === "awaiting_approval") {
const checkpoint = get().planCheckpoints[envelope.sessionId];
if (isPendingPlan(checkpoint)) {
- openPlanArtifact(checkpoint, get().openWorkPanelTabForSession);
+ openPlanArtifact(
+ checkpoint,
+ get().openWorkPanelTabForSession,
+ get().pluginViews,
+ );
}
void get().restorePendingPlan(envelope.sessionId);
notifyInteractivePrompt(envelope.sessionId, "plan");
diff --git a/apps/desktop/src/stores/slices/session-slice.ts b/apps/desktop/src/stores/slices/session-slice.ts
index 7af59e84c..e5901c1f0 100644
--- a/apps/desktop/src/stores/slices/session-slice.ts
+++ b/apps/desktop/src/stores/slices/session-slice.ts
@@ -68,6 +68,7 @@ export type SessionSliceDependencies = StoreAccess & {
openPlanArtifact: (
proposal: PlanProposal,
openWorkPanelTabForSession: AppState["openWorkPanelTabForSession"],
+ pluginViews: AppState["pluginViews"],
) => void;
rememberSessionCompactions: (
sessionId: string,
@@ -196,7 +197,11 @@ export function createSessionSlice({
),
}));
if (checkpoint && activeProposal) {
- openPlanArtifact(checkpoint, get().openWorkPanelTabForSession);
+ openPlanArtifact(
+ checkpoint,
+ get().openWorkPanelTabForSession,
+ get().pluginViews,
+ );
}
return activeProposal ? "pending" : "terminal";
} catch {
diff --git a/apps/desktop/test/plan-approval-settings.test.mjs b/apps/desktop/test/plan-approval-settings.test.mjs
index 796761690..c4cda21d2 100644
--- a/apps/desktop/test/plan-approval-settings.test.mjs
+++ b/apps/desktop/test/plan-approval-settings.test.mjs
@@ -32,7 +32,10 @@ const interactionSource = readStoreModuleSync("slices/interaction-slice.ts");
test("plan approval exposes only the artifact and remembers the selected mode", () => {
assert.match(approvalBar, /proposal\.title/);
- assert.match(approvalBar, /fileWorkPanelTab\(artifactPath\)/);
+ assert.match(
+ approvalBar,
+ /preferredFileWorkPanelTab\(artifactPath, pluginViews\)/,
+ );
assert.match(approvalBar, /openWorkPanelTabForSession/);
assert.match(approvalBar, /const isPending = proposal\.status === "pending"/);
assert.match(approvalBar, /PLAN_APPROVAL_DEFAULT_MODE/);
diff --git a/apps/desktop/test/plan-mode-source-contract.test.mjs b/apps/desktop/test/plan-mode-source-contract.test.mjs
index 7a114b7bb..e9b93cb19 100644
--- a/apps/desktop/test/plan-mode-source-contract.test.mjs
+++ b/apps/desktop/test/plan-mode-source-contract.test.mjs
@@ -166,7 +166,10 @@ test("plan approval sends exact identities and waits for host confirmation", ()
assert.doesNotMatch(transcriptSource, /PlanApprovalCard|plan-approval-card/);
assert.doesNotMatch(transcriptSource, /\bpendingPlan\b/);
assert.match(storeSource, /openPlanArtifact/);
- assert.match(storeSource, /fileWorkPanelTab\(relativePath\)/);
+ assert.match(
+ storeSource,
+ /preferredFileWorkPanelTab\(relativePath, pluginViews\)/,
+ );
assert.match(barSource, /const isPending = proposal\.status === "pending"/);
const resolveBlock = interactionSource.slice(interactionSource.indexOf("resolvePlan: async"));
assert.match(resolveBlock, /await api\.resolvePlan\(resolution\)/);
diff --git a/apps/desktop/test/work-panel-tabs.test.mjs b/apps/desktop/test/work-panel-tabs.test.mjs
index 2a2121b39..a2313d920 100644
--- a/apps/desktop/test/work-panel-tabs.test.mjs
+++ b/apps/desktop/test/work-panel-tabs.test.mjs
@@ -2,17 +2,20 @@ import assert from "node:assert/strict";
import test from "node:test";
const {
+ FILE_MANAGER_PLUGIN_TAB,
activateWorkPanelTabState,
browserPluginTab,
closeWorkPanelTabState,
emptyWorkPanelContext,
fileWorkPanelTab,
+ hasPluginView,
isKnownWorkPanelTab,
isToolWorkPanelTab,
normalizeWorkPanelFilePath,
newWorkPanelTab,
openWorkPanelTabState,
pluginWorkPanelTab,
+ preferredFileWorkPanelTab,
replaceWorkPanelTabState,
sanitizeWorkPanelTabsState,
switchWorkPanelContextState,
@@ -139,6 +142,30 @@ test("only plugin views are launchable tools", () => {
assert.equal(isKnownWorkPanelTab(newWorkPanelTab()), true);
});
+test("a host-chosen project file prefers the bundled file view", () => {
+ // A plan or goal artifact is project markdown the host opens for the user, so
+ // it lands in the same view the user's own file work uses. The bundle is
+ // never required: without that view the host file tab remains.
+ const fileView = { pluginId: "pi.file-manager", viewId: "manager" };
+ const openedInView = preferredFileWorkPanelTab("plans/plan.md", [fileView]);
+
+ assert.equal(hasPluginView([fileView], FILE_MANAGER_PLUGIN_TAB), true);
+ assert.equal(
+ hasPluginView(
+ [{ pluginId: "pi.browser", viewId: "browser" }],
+ FILE_MANAGER_PLUGIN_TAB,
+ ),
+ false,
+ );
+ assert.equal(openedInView.kind, "plugin");
+ assert.equal(openedInView.id, "plugin:pi.file-manager/manager");
+ assert.equal(openedInView.location, "plans/plan.md");
+ assert.deepEqual(
+ preferredFileWorkPanelTab("plans/plan.md", []),
+ fileWorkPanelTab("plans/plan.md"),
+ );
+});
+
test("empty work panel context has no visible or retained resource state", () => {
assert.deepEqual(emptyWorkPanelContext(), {
open: false,
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index ce34a8ad2..a5de73b71 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -1019,6 +1019,9 @@ entirely inside the plugin's isolated page:
context the viewport-fixed toggle and `Cmd/Ctrl + J` reveal, so a successful
workspace Write/Edit cannot open, activate, or resize the panel in any
session.
+ The plan/goal approval artifact still creates or activates a tab in its
+ originating session, but the host picks its surface: the bundled file view when
+ that view is launchable, otherwise the host file tab (D452).
The viewport-fixed toggle and `Cmd/Ctrl + J` both toggle the active session's
retained panel context: they reveal the panel without creating a resource and
collapse the visible panel without deleting one. With no active session the
@@ -2386,10 +2389,12 @@ execution permission mode, not an individual tool call.
### 10A.2 Content
The card renders the structured title and an opener for the exact
-`.pi/<kind>/*.md` path. Opening the artifact reads the host-written file;
-renderer edits do not change the approved bytes. The submitted question/
-description, status, validity/deadline, inline Markdown, SHA-256, byte size,
-and revision/feedback controls are not rendered card content.
+`.pi/<kind>/*.md` path; the opener prefers the bundled file view and falls back
+to the host file tab when that view is not launchable (D452). Opening the
+artifact reads the host-written file; renderer edits do not change the approved
+bytes. The submitted question/description, status, validity/deadline, inline
+Markdown, SHA-256, byte size, and revision/feedback controls are not rendered
+card content.
### 10A.3 Actions and states
diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.md
index 3794d530d..20b6166f3 100644
--- a/docs/spec/04-ux/09-interaction-patterns.md
+++ b/docs/spec/04-ux/09-interaction-patterns.md
@@ -854,6 +854,9 @@ Agent calls a permission-gated tool (including Plan/Goal Bash under Ask or Accep
`.pi/plan/*.md` or `.pi/goal/*.md` artifact, records its path/hash/size and structured
title/question, and the renderer displays the shared contract approval card with
only the title and artifact opener; the question remains host-side contract data.
+ The opener hands that path to the bundled file view when it is launchable and to
+ the host file tab otherwise, so the artifact opens beside the conversation in the
+ same view the user's other project files use (D452).
4. Approve requires Ask / Accept edits / Auto selection. The renderer remembers
the last selected mode on this device and uses it as the next approval's
default. Host-core commits the approval, `mode = agent`, permission mode,
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 42899fe0d..d8dc0812c 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -5444,7 +5444,9 @@ identify the platform validation still needed.
unique artifact, records its relative path/hash/size with structured
title/question, and never lets the renderer or sidecar write or replace it.
The title-derived artifact filename is recognizable from the title, including
- non-ASCII title characters. The card shows the title and opens the artifact;
+ non-ASCII title characters. The card shows the title and opens the artifact in
+ the bundled file view, falling back to the host file tab when that view is
+ absent (D452);
it does not require inline question/Markdown/hash/size or a validity/deadline
indicator. The selected approval mode is remembered locally for the next
approval.
diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.md
index 5daefa366..5e32ac87b 100644
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@ -25,6 +25,7 @@ This log freezes previously open questions into concrete decisions.
| D447 | Headless runtime boundary | **Amend ADR 0205 rollout R2 prerequisites (ADR 0284): the Electron-independent runtime layer under the Agent Host module lives in `packages/host-runtime` — the host-core and sidecar stdio transports, the restart supervisor (process-model §4 policy), the durable turn lifecycle (`RuntimeService` as the module's `RuntimePort`: `session.beginTurn` → user row → prompt → `session.endTurn`, abort lock, stale-terminal guard, single-flight finalization), transcript persistence with the D299 checkpoint, a headless launch resolver over host-core's own registries, approved Plan/Goal dispatch (D189), and the host-core adapters for `SessionPort` / `QueueStore` / `permissions.pending`. Electron main keeps thin adapters (binary and bundle locations, `ELECTRON_RUN_AS_NODE`, redacted stderr, schema/glibc diagnoses, renderer status pushes) and its own local prompt path. `TurnStartRequest` gains an optional `userMessageId`. No IPC, sidecar, host-core, Plugin SDK, default, or persisted-data change.** | `pi-host` must run the same lifecycle invariants as the desktop without Electron; a second implementation of abort locks, stale terminal events, and queue release after durable settlement would drift from the one the desktop already fixed |
| D448 | RACP-WS transport and device pairing | **Amend ADR 0205 rollout R2 (ADR 0285): `packages/racp` holds both ends of the normative `RACP-WS` binding. `RacpServer` dispatches every catalog operation through its role rule onto the Agent Host module and a `RacpHostOperations` interface the Host implements; `RacpClient` correlates requests, answers server-initiated requests, tracks the last durable cursor per session, reconnects with bounded backoff, and fails the dropped connection's in-flight calls with `HOST_DISCONNECTED` instead of re-sending them. Authentication is the header profile with Host-issued `pdt1.` device tokens and single-use, expiring `ppt1.` pairing tokens (hashed, constant-time compared; never in a URL); `connection/pair` mints an `owner` device. `connection/pair`, `project/register`, `project/browse`, `server.hostId`, the `events/closed` notification, and the codes `PAIRING_FAILED`, `PAIRING_TOKEN_EXPIRED`, `CAPABILITY_UNAVAILABLE`, `REMOTE_PATH_NOT_FOUND`, `REMOTE_PATH_FORBIDDEN`, `HOST_DISCONNECTED`, `HOST_BOOTSTRAP_FAILED`, `HOST_VERSION_MISMATCH`, `REMOTE_AUTH_FAILED`, `REMOTE_CONNECTION_FAILED`, `REMOTE_FORWARD_FAILED` join the contract (spec §14a). The bind refuses non-loopback addresses; attachments and the tool relay are advertised unavailable.** | The SSH-tunnel topology needs a server `pi-host` can bind and a client the desktop can run, with the pairing the security spec describes; the conformance behaviors that need no machine boundary become package tests |
| D451 | Review opens only on explicit user action | **A tool result never opens, activates, or resizes the work panel. The `tool_end` artifact gate and `shouldOpenReviewArtifact` are removed; Review is reached only from the `+` New launcher row or from the retained session context the viewport-fixed toggle / `Cmd/Ctrl + J` reveals. A successful workspace Write/Edit still records its message-owned inline review card in the transcript.** | An agent edit silently revealing a side panel competes with the user's own reading and layout, and the transcript card already carries the change evidence. See ADR 0043, `04-ux/01-ui-ia.md`, `04-ux/08-component-spec.md` §5, `04-ux/09-interaction-patterns.md`, E2E-057. |
+| D452 | Plan and goal artifacts open in the bundled file view | **The contract approval card's artifact opener hands the immutable `.pi/plan/*.md` or `.pi/goal/*.md` path to the bundled `pi.file-manager` view whenever that view is launchable, and to the host file tab otherwise — the same preference and fallback a chat file reference already uses (ADR 0241). The artifact still creates or activates a tab in its originating session, so the approval reveal itself is unchanged; only the surface changes. Renderer-only; no protocol, host, storage, artifact-content, or permission change. See D189, ADR 0043, `04-ux/08-component-spec.md` §5.4 and §10A.2, `04-ux/09-interaction-patterns.md` §5A, E2E-106.** | The approval opener used a host file tab while every other project file the conversation names already opens in the user's own file view, so a plan or goal landed in the one surface the user does not browse project files in. |
| D450 | Signed macOS GitHub Releases | **Amend D078 / ADR 0022: GitHub tag releases Developer ID-sign, notarize (`notarytool` via electron-builder 26), staple, and Gatekeeper-verify macOS DMG/ZIP before upload, using identity `Developer ID Application: XingYu Liu (DUV63RKYTW)` / team `DUV63RKYTW` from Actions secrets (`CSC_LINK`, `CSC_KEY_PASSWORD`, `APPLE_ID`, `APPLE_APP_SPECIFIC_PASSWORD`, `APPLE_TEAM_ID`). Missing secrets fail the job. Local unsigned packaging without a certificate remains. `workflow_dispatch` may set `sign_macos: false` only for unsigned debug artifacts. Packaged macOS uses in-app `electron-updater` (ZIP + merged `latest-mac.yml`); Linux deb/rpm and Windows portable stay notify-and-link. No afterPack/afterSign adhoc codesign (ADR 0278).** | Production DMGs must open without a Gatekeeper warning, and signed macOS installs can download and restart into a new tag. See ADR 0289, E2E-196c, E2E-067A. |
## B. Secondary implementation defaults