ali-skills 0.0.30 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -440,8 +440,22 @@ function getGitUserConfig() {
|
|
|
440
440
|
return null;
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
|
+
function getBucUser() {
|
|
444
|
+
try {
|
|
445
|
+
const authFile = join(homedir(), ".ali-skills", "auth.json");
|
|
446
|
+
if (!existsSync(authFile)) return null;
|
|
447
|
+
const auth = JSON.parse(readFileSync(authFile, "utf-8"));
|
|
448
|
+
if (!auth.account) return null;
|
|
449
|
+
return {
|
|
450
|
+
username: auth.name || auth.account,
|
|
451
|
+
email: `${auth.account}@alibaba-inc.com`
|
|
452
|
+
};
|
|
453
|
+
} catch {
|
|
454
|
+
return null;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
443
457
|
function getCurrentUser() {
|
|
444
|
-
return getGitUserConfig();
|
|
458
|
+
return getBucUser() ?? getGitUserConfig();
|
|
445
459
|
}
|
|
446
460
|
var GitCloneError = class extends Error {
|
|
447
461
|
url;
|
|
@@ -2340,7 +2354,7 @@ function logSkillParseFailures(failures) {
|
|
|
2340
2354
|
if (f.hint) M.message(import_picocolors.default.yellow(` 提示: ${f.hint}`));
|
|
2341
2355
|
}
|
|
2342
2356
|
}
|
|
2343
|
-
var version$1 = "2.0.
|
|
2357
|
+
var version$1 = "2.0.33";
|
|
2344
2358
|
const isCancelled$1 = (value) => typeof value === "symbol";
|
|
2345
2359
|
function redactSensitiveText(text) {
|
|
2346
2360
|
return text.replace(/(https?:\/\/)([^/\s:@]+)(?::([^@/\s]*))?@/gi, "$1").replace(/([?&](?:private_token|access_token|token|api_key|access_key|secret|password)=)[^&\s]+/gi, "$1***");
|
|
@@ -2368,7 +2382,7 @@ function socketLabel(audit) {
|
|
|
2368
2382
|
const count = audit.alerts ?? 0;
|
|
2369
2383
|
return count > 0 ? import_picocolors.default.red(`${count} alert${count !== 1 ? "s" : ""}`) : import_picocolors.default.green("0 alerts");
|
|
2370
2384
|
}
|
|
2371
|
-
function padEnd(str, width) {
|
|
2385
|
+
function padEnd$1(str, width) {
|
|
2372
2386
|
const visible = str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
2373
2387
|
const pad = Math.max(0, width - visible.length);
|
|
2374
2388
|
return str + " ".repeat(pad);
|
|
@@ -2381,7 +2395,7 @@ function buildSecurityLines(auditData, skills, source) {
|
|
|
2381
2395
|
})) return [];
|
|
2382
2396
|
const nameWidth = Math.min(Math.max(...skills.map((s) => s.displayName.length)), 36);
|
|
2383
2397
|
const lines = [];
|
|
2384
|
-
const header = padEnd("", nameWidth + 2) + padEnd(import_picocolors.default.dim("Gen"), 18) + padEnd(import_picocolors.default.dim("Socket"), 18) + import_picocolors.default.dim("Snyk");
|
|
2398
|
+
const header = padEnd$1("", nameWidth + 2) + padEnd$1(import_picocolors.default.dim("Gen"), 18) + padEnd$1(import_picocolors.default.dim("Socket"), 18) + import_picocolors.default.dim("Snyk");
|
|
2385
2399
|
lines.push(header);
|
|
2386
2400
|
for (const skill of skills) {
|
|
2387
2401
|
const data = auditData[skill.slug];
|
|
@@ -2389,7 +2403,7 @@ function buildSecurityLines(auditData, skills, source) {
|
|
|
2389
2403
|
const ath = data?.ath ? riskLabel(data.ath.risk) : import_picocolors.default.dim("--");
|
|
2390
2404
|
const socket = data?.socket ? socketLabel(data.socket) : import_picocolors.default.dim("--");
|
|
2391
2405
|
const snyk = data?.snyk ? riskLabel(data.snyk.risk) : import_picocolors.default.dim("--");
|
|
2392
|
-
lines.push(padEnd(import_picocolors.default.cyan(name), nameWidth + 2) + padEnd(ath, 18) + padEnd(socket, 18) + snyk);
|
|
2406
|
+
lines.push(padEnd$1(import_picocolors.default.cyan(name), nameWidth + 2) + padEnd$1(ath, 18) + padEnd$1(socket, 18) + snyk);
|
|
2393
2407
|
}
|
|
2394
2408
|
lines.push("");
|
|
2395
2409
|
lines.push(`${import_picocolors.default.dim("Details:")} ${import_picocolors.default.dim(`https://skills.sh/${source}`)}`);
|
|
@@ -3564,9 +3578,9 @@ function parseAddOptions(args) {
|
|
|
3564
3578
|
options
|
|
3565
3579
|
};
|
|
3566
3580
|
}
|
|
3567
|
-
const RESET$
|
|
3568
|
-
const BOLD$
|
|
3569
|
-
const DIM$
|
|
3581
|
+
const RESET$6 = "\x1B[0m";
|
|
3582
|
+
const BOLD$3 = "\x1B[1m";
|
|
3583
|
+
const DIM$6 = "\x1B[38;5;102m";
|
|
3570
3584
|
const TEXT$5 = "\x1B[38;5;145m";
|
|
3571
3585
|
const CYAN$1 = "\x1B[36m";
|
|
3572
3586
|
const YELLOW$5 = "\x1B[33m";
|
|
@@ -3622,29 +3636,29 @@ async function runSearchPrompt(initialQuery = "") {
|
|
|
3622
3636
|
if (lastRenderedLines > 0) process.stdout.write(MOVE_UP(lastRenderedLines) + MOVE_TO_COL(1));
|
|
3623
3637
|
process.stdout.write(CLEAR_DOWN);
|
|
3624
3638
|
const lines = [];
|
|
3625
|
-
const cursor = `${BOLD$
|
|
3626
|
-
lines.push(`${TEXT$5}Search skills:${RESET$
|
|
3639
|
+
const cursor = `${BOLD$3}_${RESET$6}`;
|
|
3640
|
+
lines.push(`${TEXT$5}Search skills:${RESET$6} ${query}${cursor}`);
|
|
3627
3641
|
lines.push("");
|
|
3628
|
-
if (!query || query.length < 2) lines.push(`${DIM$
|
|
3629
|
-
else if (results.length === 0 && loading) lines.push(`${DIM$
|
|
3630
|
-
else if (results.length === 0) lines.push(`${DIM$
|
|
3642
|
+
if (!query || query.length < 2) lines.push(`${DIM$6}Start typing to search (min 2 chars)${RESET$6}`);
|
|
3643
|
+
else if (results.length === 0 && loading) lines.push(`${DIM$6}Searching...${RESET$6}`);
|
|
3644
|
+
else if (results.length === 0) lines.push(`${DIM$6}No skills found${RESET$6}`);
|
|
3631
3645
|
else {
|
|
3632
3646
|
const visible = results.slice(0, 8);
|
|
3633
3647
|
for (let i = 0; i < visible.length; i++) {
|
|
3634
3648
|
const skill = visible[i];
|
|
3635
3649
|
const isSelected = i === selectedIndex;
|
|
3636
|
-
const arrow = isSelected ? `${BOLD$
|
|
3637
|
-
const name = isSelected ? `${BOLD$
|
|
3638
|
-
const source = skill.source ? ` ${DIM$
|
|
3650
|
+
const arrow = isSelected ? `${BOLD$3}>${RESET$6}` : " ";
|
|
3651
|
+
const name = isSelected ? `${BOLD$3}${skill.name}${RESET$6}` : `${TEXT$5}${skill.name}${RESET$6}`;
|
|
3652
|
+
const source = skill.source ? ` ${DIM$6}${skill.source}${RESET$6}` : "";
|
|
3639
3653
|
const installs = formatInstalls(skill.installs);
|
|
3640
|
-
const installsBadge = installs ? ` ${CYAN$1}${installs}${RESET$
|
|
3641
|
-
const githubBadge = skill.sourceType === "github" ? ` ${YELLOW$5}GitHub${RESET$
|
|
3642
|
-
const loadingIndicator = loading && i === 0 ? ` ${DIM$
|
|
3654
|
+
const installsBadge = installs ? ` ${CYAN$1}${installs}${RESET$6}` : "";
|
|
3655
|
+
const githubBadge = skill.sourceType === "github" ? ` ${YELLOW$5}GitHub${RESET$6}` : "";
|
|
3656
|
+
const loadingIndicator = loading && i === 0 ? ` ${DIM$6}...${RESET$6}` : "";
|
|
3643
3657
|
lines.push(` ${arrow} ${name}${source}${githubBadge}${installsBadge}${loadingIndicator}`);
|
|
3644
3658
|
}
|
|
3645
3659
|
}
|
|
3646
3660
|
lines.push("");
|
|
3647
|
-
lines.push(`${DIM$
|
|
3661
|
+
lines.push(`${DIM$6}up/down navigate | enter select | esc cancel${RESET$6}`);
|
|
3648
3662
|
for (const line of lines) process.stdout.write(line + "\n");
|
|
3649
3663
|
lastRenderedLines = lines.length;
|
|
3650
3664
|
}
|
|
@@ -3728,9 +3742,9 @@ async function runSearchPrompt(initialQuery = "") {
|
|
|
3728
3742
|
async function runFind(args) {
|
|
3729
3743
|
const query = args.join(" ");
|
|
3730
3744
|
const isNonInteractive = !process.stdin.isTTY;
|
|
3731
|
-
const agentTip = `${DIM$
|
|
3732
|
-
${DIM$
|
|
3733
|
-
${DIM$
|
|
3745
|
+
const agentTip = `${DIM$6}Tip: if running in a coding agent, follow these steps:${RESET$6}
|
|
3746
|
+
${DIM$6} 1) npx @ali/cli-skills find [query]${RESET$6}
|
|
3747
|
+
${DIM$6} 2) npx @ali/cli-skills add <owner/repo@skill>${RESET$6}`;
|
|
3734
3748
|
if (query) {
|
|
3735
3749
|
const results = await searchSkillsAPI(query);
|
|
3736
3750
|
track({
|
|
@@ -3739,18 +3753,18 @@ ${DIM$5} 2) npx @ali/cli-skills add <owner/repo@skill>${RESET$5}`;
|
|
|
3739
3753
|
resultCount: String(results.length)
|
|
3740
3754
|
});
|
|
3741
3755
|
if (results.length === 0) {
|
|
3742
|
-
console.log(`${DIM$
|
|
3756
|
+
console.log(`${DIM$6}No skills found for "${query}"${RESET$6}`);
|
|
3743
3757
|
return;
|
|
3744
3758
|
}
|
|
3745
|
-
console.log(`${DIM$
|
|
3759
|
+
console.log(`${DIM$6}Install with${RESET$6} npx ali-skills add <owner/repo>`);
|
|
3746
3760
|
console.log();
|
|
3747
3761
|
for (const skill of results.slice(0, 6)) {
|
|
3748
3762
|
const pkg = skill.source || skill.slug;
|
|
3749
3763
|
const installs = formatInstalls(skill.installs);
|
|
3750
|
-
const githubBadge = skill.sourceType === "github" ? ` ${YELLOW$5}GitHub${RESET$
|
|
3751
|
-
console.log(`${TEXT$5}${pkg}@${skill.name}${RESET$
|
|
3764
|
+
const githubBadge = skill.sourceType === "github" ? ` ${YELLOW$5}GitHub${RESET$6}` : "";
|
|
3765
|
+
console.log(`${TEXT$5}${pkg}@${skill.name}${RESET$6}${githubBadge}${installs ? ` ${CYAN$1}${installs}${RESET$6}` : ""}`);
|
|
3752
3766
|
const skillUrl = buildSkillUrl(skill);
|
|
3753
|
-
console.log(`${DIM$
|
|
3767
|
+
console.log(`${DIM$6}└ ${skillUrl}${RESET$6}`);
|
|
3754
3768
|
console.log();
|
|
3755
3769
|
}
|
|
3756
3770
|
return;
|
|
@@ -3767,14 +3781,14 @@ ${DIM$5} 2) npx @ali/cli-skills add <owner/repo@skill>${RESET$5}`;
|
|
|
3767
3781
|
interactive: "1"
|
|
3768
3782
|
});
|
|
3769
3783
|
if (!selected) {
|
|
3770
|
-
console.log(`${DIM$
|
|
3784
|
+
console.log(`${DIM$6}Search cancelled${RESET$6}`);
|
|
3771
3785
|
console.log();
|
|
3772
3786
|
return;
|
|
3773
3787
|
}
|
|
3774
3788
|
const pkg = selected.source || selected.slug;
|
|
3775
3789
|
const skillName = selected.name;
|
|
3776
3790
|
console.log();
|
|
3777
|
-
console.log(`${TEXT$5}Installing ${BOLD$
|
|
3791
|
+
console.log(`${TEXT$5}Installing ${BOLD$3}${skillName}${RESET$6} from ${DIM$6}${pkg}${RESET$6}...`);
|
|
3778
3792
|
console.log();
|
|
3779
3793
|
const { source, options } = parseAddOptions([
|
|
3780
3794
|
pkg,
|
|
@@ -3784,7 +3798,7 @@ ${DIM$5} 2) npx @ali/cli-skills add <owner/repo@skill>${RESET$5}`;
|
|
|
3784
3798
|
await runAdd(source, options);
|
|
3785
3799
|
console.log();
|
|
3786
3800
|
const skillUrl = buildSkillUrl(selected);
|
|
3787
|
-
console.log(`${DIM$
|
|
3801
|
+
console.log(`${DIM$6}View the skill at${RESET$6} ${TEXT$5}${skillUrl}${RESET$6}`);
|
|
3788
3802
|
console.log();
|
|
3789
3803
|
}
|
|
3790
3804
|
const isCancelled = (value) => typeof value === "symbol";
|
|
@@ -4123,9 +4137,9 @@ async function runInstallFromLock(args) {
|
|
|
4123
4137
|
}
|
|
4124
4138
|
}
|
|
4125
4139
|
}
|
|
4126
|
-
const RESET$
|
|
4127
|
-
const BOLD$
|
|
4128
|
-
const DIM$
|
|
4140
|
+
const RESET$5 = "\x1B[0m";
|
|
4141
|
+
const BOLD$2 = "\x1B[1m";
|
|
4142
|
+
const DIM$5 = "\x1B[38;5;102m";
|
|
4129
4143
|
const TEXT$4 = "\x1B[38;5;145m";
|
|
4130
4144
|
const CYAN = "\x1B[36m";
|
|
4131
4145
|
const YELLOW$4 = "\x1B[33m";
|
|
@@ -4167,8 +4181,8 @@ async function runList(args) {
|
|
|
4167
4181
|
const validAgents = Object.keys(agents);
|
|
4168
4182
|
const invalidAgents = options.agent.filter((a) => !validAgents.includes(a));
|
|
4169
4183
|
if (invalidAgents.length > 0) {
|
|
4170
|
-
console.log(`${YELLOW$4}Invalid agents: ${invalidAgents.join(", ")}${RESET$
|
|
4171
|
-
console.log(`${DIM$
|
|
4184
|
+
console.log(`${YELLOW$4}Invalid agents: ${invalidAgents.join(", ")}${RESET$5}`);
|
|
4185
|
+
console.log(`${DIM$5}Valid agents: ${validAgents.join(", ")}${RESET$5}`);
|
|
4172
4186
|
process.exit(1);
|
|
4173
4187
|
}
|
|
4174
4188
|
agentFilter = options.agent;
|
|
@@ -4188,7 +4202,7 @@ async function runList(args) {
|
|
|
4188
4202
|
return;
|
|
4189
4203
|
}
|
|
4190
4204
|
if (!scope && !options.scopeSpecified) {
|
|
4191
|
-
console.log(`${DIM$
|
|
4205
|
+
console.log(`${DIM$5}提示: 当前为项目级列表。如需查看全局技能,请执行: ${TEXT$4}npx ali-skills list -g${RESET$5}`);
|
|
4192
4206
|
console.log();
|
|
4193
4207
|
}
|
|
4194
4208
|
const lockedSkills = await getAllLockedSkills();
|
|
@@ -4199,19 +4213,19 @@ async function runList(args) {
|
|
|
4199
4213
|
console.log("[]");
|
|
4200
4214
|
return;
|
|
4201
4215
|
}
|
|
4202
|
-
console.log(`${DIM$
|
|
4203
|
-
if (scope) console.log(`${DIM$
|
|
4216
|
+
console.log(`${DIM$5}No ${scopeLabel.toLowerCase()} skills found.${RESET$5}`);
|
|
4217
|
+
if (scope) console.log(`${DIM$5}Try listing project skills without -g${RESET$5}`);
|
|
4204
4218
|
return;
|
|
4205
4219
|
}
|
|
4206
4220
|
function printSkill(skill, indent = false) {
|
|
4207
4221
|
const prefix = indent ? " " : "";
|
|
4208
4222
|
const shortPath = shortenPath(skill.canonicalPath, cwd);
|
|
4209
4223
|
const agentNames = skill.agents.map((a) => agents[a].displayName);
|
|
4210
|
-
const agentInfo = skill.agents.length > 0 ? formatList(agentNames) : `${YELLOW$4}not linked${RESET$
|
|
4211
|
-
console.log(`${prefix}${CYAN}${skill.name}${RESET$
|
|
4212
|
-
console.log(`${prefix} ${DIM$
|
|
4224
|
+
const agentInfo = skill.agents.length > 0 ? formatList(agentNames) : `${YELLOW$4}not linked${RESET$5}`;
|
|
4225
|
+
console.log(`${prefix}${CYAN}${skill.name}${RESET$5} ${DIM$5}${shortPath}${RESET$5}`);
|
|
4226
|
+
console.log(`${prefix} ${DIM$5}Agents:${RESET$5} ${agentInfo}`);
|
|
4213
4227
|
}
|
|
4214
|
-
console.log(`${BOLD$
|
|
4228
|
+
console.log(`${BOLD$2}${scopeLabel} Skills${RESET$5}`);
|
|
4215
4229
|
console.log();
|
|
4216
4230
|
const groupedSkills = {};
|
|
4217
4231
|
const ungroupedSkills = [];
|
|
@@ -4227,13 +4241,13 @@ async function runList(args) {
|
|
|
4227
4241
|
const sortedGroups = Object.keys(groupedSkills).sort();
|
|
4228
4242
|
for (const group of sortedGroups) {
|
|
4229
4243
|
const title = group.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
4230
|
-
console.log(`${BOLD$
|
|
4244
|
+
console.log(`${BOLD$2}${title}${RESET$5}`);
|
|
4231
4245
|
const skills = groupedSkills[group];
|
|
4232
4246
|
if (skills) for (const skill of skills) printSkill(skill, true);
|
|
4233
4247
|
console.log();
|
|
4234
4248
|
}
|
|
4235
4249
|
if (ungroupedSkills.length > 0) {
|
|
4236
|
-
console.log(`${BOLD$
|
|
4250
|
+
console.log(`${BOLD$2}General${RESET$5}`);
|
|
4237
4251
|
for (const skill of ungroupedSkills) printSkill(skill, true);
|
|
4238
4252
|
console.log();
|
|
4239
4253
|
}
|
|
@@ -4786,7 +4800,7 @@ function removeAuth() {
|
|
|
4786
4800
|
if (existsSync(AUTH_FILE)) throw new Error(`Failed to remove auth file: ${AUTH_FILE}`);
|
|
4787
4801
|
}
|
|
4788
4802
|
function isAuthExpired(auth) {
|
|
4789
|
-
return Date.now() >= auth.expiresAt
|
|
4803
|
+
return Date.now() >= auth.expiresAt;
|
|
4790
4804
|
}
|
|
4791
4805
|
function getPrivateToken() {
|
|
4792
4806
|
return readAuth()?.privateToken || null;
|
|
@@ -4952,12 +4966,12 @@ function listPlatforms() {
|
|
|
4952
4966
|
config
|
|
4953
4967
|
}));
|
|
4954
4968
|
}
|
|
4955
|
-
const DIM$
|
|
4969
|
+
const DIM$4 = "\x1B[38;5;102m";
|
|
4956
4970
|
const TEXT$3 = "\x1B[38;5;145m";
|
|
4957
|
-
const RESET$
|
|
4971
|
+
const RESET$4 = "\x1B[0m";
|
|
4958
4972
|
const GREEN$2 = "\x1B[32m";
|
|
4959
4973
|
const YELLOW$3 = "\x1B[33m";
|
|
4960
|
-
const RED$
|
|
4974
|
+
const RED$4 = "\x1B[31m";
|
|
4961
4975
|
const STATUS_PLATFORM_KEYS = [
|
|
4962
4976
|
"code",
|
|
4963
4977
|
"yuque",
|
|
@@ -4971,9 +4985,9 @@ function isGatewayDebugEnabled() {
|
|
|
4971
4985
|
}
|
|
4972
4986
|
function gatewayDebugLog(message) {
|
|
4973
4987
|
if (!isGatewayDebugEnabled()) return;
|
|
4974
|
-
console.log(`${DIM$
|
|
4988
|
+
console.log(`${DIM$4}[gateway-debug]${RESET$4} ${message}`);
|
|
4975
4989
|
}
|
|
4976
|
-
function displayWidth(str) {
|
|
4990
|
+
function displayWidth$1(str) {
|
|
4977
4991
|
let width = 0;
|
|
4978
4992
|
for (const char of str) width += char.charCodeAt(0) > 127 ? 2 : 1;
|
|
4979
4993
|
return width;
|
|
@@ -5183,11 +5197,11 @@ async function revokeGatewaySessionIfPossible(auth) {
|
|
|
5183
5197
|
method: "POST",
|
|
5184
5198
|
headers: { "X-Private-Token": auth.privateToken }
|
|
5185
5199
|
});
|
|
5186
|
-
if (revokeRes.ok) console.log(`${GREEN$2}✓ 已撤销当前网关会话${RESET$
|
|
5187
|
-
else if (revokeRes.status === 404) console.log(`${DIM$
|
|
5188
|
-
else console.log(`${YELLOW$3}⚠️ 撤销网关会话失败,继续本机登出${RESET$
|
|
5200
|
+
if (revokeRes.ok) console.log(`${GREEN$2}✓ 已撤销当前网关会话${RESET$4}`);
|
|
5201
|
+
else if (revokeRes.status === 404) console.log(`${DIM$4}服务端暂不支持撤销网关会话,继续本机登出${RESET$4}`);
|
|
5202
|
+
else console.log(`${YELLOW$3}⚠️ 撤销网关会话失败,继续本机登出${RESET$4}`);
|
|
5189
5203
|
} catch {
|
|
5190
|
-
console.log(`${YELLOW$3}⚠️ 撤销网关会话失败,继续本机登出${RESET$
|
|
5204
|
+
console.log(`${YELLOW$3}⚠️ 撤销网关会话失败,继续本机登出${RESET$4}`);
|
|
5191
5205
|
}
|
|
5192
5206
|
}
|
|
5193
5207
|
async function login(options) {
|
|
@@ -5200,22 +5214,22 @@ async function login(options) {
|
|
|
5200
5214
|
} else {
|
|
5201
5215
|
const existingAuth = readAuth();
|
|
5202
5216
|
if (existingAuth && !isAuthExpired(existingAuth)) {
|
|
5203
|
-
console.log(`${YELLOW$3}! 您已经登录为: ${existingAuth.name} (${existingAuth.account})${RESET$
|
|
5217
|
+
console.log(`${YELLOW$3}! 您已经登录为: ${existingAuth.name} (${existingAuth.account})${RESET$4}`);
|
|
5204
5218
|
console.log();
|
|
5205
|
-
console.log(`${DIM$
|
|
5219
|
+
console.log(`${DIM$4}如需重新登录,请执行: npx ali-skills login --reauth${RESET$4}`);
|
|
5206
5220
|
return;
|
|
5207
5221
|
}
|
|
5208
5222
|
}
|
|
5209
|
-
console.log(`${TEXT$3}正在启动本地服务...${RESET$
|
|
5223
|
+
console.log(`${TEXT$3}正在启动本地服务...${RESET$4}`);
|
|
5210
5224
|
const { port, waitForCallback, close } = await startLocalServer();
|
|
5211
5225
|
const callbackUrl = `http://localhost:${port}/callback`;
|
|
5212
5226
|
const gatewayUrl = getGatewayUrl();
|
|
5213
5227
|
const loginUrl = `${gatewayUrl}/api/gateway/login?callback_url=${encodeURIComponent(callbackUrl)}&type=cli`;
|
|
5214
|
-
console.log(`${TEXT$3}正在打开浏览器进行 BUC 授权...${RESET$
|
|
5215
|
-
console.log(`${DIM$
|
|
5216
|
-
console.log(`${DIM$
|
|
5228
|
+
console.log(`${TEXT$3}正在打开浏览器进行 BUC 授权...${RESET$4}`);
|
|
5229
|
+
console.log(`${DIM$4}如果浏览器没有自动打开,请手动访问:${RESET$4}`);
|
|
5230
|
+
console.log(`${DIM$4}${loginUrl}${RESET$4}`);
|
|
5217
5231
|
openBrowser$2(loginUrl);
|
|
5218
|
-
console.log(`${TEXT$3}等待授权完成...${RESET$
|
|
5232
|
+
console.log(`${TEXT$3}等待授权完成...${RESET$4}`);
|
|
5219
5233
|
try {
|
|
5220
5234
|
const { empId, account, name, privateToken, ssoRefreshToken, expiresAt } = await waitForCallback();
|
|
5221
5235
|
saveAuth({
|
|
@@ -5229,13 +5243,13 @@ async function login(options) {
|
|
|
5229
5243
|
expiresAt: expiresAt * 1e3
|
|
5230
5244
|
});
|
|
5231
5245
|
console.log();
|
|
5232
|
-
console.log(`${GREEN$2}✓ 登录成功!${RESET$
|
|
5233
|
-
console.log(`${TEXT$3}欢迎: ${name} (${account})${RESET$
|
|
5234
|
-
console.log(`${DIM$
|
|
5246
|
+
console.log(`${GREEN$2}✓ 登录成功!${RESET$4}`);
|
|
5247
|
+
console.log(`${TEXT$3}欢迎: ${name} (${account})${RESET$4}`);
|
|
5248
|
+
console.log(`${DIM$4}Token 有效期至: ${(/* @__PURE__ */ new Date(expiresAt * 1e3)).toLocaleDateString()}${RESET$4}`);
|
|
5235
5249
|
if (!ssoRefreshToken) {
|
|
5236
5250
|
console.log();
|
|
5237
|
-
console.log(`${YELLOW$3}⚠ SSO_REFRESH_TOKEN 获取异常:本次授权回调未携带该凭证,网关代理等依赖 SSO Cookie 的能力可能不可用${RESET$
|
|
5238
|
-
console.log(`${DIM$
|
|
5251
|
+
console.log(`${YELLOW$3}⚠ SSO_REFRESH_TOKEN 获取异常:本次授权回调未携带该凭证,网关代理等依赖 SSO Cookie 的能力可能不可用${RESET$4}`);
|
|
5252
|
+
console.log(`${DIM$4}可尝试:在网页端(https://ali-skills.alibaba-inc.com)退出平台登录后重新执行 login 命令。同时请将此问题反馈给本工具开发者处理,感谢!${RESET$4}`);
|
|
5239
5253
|
}
|
|
5240
5254
|
} catch (error) {
|
|
5241
5255
|
close();
|
|
@@ -5246,18 +5260,18 @@ async function logout(platformInput, yuqueGroup, clearAll) {
|
|
|
5246
5260
|
if (platformInput) {
|
|
5247
5261
|
const platform = resolvePlatformByInput(platformInput);
|
|
5248
5262
|
if (!platform) {
|
|
5249
|
-
console.error(`${RED$
|
|
5250
|
-
console.log(`${DIM$
|
|
5263
|
+
console.error(`${RED$4}不支持的平台: ${platformInput}${RESET$4}`);
|
|
5264
|
+
console.log(`${DIM$4}可用平台: ${STATUS_PLATFORM_KEYS.join(", ")}${RESET$4}`);
|
|
5251
5265
|
process.exit(1);
|
|
5252
5266
|
}
|
|
5253
5267
|
if (platform.key === "yuque") {
|
|
5254
5268
|
if (clearAll) {
|
|
5255
5269
|
if (!hasYuqueCredentials(readConfig().platforms?.yuque)) {
|
|
5256
|
-
console.log(`${DIM$
|
|
5270
|
+
console.log(`${DIM$4}${platform.config.name} 未配置 Token${RESET$4}`);
|
|
5257
5271
|
return;
|
|
5258
5272
|
}
|
|
5259
5273
|
removePlatformToken(platform.key);
|
|
5260
|
-
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 的全部 Token 配置${RESET$
|
|
5274
|
+
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 的全部 Token 配置${RESET$4}`);
|
|
5261
5275
|
return;
|
|
5262
5276
|
}
|
|
5263
5277
|
if (!yuqueGroup) {
|
|
@@ -5266,10 +5280,10 @@ async function logout(platformInput, yuqueGroup, clearAll) {
|
|
|
5266
5280
|
if (groups.length === 0) {
|
|
5267
5281
|
if (yuque?.privateToken?.trim()) {
|
|
5268
5282
|
removePlatformToken(platform.key);
|
|
5269
|
-
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 的 Token 配置${RESET$
|
|
5283
|
+
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 的 Token 配置${RESET$4}`);
|
|
5270
5284
|
return;
|
|
5271
5285
|
}
|
|
5272
|
-
console.log(`${DIM$
|
|
5286
|
+
console.log(`${DIM$4}${platform.config.name} 未配置 Token${RESET$4}`);
|
|
5273
5287
|
return;
|
|
5274
5288
|
}
|
|
5275
5289
|
const selected = await fe({
|
|
@@ -5281,61 +5295,61 @@ async function logout(platformInput, yuqueGroup, clearAll) {
|
|
|
5281
5295
|
required: false
|
|
5282
5296
|
});
|
|
5283
5297
|
if (pD(selected)) {
|
|
5284
|
-
console.log(`${DIM$
|
|
5298
|
+
console.log(`${DIM$4}已取消${RESET$4}`);
|
|
5285
5299
|
return;
|
|
5286
5300
|
}
|
|
5287
5301
|
if (selected.length === 0) {
|
|
5288
|
-
console.log(`${DIM$
|
|
5302
|
+
console.log(`${DIM$4}未选择任何团队,已取消${RESET$4}`);
|
|
5289
5303
|
return;
|
|
5290
5304
|
}
|
|
5291
5305
|
for (const group of selected) removeYuqueGroup(group);
|
|
5292
|
-
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 团队 Token: ${selected.join(", ")}${RESET$
|
|
5306
|
+
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 团队 Token: ${selected.join(", ")}${RESET$4}`);
|
|
5293
5307
|
const remaining = Object.keys(readConfig().platforms?.yuque?.groups ?? {});
|
|
5294
|
-
if (remaining.length > 0) console.log(`${DIM$
|
|
5295
|
-
console.log(`${DIM$
|
|
5308
|
+
if (remaining.length > 0) console.log(`${DIM$4}剩余团队: ${remaining.join(", ")}${RESET$4}`);
|
|
5309
|
+
console.log(`${DIM$4}如需清除全部,请执行: npx ali-skills logout yuque --all${RESET$4}`);
|
|
5296
5310
|
return;
|
|
5297
5311
|
}
|
|
5298
5312
|
if (!hasYuqueCredentials(readConfig().platforms?.yuque)) {
|
|
5299
|
-
console.log(`${DIM$
|
|
5313
|
+
console.log(`${DIM$4}${platform.config.name} 未配置 Token${RESET$4}`);
|
|
5300
5314
|
return;
|
|
5301
5315
|
}
|
|
5302
5316
|
const g = yuqueGroup.trim();
|
|
5303
5317
|
if (!(readConfig().platforms?.yuque)?.groups?.[g]?.privateToken?.trim()) {
|
|
5304
|
-
console.log(`${DIM$
|
|
5318
|
+
console.log(`${DIM$4}${platform.config.name} 团队 ${g} 未配置 Group Access Token${RESET$4}`);
|
|
5305
5319
|
return;
|
|
5306
5320
|
}
|
|
5307
5321
|
removeYuqueGroup(g);
|
|
5308
|
-
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 团队 ${g} 的 Token${RESET$
|
|
5322
|
+
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 团队 ${g} 的 Token${RESET$4}`);
|
|
5309
5323
|
return;
|
|
5310
5324
|
}
|
|
5311
5325
|
if (platform.key === "o2") {
|
|
5312
5326
|
const gatewayAuth = readAuth();
|
|
5313
5327
|
const bucLoggedIn = Boolean(gatewayAuth) && !isAuthExpired(gatewayAuth);
|
|
5314
|
-
console.log(`${TEXT$3}${platform.config.name} 使用内置服务调用身份,无独立平台 Token${RESET$
|
|
5315
|
-
console.log(` BUC 登录态: ${bucLoggedIn ? `${GREEN$2}已登录${RESET$
|
|
5316
|
-
console.log(`${DIM$
|
|
5328
|
+
console.log(`${TEXT$3}${platform.config.name} 使用内置服务调用身份,无独立平台 Token${RESET$4}`);
|
|
5329
|
+
console.log(` BUC 登录态: ${bucLoggedIn ? `${GREEN$2}已登录${RESET$4}` : `${YELLOW$3}未登录${RESET$4}`}`);
|
|
5330
|
+
console.log(`${DIM$4}如需退出 BUC 登录态,请执行: npx ali-skills logout${RESET$4}`);
|
|
5317
5331
|
return;
|
|
5318
5332
|
}
|
|
5319
5333
|
const token = readConfig().platforms?.[platform.key]?.privateToken;
|
|
5320
5334
|
if (!token || !token.trim()) {
|
|
5321
|
-
console.log(`${DIM$
|
|
5335
|
+
console.log(`${DIM$4}${platform.config.name} 未配置 Private Token${RESET$4}`);
|
|
5322
5336
|
return;
|
|
5323
5337
|
}
|
|
5324
5338
|
removePlatformToken(platform.key);
|
|
5325
|
-
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 的 Private Token 配置${RESET$
|
|
5339
|
+
console.log(`${GREEN$2}✓ 已清除 ${platform.config.name} 的 Private Token 配置${RESET$4}`);
|
|
5326
5340
|
return;
|
|
5327
5341
|
}
|
|
5328
5342
|
const auth = readAuth();
|
|
5329
5343
|
if (!auth) {
|
|
5330
|
-
console.log(`${DIM$
|
|
5344
|
+
console.log(`${DIM$4}您尚未登录${RESET$4}`);
|
|
5331
5345
|
return;
|
|
5332
5346
|
}
|
|
5333
5347
|
try {
|
|
5334
5348
|
await revokeGatewaySessionIfPossible(auth);
|
|
5335
5349
|
removeAuth();
|
|
5336
|
-
console.log(`${GREEN$2}✓ 已登出${RESET$
|
|
5350
|
+
console.log(`${GREEN$2}✓ 已登出${RESET$4}`);
|
|
5337
5351
|
} catch (error) {
|
|
5338
|
-
console.error(`${RED$
|
|
5352
|
+
console.error(`${RED$4}登出失败: ${error.message}${RESET$4}`);
|
|
5339
5353
|
process.exit(1);
|
|
5340
5354
|
}
|
|
5341
5355
|
}
|
|
@@ -5365,52 +5379,52 @@ function resolvePlatformByInput(platformInput) {
|
|
|
5365
5379
|
function printSinglePlatformStatus(platformInput, isLoggedIn) {
|
|
5366
5380
|
const platform = resolvePlatformByInput(platformInput);
|
|
5367
5381
|
if (!platform) {
|
|
5368
|
-
console.error(`${RED$
|
|
5369
|
-
console.log(`${DIM$
|
|
5382
|
+
console.error(`${RED$4}不支持的平台: ${platformInput}${RESET$4}`);
|
|
5383
|
+
console.log(`${DIM$4}可用平台: ${STATUS_PLATFORM_KEYS.join(", ")}${RESET$4}`);
|
|
5370
5384
|
process.exit(1);
|
|
5371
5385
|
}
|
|
5372
5386
|
const config = readConfig();
|
|
5373
5387
|
const yuque = platform.key === "yuque" ? config.platforms?.yuque : void 0;
|
|
5374
5388
|
const isBuiltinServiceIdentity = platform.key === "o2";
|
|
5375
5389
|
const hasPrivateToken = platform.key === "yuque" ? hasYuqueCredentials(yuque) : isBuiltinServiceIdentity || Boolean(config.platforms?.[platform.key]?.privateToken?.trim());
|
|
5376
|
-
console.log(`${TEXT$3}平台状态: ${platform.config.name}${RESET$
|
|
5390
|
+
console.log(`${TEXT$3}平台状态: ${platform.config.name}${RESET$4}`);
|
|
5377
5391
|
if (platform.key === "yuque") {
|
|
5378
5392
|
const groupCount = yuque?.groups ? Object.keys(yuque.groups).length : 0;
|
|
5379
|
-
const line = groupCount > 0 ? ` Group Access Token: ${hasPrivateToken ? `${GREEN$2}已配置${RESET$
|
|
5393
|
+
const line = groupCount > 0 ? ` Group Access Token: ${hasPrivateToken ? `${GREEN$2}已配置${RESET$4}` : `${YELLOW$3}未配置${RESET$4}`} ${DIM$4}(${groupCount} 团队)${RESET$4}` : ` Token: ${hasPrivateToken ? `${GREEN$2}已配置${RESET$4}` : `${YELLOW$3}未配置${RESET$4}`}`;
|
|
5380
5394
|
console.log(line);
|
|
5381
|
-
if (yuque?.defaultGroup) console.log(`${DIM$
|
|
5382
|
-
} else if (isBuiltinServiceIdentity) console.log(` Token: ${GREEN$2}无需配置(走内置服务调用身份)${RESET$
|
|
5383
|
-
else console.log(` Private Token: ${hasPrivateToken ? `${GREEN$2}已配置${RESET$
|
|
5384
|
-
if (!hasPrivateToken && !isBuiltinServiceIdentity) console.log(`${DIM$
|
|
5385
|
-
if (platform.config.authType !== "private_token") console.log(` BUC 登录: ${isLoggedIn ? `${GREEN$2}已登录${RESET$
|
|
5395
|
+
if (yuque?.defaultGroup) console.log(`${DIM$4} 默认团队: ${yuque.defaultGroup}${RESET$4}`);
|
|
5396
|
+
} else if (isBuiltinServiceIdentity) console.log(` Token: ${GREEN$2}无需配置(走内置服务调用身份)${RESET$4}`);
|
|
5397
|
+
else console.log(` Private Token: ${hasPrivateToken ? `${GREEN$2}已配置${RESET$4}` : `${YELLOW$3}未配置${RESET$4}`}`);
|
|
5398
|
+
if (!hasPrivateToken && !isBuiltinServiceIdentity) console.log(`${DIM$4} 配置命令: npx ali-skills login ${platform.key}${RESET$4}`);
|
|
5399
|
+
if (platform.config.authType !== "private_token") console.log(` BUC 登录: ${isLoggedIn ? `${GREEN$2}已登录${RESET$4}` : `${YELLOW$3}未登录${RESET$4}`}`);
|
|
5386
5400
|
}
|
|
5387
5401
|
function printYuqueGroupStatus(group) {
|
|
5388
5402
|
const yuque = readConfig().platforms?.yuque;
|
|
5389
5403
|
const token = yuque?.groups?.[group]?.privateToken?.trim() ?? "";
|
|
5390
5404
|
const hasToken = Boolean(token);
|
|
5391
5405
|
const isDefault = yuque?.defaultGroup === group;
|
|
5392
|
-
console.log(`${TEXT$3}语雀团队状态: ${group}${RESET$
|
|
5393
|
-
console.log(` Group Access Token: ${hasToken ? `${GREEN$2}已配置${RESET$
|
|
5394
|
-
if (isDefault) console.log(` 默认团队: ${GREEN$2}是${RESET$
|
|
5395
|
-
else if (yuque?.defaultGroup) console.log(`${DIM$
|
|
5396
|
-
if (!hasToken) console.log(`${DIM$
|
|
5406
|
+
console.log(`${TEXT$3}语雀团队状态: ${group}${RESET$4}`);
|
|
5407
|
+
console.log(` Group Access Token: ${hasToken ? `${GREEN$2}已配置${RESET$4}` : `${YELLOW$3}未配置${RESET$4}`}`);
|
|
5408
|
+
if (isDefault) console.log(` 默认团队: ${GREEN$2}是${RESET$4}`);
|
|
5409
|
+
else if (yuque?.defaultGroup) console.log(`${DIM$4} 当前默认团队: ${yuque.defaultGroup}${RESET$4}`);
|
|
5410
|
+
if (!hasToken) console.log(`${DIM$4} 配置命令: npx ali-skills login yuque ${group}${RESET$4}`);
|
|
5397
5411
|
}
|
|
5398
5412
|
function printAllPlatformStatuses(isLoggedIn) {
|
|
5399
5413
|
const config = readConfig();
|
|
5400
5414
|
const platforms = listPlatforms().filter(({ key }) => STATUS_PLATFORM_KEYS.includes(key));
|
|
5401
|
-
const maxKeyWidth = Math.max(...platforms.map(({ key }) => displayWidth(key)));
|
|
5402
|
-
const maxNameWidth = Math.max(...platforms.map(({ config: p }) => displayWidth(p.name)));
|
|
5415
|
+
const maxKeyWidth = Math.max(...platforms.map(({ key }) => displayWidth$1(key)));
|
|
5416
|
+
const maxNameWidth = Math.max(...platforms.map(({ config: p }) => displayWidth$1(p.name)));
|
|
5403
5417
|
console.log();
|
|
5404
|
-
console.log(`${TEXT$3}平台凭证状态:${RESET$
|
|
5418
|
+
console.log(`${TEXT$3}平台凭证状态:${RESET$4}`);
|
|
5405
5419
|
for (const { key, config: platform } of platforms) {
|
|
5406
5420
|
const yuque = key === "yuque" ? config.platforms?.yuque : void 0;
|
|
5407
5421
|
const isBuiltinServiceIdentity = key === "o2";
|
|
5408
5422
|
const hasPrivateToken = key === "yuque" ? hasYuqueCredentials(yuque) : isBuiltinServiceIdentity || Boolean(config.platforms?.[key]?.privateToken?.trim());
|
|
5409
5423
|
const groupCount = key === "yuque" && yuque?.groups ? Object.keys(yuque.groups).length : 0;
|
|
5410
|
-
let statusText = isBuiltinServiceIdentity ? `${GREEN$2}Token 无需配置(走内置服务调用身份)${RESET$
|
|
5411
|
-
if (platform.authType !== "private_token") statusText += isLoggedIn ? ` ${DIM$
|
|
5412
|
-
const keyPadding = " ".repeat(maxKeyWidth - displayWidth(key) + 2);
|
|
5413
|
-
const namePadding = " ".repeat(maxNameWidth - displayWidth(platform.name) + 2);
|
|
5424
|
+
let statusText = isBuiltinServiceIdentity ? `${GREEN$2}Token 无需配置(走内置服务调用身份)${RESET$4}` : hasPrivateToken ? key === "yuque" && groupCount > 0 ? `${GREEN$2}Group Token 已配置${RESET$4} ${DIM$4}(${groupCount} 团队)${RESET$4}` : `${GREEN$2}Private Token 已配置${RESET$4}` : key === "yuque" ? `${YELLOW$3}Token 未配置${RESET$4}` : `${YELLOW$3}Private Token 未配置${RESET$4}`;
|
|
5425
|
+
if (platform.authType !== "private_token") statusText += isLoggedIn ? ` ${DIM$4}(BUC 已登录)${RESET$4}` : ` ${DIM$4}(BUC 未登录)${RESET$4}`;
|
|
5426
|
+
const keyPadding = " ".repeat(maxKeyWidth - displayWidth$1(key) + 2);
|
|
5427
|
+
const namePadding = " ".repeat(maxNameWidth - displayWidth$1(platform.name) + 2);
|
|
5414
5428
|
console.log(` ${key}${keyPadding}${platform.name}${namePadding}${statusText}`);
|
|
5415
5429
|
}
|
|
5416
5430
|
}
|
|
@@ -5419,11 +5433,11 @@ async function status(args = {}) {
|
|
|
5419
5433
|
const auth = readAuth();
|
|
5420
5434
|
if (showPrivateToken && !targetPlatform) {
|
|
5421
5435
|
if (showAll) {
|
|
5422
|
-
console.error(`${RED$
|
|
5436
|
+
console.error(`${RED$4}--show/-s 与 --all 同用时需指定平台,例如: npx ali-skills status yuque -s --all${RESET$4}`);
|
|
5423
5437
|
process.exit(1);
|
|
5424
5438
|
}
|
|
5425
5439
|
if (!auth) {
|
|
5426
|
-
console.error(`${RED$
|
|
5440
|
+
console.error(`${RED$4}未登录网关,请执行: npx ali-skills login${RESET$4}`);
|
|
5427
5441
|
process.exit(1);
|
|
5428
5442
|
}
|
|
5429
5443
|
printJson(auth, prettyJson);
|
|
@@ -5432,21 +5446,21 @@ async function status(args = {}) {
|
|
|
5432
5446
|
if (targetPlatform && showPrivateToken) {
|
|
5433
5447
|
const platform = resolvePlatformByInput(targetPlatform);
|
|
5434
5448
|
if (!platform) {
|
|
5435
|
-
console.error(`${RED$
|
|
5436
|
-
console.log(`${DIM$
|
|
5449
|
+
console.error(`${RED$4}不支持的平台: ${targetPlatform}${RESET$4}`);
|
|
5450
|
+
console.log(`${DIM$4}可用平台: ${STATUS_PLATFORM_KEYS.join(", ")}${RESET$4}`);
|
|
5437
5451
|
process.exit(1);
|
|
5438
5452
|
}
|
|
5439
5453
|
if (platform.key === "yuque") {
|
|
5440
5454
|
const yuque = readConfig().platforms?.yuque;
|
|
5441
5455
|
if (!yuque) {
|
|
5442
|
-
console.error(`${RED$
|
|
5456
|
+
console.error(`${RED$4}未配置语雀 Token,请执行: npx ali-skills login yuque${RESET$4}`);
|
|
5443
5457
|
process.exit(1);
|
|
5444
5458
|
}
|
|
5445
5459
|
if (yuqueGroup) {
|
|
5446
5460
|
const token = yuque.groups?.[yuqueGroup]?.privateToken?.trim();
|
|
5447
5461
|
if (!token) {
|
|
5448
|
-
console.error(`${RED$
|
|
5449
|
-
console.log(`${DIM$
|
|
5462
|
+
console.error(`${RED$4}语雀团队 ${yuqueGroup} 未配置 Group Access Token${RESET$4}`);
|
|
5463
|
+
console.log(`${DIM$4}可先执行: npx ali-skills login yuque ${yuqueGroup}${RESET$4}`);
|
|
5450
5464
|
process.exit(1);
|
|
5451
5465
|
}
|
|
5452
5466
|
printJson({
|
|
@@ -5460,7 +5474,7 @@ async function status(args = {}) {
|
|
|
5460
5474
|
}
|
|
5461
5475
|
const token = readConfig().platforms?.[platform.key]?.privateToken?.trim() ?? "";
|
|
5462
5476
|
if (!token) {
|
|
5463
|
-
console.error(`${RED$
|
|
5477
|
+
console.error(`${RED$4}未配置 Private Token,请执行: npx ali-skills login ${platform.key}${RESET$4}`);
|
|
5464
5478
|
process.exit(1);
|
|
5465
5479
|
}
|
|
5466
5480
|
printJson({ privateToken: token }, prettyJson);
|
|
@@ -5475,8 +5489,8 @@ async function status(args = {}) {
|
|
|
5475
5489
|
return;
|
|
5476
5490
|
}
|
|
5477
5491
|
if (!auth) {
|
|
5478
|
-
console.log(`${DIM$
|
|
5479
|
-
console.log(`${TEXT$3}请执行: npx ali-skills login${RESET$
|
|
5492
|
+
console.log(`${DIM$4}您尚未登录${RESET$4}`);
|
|
5493
|
+
console.log(`${TEXT$3}请执行: npx ali-skills login${RESET$4}`);
|
|
5480
5494
|
if (showAll) {
|
|
5481
5495
|
console.log();
|
|
5482
5496
|
printAllPlatformStatuses(false);
|
|
@@ -5486,15 +5500,15 @@ async function status(args = {}) {
|
|
|
5486
5500
|
const expired = isAuthExpired(auth);
|
|
5487
5501
|
const remaining = auth.expiresAt - Date.now();
|
|
5488
5502
|
const remainingDays = Math.max(0, Math.floor(remaining / (1440 * 60 * 1e3)));
|
|
5489
|
-
console.log(`${TEXT$3}登录状态:${RESET$
|
|
5503
|
+
console.log(`${TEXT$3}登录状态:${RESET$4}`);
|
|
5490
5504
|
console.log(` 用户: ${auth.name} (${auth.account})`);
|
|
5491
5505
|
console.log(` 工号: ${auth.empId}`);
|
|
5492
5506
|
console.log(` 网关: ${getGatewayUrl()}`);
|
|
5493
|
-
console.log(` SSO_REFRESH_TOKEN: ${auth.ssoRefreshToken ? `${GREEN$2}已缓存${RESET$
|
|
5507
|
+
console.log(` SSO_REFRESH_TOKEN: ${auth.ssoRefreshToken ? `${GREEN$2}已缓存${RESET$4}` : `${YELLOW$3}未缓存${RESET$4}`}${auth.ssoRefreshTokenUpdatedAt ? `${DIM$4}(更新于 ${new Date(auth.ssoRefreshTokenUpdatedAt).toLocaleString()})${RESET$4}` : ""}`);
|
|
5494
5508
|
if (expired) {
|
|
5495
|
-
console.log(` Token: ${YELLOW$3}
|
|
5496
|
-
console.log(`${TEXT$3}
|
|
5497
|
-
} else console.log(` Token: ${GREEN$2}有效${RESET$
|
|
5509
|
+
console.log(` Token: ${YELLOW$3}已过期${RESET$4}`);
|
|
5510
|
+
console.log(`${TEXT$3}请重新登录: npx ali-skills login --reauth${RESET$4}`);
|
|
5511
|
+
} else console.log(` Token: ${GREEN$2}有效${RESET$4} (还剩 ${remainingDays} 天)`);
|
|
5498
5512
|
if (showAll) {
|
|
5499
5513
|
console.log();
|
|
5500
5514
|
printAllPlatformStatuses(true);
|
|
@@ -5518,19 +5532,19 @@ async function ensureSsoRefreshToken() {
|
|
|
5518
5532
|
ssoRefreshToken: data.ssoRefreshToken,
|
|
5519
5533
|
ssoRefreshTokenUpdatedAt: Date.now()
|
|
5520
5534
|
});
|
|
5521
|
-
console.log(`${DIM$
|
|
5535
|
+
console.log(`${DIM$4}已从服务端获取 SSO_REFRESH_TOKEN${RESET$4}`);
|
|
5522
5536
|
return data.ssoRefreshToken;
|
|
5523
5537
|
}
|
|
5524
5538
|
if (response.status === 404) {
|
|
5525
|
-
console.log(`${YELLOW$3}⚠️ SSO_REFRESH_TOKEN 不可用${RESET$
|
|
5526
|
-
console.log(`${DIM$
|
|
5539
|
+
console.log(`${YELLOW$3}⚠️ SSO_REFRESH_TOKEN 不可用${RESET$4}`);
|
|
5540
|
+
console.log(`${DIM$4}提示: 请通过浏览器登录以获取 SSO_REFRESH_TOKEN${RESET$4}`);
|
|
5527
5541
|
return null;
|
|
5528
5542
|
}
|
|
5529
5543
|
const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
5530
|
-
console.error(`${RED$
|
|
5544
|
+
console.error(`${RED$4}获取 SSO_REFRESH_TOKEN 失败: ${errorData.error}${RESET$4}`);
|
|
5531
5545
|
return null;
|
|
5532
5546
|
} catch (error) {
|
|
5533
|
-
console.error(`${RED$
|
|
5547
|
+
console.error(`${RED$4}获取 SSO_REFRESH_TOKEN 失败: ${error.message}${RESET$4}`);
|
|
5534
5548
|
return null;
|
|
5535
5549
|
}
|
|
5536
5550
|
}
|
|
@@ -5554,15 +5568,16 @@ async function ensureSsoTicket() {
|
|
|
5554
5568
|
const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
5555
5569
|
gatewayDebugLog(`sso-ticket failed: code=${errorData.code ?? "n/a"}, error=${errorData.error ?? "Unknown error"}`);
|
|
5556
5570
|
if (response.status === 401 && errorData.code === "INVALID_TOKEN") {
|
|
5557
|
-
console.error(`${RED$
|
|
5558
|
-
console.log(`${TEXT$3}请重新登录: npx ali-skills login${RESET$
|
|
5571
|
+
console.error(`${RED$4}ali-skills CLI 会话凭证(Gateway private token)已失效,无法获取 BUC SSO_TICKET${RESET$4}`);
|
|
5572
|
+
console.log(`${TEXT$3}请重新登录: npx ali-skills login --reauth${RESET$4}`);
|
|
5559
5573
|
return null;
|
|
5560
5574
|
}
|
|
5561
|
-
console.error(`${RED$
|
|
5575
|
+
console.error(`${RED$4}获取 BUC SSO_TICKET 失败: ${errorData.error || errorData.code || "Unknown error"}${RESET$4}`);
|
|
5576
|
+
console.log(`${TEXT$3}如果问题持续,请重新登录: npx ali-skills login --reauth${RESET$4}`);
|
|
5562
5577
|
return null;
|
|
5563
5578
|
} catch (error) {
|
|
5564
5579
|
gatewayDebugLog(`sso-ticket fetch exception: ${error.message}`);
|
|
5565
|
-
console.error(`${RED$
|
|
5580
|
+
console.error(`${RED$4}获取 SSO_TICKET 失败: ${error.message}${RESET$4}`);
|
|
5566
5581
|
return null;
|
|
5567
5582
|
}
|
|
5568
5583
|
}
|
|
@@ -5584,7 +5599,7 @@ async function refreshSsoSession(ssoRefreshToken) {
|
|
|
5584
5599
|
async function ensureLogin() {
|
|
5585
5600
|
const auth = readAuth();
|
|
5586
5601
|
if (!auth) throw new Error("未登录,请先执行: npx ali-skills login");
|
|
5587
|
-
if (isAuthExpired(auth)) throw new Error("登录已过期,请重新执行: npx ali-skills login");
|
|
5602
|
+
if (isAuthExpired(auth)) throw new Error("登录已过期,请重新执行: npx ali-skills login --reauth");
|
|
5588
5603
|
return {
|
|
5589
5604
|
privateToken: auth.privateToken,
|
|
5590
5605
|
ssoRefreshToken: auth.ssoRefreshToken
|
|
@@ -5698,6 +5713,157 @@ function clearCookiesForDomain(hostname) {
|
|
|
5698
5713
|
writeJar(jar);
|
|
5699
5714
|
}
|
|
5700
5715
|
}
|
|
5716
|
+
const RESET$3 = "\x1B[0m";
|
|
5717
|
+
const BOLD$1 = "\x1B[1m";
|
|
5718
|
+
const DIM$3 = "\x1B[38;5;102m";
|
|
5719
|
+
const RED$3 = "\x1B[31m";
|
|
5720
|
+
const STAFF_ENDPOINT = `${SKILLS_API_BASE_URL.replace(/\/skills\/?$/, "")}/staff-info`;
|
|
5721
|
+
const SUPPORTED_FLAGS = [
|
|
5722
|
+
"workNo",
|
|
5723
|
+
"nickName",
|
|
5724
|
+
"name",
|
|
5725
|
+
"licenseNo",
|
|
5726
|
+
"workNoList"
|
|
5727
|
+
];
|
|
5728
|
+
function showStaffHelp() {
|
|
5729
|
+
console.log(`
|
|
5730
|
+
${BOLD$1}Usage:${RESET$3} ali-skills staff <workNo|nickName>
|
|
5731
|
+
|
|
5732
|
+
${BOLD$1}Examples:${RESET$3}
|
|
5733
|
+
${DIM$3}$${RESET$3} ali-skills staff 000001
|
|
5734
|
+
${DIM$3}$${RESET$3} ali-skills staff 花名
|
|
5735
|
+
${DIM$3}$${RESET$3} ali-skills staff --name=姓名
|
|
5736
|
+
${DIM$3}$${RESET$3} ali-skills staff --workNoList=000001,000002
|
|
5737
|
+
`);
|
|
5738
|
+
}
|
|
5739
|
+
function parseStaffArgs(args) {
|
|
5740
|
+
for (let i = 0; i < args.length; i++) {
|
|
5741
|
+
const arg = args[i];
|
|
5742
|
+
for (const flag of SUPPORTED_FLAGS) {
|
|
5743
|
+
const prefix = `--${flag}=`;
|
|
5744
|
+
if (arg.startsWith(prefix)) {
|
|
5745
|
+
const value = arg.slice(prefix.length).trim();
|
|
5746
|
+
if (value) return {
|
|
5747
|
+
param: flag,
|
|
5748
|
+
value
|
|
5749
|
+
};
|
|
5750
|
+
}
|
|
5751
|
+
}
|
|
5752
|
+
if (arg.startsWith("--")) {
|
|
5753
|
+
const withoutDashes = arg.slice(2);
|
|
5754
|
+
if (withoutDashes.indexOf("=") === -1) {
|
|
5755
|
+
const flagName = withoutDashes;
|
|
5756
|
+
const nextVal = args[i + 1];
|
|
5757
|
+
if (nextVal && SUPPORTED_FLAGS.includes(flagName)) return {
|
|
5758
|
+
param: flagName,
|
|
5759
|
+
value: nextVal
|
|
5760
|
+
};
|
|
5761
|
+
}
|
|
5762
|
+
}
|
|
5763
|
+
}
|
|
5764
|
+
const positional = args.find((a, idx) => !a.startsWith("-") && args[idx - 1] !== "--format");
|
|
5765
|
+
if (positional) return {
|
|
5766
|
+
param: /^\d+$/.test(positional) || /^wb\d+$/i.test(positional) ? "workNo" : "nickName",
|
|
5767
|
+
value: positional
|
|
5768
|
+
};
|
|
5769
|
+
return null;
|
|
5770
|
+
}
|
|
5771
|
+
function displayWidth(str) {
|
|
5772
|
+
let width = 0;
|
|
5773
|
+
for (const char of str) {
|
|
5774
|
+
const code = char.codePointAt(0) ?? 0;
|
|
5775
|
+
if (code >= 4352 && code <= 4447 || code >= 11904 && code <= 42191 && code !== 12351 || code >= 44032 && code <= 55203 || code >= 63744 && code <= 64255 || code >= 65040 && code <= 65135 || code >= 65281 && code <= 65376 || code >= 65504 && code <= 65510 || code >= 131072 && code <= 196605 || code >= 196608 && code <= 262141) width += 2;
|
|
5776
|
+
else width += 1;
|
|
5777
|
+
}
|
|
5778
|
+
return width;
|
|
5779
|
+
}
|
|
5780
|
+
function padEnd(str, targetWidth) {
|
|
5781
|
+
const diff = targetWidth - displayWidth(str);
|
|
5782
|
+
return diff > 0 ? str + " ".repeat(diff) : str;
|
|
5783
|
+
}
|
|
5784
|
+
function formatColumns(records) {
|
|
5785
|
+
const headers = [
|
|
5786
|
+
"NickName",
|
|
5787
|
+
"WorkNo",
|
|
5788
|
+
"Name",
|
|
5789
|
+
"Email"
|
|
5790
|
+
];
|
|
5791
|
+
const rows = records.map((r) => [
|
|
5792
|
+
r.nickName,
|
|
5793
|
+
r.workNo,
|
|
5794
|
+
r.name,
|
|
5795
|
+
r.buMail
|
|
5796
|
+
]);
|
|
5797
|
+
const widths = headers.map((h, i) => {
|
|
5798
|
+
const colValues = rows.map((row) => displayWidth(row[i] ?? ""));
|
|
5799
|
+
return Math.max(displayWidth(h), ...colValues);
|
|
5800
|
+
});
|
|
5801
|
+
const lines = [];
|
|
5802
|
+
lines.push(headers.map((h, i) => padEnd(h, widths[i])).join(" "));
|
|
5803
|
+
for (const row of rows) lines.push(row.map((cell, i) => padEnd(cell ?? "", widths[i])).join(" "));
|
|
5804
|
+
return lines.join("\n");
|
|
5805
|
+
}
|
|
5806
|
+
function parseFormat(args) {
|
|
5807
|
+
for (let i = 0; i < args.length; i++) {
|
|
5808
|
+
const arg = args[i];
|
|
5809
|
+
if (arg === "--format" && args[i + 1]) return args[i + 1] === "json" ? "json" : "md";
|
|
5810
|
+
if (arg.startsWith("--format=")) return arg.slice(9) === "json" ? "json" : "md";
|
|
5811
|
+
}
|
|
5812
|
+
return "md";
|
|
5813
|
+
}
|
|
5814
|
+
async function runStaff(args) {
|
|
5815
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
5816
|
+
showStaffHelp();
|
|
5817
|
+
return;
|
|
5818
|
+
}
|
|
5819
|
+
const format = parseFormat(args);
|
|
5820
|
+
const parsed = parseStaffArgs(args);
|
|
5821
|
+
if (!parsed) {
|
|
5822
|
+
showStaffHelp();
|
|
5823
|
+
return;
|
|
5824
|
+
}
|
|
5825
|
+
const url = `${STAFF_ENDPOINT}?${encodeURIComponent(parsed.param)}=${encodeURIComponent(parsed.value)}`;
|
|
5826
|
+
try {
|
|
5827
|
+
await ensureLogin();
|
|
5828
|
+
const ssoRefreshToken = await ensureSsoRefreshToken();
|
|
5829
|
+
if (!ssoRefreshToken) {
|
|
5830
|
+
console.error(`${RED$3}Error:${RESET$3} 缺少登录态,请先执行: npx ali-skills login`);
|
|
5831
|
+
process.exit(1);
|
|
5832
|
+
}
|
|
5833
|
+
const hostname = new URL(url).hostname;
|
|
5834
|
+
const res = await fetch(url, {
|
|
5835
|
+
headers: {
|
|
5836
|
+
"User-Agent": "ali-skills-cli/1.0",
|
|
5837
|
+
Cookie: buildCookieHeader(ssoRefreshToken, hostname)
|
|
5838
|
+
},
|
|
5839
|
+
redirect: "manual"
|
|
5840
|
+
});
|
|
5841
|
+
if (res.status >= 300 && res.status < 400) {
|
|
5842
|
+
console.error(`${RED$3}Error:${RESET$3} 登录态已过期,请执行: npx ali-skills login --reauth`);
|
|
5843
|
+
process.exit(1);
|
|
5844
|
+
}
|
|
5845
|
+
const json = await res.json();
|
|
5846
|
+
if (!res.ok || !json.success) {
|
|
5847
|
+
console.error(`${RED$3}Error:${RESET$3} ${json.error || `Request failed (${res.status})`}`);
|
|
5848
|
+
process.exit(1);
|
|
5849
|
+
}
|
|
5850
|
+
const records = json.data?.records ?? [];
|
|
5851
|
+
track({
|
|
5852
|
+
event: "staff",
|
|
5853
|
+
param: parsed.param
|
|
5854
|
+
});
|
|
5855
|
+
if (records.length === 0) {
|
|
5856
|
+
console.log(`${DIM$3}No results found.${RESET$3}`);
|
|
5857
|
+
return;
|
|
5858
|
+
}
|
|
5859
|
+
if (format === "json") console.log(JSON.stringify(records, null, 2));
|
|
5860
|
+
else console.log(formatColumns(records));
|
|
5861
|
+
} catch (error) {
|
|
5862
|
+
if (error.code === "ERR_INVALID_URL") console.error(`${RED$3}Error:${RESET$3} Invalid API URL: ${url}`);
|
|
5863
|
+
else console.error(`${RED$3}Error:${RESET$3} ${error instanceof Error ? error.message : "Network request failed"}`);
|
|
5864
|
+
process.exit(1);
|
|
5865
|
+
}
|
|
5866
|
+
}
|
|
5701
5867
|
const DIM$2 = "\x1B[38;5;102m";
|
|
5702
5868
|
const TEXT$2 = "\x1B[38;5;145m";
|
|
5703
5869
|
const RESET$2 = "\x1B[0m";
|
|
@@ -6056,7 +6222,7 @@ async function sendSsoCookieDirectRequest(targetUrl, options) {
|
|
|
6056
6222
|
console.log(`${DIM$2} 1. 尚未通过 ali-skills 登录${RESET$2}`);
|
|
6057
6223
|
console.log(`${DIM$2} 2. 登录时未拿到根域 token${RESET$2}`);
|
|
6058
6224
|
console.log(`${DIM$2} 3. token 已失效${RESET$2}`);
|
|
6059
|
-
console.log(`${TEXT$2}建议执行: npx ali-skills login${RESET$2}`);
|
|
6225
|
+
console.log(`${TEXT$2}建议执行: npx ali-skills login --reauth${RESET$2}`);
|
|
6060
6226
|
process.exit(1);
|
|
6061
6227
|
}
|
|
6062
6228
|
const hostname = new URL(targetUrl).hostname;
|
|
@@ -6154,7 +6320,7 @@ async function sendSsoTicketDirectRequest(targetUrl, options) {
|
|
|
6154
6320
|
}
|
|
6155
6321
|
if (!ssoTicket) {
|
|
6156
6322
|
console.error(`${RED$2}Error: 缺少 SSO_TICKET,无法进行直连请求${RESET$2}`);
|
|
6157
|
-
console.log(`${TEXT$2}建议执行: npx ali-skills login${RESET$2}`);
|
|
6323
|
+
console.log(`${TEXT$2}建议执行: npx ali-skills login --reauth${RESET$2}`);
|
|
6158
6324
|
process.exit(1);
|
|
6159
6325
|
}
|
|
6160
6326
|
const requestHeaders = {
|
|
@@ -6388,7 +6554,7 @@ async function sendGatewayRequest(targetUrl, platformKey, options, authMode = "g
|
|
|
6388
6554
|
code: "UNKNOWN"
|
|
6389
6555
|
}))).code === "INVALID_TOKEN") {
|
|
6390
6556
|
console.error(`${RED$2}Error: ali-skills CLI 会话凭证(Gateway private token)已失效${RESET$2}`);
|
|
6391
|
-
console.log(`${TEXT$2}请重新登录: npx ali-skills login${RESET$2}`);
|
|
6557
|
+
console.log(`${TEXT$2}请重新登录: npx ali-skills login --reauth${RESET$2}`);
|
|
6392
6558
|
process.exit(1);
|
|
6393
6559
|
}
|
|
6394
6560
|
}
|
|
@@ -6913,6 +7079,8 @@ function showBanner() {
|
|
|
6913
7079
|
console.log(` ${DIM}$${RESET} ${TEXT}npx ali-skills check${RESET} ${DIM}Check for updates${RESET}`);
|
|
6914
7080
|
console.log(` ${DIM}$${RESET} ${TEXT}npx ali-skills update${RESET} ${DIM}Update all skills${RESET}`);
|
|
6915
7081
|
console.log();
|
|
7082
|
+
console.log(` ${DIM}$${RESET} ${TEXT}npx ali-skills staff ${DIM}<workNo>${RESET} ${DIM}Query staff info${RESET}`);
|
|
7083
|
+
console.log();
|
|
6916
7084
|
console.log(` ${DIM}$${RESET} ${TEXT}npx ali-skills experimental_install${RESET} ${DIM}Restore from skills-lock.json${RESET}`);
|
|
6917
7085
|
console.log(` ${DIM}$${RESET} ${TEXT}npx ali-skills init ${DIM}[name]${RESET} ${DIM}Create a new skill${RESET}`);
|
|
6918
7086
|
console.log(` ${DIM}$${RESET} ${TEXT}npx ali-skills experimental_sync${RESET} ${DIM}Sync skills from node_modules${RESET}`);
|
|
@@ -6948,6 +7116,12 @@ ${BOLD}Updates:${RESET}
|
|
|
6948
7116
|
${BOLD}Project:${RESET}
|
|
6949
7117
|
init [name] Initialize a skill (creates <name>/SKILL.md or ./SKILL.md)
|
|
6950
7118
|
|
|
7119
|
+
${BOLD}Staff:${RESET}
|
|
7120
|
+
staff <workNo> Query employee info by workNo (positional)
|
|
7121
|
+
staff --nickName=X Query by nick name
|
|
7122
|
+
staff --name=X Query by real name
|
|
7123
|
+
staff --workNoList=X Query by comma-separated work numbers
|
|
7124
|
+
|
|
6951
7125
|
${BOLD}Gateway:${RESET}
|
|
6952
7126
|
gateway 鉴权请求能力入口(login/logout/status/req)
|
|
6953
7127
|
支持 privateToken/accessKey 身份托管请求(code、yuque、o2)
|
|
@@ -8130,6 +8304,9 @@ async function main() {
|
|
|
8130
8304
|
});
|
|
8131
8305
|
break;
|
|
8132
8306
|
}
|
|
8307
|
+
case "staff":
|
|
8308
|
+
await runStaff(restArgs);
|
|
8309
|
+
break;
|
|
8133
8310
|
case "gateway":
|
|
8134
8311
|
case "gw":
|
|
8135
8312
|
await runGatewayCommand(restArgs);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ali-skills",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "The open agent skills ecosystem",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"author": "",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ali/cli-skills": "^2.0.
|
|
34
|
+
"@ali/cli-skills": "^2.0.33"
|
|
35
35
|
},
|
|
36
36
|
"bundleDependencies": [
|
|
37
37
|
"@ali/cli-skills"
|