import { stdin, stdout } from "node:process";
import * as readline from "node:readline/promises";
//#region src/agent/tools/cli-clarify.ts
/**
* stdin/stdout prompts for `clarify` when running the CLI agent (no gateway).
*/
function createCliReadlineClarifyRequestFn() {
	return async (_sessionKey, req) => {
		const rl = readline.createInterface({
			input: stdin,
			output: stdout
		});
		try {
			const choices = req.choices;
			if (choices && choices.length >= 2) {
				stdout.write(`\n${req.question}\n`);
				choices.forEach((c, i) => stdout.write(`  ${i + 1}) ${c}\n`));
				if (req.default) stdout.write(`  (default: ${req.default})\n`);
				const raw = (await rl.question("Choice (number or exact text): ")).trim();
				const n = parseInt(raw, 10);
				if (!Number.isNaN(n) && n >= 1 && n <= choices.length) return choices[n - 1];
				if (raw) return raw;
				if (req.default) return req.default;
				throw new Error("No answer provided");
			}
			stdout.write(`\n${req.question}\n`);
			if (req.default) stdout.write(`(Press Enter for default: ${req.default})\n`);
			const raw = (await rl.question("> ")).trim();
			if (raw) return raw;
			if (req.default) return req.default;
			throw new Error("No answer provided");
		} finally {
			rl.close();
		}
	};
}
//#endregion
export { createCliReadlineClarifyRequestFn };

//# sourceMappingURL=cli-clarify.js.map