MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / extractClaudeCodeHints

Function extractClaudeCodeHints

source code/utils/claudeCodeHints.ts:74–122  ·  view source on GitHub ↗
(
  output: string,
  command: string,
)

Source from the content-addressed store, hash-verified

72 * whitespace-separated token is recorded as `sourceCommand`.
73 */
74export function extractClaudeCodeHints(
75 output: string,
76 command: string,
77): { hints: ClaudeCodeHint[]; stripped: string } {
78 // Fast path: no tag open sequence → no work, no allocation.
79 if (!output.includes('<claude-code-hint')) {
80 return { hints: [], stripped: output }
81 }
82
83 const sourceCommand = firstCommandToken(command)
84 const hints: ClaudeCodeHint[] = []
85
86 const stripped = output.replace(HINT_TAG_RE, rawLine => {
87 const attrs = parseAttrs(rawLine)
88 const v = Number(attrs.v)
89 const type = attrs.type
90 const value = attrs.value
91
92 if (!SUPPORTED_VERSIONS.has(v)) {
93 logForDebugging(
94 `[claudeCodeHints] dropped hint with unsupported v=${attrs.v}`,
95 )
96 return ''
97 }
98 if (!type || !SUPPORTED_TYPES.has(type)) {
99 logForDebugging(
100 `[claudeCodeHints] dropped hint with unsupported type=${type}`,
101 )
102 return ''
103 }
104 if (!value) {
105 logForDebugging('[claudeCodeHints] dropped hint with empty value')
106 return ''
107 }
108
109 hints.push({ v, type: type as ClaudeCodeHintType, value, sourceCommand })
110 return ''
111 })
112
113 // Dropping a matched line leaves a blank line (the surrounding newlines
114 // remain). Collapse runs of blank lines introduced by the replace so the
115 // model-visible output doesn't grow vertical whitespace.
116 const collapsed =
117 hints.length > 0 || stripped !== output
118 ? stripped.replace(/\n{3,}/g, '\n\n')
119 : stripped
120
121 return { hints, stripped: collapsed }
122}
123
124function parseAttrs(tagBody: string): Record<string, string> {
125 const attrs: Record<string, string> = {}

Callers 2

callFunction · 0.85
callFunction · 0.85

Calls 4

firstCommandTokenFunction · 0.85
parseAttrsFunction · 0.85
logForDebuggingFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected