fix(chat): use ~/.codex/skills/ for Codex expert symlinks and keep expert button always enabled

Change Codex skill storage to use only ~/.codex/skills/ instead of
~/.agents/skills/, and never disable the expert skills button so users
can always access the empty-state hint. Also fix stale expert list in
conversation window after linking in the separate settings window by
re-fetching on window focus.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
xintaofei
2026-04-11 00:37:31 +08:00
parent ade59f474c
commit 19979d50d0
4 changed files with 44 additions and 30 deletions

View File

@@ -1757,7 +1757,7 @@ export function MessageInput({
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
disabled={disabled || availableExperts.length === 0}
disabled={disabled}
variant="outline"
size="icon"
className="h-6 w-6 shrink-0 bg-transparent"

View File

@@ -1,6 +1,6 @@
"use client"
import { useEffect, useMemo, useState } from "react"
import { useCallback, useEffect, useMemo, useState } from "react"
import { expertsListForAgent } from "@/lib/api"
import type { AgentType, ExpertListItem } from "@/lib/types"
@@ -10,6 +10,25 @@ const inflightMap = new Map<AgentType, Promise<ExpertListItem[]>>()
const EMPTY: ExpertListItem[] = []
function fetchForAgent(agentType: AgentType): Promise<ExpertListItem[]> {
let promise = inflightMap.get(agentType)
if (!promise) {
promise = expertsListForAgent(agentType)
.then((list) => {
agentCache.set(agentType, list)
inflightMap.delete(agentType)
return list
})
.catch((err) => {
inflightMap.delete(agentType)
console.warn("[useAgentExperts] failed:", err)
return EMPTY
})
inflightMap.set(agentType, promise)
}
return promise
}
export function useAgentExperts(agentType: AgentType | null): ExpertListItem[] {
const cached = useMemo(
() => (agentType ? (agentCache.get(agentType) ?? null) : null),
@@ -22,35 +41,34 @@ export function useAgentExperts(agentType: AgentType | null): ExpertListItem[] {
experts: ExpertListItem[]
} | null>(null)
useEffect(() => {
const doFetch = useCallback(() => {
if (!agentType || agentCache.has(agentType)) return
let cancelled = false
let promise = inflightMap.get(agentType)
if (!promise) {
promise = expertsListForAgent(agentType)
.then((list) => {
agentCache.set(agentType, list)
inflightMap.delete(agentType)
return list
})
.catch((err) => {
inflightMap.delete(agentType)
console.warn("[useAgentExperts] failed:", err)
return EMPTY
})
inflightMap.set(agentType, promise)
}
promise.then((list) => {
fetchForAgent(agentType).then((list) => {
if (!cancelled) setFetched({ agentType, experts: list })
})
return () => {
cancelled = true
}
}, [agentType])
// Initial fetch
useEffect(() => doFetch(), [doFetch])
// Re-fetch when window regains focus (covers cross-window cache
// invalidation — e.g. settings window links/unlinks experts while the
// conversation window stays mounted).
useEffect(() => {
const onFocus = () => {
if (!agentType) return
agentCache.delete(agentType)
inflightMap.delete(agentType)
doFetch()
}
window.addEventListener("focus", onFocus)
return () => window.removeEventListener("focus", onFocus)
}, [agentType, doFetch])
if (!agentType) return EMPTY
if (cached) return cached
if (fetched && fetched.agentType === agentType) return fetched.experts