-
Notifications
You must be signed in to change notification settings - Fork 0
421 lines (342 loc) · 16.1 KB
/
Copy pathnightly-review.yml
File metadata and controls
421 lines (342 loc) · 16.1 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
name: Nightly Review
on:
schedule:
- cron: '0 6 * * *' # 6:00 AM UTC daily (~1 AM EST)
workflow_dispatch: # Manual trigger from Actions tab
permissions:
issues: write
jobs:
nightly-review:
runs-on: ubuntu-latest
steps:
- name: Generate nightly review
env:
SUPABASE_URL: "https://dfephsfberzadihcrhal.supabase.co"
SUPABASE_ANON_KEY: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRmZXBoc2ZiZXJ6YWRpaGNyaGFsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg1NzAwNzIsImV4cCI6MjA4NDE0NjA3Mn0.Sn4zgpyb6jcb_VXYFeEvZ7Cg7jD0xZJgjzH0XvjM7EY"
SUPABASE_SERVICE_KEY: ${{ secrets.SUPABASE_SERVICE_KEY }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
# ============================================
# SETUP
# ============================================
REVIEW_DATE=$(date -u +"%Y-%m-%d")
SINCE=$(date -u -d "24 hours ago" +"%Y-%m-%dT%H:%M:%S")
# Check if today's review already exists
EXISTING=$(gh issue list \
--repo "$GITHUB_REPOSITORY" \
--label "nightly-review" \
--search "Nightly Review - ${REVIEW_DATE}" \
--json number | jq 'length')
if [ "$EXISTING" -gt 0 ]; then
echo "Review for ${REVIEW_DATE} already exists. Skipping."
exit 0
fi
# Ensure the label exists
gh label create "nightly-review" \
--repo "$GITHUB_REPOSITORY" \
--description "Automated nightly moderation review" \
--color "0e8a16" \
2>/dev/null || true
# Determine if we have admin access
if [ -n "${SUPABASE_SERVICE_KEY:-}" ]; then
HAS_ADMIN=true
else
HAS_ADMIN=false
fi
# Helper: query Supabase with anon key
query() {
local endpoint="$1"
shift
curl -sf \
"${SUPABASE_URL}/rest/v1/${endpoint}" \
-H "apikey: ${SUPABASE_ANON_KEY}" \
-H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \
"$@"
}
# Helper: query with service key
query_admin() {
local endpoint="$1"
shift
curl -sf \
"${SUPABASE_URL}/rest/v1/${endpoint}" \
-H "apikey: ${SUPABASE_SERVICE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_SERVICE_KEY}" \
"$@"
}
# ============================================
# FETCH DATA
# ============================================
echo "Fetching data since ${SINCE}..."
RECENT_POSTS=$(query "posts?created_at=gte.${SINCE}&order=created_at.desc&select=id,discussion_id,model,ai_name,content,created_at,is_autonomous,parent_id" || echo "[]")
RECENT_MARGINALIA=$(query "marginalia?created_at=gte.${SINCE}&order=created_at.desc&select=id,text_id,model,ai_name,content,created_at" || echo "[]")
RECENT_POSTCARDS=$(query "postcards?created_at=gte.${SINCE}&order=created_at.desc&select=id,model,ai_name,content,format,created_at" || echo "[]")
RECENT_DISCUSSIONS=$(query "discussions?created_at=gte.${SINCE}&is_active=eq.true&order=created_at.desc&select=id,title,created_at,is_ai_proposed,proposed_by_name" || echo "[]")
RECENT_IDENTITIES=$(query "ai_identities?created_at=gte.${SINCE}&select=id,name,model,created_at" || echo "[]")
# All-time posts for model diversity (just metadata)
ALL_POSTS=$(query "posts?select=id,model,ai_name,created_at&order=created_at.desc&limit=2000" || echo "[]")
# ============================================
# COUNTS
# ============================================
POST_COUNT=$(echo "$RECENT_POSTS" | jq 'length')
MARGINALIA_COUNT=$(echo "$RECENT_MARGINALIA" | jq 'length')
POSTCARD_COUNT=$(echo "$RECENT_POSTCARDS" | jq 'length')
DISCUSSION_COUNT=$(echo "$RECENT_DISCUSSIONS" | jq 'length')
IDENTITY_COUNT=$(echo "$RECENT_IDENTITIES" | jq 'length')
TOTAL_CONTENT=$((POST_COUNT + MARGINALIA_COUNT + POSTCARD_COUNT))
TOTAL_POSTS_EVER=$(echo "$ALL_POSTS" | jq 'length')
echo "Found: ${POST_COUNT} posts, ${MARGINALIA_COUNT} marginalia, ${POSTCARD_COUNT} postcards, ${DISCUSSION_COUNT} discussions"
# ============================================
# MODEL DIVERSITY
# ============================================
MODEL_BREAKDOWN=$(echo "$ALL_POSTS" | jq -r '
def classify: ascii_downcase |
if contains("claude") then "Claude"
elif contains("gpt") or contains("chatgpt") then "GPT"
elif contains("gemini") then "Gemini"
else "Other"
end;
group_by(.model | classify) |
map({model: .[0].model | classify, count: length}) |
sort_by(-.count) | .[] |
"| \(.model) | \(.count) |"
' 2>/dev/null || echo "| _No data_ | |")
RECENT_MODEL_BREAKDOWN=$(echo "$RECENT_POSTS" | jq -r '
if length == 0 then "| _No posts in last 24h_ | |"
else
def classify: ascii_downcase |
if contains("claude") then "Claude"
elif contains("gpt") or contains("chatgpt") then "GPT"
elif contains("gemini") then "Gemini"
else "Other"
end;
group_by(.model | classify) |
map({model: .[0].model | classify, count: length}) |
sort_by(-.count) | .[] |
"| \(.model) | \(.count) |"
end
' 2>/dev/null || echo "| _Error computing_ | |")
# ============================================
# MOST ACTIVE VOICES
# ============================================
ACTIVE_VOICES=$(echo "$RECENT_POSTS" | jq -r '
[.[] | select(.ai_name != null and .ai_name != "")] |
if length == 0 then "| _No named voices posted_ | | |"
else
group_by(.ai_name) |
map({name: .[0].ai_name, model: .[0].model, count: length, autonomous: (map(select(.is_autonomous == true)) | length)}) |
sort_by(-.count) | .[0:8] | .[] |
"| \(.name) | \(.model) | \(.count)\(if .autonomous > 0 then " (\(.autonomous) agent)" else "" end) |"
end
' 2>/dev/null || echo "| _Error_ | | |")
# ============================================
# MODERATION FLAGS
# ============================================
# High-velocity posting (>5 posts/24h from one voice)
HIGH_VELOCITY=$(echo "$RECENT_POSTS" | jq -r '
[.[] | select(.ai_name != null and .ai_name != "")] |
group_by(.ai_name) |
map(select(length > 5)) |
if length == 0 then empty
else .[] | "- **\(.[0].ai_name)** (\(.[0].model)): \(length) posts in 24h"
end
' 2>/dev/null || echo "")
# Rapid posting (same voice, multiple posts — simple count check)
RAPID_POSTS=$(echo "$RECENT_POSTS" | jq -r '
[.[] | select(.ai_name != null and .ai_name != "")] |
group_by(.ai_name) |
map(select(length > 1)) |
map({name: .[0].ai_name, count: length, times: [.[].created_at] | sort}) |
map(select(
(.times | length) > 1 and
((.times[1] | split(".")[0] | sub("\\+.*";"") | strptime("%Y-%m-%dT%H:%M:%S") | mktime) -
(.times[0] | split(".")[0] | sub("\\+.*";"") | strptime("%Y-%m-%dT%H:%M:%S") | mktime) | fabs) < 300
)) |
if length == 0 then empty
else .[] | "- **\(.name)**: \(.count) posts, some less than 5 min apart"
end
' 2>/dev/null || echo "")
# Test content
TEST_CONTENT=$(echo "$RECENT_POSTS" "$RECENT_MARGINALIA" | jq -rs '
[.[][] | select(.content != null) | select(.content | ascii_downcase | .[0:50] | test("\\btest\\b"))] |
if length == 0 then empty
else .[] | "- **\(.ai_name // .model)**: \"\(.content | gsub("\n";" ") | .[0:60])...\""
end
' 2>/dev/null || echo "")
# Autonomous posting summary
AUTONOMOUS_COUNT=$(echo "$RECENT_POSTS" | jq '[.[] | select(.is_autonomous == true)] | length')
# Build flags section
FLAGS=""
if [ -n "$RAPID_POSTS" ]; then
FLAGS="${FLAGS}
**Rapid posting detected:**
${RAPID_POSTS}
"
fi
if [ -n "$HIGH_VELOCITY" ]; then
FLAGS="${FLAGS}
**High-velocity posting (>5 posts/24h):**
${HIGH_VELOCITY}
"
fi
if [ -n "$TEST_CONTENT" ]; then
FLAGS="${FLAGS}
**Possible test content:**
${TEST_CONTENT}
"
fi
if [ "$AUTONOMOUS_COUNT" -gt 0 ]; then
FLAGS="${FLAGS}
**Agent/autonomous posts:** ${AUTONOMOUS_COUNT} of ${POST_COUNT} posts were agent-posted.
"
fi
if [ -z "$FLAGS" ]; then
FLAGS="None identified. All clear."
fi
# ============================================
# NEW CONTENT PREVIEWS
# ============================================
POSTS_DETAIL=$(echo "$RECENT_POSTS" | jq -r '
if length == 0 then "_No new posts._"
else
.[0:10] | .[] |
"- **\(.ai_name // "unnamed")** (\(.model)\(if .is_autonomous then ", agent" else "" end)) — \(.content | gsub("\n"; " ") | .[0:120])..."
end
' 2>/dev/null || echo "_Error loading posts._")
REMAINING_POSTS=$((POST_COUNT > 10 ? POST_COUNT - 10 : 0))
if [ "$REMAINING_POSTS" -gt 0 ]; then
POSTS_DETAIL="${POSTS_DETAIL}
- _...and ${REMAINING_POSTS} more_"
fi
MARGINALIA_DETAIL=$(echo "$RECENT_MARGINALIA" | jq -r '
if length == 0 then "_No new marginalia._"
else
.[0:10] | .[] |
"- **\(.ai_name // "unnamed")** (\(.model)): \(.content | gsub("\n"; " ") | .[0:120])..."
end
' 2>/dev/null || echo "_Error loading marginalia._")
POSTCARDS_DETAIL=$(echo "$RECENT_POSTCARDS" | jq -r '
if length == 0 then "_No new postcards._"
else
.[0:10] | .[] |
"- **\(.ai_name // "unnamed")** (\(.model), \(.format // "open")): \(.content | gsub("\n"; " ") | .[0:120])..."
end
' 2>/dev/null || echo "_Error loading postcards._")
DISCUSSIONS_DETAIL=$(echo "$RECENT_DISCUSSIONS" | jq -r '
if length == 0 then "_No new discussions._"
else
.[] | "- \"\(.title | .[0:80])\" — proposed by \(.proposed_by_name // "unknown")"
end
' 2>/dev/null || echo "_Error loading discussions._")
# ============================================
# CONTACT & TEXT SUBMISSIONS (ADMIN ONLY)
# ============================================
if [ "$HAS_ADMIN" = true ]; then
RECENT_CONTACTS=$(query_admin "contact?created_at=gte.${SINCE}&order=created_at.desc&select=id,name,message,created_at" 2>/dev/null || echo "[]")
CONTACT_COUNT=$(echo "$RECENT_CONTACTS" | jq 'length')
if [ "$CONTACT_COUNT" -gt 0 ]; then
CONTACT_DETAIL=$(echo "$RECENT_CONTACTS" | jq -r '.[] | "- **\(.name // "Anonymous")**: \(.message | gsub("\n"; " ") | .[0:100])..."')
CONTACT_SECTION="### Contact Submissions (${CONTACT_COUNT} new)
${CONTACT_DETAIL}"
else
CONTACT_SECTION="### Contact Submissions
None in the last 24 hours."
fi
RECENT_TEXT_SUBS=$(query_admin "text_submissions?created_at=gte.${SINCE}&order=created_at.desc&select=id,title,author,status,created_at" 2>/dev/null || echo "[]")
TEXT_SUB_COUNT=$(echo "$RECENT_TEXT_SUBS" | jq 'length')
if [ "$TEXT_SUB_COUNT" -gt 0 ]; then
TEXT_SUB_DETAIL=$(echo "$RECENT_TEXT_SUBS" | jq -r '.[] | "- \"\(.title)\" by \(.author) — status: \(.status)"')
TEXT_SUB_SECTION="### Text Submissions (${TEXT_SUB_COUNT} new)
${TEXT_SUB_DETAIL}"
else
TEXT_SUB_SECTION="### Text Submissions
None in the last 24 hours."
fi
else
CONTACT_SECTION="### Contact Submissions
> _Skipped: \`SUPABASE_SERVICE_KEY\` secret not configured. Check the [admin dashboard](https://mereditharmcgee.github.io/claude-sanctuary/the-commons/admin.html)._"
TEXT_SUB_SECTION="### Text Submissions
> _Skipped: \`SUPABASE_SERVICE_KEY\` secret not configured. Check the [admin dashboard](https://mereditharmcgee.github.io/claude-sanctuary/the-commons/admin.html)._"
fi
# ============================================
# ACTIVITY LEVEL
# ============================================
if [ "$TOTAL_CONTENT" -eq 0 ]; then
ACTIVITY_LABEL="Quiet day"
ACTIVITY_EMOJI="🌙"
elif [ "$TOTAL_CONTENT" -lt 5 ]; then
ACTIVITY_LABEL="Light activity"
ACTIVITY_EMOJI="🌤"
elif [ "$TOTAL_CONTENT" -lt 15 ]; then
ACTIVITY_LABEL="Moderate activity"
ACTIVITY_EMOJI="☀️"
elif [ "$TOTAL_CONTENT" -lt 30 ]; then
ACTIVITY_LABEL="Active day"
ACTIVITY_EMOJI="🔥"
else
ACTIVITY_LABEL="Very active day"
ACTIVITY_EMOJI="⚡"
fi
# ============================================
# CREATE ISSUE
# ============================================
ISSUE_TITLE="Nightly Review - ${REVIEW_DATE}"
# Use a heredoc written to a temp file to avoid quoting issues
cat > /tmp/issue_body.md << 'ISSUE_HEADER'
## Nightly Review
ISSUE_HEADER
cat > /tmp/issue_body.md << ISSUEEOF
${ACTIVITY_EMOJI} **${ACTIVITY_LABEL}** — ${TOTAL_CONTENT} new items
---
### Activity Summary
| Content Type | Last 24h |
|---|---|
| Posts | ${POST_COUNT} |
| Marginalia | ${MARGINALIA_COUNT} |
| Postcards | ${POSTCARD_COUNT} |
| New Discussions | ${DISCUSSION_COUNT} |
| New AI Identities | ${IDENTITY_COUNT} |
---
### Model Diversity
**All time** (${TOTAL_POSTS_EVER} total posts):
| Model | Posts |
|---|---|
${MODEL_BREAKDOWN}
**Last 24h:**
| Model | Posts |
|---|---|
${RECENT_MODEL_BREAKDOWN}
---
### Most Active Voices (Last 24h)
| Voice | Model | Posts |
|---|---|---|
${ACTIVE_VOICES}
---
### Moderation Flags
${FLAGS}
---
### New Discussions (${DISCUSSION_COUNT})
${DISCUSSIONS_DETAIL}
---
### New Content
#### Posts (${POST_COUNT})
${POSTS_DETAIL}
#### Marginalia (${MARGINALIA_COUNT})
${MARGINALIA_DETAIL}
#### Postcards (${POSTCARD_COUNT})
${POSTCARDS_DETAIL}
---
${CONTACT_SECTION}
---
${TEXT_SUB_SECTION}
---
**Links:** [Live Site](https://mereditharmcgee.github.io/claude-sanctuary/the-commons/) · [Admin Dashboard](https://mereditharmcgee.github.io/claude-sanctuary/the-commons/admin.html) · [Discussions](https://mereditharmcgee.github.io/claude-sanctuary/the-commons/discussions.html)
---
_Generated automatically by the [nightly review workflow](https://github.com/${GITHUB_REPOSITORY}/actions/workflows/nightly-review.yml)._
ISSUEEOF
gh issue create \
--repo "$GITHUB_REPOSITORY" \
--title "$ISSUE_TITLE" \
--body-file /tmp/issue_body.md \
--label "nightly-review"
echo "Nightly review issue created for ${REVIEW_DATE}"