From e5da7397fa57983c26c67c8a3c81130f4a36cb9f Mon Sep 17 00:00:00 2001 From: chenbaowang <49091147+Rsweater@users.noreply.github.com> Date: Mon, 20 Apr 2026 19:46:00 +0800 Subject: [PATCH] refactor(cli): sort all list outputs and agent names alphabetically - update.ts: sort skill selection list alphabetically - check.ts: sort results by status then name, sort agent names in locations - install.ts: sort agent names in buildAgentSummary, sort --list output - sync.ts: sort discovered skills by name before display Ensures consistent alphabetical ordering across all CLI commands for better user experience and predictability. --- skillhub-cli/src/commands/check.ts | 11 +++++++++-- skillhub-cli/src/commands/install.ts | 14 +++++++++----- skillhub-cli/src/commands/sync.ts | 3 ++- skillhub-cli/src/commands/update.ts | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/skillhub-cli/src/commands/check.ts b/skillhub-cli/src/commands/check.ts index e8fb840e..9580d8b4 100644 --- a/skillhub-cli/src/commands/check.ts +++ b/skillhub-cli/src/commands/check.ts @@ -70,7 +70,7 @@ export function registerCheck(program: Command) { name, status: "ok", source: entry.source, - location: installedLocations.join(", "), + location: installedLocations.sort((a, b) => a.localeCompare(b)).join(", "), }); } else { results.push({ @@ -86,11 +86,18 @@ export function registerCheck(program: Command) { results.push({ name, status: "orphaned", - location: locations.join(", "), + location: locations.sort((a, b) => a.localeCompare(b)).join(", "), }); } } + // Sort results: ok → missing → orphaned, then alphabetically by name + results.sort((a, b) => { + const order = { ok: 0, missing: 1, orphaned: 2 }; + const diff = order[a.status] - order[b.status]; + return diff !== 0 ? diff : a.name.localeCompare(b.name); + }); + if (opts.json) { console.log(JSON.stringify(results, null, 2)); return; diff --git a/skillhub-cli/src/commands/install.ts b/skillhub-cli/src/commands/install.ts index 43bb113b..4a272a4f 100644 --- a/skillhub-cli/src/commands/install.ts +++ b/skillhub-cli/src/commands/install.ts @@ -180,15 +180,17 @@ function buildAgentSummary(targetAgents: AgentInfo[], mode: "symlink" | "copy", const universal = targetAgents.filter((a) => isUniversalForScope(a, isGlobal)); const symlinked = targetAgents.filter((a) => !isUniversalForScope(a, isGlobal)); + const sortNames = (agents: AgentInfo[]) => agents.map((a) => a.name).sort((a, b) => a.localeCompare(b)); + if (mode === "symlink") { if (universal.length > 0) { - lines.push(` universal: ${universal.map((a) => a.name).join(", ")}`); + lines.push(` universal: ${sortNames(universal).join(", ")}`); } if (symlinked.length > 0) { - lines.push(` symlink → ${symlinked.map((a) => a.name).join(", ")}`); + lines.push(` symlink → ${sortNames(symlinked).join(", ")}`); } } else { - lines.push(` copy → ${targetAgents.map((a) => a.name).join(", ")}`); + lines.push(` copy → ${sortNames(targetAgents).join(", ")}`); } return lines; @@ -397,7 +399,8 @@ async function installFromRegistry(slug: string, opts: Record a.name.localeCompare(b.name)); + for (const s of sorted) { info(`${s.name}`); dim(` ${s.description}`); } @@ -630,7 +633,8 @@ async function installFromGit(skillName: string, source: string, sourceType: Sou spinner.succeed(`Found ${skills.length} skill(s)`); if (opts.list) { - for (const s of skills) { + const sorted = [...skills].sort((a, b) => a.name.localeCompare(b.name)); + for (const s of sorted) { info(`${s.name}`); dim(` ${s.description}`); } diff --git a/skillhub-cli/src/commands/sync.ts b/skillhub-cli/src/commands/sync.ts index 4cc7afea..9ded9ae6 100644 --- a/skillhub-cli/src/commands/sync.ts +++ b/skillhub-cli/src/commands/sync.ts @@ -49,7 +49,8 @@ export function registerSync(program: Command) { console.log(""); info(`Found ${skills.length} skill(s):`); - for (const skill of skills) { + const sortedSkills = [...skills].sort((a, b) => a.name.localeCompare(b.name)); + for (const skill of sortedSkills) { console.log(` - ${skill.name} (${skill.description})`); } console.log(""); diff --git a/skillhub-cli/src/commands/update.ts b/skillhub-cli/src/commands/update.ts index 736863e4..78c5ca35 100644 --- a/skillhub-cli/src/commands/update.ts +++ b/skillhub-cli/src/commands/update.ts @@ -26,7 +26,7 @@ export function registerUpdate(program: Command) { } const lockedSkills = await getAllLockedSkills(); - const allSkillNames = Object.keys(lockedSkills); + const allSkillNames = Object.keys(lockedSkills).sort((a, b) => a.localeCompare(b)); if (allSkillNames.length === 0) { error("No skills in lock file.");