Track feature interactions (#2959)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -387,7 +387,8 @@ export function getDefaultUIState(): PersistedUIState {
|
||||
setupScriptPromptDismissedRepoIds: [],
|
||||
acknowledgedAgentsByPaneKey: {},
|
||||
workspaceCleanup: { dismissals: {} },
|
||||
featureTipsSeenIds: []
|
||||
featureTipsSeenIds: [],
|
||||
featureInteractions: {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
import { readdirSync, readFileSync, statSync } from 'node:fs'
|
||||
import { join, relative } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
FEATURE_INTERACTIONS,
|
||||
hasFeatureInteraction,
|
||||
normalizeFeatureInteractions,
|
||||
type FeatureInteractionId
|
||||
} from './feature-interactions'
|
||||
|
||||
type DefinedFeatureInteractionId = (typeof FEATURE_INTERACTIONS)[number]['id']
|
||||
type MissingFeatureInteractionId = Exclude<FeatureInteractionId, DefinedFeatureInteractionId>
|
||||
type ExtraFeatureInteractionId = Exclude<DefinedFeatureInteractionId, FeatureInteractionId>
|
||||
|
||||
const REPO_ROOT = join(__dirname, '..', '..')
|
||||
const SOURCE_ROOTS = ['src/main', 'src/renderer/src', 'src/preload']
|
||||
const PRODUCTION_FILE_PATTERN = /\.(ts|tsx)$/
|
||||
const TEST_FILE_PATTERN = /(?:^|\.)(test|spec)\.(ts|tsx)$/
|
||||
|
||||
describe('feature interactions', () => {
|
||||
it('defines local interaction semantics for product education features', () => {
|
||||
const catalogMatchesPublicUnion: [
|
||||
MissingFeatureInteractionId,
|
||||
ExtraFeatureInteractionId
|
||||
] extends [never, never]
|
||||
? true
|
||||
: never = true
|
||||
const expectedIds: FeatureInteractionId[] = [
|
||||
'workspace-board',
|
||||
'workspace-board-actions',
|
||||
'browser',
|
||||
'tasks',
|
||||
'automations',
|
||||
'automation-created',
|
||||
'automation-run',
|
||||
'browser-annotations',
|
||||
'browser-grab',
|
||||
'workspace-creation',
|
||||
'agent-browser-setup',
|
||||
'agent-browser-use',
|
||||
'agent-orchestration-setup',
|
||||
'agent-orchestration',
|
||||
'ai-commit-generation',
|
||||
'ai-pr-generation',
|
||||
'claude-account-switching',
|
||||
'computer-use-setup',
|
||||
'computer-use',
|
||||
'codex-account-switching',
|
||||
'cookie-import',
|
||||
'floating-workspace',
|
||||
'mobile-pairing',
|
||||
'notifications',
|
||||
'ports',
|
||||
'quick-commands',
|
||||
'resource-manager',
|
||||
'review-notes',
|
||||
'ssh',
|
||||
'terminal-panes',
|
||||
'terminal-tabs',
|
||||
'tab-splits',
|
||||
'usage-tracking',
|
||||
'voice-dictation',
|
||||
'workspace-cleanup'
|
||||
]
|
||||
|
||||
expect(catalogMatchesPublicUnion).toBe(true)
|
||||
expect(FEATURE_INTERACTIONS.map((feature) => feature.id)).toEqual(expectedIds)
|
||||
for (const feature of FEATURE_INTERACTIONS) {
|
||||
expect(feature.interaction.length).toBeGreaterThan(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('normalizes persisted records by removing unknown ids and malformed values', () => {
|
||||
expect(
|
||||
normalizeFeatureInteractions({
|
||||
tasks: { firstInteractedAt: 100 },
|
||||
browser: { firstInteractedAt: Number.NaN },
|
||||
automations: { firstInteractedAt: 200, interactionCount: 3 },
|
||||
'browser-grab': { firstInteractedAt: 250, interactionCount: 0 },
|
||||
unknown: { firstInteractedAt: 200 },
|
||||
'voice-dictation': { firstInteractedAt: 300 }
|
||||
})
|
||||
).toEqual({
|
||||
tasks: { firstInteractedAt: 100, interactionCount: 1 },
|
||||
automations: { firstInteractedAt: 200, interactionCount: 3 },
|
||||
'browser-grab': { firstInteractedAt: 250, interactionCount: 1 },
|
||||
'voice-dictation': { firstInteractedAt: 300, interactionCount: 1 }
|
||||
})
|
||||
})
|
||||
|
||||
it('treats only valid known records as interacted', () => {
|
||||
expect(
|
||||
hasFeatureInteraction({ tasks: { firstInteractedAt: 100, interactionCount: 1 } }, 'tasks')
|
||||
).toBe(true)
|
||||
expect(
|
||||
hasFeatureInteraction({ tasks: { firstInteractedAt: 100, interactionCount: 1 } }, 'browser')
|
||||
).toBe(false)
|
||||
expect(
|
||||
hasFeatureInteraction(
|
||||
{ tasks: { firstInteractedAt: Number.POSITIVE_INFINITY, interactionCount: 1 } },
|
||||
'tasks'
|
||||
)
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps every catalog id wired to a production writer', () => {
|
||||
const productionText = collectProductionSourceText()
|
||||
const missingWriters = FEATURE_INTERACTIONS.map((feature) => feature.id).filter((id) => {
|
||||
const escaped = escapeRegExp(id)
|
||||
const directRecord = new RegExp(
|
||||
`recordFeatureInteraction(?:\\?\\.)?\\(\\s*['"]${escaped}['"]`
|
||||
)
|
||||
const runtimeMappingReturn = new RegExp(`return[^\\n]*['"]${escaped}['"]`)
|
||||
return !directRecord.test(productionText) && !runtimeMappingReturn.test(productionText)
|
||||
})
|
||||
|
||||
expect(missingWriters).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
function collectProductionSourceText(): string {
|
||||
const files = SOURCE_ROOTS.flatMap((root) => collectSourceFiles(join(REPO_ROOT, root)))
|
||||
return files
|
||||
.sort()
|
||||
.map((file) => readFileSync(file, 'utf8'))
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
function collectSourceFiles(directory: string): string[] {
|
||||
const files: string[] = []
|
||||
for (const entry of readdirSync(directory)) {
|
||||
const path = join(directory, entry)
|
||||
const stats = statSync(path)
|
||||
if (stats.isDirectory()) {
|
||||
if (entry === 'node_modules' || entry === 'dist' || entry === 'out') {
|
||||
continue
|
||||
}
|
||||
files.push(...collectSourceFiles(path))
|
||||
continue
|
||||
}
|
||||
const repoRelativePath = relative(REPO_ROOT, path)
|
||||
if (!PRODUCTION_FILE_PATTERN.test(entry) || TEST_FILE_PATTERN.test(entry)) {
|
||||
continue
|
||||
}
|
||||
// Why: the catalog itself proves the id exists, not that runtime code writes it.
|
||||
if (repoRelativePath === 'src/shared/feature-interactions.ts') {
|
||||
continue
|
||||
}
|
||||
files.push(path)
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
export type FeatureInteractionId =
|
||||
| 'workspace-board'
|
||||
| 'workspace-board-actions'
|
||||
| 'browser'
|
||||
| 'tasks'
|
||||
| 'automations'
|
||||
| 'automation-created'
|
||||
| 'automation-run'
|
||||
| 'browser-annotations'
|
||||
| 'browser-grab'
|
||||
| 'workspace-creation'
|
||||
| 'agent-browser-setup'
|
||||
| 'agent-browser-use'
|
||||
| 'agent-orchestration-setup'
|
||||
| 'agent-orchestration'
|
||||
| 'ai-commit-generation'
|
||||
| 'ai-pr-generation'
|
||||
| 'claude-account-switching'
|
||||
| 'computer-use-setup'
|
||||
| 'computer-use'
|
||||
| 'codex-account-switching'
|
||||
| 'cookie-import'
|
||||
| 'floating-workspace'
|
||||
| 'mobile-pairing'
|
||||
| 'notifications'
|
||||
| 'ports'
|
||||
| 'quick-commands'
|
||||
| 'resource-manager'
|
||||
| 'review-notes'
|
||||
| 'ssh'
|
||||
| 'terminal-panes'
|
||||
| 'terminal-tabs'
|
||||
| 'tab-splits'
|
||||
| 'usage-tracking'
|
||||
| 'voice-dictation'
|
||||
| 'workspace-cleanup'
|
||||
|
||||
export type FeatureInteractionDefinition = {
|
||||
id: FeatureInteractionId
|
||||
/** The product action that counts as "the user has interacted with this feature." */
|
||||
interaction: string
|
||||
}
|
||||
|
||||
export type FeatureInteractionRecord = {
|
||||
/** Unix timestamp in milliseconds for the first local interaction. */
|
||||
firstInteractedAt: number
|
||||
/** Number of local interactions recorded for this feature. */
|
||||
interactionCount: number
|
||||
}
|
||||
|
||||
export type FeatureInteractionState = Partial<
|
||||
Record<FeatureInteractionId, FeatureInteractionRecord>
|
||||
>
|
||||
|
||||
// Why: these ids become persisted product state; see
|
||||
// docs/reference/feature-discovery-interaction-tracking.md before changing them.
|
||||
export const FEATURE_INTERACTIONS = [
|
||||
{
|
||||
id: 'workspace-board',
|
||||
interaction: 'workspace board opened'
|
||||
},
|
||||
{
|
||||
id: 'workspace-board-actions',
|
||||
interaction: 'workspace board card, lane, density, or status action used'
|
||||
},
|
||||
{
|
||||
id: 'browser',
|
||||
interaction: 'non-blank browser page viewed'
|
||||
},
|
||||
{
|
||||
id: 'tasks',
|
||||
interaction: 'Tasks page opened'
|
||||
},
|
||||
{
|
||||
id: 'automations',
|
||||
interaction: 'Automations page opened'
|
||||
},
|
||||
{
|
||||
id: 'automation-created',
|
||||
interaction: 'automation created'
|
||||
},
|
||||
{
|
||||
id: 'automation-run',
|
||||
interaction: 'automation run queued'
|
||||
},
|
||||
{
|
||||
id: 'browser-annotations',
|
||||
interaction: 'browser annotation added, copied, or cleared'
|
||||
},
|
||||
{
|
||||
id: 'browser-grab',
|
||||
interaction: 'browser element grab or screenshot used'
|
||||
},
|
||||
{
|
||||
id: 'workspace-creation',
|
||||
interaction: 'workspace creation flow opened'
|
||||
},
|
||||
{
|
||||
id: 'agent-browser-setup',
|
||||
interaction: 'Agent Browser Use setup enabled or opened'
|
||||
},
|
||||
{
|
||||
id: 'agent-browser-use',
|
||||
interaction: 'agent browser runtime method used'
|
||||
},
|
||||
{
|
||||
id: 'agent-orchestration-setup',
|
||||
interaction: 'Agent Orchestration setup enabled or opened'
|
||||
},
|
||||
{
|
||||
id: 'agent-orchestration',
|
||||
interaction: 'agent orchestration runtime method used'
|
||||
},
|
||||
{
|
||||
id: 'ai-commit-generation',
|
||||
interaction: 'AI commit message generation enabled or used'
|
||||
},
|
||||
{
|
||||
id: 'ai-pr-generation',
|
||||
interaction: 'AI pull request generation used'
|
||||
},
|
||||
{
|
||||
id: 'claude-account-switching',
|
||||
interaction: 'Claude managed account added, selected, reauthenticated, or removed'
|
||||
},
|
||||
{
|
||||
id: 'computer-use-setup',
|
||||
interaction: 'Computer Use setup or permission flow opened'
|
||||
},
|
||||
{
|
||||
id: 'computer-use',
|
||||
interaction: 'computer-use runtime method used'
|
||||
},
|
||||
{
|
||||
id: 'codex-account-switching',
|
||||
interaction: 'Codex managed account added, selected, reauthenticated, or removed'
|
||||
},
|
||||
{
|
||||
id: 'cookie-import',
|
||||
interaction: 'browser cookies imported or cleared'
|
||||
},
|
||||
{
|
||||
id: 'floating-workspace',
|
||||
interaction: 'Floating Workspace opened or configured'
|
||||
},
|
||||
{
|
||||
id: 'mobile-pairing',
|
||||
interaction: 'mobile pairing enabled or QR code generated'
|
||||
},
|
||||
{
|
||||
id: 'notifications',
|
||||
interaction: 'desktop notifications enabled or tested'
|
||||
},
|
||||
{
|
||||
id: 'ports',
|
||||
interaction: 'Ports popover opened, configured, or port action used'
|
||||
},
|
||||
{
|
||||
id: 'quick-commands',
|
||||
interaction: 'terminal quick command created or edited'
|
||||
},
|
||||
{
|
||||
id: 'resource-manager',
|
||||
interaction: 'Resource Manager opened or configured'
|
||||
},
|
||||
{
|
||||
id: 'review-notes',
|
||||
interaction: 'review note added or sent to an agent'
|
||||
},
|
||||
{
|
||||
id: 'ssh',
|
||||
interaction: 'SSH target added, imported, tested, connected, disconnected, or configured'
|
||||
},
|
||||
{
|
||||
id: 'terminal-panes',
|
||||
interaction: 'terminal/editor/browser pane created, resized, or merged'
|
||||
},
|
||||
{
|
||||
id: 'terminal-tabs',
|
||||
interaction: 'workspace tab created, moved, reordered, pinned, renamed, recolored, or closed'
|
||||
},
|
||||
{
|
||||
id: 'tab-splits',
|
||||
interaction: 'workspace tab split into another pane'
|
||||
},
|
||||
{
|
||||
id: 'usage-tracking',
|
||||
interaction: 'Stats & Usage or provider usage details opened or configured'
|
||||
},
|
||||
{
|
||||
id: 'voice-dictation',
|
||||
interaction: 'dictation session started'
|
||||
},
|
||||
{
|
||||
id: 'workspace-cleanup',
|
||||
interaction: 'workspace disk space scan, review, or cleanup action used'
|
||||
}
|
||||
] as const satisfies readonly FeatureInteractionDefinition[]
|
||||
|
||||
export const FEATURE_INTERACTION_IDS = FEATURE_INTERACTIONS.map((feature) => feature.id)
|
||||
|
||||
export function isFeatureInteractionId(value: unknown): value is FeatureInteractionId {
|
||||
return (
|
||||
typeof value === 'string' && FEATURE_INTERACTION_IDS.includes(value as FeatureInteractionId)
|
||||
)
|
||||
}
|
||||
|
||||
export function hasFeatureInteraction(
|
||||
state: FeatureInteractionState | null | undefined,
|
||||
id: FeatureInteractionId
|
||||
): boolean {
|
||||
return normalizeFeatureInteractionRecord(state?.[id]) !== null
|
||||
}
|
||||
|
||||
export function normalizeFeatureInteractions(value: unknown): FeatureInteractionState {
|
||||
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
||||
return {}
|
||||
}
|
||||
|
||||
const input = value as Record<string, unknown>
|
||||
const out: FeatureInteractionState = {}
|
||||
for (const id of FEATURE_INTERACTION_IDS) {
|
||||
const record = normalizeFeatureInteractionRecord(input[id])
|
||||
if (record) {
|
||||
out[id] = record
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function normalizeFeatureInteractionRecord(value: unknown): FeatureInteractionRecord | null {
|
||||
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
||||
return null
|
||||
}
|
||||
const input = value as Record<string, unknown>
|
||||
const firstInteractedAt = input.firstInteractedAt
|
||||
if (
|
||||
typeof firstInteractedAt !== 'number' ||
|
||||
!Number.isFinite(firstInteractedAt) ||
|
||||
firstInteractedAt < 0
|
||||
) {
|
||||
return null
|
||||
}
|
||||
const rawInteractionCount = input.interactionCount
|
||||
const interactionCount =
|
||||
typeof rawInteractionCount === 'number' &&
|
||||
Number.isInteger(rawInteractionCount) &&
|
||||
rawInteractionCount > 0
|
||||
? rawInteractionCount
|
||||
: 1
|
||||
return { firstInteractedAt, interactionCount }
|
||||
}
|
||||
@@ -30,6 +30,20 @@ describe('feature tips', () => {
|
||||
expect(tips.map((tip) => tip.id)).toEqual([])
|
||||
})
|
||||
|
||||
it('skips tips for features the user has already interacted with', () => {
|
||||
const tips = getOrderedUnseenFeatureTips({
|
||||
seenTipIds: new Set<FeatureTipId>(),
|
||||
completedTipIds: getCompletedFeatureTipIds({
|
||||
voiceDictationEnabled: false,
|
||||
featureInteractions: {
|
||||
'voice-dictation': { firstInteractedAt: 100, interactionCount: 1 }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
expect(tips.map((tip) => tip.id)).toEqual([])
|
||||
})
|
||||
|
||||
it('normalizes persisted tip ids', () => {
|
||||
expect(normalizeFeatureTipIds(['feature-tour', 'bogus', 'voice-dictation'])).toEqual([
|
||||
'voice-dictation'
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import {
|
||||
hasFeatureInteraction,
|
||||
type FeatureInteractionId,
|
||||
type FeatureInteractionState
|
||||
} from './feature-interactions'
|
||||
|
||||
export type FeatureTipId = 'voice-dictation'
|
||||
|
||||
export type FeatureTipPriority = 'new' | 'unseen'
|
||||
@@ -12,10 +18,13 @@ export type FeatureTip = {
|
||||
description: string
|
||||
action: FeatureTipAction
|
||||
ctaLabel: string
|
||||
/** Feature interactions that mean this tip is no longer useful to show. */
|
||||
completedByFeatureInteractions?: readonly FeatureInteractionId[]
|
||||
}
|
||||
|
||||
export type CompletedFeatureTipState = {
|
||||
voiceDictationEnabled: boolean
|
||||
featureInteractions?: FeatureInteractionState
|
||||
}
|
||||
|
||||
export const FEATURE_TIPS = [
|
||||
@@ -27,7 +36,8 @@ export const FEATURE_TIPS = [
|
||||
description:
|
||||
'Speak into any focused pane and Orca will transcribe it. Press the dictation shortcut to start and stop.',
|
||||
action: 'enable-voice',
|
||||
ctaLabel: 'Set Up Voice'
|
||||
ctaLabel: 'Set Up Voice',
|
||||
completedByFeatureInteractions: ['voice-dictation']
|
||||
}
|
||||
] as const satisfies readonly FeatureTip[]
|
||||
|
||||
@@ -56,6 +66,15 @@ export function getCompletedFeatureTipIds(state: CompletedFeatureTipState): Set<
|
||||
if (state.voiceDictationEnabled) {
|
||||
completedIds.add('voice-dictation')
|
||||
}
|
||||
for (const tip of FEATURE_TIPS) {
|
||||
if (
|
||||
tip.completedByFeatureInteractions?.some((id) =>
|
||||
hasFeatureInteraction(state.featureInteractions, id)
|
||||
)
|
||||
) {
|
||||
completedIds.add(tip.id)
|
||||
}
|
||||
}
|
||||
return completedIds
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
export const ORCA_RUNTIME_RPC_FEATURE_INTERACTION_SOURCE_KEY = '__orcaFeatureInteractionSource'
|
||||
|
||||
export const ORCA_RUNTIME_RPC_BROWSER_UI_SOURCE = 'browser-pane-ui'
|
||||
|
||||
export function withBrowserPaneUiRuntimeRpcSource(value: unknown): unknown {
|
||||
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
||||
return {
|
||||
[ORCA_RUNTIME_RPC_FEATURE_INTERACTION_SOURCE_KEY]: ORCA_RUNTIME_RPC_BROWSER_UI_SOURCE
|
||||
}
|
||||
}
|
||||
return {
|
||||
...value,
|
||||
[ORCA_RUNTIME_RPC_FEATURE_INTERACTION_SOURCE_KEY]: ORCA_RUNTIME_RPC_BROWSER_UI_SOURCE
|
||||
}
|
||||
}
|
||||
|
||||
export function isBrowserPaneUiRuntimeRpcParams(value: unknown): boolean {
|
||||
return (
|
||||
value !== null &&
|
||||
typeof value === 'object' &&
|
||||
!Array.isArray(value) &&
|
||||
(value as Record<string, unknown>)[ORCA_RUNTIME_RPC_FEATURE_INTERACTION_SOURCE_KEY] ===
|
||||
ORCA_RUNTIME_RPC_BROWSER_UI_SOURCE
|
||||
)
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import type { WorkspaceCleanupUIState } from './workspace-cleanup'
|
||||
import type { GitLabProjectSettings } from './gitlab-types'
|
||||
import type { TaskProvider } from './task-providers'
|
||||
import type { FeatureTipId } from './feature-tips'
|
||||
import type { FeatureInteractionState } from './feature-interactions'
|
||||
import type { GitBranchChangeStatus } from './git-status-types'
|
||||
import type { KeybindingOverrides, TerminalShortcutPolicy } from './keybindings'
|
||||
import type { RepoIcon } from './repo-icon'
|
||||
@@ -2309,6 +2310,9 @@ export type PersistedUIState = {
|
||||
/** Feature tips already surfaced to the user. Startup only opens the tips
|
||||
* modal when this list is missing one of the current tip ids. */
|
||||
featureTipsSeenIds?: FeatureTipId[]
|
||||
/** Local product-state facts: feature ids the user has actually used.
|
||||
* Used by education surfaces to avoid teaching already-discovered features. */
|
||||
featureInteractions?: FeatureInteractionState
|
||||
}
|
||||
|
||||
export const PET_SIZE_MIN = 60
|
||||
|
||||
Reference in New Issue
Block a user