beast-agent 1.3.1 → 1.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "beast-agent",
3
3
  "productName": "Beast Agent",
4
- "version": "1.3.1",
4
+ "version": "1.4.1",
5
5
  "description": "Ultra-fast local agent shell for Windows.",
6
6
  "author": "algokodcom (AlgoKod)",
7
7
  "license": "MIT",
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,34 @@ 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
+ /* masaüstü Beast Code paneliyle AYNI klasör — WhatsApp'tan yazınca
320
+ panelde aynı dosyalar canlı görünür */
321
+ const dir = ideRoot();
322
+ try { fs.mkdirSync(dir, { recursive: true }); } catch {}
323
+ return dir;
324
+ }
325
+
326
+ /* Sohbetin Beast Code oturumu: masaüstü paneliyle AYNI oturum (klasör bazlı
327
+ bcGetSession) — WhatsApp'tan yazılan sohbet, masaüstü Beast Code panelinde
328
+ canlı akar; panelde yazılan da WhatsApp'a düşer */
329
+ function waBcSession(jid) {
330
+ const s = bcGetSession(waBcWorkspace());
331
+ if (waChats.get(jid) !== s.id) {
332
+ waChats.set(jid, s.id);
333
+ waRememberSession(jid, s.id);
334
+ saveWaChats();
335
+ if (wa) wa.setWatchJids([...waChats.keys()]);
336
+ }
337
+ return s;
338
+ }
339
+
306
340
  function settingsLog(line) {
307
341
  try {
308
342
  fs.appendFileSync(
@@ -655,6 +689,9 @@ function waSlashHelp() {
655
689
  '• */new* – yeni oturum aç (kod verilir)',
656
690
  '• */open* <kod> – o koddaki oturuma geç',
657
691
  '• */sessions* – bu sohbetin oturumları',
692
+ '• */beastcode* [görev] – ⚡ UZAKTAN KODLAMA: masaüstünde Beast Code paneli açılır, WhatsApp\u2019tan uygulama yazdır (örn: /beastcode hava durumu uygulaması yaz)',
693
+ '• */beastagent* – kodlama modunu kapat, masaüstünde chat ekranına dön',
694
+ '• */plan* · */build* · */auto* – BeastCode modunda çalışma modu (planla · uygula · otomatik)',
658
695
  '• */stop* – koşan işleri durdur (ajanlar+turlar; cron/izleyici/olay sürer)',
659
696
  '• */start* – durdurulan servisleri devam ettir',
660
697
  '• */restart* – uygulamayı yeniden başlat',
@@ -910,7 +947,7 @@ function resolveFirstApproval(ok, always) {
910
947
  }
911
948
 
912
949
  /* true dönerse mesaj slash komutuydu ve cevap gönderildi */
913
- async function tryWaSlash(jid, rawText, senderNum) {
950
+ async function tryWaSlash(jid, rawText, senderNum, payload0) {
914
951
  const t = String(rawText || '').trim();
915
952
  if (!t.startsWith('/') || t.includes('\n')) return false;
916
953
  const parts = t.slice(1).split(/\s+/);
@@ -1150,6 +1187,67 @@ async function tryWaSlash(jid, rawText, senderNum) {
1150
1187
  out =
1151
1188
  `*WA:* ${wst.status}${wst.user ? ' (' + wst.user + ')' : ''}\n` +
1152
1189
  `*İzleyici:* ${watchers.list().length} adet\n*Cron:* ${jobs} aktif görev`;
1190
+ } else if (cmd === 'beastcode') {
1191
+ /* /beastcode [görev] — WhatsApp'tan UZAKTAN KODLAMA modu:
1192
+ masaüstünde GERÇEK Beast Code paneli açılır (IDE ekranı), sohbet
1193
+ panel oturumuyla birleşir; yazılanlar panelde canlı akar */
1194
+ const s = waBcSession(jid);
1195
+ waBcMode.add(jid);
1196
+ saveWaChats();
1197
+ emitWaEventSafe({ type: 'bc-screen', on: true, sessionId: s.id, workspace: s.workspace || waBcWorkspace() });
1198
+ if (arg) {
1199
+ /* görev normal WA akışına verilir — meşgulse bekleme-kuyruğu devrede */
1200
+ waQueuePush(jid, { text: arg, isGroup: !!(payload0 && payload0.isGroup) }, senderNum);
1201
+ out =
1202
+ `*⚡ BEASTCODE MODU AÇILDI — görev alındı, yazıyorum.*\n` +
1203
+ `Bilgisayarda Beast Code paneli açıldı: \`${s.workspace || waBcWorkspace()}\`\n` +
1204
+ `Mod değiştir: \`/plan\` (sadece plan) · \`/build\` (uygula) · \`/auto\`\n` +
1205
+ `Sohbete dönmek için: /beastagent`;
1206
+ } else {
1207
+ out =
1208
+ `*⚡ BEASTCODE MODU AÇILDI*\n` +
1209
+ `Bilgisayarda Beast Code paneli açıldı — çalışma klasörü: \`${s.workspace || waBcWorkspace()}\`\n` +
1210
+ `Ne yazarsan UYGULAMA olarak yaparım: dosyalar yazar, komut çalıştırır, doğrular.\n` +
1211
+ `İlk görevi yaz — örn: "todo listesi uygulaması yaz"\n` +
1212
+ `Sohbete dönmek için: /beastagent`;
1213
+ }
1214
+ } else if (cmd === 'beastagent') {
1215
+ /* /beastagent — kodlama modundan normal sohbete dön; masaüstünde
1216
+ Beast Code paneli kapanır, chat ekranı geri gelir */
1217
+ if (!waBcMode.has(jid)) {
1218
+ out = 'Zaten sohbet modundasın — kodlamak için /beastcode yaz.';
1219
+ } else {
1220
+ const sid = waChats.get(jid);
1221
+ if (sid && engine.isBusy(sid)) {
1222
+ try { engine.interrupt(sid, 'kullanıcı /beastagent ile sohbet moduna döndü'); } catch {}
1223
+ }
1224
+ waBcMode.delete(jid);
1225
+ const v = engine.createSession();
1226
+ waChats.set(jid, v.id);
1227
+ waRememberSession(jid, v.id);
1228
+ saveWaChats();
1229
+ if (wa) wa.setWatchJids([...waChats.keys()]);
1230
+ emitWaEventSafe({ type: 'bc-screen', on: false });
1231
+ out =
1232
+ `*💬 Sohbet moduna dönüldü* — masaüstünde chat ekranı açıldı, yeni oturum \`${v.code}\`.\n` +
1233
+ `Kodlar duruyor: \`${waBcWorkspace()}\`\n` +
1234
+ `Tekrar kodlamak için: /beastcode`;
1235
+ }
1236
+ } else if (waBcMode.has(jid) && (cmd === 'plan' || cmd === 'build' || cmd === 'auto')) {
1237
+ /* BeastCode modunda çalışma modu: /plan · /build · /auto */
1238
+ const sid = waChats.get(jid);
1239
+ const s = sid ? engine.cache.get(sid) : null;
1240
+ if (s && s.bcCode) {
1241
+ s.bcMode = cmd;
1242
+ engine.cache.set(sid, s);
1243
+ out = cmd === 'plan'
1244
+ ? '*🔍 PLAN MODU* — dosyaları inceler, kod YAZMAZ; adım adım uygulama planı verir.'
1245
+ : cmd === 'build'
1246
+ ? '*🛠 BUILD MODU* — son planı uygular: dosyalar, komutlar, doğrulama.'
1247
+ : '*⚡ AUTO MOD* — kısa plan + uygulama + doğrulama.';
1248
+ } else {
1249
+ out = 'Bu komut yalnız BeastCode modunda çalışır — önce /beastcode yaz.';
1250
+ }
1153
1251
  } else if (cmd === 'version') {
1154
1252
  out = `*Beast Agent v${beastVersion()}*\nGüncelleme için: /update (kurulum hazır olunca /update now)`;
1155
1253
  } else {
@@ -1640,7 +1738,7 @@ async function handleWaIncoming(jid, payload, senderNum) {
1640
1738
  /* slash komutları: DM'de her zaman; grupta sadece bot mention edildiyse */
1641
1739
  const txt0 = String(payload.text || '').trim();
1642
1740
  if (txt0.startsWith('/') && !txt0.includes('\n') && (!isGroup || payload.mentioned)) {
1643
- if (await tryWaSlash(jid, txt0, senderNum)) return;
1741
+ if (await tryWaSlash(jid, txt0, senderNum, payload)) return;
1644
1742
  }
1645
1743
 
1646
1744
  if (isGroup) {
@@ -1823,7 +1921,18 @@ async function processWaMessage(jid, payload, senderNum, requeues = 0) {
1823
1921
  engine.setSessionTools(sid, null);
1824
1922
  }
1825
1923
  engine.setSessionModel(sid, botCfg && !botCfg.admin ? (botCfg.model || null) : null);
1826
- waLog(`perm=${fmtPerm(perm)} bot=${botId} sid=${sid}`);
1924
+ /* BEASTCODE MODU: sohbet uzaktan kodlama modundaysa oturumu Beast Code
1925
+ olarak tazele — restart sonrası bcCode/workspace bayrakları dosyadan
1926
+ yüklenmediği için masaüstü bcFlush disipliniyle her mesajda bindirilir */
1927
+ if (waBcMode.has(jid)) {
1928
+ const bs = engine.cache.get(sid);
1929
+ if (bs) {
1930
+ bs.bcCode = true;
1931
+ bs.workspace = waBcWorkspace();
1932
+ engine.cache.set(sid, bs);
1933
+ }
1934
+ }
1935
+ waLog(`perm=${fmtPerm(perm)} bot=${botId} sid=${sid}${waBcMode.has(jid) ? ' beastcode=1' : ''}`);
1827
1936
 
1828
1937
  const participantName = payload.participant ? '+' + String(payload.participant).split('@')[0].split(':')[0] : '';
1829
1938
  /* GRUP GÖNDERENİ: LID çağında gerçek telefon participantAlt'ta gelir.
@@ -1844,6 +1844,23 @@ function onWaEvent(ev) {
1844
1844
  if (!els.settingsOverlay.hidden && setTab === 'integrations') renderIntegrationsPane();
1845
1845
  return;
1846
1846
  }
1847
+ if (ev.type === 'bc-screen') {
1848
+ /* WA'dan /beastcode → masaüstünde GERÇEK Beast Code paneli açılır;
1849
+ /beastagent → chat ekranına dönülür. Panel, WA oturumuna bağlanır:
1850
+ WhatsApp'tan yazılan sohbet canlı olarak panelde akar. */
1851
+ setIdeMode(!!ev.on);
1852
+ if (ev.on) {
1853
+ if (ev.sessionId) bcSessionId = ev.sessionId;
1854
+ bcSetBusy(false);
1855
+ if (ev.workspace) bcLine('t-sys', '[WhatsApp — Beast Code modu açıldı · ' + ev.workspace + ']');
1856
+ else bcLine('t-sys', '[WhatsApp — Beast Code modu açıldı]');
1857
+ } else {
1858
+ if (bcSessionId) bcSessionId = null;
1859
+ bcSetBusy(false);
1860
+ bcStatusHide();
1861
+ }
1862
+ return;
1863
+ }
1847
1864
  if (ev.type === 'queue') {
1848
1865
  /* FEATURE 2: offline kuyruk bildirimi — toast + paneldeki sayaç */
1849
1866
  if (ev.text) toast(ev.text);