Files
seal-use/src/cli/commands/preference.ts
T
gitea ca9d87e13f Group CLI modules into parse, run, output, and help
Move parser, tokenize, and area-aliases under cli/parse; runner and read-only under cli/run; printer under cli/output; help plus the docs/naming contract tests under cli/help. types.ts and helpers.ts stay at the cli root. Update imports, the app-root depth calculation, test fixtures, and the CLI doc generator path. No behavior change.
2026-11-19 16:38:14 +08:00

94 lines
3.8 KiB
TypeScript

import { usageError } from "../../core/errors.js";
import { readFileSync } from "node:fs";
import type { CorpConfig } from "../../core/config/types.js";
import type { createSealClient } from "../../core/http/factory.js";
import { runCapability } from "../helpers.js";
import { booleanOption, jsonObject, stringOption } from "../parse/parser.js";
import { outputOptions } from "../output/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<ReturnType<typeof createSealClient>>,
corp: CorpConfig,
args: ParsedArgs
) {
if (!action || action === "get") {
await runCapability("sealPreferenceGet", 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 usageError("Usage: seal-use preference decision update --json '{\"explicitApprove\":\"...\"}'");
}
await runCapability("sealPreferenceDecisionUpdate", client, corp, {
...payload,
dryRun: booleanOption(args.options.dryRun) ?? booleanOption(args.options["dry-run"])
}, 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 usageError("Usage: seal-use preference thinking-depth set --default <medium|high>");
}
await runCapability("sealPreferenceThinkingDepthSet", client, corp, {
defaultLevel,
dryRun: booleanOption(args.options.dryRun) ?? booleanOption(args.options["dry-run"])
}, outputOptions(args.options));
return;
}
if (subAction === "policies") {
if (thirdAction === "list" || !thirdAction) {
await runCapability("sealPreferenceThinkingDepthPoliciesList", 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 usageError("Usage: seal-use preference thinking-depth policies upsert --json '{\"id\":\"...\",\"name\":\"...\",\"level\":\"high\"}'");
}
await runCapability("sealPreferenceThinkingDepthPoliciesUpsert", client, corp, {
...payload,
dryRun: booleanOption(args.options.dryRun) ?? booleanOption(args.options["dry-run"])
}, outputOptions(args.options));
return;
}
if (thirdAction === "remove" || thirdAction === "delete") {
const policyId = maybeTarget ?? stringOption(args.options.id) ?? stringOption(args.options.policyId);
if (!policyId) {
throw usageError("Usage: seal-use preference thinking-depth policies remove <policyId>");
}
await runCapability("sealPreferenceThinkingDepthPoliciesRemove", client, corp, {
policyId,
dryRun: booleanOption(args.options.dryRun) ?? booleanOption(args.options["dry-run"])
}, outputOptions(args.options));
return;
}
}
}
throw usageError(`Unknown preference action: ${action ?? ""}. Available: get, decision update, thinking-depth set, thinking-depth policies list/upsert/remove.`);
}