draply-dev 1.3.6 → 1.3.8

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.
Files changed (2) hide show
  1. package/bin/cli.js +22 -18
  2. 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 applying 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 is:
295
- {"search": "exact existing code to find", "replace": "modified code to replace it with"}
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
- - "search" should be minimal just the line(s) that need changing
300
- - For CSS: modify the class rule properties. If rule doesn't exist, set search to the closing bracket of the nearest rule and add the new rule after it.
301
- - For JSX with className: add/update the style prop on that element
302
- - For JSX with imported CSS: add CSS rules (search for the import line, replace with import + note)
303
- - Keep changes minimal
298
+ - "search" must be an EXACT substring from the file snippet 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
+ - If adding properties to an existing CSS rule or JS object (like a style object), you MUST REPLACE the old values for those properties if they already exist. DO NOT CREATE DUPLICATE KEYS.
302
+ - If the file is JSX, update the style object/prop. Do not duplicate properties inside object literals.
304
303
 
305
304
  Example response:
306
- [{"search": "className=\\"hero\\"", "replace": "className=\\"hero\\" style={{color: 'red', fontSize: '20px'}}"}]
307
-
308
- Return ONLY valid JSON array. No markdown, no explanation.`;
305
+ [
306
+ {
307
+ "search": "style={{ color: 'blue', opacity: 0.5 }}",
308
+ "replace": "style={{ color: '#ff0000', opacity: 0.5 }}"
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
- // Clean markdown fences if present
314
- if (jsonStr.startsWith('```')) {
315
- jsonStr = jsonStr.replace(/^```[a-z]*\n?/, '').replace(/\n?```$/, '');
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, 200)}`);
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draply-dev",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "Visual overlay for any frontend project — move, resize, restyle live in the browser, save to CSS",
5
5
  "author": "Arman",
6
6
  "type": "commonjs",