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

Function pickDepthOneUuidCandidate

src/utils/sessionStorage.ts:3276–3305  ·  view source on GitHub ↗

* Disambiguate multiple `"uuid":"<36>","timestamp":"` matches in one line by * finding the one at JSON nesting depth 1. String-aware brace counter: * `{`/`}` inside string values don't count; `\"` and `\\` inside strings are * handled. Candidates is sorted ascending (the scan loop produces them i

(
  buf: Buffer,
  lineStart: number,
  candidates: number[],
)

Source from the content-addressed store, hash-verified

3274 * first depth-1 hit.
3275 */
3276function pickDepthOneUuidCandidate(
3277 buf: Buffer,
3278 lineStart: number,
3279 candidates: number[],
3280): number {
3281 const QUOTE = 0x22
3282 const BACKSLASH = 0x5c
3283 const OPEN_BRACE = 0x7b
3284 const CLOSE_BRACE = 0x7d
3285 let depth = 0
3286 let inString = false
3287 let escapeNext = false
3288 let ci = 0
3289 for (let i = lineStart; ci < candidates.length; i++) {
3290 if (i === candidates[ci]) {
3291 if (depth === 1 && !inString) return candidates[ci]!
3292 ci++
3293 }
3294 const b = buf[i]!
3295 if (escapeNext) {
3296 escapeNext = false
3297 } else if (inString) {
3298 if (b === BACKSLASH) escapeNext = true
3299 else if (b === QUOTE) inString = false
3300 } else if (b === QUOTE) inString = true
3301 else if (b === OPEN_BRACE) depth++
3302 else if (b === CLOSE_BRACE) depth--
3303 }
3304 return candidates.at(-1)!
3305}
3306
3307function walkChainBeforeParse(buf: Buffer): Buffer {
3308 const NEWLINE = 0x0a

Callers 1

walkChainBeforeParseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected