diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 0e95e22e..ff0512ee 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -6,8 +6,13 @@ - **Compaction UI**: Simplified collapsed compaction indicator to show warning-colored text with token count instead of styled banner. Removed redundant success message after compaction. ([#108](https://github.com/badlogic/pi-mono/issues/108)) +### Fixed + +- **Print mode error handling**: `-p` flag now outputs error messages and exits with code 1 when requests fail, instead of silently producing no output. + ### Added +- **`authHeader` option in models.json**: Custom providers can set `"authHeader": true` to automatically add `Authorization: Bearer ` header. Useful for providers that require explicit auth headers. ([#81](https://github.com/badlogic/pi-mono/issues/81)) - **`--append-system-prompt` Flag**: Append additional text or file contents to the system prompt. Supports both inline text and file paths. Complements `--system-prompt` for layering custom instructions without replacing the base system prompt. ([#114](https://github.com/badlogic/pi-mono/pull/114) by [@markusylisiurunen](https://github.com/markusylisiurunen)) - **Thinking Block Toggle**: Added `Ctrl+T` shortcut to toggle visibility of LLM thinking blocks. When toggled off, shows a static "Thinking..." label instead of full content. Useful for reducing visual clutter during long conversations. ([#113](https://github.com/badlogic/pi-mono/pull/113) by [@markusylisiurunen](https://github.com/markusylisiurunen)) diff --git a/packages/coding-agent/src/main.ts b/packages/coding-agent/src/main.ts index 12c80360..7f764ac1 100644 --- a/packages/coding-agent/src/main.ts +++ b/packages/coding-agent/src/main.ts @@ -817,7 +817,15 @@ async function runSingleShotMode( if (mode === "text") { const lastMessage = agent.state.messages[agent.state.messages.length - 1]; if (lastMessage.role === "assistant") { - for (const content of lastMessage.content) { + const assistantMsg = lastMessage as AssistantMessage; + + // Check for error/aborted and output error message + if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") { + console.error(assistantMsg.errorMessage || `Request ${assistantMsg.stopReason}`); + process.exit(1); + } + + for (const content of assistantMsg.content) { if (content.type === "text") { console.log(content.text); } diff --git a/packages/coding-agent/src/model-config.ts b/packages/coding-agent/src/model-config.ts index b5265028..abbebdb1 100644 --- a/packages/coding-agent/src/model-config.ts +++ b/packages/coding-agent/src/model-config.ts @@ -46,6 +46,7 @@ const ProviderConfigSchema = Type.Object({ ]), ), headers: Type.Optional(Type.Record(Type.String(), Type.String())), + authHeader: Type.Optional(Type.Boolean()), models: Type.Array(ModelDefinitionSchema), }); @@ -177,9 +178,17 @@ function parseModels(config: ModelsConfig): Model[] { } // Merge headers: provider headers are base, model headers override - const headers = + let headers = providerConfig.headers || modelDef.headers ? { ...providerConfig.headers, ...modelDef.headers } : undefined; + // If authHeader is true, add Authorization header with resolved API key + if (providerConfig.authHeader) { + const resolvedKey = resolveApiKey(providerConfig.apiKey); + if (resolvedKey) { + headers = { ...headers, Authorization: `Bearer ${resolvedKey}` }; + } + } + models.push({ id: modelDef.id, name: modelDef.name,