draply-dev 1.4.4 → 1.4.6
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 +13 -7
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -201,12 +201,18 @@ const server = http.createServer((req, res) => {
|
|
|
201
201
|
const parts = c.selector.split('.');
|
|
202
202
|
return parts.length > 1 ? parts.pop() : '';
|
|
203
203
|
}).filter(Boolean);
|
|
204
|
+
let idsToFind = items.map(c => {
|
|
205
|
+
const parts = c.selector.split('#');
|
|
206
|
+
return parts.length > 1 ? parts.pop() : '';
|
|
207
|
+
}).filter(Boolean);
|
|
204
208
|
|
|
205
209
|
let ctxStart = -1, ctxEnd = -1;
|
|
206
210
|
for (let i = 0; i < lines.length; i++) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
211
|
+
const hasClass = classNamesToFind.some(cls => lines[i].includes(cls));
|
|
212
|
+
const hasId = idsToFind.some(id => lines[i].includes(id));
|
|
213
|
+
if (hasClass || hasId) {
|
|
214
|
+
const s = Math.max(0, i - 60);
|
|
215
|
+
const e = Math.min(lines.length - 1, i + 60);
|
|
210
216
|
if (ctxStart === -1 || s < ctxStart) ctxStart = s;
|
|
211
217
|
if (ctxEnd === -1 || e > ctxEnd) ctxEnd = e;
|
|
212
218
|
}
|
|
@@ -328,18 +334,18 @@ Return ONLY the patch blocks.`;
|
|
|
328
334
|
console.log("Full AI response context for debugging:");
|
|
329
335
|
console.log(apiResult);
|
|
330
336
|
|
|
331
|
-
// Forced fallback for creation if AI
|
|
332
|
-
|
|
337
|
+
// Forced fallback for creation if AI failed match but we have a creation request
|
|
338
|
+
const creationItem = items.find(it => it.type === 'create');
|
|
339
|
+
if (creationItem) {
|
|
333
340
|
console.log("Attempting forced creation fallback...");
|
|
334
341
|
const index = content.toLowerCase().lastIndexOf('</body>');
|
|
335
342
|
if (index >= 0) {
|
|
336
|
-
const creationItem = items.find(it => it.type === 'create');
|
|
337
343
|
const patched = content.slice(0, index) + creationItem.outerHTML + '\n' + content.slice(index);
|
|
338
344
|
const final = rawContent.includes('\r\n') ? patched.replace(/\n/g, '\r\n') : patched;
|
|
339
345
|
fs.writeFileSync(filePath, final, 'utf8');
|
|
340
346
|
console.log(` \x1b[32m✓\x1b[0m Forced creation applied to ${path.basename(filePath)}`);
|
|
341
347
|
items.forEach(item => results.push({ selector: item.selector, ok: true }));
|
|
342
|
-
|
|
348
|
+
continue;
|
|
343
349
|
}
|
|
344
350
|
}
|
|
345
351
|
items.forEach(item => results.push({ selector: item.selector, ok: false, reason: 'AI patch failed to match' }));
|