-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (127 loc) · 4.82 KB
/
agent-task-queue.yml
File metadata and controls
145 lines (127 loc) · 4.82 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
name: Agent Task Queue
on:
issues:
types: [labeled]
permissions:
contents: read
issues: write
jobs:
queue:
if: ${{ github.event.label.name == 'agent:ready' && github.event.issue.pull_request == null }}
runs-on: ubuntu-latest
env:
VERIFY_COMMAND: make verify
steps:
- name: Build agent task packet and notify Copilot
uses: actions/github-script@v8
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");
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}: ${issue.title}`)
);
if (existingContract) {
core.info("Execution contract comment already exists; skipping duplicate enqueue.");
return;
}
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;
}
}
}
const intro = repo === "SWFOC-Mod-Menu"
? "@copilot Please implement this task using SWFOC runtime safety guardrails."
: "@copilot Please implement this task using repository guardrails.";
const lines = [
intro,
"",
"### 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.",
];
if (repo === "SWFOC-Mod-Menu") {
lines.push(
"6. Keep profile compatibility explicit (`base`, `aotr`, `roe`, `custom`).",
"7. Include reason-code-level diagnostics for runtime behavior changes.",
"8. Attach repro-bundle evidence for runtime/mod bugfixes.",
);
}
lines.push(
"",
"### 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;
}