import { readFileSync } from "node:fs"; import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runTool } from "../helpers.js"; import { jsonObject, stringOption } from "../parser.js"; import { outputOptions } from "../printer.js"; import type { ParsedArgs } from "../types.js"; export async function handlePreferenceCommand( action: string | undefined, subAction: string | undefined, thirdAction: string | undefined, maybeTarget: string | undefined, client: Awaited>, corp: CorpConfig, args: ParsedArgs ) { if (!action || action === "get") { await runTool("seal_preference_get", client, corp, {}, outputOptions(args.options)); return; } if (action === "decision") { if (subAction === "update" || !subAction) { const rawInput = stringOption(args.options.input); const payload = rawInput ? JSON.parse(readFileSync(rawInput, "utf8")) : jsonObject(args.json); if (!payload || Object.keys(payload).length === 0) { throw new Error("Usage: seal-use preference decision update --json '{\"explicitApprove\":\"...\"}'"); } await runTool("seal_preference_decision_update", client, corp, payload, outputOptions(args.options)); return; } } if (action === "thinking-depth" || action === "thinkingDepth") { if (subAction === "set") { const defaultLevel = stringOption(args.options.default) ?? stringOption(args.options.level) ?? maybeTarget; if (defaultLevel !== "medium" && defaultLevel !== "high") { throw new Error("Usage: seal-use preference thinking-depth set --default "); } await runTool("seal_preference_thinking_depth_set", client, corp, { defaultLevel }, outputOptions(args.options)); return; } if (subAction === "policies") { if (thirdAction === "list" || !thirdAction) { await runTool("seal_preference_thinking_depth_policies_list", client, corp, {}, outputOptions(args.options)); return; } if (thirdAction === "upsert") { const rawInput = stringOption(args.options.input); const payload = rawInput ? JSON.parse(readFileSync(rawInput, "utf8")) : jsonObject(args.json); if (!payload || !payload.id || !payload.name) { throw new Error("Usage: seal-use preference thinking-depth policies upsert --json '{\"id\":\"...\",\"name\":\"...\",\"level\":\"high\"}'"); } await runTool("seal_preference_thinking_depth_policies_upsert", client, corp, payload, outputOptions(args.options)); return; } if (thirdAction === "remove" || thirdAction === "delete") { const policyId = maybeTarget ?? stringOption(args.options.id) ?? stringOption(args.options.policyId); if (!policyId) { throw new Error("Usage: seal-use preference thinking-depth policies remove "); } await runTool("seal_preference_thinking_depth_policies_remove", client, corp, { policyId }, outputOptions(args.options)); return; } } } throw new Error(`Unknown preference action: ${action ?? ""}. Available: get, decision update, thinking-depth set, thinking-depth policies list/upsert/remove.`); }