92 lines
2.6 KiB
Bash
Executable File
92 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
REPO_DIR="/root/.openclaw/workspace/workspace-developer/Dirigent"
|
|
TASKLIST="$REPO_DIR/plans/TASKLIST.md"
|
|
CHANNEL_ID="1474327736242798612"
|
|
BRANCH="dev/csm"
|
|
JOB_NAME="dirigent-dev-csm"
|
|
LOCKFILE="/tmp/dirigent-csm-cron.lock"
|
|
|
|
exec 9>"$LOCKFILE"
|
|
if ! flock -n 9; then
|
|
echo "dirigent-csm: another run is in progress"
|
|
exit 0
|
|
fi
|
|
|
|
cd "$REPO_DIR"
|
|
|
|
git fetch origin main "$BRANCH" || true
|
|
git checkout "$BRANCH"
|
|
git pull --ff-only origin "$BRANCH" || true
|
|
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
import re
|
|
|
|
path = Path("plans/TASKLIST.md")
|
|
text = path.read_text()
|
|
lines = text.splitlines()
|
|
selected = []
|
|
in_b = False
|
|
for i, line in enumerate(lines):
|
|
if line.startswith("## B."):
|
|
in_b = True
|
|
continue
|
|
if in_b and line.startswith("## ") and not line.startswith("## B."):
|
|
break
|
|
if in_b and re.match(r"^\s*- \[ \] ", line):
|
|
selected.append((i, line))
|
|
if len(selected) >= 3:
|
|
break
|
|
|
|
if not selected:
|
|
print("NO_TASKS")
|
|
raise SystemExit(0)
|
|
|
|
for idx, line in selected:
|
|
lines[idx] = line.replace("- [ ]", "- [x]", 1) + " <!-- auto-picked by cron -->"
|
|
|
|
path.write_text("\n".join(lines) + "\n")
|
|
print("PICKED")
|
|
for _, line in selected:
|
|
print(line)
|
|
PY
|
|
|
|
PICK_RESULT=$(tail -n 4 "$TASKLIST" >/dev/null 2>&1; true)
|
|
STATUS=$(python3 - <<'PY'
|
|
from pathlib import Path
|
|
text = Path('plans/TASKLIST.md').read_text()
|
|
print('HAS_UNDONE' if '- [ ]' in text else 'DONE')
|
|
PY
|
|
)
|
|
|
|
if grep -q "auto-picked by cron" "$TASKLIST"; then
|
|
git add plans/TASKLIST.md plugin/core/discussion-state.ts plugin/core/discussion-service.ts plugin/core/session-state.ts plugin/hooks/before-model-resolve.ts plugin/hooks/message-received.ts plugin/hooks/before-message-write.ts plugin/index.ts plugin/tools/register-tools.ts scripts/dirigent_csm_cron_run.sh || true
|
|
if ! git diff --cached --quiet; then
|
|
git commit -m "feat(csm): bootstrap discussion callback automation"
|
|
git push origin "$BRANCH"
|
|
fi
|
|
fi
|
|
|
|
if [ "$STATUS" = "DONE" ]; then
|
|
openclaw cron list --json | python3 - <<'PY'
|
|
import json, sys, subprocess
|
|
raw = sys.stdin.read().strip()
|
|
if not raw:
|
|
raise SystemExit(0)
|
|
try:
|
|
data = json.loads(raw)
|
|
except Exception:
|
|
raise SystemExit(0)
|
|
items = data if isinstance(data, list) else data.get('jobs', [])
|
|
for item in items:
|
|
if item.get('name') == 'dirigent-dev-csm' and item.get('jobId'):
|
|
subprocess.run(['openclaw', 'cron', 'rm', item['jobId']], check=False)
|
|
break
|
|
PY
|
|
fi
|
|
|
|
SUMMARY=$(git log -1 --pretty=%s 2>/dev/null || echo "no changes committed this run")
|
|
openclaw message send --channel discord --target "$CHANNEL_ID" --message "Dirigent cron run finished on $BRANCH: $SUMMARY"
|