Step 1 of 5
Back up the VPS library
Treat the existing VPS library as the initial source of truth. Make a timestamped copy before adding Git metadata.
test -d ~/.agents
backup_dir="$HOME/.agents.backup.$(date +%Y%m%d-%H%M%S)"
cp -a ~/.agents "$backup_dir"
echo "Backup: $backup_dir"Step 2 of 5
Create the private Git source
Authenticate GitHub CLI over HTTPS first. Its credential helper remains available to the background timer without an SSH agent.
gh auth status || gh auth login
gh config set git_protocol https
gh auth setup-gitThen initialize ~/.agents directly so the repository contains the library contents—not an extra wrapper directory. Exclude credentials before the first commit.
cd ~/.agents
test -d .git || git init -b main
printf '%s
' '.env' '.env.*' '*.key' '*.pem' '*token*' '*secret*' >> .gitignore
git config user.name "YOUR_NAME"
git config user.email "YOUR_EMAIL"
git add -A
git commit -m "chore: initialize shared agent skills"
gh repo create stackenv-skills --private --source=. --remote=origin --pushIf the private repository already exists, replace the final command with git remote add origin https://github.com/YOUR_ACCOUNT/stackenv-skills.git and git push -u origin main.
Step 3 of 5
Install the sync worker
The worker commits local changes, rebases on the remote branch, and pushes the resulting state. A directory lock prevents overlapping executions.
mkdir -p ~/.local/bin
curl -fsSL https://stackend.codelynx.dev/skills-sync.sh -o ~/.local/bin/stackenv-skills-sync
chmod 700 ~/.local/bin/stackenv-skills-sync
~/.local/bin/stackenv-skills-syncStep 4 of 5
Schedule it with systemd
A user timer runs the worker after boot and every two minutes. It remains independent from the StackEnv dashboard process.
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/stackenv-skills-sync.service <<'EOF'
[Unit]
Description=Synchronize StackEnv agent skills
After=network-online.target
[Service]
Type=oneshot
ExecStart=%h/.local/bin/stackenv-skills-sync
Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin
NoNewPrivileges=true
PrivateTmp=true
EOF
cat > ~/.config/systemd/user/stackenv-skills-sync.timer <<'EOF'
[Unit]
Description=Run StackEnv skills synchronization
[Timer]
OnBootSec=45s
OnUnitActiveSec=2min
Persistent=true
[Install]
WantedBy=timers.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now stackenv-skills-sync.timer
sudo loginctl enable-linger "$USER"Step 5 of 5
Verify the VPS side
Trigger one execution, inspect its log, and confirm that the checkout is clean and tracking origin/main.
systemctl --user start stackenv-skills-sync.service
journalctl --user -u stackenv-skills-sync.service -n 30 --no-pager
git -C ~/.agents status --short --branch
systemctl --user list-timers stackenv-skills-sync.timerIf Git reports a conflict
The worker stops and will not stage anything else while a rebase, merge, or unresolved file exists. Inspect the files and choose one path:
git -C ~/.agents status
# Keep the rebase and resolve each reported file
git -C ~/.agents add PATH_TO_RESOLVED_FILE
git -C ~/.agents rebase --continue
~/.local/bin/stackenv-skills-sync
# Or return to the exact state before the pull
git -C ~/.agents rebase --abort