From 4c6c4482b4b1ff59a4114d52eb8331796b6ffaf0 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 2 Jun 2026 12:12:10 +0200 Subject: [PATCH] Fix SDK embed ENOENT when package.json missing (closes #5226) - Wrap package.json read in try/catch to handle missing file gracefully - Use defaults (APP_NAME=pi, CONFIG_DIR_NAME=.pi, etc.) when package.json not found - Preserves rebranding via piConfig when package.json exists - Only ignores ENOENT; other errors still throw --- packages/coding-agent/CHANGELOG.md | 1 + packages/coding-agent/src/config.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 1fcde0b7..85b26f8f 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixed +- Fixed SDK embedding in bundled Node apps failing with `ENOENT` when `package.json` is not present next to the bundle entrypoint. The package metadata reader now gracefully handles missing `package.json` by using defaults, enabling `createAgentSession()` without requiring package-adjacent files at runtime ([#5226](https://github.com/earendil-works/pi/issues/5226)). - Fixed HTTP timeout setting not being respected for non-Codex providers (e.g., llama.cpp via OpenAI-compatible API). The `httpIdleTimeoutMs` setting (set via `/settings` HTTP timeout) now applies as the default SDK request timeout for all providers that support it, not just OpenAI Codex Responses. Disabling the timeout (HTTP timeout = false) now correctly disables SDK timeouts for all supported providers by sending a maximum int32 value (effectively infinite) instead of 0, since SDKs treat timeout=0 as an immediate timeout ([#5294](https://github.com/earendil-works/pi/issues/5294)). - Fixed opening and listing very large JSONL session files by reading session entries line-by-line instead of materializing the full file as one string ([#5231](https://github.com/earendil-works/pi/issues/5231)). diff --git a/packages/coding-agent/src/config.ts b/packages/coding-agent/src/config.ts index 01ec8f8e..65fb220e 100644 --- a/packages/coding-agent/src/config.ts +++ b/packages/coding-agent/src/config.ts @@ -452,7 +452,13 @@ interface PackageJson { }; } -const pkg = JSON.parse(readFileSync(getPackageJsonPath(), "utf-8")) as PackageJson; +let pkg: PackageJson = {}; +try { + pkg = JSON.parse(readFileSync(getPackageJsonPath(), "utf-8")) as PackageJson; +} catch (e: unknown) { + const err = e as NodeJS.ErrnoException; + if (err.code !== "ENOENT") throw e; +} const piConfigName: string | undefined = pkg.piConfig?.name; export const PACKAGE_NAME: string = pkg.name || "@earendil-works/pi-coding-agent";