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

Function processChunk

source code/utils/earlyInput.ts:74–138  ·  view source on GitHub ↗

* Process a chunk of input data

(str: string)

Source from the content-addressed store, hash-verified

72 * Process a chunk of input data
73 */
74function processChunk(str: string): void {
75 let i = 0
76 while (i < str.length) {
77 const char = str[i]!
78 const code = char.charCodeAt(0)
79
80 // Ctrl+C (code 3) - stop capturing and exit immediately.
81 // We use process.exit here instead of gracefulShutdown because at this
82 // early stage of startup, the shutdown machinery isn't initialized yet.
83 if (code === 3) {
84 stopCapturingEarlyInput()
85 // eslint-disable-next-line custom-rules/no-process-exit
86 process.exit(130) // Standard exit code for Ctrl+C
87 return
88 }
89
90 // Ctrl+D (code 4) - EOF, stop capturing
91 if (code === 4) {
92 stopCapturingEarlyInput()
93 return
94 }
95
96 // Backspace (code 127 or 8) - remove last grapheme cluster
97 if (code === 127 || code === 8) {
98 if (earlyInputBuffer.length > 0) {
99 const last = lastGrapheme(earlyInputBuffer)
100 earlyInputBuffer = earlyInputBuffer.slice(0, -(last.length || 1))
101 }
102 i++
103 continue
104 }
105
106 // Skip escape sequences (arrow keys, function keys, focus events, etc.)
107 // All escape sequences start with ESC (0x1B) and end with a byte in 0x40-0x7E
108 if (code === 27) {
109 i++ // Skip the ESC character
110 // Skip until the terminating byte (@ to ~) or end of string
111 while (
112 i < str.length &&
113 !(str.charCodeAt(i) >= 64 && str.charCodeAt(i) <= 126)
114 ) {
115 i++
116 }
117 if (i < str.length) i++ // Skip the terminating byte
118 continue
119 }
120
121 // Skip other control characters (except tab and newline)
122 if (code < 32 && code !== 9 && code !== 10 && code !== 13) {
123 i++
124 continue
125 }
126
127 // Convert carriage return to newline
128 if (code === 13) {
129 earlyInputBuffer += '\n'
130 i++
131 continue

Callers 1

startCapturingEarlyInputFunction · 0.85

Calls 2

stopCapturingEarlyInputFunction · 0.85
lastGraphemeFunction · 0.85

Tested by

no test coverage detected