The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tui): keep the skills.changed refetch out of the event switch
Tekniumb422f1af5235
diff --git a/ui-tui/src/__tests__/createGatewayEventHandler.test.ts b/ui-tui/src/__tests__/createGatewayEventHandler.test.tsindex baedf7e5738..0f48af0132a 100644--- a/ui-tui/src/__tests__/createGatewayEventHandler.test.ts+++ b/ui-tui/src/__tests__/createGatewayEventHandler.test.ts@@ -1070,21 +1070,6 @@ describe('createGatewayEventHandler', () => {vi.unstubAllEnvs()})- it('skills.changed refetches the slash catalog from the gateway for the live session (CFG-8)', async () => {- const ctx = buildCtx([])-- const rpc = vi.fn(async () => ({ canon: { '/new-skill': '/new-skill' }, pairs: [['/new-skill', 'd']], skill_count: 1 }))-- ;(ctx.gateway as any).rpc = rpc- patchUiState({ sid: 'sid-cfg8' })-- createGatewayEventHandler(ctx)({ payload: {}, type: 'skills.changed' } as any)- await vi.waitFor(() => expect(ctx.session.setCatalog).toHaveBeenCalled())-- expect(rpc).toHaveBeenCalledWith('commands.catalog', { session_id: 'sid-cfg8' })- expect((ctx.session.setCatalog as any).mock.calls.at(-1)[0].canon).toEqual({ '/new-skill': '/new-skill' })- })-it('a skin that owns the background paints BOTH terminal defaults (OSC 11 bg + OSC 10 fg)', () => {// Default-fg tokens (markdown body, borders) render with the TERMINAL's// default foreground. A dark skin on a light terminal repaints thediff --git a/ui-tui/src/__tests__/slashCatalogSkillsChanged.test.ts b/ui-tui/src/__tests__/slashCatalogSkillsChanged.test.tsnew file mode 100644index 00000000000..68b8bc5f244--- /dev/null+++ b/ui-tui/src/__tests__/slashCatalogSkillsChanged.test.ts@@ -0,0 +1,29 @@+import { beforeEach, describe, expect, it, vi } from 'vitest'++import { refreshSlashCatalogOnSkillsChange } from '../app/slashCatalog.js'+import { patchUiState, resetUiState } from '../app/uiStore.js'++// CFG-8: a skill installed from another terminal reaches Ink's palette through the gateway.+describe('refreshSlashCatalogOnSkillsChange', () => {+ beforeEach(() => resetUiState())++ it('refetches commands.catalog from the gateway for the live session', async () => {+ const rpc = vi.fn(async () => ({ canon: { '/new-skill': '/new-skill' }, pairs: [['/new-skill', 'd']], skill_count: 1 }))+ const setCatalog = vi.fn()++ patchUiState({ sid: 'sid-cfg8' })++ expect(refreshSlashCatalogOnSkillsChange({ type: 'skills.changed' }, rpc as never, setCatalog)).toBe(true)+ await vi.waitFor(() => expect(setCatalog).toHaveBeenCalled())++ expect(rpc).toHaveBeenCalledWith('commands.catalog', { session_id: 'sid-cfg8' })+ expect(setCatalog.mock.calls.at(-1)?.[0].canon).toEqual({ '/new-skill': '/new-skill' })+ })++ it('leaves every other event to the main handler', () => {+ const rpc = vi.fn()++ expect(refreshSlashCatalogOnSkillsChange({ type: 'skin.changed' }, rpc as never, vi.fn())).toBe(false)+ expect(rpc).not.toHaveBeenCalled()+ })+})diff --git a/ui-tui/src/app/createGatewayEventHandler.ts b/ui-tui/src/app/createGatewayEventHandler.tsindex c4e752c44cb..1353fae0fd9 100644--- a/ui-tui/src/app/createGatewayEventHandler.ts+++ b/ui-tui/src/app/createGatewayEventHandler.ts@@ -48,7 +48,7 @@ import { flashGoodVibes, flashPet } from './petFlashStore.js'import { forgetServerRequest } from './serverRequestStore.js'import { noteCanonicalCompletion } from './slash/canonicalSessionCommands.js'import { mutateCanonicalSession, openModelConfirmation } from './slash/canonicalSessionControls.js'-import { loadSlashCatalog } from './slashCatalog.js'+import { loadSlashCatalog, refreshSlashCatalogOnSkillsChange } from './slashCatalog.js'import { reportStartupLatency } from './startupLatency.js'import { markNextSubmitVoice } from './submissionCore.js'import { captureDestination, isCurrentDestination } from './submissionDestination.js'@@ -1064,6 +1064,10 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:})}+ // Shared-control settles and the skills.changed catalog refetch need no per-event state.+ const handledBeforeSwitch = (ev: AnyGatewayEvent) =>+ settleSharedPrompt(ev) || refreshSlashCatalogOnSkillsChange(ev, rpc, setCatalog)+return (ev: AnyGatewayEvent) => {const sid = getUiState().sid@@ -1078,7 +1082,7 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:return}- if (settleSharedPrompt(ev)) {+ if (handledBeforeSwitch(ev)) {return}@@ -1116,13 +1120,6 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:return- // A skill installed or removed from another terminal: refetch the palette from the gateway- // (it rescans; this client never reads the skills dir itself).- case 'skills.changed':- void loadSlashCatalog(rpc, getUiState().sid, setCatalog)-- return-case 'free_tier.challenge':showChallenge(ev.payload)diff --git a/ui-tui/src/app/slashCatalog.ts b/ui-tui/src/app/slashCatalog.tsindex b0c2e7f10e4..fcacdcd09e4 100644--- a/ui-tui/src/app/slashCatalog.ts+++ b/ui-tui/src/app/slashCatalog.ts@@ -35,6 +35,22 @@ export const loadSlashCatalog = (rpc: GatewayRpc, sid: null | string, setCatalog}).catch(e => turnController.pushActivity(t('gatewayMsg.startup.commandCatalogUnavailable', rpcErrorMessage(e)), 'info'))+/** `skills.changed`: a skill was installed or removed from another terminal. Refetch the palette+ * from the gateway, which rescans; this client never reads the skills dir itself. True when handled. */+export function refreshSlashCatalogOnSkillsChange(+ ev: { type: string },+ rpc: GatewayRpc,+ setCatalog: (catalog: null | SlashCatalog) => void+): boolean {+ if (ev.type !== 'skills.changed') {+ return false+ }++ void loadSlashCatalog(rpc, $uiState.get().sid, setCatalog)++ return true+}+/** The slash catalog for the live session (or the launch workspace before one exists). */export const $slashCatalog = atom<null | SlashCatalog>(null)