Skip to content

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

Merge remote-tracking branch 'origin/main' into feat/trust-user-supplied-endpoints

vastsa73c10fc9ddd5
diff --cc apps/desktop/electron/main/runtime/sidecar.ts
index fcd68d044,56b287c0b..d978656fd
--- a/apps/desktop/electron/main/runtime/sidecar.ts
+++ b/apps/desktop/electron/main/runtime/sidecar.ts
@@@ -12,6 -12,6 +12,7 @@@ import { registerPluginDevTools } from
import { resolveLocalFile } from "../browser-view";
import { modelConfigFromModelsDev } from "../models-dev-catalog";
import { AgentSidecar } from "../agent-sidecar";
++import { relaxedNetworkPolicyEnabled } from "../endpoint-policy";
import { OAUTH_AUTH_KIND, type VendorOAuth } from "../oauth";
import type { AgentExtensionBridge } from "../agent-extensions";
import type { BrowserHost } from "../browser-host";
@@@ -470,7 -470,11 +471,12 @@@ export function createSidecarRuntime(
});
// Agent-driven work panel preview (D100): open a workspace HTML file in
// the embedded browser; live reload keeps it current through later edits.
- s.setLocalTool("GenerateImages", createImageGenerationTool({ dataDir, getHost: () => runtimeState.host }));
+ s.setLocalTool("GenerateImages", createImageGenerationTool({
+ dataDir,
+ getHost: () => runtimeState.host,
- allowFakeIp: () => currentNetworkProxy().allowFakeIp === true,
++ // Fake-IP tolerance belongs to the network policy, not to the proxy switch.
++ allowFakeIp: () => relaxedNetworkPolicyEnabled(),
+ }));
s.setLocalTool("BrowserPreview", async ({ args, sessionId }) => {
const raw = String((args as { path?: unknown })?.path ?? "").trim();
if (!raw) {
diff --cc packages/agent-runtime/src/image-generation/download.ts
index 513e628e0,de33ad22b..70db9d85f
--- a/packages/agent-runtime/src/image-generation/download.ts
+++ b/packages/agent-runtime/src/image-generation/download.ts
@@@ -1,12 -1,15 +1,19 @@@
import { lookup } from "node:dns/promises";
-import { isIP } from "node:net";
+import {
+ classifyIpLiteral,
+ isAcceptableUserEndpointAddress,
+ isCloudMetadataAddress,
++ isProxyFakeIpAddress,
+} from "@pi-desktop/shared";
import { Agent, fetch as fetchPinned } from "undici";
-import { classifyIpLiteral, isProxyFakeIpAddress } from "@pi-desktop/shared";
export const MAX_IMAGE_BYTES = 16 * 1024 * 1024;
+ export type ImageDownloadOptions = {
+ /** Explicitly permits router/TUN benchmark fake-IP answers. */
+ allowFakeIp?: boolean;
+ /** Proxy-aware transport used when a fake-IP answer must be resolved by the proxy. */
+ fetchImpl?: typeof fetch;
+ };
export function imageError(code: string): Error & { errorCode: string } {
return Object.assign(new Error(code), { errorCode: code });
}
@@@ -59,15 -69,8 +66,18 @@@ export function publicImageAddress(addr
/**
* Pin the checked DNS answer to the connection; never forward provider headers.
+ *
+ * Plain `http` and any port are accepted because the realistic target is a
+ * self-hosted generator on the user's own machine or LAN, where TLS and port
+ * 443 are the exception. `@pi-desktop/agent-runtime` has no access to the app's
- * `networkPolicy.allowInsecureUserEndpoints` setting (it must not import
- * Electron main-process modules), so plaintext to a private address cannot be
- * gated on the user's opt-in here; the trade-off is accepted because the
- * endpoint this dials is the one the user configured, and the response is
- * still size-capped and stripped of provider-supplied headers.
++ * network policy (it must not import Electron main-process modules), so a
++ * plaintext hop to a private address cannot be gated on the user's choice here;
++ * the trade-off is accepted because the endpoint this dials is the one the user
++ * configured, and the response is still size-capped and stripped of
++ * provider-supplied headers.
++ *
+ * An explicitly opted-in fake-IP answer is the one exception: it goes through the
+ * global fetch instead, which resolves the hostname again at connect time.
*/
export async function downloadGeneratedImage(
raw: string,