import { t as formatDocsLink } from "./links-CsLBrRff.js";
import { r as theme } from "./theme-vjDs9tao.js";
import { n as defaultRuntime } from "./runtime-B4lgFmsS.js";
import { r as setVerbose } from "./global-state-BAD7XgmL.js";
import "./globals-CI9McsdF.js";
import { n as runCommandWithRuntime } from "./cli-utils-Cr8nEK78.js";
import { t as formatHelpExamples } from "./help-format-CAcwboTs.js";
import { i as parseStrictPositiveIntOrUndefined, n as parsePositiveIntOrUndefined } from "./helpers-gBVG4H2O.js";
//#region src/cli/program/register.status-health-sessions.ts
function resolveVerbose(opts) {
	return Boolean(opts.verbose || opts.debug);
}
function createModuleLoader(load) {
	let promise;
	return () => promise ??= load();
}
const loadCommitmentsCommands = createModuleLoader(() => import("./commitments-DDviwjgk.js"));
const loadTasksCommands = createModuleLoader(() => import("./tasks-DLC7mKxV.js"));
const loadFlowsCommands = createModuleLoader(() => import("./flows-CzUdkfXo.js"));
function addSessionsListOptions(command) {
	return command.option("--json", "以 JSON 格式输出", false).option("--verbose", "详细日志", false).option("--store <path>", "会话存储路径（默认：从配置解析）").option("--agent <id>", "要检查的代理 ID（默认：已配置的默认代理）").option("--all-agents", "聚合所有已配置代理的会话", false).option("--active <minutes>", "仅显示过去 N 分钟内更新的会话").option("--limit <count>", "Max sessions to show (default: 100; use \"all\" for full output)");
}
function mergeSessionsListOptions(opts, parentOpts) {
	return {
		json: Boolean(opts.json || parentOpts?.json),
		verbose: Boolean(opts.verbose || parentOpts?.verbose),
		store: opts.store ?? parentOpts?.store,
		agent: opts.agent ?? parentOpts?.agent,
		allAgents: Boolean(opts.allAgents || parentOpts?.allAgents),
		active: opts.active ?? parentOpts?.active,
		limit: opts.limit ?? parentOpts?.limit
	};
}
async function runSessionsListCli(opts) {
	setVerbose(Boolean(opts.verbose));
	const { sessionsCommand } = await import("./sessions-Bq5mz2V1.js");
	await sessionsCommand({
		json: Boolean(opts.json),
		store: opts.store,
		agent: opts.agent,
		allAgents: Boolean(opts.allAgents),
		active: opts.active,
		limit: opts.limit
	}, defaultRuntime);
}
function parseTimeoutMs(timeout) {
	const parsed = parsePositiveIntOrUndefined(timeout);
	if (timeout !== void 0 && parsed === void 0) {
		defaultRuntime.error("--timeout 必须是正整数（毫秒）");
		defaultRuntime.exit(1);
		return null;
	}
	return parsed;
}
function parseTasksAuditLimit(limit) {
	const parsed = parseStrictPositiveIntOrUndefined(limit);
	if (limit !== void 0 && parsed === void 0) {
		defaultRuntime.error("--limit must be a positive integer, for example --limit 25.");
		defaultRuntime.exit(1);
		return null;
	}
	return parsed;
}
async function runWithVerboseAndTimeout(opts, action) {
	const verbose = resolveVerbose(opts);
	setVerbose(verbose);
	const timeoutMs = parseTimeoutMs(opts.timeout);
	if (timeoutMs === null) return;
	await runCommandWithRuntime(defaultRuntime, async () => {
		await action({
			verbose,
			timeoutMs
		});
	});
}
/** Register status/health plus persistent session/task inspection command groups. */
function registerStatusHealthSessionsCommands(program) {
	program.command("status").description("显示渠道健康状态和最近会话接收者").option("--json", "输出 JSON 而非文本", false).option("--all", "完整诊断（只读，可粘贴）", false).option("--usage", "显示模型提供商用量/配额快照", false).option("--deep", "探测渠道（WhatsApp Web + Telegram + Discord + Slack + Signal）", false).option("--timeout <ms>", "探测超时（毫秒）", "10000").option("--verbose", "详细日志", false).option("--debug", "--verbose 的别名", false).addHelpText("after", () => `\n${theme.heading("示例：")}\n${formatHelpExamples([
		["openclaw status", "显示渠道健康状态和会话摘要。"],
		["openclaw status --all", "完整诊断（只读）。"],
		["openclaw status --json", "机器可读输出。"],
		["openclaw status --usage", "显示模型提供商用量/配额快照。"],
		["openclaw status --deep", "运行渠道探测（WA + Telegram + Discord + Slack + Signal）。"],
		["openclaw status --deep --timeout 5000", "缩短探测超时。"]
	])}`).addHelpText("after", () => `\n${theme.muted("文档：")} ${formatDocsLink("/cli/status", "docs.openclaw.ai/cli/status")}\n`).action(async (opts) => {
		await runWithVerboseAndTimeout(opts, async ({ verbose, timeoutMs }) => {
			const { statusCommand } = await import("./status-BPJ2q5t1.js");
			await statusCommand({
				json: Boolean(opts.json),
				all: Boolean(opts.all),
				deep: Boolean(opts.deep),
				usage: Boolean(opts.usage),
				timeoutMs,
				verbose
			}, defaultRuntime);
		});
	});
	program.command("health").description("从运行中的网关获取健康状态").option("--json", "输出 JSON 而非文本", false).option("--timeout <ms>", "连接超时（毫秒）", "10000").option("--verbose", "详细日志", false).option("--debug", "--verbose 的别名", false).addHelpText("after", () => `\n${theme.muted("文档：")} ${formatDocsLink("/cli/health", "docs.openclaw.ai/cli/health")}\n`).action(async (opts) => {
		await runWithVerboseAndTimeout(opts, async ({ verbose, timeoutMs }) => {
			const { healthCommand } = await import("./health-Be1yDAxu.js");
			await healthCommand({
				json: Boolean(opts.json),
				timeoutMs,
				verbose
			}, defaultRuntime);
		});
	});
	const sessionsCmd = addSessionsListOptions(program.command("sessions").description("列出已存储的对话会话")).addHelpText("after", () => `\n${theme.heading("示例：")}\n${formatHelpExamples([
		["openclaw sessions", "列出所有会话。"],
		["openclaw sessions --agent work", "列出某个代理的会话。"],
		["openclaw sessions --all-agents", "聚合所有代理的会话。"],
		["openclaw sessions --active 120", "仅最近 2 小时。"],
		["openclaw sessions --limit 25", "Show the newest 25 sessions."],
		["openclaw sessions --json", "机器可读输出。"],
		["openclaw sessions --store ./tmp/sessions.json", "使用特定的会话存储。"]
	])}\n\n${theme.muted("当代理报告时显示每个会话的令牌用量；设置 agents.defaults.contextTokens 以限定窗口并显示百分比。")}`).addHelpText("after", () => `\n${theme.muted("文档：")} ${formatDocsLink("/cli/sessions", "docs.openclaw.ai/cli/sessions")}\n`).action(async (opts) => {
		await runSessionsListCli(opts);
	});
	sessionsCmd.enablePositionalOptions();
	addSessionsListOptions(sessionsCmd.command("list").description("列出已存储的对话会话")).action(async (opts, command) => {
		const parentOpts = command.parent?.opts();
		await runSessionsListCli(mergeSessionsListOptions(opts, parentOpts));
	});
	sessionsCmd.command("cleanup").description("立即运行会话存储维护").option("--store <path>", "会话存储路径（默认：从配置解析）").option("--agent <id>", "要维护的代理 ID（默认：已配置的默认代理）").option("--all-agents", "在所有已配置代理上运行维护", false).option("--dry-run", "预览维护操作而不写入", false).option("--enforce", "即使配置模式为 warn 也应用维护", false).option("--fix-missing", "移除转录文件缺失的存储条目（绕过年龄/数量保留规则）", false).option("--fix-dm-scope", "Retire stale direct-DM session rows that no longer match session.dmScope=main", false).option("--active-key <key>", "保护此会话键免受预算驱逐").option("--json", "输出 JSON", false).addHelpText("after", () => `\n${theme.heading("示例：")}\n${formatHelpExamples([
		["openclaw sessions cleanup --dry-run", "预览过期/上限清理。"],
		["openclaw sessions cleanup --dry-run --fix-missing", "也预览裁剪转录文件缺失的条目。"],
		["openclaw sessions cleanup --dry-run --fix-dm-scope", "Preview stale direct-DM rows after returning dmScope to main."],
		["openclaw sessions cleanup --enforce", "立即应用维护。"],
		["openclaw sessions cleanup --agent work --dry-run", "预览某个代理的存储。"],
		["openclaw sessions cleanup --all-agents --dry-run", "预览所有代理的存储。"],
		["openclaw sessions cleanup --enforce --store ./tmp/sessions.json", "使用特定的存储。"]
	])}`).action(async (opts, command) => {
		const parentOpts = command.parent?.opts();
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { sessionsCleanupCommand } = await import("./sessions-cleanup-CVDvIuBQ.js");
			await sessionsCleanupCommand({
				store: opts.store ?? parentOpts?.store,
				agent: opts.agent ?? parentOpts?.agent,
				allAgents: Boolean(opts.allAgents || parentOpts?.allAgents),
				dryRun: Boolean(opts.dryRun),
				enforce: Boolean(opts.enforce),
				fixMissing: Boolean(opts.fixMissing),
				fixDmScope: Boolean(opts.fixDmScope),
				activeKey: opts.activeKey,
				json: Boolean(opts.json || parentOpts?.json)
			}, defaultRuntime);
		});
	});
	sessionsCmd.command("tail").description("Tail human-readable session trajectory progress").option("--session-key <key>", "Session key to tail (default: active sessions or latest)").option("--tail <count>", "Number of existing trajectory events to show", "80").option("--follow", "Continue following for new trajectory events", false).option("--store <path>", "会话存储路径（默认：从配置解析）").option("--agent <id>", "要检查的代理 ID（默认：已配置的默认代理）").option("--all-agents", "聚合所有已配置代理的会话", false).action(async (opts, command) => {
		const parentOpts = command.parent?.opts();
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { sessionsTailCommand } = await import("./sessions-tail-D_FBDcvs.js");
			await sessionsTailCommand({
				sessionKey: opts.sessionKey,
				store: opts.store ?? parentOpts?.store,
				agent: opts.agent ?? parentOpts?.agent,
				allAgents: Boolean(opts.allAgents || parentOpts?.allAgents),
				follow: Boolean(opts.follow),
				tail: opts.tail
			}, defaultRuntime);
		});
	});
	sessionsCmd.command("export-trajectory").description("Export a redacted trajectory bundle for a stored session").option("--session-key <key>", "Session key to export").option("--output <path>", "Output directory name inside .openclaw/trajectory-exports").option("--workspace <path>", "Workspace root for the export (default: current directory)").option("--store <path>", "Path to session store (default: resolved from session key)").option("--agent <id>", "Agent id for resolving the default session store").option("--request-json-base64 <payload>", "Base64url-encoded export request").option("--json", "输出 JSON", false).action(async (opts, command) => {
		const parentOpts = command.parent?.opts();
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { exportTrajectoryCommand } = await import("./export-trajectory-Dp2Y1y6Z.js");
			await exportTrajectoryCommand({
				sessionKey: opts.sessionKey,
				output: opts.output,
				workspace: opts.workspace,
				store: opts.store ?? parentOpts?.store,
				agent: opts.agent ?? parentOpts?.agent,
				requestJsonBase64: opts.requestJsonBase64,
				json: Boolean(opts.json || parentOpts?.json)
			}, defaultRuntime);
		});
	});
	const commitmentsCmd = program.command("commitments").description("列出并管理推断出的后续跟进事项").option("--json", "输出 JSON 而非文本", false).option("--agent <id>", "Agent id to inspect").option("--status <status>", "Filter by status (pending, sent, dismissed, snoozed, expired)").option("--all", "Show all statuses", false).addHelpText("after", () => `\n${theme.heading("示例：")}\n${formatHelpExamples([
		["openclaw commitments", "List pending inferred follow-ups."],
		["openclaw commitments --all", "List all inferred follow-ups."],
		["openclaw commitments --agent work", "List one agent's inferred follow-ups."],
		["openclaw commitments dismiss cm_abc123", "Dismiss a follow-up."]
	])}`).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { commitmentsListCommand } = await loadCommitmentsCommands();
			await commitmentsListCommand({
				json: Boolean(opts.json),
				agent: opts.agent,
				status: opts.status,
				all: Boolean(opts.all)
			}, defaultRuntime);
		});
	});
	commitmentsCmd.enablePositionalOptions();
	commitmentsCmd.command("list").description("List inferred follow-up commitments").option("--json", "输出 JSON 而非文本", false).option("--agent <id>", "Agent id to inspect").option("--status <status>", "Filter by status (pending, sent, dismissed, snoozed, expired)").option("--all", "Show all statuses", false).action(async (opts, command) => {
		const parentOpts = command.parent?.opts();
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { commitmentsListCommand } = await loadCommitmentsCommands();
			await commitmentsListCommand({
				json: Boolean(opts.json || parentOpts?.json),
				agent: opts.agent ?? parentOpts?.agent,
				status: opts.status ?? parentOpts?.status,
				all: Boolean(opts.all || parentOpts?.all)
			}, defaultRuntime);
		});
	});
	commitmentsCmd.command("dismiss <ids...>").description("Dismiss inferred follow-up commitments").option("--json", "输出 JSON 而非文本", false).action(async (ids, opts, command) => {
		const parentOpts = command.parent?.opts();
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { commitmentsDismissCommand } = await loadCommitmentsCommands();
			await commitmentsDismissCommand({
				ids,
				json: Boolean(opts.json || parentOpts?.json)
			}, defaultRuntime);
		});
	});
	const tasksCmd = program.command("tasks").description("查看持久化后台任务和 TaskFlow 状态").option("--json", "以 JSON 格式输出", false).option("--runtime <name>", "按种类过滤（subagent、acp、cron、cli）").option("--status <name>", "按状态过滤（queued、running、succeeded、failed、timed_out、cancelled、lost）").action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { tasksListCommand } = await loadTasksCommands();
			await tasksListCommand({
				json: Boolean(opts.json),
				runtime: opts.runtime,
				status: opts.status
			}, defaultRuntime);
		});
	});
	tasksCmd.enablePositionalOptions();
	tasksCmd.command("list").description("列出已跟踪的后台任务").option("--json", "以 JSON 格式输出", false).option("--runtime <name>", "按种类过滤（subagent、acp、cron、cli）").option("--status <name>", "按状态过滤（queued、running、succeeded、failed、timed_out、cancelled、lost）").action(async (opts, command) => {
		const parentOpts = command.parent?.opts();
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { tasksListCommand } = await loadTasksCommands();
			await tasksListCommand({
				json: Boolean(opts.json || parentOpts?.json),
				runtime: opts.runtime ?? parentOpts?.runtime,
				status: opts.status ?? parentOpts?.status
			}, defaultRuntime);
		});
	});
	tasksCmd.command("audit").description("显示过期或损坏的后台任务和 TaskFlow").option("--json", "以 JSON 格式输出", false).option("--severity <level>", "按严重性过滤（warn、error）").option("--code <name>", "按发现码过滤（stale_queued、stale_running、lost、delivery_failed、missing_cleanup、inconsistent_timestamps、restore_failed、stale_waiting、stale_blocked、cancel_stuck、missing_linked_tasks、blocked_task_missing）").option("--limit <n>", "限制显示的发现数量").action(async (opts, command) => {
		const parentOpts = command.parent?.opts();
		const limit = parseTasksAuditLimit(opts.limit);
		if (limit === null) return;
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { tasksAuditCommand } = await loadTasksCommands();
			await tasksAuditCommand({
				json: Boolean(opts.json || parentOpts?.json),
				severity: opts.severity,
				code: opts.code,
				limit
			}, defaultRuntime);
		});
	});
	tasksCmd.command("maintenance").description("预览或应用任务和 TaskFlow 维护").option("--json", "以 JSON 格式输出", false).option("--apply", "应用对账、清理戳记和裁剪", false).action(async (opts, command) => {
		const parentOpts = command.parent?.opts();
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { tasksMaintenanceCommand } = await loadTasksCommands();
			await tasksMaintenanceCommand({
				json: Boolean(opts.json || parentOpts?.json),
				apply: Boolean(opts.apply)
			}, defaultRuntime);
		});
	});
	tasksCmd.command("show").description("通过任务 ID、运行 ID 或会话键显示一个后台任务").argument("<lookup>", "任务 ID、运行 ID 或会话键").option("--json", "以 JSON 格式输出", false).action(async (lookup, opts, command) => {
		const parentOpts = command.parent?.opts();
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { tasksShowCommand } = await loadTasksCommands();
			await tasksShowCommand({
				lookup,
				json: Boolean(opts.json || parentOpts?.json)
			}, defaultRuntime);
		});
	});
	tasksCmd.command("notify").description("设置任务通知策略").argument("<lookup>", "任务 ID、运行 ID 或会话键").argument("<notify>", "通知策略（done_only、state_changes、silent）").action(async (lookup, notify) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { tasksNotifyCommand } = await loadTasksCommands();
			await tasksNotifyCommand({
				lookup,
				notify
			}, defaultRuntime);
		});
	});
	tasksCmd.command("cancel").description("取消运行中的后台任务").argument("<lookup>", "任务 ID、运行 ID 或会话键").action(async (lookup) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { tasksCancelCommand } = await loadTasksCommands();
			await tasksCancelCommand({ lookup }, defaultRuntime);
		});
	});
	const tasksFlowCmd = tasksCmd.command("flow").description("查看 tasks 下的持久化 TaskFlow 状态");
	tasksFlowCmd.command("list").description("列出已跟踪的 TaskFlow").option("--json", "以 JSON 格式输出", false).option("--status <name>", "按状态过滤（queued、running、waiting、blocked、succeeded、failed、cancelled、lost）").action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { flowsListCommand } = await loadFlowsCommands();
			await flowsListCommand({
				json: Boolean(opts.json),
				status: opts.status
			}, defaultRuntime);
		});
	});
	tasksFlowCmd.command("show").description("通过流 ID 或所有者键显示一个 TaskFlow").argument("<lookup>", "流 ID 或所有者键").option("--json", "以 JSON 格式输出", false).action(async (lookup, opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { flowsShowCommand } = await loadFlowsCommands();
			await flowsShowCommand({
				lookup,
				json: Boolean(opts.json)
			}, defaultRuntime);
		});
	});
	tasksFlowCmd.command("cancel").description("取消运行中的 TaskFlow").argument("<lookup>", "流 ID 或所有者键").action(async (lookup) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			const { flowsCancelCommand } = await loadFlowsCommands();
			await flowsCancelCommand({ lookup }, defaultRuntime);
		});
	});
}
//#endregion
export { registerStatusHealthSessionsCommands };
