import { t as isTruthyEnvValue } from "./env-BGnGIPH-.js";
import { a as formatUncaughtError, i as formatErrorMessage } from "./errors-D_oyTIw2.js";
import { t as formatCliCommand } from "./command-format-tWmMYcvZ.js";
//#region src/cli/failure-output.ts
function hasDebugArg(argv) {
	return Boolean(argv?.some((arg) => arg === "--debug" || arg === "--verbose"));
}
function shouldShowStack(argv, env) {
	return hasDebugArg(argv) || isTruthyEnvValue(env.DAOCORE_DEBUG);
}
function pushPrefixed(out, value) {
	for (const line of value.split("\n")) if (line.trim().length > 0) out.push(`[daocore] ${line}`);
}
function formatCliFailureLines(options) {
	const env = options.env ?? process.env;
	const lines = [`[daocore] ${options.title}`, `[daocore] Reason: ${formatErrorMessage(options.error)}`];
	if (shouldShowStack(options.argv, env)) {
		lines.push("[daocore] Stack:");
		pushPrefixed(lines, formatUncaughtError(options.error));
	} else lines.push("[daocore] Debug: set DAOCORE_DEBUG=1 to include the stack trace.");
	if (options.includeDoctorHint !== false) lines.push(`[daocore] Try: ${formatCliCommand("daocore doctor", env)}`);
	lines.push(`[daocore] Help: ${formatCliCommand("daocore --help", env)}`);
	return lines;
}
//#endregion
export { formatCliFailureLines as t };
