Files
ruflo/plugins/ruflo-console/hooks/data/json-span.ts
ruv 8612da1ed9 fix(ruflo-console): a Dev Tools entry's own cost is the floor of its class; jsonAfter stops at the JSON's own end (0.33.17)
#3788: Claude's confirm gate re-derived the action class from English words and ignored each Dev Tools entry's declared cost, so the
network entry dt-prov-test read as a plain write and could auto-run at write + auto. The entry's cost now travels with the ask
(`declared`) and the gate takes the stricter of the two classes. Live drive: at level write the entry is now refused as a network
action (needs manage); before, it was not asked about.

#3789: jsonAfter sliced to the LAST } or ] in the output, so a trailing log line holding one dropped valid JSON. It now finds the
bracket that closes the first one, skipping strings.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-10-05 11:51:32 -04:00

23 lines
650 B
TypeScript

/** The index of the bracket that closes the one at `start`, skipping strings; -1 when it never closes. A trailing log line with a stray `}` or `]` is not part of the JSON. */
export function closeOf(text: string, start: number): number {
let depth = 0
let inString = false
for (let i = start; i < text.length; i++) {
const ch = text[i]
if (inString) {
if (ch === '\\') i++
else if (ch === '"') inString = false
} else if (ch === '"') {
inString = true
} else if (ch === '{' || ch === '[') {
depth++
} else if ((ch === '}' || ch === ']') && --depth === 0) {
return i
}
}
return -1
}