diff --git a/documentation/plans/plan-promptDistribution.md b/documentation/plans/plan-promptDistribution.md new file mode 100644 index 0000000..9c5385d --- /dev/null +++ b/documentation/plans/plan-promptDistribution.md @@ -0,0 +1,406 @@ +# Centralized Prompt Repository with Automated Distribution + +## Goal + +Create a centralized "llm-prompts" repository that automatically distributes prompt files, instructions, and knowledge bases to multiple consumer repositories whenever changes are pushed. + +## Architecture Overview + +```mermaid +graph LR + A[llm-prompts repo
Central Source] -->|Push| B[Gitea Webhook] + B -->|Trigger| C[Sync Script] + C -->|Git Pull & Copy| D[homelab repo] + C -->|Git Pull & Copy| E[repo-2] + C -->|Git Pull & Copy| F[repo-N] + + style A fill:#ff6b6b,color:#fff + style C fill:#326ce5,color:#fff +``` + +--- + +## Option 1: Gitea Webhook + Sync Script (Recommended) + +**Best for:** Your current stack (Gitea, automation-friendly) + +### Step 1: Create Central Repository + +```bash +# On Gitea: Create new repo "llm-prompts" +# URL: https://git.castaldifamily.com/nathan/llm-prompts + +# Initialize locally +mkdir ~/llm-prompts +cd ~/llm-prompts + +# Move your existing prompts +cp -r ~/homelab/.github/prompts ./ +cp -r ~/homelab/.github/instructions ./ +cp -r ~/homelab/.github/knowledge ./ + +git init +git add . +git commit -m "feat: initialize centralized prompt library" +git remote add origin https://git.castaldifamily.com/nathan/llm-prompts.git +git push -u origin main +``` + +### Step 2: Create Sync Script + +Create `/mnt/appdata/scripts/sync-prompts.sh` on Heimdall: + +```bash +#!/bin/bash +# Sync Script: Distribute prompts from central repo to consumers +set -euo pipefail + +CENTRAL_REPO="/mnt/appdata/git-repos/llm-prompts" +TARGET_REPOS=( + "/mnt/appdata/git-repos/homelab" + "/mnt/appdata/git-repos/another-project" + # Add more repos here +) + +# Pull latest from central repo +cd "$CENTRAL_REPO" +git pull origin main + +# Sync to each target repo +for REPO in "${TARGET_REPOS[@]}"; do + echo "Syncing to $REPO..." + + # Create .github directory if it doesn't exist + mkdir -p "$REPO/.github" + + # Copy directories (overwrite) + rsync -av --delete "$CENTRAL_REPO/prompts/" "$REPO/.github/prompts/" + rsync -av --delete "$CENTRAL_REPO/instructions/" "$REPO/.github/instructions/" + rsync -av --delete "$CENTRAL_REPO/knowledge/" "$REPO/.github/knowledge/" + + # Auto-commit in target repo + cd "$REPO" + if [[ -n $(git status --porcelain) ]]; then + git add .github/ + git commit -m "chore: sync prompts from llm-prompts@$(cd $CENTRAL_REPO && git rev-parse --short HEAD)" + git push origin main + fi +done + +echo "✅ Sync complete" +``` + +### Step 3: Configure Gitea Webhook + +1. **In Gitea UI** → llm-prompts repo → Settings → Webhooks +2. **Add Webhook:** + - Target URL: `http://script-runner:8080/sync-prompts` (see Option A or B below) + - Content Type: `application/json` + - Trigger: `Push events` only + - Active: ✅ + +### Step 4: Choose Webhook Receiver + +**Option A: Simple HTTP Server (Quick)** + +```bash +# On Heimdall, install webhook listener +mkdir -p /mnt/appdata/webhook-listener +cat > /mnt/appdata/webhook-listener/docker-compose.yaml < /mnt/appdata/webhook-listener/hooks.json < >(tee -a /var/log/prompt-sync.log) + +# Check last sync status +cd /mnt/appdata/git-repos/homelab +git log --oneline | grep "sync prompts" +``` + +### Common Issues + +**Issue: Sync script fails with "permission denied"** +- Check file ownership: `ls -la /mnt/appdata/scripts/sync-prompts.sh` +- Verify execute permission: `chmod +x /mnt/appdata/scripts/sync-prompts.sh` +- Check Git authentication: `ssh -T git@git.castaldifamily.com` + +**Issue: Webhook not triggering** +- Verify webhook URL is accessible from Gitea +- Check Gitea webhook delivery logs +- Test webhook manually: `curl -X POST http://webhook-listener:9000/hooks/sync-prompts` + +**Issue: Merge conflicts in target repos** +- Never manually edit `.github/prompts/` in target repos +- If conflict occurs, revert local changes: `git checkout HEAD -- .github/prompts/` +- Re-run sync manually + +--- + +## Alternative: GitHub Actions Style Workflow + +If you want more advanced features (testing, validation, notifications): + +```yaml +# In llm-prompts repo: .gitea/workflows/sync.yaml +name: Sync Prompts to Consumer Repos + +on: + push: + branches: + - main + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Validate prompt structure + run: | + # Add validation logic + + sync: + needs: validate + runs-on: ubuntu-latest + steps: + - name: Sync to homelab + run: | + # Clone target repo + # Copy files + # Push changes +``` + +**Note:** Gitea Actions support varies by version. Verify your Gitea version supports Actions before implementing. + +--- + +## Next Steps + +1. **Decision Point:** Choose Option 1, 2, or 3 based on your priorities +2. **Create Infrastructure:** Set up webhook listener or NFS share +3. **Test in Isolation:** Start with single target repo +4. **Document Process:** Add to SOPs when stable +5. **Scale Gradually:** Add repos incrementally + +--- + +## Related Documentation + +- Gitea Webhooks: https://docs.gitea.io/en-us/webhooks/ +- Webhook Tool: https://github.com/adnanh/webhook +- Git Submodules: https://git-scm.com/book/en/v2/Git-Tools-Submodules + +--- + +## Future Enhancements + +- **Selective Sync:** Only sync specific directories based on target repo config +- **Version Pinning:** Allow target repos to specify prompt version +- **Rollback Mechanism:** Automatic rollback if validation fails in target +- **Notification System:** Slack/Discord notifications on sync completion +- **Dry-Run Mode:** Preview changes before applying +- **Conflict Resolution:** Automatic strategies for handling local modifications