MCPcopy Create free account
hub / github.com/WJX20/claude-code / UserPromptMessage

Function UserPromptMessage

src/components/messages/UserPromptMessage.tsx:31–79  ·  view source on GitHub ↗
({
  addMargin,
  param: {
    text
  },
  isTranscriptMode,
  timestamp
}: Props)

Source from the content-addressed store, hash-verified

29const TRUNCATE_HEAD_CHARS = 2_500;
30const TRUNCATE_TAIL_CHARS = 2_500;
31export function UserPromptMessage({
32 addMargin,
33 param: {
34 text
35 },
36 isTranscriptMode,
37 timestamp
38}: Props): React.ReactNode {
39 // REPL.tsx passes isBriefOnly={viewedTeammateTask ? false : isBriefOnly}
40 // but that prop isn't threaded this deep — replicate the override by
41 // reading viewingAgentTaskId directly. Computed here (not in the child)
42 // so the parent Box can drop its backgroundColor: in brief mode the
43 // child renders a label-style layout, and Box backgroundColor paints
44 // behind children unconditionally (they can't opt out).
45 //
46 // Hooks stay INSIDE feature() ternaries so external builds don't pay
47 // the per-scrollback-message store subscription (useSyncExternalStore
48 // bypasses React.memo). Runtime-gated like isBriefEnabled() but inlined
49 // to avoid pulling BriefTool.ts → prompt.ts tool-name strings into
50 // external builds.
51 const isBriefOnly = feature('KAIROS') || feature('KAIROS_BRIEF') ?
52 // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
53 useAppState(s => s.isBriefOnly) : false;
54 const viewingAgentTaskId = feature('KAIROS') || feature('KAIROS_BRIEF') ?
55 // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
56 useAppState(s_0 => s_0.viewingAgentTaskId) : null;
57 // Hoisted to mount-time — per-message component, re-renders on every scroll.
58 const briefEnvEnabled = feature('KAIROS') || feature('KAIROS_BRIEF') ?
59 // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
60 useMemo(() => isEnvTruthy(process.env.CLAUDE_CODE_BRIEF), []) : false;
61 const useBriefLayout = feature('KAIROS') || feature('KAIROS_BRIEF') ? (getKairosActive() || getUserMsgOptIn() && (briefEnvEnabled || getFeatureValue_CACHED_MAY_BE_STALE('tengu_kairos_brief', false))) && isBriefOnly && !isTranscriptMode && !viewingAgentTaskId : false;
62
63 // Truncate before the early return so the hook order is stable.
64 const displayText = useMemo(() => {
65 if (text.length <= MAX_DISPLAY_CHARS) return text;
66 const head = text.slice(0, TRUNCATE_HEAD_CHARS);
67 const tail = text.slice(-TRUNCATE_TAIL_CHARS);
68 const hiddenLines = countCharInString(text, '\n', TRUNCATE_HEAD_CHARS) - countCharInString(tail, '\n');
69 return `${head}\n… +${hiddenLines} lines …\n${tail}`;
70 }, [text]);
71 const isSelected = useContext(MessageActionsSelectedContext);
72 if (!text) {
73 logError(new Error('No content found in user prompt message'));
74 return null;
75 }
76 return <Box flexDirection="column" marginTop={addMargin ? 1 : 0} backgroundColor={isSelected ? 'messageActionsBackground' : useBriefLayout ? undefined : 'userMessageBackground'} paddingRight={useBriefLayout ? 0 : 1}>
77 <HighlightedThinkingText text={displayText} useBriefLayout={useBriefLayout} timestamp={useBriefLayout ? timestamp : undefined} />
78 </Box>;
79}

Callers

nothing calls this directly

Calls 8

featureFunction · 0.85
useAppStateFunction · 0.85
isEnvTruthyFunction · 0.85
getKairosActiveFunction · 0.85
getUserMsgOptInFunction · 0.85
countCharInStringFunction · 0.85
logErrorFunction · 0.50

Tested by

no test coverage detected