mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Fuse two to five completed multi-run entries into one synthesized session, and explain a session's diff as ordered walkthrough stops cached by diff hash. - Multi-run fusion service, persistence, routes and FuseRunDialog - Change walkthrough service, persistence, routes and ChangesWalkthroughDialog - Shared unified-diff parser plus bounded text generation, json-extract, text-truncate and service-error helpers
42 lines
771 B
TypeScript
42 lines
771 B
TypeScript
export function extractFirstJsonObject(text: string): string | null {
|
|
const start = text.indexOf('{')
|
|
if (start === -1) {
|
|
return null
|
|
}
|
|
|
|
let depth = 0
|
|
let inString = false
|
|
let escaped = false
|
|
|
|
for (let index = start; index < text.length; index += 1) {
|
|
const char = text[index]
|
|
|
|
if (inString) {
|
|
if (escaped) {
|
|
escaped = false
|
|
} else if (char === '\\') {
|
|
escaped = true
|
|
} else if (char === '"') {
|
|
inString = false
|
|
}
|
|
continue
|
|
}
|
|
|
|
if (char === '"') {
|
|
inString = true
|
|
continue
|
|
}
|
|
|
|
if (char === '{') {
|
|
depth += 1
|
|
} else if (char === '}') {
|
|
depth -= 1
|
|
if (depth === 0) {
|
|
return text.slice(start, index + 1)
|
|
}
|
|
}
|
|
}
|
|
|
|
return null
|
|
}
|