import { parseArgs } from "node:util";

//#region src/cli/parse.ts
function parseArgv(argv) {
	const options = {
		"access-token": { type: "string" },
		host: { type: "string" },
		url: { type: "string" },
		"mcp-url": { type: "string" },
		"sentry-dsn": { type: "string" },
		"openai-base-url": { type: "string" },
		"openai-model": { type: "string" },
		"organization-slug": { type: "string" },
		"project-slug": { type: "string" },
		skills: { type: "string" },
		agent: { type: "boolean" },
		help: {
			type: "boolean",
			short: "h"
		},
		version: {
			type: "boolean",
			short: "v"
		}
	};
	const { values, positionals, tokens } = parseArgs({
		args: argv,
		options,
		allowPositionals: false,
		strict: false,
		tokens: true
	});
	const knownLong = new Set(Object.keys(options));
	const knownShort = new Set([...Object.values(options).map((o) => "short" in o ? o.short : void 0).filter(Boolean)]);
	const unknownArgs = [];
	for (const t of tokens || []) if (t.kind === "option") {
		const name = t.name;
		if (name && !(knownLong.has(name) || knownShort.has(name))) unknownArgs.push(t.raw ?? `--${name}`);
	} else if (t.kind === "positional") unknownArgs.push(t.raw ?? String(t.value ?? ""));
	return {
		accessToken: values["access-token"],
		host: values.host,
		url: values.url,
		mcpUrl: values["mcp-url"],
		sentryDsn: values["sentry-dsn"],
		openaiBaseUrl: values["openai-base-url"],
		openaiModel: values["openai-model"],
		organizationSlug: values["organization-slug"],
		projectSlug: values["project-slug"],
		skills: values.skills,
		agent: values.agent === true,
		help: values.help === true,
		version: values.version === true,
		unknownArgs: unknownArgs.length > 0 ? unknownArgs : positionals || []
	};
}
function parseEnv(env) {
	const fromEnv = {};
	if (env.SENTRY_ACCESS_TOKEN) fromEnv.accessToken = env.SENTRY_ACCESS_TOKEN;
	if (env.SENTRY_URL) fromEnv.url = env.SENTRY_URL;
	if (env.SENTRY_HOST) fromEnv.host = env.SENTRY_HOST;
	if (env.MCP_URL) fromEnv.mcpUrl = env.MCP_URL;
	if (env.SENTRY_DSN || env.DEFAULT_SENTRY_DSN) fromEnv.sentryDsn = env.SENTRY_DSN || env.DEFAULT_SENTRY_DSN;
	if (env.OPENAI_MODEL) fromEnv.openaiModel = env.OPENAI_MODEL;
	if (env.MCP_SKILLS) fromEnv.skills = env.MCP_SKILLS;
	return fromEnv;
}
function merge(cli, env) {
	return {
		accessToken: cli.accessToken ?? env.accessToken,
		url: cli.url ?? env.url,
		host: cli.host ?? env.host,
		mcpUrl: cli.mcpUrl ?? env.mcpUrl,
		sentryDsn: cli.sentryDsn ?? env.sentryDsn,
		openaiBaseUrl: cli.openaiBaseUrl,
		openaiModel: cli.openaiModel ?? env.openaiModel,
		skills: cli.skills ?? env.skills,
		agent: cli.agent === true,
		organizationSlug: cli.organizationSlug,
		projectSlug: cli.projectSlug,
		help: cli.help === true,
		version: cli.version === true,
		unknownArgs: cli.unknownArgs
	};
}

//#endregion
export { merge, parseArgv, parseEnv };
//# sourceMappingURL=parse-46t_fITC.js.map