Files
bootstrap/bin/mosaic-bootstrap-repo

93 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
TARGET_DIR="$(pwd)"
FORCE=0
while [[ $# -gt 0 ]]; do
case "$1" in
--force)
FORCE=1
shift
;;
*)
TARGET_DIR="$1"
shift
;;
esac
done
if [[ ! -d "$TARGET_DIR" ]]; then
echo "[mosaic] Target directory does not exist: $TARGET_DIR" >&2
exit 1
fi
MOSAIC_HOME="${MOSAIC_HOME:-$HOME/.mosaic}"
TEMPLATE_ROOT="$MOSAIC_HOME/templates/repo"
if [[ ! -d "$TEMPLATE_ROOT" ]]; then
echo "[mosaic] Missing templates at $TEMPLATE_ROOT" >&2
echo "[mosaic] Install or refresh framework: ~/.mosaic/install.sh" >&2
exit 1
fi
mkdir -p "$TARGET_DIR/.mosaic" "$TARGET_DIR/scripts/agent"
copy_file() {
local src="$1"
local dst="$2"
if [[ -f "$dst" && "$FORCE" -ne 1 ]]; then
echo "[mosaic] Skip existing: $dst"
return
fi
cp "$src" "$dst"
echo "[mosaic] Wrote: $dst"
}
copy_file "$TEMPLATE_ROOT/.mosaic/README.md" "$TARGET_DIR/.mosaic/README.md"
copy_file "$TEMPLATE_ROOT/.mosaic/repo-hooks.sh" "$TARGET_DIR/.mosaic/repo-hooks.sh"
for file in "$TEMPLATE_ROOT"/scripts/agent/*.sh; do
base="$(basename "$file")"
copy_file "$file" "$TARGET_DIR/scripts/agent/$base"
chmod +x "$TARGET_DIR/scripts/agent/$base"
done
if [[ ! -f "$TARGET_DIR/AGENTS.md" ]]; then
cat > "$TARGET_DIR/AGENTS.md" <<'AGENTS_EOF'
# Agent Guidelines
## Standards Load Order
1. `~/.mosaic/STANDARDS.md`
2. `AGENTS.md` (this file)
3. `.mosaic/repo-hooks.sh`
## Session Lifecycle
```bash
bash scripts/agent/session-start.sh
bash scripts/agent/critical.sh
bash scripts/agent/session-end.sh
```
## Shared Rails
- Quality and orchestration guides: `~/.mosaic/guides/`
- Shared automation rails: `~/.mosaic/rails/`
## Repo-Specific Notes
- Add project constraints and workflows here.
- Implement hook functions in `.mosaic/repo-hooks.sh`.
AGENTS_EOF
echo "[mosaic] Wrote: $TARGET_DIR/AGENTS.md"
else
echo "[mosaic] AGENTS.md exists; add standards load order if missing"
fi
echo "[mosaic] Repo bootstrap complete: $TARGET_DIR"
echo "[mosaic] Next: edit $TARGET_DIR/.mosaic/repo-hooks.sh with project workflows"