feat(cli): show acting staff identity per enterprise

- hose-use whoami: 逐企业一行显示执行身份(姓名 + 工号 + 来源)
- corps ls: 新增「员工姓名」列
- context/status 保持全局诊断
This commit is contained in:
gitea committed 2026-10-23 17:54:16 +08:00
1 parent dda9b2c7a0
commit a797196caa
6 files changed
+499 -423

No files matched your search

+424 -419
View File
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -48,7 +48,7 @@ describe("CLI - 上下文自省与 AI PRO 状态命令 (Zero-Source-Reading Cont
expect(data.runtime.configFile).toBeDefined();
});
test("hose-use status 与 whoami 别名成功解析至 context", async () => {
test("hose-use status 解析至 context,whoami 输出逐企业执行身份", async () => {
const resStatus = await runCli(["status", "--json"]);
expect(resStatus.exitCode).toBe(0);
const dataStatus = JSON.parse(resStatus.stdout);
@@ -57,7 +57,7 @@ describe("CLI - 上下文自省与 AI PRO 状态命令 (Zero-Source-Reading Cont
const resWhoami = await runCli(["whoami", "--json"]);
expect(resWhoami.exitCode).toBe(0);
const dataWhoami = JSON.parse(resWhoami.stdout);
expect(dataWhoami.tool).toBe("hose-use");
expect(Array.isArray(dataWhoami.corporations)).toBe(true);
});
test("hose-aipro status 输出 AI PRO 专属上下文", async () => {
+6
View File
@@ -10,11 +10,17 @@ import { ApprovalRepository } from "../../domains/approval/index.js";
import { VERSION } from "../../version.js";
import { formatExpiresAt, formatSourceLabel, formatCorpEnvLabel, printJson } from "../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { handleWhoami } from "./corps/whoami.js";
export async function handleContextCommand(
parsed: CliParsedArgs,
runtime: CliRuntime
): Promise<CliResult> {
// `whoami` 输出按企业逐一列出当前执行身份;`context/status` 保留全局诊断。
const invoked = (parsed.raw ?? []).find((arg) => !arg.startsWith("-"));
if (invoked?.toLowerCase() === "whoami") {
return handleWhoami(parsed, runtime);
}
const currentCorp = runtime.selectedCorp;
const allCorps = runtime.corpContext.listCorps();
const activeAccount = getActiveAccount();
+5 -1
View File
@@ -2,6 +2,7 @@ import { stringOption } from "../../parser.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
import { handleList, handleSearch } from "./query.js";
import { handleSwitch, handleCurrent } from "./context.js";
import { handleWhoami } from "./whoami.js";
import { handleGenerateCorpLink, handleAddLink } from "./link.js";
import { handleAddPersistent, handleExtractKeys, handleElevateCorp, handleSyncFromSeal } from "./credentials.js";
import { handleProbeHose, handleHoseStaffs } from "./probe.js";
@@ -36,8 +37,11 @@ export async function handleCorpsCommand(
case "switch":
case "use":
return handleSwitch(parsed, runtime);
case "current":
case "whoami":
case "identities":
case "identity":
return handleWhoami(parsed, runtime);
case "current":
case "status":
case "active":
return handleCurrent(parsed, runtime);
+2 -1
View File
@@ -233,6 +233,7 @@ export async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Pr
formatCorpEnvLabel(c.env),
c.id,
c.name,
c.staffName || "-",
c.staffId,
formatSourceLabel(c.source, c.hasOpenApi),
formatExpiresAt(c.expiresAt, c.persistent, c.hasOpenApi ? "openapi" : c.source),
@@ -240,7 +241,7 @@ export async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Pr
]);
const table = printTable(
["#", "环境", "企业 ID", "企业名称", "员工工号", "来源", "Token 过期时间", "所属账号"],
["#", "环境", "企业 ID", "企业名称", "员工姓名", "员工工号", "来源", "Token 过期时间", "所属账号"],
rows
);
+60
View File
@@ -0,0 +1,60 @@
import { formatSourceLabel } from "../../printer.js";
import { printJson, printTable } from "../../printer.js";
import type { CliResult, CliRuntime } from "../../types.js";
/**
* `hose-use whoami` — 按企业逐行显示当前执行身份(员工姓名 + 工号)。
*
* 只读本地配置,不发网络请求;写操作前可快速核对“我会以谁的身份执行”。
*/
export async function handleWhoami(_parsed: unknown, runtime: CliRuntime): Promise<CliResult> {
const corps = runtime.corpContext.listCorps();
if (runtime.jsonMode) {
return {
stdout: printJson(
{
activeCorpId: runtime.selectedCorp?.id,
corporations: corps.map((corp: any) => ({
id: corp.id,
name: corp.name,
env: corp.env,
staffId: corp.staffId,
staffName: corp.staffName || null,
source: corp.source,
current: Boolean(corp.current),
})),
},
runtime.outputOptions
),
stderr: "",
exitCode: 0,
};
}
if (corps.length === 0) {
return { stdout: "未配置任何企业,请先运行 hose-use auth login\n", stderr: "", exitCode: 0 };
}
const rows = corps.map((corp: any, index: number) => [
corp.current ? `* ${index + 1}` : ` ${index + 1}`,
corp.name,
corp.id,
corp.staffName || "-",
corp.staffId || "-",
formatSourceLabel(corp.source, corp.hasOpenApi),
]);
const table = printTable(
["#", "企业名称", "企业 ID", "执行身份", "员工工号", "来源"],
rows
);
return {
stdout:
`====== 当前执行身份(共 ${corps.length} 家企业)======\n${table}\n` +
`\n提示: 标记 * 为当前激活企业;写操作前请核对「执行身份」是否为你本人。\n`,
stderr: "",
exitCode: 0,
};
}