Skip to content

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

fix(desktop): repair merged PR integration

vastsafb009d2d192d
diff --git a/apps/desktop/electron/main/bootstrap/main-state.ts b/apps/desktop/electron/main/bootstrap/main-state.ts
index 134969305..6fae3582b 100644
--- a/apps/desktop/electron/main/bootstrap/main-state.ts
+++ b/apps/desktop/electron/main/bootstrap/main-state.ts
@@ -3,10 +3,12 @@ import { nativeTheme } from "electron";
import type {
AppMenuCommand,
CloseBehavior,
- WindowBounds,
- WorkPanelReservationState,
} from "@pi-desktop/shared";
-import { emptyWorkPanelReservationState } from "../work-panel-window";
+import {
+ emptyWorkPanelReservationState,
+ type WindowBounds,
+ type WorkPanelReservationState,
+} from "../work-panel-window";
import type { WindowLifecycleState } from "./window";
import type { LauncherState } from "./launcher";
import type { RuntimeState } from "../runtime/context";
diff --git a/apps/desktop/electron/main/chat-ref-resolve.ts b/apps/desktop/electron/main/chat-ref-resolve.ts
index 037cef8a9..10fe041e9 100644
--- a/apps/desktop/electron/main/chat-ref-resolve.ts
+++ b/apps/desktop/electron/main/chat-ref-resolve.ts
@@ -275,6 +275,9 @@ export async function resolveChatFileRef(
const rootList = orderedRoots(roots);
if (rootList.length === 0) return null;
+ const cleanedPosixRef = toPosix(cleanRef(ref));
+ const isAttachmentRef = /^attachments(?:\/|$)/i.test(cleanedPosixRef);
+
// 1. An absolute reference that already names a real path inside a known root
// is unambiguous evidence, so it outranks every shorthand rule below. A
// POSIX-style path on Windows finds nothing here, which is correct: step 2
@@ -300,10 +303,11 @@ export async function resolveChatFileRef(
// filesystem path: it names a stored blob by hash, and the files-tab
// contract spells it that way. Resolve it against the attachment root
// directly instead of searching for a path that cannot exist.
- if (isAttachmentBlobRef(ref)) {
+ if (isAttachmentRef) {
+ if (!isAttachmentBlobRef(cleanedPosixRef)) return null;
const attachmentsRoot = roots.attachments;
if (!attachmentsRoot) return null;
- const blobHash = segmentsOf(cleanRef(ref)).at(-1);
+ const blobHash = segmentsOf(cleanedPosixRef).at(-1);
if (!blobHash || !ATTACHMENT_HASH_PATTERN.test(blobHash)) return null;
const resolvedRoot = resolve(attachmentsRoot);
const absolutePath = join(resolvedRoot, blobHash.toLowerCase());
diff --git a/apps/desktop/electron/main/index.ts b/apps/desktop/electron/main/index.ts
index 4c70a6695..034e6fb14 100644
--- a/apps/desktop/electron/main/index.ts
+++ b/apps/desktop/electron/main/index.ts
@@ -372,8 +372,9 @@ const modelsDevCatalog = new ModelsDevCatalog({
const vendorOAuth = new VendorOAuth({
call: <T,>(method: string, params?: unknown): Promise<T> => {
- if (!host) throw new Error("host unavailable");
- return host.call<T>(method, params);
+ const currentHost = getHost();
+ if (!currentHost) throw new Error("host unavailable");
+ return currentHost.call<T>(method, params);
},
emit: (event) => sendToRenderer(IPC.event.providersOauth, event),
openExternal: async (url) => {
@@ -642,7 +643,7 @@ const {
wirePluginThemeRuntimeServices({
plugins,
- getHost: () => host,
+ getHost,
sendToRenderer,
applyAppThemePreference,
broadcastAppearance,
@@ -651,7 +652,7 @@ wirePluginThemeRuntimeServices({
closeBehaviorRuntime = createCloseBehaviorRuntime({
state: windowLifecycleState,
dataDir,
- getLocale: () => updaterLocale,
+ getLocale: () => mainState.updaterLocale,
createTray,
});
const {
@@ -664,7 +665,7 @@ const createdLauncher = createLauncher({
state: windowLifecycleState,
launcherState,
appState: applicationLifecycleState,
- getHost: () => host,
+ getHost,
logger,
safeOpenExternal,
toggleMainWindow,
@@ -768,7 +769,7 @@ const sessionCollaboration = createSessionCollaborationService({
return persistenceOutbox.size() === 0;
},
isPluginLoaded: (pluginId) => plugins.listLoaded().some((plugin) => plugin.manifest.id === pluginId),
- isQuitting: () => quitting,
+ isQuitting: () => mainState.quitting,
onChanged: () => sendToRenderer(IPC.event.sessionsChanged, { reason: "session.collaboration" }),
log: (message, data) => logger.app("runtime", "warn", message, { data }),
});
@@ -794,7 +795,7 @@ const planRuntime = createPlanRuntime({
emitAgentEvent: (envelope) => emitAgentEvent(envelope),
acquireSessionOperation,
resolveAgentRuntimeLaunch,
- isQuitting: () => quitting,
+ isQuitting: () => mainState.quitting,
onTurnSettled: sessionCollaboration.settle,
});
const {
@@ -1074,7 +1075,7 @@ registerShutdownHandlers({
registerApplicationActivation({
restoreMainWindow,
- isQuitting: () => quitting,
+ isQuitting: () => mainState.quitting,
isApplicationBooted: () => applicationLifecycleState.applicationBooted,
hasVisibleWindow,
});
diff --git a/apps/desktop/electron/main/remote/pi-host-bootstrap-script.ts b/apps/desktop/electron/main/remote/pi-host-bootstrap-script.ts
index 29ee8daa3..e2a380ffb 100644
--- a/apps/desktop/electron/main/remote/pi-host-bootstrap-script.ts
+++ b/apps/desktop/electron/main/remote/pi-host-bootstrap-script.ts
@@ -105,7 +105,7 @@ node_major=$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || printf
work="$HOME/.pi-desktop/pi-host/.bootstrap"
mkdir -p "$work"
-chmod 700 "$work" 2>/dev/null || true
+chmod 700 "$work" 2>/dev/null || die "bootstrap-permissions"
log="$work/pi-host.log"
err="$work/pi-host.err"
pidfile="$work/pi-host.pid"
@@ -127,7 +127,7 @@ http_get() {
tarball="$work/$ARTIFACT_NAME"
rm -f "$tarball"
http_get "$ARTIFACT_URL" "$tarball" || die "download-failed"
-chmod 600 "$tarball" 2>/dev/null || true
+chmod 600 "$tarball" 2>/dev/null || die "artifact-permissions"
# --- verify the published digest ------------------------------------------
step "verify"
diff --git a/apps/desktop/src/stores/app-store.ts b/apps/desktop/src/stores/app-store.ts
index c0f42ca93..a632c7ca1 100644
--- a/apps/desktop/src/stores/app-store.ts
+++ b/apps/desktop/src/stores/app-store.ts
@@ -3,9 +3,7 @@ import i18n from "i18next";
import type {
AgentEventEnvelope,
AgentStatus,
- AgentPromptAttachment,
AskToolResolution,
- AppError,
AppNotification,
AppSettings,
AppVersionInfo,
@@ -14,7 +12,6 @@ import type {
ModelInfo,
OnboardingState,
Mode,
- PlanProposal,
PlanResolveRequest,
PlanResolutionResult,
PlanningState,
@@ -24,19 +21,16 @@ import type {
PluginViewMeta,
PermissionMode,
ProjectWorkspace,
- ProposalKind,
ProviderPublic,
ReviewRollbackResult,
SessionDetail,
SessionSummary,
ThinkingLevel,
- UiMessage,
} from "@pi-desktop/shared";
import {
contextCompactionMark,
ErrorCodes as SharedErrorCodes,
initialThinkingLevelForBinding,
- modeForProposalKind,
migrateKeybindingOverrides,
modelIdsMatch,
normalizeMode,
@@ -68,7 +62,6 @@ import {
releaseSessionPane,
retainSessionPane,
} from "../lib/session-panes";
-import { normalizeProjectPath, sessionMatchesProject } from "../lib/sidebar-session-groups";
import {
dedupeSessionMessages,
mergeLiveSessionMessages,
@@ -88,20 +81,15 @@ import {
projectIsPinned,
projectWorkspaceFromPath,
saveSidebarPreferences,
- sessionIsArchived,
- sessionIsPinned,
sortProjects,
sortSessions,
normalizeProjectName,
- type ProjectMeta,
type ProjectSort,
- type SessionMeta,
type SessionSort,
} from "../lib/sidebar-preferences";
import { settleStoppedAssistantMetrics } from "../lib/context-usage";
import { formatToolValue } from "../lib/tool-display";
import { withReviewChangeState } from "../lib/workspace-review";
-import { preferredFileWorkPanelTab } from "../lib/work-panel-tabs";
import {
clearSessionPermissions,
enqueuePermission,
@@ -132,7 +120,6 @@ import {
} from "../lib/plan-mode-state";
import {
resolveComposerSmartStop,
- type ComposerDraftSnapshot,
type ComposerPrefill,
} from "../lib/composer-smart-stop";
import {
@@ -207,43 +194,9 @@ export { isDefaultSessionTitle } from "./runtime/session-title-runtime";
export type { WorkPanelTab } from "../lib/work-panel-tabs";
-function promptAttachmentsFromDraft(
- references: ComposerDraftSnapshot["fileReferences"],
-): AgentPromptAttachment[] {
- return references.flatMap((reference) => {
- const kind =
- reference.kind ??
- (/\.(avif|bmp|gif|heic|jpe?g|png|tiff?|webp)$/i.test(reference.path)
- ? "image"
- : "file");
- // Inline chips use tokens for both files and images. Ordinary file chips
- // already serialize to @path text (the model can Read them); only image
- // chips need the structured transport for vision/fallback handling.
- if (reference.token && kind !== "image") return [];
- return [
- {
- path: reference.path,
- name: reference.name,
- kind,
- ...(reference.mimeType ? { mimeType: reference.mimeType } : {}),
- },
- ];
- });
-}
-
-function promptAttachmentsFromMessage(
- attachments: UiMessage["attachments"],
-): AgentPromptAttachment[] {
- return (attachments ?? []).map((attachment) => ({
- path: attachment.ref,
- name: attachment.name,
- kind: attachment.kind,
- ...(attachment.mimeType ? { mimeType: attachment.mimeType } : {}),
- ...(attachment.size !== undefined ? { size: attachment.size } : {}),
- }));
-}
-
import {
+ promptAttachmentsFromDraft,
+ promptAttachmentsFromMessage,
withoutRecordKey,
viewingSessionIdForPrompt,
messageErrorFromUnknown,
diff --git a/apps/desktop/test/auto-update.test.mjs b/apps/desktop/test/auto-update.test.mjs
index c4da00763..5593e8eef 100644
--- a/apps/desktop/test/auto-update.test.mjs
+++ b/apps/desktop/test/auto-update.test.mjs
@@ -305,7 +305,7 @@ test("shared shipped-locale changelog is the in-app notes source of truth", () =
assert.match(changelogSource, /version: "0\.2\.7"/);
assert.match(
mainSource,
- /getLocale:\s*\(\)\s*=>\s*updaterLocale/,
+ /getLocale:\s*\(\)\s*=>\s*(?:updaterLocale|mainState\.updaterLocale)/,
"Main supplies product locale to the updater for note selection",
);
assert.match(mainSource, /updater\.refreshReleaseNotes\(\)/);
diff --git a/apps/desktop/test/chat-ref-resolve.test.mjs b/apps/desktop/test/chat-ref-resolve.test.mjs
index 21aa5bada..fe4750a65 100644
--- a/apps/desktop/test/chat-ref-resolve.test.mjs
+++ b/apps/desktop/test/chat-ref-resolve.test.mjs
@@ -187,6 +187,10 @@ test("an attachment blob reference rejects invalid hash formats or non-hex chara
await resolve("attachments/not-a-valid-sha256", { attachments }),
null,
);
+ assert.equal(
+ await resolve("Attachments/not-a-valid-sha256", { attachments }),
+ null,
+ );
assert.equal(
await resolve(`attachments/${"z".repeat(64)}`, { attachments }),
null,
diff --git a/apps/desktop/test/close-behavior-tray.test.mjs b/apps/desktop/test/close-behavior-tray.test.mjs
index e66724761..95242fc31 100644
--- a/apps/desktop/test/close-behavior-tray.test.mjs
+++ b/apps/desktop/test/close-behavior-tray.test.mjs
@@ -89,7 +89,7 @@ test("permission to close does not leak into the next window", () => {
assert.doesNotMatch(mainSource, /let allowWindowClose\b/);
assert.match(
mainSource,
- /const windowsAllowedToClose = new WeakSet<BrowserWindow>\(\)/,
+ /(?:const|readonly)\s+windowsAllowedToClose = new WeakSet<BrowserWindow>\(\)/,
);
assert.match(mainSource, /windowsAllowedToClose\.has\(window\)/);
});
diff --git a/apps/desktop/test/composer-send-state.test.mjs b/apps/desktop/test/composer-send-state.test.mjs
index 013a39ef3..d772e40eb 100644
--- a/apps/desktop/test/composer-send-state.test.mjs
+++ b/apps/desktop/test/composer-send-state.test.mjs
@@ -23,6 +23,7 @@ const [
eventsSlice,
queueSlice,
transcriptSlice,
+ storeHelpers,
toolbar,
submitHook,
draftHook,
@@ -38,6 +39,7 @@ const [
readStoreModule("slices/events-slice.ts"),
readStoreModule("slices/queue-slice.ts"),
readStoreModule("slices/transcript-slice.ts"),
+ readStoreModule("helpers/store-helpers.ts"),
readComposerModule("ComposerToolbar.tsx"),
readComposerModule("hooks/useComposerSubmit.ts"),
readComposerModule("hooks/useComposerDraft.ts"),
@@ -296,9 +298,11 @@ test("mode slash prefixes send the trailing prompt and retain failed drafts", ()
});
test("draft attachment routing keeps image chips structured and file chips textual", () => {
- const helperSource = appStore.match(
- /function promptAttachmentsFromDraft\([\s\S]*?\n\}\n\nfunction promptAttachmentsFromMessage/,
- )?.[0]?.replace(/\n\nfunction promptAttachmentsFromMessage[\s\S]*$/, "");
+ const helperSource = storeHelpers.match(
+ /(?:export\s+)?function promptAttachmentsFromDraft\([\s\S]*?\n\}\n\n(?:export\s+)?function promptAttachmentsFromMessage/,
+ )?.[0]
+ ?.replace(/\n\n(?:export\s+)?function promptAttachmentsFromMessage[\s\S]*$/, "")
+ .replace(/^export\s+/, "");
assert.ok(helperSource, "prompt attachment mapper not found");
const executable = helperSource.replace(
/function promptAttachmentsFromDraft\(\s*references: ComposerDraftSnapshot\["fileReferences"\],\s*\): AgentPromptAttachment\[\] \{/,
diff --git a/apps/desktop/test/remote-host-bootstrap-script.test.mjs b/apps/desktop/test/remote-host-bootstrap-script.test.mjs
index bea2acefb..183c36722 100644
--- a/apps/desktop/test/remote-host-bootstrap-script.test.mjs
+++ b/apps/desktop/test/remote-host-bootstrap-script.test.mjs
@@ -172,6 +172,14 @@ test("buildBootstrapScript interpolates every input as a quoted literal", () =>
assert.ok(script.includes("PORT='0'"));
assert.ok(script.includes("PAIRING_LIFETIME_MS='600000'"));
assert.ok(script.includes("READY_TIMEOUT_SEC='30'"));
+ assert.match(
+ script,
+ /chmod 700 "\$work" 2>\/dev\/null \|\| die "bootstrap-permissions"/,
+ );
+ assert.match(
+ script,
+ /chmod 600 "\$tarball" 2>\/dev\/null \|\| die "artifact-permissions"/,
+ );
// The Node floor is injected from the module, not left as an empty shell var.
assert.match(script, /^MIN_NODE_MAJOR='\d+'$/m);
assert.ok(script.includes('$MIN_NODE_MAJOR'));
diff --git a/apps/desktop/test/window-menu.test.mjs b/apps/desktop/test/window-menu.test.mjs
index 74bcb6019..f452c98a7 100644
--- a/apps/desktop/test/window-menu.test.mjs
+++ b/apps/desktop/test/window-menu.test.mjs
@@ -123,7 +123,7 @@ test("developer mode gates every devtools entry point in the main process", () =
menuSource,
/\.\.\.\(developerMode[\s\S]*role: "toggleDevTools"/,
);
- assert.match(mainSource, /let developerMode = false/);
+ assert.match(mainSource, /(?:let\s+)?developerMode\s*=\s*false/);
assert.match(mainSource, /function applyDeveloperMode/);
assert.match(
mainSource,