@7ots/cli 0.1.17 → 0.1.36

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 (107) hide show
  1. package/.env.example +14 -0
  2. package/README.md +11 -0
  3. package/brand/logos/base.svg +1 -0
  4. package/brand/logos/clawpump.png +0 -0
  5. package/brand/logos/conductors.svg +1 -0
  6. package/brand/logos/notlogin.svg +12 -0
  7. package/brand/logos/pumpfun.png +0 -0
  8. package/brand/logos/solana.png +0 -0
  9. package/brand/logos/spawnerbot.svg +1 -0
  10. package/brand/logos/virtuals.png +0 -0
  11. package/cli/7ots.mjs +61 -1
  12. package/cli/lib/account.mjs +23 -3
  13. package/cli/lib/assistant.mjs +92 -14
  14. package/cli/lib/brain.mjs +84 -11
  15. package/cli/lib/card-shot.mjs +1 -1
  16. package/cli/lib/config.mjs +14 -3
  17. package/cli/lib/desktop-sync.mjs +177 -0
  18. package/cli/lib/i18n.mjs +9 -0
  19. package/cli/lib/inferences.mjs +19 -2
  20. package/cli/lib/integrations.mjs +98 -13
  21. package/cli/lib/mcp.mjs +1 -1
  22. package/cli/lib/open.mjs +3 -1
  23. package/cli/lib/pet-server.mjs +352 -41
  24. package/cli/lib/prompts.mjs +1 -1
  25. package/cli/lib/screen.mjs +1 -1
  26. package/cli/lib/senses/gestures.mjs +121 -0
  27. package/cli/lib/senses/index.mjs +490 -0
  28. package/cli/lib/senses/rules.mjs +159 -0
  29. package/cli/lib/senses/sources/activity.mjs +95 -0
  30. package/cli/lib/senses/sources/calendar.mjs +75 -0
  31. package/cli/lib/senses/sources/index.mjs +17 -0
  32. package/cli/lib/senses/sources/mail.mjs +48 -0
  33. package/cli/lib/senses/sources/system.mjs +39 -0
  34. package/cli/lib/senses/util.mjs +41 -0
  35. package/cli/lib/senses/vendor.mjs +78 -0
  36. package/cli/lib/stt-local.py +16 -8
  37. package/cli/lib/stt.mjs +53 -6
  38. package/cli/lib/tooluse.mjs +56 -0
  39. package/cli/lib/tts-local.mjs +2 -2
  40. package/cli/lib/vm.mjs +2 -2
  41. package/cli/lib/wake-local.py +109 -0
  42. package/cli/lib/wake.mjs +102 -0
  43. package/cli/pet/electron/main.cjs +190 -8
  44. package/cli/pet/pet.html +153 -34
  45. package/cli/pet/senses.html +342 -0
  46. package/cli/pet/settings.html +815 -74
  47. package/dist/7ots.esm.js +373 -146
  48. package/dist/7ots.esm.js.map +4 -4
  49. package/dist/7ots.iife.js +373 -146
  50. package/dist/7ots.iife.js.map +4 -4
  51. package/llms.txt +27 -0
  52. package/package.json +5 -2
  53. package/server/channels/apuchat.mjs +18 -4
  54. package/server/errors.mjs +90 -0
  55. package/server/notify.mjs +78 -0
  56. package/server/server.mjs +84 -14
  57. package/server/settings.mjs +3 -0
  58. package/server/site.mjs +401 -0
  59. package/server/tts.mjs +29 -5
  60. package/src/avatar/AvatarStage.js +2 -2
  61. package/src/avatar/three.js +3 -2
  62. package/src/character/AvatarEditor.js +2 -1
  63. package/src/character/Character.js +38 -5
  64. package/src/character/TradingCard.js +2 -0
  65. package/src/character/beat.js +64 -2
  66. package/src/character/mods/orc.js +8 -1
  67. package/src/character/mods.js +104 -10
  68. package/src/character/motion.js +252 -1
  69. package/src/character/parts.js +40 -38
  70. package/src/character/styles.js +40 -38
  71. package/src/character3d/Character3D.js +26 -5
  72. package/src/character3d/body.js +14 -12
  73. package/src/character3d/export.js +693 -0
  74. package/src/character3d/fx.js +13 -0
  75. package/src/character3d/index.js +2 -0
  76. package/src/character3d/materials.js +106 -10
  77. package/src/character3d/room-themes.js +1184 -0
  78. package/src/character3d/room.js +487 -0
  79. package/src/character3d/stage.js +14 -2
  80. package/src/creator/StepCreator.js +316 -0
  81. package/src/i18n/index.js +3 -3
  82. package/src/i18n/messages/character.js +352 -4
  83. package/src/i18n/messages/creator.js +138 -0
  84. package/src/i18n/messages/identity.js +89 -1
  85. package/src/i18n/messages/platform.js +270 -4
  86. package/src/i18n/messages/server.js +443 -1
  87. package/src/i18n/messages/widget.js +233 -0
  88. package/src/identity/random.js +14 -2
  89. package/src/identity/schema.js +2 -1
  90. package/src/index.js +9 -2
  91. package/src/voice/tags.js +22 -0
  92. package/server/platform/apuchat.mjs +0 -266
  93. package/server/platform/auth.mjs +0 -319
  94. package/server/platform/connect.mjs +0 -387
  95. package/server/platform/crypto.mjs +0 -80
  96. package/server/platform/db.mjs +0 -275
  97. package/server/platform/device.mjs +0 -222
  98. package/server/platform/integrations.mjs +0 -169
  99. package/server/platform/look.mjs +0 -20
  100. package/server/platform/mods.mjs +0 -222
  101. package/server/platform/orquesta.mjs +0 -577
  102. package/server/platform/profile.mjs +0 -161
  103. package/server/platform/routes.mjs +0 -542
  104. package/server/platform/runtime.mjs +0 -242
  105. package/server/platform/sites.mjs +0 -146
  106. package/server/platform/store.mjs +0 -456
  107. package/server/platform/vm.mjs +0 -1057
@@ -12,7 +12,7 @@
12
12
 
13
13
  const path = require('node:path');
14
14
  const { execFile } = require('node:child_process');
15
- const { app, BrowserWindow, Menu, Tray, globalShortcut, nativeImage, screen, session, shell } = require('electron');
15
+ const { app, BrowserWindow, Menu, Tray, globalShortcut, nativeImage, screen, session, shell, systemPreferences } = require('electron');
16
16
 
17
17
  const URL_ = process.env.SEVENOTS_PET_URL;
18
18
  const TOKEN = process.env.SEVENOTS_PET_TOKEN;
@@ -31,9 +31,9 @@ const MIN = { w: 288, h: 272 };
31
31
  const linux = process.platform === 'linux';
32
32
 
33
33
  const L = {
34
- en: { settings: '⚙️ Settings', talk: '💬 Talk', listen: '🎙️ Listen (Ctrl+Alt+Space)', show: 'Show pet', hide: 'Hide (keeps living)', feed: '🍎 Treat', play: '🎾 Play', sleep: '💤 Sleep', wake: '☀️ Wake up', still: 'Stay still', quit: 'Quit pet' },
35
- es: { settings: '⚙️ Configuración', talk: '💬 Hablar', listen: '🎙️ Escúchame (Ctrl+Alt+Espacio)', show: 'Mostrar mascota', hide: 'Ocultar (sigue viva)', feed: '🍎 Mimar', play: '🎾 Jugar', sleep: '💤 Dormir', wake: '☀️ Despertar', still: 'Quedarse quieta', quit: 'Cerrar mascota' },
36
- pt: { settings: '⚙️ Configurações', talk: '💬 Falar', listen: '🎙️ Me escute (Ctrl+Alt+Espaço)', show: 'Mostrar bichinho', hide: 'Esconder (segue vivo)', feed: '🍎 Mimar', play: '🎾 Brincar', sleep: '💤 Dormir', wake: '☀️ Acordar', still: 'Ficar parado', quit: 'Fechar bichinho' },
34
+ en: { settings: '⚙️ Settings', talk: '💬 Talk', listen: '🎙️ Listen (Ctrl+Alt+Space)', show: 'Show pet', hide: 'Hide (keeps living)', feed: '🍎 Treat', play: '🎾 Play', byte: '🎮 Play on byte', watch: '📺 Watch the game', stopGame: '⏹ Stop the game', lastGame: 'Last played', moreGames: 'More games', noGames: 'byte: no games (sign in to 7ots.com)', sleep: '💤 Sleep', wake: '☀️ Wake up', still: 'Stay still', quit: 'Quit pet' },
35
+ es: { settings: '⚙️ Configuración', talk: '💬 Hablar', listen: '🎙️ Escúchame (Ctrl+Alt+Espacio)', show: 'Mostrar mascota', hide: 'Ocultar (sigue viva)', feed: '🍎 Mimar', play: '🎾 Jugar', byte: '🎮 Jugar en byte', watch: '📺 Ver la partida', stopGame: '⏹ Parar la partida', lastGame: 'Último jugado', moreGames: 'Más juegos', noGames: 'byte: sin juegos (entra a 7ots.com)', sleep: '💤 Dormir', wake: '☀️ Despertar', still: 'Quedarse quieta', quit: 'Cerrar mascota' },
36
+ pt: { settings: '⚙️ Configurações', talk: '💬 Falar', listen: '🎙️ Me escute (Ctrl+Alt+Espaço)', show: 'Mostrar bichinho', hide: 'Esconder (segue vivo)', feed: '🍎 Mimar', play: '🎾 Brincar', byte: '🎮 Jogar no byte', watch: '📺 Ver a partida', stopGame: '⏹ Parar a partida', lastGame: 'Último jogado', moreGames: 'Mais jogos', noGames: 'byte: sem jogos (entre no 7ots.com)', sleep: '💤 Dormir', wake: '☀️ Acordar', still: 'Ficar parado', quit: 'Fechar bichinho' },
37
37
  }[LANG] || {};
38
38
  const tr = (k) => L[k] || { listen: 'Listen', show: 'Show pet', hide: 'Hide', talk: 'Talk', settings: 'Settings', feed: 'Feed', play: 'Play', sleep: 'Sleep', wake: 'Wake up', still: 'Stay still', quit: 'Quit pet' }[k];
39
39
 
@@ -47,7 +47,8 @@ if (linux && !OPAQUE) {
47
47
  const post = (p, body) =>
48
48
  fetch(new URL(p, URL_), { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-7ots-Token': TOKEN }, body: JSON.stringify(body || {}) }).catch(() => {});
49
49
 
50
- app.whenReady().then(() => setTimeout(start, linux ? 400 : 0)); // Linux: the compositor needs a moment
50
+ // The packaged desktop app (desktop/launcher.cjs) starts the daemon itself and sets sevenotsReady: wait for it.
51
+ app.whenReady().then(() => globalThis.sevenotsReady).then(() => setTimeout(start, linux ? 400 : 0)); // Linux: the compositor needs a moment
51
52
 
52
53
  // The shell lives as long as the daemon that started it: when that one stops (7ots stop) or another takes
53
54
  // its place (a relaunch), this shell leaves too, so there are never two shells (and two directors) at once.
@@ -59,7 +60,8 @@ app.whenReady().then(() => setTimeout(start, linux ? 400 : 0)); // Linux: the co
59
60
  if (!h?.pid) return ++misses > 4 && app.quit(); // gone for ~25 s
60
61
  misses = 0;
61
62
  pid ||= h.pid;
62
- if (h.pid !== pid) app.quit();
63
+ // The packaged app owns its shell: a daemon that restarted itself (new identity) is adopted, not a reason to leave.
64
+ if (h.pid !== pid) process.env.SEVENOTS_PET_APP ? (pid = h.pid) : app.quit();
63
65
  }, 5000);
64
66
  }
65
67
 
@@ -89,7 +91,7 @@ function watchX11Cursor() {
89
91
  ].join('\n');
90
92
  let child;
91
93
  try {
92
- child = require('node:child_process').spawn('python3', ['-c', py], { stdio: ['ignore', 'pipe', 'ignore'] });
94
+ child = require('node:child_process').spawn('python3', ['-c', py], { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
93
95
  } catch {
94
96
  return;
95
97
  }
@@ -140,6 +142,32 @@ function start() {
140
142
  setTimeout(syncVisitors, 2500);
141
143
  setInterval(syncVisitors, 4000);
142
144
  require('./director.cjs').createDirector({ ots, lang: LANG, url: URL_, token: TOKEN });
145
+ setInterval(syncSenses, 5000);
146
+ setTimeout(syncSenses, 4000);
147
+ }
148
+
149
+ // The ot's eyes (settings → Senses → camera): /senses in a hidden window while the daemon wants the camera.
150
+ // Closing the window is what turns the camera off (its light goes out), so off and paused destroy it.
151
+ let sensesWin = null;
152
+ let askedCamera = false;
153
+ async function syncSenses() {
154
+ const st = await fetch(new URL('/senses/status', URL_), { headers: { 'X-7ots-Token': TOKEN } }).then((r) => (r.ok ? r.json() : null), () => null);
155
+ const want = Boolean(st?.wantCamera);
156
+ if (!want) {
157
+ if (sensesWin && !sensesWin.isDestroyed()) sensesWin.destroy();
158
+ sensesWin = null;
159
+ return;
160
+ }
161
+ if (sensesWin && !sensesWin.isDestroyed()) return;
162
+ if (process.platform === 'darwin' && !askedCamera) {
163
+ askedCamera = true;
164
+ if (systemPreferences.getMediaAccessStatus('camera') !== 'granted' && !(await systemPreferences.askForMediaAccess('camera').catch(() => false))) return;
165
+ }
166
+ sensesWin = new BrowserWindow({ show: false, width: 640, height: 480, skipTaskbar: true, webPreferences: { contextIsolation: true, sandbox: true, backgroundThrottling: false } });
167
+ sensesWin.webContents.on('will-navigate', (e) => e.preventDefault());
168
+ sensesWin.webContents.on('console-message', (e, level, msg) => ['warning', 'error', 2, 3].includes(e?.level ?? level) && console.log(`[7ots senses] ${msg ?? e?.message}`));
169
+ sensesWin.on('closed', () => (sensesWin = null));
170
+ sensesWin.loadURL(`${URL_}/senses?token=${encodeURIComponent(TOKEN)}`).catch(() => {});
143
171
  }
144
172
 
145
173
  // Settings in a window of our own (not a browser tab); links elsewhere open in the browser.
@@ -169,6 +197,8 @@ function makeOt(opt = {}) {
169
197
  const FULL = HOST || !!opt.url;
170
198
  const postOt = (p, body) =>
171
199
  fetch(new URL(p, base), { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-7ots-Token': tok }, body: JSON.stringify(body || {}) }).catch(() => {});
200
+ const getOt = (p) =>
201
+ fetch(new URL(p, base), { headers: { 'X-7ots-Token': tok } }).then((r) => r.json()).catch(() => ({}));
172
202
  const area = screen.getPrimaryDisplay().workArea;
173
203
  const right = area.x + area.width;
174
204
  const floor = area.y + area.height;
@@ -222,6 +252,7 @@ function makeOt(opt = {}) {
222
252
  // Only our own pet page may load (its reload after a settings change or another ot: Electron routes
223
253
  // location.reload() through will-navigate too, so blocking everything froze the old look until a restart).
224
254
  win.webContents.on('will-navigate', (e, url) => String(url || e?.url || '').startsWith(`${base}/pet?`) || e.preventDefault());
255
+ win.webContents.on('did-finish-load', () => ((offTold = ''), alive() && tellOff(win.getBounds()))); // a reload forgets it
225
256
  win.webContents.on('console-message', (e, level, msg) => /\[7ots/.test(msg ?? e?.message) && console.log(msg ?? e?.message)); // to ~/.7ots/electron.log
226
257
  // The microphone, only for our own page (voice control).
227
258
  const ours = (u) => /^http:\/\/127\.0\.0\.1:\d+\//.test(String(u || '')); // our daemons
@@ -232,11 +263,25 @@ function makeOt(opt = {}) {
232
263
 
233
264
  let still = false;
234
265
  let lastBounds = null;
266
+ // How much of the window hangs off the screen it is on (a drag may leave it 40 px past the floor or the
267
+ // right edge, or over the taskbar): the page lifts the hover menu by that much, and moves it to the ot's
268
+ // left when the right side is cut, so the buttons are never off screen (QA BUG-015).
269
+ let offTold = '';
270
+ const tellOff = (b) => {
271
+ const wa = screen.getDisplayNearestPoint({ x: Math.round(b.x + b.width / 2), y: Math.round(b.y + b.height / 2) }).workArea;
272
+ const below = Math.max(0, b.y + b.height - (wa.y + wa.height));
273
+ const pastRight = Math.max(0, b.x + b.width - (wa.x + wa.width));
274
+ const key = `${below},${pastRight}`;
275
+ if (key === offTold) return;
276
+ offTold = key;
277
+ page(`document.documentElement.style.setProperty('--off-below', '${below}px'); document.body.classList.toggle('menu-left', ${pastRight > 0})`);
278
+ };
235
279
  const place = (lift = 0) => {
236
280
  const b = bounds(size, pos, lift);
237
281
  if (lastBounds && b.x === lastBounds.x && b.y === lastBounds.y && b.width === lastBounds.width && b.height === lastBounds.height) return;
238
282
  lastBounds = b;
239
283
  win.setBounds(b);
284
+ tellOff(b);
240
285
  };
241
286
  const show = () => {
242
287
  Object.assign(pos, homeAnchor());
@@ -261,11 +306,140 @@ function makeOt(opt = {}) {
261
306
  { label: tr('feed'), click: () => postOt('/event', { type: 'feed' }) },
262
307
  { label: tr('sleep'), click: () => postOt('/event', { type: 'sleep' }) },
263
308
  { label: tr('wake'), click: () => postOt('/event', { type: 'wake' }) },
309
+ { label: tr('byte'), click: () => gameMenu().then((m) => m.popup({ window: win })) },
264
310
  { type: 'separator' },
265
311
  { label: tr('settings'), click: () => openSettings(base, tok) },
266
312
  { label: tr('still'), type: 'checkbox', checked: still, click: (i) => (still = i.checked) },
267
313
  HOST ? { label: tr('quit'), click: () => post('/quit').finally(() => app.quit()) } : { label: { es: '👋 Despedir', pt: '👋 Mandar embora' }[LANG] || '👋 Send home', click: dismiss },
268
314
  ]);
315
+ // ── byte arena: the ot plays a game live (7ots.com runs its moves) and a small window shows it, beside it ──
316
+ let gameWin = null;
317
+ const watchGame = (url) => {
318
+ if (!/^https:\/\/[^/]+\/stream\/s_[a-z0-9]+$/i.test(String(url || ''))) return;
319
+ if (gameWin && !gameWin.isDestroyed()) return gameWin.loadURL(url), gameWin.showInactive();
320
+ const w = 480;
321
+ const h = 300;
322
+ const [wx, wy] = win.getPosition();
323
+ const x = Math.max(area.x, Math.min(right - w, wx + size.w / 2 - w - 40));
324
+ const y = Math.max(area.y, Math.min(floor - h, wy + size.h - h));
325
+ gameWin = new BrowserWindow({ x, y, width: w, height: h, minWidth: 320, minHeight: 200, alwaysOnTop: true, title: 'byte arena', icon: ICON, autoHideMenuBar: true, backgroundColor: '#0b0b12', show: false, webPreferences: { contextIsolation: true, sandbox: true } });
326
+ gameWin.removeMenu?.();
327
+ gameWin.setAlwaysOnTop(true, 'floating');
328
+ gameWin.webContents.setAudioMuted(false);
329
+ // the page stays on byte's stream; any other link goes to the browser
330
+ const origin = new URL(url).origin;
331
+ gameWin.webContents.setWindowOpenHandler(({ url: u }) => (shell.openExternal(u).catch(() => {}), { action: 'deny' }));
332
+ gameWin.webContents.on('will-navigate', (e, u) => String(u).startsWith(`${origin}/stream/`) || (e.preventDefault(), shell.openExternal(u).catch(() => {})));
333
+ gameWin.loadURL(url);
334
+ gameWin.once('ready-to-show', () => gameWin.showInactive());
335
+ gameWin.on('closed', () => (gameWin = null));
336
+ };
337
+ // what it saw when you asked it to look at you ("¿cómo me ves?"): a small window beside it, like the game's.
338
+ // The frame comes from the pet page (in memory) and is shown from a data: page; nothing is written to disk.
339
+ let photoWin = null;
340
+ const showPhoto = ({ photo }) => {
341
+ if (!/^data:image\/jpeg;base64,[\w+/=]+$/.test(String(photo || ''))) return;
342
+ const title = { es: 'Lo que vi', pt: 'O que eu vi' }[LANG] || 'What I saw';
343
+ const html = `<!doctype html><meta charset="utf-8"><title>${title}</title><style>html,body{margin:0;height:100%;background:#0b0b12;color:#e8e8f0;font:13px/1.4 system-ui,sans-serif}body{display:flex;flex-direction:column}img{flex:1;min-height:0;width:100%;object-fit:contain;background:#000}</style><img src="${photo}" alt="">`;
344
+ const url = `data:text/html;charset=utf-8,${encodeURIComponent(html)}`;
345
+ if (photoWin && !photoWin.isDestroyed()) return photoWin.loadURL(url), photoWin.showInactive();
346
+ const w = 400;
347
+ const h = 330;
348
+ const [wx, wy] = win.getPosition();
349
+ const x = Math.max(area.x, Math.min(right - w, wx + size.w / 2 - w - 40));
350
+ const y = Math.max(area.y, Math.min(floor - h, wy + size.h - h));
351
+ photoWin = new BrowserWindow({ x, y, width: w, height: h, minWidth: 240, minHeight: 200, alwaysOnTop: true, title, icon: ICON, autoHideMenuBar: true, backgroundColor: '#0b0b12', show: false, webPreferences: { contextIsolation: true, sandbox: true, javascript: false } });
352
+ photoWin.removeMenu?.();
353
+ photoWin.setAlwaysOnTop(true, 'floating');
354
+ photoWin.webContents.on('will-navigate', (e) => e.preventDefault());
355
+ photoWin.loadURL(url);
356
+ photoWin.once('ready-to-show', () => photoWin.showInactive());
357
+ photoWin.on('closed', () => (photoWin = null));
358
+ };
359
+ const playGame = async (game) => {
360
+ try {
361
+ require('node:fs').writeFileSync(path.join(process.env.SEVENOTS_HOME || path.join(require('node:os').homedir(), '.7ots'), 'byte-last.json'), JSON.stringify({ slug: game, at: Date.now() }));
362
+ } catch {}
363
+ const r = await fetch(new URL('/byte/play', base), { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-7ots-Token': tok }, body: JSON.stringify({ game }) }).then((x) => x.json()).catch((e) => ({ error: e.message }));
364
+ if (r.streamUrl) {
365
+ watchGame(r.streamUrl);
366
+ postOt('/event', { type: 'say', text: `🎮 ${r.game}` });
367
+ watchStart(r.sessionId);
368
+ } else postOt('/event', { type: 'say', text: `byte: ${r.error || 'no'}` });
369
+ };
370
+ // a game that dies before its first move leaves the stream black: say why and close the window
371
+ const watchStart = (sid, n = 0) =>
372
+ setTimeout(async () => {
373
+ const st = await getOt('/byte/status').catch(() => ({}));
374
+ if (st.sessionId !== sid) return;
375
+ if (st.status === 'error' || ((st.status === 'finished' || st.status === 'stopped') && !st.moves)) {
376
+ postOt('/event', { type: 'say', text: `byte: ${st.error || st.status}` });
377
+ if (gameWin && !gameWin.isDestroyed()) gameWin.close();
378
+ } else if (!st.moves && n < 12) watchStart(sid, n + 1);
379
+ }, 4000);
380
+ // The 🎮 menu: only what the ot can play from here, with byte's covers as thumbnails: the last one it played,
381
+ // 3 at random, and "more games" with the rest. byte's covers are webp (a menu icon takes png/jpg), so the
382
+ // pet's own page decodes each one once into a small png, kept in ~/.7ots/byte-thumbs.
383
+ const fs = require('node:fs');
384
+ const SEVEN = process.env.SEVENOTS_HOME || path.join(require('node:os').homedir(), '.7ots');
385
+ const THUMBS = path.join(SEVEN, 'byte-thumbs');
386
+ const LAST_FILE = path.join(SEVEN, 'byte-last.json');
387
+ const thumbs = new Map(); // slug → nativeImage | null
388
+ const thumbOf = async (g) => {
389
+ if (thumbs.has(g.slug)) return thumbs.get(g.slug);
390
+ const file = path.join(THUMBS, `${String(g.slug).replace(/[^\w-]/g, '_')}.png`);
391
+ let img = null;
392
+ try {
393
+ if (fs.existsSync(file)) img = nativeImage.createFromPath(file);
394
+ else if (/^https:\/\//.test(g.cover || '')) {
395
+ const r = await fetch(g.cover, { signal: AbortSignal.timeout(6000) });
396
+ const type = (r.headers.get('content-type') || 'image/webp').split(';')[0];
397
+ if (r.ok && /^image\//.test(type)) {
398
+ const src = `data:${type};base64,${Buffer.from(await r.arrayBuffer()).toString('base64')}`;
399
+ const png = await win.webContents.executeJavaScript(`(async () => { const i = new Image(); i.src = ${JSON.stringify(src)}; await i.decode();
400
+ const h = 40, w = 30, c = document.createElement('canvas'); c.width = w * 2; c.height = h * 2; const x = c.getContext('2d');
401
+ const s = Math.max(c.width / i.naturalWidth, c.height / i.naturalHeight); x.drawImage(i, (c.width - i.naturalWidth * s) / 2, (c.height - i.naturalHeight * s) / 2, i.naturalWidth * s, i.naturalHeight * s);
402
+ return c.toDataURL('image/png'); })()`, true);
403
+ img = nativeImage.createFromDataURL(png);
404
+ fs.mkdirSync(THUMBS, { recursive: true });
405
+ fs.writeFileSync(file, img.toPNG());
406
+ }
407
+ }
408
+ } catch {}
409
+ img = img && !img.isEmpty() ? img.resize({ width: 30, height: 40, quality: 'best' }) : null;
410
+ thumbs.set(g.slug, img);
411
+ return img;
412
+ };
413
+ const lastPlayed = () => {
414
+ try {
415
+ return JSON.parse(fs.readFileSync(LAST_FILE, 'utf8')).slug || '';
416
+ } catch {
417
+ return '';
418
+ }
419
+ };
420
+ const gameMenu = async () => {
421
+ const [st, g] = await Promise.all([getOt('/byte'), getOt('/byte/games')]);
422
+ if (st.play?.status === 'running') {
423
+ return Menu.buildFromTemplate([
424
+ { label: `${st.play.game} · ${st.play.moves}`, enabled: false },
425
+ { label: tr('watch'), click: () => watchGame(st.play.streamUrl) },
426
+ { label: tr('stopGame'), click: () => postOt('/byte/stop').then(() => gameWin && !gameWin.isDestroyed() && gameWin.close()) },
427
+ ]);
428
+ }
429
+ const games = (g.games || []).filter((x) => x.playable !== false && x.slug);
430
+ if (!games.length) return Menu.buildFromTemplate([{ label: tr('noGames'), enabled: false }]);
431
+ await Promise.all(games.map((x) => thumbOf(x).catch(() => null)));
432
+ const item = (x) => ({ label: x.name || x.slug, ...(thumbs.get(x.slug) ? { icon: thumbs.get(x.slug) } : {}), click: () => playGame(x.slug) });
433
+ const last = games.find((x) => x.slug === lastPlayed());
434
+ const rest = games.filter((x) => x !== last);
435
+ const pick = [...rest].sort(() => Math.random() - 0.5).slice(0, 3);
436
+ const more = rest.filter((x) => !pick.includes(x));
437
+ return Menu.buildFromTemplate([
438
+ ...(last ? [{ label: tr('lastGame'), enabled: false }, item(last), { type: 'separator' }] : []),
439
+ ...pick.map(item),
440
+ ...(more.length ? [{ type: 'separator' }, { label: tr('moreGames'), submenu: more.map(item) }] : []),
441
+ ]);
442
+ };
269
443
  function listen() {
270
444
  if (!win.isVisible()) win.showInactive();
271
445
  page('postMessage({ listen: true })');
@@ -458,6 +632,14 @@ function makeOt(opt = {}) {
458
632
  }
459
633
  if (m.startsWith('\u00a77bye')) return HOST || dismiss();
460
634
  if (m.startsWith('\u00a77ctx')) return (FULL ? menu() : guestMenu()).popup({ window: win });
635
+ if (m.startsWith('\u00a77game')) return FULL && gameMenu().then((mm) => mm.popup({ window: win }));
636
+ if (m.startsWith('\u00a77photo')) {
637
+ try {
638
+ return showPhoto(JSON.parse(m.slice(7)));
639
+ } catch {
640
+ return;
641
+ }
642
+ }
461
643
  if (m.startsWith('\u00a77view')) return setView(m.slice(6) === '3d');
462
644
  if (m.startsWith('\u00a77enter')) return enter();
463
645
  if (!m.startsWith('\u00a77need')) return;
@@ -594,7 +776,7 @@ function makeOt(opt = {}) {
594
776
  const minY = area.y + BIG.h;
595
777
  const TERM = /terminal|kitty|alacritty|konsole|tilix|wezterm|xterm|ghostty|warp|terminator|code|cursor|windsurf|zed|jetbrains|idea|pycharm|webstorm/i;
596
778
  const BROWSER = /chrom|firefox|brave|vivaldi|opera|edge|epiphany|librewolf|zen/i;
597
- const run = (cmd, args) => new Promise((res) => execFile(cmd, args, { timeout: 1500 }, (e, out) => res(e ? '' : String(out))));
779
+ const run = (cmd, args) => new Promise((res) => execFile(cmd, args, { timeout: 1500, windowsHide: true }, (e, out) => res(e ? '' : String(out))));
598
780
  // The top-most visible window whose class matches, if it is not mostly covered by others (no use pointing
599
781
  // at a terminal hidden behind the browser: then it comes to the cursor instead).
600
782
  async function findWindow(re) {