| 3 | import { STDIO_PACKAGE } from "./agents.js"; |
| 4 | |
| 5 | function stripJsonComments(text: string): string { |
| 6 | let result = ""; |
| 7 | let i = 0; |
| 8 | while (i < text.length) { |
| 9 | if (text[i] === '"') { |
| 10 | const start = i++; |
| 11 | while (i < text.length && text[i] !== '"') { |
| 12 | if (text[i] === "\\") i++; |
| 13 | i++; |
| 14 | } |
| 15 | result += text.slice(start, ++i); |
| 16 | } else if (text[i] === "/" && text[i + 1] === "/") { |
| 17 | i += 2; |
| 18 | while (i < text.length && text[i] !== "\n") i++; |
| 19 | } else if (text[i] === "/" && text[i + 1] === "*") { |
| 20 | i += 2; |
| 21 | while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++; |
| 22 | i += 2; |
| 23 | } else { |
| 24 | result += text[i++]; |
| 25 | } |
| 26 | } |
| 27 | return result; |
| 28 | } |
| 29 | |
| 30 | export async function readJsonConfig(filePath: string): Promise<Record<string, unknown>> { |
| 31 | let raw: string; |