From 552c22d74e5df915088d9e9ff4a286c96c2a54d6 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Fri, 5 Jun 2026 21:20:34 +0900 Subject: feat(cli): one-shot terminal client (models, chat, --text/--file/--cwd/--conversation) HTTP client of transport-contract; pure-core arg/render/ndjson + injected fetch/fs shell. Docs: GLOSSARY (credential/key/model name/model catalog), tasks.md milestone, ORCHESTRATOR geography. --- packages/cli/src/message.ts | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 packages/cli/src/message.ts (limited to 'packages/cli/src/message.ts') diff --git a/packages/cli/src/message.ts b/packages/cli/src/message.ts new file mode 100644 index 0000000..0c3f538 --- /dev/null +++ b/packages/cli/src/message.ts @@ -0,0 +1,55 @@ +/** + * Pure message composition — zero I/O. + * + * Combines text and file content into a single message string, + * and builds a ChatRequest from a parsed command. + */ + +import type { ChatRequest } from "@dispatch/transport-contract"; + +interface ComposeInput { + readonly text?: string; + readonly file?: string; + readonly fileContent?: string; +} + +function basename(filePath: string): string { + const segments = filePath.split("/"); + return segments[segments.length - 1] ?? filePath; +} + +export function composeMessage(input: ComposeInput): string { + const { text, fileContent } = input; + const file = input.file; + + if (text && file) { + return `${text}\n\nAttached file (${basename(file)}):\n${fileContent ?? ""}`; + } + if (file) { + return `Attached file (${basename(file)}):\n${fileContent ?? ""}`; + } + return text ?? ""; +} + +interface ChatCmd { + readonly modelName: string; + readonly text?: string | undefined; + readonly file?: string | undefined; + readonly cwd?: string | undefined; + readonly conversationId?: string | undefined; + readonly showReasoning: boolean; +} + +interface BuildCtx { + readonly cwd: string; + readonly message: string; +} + +export function buildChatRequest(cmd: ChatCmd, ctx: BuildCtx): ChatRequest { + return { + message: ctx.message, + model: cmd.modelName, + ...(cmd.conversationId !== undefined && { conversationId: cmd.conversationId }), + ...(cmd.cwd !== undefined ? { cwd: cmd.cwd } : { cwd: ctx.cwd }), + }; +} -- cgit v1.2.3