Skip to content

The agent that grows with you

fix(tui): reload the slash catalog bound to each live session

yoniebans1f8c6134c290
diff --git a/ui-tui/src/__tests__/slashCatalog.test.ts b/ui-tui/src/__tests__/slashCatalog.test.ts
new file mode 100644
index 00000000000..7471431166c
--- /dev/null
+++ b/ui-tui/src/__tests__/slashCatalog.test.ts
@@ -0,0 +1,53 @@
+import { describe, expect, it } from 'vitest'
+
+import type { CommandsCatalogResponse } from '../gatewayTypes.js'
+import type { GatewayRpc } from '../app/interfaces.js'
+import { loadSlashCatalog } from '../app/slashCatalog.js'
+import type { SlashCatalog } from '../types.js'
+
+const REPO_SKILL = '/repo-probe'
+
+const catalogFor = (sessionId: string | undefined): CommandsCatalogResponse => {
+ const skills = sessionId === 'repo' ? [REPO_SKILL] : []
+
+ return {
+ canon: Object.fromEntries(skills.map(skill => [skill, skill])),
+ categories: [],
+ pairs: skills.map(skill => [skill, 'skill']),
+ skill_count: skills.length,
+ sub: {}
+ }
+}
+
+describe('loadSlashCatalog', () => {
+ it("binds the catalog to the session, so each session's project skills replace the last one's", async () => {
+ const requested: (string | undefined)[] = []
+
+ const fake = async (method: string, params: { session_id?: string } = {}) => {
+ expect(method).toBe('commands.catalog')
+ requested.push(params.session_id)
+
+ return catalogFor(params.session_id)
+ }
+
+ // SAFETY: the fake answers only commands.catalog, the one method loadSlashCatalog calls, with that method's result type.
+ const rpc = fake as GatewayRpc
+
+ let catalog: null | SlashCatalog = null
+ const setCatalog = (next: null | SlashCatalog) => {
+ catalog = next
+ }
+
+ await loadSlashCatalog(rpc, null, setCatalog)
+ expect(catalog?.canon[REPO_SKILL]).toBeUndefined()
+
+ await loadSlashCatalog(rpc, 'repo', setCatalog)
+ expect(catalog?.canon[REPO_SKILL]).toBe(REPO_SKILL)
+ expect(catalog?.skillCount).toBe(1)
+
+ await loadSlashCatalog(rpc, 'elsewhere', setCatalog)
+ expect(catalog?.canon[REPO_SKILL]).toBeUndefined()
+
+ expect(requested).toEqual([undefined, 'repo', 'elsewhere'])
+ })
+})
diff --git a/ui-tui/src/app/createGatewayEventHandler.ts b/ui-tui/src/app/createGatewayEventHandler.ts
index a99d58563bd..aa01cc69a43 100644
--- a/ui-tui/src/app/createGatewayEventHandler.ts
+++ b/ui-tui/src/app/createGatewayEventHandler.ts
@@ -11,7 +11,6 @@ import { buildSetupRequiredSections, setupRequiredTitle } from '../content/setup
import { usageFromTick } from '../domain/usage.js'
import type {
AnyGatewayEvent,
- CommandsCatalogResponse,
ConfigFullResponse,
DelegationStatusResponse,
GatewaySkin,
@@ -47,6 +46,7 @@ import { markBubbleShown, newlyStartedRows } from './pendingBubbles.js'
import { flashGoodVibes, flashPet } from './petFlashStore.js'
import { forgetServerRequest } from './serverRequestStore.js'
import { noteCanonicalCompletion } from './slash/canonicalSessionCommands.js'
+import { loadSlashCatalog } from './slashCatalog.js'
import { reportStartupLatency } from './startupLatency.js'
import { markNextSubmitVoice } from './submissionCore.js'
import { captureDestination, isCurrentDestination } from './submissionDestination.js'
@@ -915,32 +915,9 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:
void rpc('wake.start', { surface: 'tui' }).catch(() => undefined)
}
- // Bound to the live session when one exists (reconnect): project-local
- // skills follow the session's repo. Before the first session the gateway
- // uses the same workspace it seeds a new session with.
- const catalogSid = getUiState().sid
-
- rpc<CommandsCatalogResponse>('commands.catalog', catalogSid ? { session_id: catalogSid } : {})
- .then(r => {
- if (!r?.pairs) {
- return
- }
-
- setCatalog({
- canon: (r.canon ?? {}) as Record<string, string>,
- categories: r.categories ?? [],
- pairs: r.pairs as [string, string][],
- skillCount: (r.skill_count ?? 0) as number,
- sub: (r.sub ?? {}) as Record<string, string[]>
- })
-
- if (r.warning) {
- turnController.pushActivity(String(r.warning), 'warn')
- }
- })
- .catch((e: unknown) =>
- turnController.pushActivity(t('gatewayMsg.startup.commandCatalogUnavailable', rpcErrorMessage(e)), 'info')
- )
+ // Before the first session the gateway uses the same workspace it seeds a new session with;
+ // useMainApp reloads it bound to each session once one is live.
+ void loadSlashCatalog(rpc, getUiState().sid, setCatalog)
// Keep the recovery target until resume succeeds, including across a second
// disconnect during setup or history loading. Recovery never resends the prompt.
diff --git a/ui-tui/src/app/slashCatalog.ts b/ui-tui/src/app/slashCatalog.ts
new file mode 100644
index 00000000000..4d2db838015
--- /dev/null
+++ b/ui-tui/src/app/slashCatalog.ts
@@ -0,0 +1,30 @@
+import type { CommandsCatalogResponse } from '../gatewayTypes.js'
+import { t } from '../i18n/runtime.js'
+import { rpcErrorMessage } from '../lib/rpc.js'
+import type { SlashCatalog } from '../types.js'
+
+import type { GatewayRpc, StateSetter } from './interfaces.js'
+import { turnController } from './turnController.js'
+
+/** `commands.catalog` bound to `sid` when there is one: project-local skills follow the session's repo,
+ * so the catalog is reloaded whenever the live session changes. */
+export const loadSlashCatalog = (rpc: GatewayRpc, sid: null | string, setCatalog: StateSetter<null | SlashCatalog>) =>
+ rpc<CommandsCatalogResponse>('commands.catalog', sid ? { session_id: sid } : {})
+ .then(r => {
+ if (!r?.pairs) {
+ return
+ }
+
+ setCatalog({
+ canon: r.canon ?? {},
+ categories: r.categories ?? [],
+ pairs: r.pairs,
+ skillCount: r.skill_count ?? 0,
+ sub: r.sub ?? {}
+ })
+
+ if (r.warning) {
+ turnController.pushActivity(r.warning, 'warn')
+ }
+ })
+ .catch(e => turnController.pushActivity(t('gatewayMsg.startup.commandCatalogUnavailable', rpcErrorMessage(e)), 'info'))
diff --git a/ui-tui/src/app/useMainApp.ts b/ui-tui/src/app/useMainApp.ts
index 310727df1c2..c438965e8d0 100644
--- a/ui-tui/src/app/useMainApp.ts
+++ b/ui-tui/src/app/useMainApp.ts
@@ -62,6 +62,7 @@ import { applyProcessSnapshot, type ProcessEntry } from './processRoster.js'
import { scrollWithSelectionBy } from './scroll.js'
import { respondToServerRequest } from './serverRequestStore.js'
import { mutateCanonicalSession } from './slash/canonicalSessionControls.js'
+import { loadSlashCatalog } from './slashCatalog.js'
import { captureDestination, isCurrentDestination, type SubmissionDestination } from './submissionDestination.js'
import { turnController } from './turnController.js'
import { patchTurnState, useTurnSelector } from './turnStore.js'
@@ -679,6 +680,12 @@ export function useMainApp(gw: GatewayClient) {
useConfigSync({ gw, setBellOnComplete, setBellOnPrompt, setVoiceEnabled, setVoiceRecordKey, sid: ui.sid })
useBatteryPoll(gw)
+ useEffect(() => {
+ if (ui.sid && ui.gatewayConnected !== false) {
+ void loadSlashCatalog(rpc, ui.sid, setCatalog)
+ }
+ }, [rpc, ui.sid, ui.gatewayConnected])
+
useEffect(() => {
if (!ui.sid) {
patchUiState({ liveSessionCount: 0, sessionTitle: '' })