Refactor seal tools into modular domains and fix layer inversions

- Split monolithic tools.ts (4,257 lines) into 11 domain-specific modules in src/domains/seal/tools/
- Extract helpers.ts containing 71 helper functions and shared tool types
- Retain tools.ts as thin re-export for complete backward compatibility
- Fix layer inversions: sink CliError to core/errors.ts, extract linter paths to core/paths.ts, move tenant-diagnose to domain
- Eliminate null as any in runner.ts by widening signatures and adding proper runtime guards
- Rebuild dist/mcp/server.js to satisfy pre-push bundle gate
This commit is contained in:
gitea committed 2026-09-22 16:36:37 +08:00
1 parent d868a29c5d
commit ab9b9965e9
26 files changed
+6375 -4983

No files matched your search

+36 -32
View File
@@ -33,43 +33,47 @@ export async function handleAuthExtractKeysCommand(maybeName: string | undefined
});
}
export async function handleAuthCommand(action: string | undefined, corp: CorpConfig, args: ParsedArgs) {
export async function handleAuthCommand(action: string | undefined, corp: CorpConfig | null, args: ParsedArgs) {
const subAction = args.command[2]?.toLowerCase();
const fromLink = stringOption(args.options["from-link"]) ?? (subAction === "from-link" ? args.command[3] : undefined);
if ((action === "seal-link" || action === "link" || (action === "hose-link" && corp?.source?.type === "seal")) && fromLink) {
const note = stringOption(args.options.note);
const session = await exchangeHoseAssistLink(fromLink);
const client = createSealClientForUrl(session.sealUrl, session.token);
const me = await getMe(client);
assertHoseAssistTenantMatches(session.corpId, me.tenant as unknown as Record<string, unknown>);
const delegation = await createDelegation(client, { note });
printJson({
tenant: {
id: me.tenant.id,
name: me.tenant.name,
tenantSlug: me.tenant.tenantSlug,
corpId: session.corpId
},
user: {
id: me.user.id,
name: me.user.name,
providerUserId: me.user.providerUserId,
isAdmin: me.user.isAdmin
},
delegation,
expiresIn: session.expiresIn
});
return;
}
if (!corp) {
throw new Error(`auth ${action ?? ""} requires an enterprise. Provide --corp <id> or select one.`);
}
if (action === "check" || action === "diagnose" || action === "status" || action === "test" || action === "doctor") {
printJson(await diagnoseAuth(corp));
return;
}
if (action === "seal-link" || action === "link" || (action === "hose-link" && corp?.source?.type === "seal")) {
const subAction = args.command[2]?.toLowerCase();
const fromLink = stringOption(args.options["from-link"]) ?? (subAction === "from-link" ? args.command[3] : undefined);
if (fromLink) {
const note = stringOption(args.options.note);
const session = await exchangeHoseAssistLink(fromLink);
const client = createSealClientForUrl(session.sealUrl, session.token);
const me = await getMe(client);
assertHoseAssistTenantMatches(session.corpId, me.tenant as unknown as Record<string, unknown>);
const delegation = await createDelegation(client, { note });
printJson({
tenant: {
id: me.tenant.id,
name: me.tenant.name,
tenantSlug: me.tenant.tenantSlug,
corpId: session.corpId
},
user: {
id: me.user.id,
name: me.user.name,
providerUserId: me.user.providerUserId,
isAdmin: me.user.isAdmin
},
delegation,
expiresIn: session.expiresIn
});
return;
}
if (action === "seal-link" || action === "link" || (action === "hose-link" && corp.source?.type === "seal")) {
const client = await createSealClient(corp);
if (subAction === "list") {
+20 -14
View File
@@ -28,18 +28,24 @@ import type { ParsedArgs } from "../types.js";
export async function handleRulesCommand(
action: string | undefined,
maybeName: string | undefined,
client: Awaited<ReturnType<typeof createSealClient>>,
client: Awaited<ReturnType<typeof createSealClient>> | null,
corp: CorpConfig,
args: ParsedArgs
) {
// lint, linters, and map actions can run without a network client
const clientless = action === "lint" || action === "linters" || action === "linter-list" || action === "map";
if (!client && !clientless) {
throw new Error(`rules ${action ?? ""} requires an authenticated enterprise. Run 'seal-use corps list' to select one.`);
}
if (action === "count") {
await runTool("seal_approval_rules_list", client, corp, { countOnly: true }, outputOptions(args.options));
await runTool("seal_approval_rules_list", client!, corp, { countOnly: true }, outputOptions(args.options));
return;
}
if (action === "list") {
if (booleanOption(args.options.count)) {
await runTool("seal_approval_rules_list", client, corp, { countOnly: true }, outputOptions(args.options));
await runTool("seal_approval_rules_list", client!, corp, { countOnly: true }, outputOptions(args.options));
return;
}
@@ -48,7 +54,7 @@ export async function handleRulesCommand(
if (booleanOption(args.options.summary)) {
await runTool(
"seal_approval_rules_list",
client,
client!,
corp,
{
fields: RULE_SUMMARY_FIELDS,
@@ -60,7 +66,7 @@ export async function handleRulesCommand(
return;
}
const result = await runToolResult("seal_approval_rules_list", client, corp, { limit, offset });
const result = await runToolResult("seal_approval_rules_list", client!, corp, { limit, offset });
const output = outputOptions(args.options);
protectLargeRuleListOutput(result, output.allowFull === true || Boolean(output.outputFile));
printJson(result, output);
@@ -76,7 +82,7 @@ export async function handleRulesCommand(
`seal-use rules clear --corp ${corp.id} --dry-run`
);
}
const result = await runToolResult("seal_approval_rules_clear", client, corp, {
const result = await runToolResult("seal_approval_rules_clear", client!, corp, {
dryRun,
recode: booleanOption(args.options.recode)
});
@@ -95,7 +101,7 @@ export async function handleRulesCommand(
}
if (action === "versions") {
await runTool("seal_approval_rule_versions_list", client, corp, {}, outputOptions(args.options));
await runTool("seal_approval_rule_versions_list", client!, corp, {}, outputOptions(args.options));
return;
}
@@ -104,7 +110,7 @@ export async function handleRulesCommand(
if (!version) throw new Error("Usage: seal-use rules version <versionId|versionNumber|latest>");
await runTool(
"seal_approval_rule_version_get",
client,
client!,
corp,
parseRuleVersionSelector(version),
outputOptions(args.options)
@@ -121,7 +127,7 @@ export async function handleRulesCommand(
const singleSelector = args.command[4];
await runTool(
"seal_approval_rule_version_diff",
client,
client!,
corp,
{
from,
@@ -142,7 +148,7 @@ export async function handleRulesCommand(
const code = rawCode ? (rawCode.startsWith("#") || rawCode.startsWith("rule-") ? rawCode : (rawCode.match(/^\d+$/) ? `#${rawCode.padStart(4, "0")}` : rawCode)) : undefined;
await runTool(
"seal_approval_rule_get",
client,
client!,
corp,
{
...ruleVersionGetOptions(stringOption(args.options.version)),
@@ -160,7 +166,7 @@ export async function handleRulesCommand(
if (!keyword) throw new Error("Usage: seal-use rules search <keyword> [--version <versionId|versionNumber|latest>]");
await runTool(
"seal_approval_search",
client,
client!,
corp,
{
keywords: [keyword],
@@ -183,7 +189,7 @@ export async function handleRulesCommand(
const out = stringOption(args.options.out) ?? stringOption(args.options.file) ?? stringOption(args.options.f);
await runTool(
"seal_approval_rules_pull",
client,
client!,
corp,
{
version,
@@ -203,7 +209,7 @@ export async function handleRulesCommand(
const result = await runToolResult(
"seal_approval_rules_push",
client,
client!,
corp,
{
file,
@@ -231,7 +237,7 @@ export async function handleRulesCommand(
if (action === "lint") {
await runTool(
"seal_approval_rules_lint",
client,
client as Awaited<ReturnType<typeof createSealClient>>,
corp,
{
file: stringOption(args.options.file) ?? stringOption(args.options.f),