qwen-code/docs
易良 d2ece83726
feat(skills): support priority field in SKILL.md for sorting skill display order (#4155)
* feat(skills): support priority field in SKILL.md for sorting skill display order

Closes #4136

* fix(skills): make /skills respect priority and treat unset as 0

- /skills was re-sorting alphabetically after listSkills(), masking the
  new priority order. Drop the redundant sort and reuse the manager's
  output directly.
- Treat missing priority as 0 instead of -Infinity so an explicit
  negative priority (e.g. -1) sorts below unset skills, which matches
  user intent.

* fix(skills): harden priority parsing and ordering

* fix(skills): warn when extension supplies invalid priority

Extension-provided skills bypass parseSkillContent / validateConfig, so a
non-number `priority` was silently normalized to 0 in the sort with zero
diagnostic. Match the SKILL.md author signal: warn at load time so the
extension author can see and fix the typo.

Addresses PR #4155 review (the extension-bypass-validation point).

* test(skills): direct unit tests for parsePriorityField and normalizeSkillPriority

Both helpers are exported but previously had no direct tests — coverage
came only via parseSkillContent and listSkills. Adds inputs the
integration paths can't surface cleanly: -0 / NaN / Infinity, numeric
strings, objects, arrays, and the boolean coercion regression that
motivated the strict typecheck.

Also adds a NOTE on parsePriorityField warning future contributors that
SKILL.md frontmatter parsing lives in two places (parseSkillContent here
and SkillManager.parseSkillContent), so any new field must be wired into
both — the same regression that previously hit whenToUse,
disable-model-invocation, paths, and priority. Full dedup of the two
parseSkillContent bodies is left as a follow-up refactor.

Addresses the remaining two [Suggestion] items from PR #4155 review.

* fix(skills): scope priority to /skills listing only

Earlier in this PR, `skill.priority` was mapped into `SlashCommand.completionPriority`
on both bundled and non-bundled skill loaders, so a high-priority skill
also bubbled up in the slash-completion menu and the `/help` custom-commands
tab. That was broader than intended — the design goal is for `priority:`
to control the `/skills` listing only, with everything else (typing `/`,
mid-input completion, `/help`) staying purely alphabetical so a skill
can't reorder built-in commands.

Changes:
- BundledSkillLoader / SkillCommandLoader: drop the
  `completionPriority: skill.priority` mapping. Skill commands now have
  no `completionPriority`, falling back to alphabetical+recency in the
  shared completion comparator.
- Help.tsx: revert the per-group sort to `localeCompare` and remove the
  `compareCommandsForHelp` helper. `/help` is again purely alphabetical
  within each group.
- Tests:
  - Both loader tests assert `completionPriority` is `undefined` when
    a skill has a `priority` set, locking the non-leakage in.
  - Help.test.tsx's "orders by completionPriority" case is replaced
    with "orders alphabetically regardless of completionPriority", so a
    future change that re-introduces the leak fails the test.
- Extension-skill validation also normalizes `skill.priority` to 0 (in
  addition to the existing sort-time normalization) so downstream
  consumers see a clean value matching the emitted warning.

Validation:
- 177/177 unit tests pass across the 5 affected test files
- core typecheck clean
- bundled CLI built (`npm run bundle`) and exercised via tmux E2E:
  E1 /skills sorted by priority, E2 / completion menu unaffected,
  E3 mid-input alphabetical, E4 invalid priority warns + skill loads,
  E5 order stable across restart — all 5 pass.

* fix(skills): tag priority warning with calling module's namespace

`parsePriorityField` previously hardcoded `debugLogger.warn` from
skill-load, so a warning emitted from `SkillManager.parseSkillContent`
(project / user / bundled skills) was tagged `[SKILL_LOAD]` instead of
`[SKILL_MANAGER]`. Annoying for log filtering and slightly misleading
about which parse path actually surfaced the bad priority.

Added an optional `warn` callback parameter; the existing extension
call site keeps the default skill-load logger, while skill-manager
passes its own. Behavior is otherwise unchanged.

* docs(skills): correct priority scope description

Earlier doc said priority sorts "in /skills, slash-command completion,
and the /help custom commands view." After the scope-narrowing in
96722aa67, priority only affects /skills. Updating the doc to match
the actual behavior so readers don't expect cross-surface ordering.

* fix(skills): keep listSkills() alphabetical, sort priority at /skills display

`listSkills()` previously returned priority-desc order for every consumer,
including `SkillTool.refreshSkills()` which builds the model-facing
`<available_skills>` description. That contradicted the stated design goal
(`priority:` controls the `/skills` listing only) and the user docs, which
say everything outside `/skills` stays alphabetical.

- skill-manager.ts: `listSkills()` now sorts name-asc only, giving all
  programmatic consumers (SkillTool, contextCommand, loaders) a stable
  alphabetical order unaffected by `priority:`.
- skillsCommand.ts: apply the priority-desc, name-asc sort at the display
  layer using the shared `normalizeSkillPriority`.
- skills/index.ts: export `normalizeSkillPriority` for the CLI display sort.
- Tests: core tests now lock in that `listSkills()` stays alphabetical
  regardless of priority; new skillsCommand.test.ts covers the display sort.

* fix: correct copyright year 2025 -> 2026 in new file [skip ci]
2026-05-21 14:49:22 +08:00
..
design feat(telemetry): support custom resource attributes and add metric cardinality controls (#4367) 2026-05-21 13:54:37 +08:00
developers feat(telemetry): support custom resource attributes and add metric cardinality controls (#4367) 2026-05-21 13:54:37 +08:00
e2e-tests fix(core): replace structuredClone with shallow copy to prevent OOM in long sessions (#4286) 2026-05-21 10:28:59 +08:00
plans fix(core): replace structuredClone with shallow copy to prevent OOM in long sessions (#4286) 2026-05-21 10:28:59 +08:00
superpowers/plans feat(worktree): Phase C — session persistence, hooksPath, Footer + WorktreeExitDialog, three-mode --resume restore (#4174) 2026-05-19 13:59:35 +08:00
users feat(skills): support priority field in SKILL.md for sorting skill display order (#4155) 2026-05-21 14:49:22 +08:00
_meta.ts feat: refactor docs 2025-12-05 10:51:57 +08:00
index.md fix: lint issues 2025-12-19 15:52:11 +08:00