/ components / PromptInput / usePromptInputPlaceholder.ts
usePromptInputPlaceholder.ts
 1  import { feature } from 'bun:bundle'
 2  import { useMemo } from 'react'
 3  import { useCommandQueue } from 'src/hooks/useCommandQueue.js'
 4  import { useAppState } from 'src/state/AppState.js'
 5  import { getGlobalConfig } from 'src/utils/config.js'
 6  import { getExampleCommandFromCache } from 'src/utils/exampleCommands.js'
 7  import { isQueuedCommandEditable } from 'src/utils/messageQueueManager.js'
 8  
 9  // Dead code elimination: conditional import for proactive mode
10  /* eslint-disable @typescript-eslint/no-require-imports */
11  const proactiveModule =
12    feature('PROACTIVE') || feature('KAIROS')
13      ? require('../../proactive/index.js')
14      : null
15  
16  type Props = {
17    input: string
18    submitCount: number
19    viewingAgentName?: string
20  }
21  
22  const NUM_TIMES_QUEUE_HINT_SHOWN = 3
23  const MAX_TEAMMATE_NAME_LENGTH = 20
24  
25  export function usePromptInputPlaceholder({
26    input,
27    submitCount,
28    viewingAgentName,
29  }: Props): string | undefined {
30    const queuedCommands = useCommandQueue()
31    const promptSuggestionEnabled = useAppState(s => s.promptSuggestionEnabled)
32    const placeholder = useMemo(() => {
33      if (input !== '') {
34        return
35      }
36  
37      // Show teammate hint when viewing teammate
38      if (viewingAgentName) {
39        const displayName =
40          viewingAgentName.length > MAX_TEAMMATE_NAME_LENGTH
41            ? viewingAgentName.slice(0, MAX_TEAMMATE_NAME_LENGTH - 3) + '...'
42            : viewingAgentName
43        return `Message @${displayName}…`
44      }
45  
46      // Show queue hint if user has not seen it yet.
47      // Only count user-editable commands — task-notification and isMeta
48      // are hidden from the prompt area (see PromptInputQueuedCommands).
49      if (
50        queuedCommands.some(isQueuedCommandEditable) &&
51        (getGlobalConfig().queuedCommandUpHintCount || 0) <
52          NUM_TIMES_QUEUE_HINT_SHOWN
53      ) {
54        return 'Press up to edit queued messages'
55      }
56  
57      // Show example command if user has not submitted yet and suggestions are enabled.
58      // Skip in proactive mode — the model drives the conversation so onboarding
59      // examples are irrelevant and block prompt suggestions from showing.
60      if (
61        submitCount < 1 &&
62        promptSuggestionEnabled &&
63        !proactiveModule?.isProactiveActive()
64      ) {
65        return getExampleCommandFromCache()
66      }
67    }, [
68      input,
69      queuedCommands,
70      submitCount,
71      promptSuggestionEnabled,
72      viewingAgentName,
73    ])
74  
75    return placeholder
76  }