#!/usr/bin/env bash # Launch an interactive (TUI) Mosaic agent in its container. # # Usage: # scripts/agent.sh [--mission ] [--workspace ] # [--session ] [--tools ] # # The agent receives the four immutable contracts (constitution, standards, # SOUL, USER) plus its own identity and optional mission directives as its # system prompt, a persistent named session, and - if declared - a # workspace and tool capabilities. The TUI opens clean; you drive. # # This is the Mosaic alternative to launching vanilla pi: same engine, # governed context. set -euo pipefail cd "$(dirname "$0")/.." # shellcheck source=common.sh source scripts/common.sh NAME="" MISSION="" WORKSPACE="" SESSION="" TOOLS="" while [ $# -gt 0 ]; do case "$1" in --mission) MISSION="${2:?}"; shift 2 ;; --workspace) WORKSPACE="${2:?}"; shift 2 ;; --session) SESSION="${2:?}"; shift 2 ;; --tools) TOOLS="${2:?}"; shift 2 ;; --help|-h) sed -n '2,12p' "$0"; exit 0 ;; *) NAME="$1"; shift ;; esac done [ -n "$NAME" ] || { echo "agent: usage: scripts/agent.sh [--mission f] [--workspace ws] [--session s] [--tools list]" >&2; exit 4; } case "$NAME" in *[!A-Za-z0-9._-]*|'') echo "agent: invalid agent name" >&2; exit 4;; esac load_config load_release bootstrap_runtime_dir SESSION="${SESSION:-agent-$NAME}" mkdir -p "$MOSAIC_DEV_DIR/sessions/$SESSION" export MOSAIC_SESSION_DIR="/var/lib/mosaic/sessions/$SESSION" export MOSAIC_AGENT_NAME="$NAME" export MOSAIC_INTERACTIVE=1 export MOSAIC_TOOLS="${TOOLS:+$TOOLS}" if [ -n "$MISSION" ]; then [ -r "$MISSION" ] || { echo "agent: mission file not readable: $MISSION" >&2; exit 4; } mkdir -p "$MOSAIC_DEV_DIR/agent-missions" cp "$MISSION" "$MOSAIC_DEV_DIR/agent-missions/$NAME.json" export MOSAIC_MISSION_FILE="/var/lib/mosaic/agent-missions/$NAME.json" fi if [ -n "$WORKSPACE" ]; then case "$WORKSPACE" in *[!A-Za-z0-9._-]*|'') echo "agent: invalid workspace name" >&2; exit 4;; esac mkdir -p "$MOSAIC_DEV_DIR/workspaces/$WORKSPACE" export MOSAIC_WORKSPACE="/var/lib/mosaic/workspaces/$WORKSPACE" fi echo "agent: launching TUI agent '$NAME' (session: $SESSION, adapter: $MOSAIC_ADAPTER, model: $MOSAIC_MODEL)" echo "agent: contracts + $([ -n "$MISSION" ] && echo 'mission' || echo 'no mission') loaded; exit the TUI with /quit" # No -T: the TTY is the point. Ctrl+C twice or /quit exits. exec docker compose run --rm mosaic-agent