-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
executable file
·645 lines (559 loc) · 23.6 KB
/
cli.py
File metadata and controls
executable file
·645 lines (559 loc) · 23.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
#!/usr/bin/env python3
"""
DJ Treta CLI — Talk to the DJ, control the decks, feel the music.
Usage:
python cli.py # Interactive mode
python cli.py status # Quick status check
python cli.py talk "msg" # One-shot talk to brain
"""
import json
import os
import readline
import signal
import sys
import threading
import time
from pathlib import Path
import httpx
from rich.console import Console
from rich.live import Live
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
from rich.layout import Layout
from rich.columns import Columns
from rich.markdown import Markdown
from rich.rule import Rule
# ── Config ────────────────────────────────────────────────────────────
MIXXX_URL = "http://localhost:7778"
STATE_FILE = Path("/tmp/dj-treta-state.json")
COMMAND_FILE = Path("/tmp/dj-treta-command.json")
DAEMON_LOG = Path("/tmp/dj-treta-daemon.log")
MUSIC_DIR = Path.home() / "Music" / "DJTreta"
console = Console()
# ── Mixxx Client ──────────────────────────────────────────────────────
def mixxx_get(path: str) -> dict | None:
try:
r = httpx.get(f"{MIXXX_URL}{path}", timeout=2)
return r.json()
except Exception:
return None
def mixxx_post(path: str, data: dict) -> dict | None:
try:
r = httpx.post(f"{MIXXX_URL}{path}", json=data, timeout=2)
return r.json()
except Exception:
return None
def read_daemon_state() -> dict | None:
try:
if STATE_FILE.exists():
return json.loads(STATE_FILE.read_text())
except Exception:
pass
return None
# ── Display Helpers ───────────────────────────────────────────────────
KEY_MAP = {
1: "C", 2: "Db", 3: "D", 4: "Eb", 5: "E", 6: "F",
7: "F#", 8: "G", 9: "Ab", 10: "A", 11: "Bb", 12: "B",
13: "Cm", 14: "C#m", 15: "Dm", 16: "Ebm", 17: "Em", 18: "Fm",
19: "F#m", 20: "Gm", 21: "G#m", 22: "Am", 23: "Bbm", 24: "Bm",
}
def format_time(seconds) -> str:
if isinstance(seconds, str):
return seconds # "infinite" etc
if seconds <= 0:
return "0:00"
m, s = divmod(int(seconds), 60)
return f"{m}:{s:02d}"
def format_key(key_num: int) -> str:
return KEY_MAP.get(key_num, "?")
def energy_bar(energy: float, width: int = 20) -> str:
filled = int(energy / 10 * width)
return "█" * filled + "░" * (width - filled)
def make_deck_panel(deck: dict, deck_num: int, is_active: bool) -> Panel:
if not deck.get("track_loaded"):
return Panel("[dim]empty[/dim]", title=f"Deck {deck_num}", border_style="dim")
bpm = deck.get("bpm", 0)
key = format_key(deck.get("key", 0))
pos = deck.get("position_seconds", 0)
dur = deck.get("duration", 0)
remaining = deck.get("remaining_seconds", 0)
playing = deck.get("playing", False)
synced = deck.get("sync_enabled", False)
vol = deck.get("volume", 0)
# Progress bar
progress_pct = pos / dur if dur > 0 else 0
bar_width = 30
filled = int(progress_pct * bar_width)
bar = "━" * filled + "●" + "─" * (bar_width - filled - 1)
status_icon = "▶" if playing else "⏸"
sync_icon = " SYNC" if synced else ""
active_marker = " ★" if is_active else ""
lines = [
f" {status_icon} {format_time(pos)} [{bar}] {format_time(dur)}",
f" BPM: [bold]{bpm:.0f}[/bold] Key: [bold]{key}[/bold] Vol: {vol:.0f}%{sync_icon}",
f" Remaining: [bold]{format_time(remaining)}[/bold]",
]
color = "cyan" if deck_num == 1 else "magenta"
if is_active:
color = "bold " + color
return Panel(
"\n".join(lines),
title=f"Deck {deck_num}{active_marker}",
border_style=color,
)
def make_crossfader(xf: float) -> str:
"""Visual crossfader. -1 = Deck 1, +1 = Deck 2."""
width = 30
pos = int((xf + 1) / 2 * width)
pos = max(0, min(width, pos))
bar = "─" * pos + "◆" + "─" * (width - pos)
return f" D1 [{bar}] D2"
def make_status_display() -> Panel:
status = mixxx_get("/api/status")
if not status:
return Panel("[red]Mixxx not responding[/red]", title="DJ Treta", border_style="red")
state = read_daemon_state()
d1 = status.get("deck1", {})
d2 = status.get("deck2", {})
xf = status.get("crossfader", 0)
# Determine active deck
if d1.get("playing") and not d2.get("playing"):
active = 1
elif d2.get("playing") and not d1.get("playing"):
active = 2
elif xf < -0.3:
active = 1
else:
active = 2
deck1_panel = make_deck_panel(d1, 1, active == 1)
deck2_panel = make_deck_panel(d2, 2, active == 2)
crossfader = make_crossfader(xf)
# Brain status
brain_lines = []
if state:
phase = state.get("phase", "?")
mood = state.get("mood", "?")
played = state.get("tracks_played", 0)
elapsed = state.get("set_elapsed", 0)
remaining = state.get("set_remaining", 0)
phase_colors = {
"playing": "green", "preparing": "yellow",
"transitioning": "blue", "recovery": "red",
"starting": "yellow", "stopped": "dim",
}
phase_color = phase_colors.get(phase, "white")
brain_lines.append(f" Brain: [{phase_color}]{phase.upper()}[/{phase_color}] Mood: [bold]{mood}[/bold]")
brain_lines.append(f" Set: {format_time(elapsed)} elapsed, {format_time(remaining)} remaining Tracks: {played}")
if state.get("next_track"):
nt = state["next_track"]
brain_lines.append(f" Next: [italic]{nt.get('title', '?')}[/italic]")
last_result = state.get("last_command_result", "")
if last_result and last_result != "processing...":
# Truncate long results
if len(last_result) > 80:
last_result = last_result[:80] + "..."
brain_lines.append(f" Last: [dim]{last_result}[/dim]")
else:
brain_lines.append(" [dim]Brain not running. Start with: /start[/dim]")
brain_text = "\n".join(brain_lines)
# Compose
content = Table.grid(padding=0)
content.add_row(Columns([deck1_panel, deck2_panel], equal=True))
content.add_row(Text(crossfader))
content.add_row(Text(""))
content.add_row(Text.from_markup(brain_text))
return Panel(content, title="[bold]DJ Treta[/bold]", border_style="bright_white")
# ── Commands ──────────────────────────────────────────────────────────
def send_brain_command(command: str, args: dict = {}) -> str:
"""Send command to brain daemon and wait for response."""
payload = {"command": command, "args": args}
COMMAND_FILE.write_text(json.dumps(payload, indent=2))
# Poll for response
for _ in range(120): # 60 seconds
time.sleep(0.5)
state = read_daemon_state()
if state:
result = state.get("last_command_result", "")
if state.get("last_command") == command and result and result != "processing...":
return result
return "No response from brain (timeout)"
def cmd_status():
"""Show current status."""
console.print(make_status_display())
def cmd_talk(message: str, readonly: bool = False):
"""Talk to the brain. readonly=True for live web listeners (no control)."""
console.print(f"\n[bold cyan]You:[/bold cyan] {message}")
console.print("[dim]thinking...[/dim]", end="\r")
response = send_brain_command("talk", {"message": message, "readonly": readonly})
# Clear "thinking..."
console.print(" " * 40, end="\r")
console.print(f"[bold magenta]DJ Treta:[/bold magenta] {response}\n")
def cmd_mood(mood: str):
"""Change mood."""
response = send_brain_command("change_mood", {"mood": mood})
console.print(f"[green]{response}[/green]")
def cmd_skip():
"""Skip current track."""
response = send_brain_command("skip", {})
console.print(f"[yellow]{response}[/yellow]")
def cmd_play(deck: int = 1):
mixxx_post("/api/play", {"deck": deck})
console.print(f"[green]▶ Deck {deck}[/green]")
def cmd_pause(deck: int = 1):
mixxx_post("/api/pause", {"deck": deck})
console.print(f"[yellow]⏸ Deck {deck}[/yellow]")
def cmd_tracks():
"""List library tracks."""
table = Table(title="Track Library", show_lines=False)
table.add_column("#", style="dim", width=4)
table.add_column("Genre", style="cyan", width=15)
table.add_column("Track", style="white")
i = 1
for genre_dir in sorted(MUSIC_DIR.iterdir()):
if not genre_dir.is_dir() or genre_dir.name.startswith('.'):
continue
for f in sorted(genre_dir.iterdir()):
if f.suffix.lower() in ('.mp3', '.wav', '.flac', '.ogg', '.m4a'):
table.add_row(str(i), genre_dir.name, f.stem)
i += 1
console.print(table)
def cmd_load(deck: int, query: str):
"""Load a track by partial name match."""
query_lower = query.lower()
for genre_dir in sorted(MUSIC_DIR.iterdir()):
if not genre_dir.is_dir():
continue
for f in sorted(genre_dir.iterdir()):
if query_lower in f.stem.lower():
result = mixxx_post("/api/load", {"deck": deck, "track": str(f)})
console.print(f"[green]Loaded on Deck {deck}:[/green] {f.stem}")
return
console.print(f"[red]No track matching '{query}'[/red]")
def cmd_transition(deck: int = 2, technique: str = "blend", duration: int = 60):
response = send_brain_command("transition_now", {
"technique": technique, "duration": duration
})
console.print(f"[blue]{response}[/blue]")
def cmd_start_brain(mood: str = "melodic-techno", duration: int = 60):
"""Start the brain daemon."""
import subprocess, shutil
# Clear old log + bytecache before starting
Path("/tmp/dj-treta-daemon.log").write_text("")
for cache_dir in [Path(__file__).parent / "agent" / "__pycache__",
Path(__file__).parent / "agent" / "tools" / "__pycache__",
Path(__file__).parent / "__pycache__"]:
if cache_dir.exists():
shutil.rmtree(cache_dir)
venv_python = Path(__file__).parent / ".venv" / "bin" / "python3"
subprocess.Popen(
[str(venv_python), "-m", "agent", "--mood", mood, "--duration", str(duration)],
cwd=str(Path(__file__).parent),
stdout=open("/tmp/dj-treta-daemon.log", "w"),
stderr=subprocess.STDOUT,
)
console.print(f"[green]Brain started — mood: {mood}, duration: {duration}m[/green]")
def cmd_stop_brain():
"""Stop the brain daemon."""
import subprocess
subprocess.run(["pkill", "-f", "python.*-m agent"], capture_output=True)
console.print("[yellow]Brain stopped[/yellow]")
def cmd_logs(n: int = 20):
"""Show recent daemon logs."""
if DAEMON_LOG.exists():
lines = DAEMON_LOG.read_text().strip().split("\n")
# Filter to key events
skip = ["LiteLLM", "Wrapper:", "completion() model", "─────", "│", "╭", "╰", "Observations:", "Step ", "Calling tool"]
key_lines = []
for l in lines:
if not any(k in l for k in ["INFO", "WARNING", "ERROR"]):
continue
if any(s in l for s in skip):
continue
# Strip ANSI and check if there's actual content after timestamp
clean = l.strip()
# Skip lines that are just "HH:MM:SS [INFO] " with nothing after
parts = clean.split("] ", 1)
if len(parts) < 2 or not parts[1].strip():
continue
key_lines.append(l)
for line in key_lines[-n:]:
if "ERROR" in line or "WARNING" in line:
console.print(f"[red]{line}[/red]")
elif "Playing:" in line or "Next:" in line:
console.print(f"[green]{line}[/green]")
elif "Transition" in line:
console.print(f"[blue]{line}[/blue]")
else:
console.print(f"[dim]{line}[/dim]")
else:
console.print("[dim]No daemon log found[/dim]")
def cmd_live():
"""Live updating status display."""
console.print("[dim]Live mode — press Ctrl+C to exit[/dim]\n")
try:
while True:
console.clear()
console.print(make_status_display())
console.print("\n[dim]Live mode — Ctrl+C to exit | refreshing every 2s[/dim]")
time.sleep(2)
except KeyboardInterrupt:
console.print("\n[dim]Exited live mode[/dim]")
def cmd_help():
"""Show help."""
help_text = """
[bold]DJ Treta CLI[/bold]
[bold cyan]Talk to the DJ:[/bold cyan]
[bold]<message>[/bold] Talk to DJ Treta brain (anything goes)
[bold cyan]Slash Commands:[/bold cyan]
[bold]/status[/bold] Show current deck status
[bold]/live[/bold] Live updating display (2s refresh)
[bold]/mood[/bold] <mood> Change mood (dark-techno, melodic-techno, deep, progressive, etc.)
[bold]/skip[/bold] Skip to next track
[bold]/tracks[/bold] List all tracks in library
[bold]/load[/bold] <deck> <query> Load track by name search onto deck
[bold]/play[/bold] [deck] Play deck (default: 1)
[bold]/pause[/bold] [deck] Pause deck (default: 1)
[bold]/transition[/bold] [tech] [s] Start transition (blend/bass_swap/filter_sweep, duration)
[bold]/start[/bold] [mood] [min] Start brain daemon
[bold]/stop[/bold] Stop brain daemon
[bold]/logs[/bold] [n] Show last n daemon log lines
[bold]/help[/bold] This help
[bold]/quit[/bold] Exit
[dim]Anything without / is sent to the brain as conversation.[/dim]
"""
console.print(help_text)
# ── Main Loop ─────────────────────────────────────────────────────────
def _daemon_cmd(action):
"""Start/stop/restart the Being daemon."""
import subprocess
DJ_HOME = Path(__file__).parent
PYTHON = DJ_HOME / ".venv" / "bin" / "python3"
PID_FILE = Path("/tmp/dj-treta.pid")
LOG = Path("/tmp/dj-treta-daemon.log")
if action in ("stop", "restart"):
if PID_FILE.exists():
try:
pid = int(PID_FILE.read_text().strip())
os.kill(pid, 15) # SIGTERM
# Wait for process to actually die before continuing
import time
for _ in range(30): # 3s max
time.sleep(0.1)
try:
os.kill(pid, 0) # check if alive
except ProcessLookupError:
break # dead
console.print(f"[yellow]Stopped (PID {pid})[/yellow]")
PID_FILE.unlink(missing_ok=True)
except (ProcessLookupError, ValueError):
PID_FILE.unlink(missing_ok=True)
else:
if action == "stop":
console.print("[dim]Not running[/dim]")
return
if action == "restart":
import time
time.sleep(1)
if action in ("start", "restart"):
if PID_FILE.exists():
try:
pid = int(PID_FILE.read_text().strip())
os.kill(pid, 0)
console.print(f"[yellow]Already running (PID {pid})[/yellow]")
return
except (ProcessLookupError, ValueError):
PID_FILE.unlink(missing_ok=True)
PID_FILE.unlink(missing_ok=True)
# Truncate log AFTER old daemon is dead — clean slate for TUI
LOG.write_text("")
subprocess.Popen(
[str(PYTHON), "-m", "agent"],
cwd=str(DJ_HOME),
stdout=open(str(LOG), "a"), # append — don't clobber our truncation
stderr=subprocess.STDOUT,
)
import time
time.sleep(2)
if PID_FILE.exists():
console.print(f"[green]Started (PID {PID_FILE.read_text().strip()})[/green]")
else:
console.print("[green]Starting...[/green]")
console.print("[dim]Talk to her: djtreta talk 'play something melodic'[/dim]")
def _kill_all():
"""Kill everything — daemon, Mixxx, LiteLLM."""
import subprocess
subprocess.run(["pkill", "-f", "python.*agent"], capture_output=True)
subprocess.run(["pkill", "-f", "mixxx"], capture_output=True)
subprocess.run(["pkill", "-f", "litellm"], capture_output=True)
Path("/tmp/dj-treta.pid").unlink(missing_ok=True)
console.print("[yellow]Killed: daemon, Mixxx, LiteLLM[/yellow]")
def _reset(hard=False):
"""Reset state. Soft = keep library + DB. Hard = delete everything."""
import shutil
import subprocess
mode = "hard" if hard else "soft"
console.print(f"[yellow]Resetting ({mode})...[/yellow]")
# Kill daemon + Mixxx
subprocess.run(["pkill", "-f", "python.*agent"], capture_output=True)
subprocess.run(["pkill", "-f", "mixxx"], capture_output=True)
# Clean state files (always)
for f in ["/tmp/dj-treta-state.json", "/tmp/dj-treta-command.json",
"/tmp/dj-treta-thinking.log", "/tmp/dj-treta-daemon.log",
"/tmp/dj-treta.pid", "/tmp/dj-treta-billing.json",
"/tmp/dj-treta-playlist.json"]:
Path(f).unlink(missing_ok=True)
# Clean session + bytecache (always)
DJ_HOME = Path.home() / "beings" / "dj-treta"
(DJ_HOME / ".beings" / "session.json").unlink(missing_ok=True)
import shutil as _shutil
for cache_dir in [DJ_HOME / "agent" / "__pycache__", DJ_HOME / "agent" / "tools" / "__pycache__", DJ_HOME / "__pycache__"]:
if cache_dir.exists():
_shutil.rmtree(cache_dir)
music_dir = Path.home() / "Music" / "DJTreta"
if hard:
# Nuclear — delete library + DB
if music_dir.exists():
shutil.rmtree(music_dir)
for genre in ["melodic-techno", "dark-techno", "deep", "progressive",
"minimal", "vocal", "psychill", "psytrance", "techno"]:
(music_dir / genre).mkdir(parents=True, exist_ok=True)
(DJ_HOME / "djtreta.db").unlink(missing_ok=True)
console.print("[green]Hard reset complete.[/green]")
console.print(f" Library: deleted")
console.print(f" Database: deleted")
else:
# Soft — keep library + DB
track_count = sum(1 for _ in music_dir.rglob("*.mp3")) if music_dir.exists() else 0
console.print("[green]Soft reset complete.[/green]")
console.print(f" Library: {track_count} tracks (kept)")
console.print(f" Database: kept")
console.print(f" State: cleared")
console.print(f" Billing: cleared")
console.print(f"[dim] djtreta start to begin fresh[/dim]")
def cmd_logs_follow():
"""Tail -f the daemon log — full raw output, no filtering."""
log_file = Path("/tmp/dj-treta-daemon.log")
if not log_file.exists():
console.print("[dim]No daemon log found[/dim]")
return
console.print("[dim]Following daemon log (Ctrl+C to stop)...[/dim]\n")
try:
import subprocess
subprocess.run(["tail", "-f", str(log_file)])
except KeyboardInterrupt:
console.print("\n[dim]Stopped[/dim]")
BANNER = """[bold bright_white]
╔══════════════════════════════════════╗
║ [bold cyan]DJ Treta[/bold cyan] [dim]v1.0[/dim] ║
║ [dim]An AI Being that DJs.[/dim] ║
╚══════════════════════════════════════╝
[/bold bright_white]"""
def main():
# One-shot commands
if len(sys.argv) > 1:
cmd = sys.argv[1]
if cmd == "status":
cmd_status()
return
elif cmd in ("ui", "tui"):
from tui import main as tui_main
tui_main()
return
elif cmd == "live":
cmd_live()
return
elif cmd == "talk" and len(sys.argv) > 2:
cmd_talk(" ".join(sys.argv[2:]))
return
elif cmd == "logs":
args = sys.argv[2:]
if args and args[0] in ("-f", "--follow", "follow", "tail"):
cmd_logs_follow()
else:
n = int(args[0]) if args else 20
cmd_logs(n)
return
elif cmd == "start":
# djtreta start [mood] — e.g., djtreta start "dark melodic techno"
mood_args = " ".join(sys.argv[2:]) if len(sys.argv) > 2 else ""
if mood_args:
Path("/tmp/dj-treta-mood.txt").write_text(mood_args)
_daemon_cmd("start")
return
elif cmd == "stop":
_daemon_cmd("stop")
return
elif cmd == "restart":
_daemon_cmd("restart")
return
elif cmd == "reset":
hard = "--hard" in sys.argv[2:] or "hard" in sys.argv[2:]
_reset(hard=hard)
return
elif cmd == "kill":
_kill_all()
return
elif cmd == "init":
from agent.init import run_init
run_init()
return
# Interactive mode
console.print(BANNER)
cmd_status()
console.print()
console.print("[dim]Type a message to talk to DJ Treta, or /help for commands[/dim]\n")
while True:
try:
user_input = input("\033[1;36m❯ \033[0m").strip()
except (EOFError, KeyboardInterrupt):
console.print("\n[dim]Later.[/dim]")
break
if not user_input:
continue
# Slash commands
if user_input.startswith("/"):
parts = user_input[1:].split()
cmd = parts[0].lower() if parts else ""
args = parts[1:]
if cmd in ("quit", "exit", "q"):
console.print("[dim]Later.[/dim]")
break
elif cmd == "help":
cmd_help()
elif cmd == "status":
cmd_status()
elif cmd == "live":
cmd_live()
elif cmd == "mood" and args:
cmd_mood(args[0])
elif cmd == "skip":
cmd_skip()
elif cmd == "tracks":
cmd_tracks()
elif cmd == "load" and len(args) >= 2:
cmd_load(int(args[0]), " ".join(args[1:]))
elif cmd == "play":
cmd_play(int(args[0]) if args else 1)
elif cmd == "pause":
cmd_pause(int(args[0]) if args else 1)
elif cmd == "transition":
tech = args[0] if args else "blend"
dur = int(args[1]) if len(args) > 1 else 60
cmd_transition(technique=tech, duration=dur)
elif cmd == "start":
mood = args[0] if args else "melodic-techno"
dur = int(args[1]) if len(args) > 1 else 60
cmd_start_brain(mood, dur)
elif cmd == "stop":
cmd_stop_brain()
elif cmd == "logs":
n = int(args[0]) if args else 20
cmd_logs(n)
else:
console.print(f"[red]Unknown command: /{cmd}[/red] — try /help")
else:
# Everything else is a message to the brain
cmd_talk(user_input)
if __name__ == "__main__":
main()