Skip to content

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

fix(voice): keep Windows native modules package-resolvable

vastsa1702dc04ef25
diff --git a/apps/desktop/electron.vite.config.ts b/apps/desktop/electron.vite.config.ts
index 58bb437f9..85b4f8c99 100644
--- a/apps/desktop/electron.vite.config.ts
+++ b/apps/desktop/electron.vite.config.ts
@@ -56,12 +56,19 @@ export default defineConfig({
},
build: {
rollupOptions: {
- // Bundle JS workspace packages into Main. Only runtime modules that
- // must resolve from the packaged node_modules stay external.
+ // Bundle JS workspace packages into Main. Native voice modules must
+ // resolve from packaged node_modules because their loaders locate
+ // platform libraries relative to their own package directories.
// jiti is loaded lazily by the sidecar's trusted-extension loader
// (D387); Electron main never calls it, and its transpiled dist
// breaks the main bundle's esbuild transform.
- external: ["electron-updater", "jiti", "jiti/static"],
+ external: [
+ "electron-updater",
+ "jiti",
+ "jiti/static",
+ "@picovoice/pvrecorder-node",
+ "transcribe-cpp",
+ ],
input: {
index: resolve(__dirname, "electron/main/index.ts"),
// Forked per plugin by PluginRuntime (ADR 0008); must stay a
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 821e72d6b..a3377ff13 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -31,6 +31,8 @@
"dist:linux": "pnpm run build:deps && pnpm run build:host-release && pnpm run bundle:runtime && electron-vite build && electron-builder --linux --publish never"
},
"dependencies": {
+ "@picovoice/pvrecorder-node": "1.2.9",
+ "transcribe-cpp": "0.2.2",
"electron-updater": "^6.8.9"
},
"devDependencies": {
@@ -45,12 +47,10 @@
"@pi-desktop/shared": "workspace:*",
"@pi-desktop/voice-runtime": "workspace:*",
"@tailwindcss/vite": "^4.3.3",
- "@picovoice/pvrecorder-node": "1.2.9",
"@types/react": "^19.2.18",
"@types/react-dom": "^19.2.4",
"@types/ws": "^8.18.1",
"@vitejs/plugin-react": "^4.6.0",
- "transcribe-cpp": "0.2.2",
"dompurify": "^3.4.13",
"electron": "^43.4.1",
"electron-builder": "^26.15.3",
diff --git a/apps/desktop/src/features/settings/SettingsPage.tsx b/apps/desktop/src/features/settings/SettingsPage.tsx
index 95e3a474d..74631e1dc 100644
--- a/apps/desktop/src/features/settings/SettingsPage.tsx
+++ b/apps/desktop/src/features/settings/SettingsPage.tsx
@@ -528,7 +528,7 @@ export function SettingsPage() {
</div>
)}
- {tab === "voice" && settings && (
+ {tab === "voice" && !tabHidden && settings && (
<VoiceSettingsSection
t={t}
settings={settings}
diff --git a/apps/desktop/src/features/settings/voice/VoiceSettingsSection.tsx b/apps/desktop/src/features/settings/voice/VoiceSettingsSection.tsx
index f87ba518d..11c36ac0b 100644
--- a/apps/desktop/src/features/settings/voice/VoiceSettingsSection.tsx
+++ b/apps/desktop/src/features/settings/voice/VoiceSettingsSection.tsx
@@ -5,7 +5,7 @@
import { useCallback, useEffect, useState } from "react";
import type { TFunction } from "i18next";
-import type { AppSettings } from "@pi-desktop/shared";
+import type { AppSettings, VoiceInputSettings } from "@pi-desktop/shared";
import { Button, Badge, CheckboxGroup, SettingsToggle } from "../../../components/ui";
import { SettingsMenuSelect } from "../../../components/settings/SettingsMenuSelect";
import { SettingsRow, SettingsCard } from "../primitives";
@@ -41,7 +41,7 @@ export function VoiceSettingsSection({
settings: AppSettings;
saveSettings: (patch: Partial<AppSettings>) => Promise<void>;
}) {
- const voice = settings.voice ?? {
+ const voice: VoiceInputSettings = settings.voice ?? {
enabled: false,
deviceId: null,
languages: ["zh", "en"],
@@ -52,12 +52,34 @@ export function VoiceSettingsSection({
const [devices, setDevices] = useState<AudioInputDevice[]>([]);
const [models, setModels] = useState<ModelState[]>([]);
const [permission, setPermission] = useState<string>("undetermined");
+ const [deviceLoadError, setDeviceLoadError] = useState(false);
useEffect(() => {
- voiceIpc
+ if (!voice.enabled) {
+ setDevices([]);
+ setDeviceLoadError(false);
+ return;
+ }
+
+ let cancelled = false;
+ setDeviceLoadError(false);
+ void voiceIpc
.getDevices()
- .then((d) => setDevices(Array.isArray(d) ? d as AudioInputDevice[] : []))
- .catch(() => {});
+ .then((d) => {
+ if (cancelled) return;
+ setDevices(Array.isArray(d) ? (d as AudioInputDevice[]) : []);
+ })
+ .catch(() => {
+ if (cancelled) return;
+ setDevices([]);
+ setDeviceLoadError(true);
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [voice.enabled]);
+
+ useEffect(() => {
voiceIpc
.getModels()
.then((m) => setModels(Array.isArray(m) ? m as ModelState[] : []))
@@ -85,9 +107,9 @@ export function VoiceSettingsSection({
}, []);
const save = useCallback(
- (patch: Record<string, unknown>) => {
+ (patch: Partial<VoiceInputSettings>) => {
const next = { ...voice, ...patch };
- void saveSettings({ voice: next as any });
+ void saveSettings({ voice: next });
void voiceIpc.updateSettings(next);
},
[voice, saveSettings],
@@ -128,7 +150,10 @@ export function VoiceSettingsSection({
{/* ---- Input ---- */}
<SettingsCard title={t("settings.voiceMicrophone")}>
- <SettingsRow title={t("settings.voiceMicrophone")}>
+ <SettingsRow
+ title={t("settings.voiceMicrophone")}
+ detail={deviceLoadError ? t("settings.voiceMicUnavailable") : undefined}
+ >
<SettingsMenuSelect
value={voice.deviceId ?? ""}
label={t("settings.voiceMicrophone")}
@@ -167,7 +192,15 @@ export function VoiceSettingsSection({
{ id: "traditional-taiwan", label: t("settings.voiceTraditionalTaiwan") },
{ id: "traditional-hong-kong", label: t("settings.voiceTraditionalHK") },
]}
- onChange={(id) => save({ chineseVariant: id })}
+ onChange={(id) => {
+ if (
+ id === "simplified" ||
+ id === "traditional-taiwan" ||
+ id === "traditional-hong-kong"
+ ) {
+ save({ chineseVariant: id });
+ }
+ }}
/>
</SettingsRow>
</SettingsCard>
diff --git a/apps/desktop/test/packaging-footprint.test.mjs b/apps/desktop/test/packaging-footprint.test.mjs
index 6a0841a46..2b3eb47f5 100644
--- a/apps/desktop/test/packaging-footprint.test.mjs
+++ b/apps/desktop/test/packaging-footprint.test.mjs
@@ -38,9 +38,11 @@ const pluginPanelPreloadSource = await readFile(
"utf8",
);
-test("packaging installs only the updater runtime dependency", () => {
+test("packaging keeps native voice modules as runtime dependencies", () => {
assert.deepEqual(Object.keys(packageJson.dependencies).sort(), [
+ "@picovoice/pvrecorder-node",
"electron-updater",
+ "transcribe-cpp",
]);
for (const dependency of [
@@ -119,11 +121,14 @@ test("legacy font fallback stripping only removes redundant fallback sources", (
}
});
-test("main bundles JavaScript dependencies and externalizes only runtime modules", () => {
+test("main bundles JavaScript dependencies and externalizes runtime modules", () => {
assert.doesNotMatch(viteConfigSource, /externalizeDepsPlugin\s*\(/);
// jiti is listed so the trusted-extension loader's lazy import never
// enters the main bundle; main itself never loads it (spec 16 §4.2).
- assert.match(viteConfigSource, /external:\s*\["electron-updater", "jiti", "jiti\/static"\]/);
+ assert.match(viteConfigSource, /external:\s*\[/);
+ for (const moduleName of ["@picovoice/pvrecorder-node", "transcribe-cpp"]) {
+ assert.match(viteConfigSource, new RegExp(`"${moduleName.replaceAll("/", "\\/")}"`));
+ }
assert.doesNotMatch(viteConfigSource, /node-pty/);
assert.doesNotMatch(JSON.stringify(packageJson.dependencies), /node-pty/);
});
diff --git a/apps/desktop/test/settings-general.test.mjs b/apps/desktop/test/settings-general.test.mjs
index dfc3f513b..26552c91e 100644
--- a/apps/desktop/test/settings-general.test.mjs
+++ b/apps/desktop/test/settings-general.test.mjs
@@ -112,12 +112,16 @@ const networkProxySource = await readFile(
new URL("../src/components/settings/NetworkProxySection.tsx", import.meta.url),
"utf8",
);
+const voiceSettingsSource = await readFile(
+ new URL("../src/features/settings/voice/VoiceSettingsSection.tsx", import.meta.url),
+ "utf8",
+);
test("Basics and AI tabs expose their respective app and AI controls", () => {
const generalStart = settingsPageSource.indexOf('{tab === "general" && settings && (');
const aiStart = settingsPageSource.indexOf('{tab === "ai" && settings && (');
const voiceStart = settingsPageSource.indexOf(
- '{tab === "voice" && settings && (',
+ '{tab === "voice" && !tabHidden && settings && (',
);
const generalSource = settingsPageSource.slice(generalStart, aiStart);
const aiSource = settingsPageSource.slice(aiStart, voiceStart);
@@ -174,7 +178,9 @@ test("Basics and AI tabs expose their respective app and AI controls", () => {
assert.doesNotMatch(aiSource, /<select/);
// Voice owns a separate destination; the AI tab does not duplicate it.
assert.doesNotMatch(aiSource, /VoiceSettingsCard|VoiceSettingsSection|voice-settings/);
- assert.match(settingsPageSource, /tab === "voice" && settings && [\s\S]*?<VoiceSettingsSection/);
+ assert.match(settingsPageSource, /tab === "voice" && !tabHidden && settings && [\s\S]*?<VoiceSettingsSection/);
+ assert.match(voiceSettingsSource, /if \(!voice\.enabled\) \{/);
+ assert.match(voiceSettingsSource, /voiceMicUnavailable/);
assert.doesNotMatch(settingsSearchSource, /settings\.speech/);
assert.doesNotMatch(stylesSource, /\.settings-speech/);
assert.doesNotMatch(enLocaleSource, /speechTitle:|speechVoicePlaceholder:/);
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 43006f43a..6265d9825 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -39,9 +39,15 @@ importers:
apps/desktop:
dependencies:
+ '@picovoice/pvrecorder-node':
+ specifier: 1.2.9
+ version: 1.2.9
electron-updater:
specifier: ^6.8.9
version: 6.8.9
+ transcribe-cpp:
+ specifier: 0.2.2
+ version: 0.2.2
devDependencies:
'@earendil-works/pi-ai':
specifier: 0.87.1
@@ -73,9 +79,6 @@ importers:
'@pi-desktop/voice-runtime':
specifier: workspace:*
version: link:../../packages/voice-runtime
- '@picovoice/pvrecorder-node':
- specifier: 1.2.9
- version: 1.2.9
'@tailwindcss/vite':
specifier: ^4.3.3
@@ -154,9 +157,6 @@ importers:
tailwindcss:
specifier: ^4.3.3
version: 4.3.3
- transcribe-cpp:
- specifier: 0.2.2
- version: 0.2.2
typescript:
specifier: ^5.9.3
version: 5.9.3