fix(mcp): refresh prompt slash commands

This commit is contained in:
OpenCode 2026-06-13 01:17:26 +00:00
commit 594eddb288
9 changed files with 172 additions and 17 deletions

View file

@ -134,6 +134,25 @@ describe("applyGlobalEvent", () => {
})
describe("applyDirectoryEvent", () => {
test("refreshes commands when command catalog changes", () => {
const [store, setStore] = createStore(baseState())
let refreshCount = 0
applyDirectoryEvent({
event: { type: "command.changed" },
store,
setStore,
push() {},
directory: "/tmp",
loadCommand() {
refreshCount += 1
},
loadLsp() {},
})
expect(refreshCount).toBe(1)
})
test("preserves a Home-specific retained session limit", () => {
const [store, setStore] = createStore(
baseState({

View file

@ -96,6 +96,7 @@ export function applyDirectoryEvent(input: {
setStore: SetStoreFunction<State>
push: (directory: string) => void
directory: string
loadCommand?: () => void
loadLsp: () => void
vcsCache?: VcsCache
setSessionTodo?: (sessionID: string, todos: Todo[] | undefined) => void
@ -108,6 +109,10 @@ export function applyDirectoryEvent(input: {
input.push(input.directory)
return
}
case "command.changed": {
input.loadCommand?.()
return
}
case "session.created": {
const info = (event.properties as { info: Session }).info
const result = Binary.search(input.store.session, info.id, (s) => s.id)

View file

@ -407,6 +407,13 @@ export function createServerSyncContextInner(_serverSDK?: ServerSDK) {
setSessionTodo,
retainedLimit: sessionMeta.get(key)?.limit,
vcsCache: children.vcsCache.get(key),
loadCommand: () => {
void retry(() =>
sdkFor(directory)
.command.list()
.then((x) => setStore("command", x.data ?? [])),
)
},
loadLsp: () => {
void queryClient.fetchQuery(queryOptionsApi.lsp(key))
},