draply-dev 1.3.6 → 1.3.7
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/bin/cli.js +22 -18
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -282,7 +282,7 @@ const server = http.createServer((req, res) => {
|
|
|
282
282
|
changesBlock += `\nElement .${item.className}:\n${propsStr}\n`;
|
|
283
283
|
});
|
|
284
284
|
|
|
285
|
-
const prompt = `You are a code editor. I need to apply CSS style changes to a file.
|
|
285
|
+
const prompt = `You are a strict code editor. I need to apply CSS style changes to a file.
|
|
286
286
|
|
|
287
287
|
FILE: ${found.relativePath} (lines ${contextStart + 1}-${contextEnd + 1})
|
|
288
288
|
\`\`\`
|
|
@@ -291,37 +291,41 @@ ${snippet}
|
|
|
291
291
|
|
|
292
292
|
CHANGES:
|
|
293
293
|
${changesBlock}
|
|
294
|
-
IMPORTANT: Return ONLY a JSON array of search-and-replace pairs. Each pair
|
|
295
|
-
{"search": "exact
|
|
294
|
+
IMPORTANT: Return ONLY a JSON array of search-and-replace pairs. Each pair format:
|
|
295
|
+
{"search": "exact code to find", "replace": "modified code to replace it with"}
|
|
296
296
|
|
|
297
297
|
Rules:
|
|
298
|
-
- "search" must be an EXACT substring from the file above (copy it precisely)
|
|
299
|
-
-
|
|
300
|
-
-
|
|
301
|
-
- For
|
|
302
|
-
- For JSX with
|
|
303
|
-
- Keep changes minimal
|
|
298
|
+
- "search" must be an EXACT substring from the file above (copy it precisely).
|
|
299
|
+
- Ensure all double quotes inside JSON string values are properly escaped (\\").
|
|
300
|
+
- Do NOT include markdown fences, preambles, or explanations. Only the JSON array.
|
|
301
|
+
- For CSS: modify the class rule.
|
|
302
|
+
- For JSX with className: add/update the style prop on the element. Do not remove existing classes.
|
|
304
303
|
|
|
305
304
|
Example response:
|
|
306
|
-
[
|
|
307
|
-
|
|
308
|
-
|
|
305
|
+
[
|
|
306
|
+
{
|
|
307
|
+
"search": "<section className=\\"hero\\">",
|
|
308
|
+
"replace": "<section className=\\"hero\\" style={{ color: '#ff0000' }}>"
|
|
309
|
+
}
|
|
310
|
+
]`;
|
|
309
311
|
|
|
310
312
|
try {
|
|
311
313
|
const result = await callAI(cfg.apiKey, prompt, cfg.provider || 'groq');
|
|
314
|
+
|
|
315
|
+
// Extract JSON array using regex to ignore any surrounding text/markdown
|
|
312
316
|
let jsonStr = result.trim();
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
jsonStr =
|
|
317
|
+
const match = jsonStr.match(/\[[\s\S]*\]/);
|
|
318
|
+
if (match) {
|
|
319
|
+
jsonStr = match[0];
|
|
316
320
|
}
|
|
317
321
|
|
|
318
322
|
let patches;
|
|
319
323
|
try {
|
|
320
324
|
patches = JSON.parse(jsonStr);
|
|
321
|
-
} catch {
|
|
325
|
+
} catch (err) {
|
|
322
326
|
console.log(` \x1b[31m✗\x1b[0m AI returned invalid JSON`);
|
|
323
|
-
console.log(` Response: ${jsonStr.substring(0,
|
|
324
|
-
items.forEach(item => results.push({ selector: item.selector, ok: false, reason: 'AI returned invalid JSON' }));
|
|
327
|
+
console.log(` Response: ${jsonStr.substring(0, 300)}`);
|
|
328
|
+
items.forEach(item => results.push({ selector: item.selector, ok: false, reason: 'AI returned invalid JSON: ' + err.message }));
|
|
325
329
|
continue;
|
|
326
330
|
}
|
|
327
331
|
|