Skip to content

The agent that grows with you

feat(telemetry): Desktop reports each typed slash command to shared metrics

teknium10631b2498cb6
diff --git a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts
index 4a619493fef..1fc9422685a 100644
--- a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts
@@ -207,8 +207,8 @@ export function useSessionTileDelegate({
deleteSession: async storedSessionId => {
await removeSession(storedSessionId)
},
- executeSlash: async (rawCommand, sessionId) => {
- await executeSlashCommand(rawCommand, { sessionId })
+ executeSlash: async (rawCommand, sessionId, options) => {
+ await executeSlashCommand(rawCommand, { sessionId, ...options })
},
// Gateway reconnect (sleep/wake, backend respawn): every stored→runtime
// binding recorded pre-reconnect points at a runtime id the respawned
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
index 1a82102dcfb..10273267988 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
@@ -66,6 +66,8 @@ vi.mock('@/store/gateway', async importOriginal => ({
// the stored sessions table and 404s on a runtime id. session.title accepts
// the runtime id directly.
const RUNTIME_SESSION_ID = 'rt-abc123'
+// Every typed command also fires this (fire-and-forget); these tests assert the command's own traffic.
+const SLASH_METRIC = 'shared_metrics.slash_command'
function sessionInfo(overrides: Partial<SessionInfo> = {}): SessionInfo {
return {
@@ -341,6 +343,10 @@ describe('usePromptActions /stop', () => {
const calls: Array<{ method: string; params?: Record<string, unknown> }> = []
const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {
+ if (method === SLASH_METRIC) {
+ return {} as never
+ }
+
calls.push({ method, params })
if (method === 'session.interrupt') {
@@ -473,6 +479,10 @@ describe('usePromptActions slash session targeting', () => {
const createBackendSessionForSend = vi.fn(async () => 'rt-brand-new-WRONG')
const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {
+ if (method === SLASH_METRIC) {
+ return {} as never
+ }
+
calls.push({ method, params })
if (method === 'session.resume') {
@@ -653,7 +663,11 @@ describe('usePromptActions /wake', () => {
await handle!.submitText('/wake')
- expect(requestGateway.mock.calls.map(([method]) => method)).toEqual(['wake.status', 'wake.stop', 'wake.status'])
+ expect(requestGateway.mock.calls.map(([method]) => method).filter(m => m !== SLASH_METRIC)).toEqual([
+ 'wake.status',
+ 'wake.stop',
+ 'wake.status'
+ ])
expect(requestGateway).toHaveBeenCalledWith('wake.stop', { persist: true })
expect(requestGateway).not.toHaveBeenCalledWith('slash.exec', expect.anything())
expect(requestGateway).not.toHaveBeenCalledWith('command.dispatch', expect.anything())
@@ -1344,6 +1358,10 @@ describe('usePromptActions slash.exec dispatch payloads', () => {
const states: Record<string, unknown>[] = []
const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {
+ if (method === SLASH_METRIC) {
+ return {} as never
+ }
+
calls.push({ method, params })
if (method === 'slash.exec') {
@@ -1472,6 +1490,10 @@ describe('usePromptActions slash.exec dispatch payloads', () => {
const busyRef = { current: true }
const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {
+ if (method === SLASH_METRIC) {
+ return {} as never
+ }
+
calls.push({ method, params })
if (method === 'slash.exec') {
@@ -1634,6 +1656,10 @@ describe('usePromptActions slash.exec dispatch payloads', () => {
const busyRef = { current: false }
const requestGateway = vi.fn(async (method: string) => {
+ if (method === SLASH_METRIC) {
+ return {} as never
+ }
+
calls.push(method)
return (method === 'slash.exec' ? { type: 'send', message: 'audit the session states' } : {}) as never
@@ -1853,6 +1879,10 @@ describe('usePromptActions slash.exec dispatch payloads', () => {
const states: Record<string, unknown>[] = []
const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {
+ if (method === SLASH_METRIC) {
+ return {} as never
+ }
+
calls.push({ method, params })
if (method === 'slash.exec') {
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts
index 2bb040f5e11..1ef9e1dab51 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash.ts
@@ -190,7 +190,7 @@ export function useSlashCommand(deps: SlashCommandDeps) {
const compressInFlightRef = useRef(new Set<string>())
return useCallback(
- async (rawCommand: string, options?: { sessionId?: string; recordInput?: boolean }) => {
+ async (rawCommand: string, options?: { sessionId?: string; recordInput?: boolean; typed?: boolean }) => {
// Resolve the session this command targets through the SHARED ladder that
// submit.ts uses. A slash command runs backend commands against a runtime
// session, and per-session state (`/goal`, `/usage`, `/status`) is keyed by
@@ -1295,6 +1295,18 @@ export function useSlashCommand(deps: SlashCommandDeps) {
return
}
+ // Shared metrics count each command the user typed exactly once, here, whether the desktop
+ // handles it locally or on the gateway (which no longer counts slash.exec itself). An alias
+ // re-dispatch (recordInput=false) and programmatic calls (typed=false) are not user input.
+ if (recordInput && options?.typed !== false) {
+ const metricsSessionId = sessionHint || activeSessionIdRef.current
+
+ void requestGateway('shared_metrics.slash_command', {
+ command: name,
+ ...(metricsSessionId ? { session_id: metricsSessionId } : {})
+ }).catch(() => undefined)
+ }
+
const ctx: SlashActionCtx = { arg, command, name, recordInput, sessionHint }
const surface = resolveDesktopCommand(`/${name}`)?.surface
diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
index 0720c034518..ffb8cc7f001 100644
--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
@@ -694,7 +694,8 @@ const CompressConversationAction: FC<{ label: string }> = ({ label }) => {
}
triggerHaptic('submit')
- void delegate.executeSlash('/compress', sessionId).catch(error => {
+ // A button, not a typed command: kept out of the slash-command usage count.
+ void delegate.executeSlash('/compress', sessionId, { typed: false }).catch(error => {
notifyError(error, t.assistant.thread.errorCompressFailed)
})
}, [sessionId, t.assistant.thread.errorCompressFailed])
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index d1b9f2f0af6..6014cdf2137 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -2047,7 +2047,7 @@ export interface SessionTileDelegate {
deleteSession(storedSessionId: string): Promise<void>
/** Run a slash command against a tile's session (app-level effects — e.g.
* branch/handoff — act on the main surface, as they should). */
- executeSlash(rawCommand: string, sessionId: string): Promise<void>
+ executeSlash(rawCommand: string, sessionId: string, options?: { typed?: boolean }): Promise<void>
/** Interrupt a tile's running turn. */
interruptSession(runtimeId: string): Promise<void>
/** Drop the wiring cache's stored→runtime bindings. Called on gateway