Personal AI, On Personal Devices
Python
feat: add jarvis channels CLI commands for iMessage daemon lifecycle
Jon Saad-Falcon8629749e36d9
diff --git a/src/openjarvis/cli/__init__.py b/src/openjarvis/cli/__init__.pyindex df3e7be2..f6125746 100644--- a/src/openjarvis/cli/__init__.py+++ b/src/openjarvis/cli/__init__.py@@ -10,6 +10,7 @@ from openjarvis.cli.agent_cmd import agentfrom openjarvis.cli.ask import askfrom openjarvis.cli.bench_cmd import benchfrom openjarvis.cli.channel_cmd import channel+from openjarvis.cli.channels_cmd import channelsfrom openjarvis.cli.chat_cmd import chatfrom openjarvis.cli.compose_cmd import composefrom openjarvis.cli.config_cmd import config@@ -68,6 +69,7 @@ cli.add_command(memory, "memory")cli.add_command(telemetry, "telemetry")cli.add_command(bench, "bench")cli.add_command(channel, "channel")+cli.add_command(channels, "channels")cli.add_command(scheduler, "scheduler")cli.add_command(doctor, "doctor")cli.add_command(agent, "agents")diff --git a/src/openjarvis/cli/channels_cmd.py b/src/openjarvis/cli/channels_cmd.pynew file mode 100644index 00000000..e4a9ecac--- /dev/null+++ b/src/openjarvis/cli/channels_cmd.py@@ -0,0 +1,150 @@+"""``jarvis channels`` — manage messaging channels for the agent."""++from __future__ import annotations++import sys++import click+from rich.console import Console+from rich.table import Table++[email protected]("channels")+def channels() -> None:+ """Manage messaging channels (iMessage, Slack, WhatsApp, SMS)."""++[email protected]("status")+def channels_status() -> None:+ """Show status of all configured channels."""+ from openjarvis.channels.imessage_daemon import is_running++ console = Console()+ table = Table(title="Channel Status")+ table.add_column("Channel", style="bold")+ table.add_column("Status")+ table.add_column("Details", style="dim")++ if is_running():+ table.add_row(+ "iMessage", "[green]running[/green]",+ "Polling chat.db",+ )+ else:+ table.add_row(+ "iMessage", "[dim]stopped[/dim]",+ "jarvis channels imessage-start <contact>",+ )++ console.print(table)++[email protected]("imessage-start")[email protected]("chat_identifier")+ "--background/--foreground",+ default=True,+ help="Run in background.",+)+def imessage_start(+ chat_identifier: str, background: bool,+) -> None:+ """Start the iMessage daemon for CHAT_IDENTIFIER.++ CHAT_IDENTIFIER is the phone number or email to monitor.+ """+ from openjarvis.channels.imessage_daemon import (+ is_running,+ run_daemon,+ )++ console = Console()++ if is_running():+ console.print(+ "[yellow]iMessage daemon already running.[/yellow]"+ )+ return++ if background:+ import subprocess++ proc = subprocess.Popen(+ [+ sys.executable, "-m",+ "openjarvis.channels.imessage_daemon",+ "--chat", chat_identifier,+ ],+ stdout=subprocess.DEVNULL,+ stderr=subprocess.DEVNULL,+ start_new_session=True,+ )+ console.print(+ f"[green]iMessage daemon started[/green] "+ f"(PID {proc.pid})\n"+ f"Monitoring: {chat_identifier}\n"+ "Text this contact from your iPhone "+ "to chat with the agent."+ )+ else:+ console.print(+ f"[green]Starting iMessage daemon[/green] "+ f"— monitoring {chat_identifier}"+ )+ console.print("Press Ctrl+C to stop.\n")++ from openjarvis.agents.deep_research import (+ DeepResearchAgent,+ )+ from openjarvis.connectors.retriever import (+ TwoStageRetriever,+ )+ from openjarvis.connectors.store import KnowledgeStore+ from openjarvis.engine.ollama import OllamaEngine+ from openjarvis.tools.knowledge_search import (+ KnowledgeSearchTool,+ )+ from openjarvis.tools.knowledge_sql import (+ KnowledgeSQLTool,+ )+ from openjarvis.tools.scan_chunks import ScanChunksTool+ from openjarvis.tools.think import ThinkTool++ engine = OllamaEngine()+ store = KnowledgeStore()+ retriever = TwoStageRetriever(store)+ tools = [+ KnowledgeSearchTool(retriever=retriever),+ KnowledgeSQLTool(store=store),+ ScanChunksTool(+ store=store, engine=engine,+ model="qwen3.5:4b",+ ),+ ThinkTool(),+ ]+ agent = DeepResearchAgent(+ engine=engine, model="qwen3.5:4b", tools=tools,+ )++ def handler(text: str) -> str:+ result = agent.run(text)+ return result.content or "No results found."++ run_daemon(+ chat_identifier=chat_identifier,+ handler=handler,+ )++[email protected]("imessage-stop")+def imessage_stop() -> None:+ """Stop the iMessage daemon."""+ from openjarvis.channels.imessage_daemon import stop_daemon++ console = Console()+ if stop_daemon():+ console.print("[green]iMessage daemon stopped.[/green]")+ else:+ console.print(+ "[dim]iMessage daemon is not running.[/dim]"+ )