Spaces:
Paused
Paused
File size: 1,625 Bytes
1567175 2bf4d46 1567175 0c0985c 823a8a2 2bf4d46 823a8a2 2bf4d46 823a8a2 2bf4d46 823a8a2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #!/bin/bash
set -e
export HF_TOKEN=${HF_TOKEN}
export HF_DATASET_ID=${HF_DATASET_ID:-""}
export OPCODE_MAX_TOOL_TIMEOUT=300000
export OPCODE_AUTO_APPROVE=true
echo "=== Sync from HF Dataset ==="
if [ -n "$HF_DATASET_ID" ]; then
git config --global user.email "opencode-bot@huggingface.co"
git config --global user.name "OpenCode Bot"
if [ ! -d "/workspace/.git" ]; then
git clone https://user:${HF_TOKEN}@huggingface.co/datasets/${HF_DATASET_ID} /workspace || mkdir -p /workspace
fi
else
mkdir -p /workspace
fi
cd /workspace
echo "Dataset ready"
echo "=== Optimizing OpenCode Configuration ==="
cat <<EOT > /workspace/opencode.json
{
"\$schema": "https://opencode.ai/config.json",
"server": {
"port": 7860,
"hostname": "0.0.0.0",
"mdns": false,
"openBrowser": false
},
"provider": {
"openai": {
"options": {
"timeout": 3600000
}
},
"anthropic": {
"options": {
"timeout": 3600000
}
},
"openrouter": {
"options": {
"timeout": 3600000
}
},
"huggingface": {
"options": {
"timeout": 3600000
}
}
}
}
EOT
sync_to_dataset() {
echo "=== Saving Workspace to HF Dataset ==="
if [ -n "$HF_DATASET_ID" ] && [ -d "/workspace/.git" ]; then
cd /workspace
git add .
git diff-index --quiet HEAD -- || git commit -m "Auto-backup from OpenCode [\$(date)]"
git push https://user:${HF_TOKEN}@huggingface.co/datasets/${HF_DATASET_ID} main || echo "Push failed"
fi
}
trap sync_to_dataset SIGTERM SIGINT EXIT
exec opencode "$@"
|