refactor: AGENTS.md is the single source of truth for all runtimes

- Create ~/.config/mosaic/AGENTS.md as the canonical universal agent config
- Runtime adapters (CLAUDE.md, opencode/AGENTS.md, codex/instructions.md) are
  now thin pointers that say "READ ~/.config/mosaic/AGENTS.md"
- mosaic claude: injects AGENTS.md via --append-system-prompt
- mosaic opencode/codex: copies AGENTS.md to runtime config path before launch
- mosaic-link-runtime-assets: pushes thin pointers for direct launch fallback

AGENTS.md is runtime-agnostic. All runtimes get the same standards.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jason Woltje
2026-02-19 13:24:12 -06:00
parent 0b7b823911
commit 3f2ba89db2
8 changed files with 723 additions and 679 deletions

View File

@@ -3,10 +3,13 @@ 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.
#
# Usage:
# mosaic claude [args...] Launch Claude Code with SOUL.md injected
# mosaic opencode [args...] Launch OpenCode
# mosaic codex [args...] Launch Codex
# 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 init [args...] Generate SOUL.md interactively
# mosaic doctor [args...] Health audit
# mosaic sync [args...] Sync skills
@@ -22,9 +25,9 @@ mosaic $VERSION — Unified agent launcher
Usage: mosaic <command> [args...]
Agent Launchers:
claude [args...] Launch Claude Code with SOUL.md injected
opencode [args...] Launch OpenCode
codex [args...] Launch Codex
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
Management:
init [args...] Generate SOUL.md (agent identity contract)
@@ -49,6 +52,14 @@ check_mosaic_home() {
fi
}
check_agents_md() {
if [[ ! -f "$MOSAIC_HOME/AGENTS.md" ]]; then
echo "[mosaic] ERROR: ~/.config/mosaic/AGENTS.md not found." >&2
echo "[mosaic] Re-run the installer: cd ~/src/mosaic-bootstrap && bash install.sh" >&2
exit 1
fi
}
check_soul() {
if [[ ! -f "$MOSAIC_HOME/SOUL.md" ]]; then
echo "[mosaic] SOUL.md not found. Running mosaic init..."
@@ -65,31 +76,51 @@ 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.
ensure_runtime_config() {
local src="$MOSAIC_HOME/AGENTS.md"
local dst="$1"
mkdir -p "$(dirname "$dst")"
if ! cmp -s "$src" "$dst" 2>/dev/null; then
cp "$src" "$dst"
fi
}
# Launcher functions
launch_claude() {
check_mosaic_home
check_agents_md
check_soul
check_runtime "claude"
# SOUL.md is loaded via ~/.claude/CLAUDE.md directive (pushed by mosaic-link-runtime-assets)
# Claude supports --append-system-prompt for direct injection
local agents_content
agents_content="$(cat "$MOSAIC_HOME/AGENTS.md")"
echo "[mosaic] Launching Claude Code..."
exec claude "$@"
exec claude --append-system-prompt "$agents_content" "$@"
}
launch_opencode() {
check_mosaic_home
check_agents_md
check_soul
check_runtime "opencode"
# OpenCode reads from ~/.config/opencode/AGENTS.md — copy canonical version there
ensure_runtime_config "$HOME/.config/opencode/AGENTS.md"
echo "[mosaic] Launching OpenCode..."
exec opencode "$@"
}
launch_codex() {
check_mosaic_home
check_agents_md
check_soul
check_runtime "codex"
# Codex reads from ~/.codex/instructions.md — copy canonical version there
ensure_runtime_config "$HOME/.codex/instructions.md"
echo "[mosaic] Launching Codex..."
exec codex "$@"
}