@7ots/cli 0.1.10 → 0.1.12

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/cli/7ots.mjs CHANGED
@@ -43,7 +43,7 @@ function parse(argv) {
43
43
  }
44
44
  return { pos, flags };
45
45
  }
46
- const VALUED = new Set(['seed', 'name', 'lang', 'target', 'mode', 'type', 'code', 'cmd', 'tool', 'from', 'port', 'text', 'minutes', 'cancel', 'server']);
46
+ const VALUED = new Set(['seed', 'name', 'lang', 'target', 'mode', 'type', 'code', 'cmd', 'tool', 'from', 'port', 'text', 'minutes', 'cancel', 'server', 'ms', 'dance']);
47
47
 
48
48
  const fail = (msg, code = 1) => {
49
49
  console.error(msg);
@@ -363,6 +363,15 @@ async function cmdCare(cmd, { pos, flags }) {
363
363
  await cmdStatus();
364
364
  }
365
365
 
366
+ async function cmdDance(cmd, { pos, flags }) {
367
+ const { DANCES } = await import('../src/character/motion.js');
368
+ if (flags.list) return console.log(DANCES.join(' '));
369
+ const name = (cmd === 'dance' ? pos[0] : flags.dance) || undefined;
370
+ const body = { name, ms: flags.ms ? Number(flags.ms) : undefined };
371
+ if (flags['no-music'] || flags.music === false) body.music = false;
372
+ if (!(await postPet('/' + cmd, body))) console.log(dim(t('pet.notRunning')));
373
+ }
374
+
366
375
  async function cmdStatus({ flags = {} } = {}) {
367
376
  const { identity } = loadIdentity();
368
377
  let state;
@@ -529,6 +538,9 @@ async function main() {
529
538
  case 'ask':
530
539
  case 'tell':
531
540
  return cmdAsk(args);
541
+ case 'dance':
542
+ case 'entrance':
543
+ return cmdDance(cmd, args);
532
544
  case 'reminders':
533
545
  return cmdReminders(args);
534
546
  case 'config':
@@ -48,7 +48,7 @@ export const CONFIG_DEFAULTS = Object.freeze({
48
48
  home: { kind: 'local' },
49
49
  brain: { kind: 'lines' },
50
50
  voice: { kind: 'browser' },
51
- pet: { mode: 'ask', annoy: 2 },
51
+ pet: { mode: 'ask', annoy: 2, music: 'synth', musicVol: 0.5, entrance: { onStart: false, kind: 'wwe', dance: '' } },
52
52
  access: { agent: true, memory: true, open: true, notify: true, sites: true, screen: false, processes: false, logs: false, inbox: false, vm: false, vmKinds: ['research', 'browse', 'long'] },
53
53
  screen: { every: 5 },
54
54
  // conversation memory: recent turns up to `tokens` (≈chars/4), older ones compacted into a summary; 0 = off
package/cli/lib/i18n.mjs CHANGED
@@ -15,6 +15,7 @@ const M = {
15
15
  7ots pet [--mode desktop|terminal|browser|auto] [--detach] [--opaque] wake up your virtual pet
16
16
  7ots pet --tmux the terminal pet in a tmux side pane
17
17
  7ots feed | play | sleep | wake | say <text> | stop
18
+ 7ots dance [name] [--ms N] [--no-music] [--list] | entrance [--dance name]
18
19
  7ots status [--line|--json] pet state (--line: one line for tmux)
19
20
  7ots ask <text> talk to it: "remind me to check email in 10 min", "open my calendar", "remember that…"
20
21
  7ots reminders [--cancel <id>] pending reminders and what it remembers
@@ -205,6 +206,7 @@ Docs: https://7ots.com/llms.txt`,
205
206
  7ots pet [--mode desktop|terminal|browser|auto] [--detach] [--opaque] despierta tu mascota virtual
206
207
  7ots pet --tmux la mascota de terminal en un panel de tmux
207
208
  7ots feed | play | sleep | wake | say <texto> | stop
209
+ 7ots dance [nombre] [--ms N] [--no-music] [--list] | entrance [--dance nombre]
208
210
  7ots status [--line|--json] estado (--line: una línea para tmux)
209
211
  7ots ask <texto> háblale: "recuérdame ver el correo en 10 min", "abre mi calendario", "anota que…"
210
212
  7ots reminders [--cancel <id>] recordatorios pendientes y lo que recuerda
@@ -395,6 +397,7 @@ Docs: https://7ots.com/llms.txt`,
395
397
  7ots pet [--mode desktop|terminal|browser|auto] [--detach] [--opaque] acorda seu bichinho virtual
396
398
  7ots pet --tmux o bichinho de terminal num painel do tmux
397
399
  7ots feed | play | sleep | wake | say <texto> | stop
400
+ 7ots dance [nombre] [--ms N] [--no-music] [--list] | entrance [--dance nombre]
398
401
  7ots status [--line|--json] estado (--line: uma linha para tmux)
399
402
  7ots ask <texto> fale com ele: "me lembre de ver o e-mail em 10 min", "abra minha agenda", "anote que…"
400
403
  7ots reminders [--cancel <id>] lembretes pendentes e o que ele lembra
@@ -28,6 +28,9 @@
28
28
  * POST /notes/forget { at | 'all' }
29
29
  * POST /conversation/forget drop the conversation memory (turns + summary)
30
30
  * POST /quit X-7ots-Token
31
+ * POST /dance X-7ots-Token { name?, ms?, music? } → dances (DANCES in motion.js) with music (beat.js or ~/.7ots/music)
32
+ * POST /entrance X-7ots-Token { dance? } → a wrestling-style entrance: walks in, spotlights, pyro, its name, a dance
33
+ * GET /music?token=… { files } your own tracks in ~/.7ots/music · GET /music/<file>?token=… plays one
31
34
  *
32
35
  * Only listens on 127.0.0.1 and only answers to Host 127.0.0.1/localhost (no DNS rebinding).
33
36
  * The token lives in ~/.7ots/pet.token (0600): other users of the machine can't drive the pet.
@@ -35,7 +38,7 @@
35
38
 
36
39
  import { createServer } from 'node:http';
37
40
  import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
38
- import { readFileSync, existsSync, writeFileSync, chmodSync, mkdirSync, symlinkSync } from 'node:fs';
41
+ import { readFileSync, existsSync, writeFileSync, chmodSync, mkdirSync, symlinkSync, readdirSync, statSync, createReadStream } from 'node:fs';
39
42
  import { cardShot } from './card-shot.mjs';
40
43
  import { join } from 'node:path';
41
44
  import { createAssistant, notify, tr } from './assistant.mjs';
@@ -44,7 +47,7 @@ import { createInferenceLog, otherInferences } from './inferences.mjs';
44
47
 
45
48
  const MAX_INF = 300;
46
49
  import { AI_CLIS, createBrain, detectClis, petSystem } from './brain.mjs';
47
- import { env, loadConfig, saveConfig, saveKey } from './config.mjs';
50
+ import { CONFIG_DEFAULTS, env, loadConfig, saveConfig, saveKey } from './config.mjs';
48
51
  import { loadIdentity } from './identity.mjs';
49
52
  import { readJson, writeJson } from './paths.mjs';
50
53
  import { sttProvider, transcribe } from './stt.mjs';
@@ -61,11 +64,24 @@ import { line } from './lines.mjs';
61
64
  import { defineIdentity, GROK_VOICES, OPENAI_VOICES } from '../../src/identity/schema.js';
62
65
  import { normalizeMod, normalizeMods, MAX_MODS } from '../../src/character/mods.js';
63
66
  import { MOD_CATALOG } from '../../src/character/mods/index.js';
67
+ import { DANCES } from '../../src/character/motion.js';
64
68
 
65
69
  /** Mods importados en este pet (~/.7ots/mods/library.json), normalizados. */
66
70
  // scenes between ots on the same desktop (pet/electron/director.cjs plays them)
67
71
  const SCENE_NAMES = ['rocky', 'sf', 'dbz', 'matrix', 'duel', 'sw', 'fight', 'twist'];
68
72
  const SCENE_EVERY = ['rare', 'normal', 'often'];
73
+ // dances and their music (pet.html plays them; music: synthesized, your own files in ~/.7ots/music, or none)
74
+ const MUSIC_MODES = ['synth', 'files', 'off'];
75
+ const ENTRANCE_KINDS = ['wwe', 'rock', 'magic'];
76
+ const MUSIC_TYPES = { mp3: 'audio/mpeg', ogg: 'audio/ogg', oga: 'audio/ogg', opus: 'audio/ogg', wav: 'audio/wav', m4a: 'audio/mp4', aac: 'audio/aac', flac: 'audio/flac', webm: 'audio/webm' };
77
+ const MUSIC_FILE = /^[^/\\\0]{1,160}\.(mp3|ogg|oga|opus|wav|m4a|aac|flac|webm)$/i;
78
+ function musicFiles() {
79
+ try {
80
+ return readdirSync(homeFile('music')).filter((f) => MUSIC_FILE.test(f) && !f.startsWith('.') && statSync(homeFile(`music/${f}`)).isFile()).sort();
81
+ } catch {
82
+ return [];
83
+ }
84
+ }
69
85
  const modLibrary = () => (readJson(homeFile('mods/library.json')) || []).map(normalizeMod).filter(Boolean);
70
86
  import { ensureHome, homeFile, PET_PORT, PKG_ROOT } from './paths.mjs';
71
87
  import { applyEvent, loadPet, need, savePet, tick, view } from './pet-core.mjs';
@@ -123,6 +139,17 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
123
139
  let config = loadConfig();
124
140
  let scenePlay = null; // { scene, at }: asked from settings, taken by the director on its next poll
125
141
  const sceneConf = (c = config) => ({ on: true, every: 'normal', list: SCENE_NAMES, ...c.pet?.scenes });
142
+ // a dance to play: its name (or one at random), how long and the music under it, per the pet's music setting
143
+ const musicFor = (d = {}) => {
144
+ const name = DANCES.includes(d.name) ? d.name : DANCES[Math.floor(Math.random() * DANCES.length)];
145
+ const ms = Math.max(1500, Math.min(60000, Number(d.ms) || 8000));
146
+ const mode = d.music === false ? 'off' : config.pet.music || 'synth';
147
+ const vol = Math.max(0, Math.min(1, Number(config.pet.musicVol ?? 0.5)));
148
+ const files = mode === 'files' ? musicFiles() : [];
149
+ const file = typeof d.file === 'string' && files.includes(d.file) ? d.file : files[Math.floor(Math.random() * files.length)];
150
+ const music = mode === 'off' ? null : file ? { file, vol } : { style: typeof d.style === 'string' ? d.style : '', vol };
151
+ return { name, ms, music };
152
+ };
126
153
  const annoyOf = (c) => Math.max(0, Math.min(3, Number(c.pet.annoy ?? 2)));
127
154
  let annoy = annoyOf(config);
128
155
  const { identity } = loadIdentity();
@@ -429,7 +456,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
429
456
 
430
457
  const page = (file = 'pet.html', extra = {}) =>
431
458
  readFileSync(join(PKG_ROOT, 'cli', 'pet', file), 'utf8')
432
- .replace('__BOOT__', JSON.stringify({ token, pid: process.pid, companion: !!process.env.SEVENOTS_COMPANION, identity, otsId: config.account?.otsId || '', voice: config.voice, lang, annoy, brain: brainLabel(config.brain), activity, stt: sttProvider(env()), ...extra }).replace(/</g, '\\u003c'));
459
+ .replace('__BOOT__', JSON.stringify({ token, pid: process.pid, companion: !!process.env.SEVENOTS_COMPANION, identity, otsId: config.account?.otsId || '', voice: config.voice, lang, annoy, brain: brainLabel(config.brain), activity, stt: sttProvider(env()), backdrop: config.pet.backdrop !== false, ...extra }).replace(/</g, '\\u003c'));
433
460
 
434
461
  // Visitors: other ots of the account invited onto this desktop (their look, saved so they come offline too).
435
462
  // The desktop shell opens a window for each and stages scenes between them (see electron/director.cjs).
@@ -482,6 +509,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
482
509
  } catch {}
483
510
  return fetch(`${c.url}/quit`, { method: 'POST', headers: { 'X-7ots-Token': t, 'Content-Type': 'application/json' }, body: '{}' }).catch(() => {});
484
511
  };
512
+ let entranceDone = false;
485
513
  const fullOnes = () => visitors().filter((v) => v.full);
486
514
  if (!process.env.SEVENOTS_COMPANION) fullOnes().forEach((v) => startCompanion(v).catch((e) => log(`companion: ${e.message}`)));
487
515
 
@@ -557,6 +585,18 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
557
585
  scenePlay = null;
558
586
  return json(200, { ...sceneConf(), play });
559
587
  }
588
+ if (req.method === 'GET' && p === '/music') return json(200, { files: musicFiles(), dir: homeFile('music') });
589
+ if (req.method === 'GET' && p.startsWith('/music/')) {
590
+ let name = '';
591
+ try {
592
+ name = decodeURIComponent(p.slice(7));
593
+ } catch {}
594
+ if (!musicFiles().includes(name)) return res.writeHead(404).end();
595
+ const f = homeFile(`music/${name}`);
596
+ const type = MUSIC_TYPES[name.split('.').pop().toLowerCase()];
597
+ res.writeHead(200, { 'Content-Type': type, 'Content-Length': statSync(f).size, 'Cache-Control': 'no-cache' });
598
+ return createReadStream(f).pipe(res);
599
+ }
560
600
  if (req.method === 'GET' && p === '/inferences') {
561
601
  // this ot's calls plus those of the ots visiting this desktop (the host sees all), each tagged with its ot
562
602
  const n = Number(url.searchParams.get('n')) || 100;
@@ -927,6 +967,21 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
927
967
  return json(e.status === 400 ? 400 : 502, { error: e.message });
928
968
  }
929
969
  }
970
+ if (p === '/dance' || p === '/entrance') {
971
+ const dance = musicFor(data);
972
+ if (p === '/dance') broadcast({ dance });
973
+ else {
974
+ // { start: true } = the page just opened: only once per run, and only if the owner wants it
975
+ const ec = { ...CONFIG_DEFAULTS.pet.entrance, ...config.pet.entrance };
976
+ if (data.start && (entranceDone || !ec.onStart)) return json(200, { ok: false });
977
+ entranceDone = true;
978
+ const want = ENTRANCE_KINDS.includes(data.kind) ? data.kind : ENTRANCE_KINDS.includes(ec.kind) ? ec.kind : ENTRANCE_KINDS[Math.floor(Math.random() * ENTRANCE_KINDS.length)];
979
+ const dn = DANCES.includes(data.name) ? data.name : DANCES.includes(ec.dance) ? ec.dance : '';
980
+ broadcast({ entrance: { ...dance, dance: dn, kind: want, name: identity.name || 'ot' } });
981
+ }
982
+ log(`${p.slice(1)}: ${dance.name}${dance.music ? ` ♪ ${dance.music.file || dance.music.style}` : ''}`);
983
+ return json(200, { ok: true, dance: dance.name, music: dance.music });
984
+ }
930
985
  if (p === '/scenes/play') {
931
986
  scenePlay = { scene: SCENE_NAMES.includes(data.scene) ? data.scene : '', at: Date.now() };
932
987
  return json(200, { ok: true });
@@ -957,6 +1012,8 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
957
1012
  otLook: identity.look?.character || null,
958
1013
  // the catalog without its 3D models (the page only draws the 2D previews)
959
1014
  modLibrary: modLibrary(),
1015
+ musicFiles: musicFiles(),
1016
+ dances: DANCES,
960
1017
  modCatalog: MOD_CATALOG.map((m) => normalizeMod(m)).map((m) => ({ ...m, parts: m.parts.map((x) => ({ ...x, glb: x.glb ? '3d' : '' })) })),
961
1018
  integrations: config.integrations,
962
1019
  character: config.character,
@@ -995,9 +1052,20 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
995
1052
  } else return 'kind';
996
1053
  }
997
1054
  const viewWas = next.pet.view || '2d';
1055
+ const bdWas = next.pet.backdrop !== false;
998
1056
  if (d.pet) {
999
1057
  if (d.pet.annoy !== undefined) next.pet.annoy = Math.max(0, Math.min(3, Math.round(Number(d.pet.annoy)) || 0));
1000
1058
  if (['2d', '3d'].includes(d.pet.view)) next.pet.view = d.pet.view;
1059
+ if (d.pet.backdrop !== undefined) next.pet.backdrop = !!d.pet.backdrop;
1060
+ if (MUSIC_MODES.includes(d.pet.music)) next.pet.music = d.pet.music;
1061
+ if (d.pet.entrance && typeof d.pet.entrance === 'object') {
1062
+ const e = { ...CONFIG_DEFAULTS.pet.entrance, ...next.pet.entrance };
1063
+ if (d.pet.entrance.onStart !== undefined) e.onStart = !!d.pet.entrance.onStart;
1064
+ if ([...ENTRANCE_KINDS, 'random'].includes(d.pet.entrance.kind)) e.kind = d.pet.entrance.kind;
1065
+ if (d.pet.entrance.dance === '' || DANCES.includes(d.pet.entrance.dance)) e.dance = d.pet.entrance.dance;
1066
+ next.pet.entrance = e;
1067
+ }
1068
+ if (d.pet.musicVol !== undefined) next.pet.musicVol = Math.max(0, Math.min(1, Math.round(Number(d.pet.musicVol) * 100) / 100 || 0));
1001
1069
  if (d.pet.scenes) {
1002
1070
  const c = { ...sceneConf(next), ...d.pet.scenes };
1003
1071
  next.pet.scenes = {
@@ -1056,6 +1124,7 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
1056
1124
  if (config.voice.kind === 'local') warmLocal();
1057
1125
  if (reload) setTimeout(() => broadcast({ reload: true }), 100); // the page reads its voice at load
1058
1126
  // 2D ↔ 3D: open pet windows switch now (the page, or the desktop shell when it needs the GPU back on).
1127
+ if ((config.pet.backdrop !== false) !== bdWas) setTimeout(() => broadcast({ backdrop: config.pet.backdrop !== false }), 100);
1059
1128
  else if ((config.pet.view || '2d') !== viewWas) (viewSet = config.pet.view), setTimeout(() => broadcast({ view: viewSet }), 100);
1060
1129
  log(`settings: brain ${brainLabel(config.brain)}`);
1061
1130
  return null;
@@ -459,6 +459,7 @@ function makeOt(opt = {}) {
459
459
  if (m.startsWith('\u00a77bye')) return HOST || dismiss();
460
460
  if (m.startsWith('\u00a77ctx')) return (FULL ? menu() : guestMenu()).popup({ window: win });
461
461
  if (m.startsWith('\u00a77view')) return setView(m.slice(6) === '3d');
462
+ if (m.startsWith('\u00a77enter')) return enter();
462
463
  if (!m.startsWith('\u00a77need')) return;
463
464
  try {
464
465
  need = JSON.parse(m.slice(6));
@@ -575,6 +576,20 @@ function makeOt(opt = {}) {
575
576
  place(Math.round(lift));
576
577
  }, 16);
577
578
 
579
+ // ── Entrance (pet.html entrance()): it reappears ~500 px toward the middle of the screen and walks back
580
+ // to where it was, like down the ramp to the ring. Not mid-scene, not pinned or asleep. ──
581
+ let enterUntil = 0;
582
+ function enter() {
583
+ if (plan.mode === 'scene' || plan.mode === 'fling' || still || asleep || Date.now() - dragged < 2000) return;
584
+ enterUntil = Date.now() + 12000;
585
+ const to = { ...pos };
586
+ const mid = area.x + area.width / 2;
587
+ pos.x = Math.max(minX, Math.min(maxX, to.x + (to.x > mid ? -1 : 1) * 520));
588
+ vel.x = vel.y = 0;
589
+ place();
590
+ plan = { mode: 'go', tx: to.x, ty: to.y, speed: 115 };
591
+ }
592
+
578
593
  // ── Errands: walk to what needs you and point at it ──
579
594
  const minY = area.y + BIG.h;
580
595
  const TERM = /terminal|kitty|alacritty|konsole|tilix|wezterm|xterm|ghostty|warp|terminator|code|cursor|windsurf|zed|jetbrains|idea|pycharm|webstorm/i;
@@ -664,7 +679,7 @@ function makeOt(opt = {}) {
664
679
  daemon: { url: base, token: opt.token || TOKEN }, // its own daemon (settings there can ask for a scene)
665
680
  // for a scene asked from settings: errands (pointing at the terminal while an agent works) may be cut short
666
681
  ready: () => alive() && win.isVisible() && !win.webContents.isLoading() && !asleep && Date.now() - dragged > 3000 && Date.now() > hoverUntil + 1500 && plan.mode !== 'scene' && plan.mode !== 'fling',
667
- free: () => alive() && win.isVisible() && !win.webContents.isLoading() && !still && !asleep && Date.now() - dragged > 8000 && Date.now() > hoverUntil + 1500 && !busy && /idle|go|hop/.test(plan.mode),
682
+ free: () => alive() && win.isVisible() && !win.webContents.isLoading() && !still && !asleep && Date.now() > enterUntil && Date.now() - dragged > 8000 && Date.now() > hoverUntil + 1500 && !busy && /idle|go|hop/.test(plan.mode),
668
683
  walkTo: (x, y = pos.y, speed = 120) => (plan = { mode: 'scene', tx: Math.max(minX, Math.min(maxX, x)), ty: Math.max(minY, Math.min(floor, y)), speed, dir: plan.dir || 0 }),
669
684
  arrivedAt: () => plan.mode === 'scene' && Math.abs(plan.tx - pos.x) < 6 && Math.abs(plan.ty - pos.y) < 6 && Math.hypot(vel.x, vel.y) < 10,
670
685
  face: (dir) => {
package/cli/pet/pet.html CHANGED
@@ -140,6 +140,13 @@
140
140
  .props .ring { top: 34%; width: 18px; height: 18px; margin: -9px; border-radius: 50%; border: 2px solid rgb(180 220 255 / .8); }
141
141
  .props .saber { left: 50%; top: 50%; width: 6px; height: 92px; margin-left: -3px; transform-origin: 50% 100%; border-radius: 4px; background: #fff; }
142
142
  .props .flash { top: 44%; width: 30px; height: 30px; margin: -15px; border-radius: 50%; background: radial-gradient(#fff, #ffd35a 40%, #ff7a1a 60%, transparent 70%); }
143
+ /* entrances (wrestling style): spotlights from above, pyro columns, the name slammed in */
144
+ .props .spot { left: 50%; bottom: 0; width: 120px; height: 140%; margin-left: -60px; transform-origin: 50% 0; top: -40%; background: linear-gradient(180deg, rgb(255 250 220 / .0), rgb(255 250 220 / .32) 70%, rgb(255 250 220 / .0)); clip-path: polygon(44% 0, 56% 0, 100% 100%, 0 100%); filter: blur(2px); mix-blend-mode: screen; }
145
+ .props .spot.rock { animation: rockhue 1s linear infinite; }
146
+ @keyframes rockhue { from { filter: blur(2px) hue-rotate(0deg) saturate(4); } to { filter: blur(2px) hue-rotate(360deg) saturate(4); } }
147
+ .props .smoke { bottom: 4%; width: 110px; height: 80px; margin-left: -55px; border-radius: 50%; background: radial-gradient(closest-side, rgb(235 230 255 / .9), rgb(190 170 255 / .5) 60%, transparent); filter: blur(6px); }
148
+ .props .pyro { bottom: 6%; width: 16px; height: 120px; margin-left: -8px; transform-origin: 50% 100%; border-radius: 8px 8px 4px 4px; background: linear-gradient(0deg, #fff6c0, #ffb627 30%, #ff5a1f 65%, transparent); filter: blur(1px) drop-shadow(0 0 10px #ff8a1f); }
149
+ .props .title { left: 50%; top: 4%; transform: translateX(-50%); font: 900 30px/1 Impact, 'Anton', system-ui, sans-serif; letter-spacing: 2px; text-transform: uppercase; white-space: nowrap; color: #fff; background: linear-gradient(180deg, #fff 30%, #ffd84a 55%, #ff8a1f); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; -webkit-text-stroke: 1.5px #2a0f00; filter: drop-shadow(0 3px 0 #1a0a00) drop-shadow(0 0 12px rgb(255 160 40 / .7)); }
143
150
  .props .pow { left: 50%; top: 6%; font: 900 22px/1 system-ui, sans-serif; color: #ffd400; -webkit-text-stroke: 2px #1a1020; transform: translateX(-50%); white-space: nowrap; }
144
151
  /* a visiting ot: its own little menu (play, say goodbye, settings, move); feeding, talking and sleep are the host's */
145
152
  body.guest .ask, body.guest #talkBtn, body.guest #micBtn, body.guest #sleepBtn { display: none !important; }
@@ -206,6 +213,7 @@
206
213
  <button class="act" id="talkBtn" type="button"><svg viewBox="0 0 24 24"><path d="M5 6h14v9H9l-4 3z"/></svg><span data-t="talk"></span></button>
207
214
  <button class="act" id="micBtn" type="button"><svg viewBox="0 0 24 24"><rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5.5 11a6.5 6.5 0 0 0 13 0M12 17.5V21"/></svg><span data-t="listen"></span></button>
208
215
  <button class="act" data-act="sleep" id="sleepBtn"><svg viewBox="0 0 24 24"><path d="M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z"/></svg><span data-t="sleep"></span></button>
216
+ <button class="act" id="danceBtn" type="button"><svg viewBox="0 0 24 24"><path d="M9 18V6l10-2v12"/><circle cx="7" cy="18" r="2"/><circle cx="17" cy="16" r="2"/></svg><span data-t="dance"></span></button>
209
217
  <a class="act" id="setBtn" target="_blank" rel="noopener"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3M5.3 5.3l2.1 2.1M16.6 16.6l2.1 2.1M5.3 18.7l2.1-2.1M16.6 7.4l2.1-2.1"/></svg><span data-t="settings"></span></a>
210
218
  <button class="act bye" id="byeBtn" type="button"><svg viewBox="0 0 24 24"><path d="M15 4h4v16h-4M10 8l-4 4 4 4M6 12h10"/></svg></button>
211
219
  <button class="act grip" id="moveBtn" type="button" title="⇔"><svg viewBox="0 0 24 24"><path d="M12 3v18M3 12h18M12 3l-3 3M12 3l3 3M12 21l-3-3M12 21l3-3M3 12l3-3M3 12l3 3M21 12l-3-3M21 12l-3 3"/></svg></button>
@@ -222,17 +230,17 @@
222
230
  <script type="module">
223
231
  const BOOT = __BOOT__;
224
232
  const T = {
225
- en: { settings: 'Settings', dismiss: 'Send home', listen: 'Listen', listening: 'Listening… 🎙️', noStt: 'Voice control needs an OpenAI or ElevenLabs key (Settings).', noMic: 'I can’t reach the microphone.', sttErr: 'I didn’t catch that.', talk: 'Talk', askPh: 'Remind me to check email in 10 min…', feed: 'Treat', play: 'Play', sleep: 'Sleep', wake: 'Wake', food: 'Food', energy: 'Energy', fun: 'Fun', level: 'Level {l}', xp: '{x} / {n} xp', live: 'Live', off: 'Reconnecting…', approve: 'Approve', reject: 'Reject',
233
+ en: { dance: 'Dance', settings: 'Settings', dismiss: 'Send home', listen: 'Listen', listening: 'Listening… 🎙️', noStt: 'Voice control needs an OpenAI or ElevenLabs key (Settings).', noMic: 'I can’t reach the microphone.', sttErr: 'I didn’t catch that.', talk: 'Talk', askPh: 'Remind me to check email in 10 min…', feed: 'Treat', play: 'Play', sleep: 'Sleep', wake: 'Wake', food: 'Food', energy: 'Energy', fun: 'Fun', level: 'Level {l}', xp: '{x} / {n} xp', live: 'Live', off: 'Reconnecting…', approve: 'Approve', reject: 'Reject',
226
234
  activity: 'Activity', empty: 'Nothing yet. Run a command or ask your coding agent something.', tally: '{ok} ok · {fail} failed · turns {turns}',
227
235
  brain: 'Brain: {b}', age: 'Born {d}', lines: 'built-in phrases', now: 'now', m: '{n}m', h: '{n}h',
228
236
  moods: { happy: 'Happy', neutral: 'Calm', sad: 'Sad', disgust: 'Bored', sleep: 'Asleep', thinking: 'Thinking' },
229
237
  kind: { tool: 'Tool', shell: 'Shell', prompt: 'You asked', stop: 'Turn finished', notify: 'Needs you', start: 'Session started' } },
230
- es: { settings: 'Ajustes', dismiss: 'Despedir', listen: 'Escuchar', listening: 'Te escucho… 🎙️', noStt: 'Para hablarme por voz falta una key de OpenAI o ElevenLabs (Ajustes).', noMic: 'No puedo usar el micrófono.', sttErr: 'No te entendí.', talk: 'Hablar', askPh: 'Recuérdame ver el correo en 10 min…', feed: 'Mimar', play: 'Jugar', sleep: 'Dormir', wake: 'Despertar', food: 'Comida', energy: 'Energía', fun: 'Diversión', level: 'Nivel {l}', xp: '{x} / {n} xp', live: 'En vivo', off: 'Reconectando…', approve: 'Aprobar', reject: 'Rechazar',
238
+ es: { dance: 'Bailar', settings: 'Ajustes', dismiss: 'Despedir', listen: 'Escuchar', listening: 'Te escucho… 🎙️', noStt: 'Para hablarme por voz falta una key de OpenAI o ElevenLabs (Ajustes).', noMic: 'No puedo usar el micrófono.', sttErr: 'No te entendí.', talk: 'Hablar', askPh: 'Recuérdame ver el correo en 10 min…', feed: 'Mimar', play: 'Jugar', sleep: 'Dormir', wake: 'Despertar', food: 'Comida', energy: 'Energía', fun: 'Diversión', level: 'Nivel {l}', xp: '{x} / {n} xp', live: 'En vivo', off: 'Reconectando…', approve: 'Aprobar', reject: 'Rechazar',
231
239
  activity: 'Actividad', empty: 'Nada todavía. Ejecuta un comando o pregúntale algo a tu agente.', tally: '{ok} ok · {fail} fallos · turnos {turns}',
232
240
  brain: 'Cerebro: {b}', age: 'Nació {d}', lines: 'frases propias', now: 'ahora', m: '{n} min', h: '{n} h',
233
241
  moods: { happy: 'Feliz', neutral: 'Tranquilo', sad: 'Triste', disgust: 'Aburrido', sleep: 'Dormido', thinking: 'Pensando' },
234
242
  kind: { tool: 'Herramienta', shell: 'Terminal', prompt: 'Preguntaste', stop: 'Turno terminado', notify: 'Te necesita', start: 'Sesión iniciada' } },
235
- pt: { settings: 'Ajustes', dismiss: 'Despedir', listen: 'Ouvir', listening: 'Estou ouvindo… 🎙️', noStt: 'Para falar por voz falta uma key da OpenAI ou ElevenLabs (Ajustes).', noMic: 'Não consigo usar o microfone.', sttErr: 'Não entendi.', talk: 'Falar', askPh: 'Me lembre de ver o e-mail em 10 min…', feed: 'Mimar', play: 'Brincar', sleep: 'Dormir', wake: 'Acordar', food: 'Comida', energy: 'Energia', fun: 'Diversão', level: 'Nível {l}', xp: '{x} / {n} xp', live: 'Ao vivo', off: 'Reconectando…', approve: 'Aprovar', reject: 'Recusar',
243
+ pt: { dance: 'Dançar', settings: 'Ajustes', dismiss: 'Despedir', listen: 'Ouvir', listening: 'Estou ouvindo… 🎙️', noStt: 'Para falar por voz falta uma key da OpenAI ou ElevenLabs (Ajustes).', noMic: 'Não consigo usar o microfone.', sttErr: 'Não entendi.', talk: 'Falar', askPh: 'Me lembre de ver o e-mail em 10 min…', feed: 'Mimar', play: 'Brincar', sleep: 'Dormir', wake: 'Acordar', food: 'Comida', energy: 'Energia', fun: 'Diversão', level: 'Nível {l}', xp: '{x} / {n} xp', live: 'Ao vivo', off: 'Reconectando…', approve: 'Aprovar', reject: 'Recusar',
236
244
  activity: 'Atividade', empty: 'Nada ainda. Rode um comando ou pergunte algo ao seu agente.', tally: '{ok} ok · {fail} falhas · turnos {turns}',
237
245
  brain: 'Cérebro: {b}', age: 'Nasceu {d}', lines: 'frases próprias', now: 'agora', m: '{n} min', h: '{n} h',
238
246
  moods: { happy: 'Feliz', neutral: 'Tranquilo', sad: 'Triste', disgust: 'Entediado', sleep: 'Dormindo', thinking: 'Pensando' },
@@ -265,21 +273,21 @@
265
273
  $('#brain').innerHTML = '';
266
274
  $('#brain').append(t('brain', { b: '' }), Object.assign(document.createElement('b'), { textContent: BOOT.brain === 'lines' ? t('lines') : BOOT.brain }));
267
275
 
268
- const { createCharacter, loadCharacter3D } = await import('/dist/7ots.esm.js');
276
+ const { createCharacter, loadCharacter3D, playBeat, DANCES = [], DANCE_STYLE = {} } = await import('/dist/7ots.esm.js');
269
277
  const spec = id.look?.character || {};
270
278
  let ch = null;
271
279
  if (new URLSearchParams(location.search).has('3d')) {
272
280
  // three comes from the CDN; without WebGL or network the 2D ot takes over
273
281
  try {
274
282
  const m = await loadCharacter3D();
275
- ch = m.createCharacter3D($('#face'), spec, { material: 'plush', backdrop: !desktop, orbit: !desktop, bleed: desktop ? 'window' : 0, stage: { key: 'pet', zIndex: 3, maxDpr: 2, minDpr: 1.25, supersample: desktop } });
283
+ ch = m.createCharacter3D($('#face'), spec, { material: 'plush', backdrop: !desktop && BOOT.backdrop !== false, orbit: !desktop, bleed: desktop ? 'window' : 0, stage: { key: 'pet', zIndex: 3, maxDpr: 2, minDpr: 1.25, supersample: desktop } });
276
284
  if (ch.fallback) console.warn('[7ots pet] no WebGL: 2D ot');
277
285
  } catch (err) {
278
286
  console.warn('[7ots pet] 3D ot unavailable, using 2D:', err?.message || err);
279
287
  ch = null;
280
288
  }
281
289
  }
282
- ch ||= createCharacter($('#face'), spec, { locale: lang, title: id.name });
290
+ ch ||= createCharacter($('#face'), spec, { locale: lang, title: id.name, backdrop: BOOT.backdrop !== false });
283
291
  const is3d = !!ch.character;
284
292
  document.body.classList.toggle('ot3d', is3d);
285
293
  // While a gesture/effect/morph plays the ot needs room around it (wings, hearts, confetti): the desktop
@@ -287,6 +295,7 @@
287
295
  let fxUntil = 0;
288
296
  let actUntil = 0; // a scene act is playing: it needs actRoom px on each side (a beam, a saber swing)
289
297
  let actRoom = 0;
298
+ let actTall = 70; // and that much room above it (an entrance's name card)
290
299
  for (const k of ['gesture', 'effect', 'morph']) {
291
300
  const f = ch[k]?.bind(ch);
292
301
  if (!f) continue;
@@ -328,7 +337,7 @@
328
337
  h = Math.max(h, st.height + 6 + b.offsetHeight + 16);
329
338
  }
330
339
  if (document.body.classList.contains('talking')) (w = Math.max(w, 240)), (h = Math.max(h, st.height + 60));
331
- if (Date.now() < actUntil) (w = Math.max(w, actRoom * 2)), (h = Math.max(h, st.height + 70));
340
+ if (Date.now() < actUntil) (w = Math.max(w, actRoom * 2)), (h = Math.max(h, st.height + actTall));
332
341
  w = Math.max(w, st.width + 2 * 58); // the menu beside it (shown on hover)
333
342
  return { w: Math.ceil(w), h: Math.ceil(h) };
334
343
  };
@@ -707,6 +716,7 @@
707
716
  const m = JSON.parse(e.data);
708
717
  if (m.reload) return location.reload(); // e.g. the voice changed in the settings
709
718
  if (m.restart) return waitAndReload(); // it became another ot: a new daemon is starting
719
+ if (m.backdrop !== undefined) return location.reload(); // its style's background on/off (settings)
710
720
  if (m.view && setView(m.view === '3d')) return; // 2D ↔ 3D changed in the settings
711
721
  if (guest) return; // the host's events are the host's
712
722
  if (m.stir || (m.say && asleep && Date.now() < stirUntil)) stir(); // awake until it has said it
@@ -718,6 +728,8 @@
718
728
  if (m.morph) ch.morph?.(m.morph);
719
729
  if (m.effect) ch.effect?.(m.effect);
720
730
  if (m.say) say(m.say, !m.gesture);
731
+ if (m.dance) dance(m.dance);
732
+ if (m.entrance) entrance(m.entrance);
721
733
  if (m.point && desktop) window.__goal = m.point; // the desktop shell walks it over there
722
734
  };
723
735
  }
@@ -927,10 +939,13 @@
927
939
  if (d.effect) ch.effect?.(d.effect);
928
940
  if (d.act && ACTS[d.act]) {
929
941
  actRoom = d.room || 150;
942
+ actTall = 70;
930
943
  actUntil = Date.now() + (d.ms || 3600);
931
944
  tellNeed();
932
945
  requestAnimationFrame(() => ACTS[d.act](d.dir || 1, d));
933
946
  }
947
+ if (d.dance) dance(d.dance);
948
+ if (d.entrance) entrance(d.entrance);
934
949
  if (d.face != null) {
935
950
  if (is3d) ch.character.yaw = -d.face * 0.9;
936
951
  else $('#stage').classList.toggle('flip', d.face < 0);
@@ -939,6 +954,112 @@
939
954
  }
940
955
  });
941
956
 
957
+ // ── dances with music, and entrances (POST /dance, /entrance on the daemon; `7ots dance`, `7ots entrance`) ──
958
+ // Music: synthesized at the dance's tempo (beat.js, no copyrighted audio) or one of your own files in ~/.7ots/music.
959
+ const any = (a) => a[Math.floor(Math.random() * a.length)];
960
+ let beat = null;
961
+ let tune = null;
962
+ let danceEnd = 0;
963
+ function stopMusic(fade = 0.4) {
964
+ beat?.stop(fade);
965
+ beat = null;
966
+ if (tune) {
967
+ const a = tune;
968
+ tune = null;
969
+ const v0 = a.volume;
970
+ const t0 = Date.now();
971
+ const f = setInterval(() => {
972
+ const k = Math.min(1, (Date.now() - t0) / (fade * 1000 || 1));
973
+ a.volume = Math.max(0, v0 * (1 - k));
974
+ if (k >= 1) (clearInterval(f), a.pause());
975
+ }, 40);
976
+ }
977
+ }
978
+ function music(m, ms, style) {
979
+ stopMusic(0.2);
980
+ if (!m || guest) return; // a visitor dances along to the host's music
981
+ const vol = Math.max(0, Math.min(1, m.vol ?? 0.5));
982
+ if (m.file) {
983
+ const a = new Audio(`/music/${encodeURIComponent(m.file)}?token=${encodeURIComponent(BOOT.token)}`);
984
+ a.volume = vol;
985
+ a.play().catch((e) => console.warn('[7ots pet] music:', e?.message || e));
986
+ tune = a;
987
+ setTimeout(() => tune === a && stopMusic(1.2), Math.max(0, ms - 1200));
988
+ } else beat = playBeat?.(m.style || style || 'hype', { ms, volume: vol });
989
+ }
990
+ function dance(d = {}) {
991
+ if (asleep) stir();
992
+ const name = DANCES.includes(d.name) ? d.name : any(DANCES.length ? DANCES : ['dance']);
993
+ const ms = Math.max(1500, Math.min(60000, Number(d.ms) || 8000));
994
+ danceEnd = Date.now() + ms;
995
+ ch.gesture(name, { ms });
996
+ music(d.music, ms, DANCE_STYLE[name]);
997
+ }
998
+ // a wrestling-style entrance: the crowd, two booms with pyro, spotlights, its name slammed in, then a dance
999
+ let entering = 0;
1000
+ function entrance(d = {}) {
1001
+ if (Date.now() < entering) return;
1002
+ const INTRO = 2200; // the music's intro (crowd + booms) before the riff
1003
+ const ms = 12000;
1004
+ entering = Date.now() + ms;
1005
+ stir();
1006
+ const kind = ['wwe', 'rock', 'magic'].includes(d.kind) ? d.kind : 'wwe';
1007
+ const style = { wwe: 'entrance', rock: 'hype', magic: 'chip' }[kind];
1008
+ music(d.music && !d.music.file ? { ...d.music, style } : d.music, ms, style);
1009
+ if (desktop) console.debug('§7enter'); // the shell walks it in from the side
1010
+ actRoom = 190;
1011
+ actTall = 150;
1012
+ actUntil = Date.now() + ms;
1013
+ tellNeed();
1014
+ // walking in under two crossing spotlights
1015
+ for (const k of kind === 'magic' ? [] : [-1, 1]) {
1016
+ const sp = prop(kind === 'rock' ? 'spot rock' : 'spot');
1017
+ gone(sp, sp.animate([{ opacity: 0, transform: `rotate(${k * 28}deg)` }, { opacity: 1, transform: `rotate(${-k * 18}deg)`, offset: 0.25 }, { opacity: 1, transform: `rotate(${k * 12}deg)`, offset: 0.5 }, { opacity: 1, transform: `rotate(${-k * 6}deg)`, offset: 0.75 }, { opacity: 0, transform: 'rotate(0deg)' }], { duration: ms, easing: 'ease-in-out' }));
1018
+ }
1019
+ ch.gesture('groove', { ms: INTRO + 1800 });
1020
+ // pyro on each boom of the music (1.0 s and 1.6 s), both sides
1021
+ const pyro = (at) =>
1022
+ setTimeout(() => {
1023
+ if (kind === 'rock') return ch.effect?.('confetti'), ch.effect?.('notes');
1024
+ if (kind === 'magic') {
1025
+ for (const x of [-1, 0, 1]) {
1026
+ const p = prop('smoke', { left: `calc(50% + ${x * (actRoom - 50)}px)` });
1027
+ gone(p, p.animate([{ transform: 'scale(.3)', opacity: 0.9 }, { transform: 'scale(1.6) translateY(-20px)', opacity: 0 }], { duration: 1600, easing: 'ease-out' }));
1028
+ }
1029
+ return ch.effect?.('sparkles');
1030
+ }
1031
+ for (const x of [-1, 1]) {
1032
+ const p = prop('pyro', { left: `calc(50% + ${x * (actRoom - 30)}px)` });
1033
+ gone(p, p.animate([{ transform: 'scaleY(0)', opacity: 1 }, { transform: 'scaleY(1.1)', opacity: 1, offset: 0.25 }, { transform: 'scaleY(.8)', opacity: 0.9, offset: 0.6 }, { transform: 'scaleY(.2)', opacity: 0 }], { duration: 1100, easing: 'ease-out' }));
1034
+ }
1035
+ const f = prop('flash', { left: '50%', top: '30%' });
1036
+ gone(f, f.animate([{ opacity: 1, transform: 'scale(.5)' }, { opacity: 0, transform: 'scale(4)' }], { duration: 500 }));
1037
+ ch.effect?.('sparkles');
1038
+ }, at);
1039
+ pyro(1000);
1040
+ pyro(1600);
1041
+ // its name, slammed in on the riff
1042
+ setTimeout(() => {
1043
+ const t = prop('title', {}, String(d.name || id.name || 'ot').slice(0, 24));
1044
+ gone(t, t.animate([{ opacity: 0, transform: 'translateX(-50%) scale(2.6)' }, { opacity: 1, transform: 'translateX(-50%) scale(.95)', offset: 0.06 }, { opacity: 1, transform: 'translateX(-50%) scale(1)', offset: 0.1 }, { opacity: 1, transform: 'translateX(-50%) scale(1.04)', offset: 0.85 }, { opacity: 0, transform: 'translateX(-50%) translateY(-10px) scale(1)' }], { duration: ms - INTRO - 600, easing: 'ease-out' }));
1045
+ ch.gesture('celebrate');
1046
+ ch.effect?.('confetti');
1047
+ }, INTRO);
1048
+ // arrived: points at the crowd, then dances to the end of the music
1049
+ setTimeout(() => (ch.gesture('point'), ch.effect?.('sparkles')), INTRO + 1900);
1050
+ setTimeout(() => {
1051
+ const name = DANCES.includes(d.dance) ? d.dance : any(DANCES.filter((n) => n !== 'dab' && n !== 'dance'));
1052
+ danceEnd = entering;
1053
+ ch.gesture(name, { ms: ms - INTRO - 3600 });
1054
+ }, INTRO + 3400);
1055
+ }
1056
+ // an entrance when the pet starts, if the owner turned it on (the server says yes once per run)
1057
+ if (!guest) setTimeout(() => post('/entrance', { start: true }).catch(() => {}), 2500);
1058
+ $('#danceBtn').title = t('dance');
1059
+ if (!guest)
1060
+ $('#danceBtn')?.addEventListener('click', () => post('/dance', {}).catch(() => dance({})));
1061
+ else $('#danceBtn')?.addEventListener('click', () => dance({}));
1062
+
942
1063
  // ── personality: small life between events (glances, fidgets, effects, shape changes) ──
943
1064
  const pick = (a) => a[Math.floor(Math.random() * a.length)];
944
1065
  const SHAPES = ['round', 'egg', 'pear', 'bean', 'squircle', 'drop', 'ghost', 'cat', 'cloud', 'blob', 'heart', 'mushroom', 'tall', 'wide'].filter((x) => x !== spec.shape);
@@ -965,6 +1086,7 @@
965
1086
  [0.6, () => ch.gesture('hiccup')],
966
1087
  [0.5, () => (ch.gesture('sneeze'), ch.effect?.('sneeze'))],
967
1088
  [happy ? 2.5 : 0.6, () => (ch.gesture('dance'), ch.effect?.('notes'))],
1089
+ [happy ? 0.8 : 0.2, () => ch.gesture(pick(DANCES.length ? DANCES : ['dance']), { ms: 3000 })], // a few silent moves (music only when asked)
968
1090
  [happy ? 0.8 : 0.2, () => (ch.gesture('celebrate'), ch.effect?.('sparkles'))],
969
1091
  [0.6, () => ch.gesture('spin')],
970
1092
  [0.5, () => ch.gesture('clap')],
@@ -980,7 +1102,7 @@
980
1102
  }
981
1103
  (function life() {
982
1104
  setTimeout(() => {
983
- if (!asleep && !thinking && !rec && !bubble.classList.contains('on') && !document.hidden) fidget();
1105
+ if (!asleep && !thinking && !rec && !bubble.classList.contains('on') && !document.hidden && Date.now() > danceEnd) fidget(); // not over a dance
984
1106
  life();
985
1107
  }, 4000 + Math.random() * 8000);
986
1108
  })();