fix(favorite): ensure /hub enabled skills appear in command list immediately

Replace incomplete clearSkillCaches() with clearCommandsCache() so the

loadAllCommands memoize layer is also busted when a cloud favorite skill is

enabled or disabled via /hub.

Add skillChangeDetector.notify() to trigger an immediate REPL command list

refresh instead of waiting for the file watcher to detect the change.

Signed-off-by: 林凯90331 <90331@sangfor.com>

Co-authored-by: CoStrict <zgsm@sangfor.com.cn>
This commit is contained in:
林凯90331 2026-05-15 22:46:03 +08:00
parent 754157fd88
commit 5bfaeb21bd
2 changed files with 12 additions and 3 deletions

View File

@ -11,7 +11,8 @@ import { createCoStrictFetch } from '../provider/fetch.js'
import { getCoStrictBaseURL } from '../provider/auth.js' import { getCoStrictBaseURL } from '../provider/auth.js'
import { getClaudeConfigHomeDir } from '../../utils/envUtils.js' import { getClaudeConfigHomeDir } from '../../utils/envUtils.js'
import { saveGlobalConfig, getGlobalConfig } from '../../utils/config.js' import { saveGlobalConfig, getGlobalConfig } from '../../utils/config.js'
import { clearSkillCaches } from '../../skills/loadSkillsDir.js' import { clearCommandsCache } from '../../commands.js'
import { skillChangeDetector } from '../../utils/skills/skillChangeDetector.js'
import { parseFrontmatter } from '../../utils/frontmatterParser.js' import { parseFrontmatter } from '../../utils/frontmatterParser.js'
import { logForDebugging } from '../../utils/debug.js' import { logForDebugging } from '../../utils/debug.js'
import type { McpServerConfig } from '../../services/mcp/types.js' import type { McpServerConfig } from '../../services/mcp/types.js'
@ -516,7 +517,8 @@ async function addItemToConfig(item: FavoriteItem, localPath: string) {
const destDir = path.join(skillsDir(), item.slug) const destDir = path.join(skillsDir(), item.slug)
await mkdir(skillsDir(), { recursive: true }) await mkdir(skillsDir(), { recursive: true })
await copyDir(localPath, destDir) await copyDir(localPath, destDir)
clearSkillCaches() clearCommandsCache()
skillChangeDetector.notify()
break break
} }
case 'agent': { case 'agent': {
@ -591,7 +593,8 @@ async function removeItemFromConfig(
case 'skill': { case 'skill': {
const destDir = path.join(skillsDir(), slug) const destDir = path.join(skillsDir(), slug)
await rm(destDir, { recursive: true, force: true }) await rm(destDir, { recursive: true, force: true })
clearSkillCaches() clearCommandsCache()
skillChangeDetector.notify()
break break
} }
case 'agent': { case 'agent': {

View File

@ -308,4 +308,10 @@ export const skillChangeDetector = {
dispose, dispose,
subscribe, subscribe,
resetForTesting, resetForTesting,
/**
* Manually trigger a skill-change notification. Used when code mutates
* skill directories directly (e.g. /hub enabling a cloud favorite) and
* needs the REPL to refresh its command list immediately.
*/
notify: () => skillsChanged.emit(),
} }