pi-interview 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +13 -5
- package/package.json +1 -1
- package/schema.ts +17 -0
package/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { randomUUID } from "node:crypto";
|
|
|
9
9
|
import { execSync, execFileSync } from "node:child_process";
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
11
|
import { startInterviewServer, getActiveSessions, type ResponseItem } from "./server.js";
|
|
12
|
-
import { validateQuestions, type QuestionsFile } from "./schema.js";
|
|
12
|
+
import { validateQuestions, sanitizeLLMJSON, type QuestionsFile } from "./schema.js";
|
|
13
13
|
import { loadSettings, type InterviewThemeSettings } from "./settings.js";
|
|
14
14
|
|
|
15
15
|
interface GlimpseWindow {
|
|
@@ -185,13 +185,21 @@ function mergeThemeConfig(
|
|
|
185
185
|
|
|
186
186
|
function loadQuestions(questionsInput: string, cwd: string): SavedQuestionsFile {
|
|
187
187
|
const trimmed = questionsInput.trimStart();
|
|
188
|
-
|
|
188
|
+
const looksLikeInlineJSON =
|
|
189
|
+
trimmed.startsWith("{") ||
|
|
190
|
+
/^`{3,}(?:json|jsonc)?\s*\n?\s*\{/i.test(trimmed);
|
|
191
|
+
|
|
192
|
+
if (looksLikeInlineJSON) {
|
|
189
193
|
let data: unknown;
|
|
190
194
|
try {
|
|
191
195
|
data = JSON.parse(trimmed);
|
|
192
|
-
} catch
|
|
193
|
-
|
|
194
|
-
|
|
196
|
+
} catch {
|
|
197
|
+
try {
|
|
198
|
+
data = JSON.parse(sanitizeLLMJSON(trimmed));
|
|
199
|
+
} catch (repairErr) {
|
|
200
|
+
const message = repairErr instanceof Error ? repairErr.message : String(repairErr);
|
|
201
|
+
throw new Error(`Invalid inline JSON: ${message}`);
|
|
202
|
+
}
|
|
195
203
|
}
|
|
196
204
|
return validateQuestions(data);
|
|
197
205
|
}
|
package/package.json
CHANGED
package/schema.ts
CHANGED
|
@@ -337,3 +337,20 @@ export function validateQuestions(data: unknown): QuestionsFile {
|
|
|
337
337
|
|
|
338
338
|
return parsed;
|
|
339
339
|
}
|
|
340
|
+
|
|
341
|
+
// Repair common LLM JSON mistakes (code fences, trailing commas, comments, smart quotes).
|
|
342
|
+
// Only called as a fallback when JSON.parse() already failed.
|
|
343
|
+
export function sanitizeLLMJSON(input: string): string {
|
|
344
|
+
let json = input.trim();
|
|
345
|
+
|
|
346
|
+
const fenceMatch = json.match(/^`{3,}(?:json|jsonc)?\s*\n([\s\S]*?)\n\s*`{3,}\s*$/i);
|
|
347
|
+
if (fenceMatch) {
|
|
348
|
+
json = fenceMatch[1];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
json = json.replace(/^\s*\/\/.*$/gm, "");
|
|
352
|
+
json = json.replace(/,(\s*[}\]])/g, "$1");
|
|
353
|
+
json = json.replace(/\u201C|\u201D/g, '"');
|
|
354
|
+
|
|
355
|
+
return json.trim();
|
|
356
|
+
}
|