-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (120 loc) · 4.58 KB
/
agent-task-queue.yml
File metadata and controls
136 lines (120 loc) · 4.58 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
name: Agent Task Queue
on:
issues:
types: [opened, labeled]
permissions:
contents: read
issues: write
jobs:
queue:
if: >-
${{ github.event.issue.pull_request == null && ((github.event.action == 'labeled' && github.event.label.name == 'agent:ready') || (github.event.action == 'opened' && contains(github.event.issue.labels.*.name, 'agent:ready'))) }}
runs-on: ubuntu-latest
env:
VERIFY_COMMAND: bash scripts/verify
steps:
- name: Build agent task packet and notify Copilot
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = issue.number;
const currentLabels = (issue.labels || []).map(l => typeof l === "string" ? l : l.name);
const hadReady = currentLabels.includes("agent:ready");
const hadInProgress = currentLabels.includes("agent:in-progress");
if (!hadReady && context.payload.action === "opened") {
core.info("Issue opened without agent:ready; skipping queue.");
return;
}
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
});
const existingContract = comments.find(c =>
c.body?.includes("### Execution Contract") &&
c.body?.includes(`- #${issue_number}:`)
);
let addedInProgress = false;
let removedReady = false;
try {
if (!hadInProgress) {
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: ["agent:in-progress"],
});
addedInProgress = true;
}
if (hadReady) {
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: "agent:ready",
});
removedReady = true;
} catch (error) {
if (error.status === 404) {
core.info("agent:ready was already removed.");
} else {
throw error;
}
}
}
if (existingContract) {
core.info("Execution contract already exists; transition applied without duplicate enqueue.");
return;
}
const lines = [
"@copilot Please implement this task using repository guardrails.",
"",
"### Execution Contract",
"1. Keep the change minimal and in scope.",
"2. Run deterministic verification before requesting review.",
`3. Required verification command: \`${process.env.VERIFY_COMMAND}\`.`,
"4. Include PR sections: Summary, Risk, Evidence, Rollback, Scope Guard.",
"5. Do not merge; maintainers perform final human review.",
"",
"### Source Issue",
`- #${issue_number}: ${issue.title}`,
];
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: lines.join("\n"),
});
} catch (error) {
core.warning(`Queue transition failed: ${error.message}`);
if (addedInProgress && !hadInProgress) {
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: "agent:in-progress",
});
} catch (rollbackError) {
core.warning(`Rollback remove agent:in-progress failed: ${rollbackError.message}`);
}
}
if (removedReady && hadReady) {
try {
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: ["agent:ready"],
});
} catch (rollbackError) {
core.warning(`Rollback add agent:ready failed: ${rollbackError.message}`);
}
}
throw error;
}