From 41e0bfba71e7d7d865b28df0f9feba47a4b03929 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Thu, 22 Oct 2026 12:35:28 +0800 Subject: [PATCH] Report verified personnel names for assistance links --- skills/seal-use/SKILL.md | 2 +- .../references/hose-enterprise-auth.md | 15 ++- src/cli/commands/auth.test.ts | 24 ++++ src/cli/commands/auth.ts | 12 +- src/cli/commands/corps.test.ts | 2 + src/cli/help.ts | 4 +- .../seal/enterprise/assist-identity.test.ts | 109 ++++++++++++++++++ .../seal/enterprise/assist-identity.ts | 64 ++++++++++ 8 files changed, 224 insertions(+), 8 deletions(-) create mode 100644 src/domains/seal/enterprise/assist-identity.test.ts create mode 100644 src/domains/seal/enterprise/assist-identity.ts diff --git a/skills/seal-use/SKILL.md b/skills/seal-use/SKILL.md index 47dc7b7..8a7074b 100644 --- a/skills/seal-use/SKILL.md +++ b/skills/seal-use/SKILL.md @@ -123,7 +123,7 @@ Hose 专属命令应从命令名或选项中明确可见:`auth hose-*`、`appr | --- | --- | --- | | 第一次接入、不会找凭据、需要截图 | `references/first-time-user.md` | 用户交付材料后,再读 `enterprise-onboarding.md` 做来源决策 | | 判断材料来源、Token 边界、cURL、Hose 提权 | `references/enterprise-onboarding.md` | 需要具体域名/员工探测时,再读 `hose-enterprise-init.md` | -| Hose 登录检查、认证失败、生成授权链接 | `references/hose-enterprise-auth.md` | 需要重新接入或判断材料类型时,先读 `enterprise-onboarding.md` | +| Hose 登录检查、认证失败、合思/Seal 协助链接及登录人员身份 | `references/hose-enterprise-auth.md` | 需要重新接入或判断材料类型时,先读 `enterprise-onboarding.md` | | Hose 域名探测、角色/员工发现、管理员选择 | `references/hose-enterprise-init.md` | 不要先加载部署或规则文档 | | 配置、同步或排查发布到 HoseCloud | `references/hose-enterprise-deploy.md` | 涉及生产/测试配对或模拟时,再读 `staging-simulation-workflow.md` | | 生产草稿、测试同步、模拟、回归、发布 | `references/staging-simulation-workflow.md` | 需要客诉证据定界时,再读 `customer-feedback-rule-remediation.md` | diff --git a/skills/seal-use/references/hose-enterprise-auth.md b/skills/seal-use/references/hose-enterprise-auth.md index b3698b8..d231cab 100644 --- a/skills/seal-use/references/hose-enterprise-auth.md +++ b/skills/seal-use/references/hose-enterprise-auth.md @@ -67,8 +67,21 @@ Important: - `seal-use auth check` proves this stage works but redacts the token, so it is not enough when the user needs the actual clickable Hose link. - **Dedicated CLI Command**: Use `seal-use auth hose-link --corp [--expire ] [--force]`. This command directly generates an independent provisional auth link without reading or mutating internal CLI session cache. It supports `--expire` (default `2h`, e.g. `7d` or `7200`). - **Formatting Requirement**: When returning a Hose authorization link (`auth hose-link`) to the user, directly use the CLI JSON output: - 1. The operator identity: directly display the returned `staffId` (or `staffName` if present in output; do NOT make additional network calls or auth checks to search for personal names), + 1. The operator identity: **always report the person's name from `staffName`**. The CLI automatically looks up the exact Hose employee for `auth hose-link`, and the actual Seal session user for `auth link`. Do not use `staffId` as a person's name, infer a name from an ID, or assume both systems use the same person. If `identityStatus` is `unresolved` (`staffName: null`), explicitly report that the identity name could not be verified; do not silently omit it or guess, 2. The exact expiration time in Beijing time (`expiresAt`), 3. BOTH a code block (` ```text ... ``` `) for easy copying without accidental default browser redirection, AND a clickable hyperlink. - **Seal AI Platform Direct Link**: If the user needs a delegation link for the Seal AI audit platform (`https://*.sealai.cc`) instead of Hose/易快报, use `seal-use auth link --corp [--note ]`. +## Assistance link identity and reporting contract + +This contract applies to both `auth hose-link` and `auth link`, including `auth link --from-link`. + +- `staffName` is the verified person's name, or `null`; `identityStatus` is `resolved` / `unresolved`. Identity lookups do not switch the configured employee, modify enterprise configuration, reset a password, or request additional privileges. +- Hose links return `roleNames` from that exact employee's role assignments. `null` means role names could not be verified; an empty array means the employee response explicitly contained no roles. Never infer “主管理员” merely because the CLI can generate a link. +- Seal links return the actual session user's `isAdmin` and `permissions`. Report administrative access only when confirmed by those fields; `null` means the lookup failed. Seal permissions describe Seal access and must not be presented as Hose permissions. +- If an identity lookup fails, the generated link remains usable, the command returns `staffName: null` / `identityStatus: "unresolved"`, and a diagnostic is written to `stderr`. Additional role-lookup failure preserves a verified name but returns `roleNames: null`. Never claim that an unresolved identity is an administrator. +- A user-facing link report must include **enterprise name, person's name, verified role/permissions (or explicitly unknown), target system, and exact Beijing expiration time**. Include both a code block and a clickable link. If returning Hose and Seal links together, report identity and permissions separately for each. +- Do not show raw tokens, full phone numbers, or internal IDs as explanatory prose. Do not fetch or list unrelated administrator candidates just to describe the identity of an existing link. + +Example presentation: “企业:示例公司;合思登录身份:张三(主管理员);有效期至北京时间 …”;“Seal 登录身份:李四(依据 CLI 返回的管理员标记及权限说明);有效期至北京时间 …”。The names may differ; use each command's actual output. + diff --git a/src/cli/commands/auth.test.ts b/src/cli/commands/auth.test.ts index b164e8f..ef4e0d3 100644 --- a/src/cli/commands/auth.test.ts +++ b/src/cli/commands/auth.test.ts @@ -62,6 +62,12 @@ describe("auth links", () => { ? input.toString() : input.url; const url = new URL(requestUrl); + if (url.pathname === "/api/v1/auth/me") { + return Response.json({ data: { + user: { id: "session-user", tenantId: "tenant", name: "当前Seal人员", isAdmin: true, permissions: ["*"] }, + tenant: { id: "tenant", name: "原生 Seal 企业" } + } }); + } if (url.pathname === "/api/v1/delegation/create") { return new Response(JSON.stringify({ data: { @@ -86,10 +92,15 @@ describe("auth links", () => { corpId: "native-corp", corpName: "原生 Seal 企业", staffId: "native-staff", + staffName: "当前Seal人员", + identityStatus: "resolved", + isAdmin: true, + permissions: ["*"], link: "https://native.seal.test/delegation?token=delegation-token", token: "delegation-token" }); expect(parsed.url).toBeUndefined(); + expect(result.stderr).not.toContain("未能核实"); expect(parsed.expiresAt).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+08:00$/); }); @@ -163,6 +174,8 @@ describe("auth links", () => { expiresInHours: 1 }); expect(floorResult.stderr).toContain("已自动向下取整为 1 小时 (1h)"); + expect(JSON.parse(floorResult.stdout)).toMatchObject({ staffName: null, identityStatus: "unresolved", isAdmin: null, permissions: null }); + expect(floorResult.stderr).toContain("未能核实实际登录人员姓名"); // Test reject exceeding 7 days (168 hours) const invalidResult = await runCli(["auth", "link", "--corp", "native-seal", "--expire", "8d"]); @@ -220,6 +233,12 @@ describe("auth links", () => { { status: 200, headers: { "content-type": "application/json" } } ); } + if (url.pathname === "/api/openapi/v1/staffs/getStaffIds") { + return Response.json({ items: [{ id: "HOSE-CORP:STAFF-1", name: "当前合思人员", active: true, roles: [{ roleDefId: "HOSE-CORP:admin" }] }] }); + } + if (url.pathname === "/api/openapi/v1/roleDefGroups") { + return Response.json({ items: [{ id: "system", name: "系统", roleDefs: [{ id: "HOSE-CORP:admin", name: "主管理员" }] }] }); + } return new Response(JSON.stringify({ error: `Unexpected request: ${url.pathname}` }), { status: 404, headers: { "content-type": "application/json" } @@ -234,6 +253,9 @@ describe("auth links", () => { corpId: "HOSE-CORP", corpName: "合思测试企业", staffId: "HOSE-CORP:STAFF-1", + staffName: "当前合思人员", + identityStatus: "resolved", + roleNames: ["主管理员"], link: "https://app.ekuaibao.com/web/thirdparty.html?accessToken=provisional-token-xyz", token: "provisional-token-xyz" }); @@ -315,6 +337,8 @@ describe("auth links", () => { expireDate: 7200 }); expect(result2.stderr).toContain("已按 2 小时 (7200s) 自动换算"); + expect(JSON.parse(result2.stdout)).toMatchObject({ staffName: null, identityStatus: "unresolved", roleNames: null }); + expect(result2.stderr).toContain("未能核实实际登录人员姓名"); }); test("runs auth check and hidden aliases (status, diagnose, test)", async () => { diff --git a/src/cli/commands/auth.ts b/src/cli/commands/auth.ts index 51f5f95..a53ec77 100644 --- a/src/cli/commands/auth.ts +++ b/src/cli/commands/auth.ts @@ -12,6 +12,7 @@ import { CliError, validationError, usageError } from "../../core/errors.js"; import { createSealClient, createSealClientForUrl } from "../../core/http/factory.js"; import { resolveSealCustomHeaders } from "../../core/http/request-headers.js"; import { createDelegation, getMe } from "../../domains/seal/api.js"; +import { resolveHoseLinkIdentity, resolveSealLinkIdentity, summarizeSealLinkIdentity } from "../../domains/seal/enterprise/assist-identity.js"; import { booleanOption, parseDelegationExpireHours, @@ -59,6 +60,7 @@ export async function handleAuthCommand(action: string | undefined, corp: CorpCo const delegation = await createDelegation(client, { note, expiresInHours }); printJson({ + ...summarizeSealLinkIdentity(me.user), tenant: { id: me.tenant.id, name: me.tenant.name, @@ -115,14 +117,15 @@ export async function handleAuthCommand(action: string | undefined, corp: CorpCo console.error(`👉 提示: 企业「${corp.name}」源类型为 Seal 原生测试环境,已自动为您生成委托免登直达链接。`); } const delegationRecord = delegation as Record; - const staffName = "staffName" in corp.source && typeof corp.source.staffName === "string" ? corp.source.staffName : undefined; const expiresAt = formatBeijingIso(Date.now() + expiresInHours * 3600 * 1000); + const identity = await resolveSealLinkIdentity(client); + if (identity.identityStatus === "unresolved") console.error("提示:链接已生成,但未能核实实际登录人员姓名;请勿将 staffId 当作姓名或推断管理员身份。"); printJson({ id: delegationRecord.id, corpId: corp.source.corpId ?? corp.id, corpName: corp.name, staffId: corp.source.staffId, - ...(staffName ? { staffName } : {}), + ...identity, link: delegationRecord.link, expiresAt, token: delegationRecord.token @@ -138,13 +141,14 @@ export async function handleAuthCommand(action: string | undefined, corp: CorpCo booleanOption(args.options.refresh) === true || booleanOption(args.options.f) === true; const provisional = await getHoseProvisionalAuthLink(corp, expiresIn, { force }); - const staffName = "staffName" in corp.source && typeof corp.source.staffName === "string" ? corp.source.staffName : undefined; const expiresAt = formatBeijingIso(Date.now() + expiresIn * 1000); + const identity = await resolveHoseLinkIdentity(corp); + if (identity.identityStatus === "unresolved") console.error("提示:链接已生成,但未能核实实际登录人员姓名;请勿将 staffId 当作姓名或推断管理员身份。"); printJson({ corpId: corp.source.corpId ?? corp.id, corpName: corp.name, staffId: corp.source.staffId, - ...(staffName ? { staffName } : {}), + ...identity, link: provisional.url, expiresAt, token: provisional.token diff --git a/src/cli/commands/corps.test.ts b/src/cli/commands/corps.test.ts index 7a0ad7d..cbb6ca1 100644 --- a/src/cli/commands/corps.test.ts +++ b/src/cli/commands/corps.test.ts @@ -80,6 +80,8 @@ describe("corps link onboarding", () => { expect(result.isError).toBe(false); expect(JSON.parse(result.stdout)).toMatchObject({ + staffName: "Support User", + identityStatus: "resolved", tenant: { corpId: "acme-01", tenantSlug: "acme-01" diff --git a/src/cli/help.ts b/src/cli/help.ts index 96ac128..eaa4c8e 100644 --- a/src/cli/help.ts +++ b/src/cli/help.ts @@ -1037,7 +1037,7 @@ export const HELP_REGISTRY: AreaHelp[] = [ { flag: "--from-link ", description: "直接由合思协助链接换取 Seal 委托直达链接" } ], description: - "生成访问当前企业 Seal AI 智能审核后台 (https://.sealai.cc/delegate) 的免密直达链接。主体作用于 Seal 审核后台。" + "生成访问当前企业 Seal AI 智能审核后台 (https://.sealai.cc/delegate) 的免密直达链接。返回实际会话人员 staffName、identityStatus、isAdmin 和 permissions;姓名查询失败时明确标记为未核实。主体作用于 Seal 审核后台。" }, { name: "link list", @@ -1059,7 +1059,7 @@ export const HELP_REGISTRY: AreaHelp[] = [ { flag: "--force, --refresh, -f", description: "强制向合思 OpenAPI 申请全新临时凭证" } ], description: - "专用于合思 (Hose) 来源企业。向合思申请临时 ticket,生成直达外部合思/易快报主站 (https://app.ekuaibao.com/web/thirdparty.html) 的免密登录链接。若需生成 Seal 自身的审核后台访问链接,请使用 'seal-use auth link'。" + "专用于合思 (Hose) 来源企业。向合思申请临时 ticket,生成直达外部合思/易快报主站 (https://app.ekuaibao.com/web/thirdparty.html) 的免密登录链接。自动查询绑定员工的 staffName、identityStatus 和 roleNames;未能核实的姓名或角色明确标记为未知。若需生成 Seal 自身的审核后台访问链接,请使用 'seal-use auth link'。" }, { name: "hose-openapi-token", diff --git a/src/domains/seal/enterprise/assist-identity.test.ts b/src/domains/seal/enterprise/assist-identity.test.ts new file mode 100644 index 0000000..b6c6e9b --- /dev/null +++ b/src/domains/seal/enterprise/assist-identity.test.ts @@ -0,0 +1,109 @@ +import { afterEach, beforeEach, describe, expect, test } from "bun:test" +import { mkdtempSync, rmSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" +import type { KyInstance } from "ky" +import { CorpConfigSchema } from "../../../core/config/types.js" +import { resolveHoseLinkIdentity, resolveSealLinkIdentity } from "./assist-identity.js" + +const originalFetch = globalThis.fetch +const originalStore = process.env.SEAL_USE_TOKEN_STORE +let dir: string +let requests: Array<{ path: string; body?: unknown }> +let staffItems: unknown[] +let roleResponseFails: boolean +let staffResponseFails: boolean + +beforeEach(() => { + dir = mkdtempSync(join(tmpdir(), "seal-assist-identity-")) + process.env.SEAL_USE_TOKEN_STORE = join(dir, "tokens.json") + requests = [] + staffItems = [{ id: "CORP:STAFF", name: "实际合思员工", roles: [{ roleDefId: "CORP:admin" }] }] + roleResponseFails = false + staffResponseFails = false + globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { + const request = new Request(input, init) + const path = new URL(request.url).pathname + const body = request.method === "POST" ? await request.json() : undefined + requests.push({ path, body }) + if (path === "/api/openapi/v1/auth/getAccessToken") return Response.json({ value: { accessToken: "test-openapi", expireTime: 7200 } }) + if (path === "/api/openapi/v1/staffs/getStaffIds") { + return staffResponseFails ? Response.json({ error: "unavailable" }, { status: 403 }) : Response.json({ items: staffItems }) + } + if (path === "/api/openapi/v1/roleDefGroups") { + return roleResponseFails ? Response.json({ error: "unavailable" }, { status: 403 }) : Response.json({ items: [ + { id: "roles", name: "系统角色", roleDefs: [{ id: "CORP:admin", name: "主管理员" }] } + ] }) + } + throw new Error(`Unexpected identity request: ${path}`) + }) as typeof fetch +}) + +afterEach(() => { + globalThis.fetch = originalFetch + if (originalStore === undefined) delete process.env.SEAL_USE_TOKEN_STORE + else process.env.SEAL_USE_TOKEN_STORE = originalStore + rmSync(dir, { recursive: true, force: true }) +}) + +function hoseCorp(staffId = "STAFF") { + return CorpConfigSchema.parse({ + id: "identity-test", name: "Fixture", seal: {}, + source: { type: "hose", corpId: "CORP", staffId, domain: "https://hose.example.test", appKey: "key", appSecurity: "secret" } + }) +} + +describe("assistance link identity", () => { + test("resolves the exact Hose employee and verified role, without unrelated staff or link requests", async () => { + const identity = await resolveHoseLinkIdentity(hoseCorp()) + expect(identity).toEqual({ staffName: "实际合思员工", identityStatus: "resolved", roleNames: ["主管理员"] }) + expect(requests.find(request => request.path.endsWith("getStaffIds"))?.body).toEqual({ type: "STAFFID", conditionIds: ["CORP:STAFF"] }) + expect(requests.map(request => request.path)).toEqual([ + "/api/openapi/v1/auth/getAccessToken", "/api/openapi/v1/staffs/getStaffIds", "/api/openapi/v1/roleDefGroups" + ]) + }) + + test("canonicalizes bare and qualified staff IDs but rejects other companies and ambiguous matches", async () => { + staffItems = [{ id: "STAFF", name: "短ID员工", roles: [] }] + expect(await resolveHoseLinkIdentity(hoseCorp("CORP:STAFF"))).toMatchObject({ staffName: "短ID员工", roleNames: [] }) + for (const items of [ + [{ id: "OTHER:STAFF", name: "其他企业员工" }], + [{ id: "CORP:OTHER", name: "其他管理员" }], + [{ id: "STAFF", name: "甲" }, { id: "CORP:STAFF", name: "乙" }], + [{ id: "STAFF", name: " " }] + ]) { + staffItems = items + expect(await resolveHoseLinkIdentity(hoseCorp())).toEqual({ staffName: null, identityStatus: "unresolved", roleNames: null }) + } + }) + + test("role lookup failure and unknown role IDs preserve a verified name without inventing permissions", async () => { + roleResponseFails = true + expect(await resolveHoseLinkIdentity(hoseCorp())).toEqual({ staffName: "实际合思员工", identityStatus: "resolved", roleNames: null }) + roleResponseFails = false + staffItems = [{ id: "STAFF", name: "员工", roles: [{ roleDefId: "not-visible" }] }] + expect(await resolveHoseLinkIdentity(hoseCorp())).toEqual({ staffName: "员工", identityStatus: "resolved", roleNames: null }) + }) + + test("missing staff visibility is explicitly unresolved", async () => { + staffResponseFails = true + expect(await resolveHoseLinkIdentity(hoseCorp())).toEqual({ staffName: null, identityStatus: "unresolved", roleNames: null }) + }) + + test("Seal identity comes from the actual session and includes its own permission scope", async () => { + const client = { get: () => ({ json: async () => ({ data: { + user: { id: "seal-user", tenantId: "tenant", name: "Seal实际人员", isAdmin: true, permissions: ["*"] }, + tenant: { id: "tenant", name: "企业" } + } }) }) } as unknown as KyInstance + expect(await resolveSealLinkIdentity(client)).toEqual({ + staffName: "Seal实际人员", identityStatus: "resolved", isAdmin: true, permissions: ["*"] + }) + }) + + test("Seal identity failure returns unknown values, not a guessed employee or administrator", async () => { + const client = { get: () => { throw new Error("private upstream details") } } as unknown as KyInstance + expect(await resolveSealLinkIdentity(client)).toEqual({ + staffName: null, identityStatus: "unresolved", isAdmin: null, permissions: null + }) + }) +}) diff --git a/src/domains/seal/enterprise/assist-identity.ts b/src/domains/seal/enterprise/assist-identity.ts new file mode 100644 index 0000000..82064c1 --- /dev/null +++ b/src/domains/seal/enterprise/assist-identity.ts @@ -0,0 +1,64 @@ +import type { KyInstance } from "ky" +import { ensureHoseOpenapiToken, fetchHoseRoleDefGroups, fetchHoseStaffDetails } from "../../../core/auth/hose.js" +import type { CorpConfig } from "../../../core/config/types.js" +import { getMe } from "../api.js" +import type { MeData } from "../types.js" + +type LinkIdentity = { + staffName: string | null; + identityStatus: "resolved" | "unresolved"; +} + +/** Use the actual Seal session user, which may differ from the configured Hose employee. */ +export function summarizeSealLinkIdentity(user: MeData["user"]) { + const staffName = user.name.trim() || null + return { + staffName, + identityStatus: staffName ? "resolved" as const : "unresolved" as const, + isAdmin: user.isAdmin, + permissions: user.permissions + } +} + +export async function resolveSealLinkIdentity(client: KyInstance) { + try { + return summarizeSealLinkIdentity((await getMe(client)).user) + } catch { + // Identity enrichment must not discard an otherwise valid assistance link. + return { staffName: null, identityStatus: "unresolved" as const, isAdmin: null, permissions: null } + } +} + +export async function resolveHoseLinkIdentity(corp: CorpConfig): Promise { + const unresolved = { staffName: null, identityStatus: "unresolved" as const, roleNames: null } + if (corp.source.type !== "hose") return unresolved + const source = corp.source + const canonicalId = (id: string) => id.includes(":") ? id : `${source.corpId}:${id}` + const targetId = canonicalId(source.staffId) + try { + const token = await ensureHoseOpenapiToken(corp) + const staffs = await fetchHoseStaffDetails(source.domain, token, [targetId]) + const matches = staffs.filter(staff => typeof staff.id === "string" && canonicalId(staff.id) === targetId) + const staff = matches.length === 1 ? matches[0] : undefined + if (!staff || typeof staff.name !== "string" || !staff.name.trim()) return unresolved + + let roleNames: string[] | null = null + if (Array.isArray(staff.roles)) { + if (staff.roles.length === 0) roleNames = [] + else { + try { + const roles = (await fetchHoseRoleDefGroups(source.domain, token)).flatMap(group => group.roleDefs) + const names = staff.roles.map(role => roles.find(item => item.id === role.roleDefId)?.name) + if (names.every((name): name is string => typeof name === "string" && name.trim().length > 0)) { + roleNames = [...new Set(names)] + } + } catch { + // Missing role visibility does not make a verified employee name unknown. + } + } + } + return { staffName: staff.name.trim(), identityStatus: "resolved", roleNames } + } catch { + return unresolved + } +}