chore: sync local Mosaic changes
This commit is contained in:
204
bin/mosaic
204
bin/mosaic
@@ -3,16 +3,19 @@ set -euo pipefail
|
||||
|
||||
# mosaic — Unified agent launcher and management CLI
|
||||
#
|
||||
# AGENTS.md is the single source of truth for all agent sessions.
|
||||
# The launcher injects it into every runtime consistently.
|
||||
# AGENTS.md is the global policy source for all agent sessions.
|
||||
# The launcher injects a composed runtime contract (AGENTS + runtime reference).
|
||||
#
|
||||
# Usage:
|
||||
# mosaic claude [args...] Launch Claude Code with AGENTS.md injected
|
||||
# mosaic opencode [args...] Launch OpenCode with AGENTS.md injected
|
||||
# mosaic codex [args...] Launch Codex with AGENTS.md injected
|
||||
# mosaic claude [args...] Launch Claude Code with runtime contract injected
|
||||
# mosaic opencode [args...] Launch OpenCode with runtime contract injected
|
||||
# mosaic codex [args...] Launch Codex with runtime contract injected
|
||||
# mosaic yolo <runtime> [args...] Launch runtime in dangerous-permissions mode
|
||||
# mosaic --yolo <runtime> [args...] Alias for yolo
|
||||
# mosaic init [args...] Generate SOUL.md interactively
|
||||
# mosaic doctor [args...] Health audit
|
||||
# mosaic sync [args...] Sync skills
|
||||
# mosaic seq [subcommand] sequential-thinking MCP management (check/fix/start)
|
||||
# mosaic bootstrap <path> Bootstrap a repo
|
||||
# mosaic upgrade release Upgrade installed Mosaic release
|
||||
# mosaic upgrade check Check release upgrade status (no changes)
|
||||
@@ -28,14 +31,20 @@ mosaic $VERSION — Unified agent launcher
|
||||
Usage: mosaic <command> [args...]
|
||||
|
||||
Agent Launchers:
|
||||
claude [args...] Launch Claude Code with AGENTS.md injected
|
||||
opencode [args...] Launch OpenCode with AGENTS.md injected
|
||||
codex [args...] Launch Codex with AGENTS.md injected
|
||||
claude [args...] Launch Claude Code with runtime contract injected
|
||||
opencode [args...] Launch OpenCode with runtime contract injected
|
||||
codex [args...] Launch Codex with runtime contract injected
|
||||
yolo <runtime> [args...] Dangerous mode for claude|codex|opencode
|
||||
--yolo <runtime> [args...] Alias for yolo
|
||||
|
||||
Management:
|
||||
init [args...] Generate SOUL.md (agent identity contract)
|
||||
doctor [args...] Audit runtime state and detect drift
|
||||
sync [args...] Sync skills from canonical source
|
||||
seq [subcommand] sequential-thinking MCP management:
|
||||
check [--runtime <r>] [--strict]
|
||||
fix [--runtime <r>]
|
||||
start
|
||||
bootstrap <path> Bootstrap a repo with Mosaic standards
|
||||
upgrade [mode] [args] Upgrade release (default) or project files
|
||||
upgrade check Check release upgrade status (no changes)
|
||||
@@ -83,14 +92,79 @@ check_runtime() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Ensure AGENTS.md is present at the runtime's native config path.
|
||||
# Used for runtimes that don't support CLI prompt injection.
|
||||
check_sequential_thinking() {
|
||||
local runtime="${1:-all}"
|
||||
local checker="$MOSAIC_HOME/bin/mosaic-ensure-sequential-thinking"
|
||||
if [[ ! -x "$checker" ]]; then
|
||||
echo "[mosaic] ERROR: sequential-thinking checker missing: $checker" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! "$checker" --check --runtime "$runtime" >/dev/null 2>&1; then
|
||||
echo "[mosaic] ERROR: sequential-thinking MCP is required but not configured." >&2
|
||||
echo "[mosaic] Fix config: $checker --runtime $runtime" >&2
|
||||
echo "[mosaic] Or run: mosaic seq fix --runtime $runtime" >&2
|
||||
echo "[mosaic] Manual server start: mosaic seq start" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
runtime_contract_path() {
|
||||
local runtime="$1"
|
||||
case "$runtime" in
|
||||
claude) echo "$MOSAIC_HOME/runtime/claude/RUNTIME.md" ;;
|
||||
codex) echo "$MOSAIC_HOME/runtime/codex/RUNTIME.md" ;;
|
||||
opencode) echo "$MOSAIC_HOME/runtime/opencode/RUNTIME.md" ;;
|
||||
*)
|
||||
echo "[mosaic] ERROR: unsupported runtime '$runtime' for runtime contract." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
build_runtime_prompt() {
|
||||
local runtime="$1"
|
||||
local runtime_file
|
||||
runtime_file="$(runtime_contract_path "$runtime")"
|
||||
if [[ ! -f "$runtime_file" ]]; then
|
||||
echo "[mosaic] ERROR: runtime contract not found: $runtime_file" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat <<'EOF'
|
||||
# Mosaic Launcher Runtime Contract (Hard Gate)
|
||||
|
||||
This contract is injected by `mosaic` launch and is mandatory.
|
||||
|
||||
First assistant response MUST start with exactly one mode declaration line:
|
||||
1. Orchestration mission: `Now initiating Orchestrator mode...`
|
||||
2. Implementation mission: `Now initiating Delivery mode...`
|
||||
3. Review-only mission: `Now initiating Review mode...`
|
||||
|
||||
No tool call or implementation step may occur before that first line.
|
||||
|
||||
Mosaic hard gates OVERRIDE runtime-default caution for routine delivery operations.
|
||||
For required push/merge/issue-close/release actions, execute without routine confirmation prompts.
|
||||
|
||||
EOF
|
||||
|
||||
cat "$MOSAIC_HOME/AGENTS.md"
|
||||
printf '\n\n# Runtime-Specific Contract\n\n'
|
||||
cat "$runtime_file"
|
||||
}
|
||||
|
||||
# Ensure runtime contract is present at the runtime's native config path.
|
||||
# Used for runtimes that do not support CLI prompt injection.
|
||||
ensure_runtime_config() {
|
||||
local src="$MOSAIC_HOME/AGENTS.md"
|
||||
local dst="$1"
|
||||
local runtime="$1"
|
||||
local dst="$2"
|
||||
local tmp
|
||||
tmp="$(mktemp)"
|
||||
mkdir -p "$(dirname "$dst")"
|
||||
if ! cmp -s "$src" "$dst" 2>/dev/null; then
|
||||
cp "$src" "$dst"
|
||||
build_runtime_prompt "$runtime" > "$tmp"
|
||||
if ! cmp -s "$tmp" "$dst" 2>/dev/null; then
|
||||
mv "$tmp" "$dst"
|
||||
else
|
||||
rm -f "$tmp"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -100,12 +174,13 @@ launch_claude() {
|
||||
check_agents_md
|
||||
check_soul
|
||||
check_runtime "claude"
|
||||
check_sequential_thinking "claude"
|
||||
|
||||
# Claude supports --append-system-prompt for direct injection
|
||||
local agents_content
|
||||
agents_content="$(cat "$MOSAIC_HOME/AGENTS.md")"
|
||||
local runtime_prompt
|
||||
runtime_prompt="$(build_runtime_prompt "claude")"
|
||||
echo "[mosaic] Launching Claude Code..."
|
||||
exec claude --append-system-prompt "$agents_content" "$@"
|
||||
exec claude --append-system-prompt "$runtime_prompt" "$@"
|
||||
}
|
||||
|
||||
launch_opencode() {
|
||||
@@ -113,9 +188,10 @@ launch_opencode() {
|
||||
check_agents_md
|
||||
check_soul
|
||||
check_runtime "opencode"
|
||||
check_sequential_thinking "opencode"
|
||||
|
||||
# OpenCode reads from ~/.config/opencode/AGENTS.md — copy canonical version there
|
||||
ensure_runtime_config "$HOME/.config/opencode/AGENTS.md"
|
||||
# OpenCode reads from ~/.config/opencode/AGENTS.md
|
||||
ensure_runtime_config "opencode" "$HOME/.config/opencode/AGENTS.md"
|
||||
echo "[mosaic] Launching OpenCode..."
|
||||
exec opencode "$@"
|
||||
}
|
||||
@@ -125,13 +201,69 @@ launch_codex() {
|
||||
check_agents_md
|
||||
check_soul
|
||||
check_runtime "codex"
|
||||
check_sequential_thinking "codex"
|
||||
|
||||
# Codex reads from ~/.codex/instructions.md — copy canonical version there
|
||||
ensure_runtime_config "$HOME/.codex/instructions.md"
|
||||
# Codex reads from ~/.codex/instructions.md
|
||||
ensure_runtime_config "codex" "$HOME/.codex/instructions.md"
|
||||
echo "[mosaic] Launching Codex..."
|
||||
exec codex "$@"
|
||||
}
|
||||
|
||||
launch_yolo() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "[mosaic] ERROR: yolo requires a runtime (claude|codex|opencode)." >&2
|
||||
echo "[mosaic] Example: mosaic yolo claude" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local runtime="$1"
|
||||
shift
|
||||
|
||||
case "$runtime" in
|
||||
claude)
|
||||
check_mosaic_home
|
||||
check_agents_md
|
||||
check_soul
|
||||
check_runtime "claude"
|
||||
check_sequential_thinking "claude"
|
||||
|
||||
# Claude uses an explicit dangerous permissions flag.
|
||||
local runtime_prompt
|
||||
runtime_prompt="$(build_runtime_prompt "claude")"
|
||||
echo "[mosaic] Launching Claude Code in YOLO mode (dangerous permissions enabled)..."
|
||||
exec claude --dangerously-skip-permissions --append-system-prompt "$runtime_prompt" "$@"
|
||||
;;
|
||||
codex)
|
||||
check_mosaic_home
|
||||
check_agents_md
|
||||
check_soul
|
||||
check_runtime "codex"
|
||||
check_sequential_thinking "codex"
|
||||
|
||||
# Codex reads instructions.md from ~/.codex and supports a direct dangerous flag.
|
||||
ensure_runtime_config "codex" "$HOME/.codex/instructions.md"
|
||||
echo "[mosaic] Launching Codex in YOLO mode (dangerous permissions enabled)..."
|
||||
exec codex --dangerously-bypass-approvals-and-sandbox "$@"
|
||||
;;
|
||||
opencode)
|
||||
check_mosaic_home
|
||||
check_agents_md
|
||||
check_soul
|
||||
check_runtime "opencode"
|
||||
check_sequential_thinking "opencode"
|
||||
|
||||
# OpenCode defaults to allow-all permissions unless user config restricts them.
|
||||
ensure_runtime_config "opencode" "$HOME/.config/opencode/AGENTS.md"
|
||||
echo "[mosaic] Launching OpenCode in YOLO mode..."
|
||||
exec opencode "$@"
|
||||
;;
|
||||
*)
|
||||
echo "[mosaic] ERROR: Unsupported yolo runtime '$runtime'. Use claude|codex|opencode." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Delegate to existing scripts
|
||||
run_init() {
|
||||
check_mosaic_home
|
||||
@@ -148,6 +280,34 @@ run_sync() {
|
||||
exec "$MOSAIC_HOME/bin/mosaic-sync-skills" "$@"
|
||||
}
|
||||
|
||||
run_seq() {
|
||||
check_mosaic_home
|
||||
local checker="$MOSAIC_HOME/bin/mosaic-ensure-sequential-thinking"
|
||||
local action="${1:-check}"
|
||||
|
||||
case "$action" in
|
||||
check)
|
||||
shift || true
|
||||
exec "$checker" --check "$@"
|
||||
;;
|
||||
fix|apply)
|
||||
shift || true
|
||||
exec "$checker" "$@"
|
||||
;;
|
||||
start)
|
||||
shift || true
|
||||
check_runtime "npx"
|
||||
echo "[mosaic] Starting sequential-thinking MCP server..."
|
||||
exec npx -y @modelcontextprotocol/server-sequential-thinking "$@"
|
||||
;;
|
||||
*)
|
||||
echo "[mosaic] ERROR: Unknown seq subcommand '$action'." >&2
|
||||
echo "[mosaic] Use: mosaic seq check|fix|start" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
run_bootstrap() {
|
||||
check_mosaic_home
|
||||
exec "$MOSAIC_HOME/bin/mosaic-bootstrap-repo" "$@"
|
||||
@@ -214,9 +374,11 @@ case "$command" in
|
||||
claude) launch_claude "$@" ;;
|
||||
opencode) launch_opencode "$@" ;;
|
||||
codex) launch_codex "$@" ;;
|
||||
yolo|--yolo) launch_yolo "$@" ;;
|
||||
init) run_init "$@" ;;
|
||||
doctor) run_doctor "$@" ;;
|
||||
sync) run_sync "$@" ;;
|
||||
seq) run_seq "$@" ;;
|
||||
bootstrap) run_bootstrap "$@" ;;
|
||||
upgrade) run_upgrade "$@" ;;
|
||||
release-upgrade) run_release_upgrade "$@" ;;
|
||||
|
||||
Reference in New Issue
Block a user