fix(cli): restored piped session persistence

- Treated undefined stdin TTY state as redirected input.

- Honored PI_CODING_AGENT_SESSION_DIR with CLI precedence.

Fixes #7378
This commit is contained in:
roboomp
2026-08-02 11:33:58 +00:00
parent 06343fef42
commit 72d8d4eaca
5 changed files with 47 additions and 4 deletions
@@ -2,7 +2,11 @@ import { afterEach, describe, expect, it, vi } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { applyResolvedSystemPromptInputs, submitInteractiveInput } from "@oh-my-pi/pi-coding-agent/main";
import {
applyResolvedSystemPromptInputs,
readPipedInput,
submitInteractiveInput,
} from "@oh-my-pi/pi-coding-agent/main";
import type { SubmittedUserInput } from "@oh-my-pi/pi-coding-agent/modes/types";
import type { CreateAgentSessionOptions } from "@oh-my-pi/pi-coding-agent/sdk";
import { discoverTitleSystemPromptFile } from "@oh-my-pi/pi-coding-agent/system-prompt";
@@ -12,6 +16,7 @@ const cleanupDirs: string[] = [];
afterEach(async () => {
await Promise.all(cleanupDirs.splice(0).map(dir => removeWithRetries(dir)));
vi.restoreAllMocks();
});
function createInput(overrides: Partial<SubmittedUserInput> = {}): SubmittedUserInput {
@@ -37,6 +42,21 @@ describe("discoverTitleSystemPromptFile", () => {
});
});
describe("readPipedInput", () => {
it("reads redirected stdin when Bun reports isTTY as undefined", async () => {
const originalIsTTY = process.stdin.isTTY;
const readText = vi.spyOn(Bun.stdin, "text").mockResolvedValue("piped prompt\n");
Object.defineProperty(process.stdin, "isTTY", { value: undefined, configurable: true });
try {
expect(await readPipedInput()).toBe("piped prompt\n");
expect(readText).toHaveBeenCalledTimes(1);
} finally {
Object.defineProperty(process.stdin, "isTTY", { value: originalIsTTY, configurable: true });
}
});
});
describe("applyResolvedSystemPromptInputs", () => {
it("routes SYSTEM.md content through template-aware session options", () => {
const options: CreateAgentSessionOptions = {};