xml-pipeline/run_organism.py
dullfig e653d63bc1 Rename agentserver to xml_pipeline, add console example
OSS restructuring for open-core model:
- Rename package from agentserver/ to xml_pipeline/
- Update all imports (44 Python files, 31 docs/configs)
- Update pyproject.toml for OSS distribution (v0.3.0)
- Move prompt_toolkit from core to optional [console] extra
- Remove auth/server/lsp from core optional deps (-> Nextra)

New console example in examples/console/:
- Self-contained demo with handlers and config
- Uses prompt_toolkit (optional, falls back to input())
- No password auth, no TUI, no LSP — just the basics
- Shows how to use xml-pipeline as a library

Import changes:
- from agentserver.* -> from xml_pipeline.*
- CLI entry points updated: xml_pipeline.cli:main

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 21:41:19 -08:00

94 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""
run_organism.py — Start the organism with TUI console.
Usage:
python run_organism.py [config.yaml]
python run_organism.py --simple [config.yaml] # Use simple console
This boots the organism with a split-screen terminal UI:
- Scrolling output area above
- Status bar separator
- Input area below
Flow:
1. Bootstrap organism
2. Start pump in background
3. Run TUI console
4. /quit shuts down gracefully
"""
import asyncio
import sys
from pathlib import Path
from xml_pipeline.message_bus import bootstrap
from xml_pipeline.console.console_registry import set_console
async def run_organism(config_path: str = "config/organism.yaml", use_simple: bool = False):
"""Boot organism with TUI console."""
# Bootstrap the pump
pump = await bootstrap(config_path)
if use_simple:
# Use old SecureConsole for compatibility
from xml_pipeline.console import SecureConsole
console = SecureConsole(pump)
if not await console.authenticate():
print("Authentication failed.")
return
set_console(None)
pump_task = asyncio.create_task(pump.run())
try:
await console.run_command_loop()
finally:
pump_task.cancel()
try:
await pump_task
except asyncio.CancelledError:
pass
await pump.shutdown()
print("Goodbye!")
else:
# Use new TUI console
from xml_pipeline.console.tui_console import TUIConsole
console = TUIConsole(pump)
set_console(console) # Register for handlers to find
# Start pump in background
pump_task = asyncio.create_task(pump.run())
try:
await console.run()
finally:
pump_task.cancel()
try:
await pump_task
except asyncio.CancelledError:
pass
await pump.shutdown()
def main():
args = sys.argv[1:]
use_simple = "--simple" in args
if use_simple:
args.remove("--simple")
config_path = args[0] if args else "config/organism.yaml"
if not Path(config_path).exists():
print(f"Config not found: {config_path}")
sys.exit(1)
try:
asyncio.run(run_organism(config_path, use_simple=use_simple))
except KeyboardInterrupt:
print("\nInterrupted")
if __name__ == "__main__":
main()