-
Notifications
You must be signed in to change notification settings - Fork 5
316 lines (279 loc) Β· 12.3 KB
/
squad-heartbeat.yml
File metadata and controls
316 lines (279 loc) Β· 12.3 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
name: Squad Heartbeat (Ralph)
on:
# DISABLED: Cron heartbeat commented out pre-migration β re-enable when ready
# schedule:
# # Every 30 minutes β adjust or remove if not needed
# - cron: '*/30 * * * *'
# React to completed work or new squad work
issues:
types: [closed, labeled]
pull_request:
types: [closed]
# Manual trigger
workflow_dispatch:
permissions:
issues: write
contents: read
pull-requests: read
jobs:
heartbeat:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Ralph β Check for squad work
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
// Read team roster β check .squad/ first, fall back to .ai-team/
let teamFile = '.squad/team.md';
if (!fs.existsSync(teamFile)) {
teamFile = '.ai-team/team.md';
}
if (!fs.existsSync(teamFile)) {
core.info('No .squad/team.md or .ai-team/team.md found β Ralph has nothing to monitor');
return;
}
const content = fs.readFileSync(teamFile, 'utf8');
// Check if Ralph is on the roster
if (!content.includes('Ralph') || !content.includes('π')) {
core.info('Ralph not on roster β heartbeat disabled');
return;
}
// Parse members from roster
const lines = content.split('\n');
const members = [];
let inMembersTable = false;
for (const line of lines) {
if (line.match(/^##\s+(Members|Team Roster)/i)) {
inMembersTable = true;
continue;
}
if (inMembersTable && line.startsWith('## ')) break;
if (inMembersTable && line.startsWith('|') && !line.includes('---') && !line.includes('Name')) {
const cells = line.split('|').map(c => c.trim()).filter(Boolean);
if (cells.length >= 2 && !['Scribe', 'Ralph'].includes(cells[0])) {
members.push({
name: cells[0],
role: cells[1],
label: `squad:${cells[0].toLowerCase()}`
});
}
}
}
if (members.length === 0) {
core.info('No squad members found β nothing to monitor');
return;
}
// 1. Find untriaged issues (labeled "squad" but no "squad:{member}" label)
const { data: squadIssues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'squad',
state: 'open',
per_page: 20
});
const memberLabels = members.map(m => m.label);
const untriaged = squadIssues.filter(issue => {
const issueLabels = issue.labels.map(l => l.name);
return !memberLabels.some(ml => issueLabels.includes(ml));
});
// 2. Find assigned but unstarted issues (has squad:{member} label, no assignee)
const unstarted = [];
for (const member of members) {
try {
const { data: memberIssues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: member.label,
state: 'open',
per_page: 10
});
for (const issue of memberIssues) {
if (!issue.assignees || issue.assignees.length === 0) {
unstarted.push({ issue, member });
}
}
} catch (e) {
// Label may not exist yet
}
}
// 3. Find squad issues missing triage verdict (no go:* label)
const missingVerdict = squadIssues.filter(issue => {
const labels = issue.labels.map(l => l.name);
return !labels.some(l => l.startsWith('go:'));
});
// 4. Find go:yes issues missing release target
const goYesIssues = squadIssues.filter(issue => {
const labels = issue.labels.map(l => l.name);
return labels.includes('go:yes') && !labels.some(l => l.startsWith('release:'));
});
// 4b. Find issues missing type: label
const missingType = squadIssues.filter(issue => {
const labels = issue.labels.map(l => l.name);
return !labels.some(l => l.startsWith('type:'));
});
// 5. Find open PRs that need attention
const { data: openPRs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 20
});
const squadPRs = openPRs.filter(pr =>
pr.labels.some(l => l.name.startsWith('squad'))
);
// Build status summary
const summary = [];
if (untriaged.length > 0) {
summary.push(`π΄ **${untriaged.length} untriaged issue(s)** need triage`);
}
if (unstarted.length > 0) {
summary.push(`π‘ **${unstarted.length} assigned issue(s)** have no assignee`);
}
if (missingVerdict.length > 0) {
summary.push(`βͺ **${missingVerdict.length} issue(s)** missing triage verdict (no \`go:\` label)`);
}
if (goYesIssues.length > 0) {
summary.push(`βͺ **${goYesIssues.length} approved issue(s)** missing release target (no \`release:\` label)`);
}
if (missingType.length > 0) {
summary.push(`βͺ **${missingType.length} issue(s)** missing \`type:\` label`);
}
if (squadPRs.length > 0) {
const drafts = squadPRs.filter(pr => pr.draft).length;
const ready = squadPRs.length - drafts;
if (drafts > 0) summary.push(`π‘ **${drafts} draft PR(s)** in progress`);
if (ready > 0) summary.push(`π’ **${ready} PR(s)** open for review/merge`);
}
if (summary.length === 0) {
core.info('π Board is clear β Ralph found no pending work');
return;
}
core.info(`π Ralph found work:\n${summary.join('\n')}`);
// Auto-triage untriaged issues
for (const issue of untriaged) {
const issueText = `${issue.title}\n${issue.body || ''}`.toLowerCase();
let assignedMember = null;
let reason = '';
// Simple keyword-based routing
for (const member of members) {
const role = member.role.toLowerCase();
if ((role.includes('frontend') || role.includes('ui')) &&
(issueText.includes('ui') || issueText.includes('frontend') ||
issueText.includes('css') || issueText.includes('component'))) {
assignedMember = member;
reason = 'Matches frontend/UI domain';
break;
}
if ((role.includes('backend') || role.includes('api') || role.includes('server')) &&
(issueText.includes('api') || issueText.includes('backend') ||
issueText.includes('database') || issueText.includes('endpoint'))) {
assignedMember = member;
reason = 'Matches backend/API domain';
break;
}
if ((role.includes('test') || role.includes('qa')) &&
(issueText.includes('test') || issueText.includes('bug') ||
issueText.includes('fix') || issueText.includes('regression'))) {
assignedMember = member;
reason = 'Matches testing/QA domain';
break;
}
}
// Default to Lead
if (!assignedMember) {
const lead = members.find(m =>
m.role.toLowerCase().includes('lead') ||
m.role.toLowerCase().includes('architect')
);
if (lead) {
assignedMember = lead;
reason = 'No domain match β routed to Lead';
}
}
if (assignedMember) {
// Add member label
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [assignedMember.label]
});
// Post triage comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: [
`### π Ralph β Auto-Triage`,
'',
`**Assigned to:** ${assignedMember.name} (${assignedMember.role})`,
`**Reason:** ${reason}`,
'',
`> Ralph auto-triaged this issue via the squad heartbeat. To reassign, swap the \`squad:*\` label.`
].join('\n')
});
core.info(`Auto-triaged #${issue.number} β ${assignedMember.name}`);
}
}
# Copilot auto-assign step (uses PAT if available)
- name: Ralph β Assign @copilot issues
if: success()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.COPILOT_ASSIGN_TOKEN || secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
let teamFile = '.squad/team.md';
if (!fs.existsSync(teamFile)) {
teamFile = '.ai-team/team.md';
}
if (!fs.existsSync(teamFile)) return;
const content = fs.readFileSync(teamFile, 'utf8');
// Check if @copilot is on the team with auto-assign
const hasCopilot = content.includes('π€ Coding Agent') || content.includes('@copilot');
const autoAssign = content.includes('<!-- copilot-auto-assign: true -->');
if (!hasCopilot || !autoAssign) return;
// Find issues labeled squad:copilot with no assignee
try {
const { data: copilotIssues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'squad:copilot',
state: 'open',
per_page: 5
});
const unassigned = copilotIssues.filter(i =>
!i.assignees || i.assignees.length === 0
);
if (unassigned.length === 0) {
core.info('No unassigned squad:copilot issues');
return;
}
// Get repo default branch
const { data: repoData } = await github.rest.repos.get({
owner: context.repo.owner,
repo: context.repo.repo
});
for (const issue of unassigned) {
try {
await github.request('POST /repos/{owner}/{repo}/issues/{issue_number}/assignees', {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
assignees: ['copilot-swe-agent[bot]'],
agent_assignment: {
target_repo: `${context.repo.owner}/${context.repo.repo}`,
base_branch: repoData.default_branch,
custom_instructions: `Read .squad/team.md (or .ai-team/team.md) for team context and .squad/routing.md (or .ai-team/routing.md) for routing rules.`
}
});
core.info(`Assigned copilot-swe-agent[bot] to #${issue.number}`);
} catch (e) {
core.warning(`Failed to assign @copilot to #${issue.number}: ${e.message}`);
}
}
} catch (e) {
core.info(`No squad:copilot label found or error: ${e.message}`);
}