rentabots-sdk 1.7.37 → 1.7.39
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/dist/index.js +1 -1
- package/init.js +63 -2
- package/init_templates.js +65 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -71,7 +71,7 @@ exports.MessageSchema = zod_1.z.object({
|
|
|
71
71
|
})
|
|
72
72
|
});
|
|
73
73
|
// --- CORE SDK ENGINE ---
|
|
74
|
-
let SDK_VERSION = '1.7.
|
|
74
|
+
let SDK_VERSION = '1.7.39'; // fallback when package.json is unavailable
|
|
75
75
|
try {
|
|
76
76
|
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
77
77
|
SDK_VERSION = pkg.version;
|
package/init.js
CHANGED
|
@@ -369,6 +369,53 @@ async function main() {
|
|
|
369
369
|
return files.length;
|
|
370
370
|
};
|
|
371
371
|
|
|
372
|
+
const synthesizeFilesFromBrain = async (reason) => {
|
|
373
|
+
const prompt = [
|
|
374
|
+
'Generate implementation file contents for this mission and return strict JSON only.',
|
|
375
|
+
'JSON format: {"files":[{"path":"README.md","content":"..."},{"path":"solution.py","content":"..."}]}',
|
|
376
|
+
'No markdown fences. No prose.',
|
|
377
|
+
'REASON: ' + (reason || 'missing-files'),
|
|
378
|
+
'MISSION TITLE: ' + job.title,
|
|
379
|
+
'MISSION DESCRIPTION: ' + job.description,
|
|
380
|
+
'WORKDIR: ' + workDir,
|
|
381
|
+
'MANDATORY OUTPUT FILES: ' + contract.deliverables.join(', '),
|
|
382
|
+
].join('\n');
|
|
383
|
+
const synthArg = JSON.stringify(prompt);
|
|
384
|
+
const synthCmds = [
|
|
385
|
+
'openclaw sessions spawn --task ' + synthArg,
|
|
386
|
+
'openclaw sessions_spawn --task ' + synthArg,
|
|
387
|
+
];
|
|
388
|
+
for (const scmd of synthCmds) {
|
|
389
|
+
const r = await agent.execute(job.id, scmd, { timeout: 600000, shell: true });
|
|
390
|
+
const out = (r.output || '').trim();
|
|
391
|
+
if (r.exitCode !== 0) continue;
|
|
392
|
+
if (/unknown command|usage: openclaw/i.test(out)) continue;
|
|
393
|
+
|
|
394
|
+
let payload = null;
|
|
395
|
+
const s = out.indexOf('{');
|
|
396
|
+
const e = out.lastIndexOf('}');
|
|
397
|
+
if (s >= 0 && e > s) {
|
|
398
|
+
try { payload = JSON.parse(out.slice(s, e + 1)); } catch (_) {}
|
|
399
|
+
}
|
|
400
|
+
const files = Array.isArray(payload?.files) ? payload.files : [];
|
|
401
|
+
let wrote = 0;
|
|
402
|
+
for (const f of files) {
|
|
403
|
+
const p = String(f?.path || '').replace(/\\/g, '/');
|
|
404
|
+
if (!p || p.startsWith('/') || p.includes('..')) continue;
|
|
405
|
+
const content = String(f?.content || '');
|
|
406
|
+
const full = path.join(workDir, p);
|
|
407
|
+
fs.mkdirSync(path.dirname(full), { recursive: true });
|
|
408
|
+
fs.writeFileSync(full, content);
|
|
409
|
+
wrote += 1;
|
|
410
|
+
}
|
|
411
|
+
if (wrote > 0) {
|
|
412
|
+
await agent.sendMessage(job.id, '🧩 Brain-to-file synthesis wrote ' + wrote + ' file(s). Continuing validation.');
|
|
413
|
+
return wrote;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return 0;
|
|
417
|
+
};
|
|
418
|
+
|
|
372
419
|
let beat = 0;
|
|
373
420
|
const heartbeat = setInterval(async () => {
|
|
374
421
|
try {
|
|
@@ -410,6 +457,12 @@ async function main() {
|
|
|
410
457
|
break;
|
|
411
458
|
}
|
|
412
459
|
await agent.sendMessage(job.id, '⚠️ OpenClaw returned but no new implementation files were created. Forcing file-creation repair pass.');
|
|
460
|
+
const wrote = await synthesizeFilesFromBrain('openclaw-returned-without-files');
|
|
461
|
+
if (wrote > 0) {
|
|
462
|
+
overallSuccess = true;
|
|
463
|
+
lastOutput = output;
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
413
466
|
}
|
|
414
467
|
}
|
|
415
468
|
|
|
@@ -459,8 +512,16 @@ async function main() {
|
|
|
459
512
|
const fallbackGenerated = false;
|
|
460
513
|
if (files.length === 0) {
|
|
461
514
|
await agent.setProgress(job.id, 40);
|
|
462
|
-
await agent.sendMessage(job.id, "⚠️ No usable code files were generated
|
|
463
|
-
|
|
515
|
+
await agent.sendMessage(job.id, "⚠️ No usable code files were generated yet. Triggering autonomous brain-to-file synthesis now.");
|
|
516
|
+
const wrote = await synthesizeFilesFromBrain('post-run-empty-workdir');
|
|
517
|
+
if (wrote > 0) {
|
|
518
|
+
files.length = 0;
|
|
519
|
+
walk(workDir);
|
|
520
|
+
}
|
|
521
|
+
if (files.length === 0) {
|
|
522
|
+
await agent.sendMessage(job.id, "⚠️ File synthesis did not produce implementation files yet. Retrying OpenClaw cycle.");
|
|
523
|
+
process.exit(42);
|
|
524
|
+
}
|
|
464
525
|
}
|
|
465
526
|
|
|
466
527
|
const repoRes = await agent.getRepo(job.id);
|
package/init_templates.js
CHANGED
|
@@ -43,7 +43,7 @@ async function main() {
|
|
|
43
43
|
const notifyOwner = async (message, data = null) => {
|
|
44
44
|
try {
|
|
45
45
|
if (!agentId || !agentApiKey) return;
|
|
46
|
-
await fetch(
|
|
46
|
+
await fetch(\`\${apiBase}/agents/\${agentId}/notify\`, {
|
|
47
47
|
method: 'POST',
|
|
48
48
|
headers: {
|
|
49
49
|
'Content-Type': 'application/json',
|
|
@@ -57,7 +57,7 @@ async function main() {
|
|
|
57
57
|
const pushLog = async (level, message) => {
|
|
58
58
|
try {
|
|
59
59
|
if (!agentId || !agentApiKey) return;
|
|
60
|
-
await fetch(
|
|
60
|
+
await fetch(\`\${apiBase}/agents/\${agentId}/logs\`, {
|
|
61
61
|
method: 'POST',
|
|
62
62
|
headers: {
|
|
63
63
|
'Content-Type': 'application/json',
|
|
@@ -353,6 +353,53 @@ async function main() {
|
|
|
353
353
|
return files.length;
|
|
354
354
|
};
|
|
355
355
|
|
|
356
|
+
const synthesizeFilesFromBrain = async (reason) => {
|
|
357
|
+
const prompt = [
|
|
358
|
+
'Generate implementation file contents for this mission and return strict JSON only.',
|
|
359
|
+
'JSON format: {"files":[{"path":"README.md","content":"..."},{"path":"solution.py","content":"..."}]}',
|
|
360
|
+
'No markdown fences. No prose.',
|
|
361
|
+
'REASON: ' + (reason || 'missing-files'),
|
|
362
|
+
'MISSION TITLE: ' + job.title,
|
|
363
|
+
'MISSION DESCRIPTION: ' + job.description,
|
|
364
|
+
'WORKDIR: ' + workDir,
|
|
365
|
+
'MANDATORY OUTPUT FILES: ' + contract.deliverables.join(', '),
|
|
366
|
+
].join('\n');
|
|
367
|
+
const synthArg = JSON.stringify(prompt);
|
|
368
|
+
const synthCmds = [
|
|
369
|
+
'openclaw sessions spawn --task ' + synthArg,
|
|
370
|
+
'openclaw sessions_spawn --task ' + synthArg,
|
|
371
|
+
];
|
|
372
|
+
for (const scmd of synthCmds) {
|
|
373
|
+
const r = await agent.execute(job.id, scmd, { timeout: 600000, shell: true });
|
|
374
|
+
const out = (r.output || '').trim();
|
|
375
|
+
if (r.exitCode !== 0) continue;
|
|
376
|
+
if (/unknown command|usage: openclaw/i.test(out)) continue;
|
|
377
|
+
|
|
378
|
+
let payload = null;
|
|
379
|
+
const s = out.indexOf('{');
|
|
380
|
+
const e = out.lastIndexOf('}');
|
|
381
|
+
if (s >= 0 && e > s) {
|
|
382
|
+
try { payload = JSON.parse(out.slice(s, e + 1)); } catch (_) {}
|
|
383
|
+
}
|
|
384
|
+
const files = Array.isArray(payload?.files) ? payload.files : [];
|
|
385
|
+
let wrote = 0;
|
|
386
|
+
for (const f of files) {
|
|
387
|
+
const p = String(f?.path || '').replace(/\\/g, '/');
|
|
388
|
+
if (!p || p.startsWith('/') || p.includes('..')) continue;
|
|
389
|
+
const content = String(f?.content || '');
|
|
390
|
+
const full = path.join(workDir, p);
|
|
391
|
+
fs.mkdirSync(path.dirname(full), { recursive: true });
|
|
392
|
+
fs.writeFileSync(full, content);
|
|
393
|
+
wrote += 1;
|
|
394
|
+
}
|
|
395
|
+
if (wrote > 0) {
|
|
396
|
+
await agent.sendMessage(job.id, '🧩 Brain-to-file synthesis wrote ' + wrote + ' file(s). Continuing validation.');
|
|
397
|
+
return wrote;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return 0;
|
|
401
|
+
};
|
|
402
|
+
|
|
356
403
|
let beat = 0;
|
|
357
404
|
const heartbeat = setInterval(async () => {
|
|
358
405
|
try {
|
|
@@ -394,6 +441,12 @@ async function main() {
|
|
|
394
441
|
break;
|
|
395
442
|
}
|
|
396
443
|
await agent.sendMessage(job.id, '⚠️ OpenClaw returned but no new implementation files were created. Forcing file-creation repair pass.');
|
|
444
|
+
const wrote = await synthesizeFilesFromBrain('openclaw-returned-without-files');
|
|
445
|
+
if (wrote > 0) {
|
|
446
|
+
overallSuccess = true;
|
|
447
|
+
lastOutput = output;
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
397
450
|
}
|
|
398
451
|
}
|
|
399
452
|
|
|
@@ -444,8 +497,16 @@ async function main() {
|
|
|
444
497
|
const fallbackGenerated = false;
|
|
445
498
|
if (files.length === 0) {
|
|
446
499
|
await agent.setProgress(job.id, 40);
|
|
447
|
-
await agent.sendMessage(job.id, "⚠️ No usable code files were generated
|
|
448
|
-
|
|
500
|
+
await agent.sendMessage(job.id, "⚠️ No usable code files were generated yet. Triggering autonomous brain-to-file synthesis now.");
|
|
501
|
+
const wrote = await synthesizeFilesFromBrain('post-run-empty-workdir');
|
|
502
|
+
if (wrote > 0) {
|
|
503
|
+
files.length = 0;
|
|
504
|
+
walk(workDir);
|
|
505
|
+
}
|
|
506
|
+
if (files.length === 0) {
|
|
507
|
+
await agent.sendMessage(job.id, "⚠️ File synthesis did not produce implementation files yet. Retrying OpenClaw cycle.");
|
|
508
|
+
process.exit(42);
|
|
509
|
+
}
|
|
449
510
|
}
|
|
450
511
|
|
|
451
512
|
const repoRes = await agent.getRepo(job.id);
|