beast-agent 1.3.1 → 1.4.0
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/package.json +1 -1
- package/src/main.js +122 -3
package/package.json
CHANGED
package/src/main.js
CHANGED
|
@@ -235,6 +235,7 @@ setTimeout(() => {
|
|
|
235
235
|
let wa = null;
|
|
236
236
|
let waChats = new Map(); // jid -> aktif session id
|
|
237
237
|
let waHistory = new Map(); // jid -> [sid,...] bu sohbete ait tüm oturumlar
|
|
238
|
+
let waBcMode = new Set(); // jid -> BeastCode modu AKTİF (WhatsApp'tan uzaktan kodlama)
|
|
238
239
|
let waJidPn = new Map(); // jid -> gerçek telefon numarası (LID fallback için)
|
|
239
240
|
const WA_HISTORY_CAP = 20;
|
|
240
241
|
let tg = null;
|
|
@@ -281,6 +282,10 @@ try {
|
|
|
281
282
|
if (!h.includes(s)) h.push(s);
|
|
282
283
|
waHistory.set(j, h.slice(-WA_HISTORY_CAP));
|
|
283
284
|
}
|
|
285
|
+
/* BeastCode modu: hangi sohbetler uzaktan kodlama yapıyor */
|
|
286
|
+
if (Array.isArray(raw.bcMode)) {
|
|
287
|
+
for (const j of raw.bcMode) if (typeof j === 'string') waBcMode.add(j);
|
|
288
|
+
}
|
|
284
289
|
}
|
|
285
290
|
} catch {}
|
|
286
291
|
|
|
@@ -291,6 +296,7 @@ function saveWaChats() {
|
|
|
291
296
|
JSON.stringify({
|
|
292
297
|
chats: Object.fromEntries(waChats),
|
|
293
298
|
history: Object.fromEntries([...waHistory.entries()].map(([j, a]) => [j, a.slice(-WA_HISTORY_CAP)])),
|
|
299
|
+
bcMode: [...waBcMode],
|
|
294
300
|
})
|
|
295
301
|
);
|
|
296
302
|
} catch {}
|
|
@@ -303,6 +309,46 @@ function waRememberSession(jid, sid) {
|
|
|
303
309
|
waHistory.set(jid, h.slice(-WA_HISTORY_CAP));
|
|
304
310
|
}
|
|
305
311
|
|
|
312
|
+
/* ---------- BEASTCODE MODU (WA'dan uzaktan kodlama) ----------
|
|
313
|
+
/beastcode → sohbet BEAST CODE oturumuna döner: masaüstü IDE paneliyle
|
|
314
|
+
AYNI motor (engine bcCode + buildBcSystem) — todo planı, edit_file/run_command
|
|
315
|
+
disiplini, /plan /build /auto modları. Dosyalar Kullanıcı\BeastCode'a düşer.
|
|
316
|
+
/beastagent → normal sohbet oturumuna geri dönülür. */
|
|
317
|
+
|
|
318
|
+
function waBcWorkspace() {
|
|
319
|
+
const dir = path.join(app.getPath('home'), 'BeastCode');
|
|
320
|
+
try { fs.mkdirSync(dir, { recursive: true }); } catch {}
|
|
321
|
+
return dir;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/* Sohbetin Beast Code oturumu: varsa onu, yoksa yenisini aç */
|
|
325
|
+
function waBcSession(jid) {
|
|
326
|
+
const sid = waChats.get(jid);
|
|
327
|
+
if (sid) {
|
|
328
|
+
try {
|
|
329
|
+
const s = engine.cache.get(sid);
|
|
330
|
+
if (s && s.bcCode) return s;
|
|
331
|
+
} catch {}
|
|
332
|
+
}
|
|
333
|
+
const s = engine._load(engine.createSession().id);
|
|
334
|
+
s.messages = s.messages || [];
|
|
335
|
+
s.bgTitle = 'Beast Code (WA)'; /* sohbet geçmişi listesinde etiketli görünür */
|
|
336
|
+
s.bcCode = true; /* engine: BEAST CODE MODU bloğu + todo disiplini */
|
|
337
|
+
s.workspace = waBcWorkspace();
|
|
338
|
+
engine.cache.set(s.id, s);
|
|
339
|
+
try {
|
|
340
|
+
fs.appendFileSync(
|
|
341
|
+
engine._file(s.id),
|
|
342
|
+
JSON.stringify({ t: 'meta2', bgOf: '', title: 'Beast Code (WA)', at: new Date().toISOString() }) + '\n'
|
|
343
|
+
);
|
|
344
|
+
} catch {}
|
|
345
|
+
waChats.set(jid, s.id);
|
|
346
|
+
waRememberSession(jid, s.id);
|
|
347
|
+
saveWaChats();
|
|
348
|
+
if (wa) wa.setWatchJids([...waChats.keys()]);
|
|
349
|
+
return s;
|
|
350
|
+
}
|
|
351
|
+
|
|
306
352
|
function settingsLog(line) {
|
|
307
353
|
try {
|
|
308
354
|
fs.appendFileSync(
|
|
@@ -655,6 +701,9 @@ function waSlashHelp() {
|
|
|
655
701
|
'• */new* – yeni oturum aç (kod verilir)',
|
|
656
702
|
'• */open* <kod> – o koddaki oturuma geç',
|
|
657
703
|
'• */sessions* – bu sohbetin oturumları',
|
|
704
|
+
'• */beastcode* [görev] – ⚡ UZAKTAN KODLAMA modu: WhatsApp\u2019tan uygulama yazdır (örn: /beastcode hava durumu uygulaması yaz)',
|
|
705
|
+
'• */beastagent* – kodlama modundan normal sohbete dön',
|
|
706
|
+
'• */plan* · */build* · */auto* – BeastCode modunda çalışma modu (planla · uygula · otomatik)',
|
|
658
707
|
'• */stop* – koşan işleri durdur (ajanlar+turlar; cron/izleyici/olay sürer)',
|
|
659
708
|
'• */start* – durdurulan servisleri devam ettir',
|
|
660
709
|
'• */restart* – uygulamayı yeniden başlat',
|
|
@@ -910,7 +959,7 @@ function resolveFirstApproval(ok, always) {
|
|
|
910
959
|
}
|
|
911
960
|
|
|
912
961
|
/* true dönerse mesaj slash komutuydu ve cevap gönderildi */
|
|
913
|
-
async function tryWaSlash(jid, rawText, senderNum) {
|
|
962
|
+
async function tryWaSlash(jid, rawText, senderNum, payload0) {
|
|
914
963
|
const t = String(rawText || '').trim();
|
|
915
964
|
if (!t.startsWith('/') || t.includes('\n')) return false;
|
|
916
965
|
const parts = t.slice(1).split(/\s+/);
|
|
@@ -1150,6 +1199,65 @@ async function tryWaSlash(jid, rawText, senderNum) {
|
|
|
1150
1199
|
out =
|
|
1151
1200
|
`*WA:* ${wst.status}${wst.user ? ' (' + wst.user + ')' : ''}\n` +
|
|
1152
1201
|
`*İzleyici:* ${watchers.list().length} adet\n*Cron:* ${jobs} aktif görev`;
|
|
1202
|
+
} else if (cmd === 'beastcode') {
|
|
1203
|
+
/* /beastcode [görev] — WhatsApp'tan UZAKTAN KODLAMA modu:
|
|
1204
|
+
sohbet masaüstü Beast Code motoruna bağlanır (bcCode + workspace) */
|
|
1205
|
+
const s = waBcSession(jid);
|
|
1206
|
+
waBcMode.add(jid);
|
|
1207
|
+
saveWaChats();
|
|
1208
|
+
emitWaEventSafe({ type: 'bc-mode', jid, on: true });
|
|
1209
|
+
if (arg) {
|
|
1210
|
+
/* görev normal WA akışına verilir — meşgulse bekleme-kuyruğu devrede */
|
|
1211
|
+
waQueuePush(jid, { text: arg, isGroup: !!(payload0 && payload0.isGroup) }, senderNum);
|
|
1212
|
+
out =
|
|
1213
|
+
`*⚡ BEASTCODE MODU — görev alındı, yazıyorum.*\n` +
|
|
1214
|
+
`Klasör: \`${s.workspace}\`\n` +
|
|
1215
|
+
`Mod değiştir: \`/plan\` (sadece plan) · \`/build\` (uygula) · \`/auto\`\n` +
|
|
1216
|
+
`Sohbete dönmek için: /beastagent`;
|
|
1217
|
+
} else {
|
|
1218
|
+
out =
|
|
1219
|
+
`*⚡ BEASTCODE MODU AKTİF*\n` +
|
|
1220
|
+
`Oturum: \`${s.code || '?'}\` · Klasör: \`${s.workspace}\`\n` +
|
|
1221
|
+
`Artık ne yazarsan UYGULAMA olarak yaparım: dosyalar yazar, komut çalıştırır, doğrular.\n` +
|
|
1222
|
+
`İlk görevi yaz — örn: "todo listesi uygulaması yaz"\n` +
|
|
1223
|
+
`Sohbete dönmek için: /beastagent`;
|
|
1224
|
+
}
|
|
1225
|
+
} else if (cmd === 'beastagent') {
|
|
1226
|
+
/* /beastagent — kodlama modundan normal sohbete dön */
|
|
1227
|
+
if (!waBcMode.has(jid)) {
|
|
1228
|
+
out = 'Zaten sohbet modundasın — kodlamak için /beastcode yaz.';
|
|
1229
|
+
} else {
|
|
1230
|
+
const sid = waChats.get(jid);
|
|
1231
|
+
if (sid && engine.isBusy(sid)) {
|
|
1232
|
+
try { engine.interrupt(sid, 'kullanıcı /beastagent ile sohbet moduna döndü'); } catch {}
|
|
1233
|
+
}
|
|
1234
|
+
waBcMode.delete(jid);
|
|
1235
|
+
const v = engine.createSession();
|
|
1236
|
+
waChats.set(jid, v.id);
|
|
1237
|
+
waRememberSession(jid, v.id);
|
|
1238
|
+
saveWaChats();
|
|
1239
|
+
if (wa) wa.setWatchJids([...waChats.keys()]);
|
|
1240
|
+
emitWaEventSafe({ type: 'bc-mode', jid, on: false });
|
|
1241
|
+
out =
|
|
1242
|
+
`*💬 Sohbet moduna dönüldü* — yeni oturum \`${v.code}\`.\n` +
|
|
1243
|
+
`Kodlar duruyor: \`${waBcWorkspace()}\`\n` +
|
|
1244
|
+
`Tekrar kodlamak için: /beastcode`;
|
|
1245
|
+
}
|
|
1246
|
+
} else if (waBcMode.has(jid) && (cmd === 'plan' || cmd === 'build' || cmd === 'auto')) {
|
|
1247
|
+
/* BeastCode modunda çalışma modu: /plan · /build · /auto */
|
|
1248
|
+
const sid = waChats.get(jid);
|
|
1249
|
+
const s = sid ? engine.cache.get(sid) : null;
|
|
1250
|
+
if (s && s.bcCode) {
|
|
1251
|
+
s.bcMode = cmd;
|
|
1252
|
+
engine.cache.set(sid, s);
|
|
1253
|
+
out = cmd === 'plan'
|
|
1254
|
+
? '*🔍 PLAN MODU* — dosyaları inceler, kod YAZMAZ; adım adım uygulama planı verir.'
|
|
1255
|
+
: cmd === 'build'
|
|
1256
|
+
? '*🛠 BUILD MODU* — son planı uygular: dosyalar, komutlar, doğrulama.'
|
|
1257
|
+
: '*⚡ AUTO MOD* — kısa plan + uygulama + doğrulama.';
|
|
1258
|
+
} else {
|
|
1259
|
+
out = 'Bu komut yalnız BeastCode modunda çalışır — önce /beastcode yaz.';
|
|
1260
|
+
}
|
|
1153
1261
|
} else if (cmd === 'version') {
|
|
1154
1262
|
out = `*Beast Agent v${beastVersion()}*\nGüncelleme için: /update (kurulum hazır olunca /update now)`;
|
|
1155
1263
|
} else {
|
|
@@ -1640,7 +1748,7 @@ async function handleWaIncoming(jid, payload, senderNum) {
|
|
|
1640
1748
|
/* slash komutları: DM'de her zaman; grupta sadece bot mention edildiyse */
|
|
1641
1749
|
const txt0 = String(payload.text || '').trim();
|
|
1642
1750
|
if (txt0.startsWith('/') && !txt0.includes('\n') && (!isGroup || payload.mentioned)) {
|
|
1643
|
-
if (await tryWaSlash(jid, txt0, senderNum)) return;
|
|
1751
|
+
if (await tryWaSlash(jid, txt0, senderNum, payload)) return;
|
|
1644
1752
|
}
|
|
1645
1753
|
|
|
1646
1754
|
if (isGroup) {
|
|
@@ -1823,7 +1931,18 @@ async function processWaMessage(jid, payload, senderNum, requeues = 0) {
|
|
|
1823
1931
|
engine.setSessionTools(sid, null);
|
|
1824
1932
|
}
|
|
1825
1933
|
engine.setSessionModel(sid, botCfg && !botCfg.admin ? (botCfg.model || null) : null);
|
|
1826
|
-
|
|
1934
|
+
/* BEASTCODE MODU: sohbet uzaktan kodlama modundaysa oturumu Beast Code
|
|
1935
|
+
olarak tazele — restart sonrası bcCode/workspace bayrakları dosyadan
|
|
1936
|
+
yüklenmediği için masaüstü bcFlush disipliniyle her mesajda bindirilir */
|
|
1937
|
+
if (waBcMode.has(jid)) {
|
|
1938
|
+
const bs = engine.cache.get(sid);
|
|
1939
|
+
if (bs) {
|
|
1940
|
+
bs.bcCode = true;
|
|
1941
|
+
bs.workspace = waBcWorkspace();
|
|
1942
|
+
engine.cache.set(sid, bs);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
waLog(`perm=${fmtPerm(perm)} bot=${botId} sid=${sid}${waBcMode.has(jid) ? ' beastcode=1' : ''}`);
|
|
1827
1946
|
|
|
1828
1947
|
const participantName = payload.participant ? '+' + String(payload.participant).split('@')[0].split(':')[0] : '';
|
|
1829
1948
|
/* GRUP GÖNDERENİ: LID çağında gerçek telefon participantAlt'ta gelir.
|