MCPcopy
hub / github.com/codeaashu/claude-code / getLogDisplayTitle

Function getLogDisplayTitle

src/utils/log.ts:30–58  ·  view source on GitHub ↗
(
  log: LogOption,
  defaultTitle?: string,
)

Source from the content-addressed store, hash-verified

28 * Falls back to a truncated session ID when no other title is available.
29 */
30export function getLogDisplayTitle(
31 log: LogOption,
32 defaultTitle?: string,
33): string {
34 // Skip firstPrompt if it's a tick/goal message (autonomous mode auto-prompt)
35 const isAutonomousPrompt = log.firstPrompt?.startsWith(`<${TICK_TAG}>`)
36 // Strip display-unfriendly tags (command-name, ide_opened_file, etc.) early
37 // so that command-only prompts (e.g. /clear) become empty and fall through
38 // to the next fallback instead of showing raw XML tags.
39 // Note: stripDisplayTags returns the original when stripping yields empty,
40 // so we call stripDisplayTagsAllowEmpty to detect command-only prompts.
41 const strippedFirstPrompt = log.firstPrompt
42 ? stripDisplayTagsAllowEmpty(log.firstPrompt)
43 : ''
44 const useFirstPrompt = strippedFirstPrompt && !isAutonomousPrompt
45 const title =
46 log.agentName ||
47 log.customTitle ||
48 log.summary ||
49 (useFirstPrompt ? strippedFirstPrompt : undefined) ||
50 defaultTitle ||
51 // For autonomous sessions without other context, show a meaningful label
52 (isAutonomousPrompt ? 'Autonomous session' : undefined) ||
53 // Fall back to truncated session ID for lite logs with no metadata
54 (log.sessionId ? log.sessionId.slice(0, 8) : '') ||
55 ''
56 // Strip display-unfriendly tags (like <ide_opened_file>) for cleaner titles
57 return stripDisplayTags(title).trim()
58}
59
60export function dateToFilename(date: Date): string {
61 return date.toISOString().replace(/[:.]/g, '-')

Callers 4

buildLogLabelFunction · 0.85
LogSelectorFunction · 0.85
logContainsQueryFunction · 0.85
agenticSessionSearchFunction · 0.85

Calls 2

stripDisplayTagsFunction · 0.85

Tested by

no test coverage detected