Close the AGENTS.md "Safety Guardrail & Mutation Preview" coverage gap: every remote-mutating command now supports --dry-run returning structured JSON with preview: true, without executing the mutation. - Domain capabilities gain an optional dryRun param and preview handlers: sealUserCreate/ResetPassword/Delete/Activate/DelegationCreate, sealDelegationRevoke, sealApprovalRuleCreate/Update/Delete/ VersionPublish, sealSimulationBatchClean, sealInsightRecordAnalyze. Previews reuse the shared mutationPreview() diff shape; reads (GET) are allowed to build the before/after, writes never fire. - CLI wiring: users create/delegation/reset-password/delete, rules create/update/delete/publish, simulation delete, analytics analyze, auth link revoke pass dryRun; dry-run bypasses the --yes gate (webhook delete pattern); corps mark previews the local config tag change without writing it. - Shared dryRunOption() helper in parser.ts; help registry documents --dry-run on all covered commands; cli-protocol.md §3 example list updated; cli.md and embedded skill regenerated. - New src/cli/commands/dry-run-gates.test.ts pins the contract: preview JSON on stdout, zero mutating requests (GET-only where reads are needed), config untouched for local previews. Local user-config writes (corps switch/rename, config mode/test-dir/ lint) stay outside this contract: they are reversible local edits with no upstream effect.
98 lines
3.7 KiB
TypeScript
98 lines
3.7 KiB
TypeScript
import { usageError } from "../../core/errors.js";
|
|
import type { CorpConfig } from "../../core/config/types.js";
|
|
import type { createSealClient } from "../../core/http/factory.js";
|
|
import { exportInsightReportToExcel } from "../../domains/seal/insight/export.js";
|
|
import { runCapability } from "../helpers.js";
|
|
import { booleanOption, dryRunOption, numberOption, stringOption } from "../parser.js";
|
|
import { outputOptions, printJson } from "../printer.js";
|
|
import type { ParsedArgs } from "../types.js";
|
|
|
|
export async function handleAnalyticsCommand(
|
|
action: string | undefined,
|
|
maybeName: string | undefined,
|
|
client: Awaited<ReturnType<typeof createSealClient>>,
|
|
corp: CorpConfig,
|
|
args: ParsedArgs
|
|
) {
|
|
if (action === "insight" || action === "insight-stats" || action === "stats") {
|
|
await runCapability(
|
|
"sealInsightStatsGet",
|
|
client,
|
|
corp,
|
|
{
|
|
startDate: stringOption(args.options.startDate) ?? stringOption(args.options["start-date"]),
|
|
endDate: stringOption(args.options.endDate) ?? stringOption(args.options["end-date"]),
|
|
limit: numberOption(args.options.limit)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "risks" || action === "risks-by-tag" || action === "tag-risks") {
|
|
const tagId = maybeName ?? stringOption(args.options.tagId) ?? stringOption(args.options["tag-id"]);
|
|
if (!tagId) {
|
|
throw usageError("Usage: seal-use analytics risks <tagId> [--start-date <ISO>] [--end-date <ISO>] [--corp <corpId>]");
|
|
}
|
|
await runCapability(
|
|
"sealInsightRisksByTagGet",
|
|
client,
|
|
corp,
|
|
{
|
|
tagId,
|
|
startDate: stringOption(args.options.startDate) ?? stringOption(args.options["start-date"]),
|
|
endDate: stringOption(args.options.endDate) ?? stringOption(args.options["end-date"])
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "performance" || action === "perf") {
|
|
await runCapability(
|
|
"sealInsightPerformanceGet",
|
|
client,
|
|
corp,
|
|
{
|
|
startDate: stringOption(args.options.startDate) ?? stringOption(args.options["start-date"]) ?? numberOption(args.options.startDate) ?? numberOption(args.options["start-date"]),
|
|
endDate: stringOption(args.options.endDate) ?? stringOption(args.options["end-date"]) ?? numberOption(args.options.endDate) ?? numberOption(args.options["end-date"])
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "analyze" || action === "reanalyze") {
|
|
const recordId = maybeName ?? stringOption(args.options.recordId) ?? stringOption(args.options["record-id"]);
|
|
if (!recordId) {
|
|
throw usageError("Usage: seal-use analytics analyze <recordId> [--corp <corpId>]");
|
|
}
|
|
await runCapability(
|
|
"sealInsightRecordAnalyze",
|
|
client,
|
|
corp,
|
|
{
|
|
recordId,
|
|
dryRun: dryRunOption(args)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "export" || action === "report" || action === "download") {
|
|
const result = await exportInsightReportToExcel(client, corp, {
|
|
startDate: stringOption(args.options.startDate) ?? stringOption(args.options["start-date"]),
|
|
endDate: stringOption(args.options.endDate) ?? stringOption(args.options["end-date"]),
|
|
limit: numberOption(args.options.limit),
|
|
outputFile: stringOption(args.options.out) ?? stringOption(args.options["output-file"]) ?? stringOption(args.options.outputFile),
|
|
toDownloads: booleanOption(args.options.downloads) ?? booleanOption(args.options["to-downloads"]),
|
|
force: booleanOption(args.options.force)
|
|
});
|
|
printJson(result);
|
|
return;
|
|
}
|
|
|
|
throw usageError(`Unknown analytics command: ${action ?? ""}. Run 'seal-use help' for available commands.`);
|
|
}
|