Refine skill and CLI for business-user centric experience

This commit is contained in:
gitea committed 2026-09-20 11:41:36 +08:00
1 parent 7bbddd7aba
commit b5e6cc0282
8 files changed
+484 -581

No files matched your search

+18
View File
@@ -841,4 +841,22 @@ describe("Hose OpenAPI key extraction from assistance link", () => {
expect(authResult.exitCode).toBe(2);
expect(authResult.stderr).toContain("合思子域专享能力");
});
test("maskCellphone masks standard 11-digit mobile and non-standard phones safely", async () => {
const { maskCellphone } = await import("./corps.js");
expect(maskCellphone("13812345678")).toBe("138****5678");
expect(maskCellphone("19988887777")).toBe("199****7777");
expect(maskCellphone(undefined)).toBe("未绑定手机");
expect(maskCellphone("")).toBe("未绑定手机");
expect(maskCellphone("010123456")).toBe("010****3456");
});
test("RULE_SUMMARY_FIELDS excludes raw internal UUID and prioritizes business fields", async () => {
const { RULE_SUMMARY_FIELDS } = await import("../printer.js");
expect(RULE_SUMMARY_FIELDS).not.toContain("id");
expect(RULE_SUMMARY_FIELDS).toContain("code");
expect(RULE_SUMMARY_FIELDS).toContain("status");
expect(RULE_SUMMARY_FIELDS).toContain("strictness");
expect(RULE_SUMMARY_FIELDS).toContain("scope");
});
});
+36 -9
View File
@@ -1038,6 +1038,25 @@ export async function handleCorpsCommand(action: string | undefined, maybeName:
throw new Error(`Unknown corps command: ${action ?? ""}. Run 'seal-use help' for available commands.`);
}
// ---------------------------------------------------------------------------
// Helpers & Sanitizers
// ---------------------------------------------------------------------------
export function maskCellphone(phone: string | undefined | null): string {
if (!phone) return "未绑定手机";
const cleaned = phone.trim();
if (cleaned.length === 11) {
return `${cleaned.slice(0, 3)}****${cleaned.slice(7)}`;
}
if (cleaned.length >= 7) {
return `${cleaned.slice(0, 3)}****${cleaned.slice(-4)}`;
}
if (cleaned.length > 4) {
return `${cleaned.slice(0, 2)}****${cleaned.slice(-2)}`;
}
return cleaned;
}
// ---------------------------------------------------------------------------
// Hosecloud integration sync helpers
// ---------------------------------------------------------------------------
@@ -1326,12 +1345,16 @@ async function addHoseCorp(input: Record<string, unknown>) {
);
}
} else if (!force) {
const candidates = staffDetails
.map((s) => `${s.name} (${s.cellphone || "no-phone"}, id: ${s.id}, active: ${s.active})`)
.join("\n - ");
const candidateLines = staffDetails
.map((s, idx) => ` [${idx + 1}] ${s.name} (${maskCellphone(s.cellphone)})`)
.join("\n");
throw new Error(
`Missing required parameter: staffId. Found ${staffDetails.length} candidate administrators:\n - ${candidates}\n` +
`Please specify 'staffId', 'staffName', or 'staffPhone' to explicitly select an account (or pass force:true to bypass).`
`Missing required parameter: staffId. 当前企业共配置了 ${staffDetails.length} 位管理员账号(手机号已脱敏):\n\n` +
`${candidateLines}\n\n` +
`👉 请指定要作为审计身份绑定的管理员:\n` +
` • 按姓名选择:追加 --staffName <姓名>(支持关键字,如: --staffName 谢子豪)\n` +
` • 按手机选择:追加 --staffPhone <手机号>(支持手机后4位,如: --staffPhone 5678)\n` +
` • 或传 force:true / --force 自动使用默认首位管理员。`
);
}
}
@@ -1348,7 +1371,7 @@ async function addHoseCorp(input: Record<string, unknown>) {
}
const id = optionalString(input, "id") ?? corpId;
const name = corpName ?? corpId;
let name = nameInput ?? corpName ?? corpId;
const sealUrl = optionalString(input, "sealUrl") ?? `https://${corpId.toLowerCase()}.sealai.cc`;
const config: CorpConfig = {
@@ -1376,7 +1399,11 @@ async function addHoseCorp(input: Record<string, unknown>) {
if (verify) {
clearCorpTokenCache(id);
await resolveLiveSealEnterpriseConfig(config);
const live = await resolveLiveSealEnterpriseConfig(config);
if ((!nameInput || nameInput === corpId) && live.tenantName && live.tenantName !== corpId) {
name = live.tenantName;
config.name = live.tenantName;
}
}
const enterprisesDir = resolveWritableEnterprisesDir();
@@ -1529,7 +1556,7 @@ async function addLinkAsHoseCorp(
appKey: selectedKey.appKey,
appSecurity: selectedKey.appSecurity,
corpId: result.corpId,
name: name ?? result.corpName ?? result.corpId,
name: name ?? result.corpName,
staffId: result.staffId,
overwrite,
force
@@ -1566,7 +1593,7 @@ export async function extractKeysFromLinkAction(
appKey: selectedKey.appKey,
appSecurity: selectedKey.appSecurity,
corpId: result.corpId,
name: options.name ?? result.corpName ?? result.corpId,
name: options.name ?? result.corpName,
staffId: result.staffId,
overwrite: options.overwrite,
force: options.force
+1 -1
View File
@@ -5,7 +5,7 @@ import type { OutputOptions } from "./types.js";
const RULE_LIST_FULL_COUNT_LIMIT = 100;
const RULE_LIST_FULL_BYTES_LIMIT = 120_000;
export const RULE_SUMMARY_FIELDS = ["id", "code", "status", "strictness", "scope", "createdAt", "updatedAt"];
export const RULE_SUMMARY_FIELDS = ["code", "status", "strictness", "scope", "updatedAt"];
const DEFAULT_OUTPUT_BYTES_LIMIT = 200_000;
export function formatConsoleOutput(values: unknown[]): string {
+14 -3
View File
@@ -22,6 +22,7 @@ export interface TenantDoctorDiagnosis {
sourceType: string;
boundCorpId?: string;
boundCorpRole?: "prodParent" | "testTarget";
boundCorpRoleDescription?: string;
};
summary: {
totalChecks: number;
@@ -58,6 +59,11 @@ export async function diagnoseTenantContract(
const environment = corp.environment === "test" ? "test" : "production";
const boundCorpId = environment === "test" ? corp.prodCorpId : corp.testCorpId;
const boundCorpRole = environment === "test" ? "prodParent" : "testTarget";
const boundCorpRoleDescription = boundCorpId
? environment === "test"
? "已绑定生产母企业 (上游配置与样本源)"
: "已绑定测试靶场 (下游隔离演练环境)"
: undefined;
// 1. Auth & Admin Probe
let userDetail: any = null;
@@ -78,6 +84,8 @@ export async function diagnoseTenantContract(
userId: userDetail.id,
userName: userDetail.name,
isAdmin: true,
permissionLevel: "超级管理员(具备完整操作权限)",
tenantName: tenantDetail?.name,
tenantSlug: tenantDetail?.tenantSlug,
permissions: userDetail.permissions
}
@@ -92,6 +100,8 @@ export async function diagnoseTenantContract(
userId: userDetail.id,
userName: userDetail.name,
isAdmin: false,
permissionLevel: "普通用户(部分管理配置受限)",
tenantName: tenantDetail?.name,
permissions: userDetail.permissions
},
recommendation: "建议使用具有管理权限的企业主账号执行规则修改与集成发布"
@@ -301,7 +311,7 @@ export async function diagnoseTenantContract(
name: "测试环境配对契约",
status: "pass",
summary: `测试租户已绑定生产母企业「${boundCorpId}」,具备样本拉取与配置同步能力`,
details: { environment, boundCorpId, boundCorpRole }
details: { environment, boundCorpId, boundCorpRole, boundCorpRoleDescription }
});
} else {
checks.push({
@@ -320,7 +330,7 @@ export async function diagnoseTenantContract(
name: "生产环境安全隔离契约",
status: "pass",
summary: `生产企业已绑定沙箱测试靶场「${boundCorpId}」,回归测试将严格限制在靶场中运行`,
details: { environment, boundCorpId, boundCorpRole }
details: { environment, boundCorpId, boundCorpRole, boundCorpRoleDescription }
});
} else {
checks.push({
@@ -356,7 +366,8 @@ export async function diagnoseTenantContract(
environment,
sourceType: corp.source?.type ?? "native",
boundCorpId,
boundCorpRole
boundCorpRole,
boundCorpRoleDescription
},
summary: {
totalChecks: checks.length,