#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)" SOURCE_DIR="$(CDPATH='' cd -- "$SCRIPT_DIR/../.." && pwd)" FORCE=0 TARGET_DIR="" usage() { cat <<'EOF' Uso: bash .vscode/automatizadores/bootstrap-workspace.sh /caminho/do/novo-workspace [--force] O script copia a base compartilhavel do workspace DavinTI para um novo diretório: - .claude/agents - .claude/settings.local.json (versao portavel) - .vscode - .github - CLAUDE.md - .mcp.json Tambem cria as pastas: - Andamento - Concluidos - Vitruvio/Documentação - Vitruvio/Documentação/Componentes EOF } log() { printf '%s\n' "$1" } fail() { printf 'Erro: %s\n' "$1" >&2 exit 1 } copy_entry() { local relative_path="$1" local source_path="$SOURCE_DIR/$relative_path" local target_path="$TARGET_DIR/$relative_path" [ -e "$source_path" ] || fail "Origem nao encontrada: $relative_path" mkdir -p "$(dirname "$target_path")" if [ -e "$target_path" ]; then if [ "$FORCE" -ne 1 ]; then fail "Destino ja existe: $relative_path. Use --force para sobrescrever." fi rm -rf "$target_path" fi cp -a "$source_path" "$target_path" log "Copiado: $relative_path" } write_portable_claude_settings() { local target_path="$TARGET_DIR/.claude/settings.local.json" mkdir -p "$(dirname "$target_path")" if [ -e "$target_path" ] && [ "$FORCE" -ne 1 ]; then fail "Destino ja existe: .claude/settings.local.json. Use --force para sobrescrever." fi cat > "$target_path" <<'EOF' { "permissions": { "allow": [ "mcp__oracle-davinti__run_query" ] }, "enableAllProjectMcpServers": true, "enabledMcpjsonServers": [ "oracle-davinti" ] } EOF log "Gerado: .claude/settings.local.json" } cleanup_vscode_mcp_dir() { local mcp_dir="$TARGET_DIR/.vscode/mcp-oracle-davinti" rm -rf "$mcp_dir/node_modules" rm -f "$mcp_dir/.env" } create_base_directories() { mkdir -p "$TARGET_DIR/Andamento" mkdir -p "$TARGET_DIR/Concluidos" mkdir -p "$TARGET_DIR/Vitruvio/Documentação" mkdir -p "$TARGET_DIR/Vitruvio/Documentação/Componentes" log "Criadas pastas base do workspace" } while [ "$#" -gt 0 ]; do case "$1" in --force) FORCE=1 shift ;; -h|--help) usage exit 0 ;; *) if [ -n "$TARGET_DIR" ]; then fail "Argumento inesperado: $1" fi TARGET_DIR="$1" shift ;; esac done [ -n "$TARGET_DIR" ] || { usage exit 1 } TARGET_DIR="$(mkdir -p "$TARGET_DIR" && CDPATH='' cd -- "$TARGET_DIR" && pwd)" [ "$TARGET_DIR" != "$SOURCE_DIR" ] || fail "O destino deve ser diferente da pasta do template." copy_entry ".claude/agents" write_portable_claude_settings copy_entry ".vscode" cleanup_vscode_mcp_dir copy_entry ".github" copy_entry "CLAUDE.md" copy_entry ".mcp.json" create_base_directories log "Workspace base criado em: $TARGET_DIR" log "Proximo passo: copie .vscode/mcp-oracle-davinti/.env.example para .env e ajuste as credenciais locais."