MCPcopy Index your code
hub / github.com/codeaashu/claude-code / read

Method read

src/cli/structuredIO.ts:215–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

213 }
214
215 private async *read() {
216 let content = ''
217
218 // Called once before for-await (an empty this.input otherwise skips the
219 // loop body entirely), then again per block. prependedLines re-check is
220 // inside the while so a prepend pushed between two messages in the SAME
221 // block still lands first.
222 const splitAndProcess = async function* (this: StructuredIO) {
223 for (;;) {
224 if (this.prependedLines.length > 0) {
225 content = this.prependedLines.join('') + content
226 this.prependedLines = []
227 }
228 const newline = content.indexOf('\n')
229 if (newline === -1) break
230 const line = content.slice(0, newline)
231 content = content.slice(newline + 1)
232 const message = await this.processLine(line)
233 if (message) {
234 logForDiagnosticsNoPII('info', 'cli_stdin_message_parsed', {
235 type: message.type,
236 })
237 yield message
238 }
239 }
240 }.bind(this)
241
242 yield* splitAndProcess()
243
244 for await (const block of this.input) {
245 content += block
246 yield* splitAndProcess()
247 }
248 if (content) {
249 const message = await this.processLine(content)
250 if (message) {
251 yield message
252 }
253 }
254 this.inputClosed = true
255 for (const request of this.pendingRequests.values()) {
256 // Reject all pending requests if the input stream
257 request.reject(
258 new Error('Tool permission stream closed before response received'),
259 )
260 }
261 }
262
263 getPendingPermissionRequests() {
264 return Array.from(this.pendingRequests.values())

Callers 1

constructorMethod · 0.95

Calls 4

processLineMethod · 0.95
logForDiagnosticsNoPIIFunction · 0.85
valuesMethod · 0.80
rejectMethod · 0.80

Tested by

no test coverage detected