run: make minimal mode more minimal (#31227)

This commit is contained in:
Simon Klee
2026-06-07 23:26:14 +02:00
committed by GitHub
parent 9a489d136e
commit 42a94c6dd1
39 changed files with 3138 additions and 959 deletions
+19 -2
View File
@@ -4,9 +4,26 @@ import { readFile, rm, writeFile } from "node:fs/promises"
import os from "node:os"
import path from "node:path"
import { spawn } from "node:child_process"
import type { Stream } from "node:stream"
import { resolveZedDbPath, resolveZedSelection } from "./editor-zed"
export async function openEditor(input: { value: string; renderer: CliRenderer; cwd?: string }) {
type EditorStdio = "inherit" | "pipe" | "ignore" | number | Stream
export function normalizePromptContent(content: string) {
if (content.endsWith("\r\n")) {
const body = content.slice(0, -2)
return !body.includes("\n") && !body.includes("\r") ? body : content
}
if (content.endsWith("\n")) {
const body = content.slice(0, -1)
return !body.includes("\n") && !body.includes("\r") ? body : content
}
return content
}
export async function openEditor(input: { value: string; renderer: CliRenderer; cwd?: string; stdin?: EditorStdio }) {
const editor = process.env.VISUAL || process.env.EDITOR
if (!editor) return
const file = path.join(os.tmpdir(), `${Date.now()}.md`)
@@ -18,7 +35,7 @@ export async function openEditor(input: { value: string; renderer: CliRenderer;
const parts = editor.split(" ")
const child = spawn(parts[0]!, [...parts.slice(1), file], {
cwd: input.cwd && existsSync(input.cwd) ? input.cwd : process.cwd(),
stdio: "inherit",
stdio: [input.stdin ?? "inherit", "inherit", "inherit"],
shell: process.platform === "win32",
})
child.on("error", reject)