fix(coding-agent): merge piped stdin into initial prompt closes #2315
This commit is contained in:
43
packages/coding-agent/src/cli/initial-message.ts
Normal file
43
packages/coding-agent/src/cli/initial-message.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import type { ImageContent } from "@mariozechner/pi-ai";
|
||||
import type { Args } from "./args.js";
|
||||
|
||||
export interface InitialMessageInput {
|
||||
parsed: Args;
|
||||
fileText?: string;
|
||||
fileImages?: ImageContent[];
|
||||
stdinContent?: string;
|
||||
}
|
||||
|
||||
export interface InitialMessageResult {
|
||||
initialMessage?: string;
|
||||
initialImages?: ImageContent[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine stdin content, @file text, and the first CLI message into a single
|
||||
* initial prompt for non-interactive mode.
|
||||
*/
|
||||
export function buildInitialMessage({
|
||||
parsed,
|
||||
fileText,
|
||||
fileImages,
|
||||
stdinContent,
|
||||
}: InitialMessageInput): InitialMessageResult {
|
||||
const parts: string[] = [];
|
||||
if (stdinContent !== undefined) {
|
||||
parts.push(stdinContent);
|
||||
}
|
||||
if (fileText) {
|
||||
parts.push(fileText);
|
||||
}
|
||||
|
||||
if (parsed.messages.length > 0) {
|
||||
parts.push(parsed.messages[0]);
|
||||
parsed.messages.shift();
|
||||
}
|
||||
|
||||
return {
|
||||
initialMessage: parts.length > 0 ? parts.join("") : undefined,
|
||||
initialImages: fileImages && fileImages.length > 0 ? fileImages : undefined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user