AgentSkillsCN

vanna-env-sync

通过查找最新版本的 .env 和 .env.local 文件,并将其同步复制到所有相关位置,实现 vanna-connect 项目克隆与工作树之间的 .env 和 .env.local 文件同步。当需要在多个 vanna-connect 仓库间同步环境文件、确保配置变更能够及时传播,或用户提及同步环境变量、环境文件、.env 或 .env.local 文件时,可使用此功能。

SKILL.md
--- frontmatter
name: vanna-env-sync
description: Syncs .env and .env.local files across vanna-connect project clones and worktrees by finding the most recent files and copying them to all locations. Use when environment files need to be synchronized across multiple vanna-connect repositories, when setup changes need to propagate, or when user mentions syncing envs, environment files, .env, or .env.local files.
allowed-tools:
  - Bash
  - Read

Vanna Environment Sync

Synchronizes .env and .env.local files across all vanna-connect project clones and worktrees in ~/code/vanna.

Quick Start

Run this skill to:

  1. Find all vanna-connect projects and worktrees
  2. Identify the most recent .env and .env.local files
  3. Copy them to all other locations (projects and worktrees)

The skill syncs these files:

Source files (.env) - contain secrets and configuration:

  • typescript/apps/cli/.env
  • typescript/apps/web/.env
  • typescript/apps/admin/.env
  • typescript/servers/api-service/.env
  • typescript/servers/automations-service/.env
  • typescript/servers/adt-service/.env
  • typescript/domains/adt/.env
  • typescript/domains/fhirdb/.env

Generated files (.env.local) - auto-generated by setup:

  • typescript/servers/api-service/.env.local
  • typescript/servers/automations-service/.env.local
  • typescript/servers/adt-service/.env.local
  • typescript/apps/cli/.env.local
  • typescript/apps/admin/.env.local
  • typescript/apps/web/.env.local

Instructions

Follow this workflow:

Step 1: Find All Projects and Worktrees

bash
# Find regular project directories
echo "Regular projects:"
for dir in ~/code/vanna/*/; do
  if [ -d "${dir}typescript" ]; then
    echo "  $(basename "$dir")"
  fi
done

echo ""
echo "Worktree projects:"
# Find worktree directories
for worktree_dir in ~/code/vanna/*/.worktrees/*/; do
  if [ -d "${worktree_dir}typescript" ]; then
    parent=$(basename "$(dirname "$(dirname "$worktree_dir")")")
    worktree=$(basename "$worktree_dir")
    echo "  $parent/.worktrees/$worktree"
  fi
done

This identifies:

  • All directories in ~/code/vanna/*/ that contain a typescript subdirectory
  • All worktree directories in ~/code/vanna/*/.worktrees/*/ that contain a typescript subdirectory

Step 2: Find Most Recent Files

bash
echo "Checking .env files (source of truth):"
find ~/code/vanna -name ".env" -path "*/typescript/*" -type f -exec ls -lt {} + 2>/dev/null | head -20

echo ""
echo "Checking .env.local files (generated):"
find ~/code/vanna -name ".env.local" -path "*/typescript/*" -type f -exec ls -lt {} + 2>/dev/null | head -20

Look for the files with the most recent modification timestamps. Prioritize .env files as the source of truth. The source project will be the one with the newest complete set of files.

Step 3: Copy Files to All Projects and Worktrees

Use this script template:

bash
#!/bin/bash
# Source directory with the most recent env files
SOURCE_DIR="/Users/juan.caicedo/code/vanna/[SOURCE_PATH]/typescript"

# Target locations (excluding the source)
# Can be either:
#   - Regular projects: "project-name"
#   - Worktrees: "project-name/.worktrees/worktree-name"
TARGETS=(
  # List all locations except the source
)

# .env files (source of truth - contain secrets and config)
ENV_FILES=(
  "apps/cli/.env"
  "apps/web/.env"
  "apps/admin/.env"
  "servers/api-service/.env"
  "servers/automations-service/.env"
  "servers/adt-service/.env"
  "domains/adt/.env"
  "domains/fhirdb/.env"
)

# .env.local files (generated files)
ENV_LOCAL_FILES=(
  "servers/api-service/.env.local"
  "servers/automations-service/.env.local"
  "servers/adt-service/.env.local"
  "apps/cli/.env.local"
  "apps/admin/.env.local"
  "apps/web/.env.local"
)

# Copy files to each location
for target in "${TARGETS[@]}"; do
  echo "Copying to $target..."

  # Copy .env files
  for file in "${ENV_FILES[@]}"; do
    SOURCE_FILE="$SOURCE_DIR/$file"
    TARGET_FILE="/Users/juan.caicedo/code/vanna/$target/typescript/$file"

    if [ -f "$SOURCE_FILE" ]; then
      mkdir -p "$(dirname "$TARGET_FILE")"
      cp "$SOURCE_FILE" "$TARGET_FILE"
      echo "  ✓ Copied $file"
    fi
  done

  # Copy .env.local files
  for file in "${ENV_LOCAL_FILES[@]}"; do
    SOURCE_FILE="$SOURCE_DIR/$file"
    TARGET_FILE="/Users/juan.caicedo/code/vanna/$target/typescript/$file"

    if [ -f "$SOURCE_FILE" ]; then
      mkdir -p "$(dirname "$TARGET_FILE")"
      cp "$SOURCE_FILE" "$TARGET_FILE"
      echo "  ✓ Copied $file"
    fi
  done

  echo ""
done

echo "Done! Verifying copied files..."
echo ""
echo ".env files:"
find ~/code/vanna -name ".env" -path "*/typescript/*" -type f -exec ls -lt {} + 2>/dev/null | head -10
echo ""
echo ".env.local files:"
find ~/code/vanna -name ".env.local" -path "*/typescript/*" -type f -exec ls -lt {} + 2>/dev/null | head -10

Step 4: Report Results

After copying, show:

  • Source location used (project or worktree)
  • Number of .env files copied (8 files)
  • Number of .env.local files copied (6 files)
  • List of target locations updated (projects and worktrees)
  • Verification of new timestamps

Examples

Example 1: Sync from most recent project

Input: User runs /vanna-env-sync

Process:

  1. Find locations: burrito-vanna-connect-2, taco-vanna-connect, vanna-connect, vanna-connect/.worktrees/feature-branch, etc.
  2. Identify most recent: burrito-vanna-connect-2 (Feb 13 10:30)
  3. Copy 8 .env files and 6 .env.local files to all other locations

Output:

code
✓ Synced environment files from burrito-vanna-connect-2

.env files (8):
- apps/cli/.env (contains EMAIL, secrets, config)
- apps/web/.env
- apps/admin/.env
- servers/api-service/.env
- servers/automations-service/.env
- servers/adt-service/.env
- domains/adt/.env
- domains/fhirdb/.env

.env.local files (6):
- servers/api-service/.env.local
- servers/automations-service/.env.local
- servers/adt-service/.env.local
- apps/cli/.env.local
- apps/admin/.env.local
- apps/web/.env.local

To locations:
- taco-vanna-connect
- vanna-connect
- vanna-connect-2
- vanna-connect/.worktrees/FT-257
- vanna-connect-exploration
- vanna-connect-FT-654
- taco-backup

All files updated to Feb 13 10:45

Example 2: No files found

If no env files exist, inform the user:

code
No .env or .env.local files found in any vanna-connect projects.
Run the setup.sh script to generate them first.

Guidelines

  • Always identify the most recent files by timestamp (across both regular projects and worktrees)
  • Exclude the source location from the copy targets
  • Create target directories if they don't exist
  • Preserve file permissions when copying
  • Show verification of timestamps after copying
  • Handle missing files gracefully with clear messages
  • Use absolute paths to avoid directory confusion
  • Treat worktrees and regular projects equally when finding the most recent files

Common Scenarios

After running localSetup: The skill detects which location (project or worktree) has the newest setup and propagates it to all others.

After manual edits: If you manually update .env.local in one location, run this to sync across all locations.

Before switching projects or worktrees: Ensure all locations have consistent environment configuration before changing your working directory.

Working with git worktrees: When using git worktrees for parallel development, this ensures all worktrees have the same environment configuration as the main project.

Notes

About .env files:

  • .env files are the source of truth
  • They contain secrets (from 1Password), email, and configuration
  • Created by setup.sh using op inject from .env.example files
  • Manual edits to .env are persistent

About .env.local files:

  • .env.local files are auto-generated from .env files
  • Created by pnpm run cli data-management local-setup and similar commands
  • Manual edits will be lost on next setup run
  • For persistent changes, edit .env instead of .env.local

Sync strategy:

  • The skill syncs both .env and .env.local files
  • It prioritizes locations with the most recent .env files
  • Since .env.local can be regenerated from .env, having .env files is critical