@plainconceptsplatform/workflows 0.19.2 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catalog-installation.js +12 -1
- package/dist/index.js +0 -0
- package/dist/stack-defaults.js +16 -16
- package/dist/worker-env.js +14 -0
- package/loops/actions/add-issue-labels/action.yml +50 -50
- package/loops/actions/agent-output.cjs +17 -17
- package/loops/actions/apply-agent-bundle/action.yml +24 -24
- package/loops/actions/apply-agent-comments/action.yml +42 -42
- package/loops/actions/apply-agent-labels/action.yml +55 -55
- package/loops/actions/apply-agent-output/action.yml +108 -108
- package/loops/actions/assess-blast-radius/action.yml +148 -0
- package/loops/actions/assess-blast-radius/assess-blast-radius.sh +138 -0
- package/loops/actions/classify-route/action.yml +100 -100
- package/loops/actions/cleanup-artifacts/action.yml +91 -91
- package/loops/actions/close-agent-issues/action.yml +43 -43
- package/loops/actions/create-agent-issues/action.yml +52 -52
- package/loops/actions/create-issue-comment/action.yml +29 -29
- package/loops/actions/download-agent-output/action.yml +53 -53
- package/loops/actions/housekeeping/action.yml +55 -2
- package/loops/actions/link-pr-to-issue/action.yml +40 -40
- package/loops/actions/list-open-issues/action.yml +33 -33
- package/loops/actions/load-issue-context/action.yml +45 -45
- package/loops/actions/merge-agent-pr/action.yml +49 -49
- package/loops/actions/push-agent-branch/action.yml +45 -45
- package/loops/actions/remove-issue-labels/action.yml +37 -37
- package/loops/actions/update-agent-issues/action.yml +58 -58
- package/loops/actions/validate-merge-gate-output/action.yml +62 -40
- package/loops/actions/validate-merge-gate-output/validate-merge-gate-output.sh +147 -31
- package/loops/actions/validate-refine-output/action.yml +48 -44
- package/loops/actions/validate-refine-output/validate-refine-output.sh +15 -4
- package/loops/actions/validate-review-output/action.yml +35 -35
- package/loops/actions/validate-triage-output/action.yml +36 -36
- package/loops/actions/verify-composite-actions/action.yml +9 -9
- package/loops/actions/verify-refine-output/action.yml +9 -9
- package/loops/actions/verify-refine-output/verify-refine-output.sh +6 -1
- package/loops/actions/verify-route-matrix/action.yml +9 -9
- package/loops/actions/verify-route-matrix/verify-gate-metrics.mjs +51 -0
- package/loops/actions/verify-route-matrix/verify-route-matrix.sh +329 -29
- package/loops/scripts/compile-agent-workflows.mjs +331 -331
- package/loops/templates/agentics/agentics-maintenance.yml +121 -121
- package/loops/templates/ci/app-ci-dotnet-next.yml +330 -330
- package/loops/templates/ci/app-ci-node-monorepo.yml +260 -260
- package/loops/templates/issues/bug_report.yml +109 -109
- package/loops/templates/issues/feature_request.yml +75 -75
- package/loops/templates/opencode/opencode.ci.json +55 -49
- package/loops/templates/opencode/opencode.ci.json.md +59 -49
- package/loops/templates/release/github-release.yml +30 -30
- package/loops/workflows/agent-merge-gate.md +367 -148
- package/loops/workflows/agent-refine.md +60 -16
- package/loops/workflows/authorize-bot-work.yml +105 -105
- package/loops/workflows/shared/opencode-ci.md +206 -206
- package/loops/workflows/shared/platform-defaults.md +19 -19
- package/package.json +12 -11
|
@@ -1,331 +1,331 @@
|
|
|
1
|
-
// Managed by @plainconceptsplatform/workflows. Source: loops/scripts/compile-agent-workflows.mjs. Update with `workflows update --force`; consumer edits may be overwritten.
|
|
2
|
-
|
|
3
|
-
const OPENCODE_VERSION = '1.18.23'
|
|
4
|
-
import { spawnSync } from "node:child_process";
|
|
5
|
-
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
|
|
8
|
-
const workflowDirectory = existsSync("loops/workflows") ? "loops/workflows" : ".github/workflows";
|
|
9
|
-
|
|
10
|
-
// On Windows, `gh` resolves to a shim that spawnSync cannot find without a shell.
|
|
11
|
-
// Resolve the full path via `where` so spawnSync works with shell: false (security-safe).
|
|
12
|
-
function resolveGhPath() {
|
|
13
|
-
if (process.platform !== "win32") return "gh";
|
|
14
|
-
const result = spawnSync("where", ["gh"], { encoding: "utf8", shell: false });
|
|
15
|
-
if (result.status === 0) {
|
|
16
|
-
const first = result.stdout.split("\n").map((s) => s.trim()).find(Boolean);
|
|
17
|
-
if (first) return first;
|
|
18
|
-
}
|
|
19
|
-
return "gh";
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// gh-aw folds a workflow's top-level `if:` into the activation job but computes activation.needs
|
|
23
|
-
// on its own, so a compiled `if:` can read `needs.<job>` for a job activation never waits for.
|
|
24
|
-
// GitHub does not reject that: the reference resolves to '' at runtime and the clause is silently
|
|
25
|
-
// true (agent-merge-gate's protected_changes guard, Pliny-Bot run 34042143350). actionlint would
|
|
26
|
-
// flag it, but it is deliberately not run on generated files (it does not model concurrency.queue
|
|
27
|
-
// or job.workflow_*). This is the one check that reads the locks, and it needs no dependency:
|
|
28
|
-
// gh-aw emits jobs at two spaces, job keys at four, list items at six.
|
|
29
|
-
function undeclaredNeeds(lock) {
|
|
30
|
-
const violations = [];
|
|
31
|
-
let inJobs = false;
|
|
32
|
-
let job = null;
|
|
33
|
-
let inList = false;
|
|
34
|
-
let jobs = 0;
|
|
35
|
-
let needs = new Set();
|
|
36
|
-
let refs = new Set();
|
|
37
|
-
const flush = () => {
|
|
38
|
-
if (!job) return;
|
|
39
|
-
for (const ref of refs) if (!needs.has(ref)) violations.push({ job, ref, needs: [...needs].sort() });
|
|
40
|
-
};
|
|
41
|
-
for (const line of lock.split("\n")) {
|
|
42
|
-
if (/^jobs:\s*$/.test(line)) { inJobs = true; continue; }
|
|
43
|
-
if (inJobs && /^[^\s#]/.test(line)) inJobs = false;
|
|
44
|
-
if (!inJobs) continue;
|
|
45
|
-
const start = line.match(/^ ([a-z_][a-zA-Z0-9_-]*):\s*$/);
|
|
46
|
-
if (start) { flush(); job = start[1]; jobs += 1; needs = new Set(); refs = new Set(); inList = false; continue; }
|
|
47
|
-
if (!job) continue;
|
|
48
|
-
if (/^ needs:\s*$/.test(line)) { inList = true; continue; }
|
|
49
|
-
const inline = line.match(/^ needs:\s*(.+?)\s*$/);
|
|
50
|
-
if (inline) {
|
|
51
|
-
for (const n of inline[1].replace(/[\[\]]/g, "").split(",")) if (n.trim()) needs.add(n.trim());
|
|
52
|
-
inList = false;
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (inList) {
|
|
56
|
-
const item = line.match(/^ - (\S+)\s*$/);
|
|
57
|
-
if (item) { needs.add(item[1]); continue; }
|
|
58
|
-
inList = false;
|
|
59
|
-
}
|
|
60
|
-
for (const m of line.matchAll(/needs\.([a-z_][a-zA-Z0-9_-]*)\./g)) refs.add(m[1]);
|
|
61
|
-
}
|
|
62
|
-
flush();
|
|
63
|
-
return { jobs, violations };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const compile = spawnSync(resolveGhPath(), ["aw", "compile", "--strict", "--dir", workflowDirectory], {
|
|
67
|
-
stdio: "inherit",
|
|
68
|
-
shell: false,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
if (compile.error?.code === "ENOENT" || compile.status === null) {
|
|
72
|
-
process.stderr.write("Could not run `gh aw compile`. Install githubnext/gh-aw first.\n");
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (compile.status !== 0) process.exit(compile.status ?? 1);
|
|
77
|
-
|
|
78
|
-
function lintLock(file, text) {
|
|
79
|
-
const lint = undeclaredNeeds(text);
|
|
80
|
-
if (lint.jobs === 0) {
|
|
81
|
-
process.stderr.write(
|
|
82
|
-
`${file}: the needs lint found no jobs; the gh-aw lock layout changed. ` +
|
|
83
|
-
`Re-anchor undeclaredNeeds() in loops/scripts/compile-agent-workflows.mjs.\n`,
|
|
84
|
-
);
|
|
85
|
-
process.exitCode = 1;
|
|
86
|
-
}
|
|
87
|
-
for (const v of lint.violations) {
|
|
88
|
-
process.stderr.write(
|
|
89
|
-
`${file}: job "${v.job}" reads needs.${v.ref} but its needs are [${v.needs.join(", ")}]; ` +
|
|
90
|
-
`the reference resolves to '' at runtime. For activation, list the job under on.needs in the ` +
|
|
91
|
-
`source frontmatter; for a custom job, add it to that job's needs.\n`,
|
|
92
|
-
);
|
|
93
|
-
process.exitCode = 1;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// gh aw compile leaves a lock alone when its frontmatter and body hashes still match the source.
|
|
98
|
-
// This script then ran over a lock it had already patched: AGENTMEMORY_URL was inserted a second
|
|
99
|
-
// time, the opencode install line was wrapped in itself, and the consumer freshness check could
|
|
100
|
-
// never be clean (Pliny-Bot agentics-checks run 33963600563). The sentinel marks a processed
|
|
101
|
-
// lock; a lock that carries it is linted and otherwise left as it is.
|
|
102
|
-
const SENTINEL = "# post-processed by scripts/compile-agent-workflows.mjs; run it again and nothing changes";
|
|
103
|
-
|
|
104
|
-
for (const file of readdirSync(workflowDirectory)) {
|
|
105
|
-
if (!file.endsWith(".lock.yml")) continue;
|
|
106
|
-
|
|
107
|
-
const path = join(workflowDirectory, file);
|
|
108
|
-
const content = readFileSync(path, "utf8");
|
|
109
|
-
if (content.includes(SENTINEL)) {
|
|
110
|
-
lintLock(file, content);
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
const patched = content
|
|
114
|
-
.replace(/^(# This file was automatically generated by gh-aw[^\n]*\n)/m, `$1${SENTINEL}\n`)
|
|
115
|
-
.replaceAll("opencode run --print-logs --log-level DEBUG", "opencode run --log-level ERROR")
|
|
116
|
-
.replaceAll("opencode run --print-logs --log-level ERROR", "opencode run --log-level ERROR")
|
|
117
|
-
.replaceAll("opencode run --log-level ERROR", "opencode run --log-level ERROR")
|
|
118
|
-
.replaceAll("--log-level DEBUG", "--log-level ERROR")
|
|
119
|
-
.replace(/GH_AW_INFO_MODEL: "[^"]*"/g, 'GH_AW_INFO_MODEL: "per-agent"')
|
|
120
|
-
.replace(/OPENCODE_MODEL: [^\n]+/g, "OPENCODE_MODEL: ''")
|
|
121
|
-
.replace(/GH_AW_INFO_MODEL_COSTS: '[^']*'/g, 'GH_AW_INFO_MODEL_COSTS: \'{"providers":{}}\'')
|
|
122
|
-
// The MCP gateway is the only thing the agent publishes on the host loopback, so it is the
|
|
123
|
-
// one thing two runners on the same machine cannot share. Honour an inherited port so each
|
|
124
|
-
// runner service can pick its own; everything else is namespaced by its Docker daemon.
|
|
125
|
-
// awf names its containers awf-agent, awf-squid and awf-api-proxy with no way to change
|
|
126
|
-
// them, so two agent jobs on one host recreate each other's containers and the first dies
|
|
127
|
-
// with exit 137. Giving each runner its own user and daemon isolated the containers but
|
|
128
|
-
// broke everything the runners share through the filesystem: awf and gh-aw both write
|
|
129
|
-
// fixed-name files into /tmp, and a file one user creates cannot be overwritten by the
|
|
130
|
-
// next. Six separate failures came from that. One host lock is the smaller trade: agent
|
|
131
|
-
// jobs run one at a time, every other job still uses all the runners, and every user is
|
|
132
|
-
// the same again. The chain is serial anyway, so in practice this only queues one consumer behind
|
|
133
|
-
// the other. Held for the whole agent run, which is deliberate. The lock lives outside the
|
|
134
|
-
// /tmp/gh-aw namespace on purpose: the keying rewrite below would otherwise make the lock
|
|
135
|
-
// file per job, which is silently no lock at all.
|
|
136
|
-
// Agent jobs run in parallel again. Each runner has its own Docker-in-Docker daemon, so
|
|
137
|
-
// awf's fixed container names (awf-agent, awf-squid, awf-api-proxy, awmg-mcpg) live in
|
|
138
|
-
// separate namespaces and cannot recreate each other. gh-aw detects the tcp DOCKER_HOST
|
|
139
|
-
// and switches to its ARC/DinD path by itself, so no flag is needed here. The host-wide
|
|
140
|
-
// flock this replaces made every agent job wait for the previous one.
|
|
141
|
-
// Three host-global resources were left, and concurrent agent jobs fought over all of them.
|
|
142
|
-
// The global npm install rewrote the opencode binary another job was executing and killed it
|
|
143
|
-
// with SIGKILL mid-run; the warm server and its data directory were shared by every runner.
|
|
144
|
-
//
|
|
145
|
-
// All of these sites are step-level run: or env:, where the runner context is available. It
|
|
146
|
-
// is not available at workflow level, which is what broke the staging path earlier.
|
|
147
|
-
//
|
|
148
|
-
// Install only when the pinned version is missing, and take a lock so two jobs starting at
|
|
149
|
-
// once cannot both write the global prefix.
|
|
150
|
-
// gh-aw pins opencode-ai 1.2.14 at every release checked, up to v0.87.5. That version is
|
|
151
|
-
// from 2026-02-25. The harness expects 1.18.9 and this is the current release, so a gh-aw
|
|
152
|
-
// upgrade does not move it and the pin is ours to choose.
|
|
153
|
-
// gh-aw defaults NPM_CONFIG_MIN_RELEASE_AGE to 3 days, which blocks any package
|
|
154
|
-
// published in the last three days with ETARGET "No matching version found ... with a
|
|
155
|
-
// date before". Lowered to 1 so a fix released yesterday is usable. This is a
|
|
156
|
-
// supply-chain cooldown: shortening it accepts a newer package sooner.
|
|
157
|
-
.replace(/NPM_CONFIG_MIN_RELEASE_AGE: ['\"]?3['\"]?/g, "NPM_CONFIG_MIN_RELEASE_AGE: '1'")
|
|
158
|
-
// The MCP gateway runs inside a per-runner Docker-in-Docker daemon. gh-aw publishes it on
|
|
159
|
-
// 127.0.0.1, which is the DinD container's own loopback, while the outer publish forwards to
|
|
160
|
-
// that container's eth0, so the two never meet and gh-aw's health check fails 120 times with
|
|
161
|
-
// ECONNREFUSED. Binding 0.0.0.0 inside the daemon connects them. The host still exposes the
|
|
162
|
-
// port on loopback only, because the DinD container is published as 127.0.0.1:<port>.
|
|
163
|
-
.replaceAll("-p 127.0.0.1:'\"${MCP_GATEWAY_PORT}\"':", "-p '\"${MCP_GATEWAY_PORT}\"':")
|
|
164
|
-
// Each runner needs its own gateway port: four DinD daemons publish through to one host
|
|
165
|
-
// loopback, so two jobs on 8080 would collide. The runner sets it in .env.
|
|
166
|
-
// awf chroots into the Docker daemon's filesystem and requires it to be the runner's own
|
|
167
|
-
// glibc host. A Docker-in-Docker daemon fails with "Detected Alpine/musl host filesystem
|
|
168
|
-
// under /host", and no dind image fixes it: the agent needs the runner's toolchain and
|
|
169
|
-
// workspace, which a separate daemon container never has. So every agent job shares one
|
|
170
|
-
// daemon, awf's container names are fixed, and the jobs must be serialised.
|
|
171
|
-
.replaceAll(' awf --config', ' flock /tmp/agentic-awf.lock awf --config')
|
|
172
|
-
.replaceAll('export MCP_GATEWAY_PORT="8080"', 'export MCP_GATEWAY_PORT="${MCP_GATEWAY_PORT:-8080}"')
|
|
173
|
-
// The agent's safe outputs land in safeoutputs.jsonl, but the collector reads
|
|
174
|
-
// agent_output.json, and nothing in the generated workflow converts one to the other.
|
|
175
|
-
// With the OpenCode engine the tool calls go through the MCP server rather than stdout,
|
|
176
|
-
// so the log parser never produces agent_output.json and the placeholder step writes
|
|
177
|
-
// {"items":[]} over a run that did real work: the job goes green and the pull request
|
|
178
|
-
// is silently dropped. Build the collector's input from what the agent actually emitted.
|
|
179
|
-
.replaceAll("echo '{\"items\":[]}' > /tmp/gh-aw-${{ github.run_id }}/agent_output.json", "if [ -s /tmp/gh-aw-${{ github.run_id }}/safeoutputs.jsonl ]; then jq -s '{items: .}' /tmp/gh-aw-${{ github.run_id }}/safeoutputs.jsonl > /tmp/gh-aw-${{ github.run_id }}/agent_output.json; else echo '{\"items\":[]}' > /tmp/gh-aw-${{ github.run_id }}/agent_output.json; fi")
|
|
180
|
-
// The "Copy Safe Outputs" step runs on the host after the awf container exits. At that
|
|
181
|
-
// point /tmp/gh-aw/ IS the host's /tmp/gh-aw/, where the safeoutputs MCP container wrote
|
|
182
|
-
// patch and bundle files (via the MCP gateway's -v /tmp:/tmp:rw mount). Extend the step
|
|
183
|
-
// to also copy those files to RUNNER_TEMP/gh-aw/ so the upload step can include them.
|
|
184
|
-
// Without this, the upload step's glob /tmp/gh-aw/aw-*.patch runs inside the awf chroot
|
|
185
|
-
// (where /tmp/gh-aw is a different path) and finds nothing. The safe_outputs and conclude
|
|
186
|
-
// jobs then receive no patches in the artifact and silently skip the push.
|
|
187
|
-
.replace(
|
|
188
|
-
' cp "$GH_AW_SAFE_OUTPUTS" /tmp/gh-aw/safeoutputs.jsonl 2>/dev/null || true\n',
|
|
189
|
-
' cp "$GH_AW_SAFE_OUTPUTS" /tmp/gh-aw/safeoutputs.jsonl 2>/dev/null || true\n' +
|
|
190
|
-
' # Copy patch/bundle files generated by the safeoutputs MCP container to\n' +
|
|
191
|
-
' # RUNNER_TEMP/gh-aw/ so the upload step includes them in the artifact.\n' +
|
|
192
|
-
' mkdir -p "${RUNNER_TEMP}/gh-aw"\n' +
|
|
193
|
-
' ls -la /tmp/gh-aw/ 2>/dev/null || true\n' +
|
|
194
|
-
' cp /tmp/gh-aw/aw-*.patch "${RUNNER_TEMP}/gh-aw/" 2>/dev/null || true\n' +
|
|
195
|
-
' cp /tmp/gh-aw/aw-*.bundle "${RUNNER_TEMP}/gh-aw/" 2>/dev/null || true\n' +
|
|
196
|
-
' ls -la "${RUNNER_TEMP}/gh-aw/"aw-* 2>/dev/null || true\n')
|
|
197
|
-
// Add patch/bundle paths to the upload glob so the agent artifact carries what
|
|
198
|
-
// push-agent-branch needs. The anchor is the two adjacent path lines of the
|
|
199
|
-
// "...agent" upload step; the "...agent-output-fallback" upload lists them in the
|
|
200
|
-
// opposite order, so it cannot match. Anchoring matters: the first bare
|
|
201
|
-
// '/tmp/gh-aw/agent_output.json\n' in the file is the placeholder step's echo line,
|
|
202
|
-
// and replacing there corrupted the placeholder into executing the globs as
|
|
203
|
-
// commands while the upload list stayed without bundles. The artifact then carried
|
|
204
|
-
// no bundle, push-agent-branch silently skipped the push, and the gate reported
|
|
205
|
-
// "remediated" on a pull request that was never touched.
|
|
206
|
-
// Only the /tmp/gh-aw globs may be added: a ${{ runner.temp }} path as well would
|
|
207
|
-
// move the upload's least-common-ancestor from /tmp/gh-aw to /, and every file in
|
|
208
|
-
// the artifact (agent_output.json included) would gain a prefix that
|
|
209
|
-
// download-agent-output does not look for.
|
|
210
|
-
.replace(
|
|
211
|
-
' /tmp/gh-aw/safeoutputs.jsonl\n /tmp/gh-aw/agent_output.json\n',
|
|
212
|
-
' /tmp/gh-aw/safeoutputs.jsonl\n' +
|
|
213
|
-
' /tmp/gh-aw/aw-*.patch\n' +
|
|
214
|
-
' /tmp/gh-aw/aw-*.bundle\n' +
|
|
215
|
-
' /tmp/gh-aw/agent_output.json\n')
|
|
216
|
-
// "A failed run is already a red run": report-failure-as-issue: false and
|
|
217
|
-
// GH_AW_REPORT_FAILED_JOBS: "false" were supposed to silence issue creation, but
|
|
218
|
-
// 0.87.5's engine-failure reporter files an "[aw] ... failed" issue anyway (seen as
|
|
219
|
-
// Pliny-Bot #57: an OOM-killed gate produced a fresh issue nobody needs, while the
|
|
220
|
-
// retry belt is the actual remediation). `if: false` keeps the step compiled but
|
|
221
|
-
// never runs it, so the failure stays visible in the run and in the belt's attempt
|
|
222
|
-
// comment, and out of the issue tracker.
|
|
223
|
-
.replace(
|
|
224
|
-
/^([ \t]+)- name: Report failed jobs\n([ \t]*)id: report_failed_jobs\n[ \t]*if: always\(\)\n/m,
|
|
225
|
-
'$1- name: Report failed jobs\n$2id: report_failed_jobs\n$2if: false # never: failures surface in the run and the retry belt\n')
|
|
226
|
-
|
|
227
|
-
// v0.87.5's arc-dind mode stages the engine CLI to a daemon-visible path but assumes the
|
|
228
|
-
// Copilot engine: command -v copilot is empty under engine: opencode and cp "" fails the
|
|
229
|
-
// job before the agent starts. OpenCode needs no staging, because npm -g installs it under
|
|
230
|
-
// the tool-cache prefix inside _work, which the dind daemon shares.
|
|
231
|
-
// Centralised AgentMemory: an always-on App Service; the shim proxies to it when the
|
|
232
|
-
// URL is set and authenticates with the HMAC secret. Local development leaves both
|
|
233
|
-
// unset and keeps the local per-run store.
|
|
234
|
-
.replace(/^env:\n/m, 'env:\n AGENTMEMORY_URL: https://agentmemory-pro-01.azurewebsites.net\n')
|
|
235
|
-
// the secret is scoped to the one step that runs the agent (semgrep: a secret in
|
|
236
|
-
// workflow-level env is visible to every job and step)
|
|
237
|
-
.replaceAll(' OPENAI_BASE_URL: https://forge.plainconcepts.com/v1',
|
|
238
|
-
' OPENAI_BASE_URL: https://forge.plainconcepts.com/v1' + '\n' +
|
|
239
|
-
' AGENTMEMORY_SECRET: ${{ secrets.AGENTMEMORY_SECRET }}')
|
|
240
|
-
// the router passes secrets explicitly (semgrep flags secrets: inherit as over-broad),
|
|
241
|
-
// so the callee must declare everything it accepts
|
|
242
|
-
.replace(/^ COPILOT_GITHUB_TOKEN:/m,
|
|
243
|
-
' AGENTMEMORY_SECRET:' + '\n' + ' required: false' + '\n' + ' COPILOT_GITHUB_TOKEN:')
|
|
244
|
-
.replaceAll(' COPILOT_SRC="$(command -v copilot)"',
|
|
245
|
-
' command -v copilot >/dev/null 2>&1 || { echo "no copilot binary (engine is opencode); skipping"; exit 0; }' + '\n' +
|
|
246
|
-
' COPILOT_SRC="$(command -v copilot)"')
|
|
247
|
-
// "A failed run is already a red run": report-failure-as-issue: false silences one
|
|
248
|
-
// reporter, but gh-aw hardcodes a second one (report_failed_jobs) that files an
|
|
249
|
-
// "[aw] Failed jobs" issue per red run. Same philosophy, same off switch.
|
|
250
|
-
.replaceAll('GH_AW_REPORT_FAILED_JOBS: "true"', 'GH_AW_REPORT_FAILED_JOBS: "false"')
|
|
251
|
-
// gh-aw sees a custom step calling dotnet and injects its own setup-dotnet, which carries
|
|
252
|
-
// no DOTNET_INSTALL_DIR and so tries to write /usr/share/dotnet. The runner user has no
|
|
253
|
-
// sudo, so the job dies with "Permission denied" before the agent starts. The shared
|
|
254
|
-
// baseline step already redirects to the tool cache; this gives every other one the same
|
|
255
|
-
// env, including ones a future gh-aw release injects.
|
|
256
|
-
.replace(
|
|
257
|
-
/^( +)- name: Setup \.NET\n\1 uses: actions\/setup-dotnet@[^\n]*\n\1 with:\n((?:\1 [^\n]*\n)+)(?!\1 env:)/gm,
|
|
258
|
-
(_m, indent, withBody) =>
|
|
259
|
-
indent + '- name: Setup .NET\n' + indent + ' uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0\n' +
|
|
260
|
-
indent + ' with:\n' + withBody +
|
|
261
|
-
indent + ' env:\n' + indent + ' DOTNET_INSTALL_DIR: ${{ runner.tool_cache }}/dotnet\n')
|
|
262
|
-
.replace(/opencode-ai@[0-9][0-9.]*/g, 'opencode-ai@' + OPENCODE_VERSION)
|
|
263
|
-
// gh-aw installs with --ignore-scripts, which blocks opencode's own postinstall. That
|
|
264
|
-
// script downloads the platform binary, so 1.18 fails at first use with "opencode-ai's
|
|
265
|
-
// postinstall script was not run". 1.2.14 did not need it. Run only opencode's postinstall
|
|
266
|
-
// explicitly, so every other package's scripts stay blocked.
|
|
267
|
-
.replace(
|
|
268
|
-
/npm install --ignore-scripts -g opencode-ai@([0-9][0-9.]*)/g,
|
|
269
|
-
(_m, v) =>
|
|
270
|
-
"opencode --version 2>/dev/null | grep -qF '" + v + "' || " +
|
|
271
|
-
"flock /tmp/opencode-install.lock sh -c 'npm install --ignore-scripts -g opencode-ai@" + v +
|
|
272
|
-
" && cd \"$(npm root -g)/opencode-ai\" && node postinstall.mjs' # opencode-ai@" + v)
|
|
273
|
-
// One warm server per runner, on its own port, with its own data directory. Keyed on the
|
|
274
|
-
// runner rather than the run so a runner keeps its server warm between its own jobs.
|
|
275
|
-
// No double quotes here: the enclosing run: is a double-quoted YAML scalar, so a quote
|
|
276
|
-
// would have to be escaped. The default has no spaces, so bare is safe shell.
|
|
277
|
-
.replace(/\/tmp\/opencode-data(?!-\$\{\{)/g, () => '/tmp/opencode-data-${{ runner.name }}');
|
|
278
|
-
|
|
279
|
-
let rewritten = patched;
|
|
280
|
-
// A queued implement executes hours after its run was created, but actions/checkout
|
|
281
|
-
// without a ref checks out github.sha, which GitHub pins at run creation. Five children
|
|
282
|
-
// queued together at 02:01 all carried the 02:01 base; once the first sibling merged,
|
|
283
|
-
// every later push became a rebase onto a moved parent, which gh-aw's signed-commit
|
|
284
|
-
// push cannot do (it dies with "cannot rebase: You have unstaged changes" and files the
|
|
285
|
-
// pull request as an issue instead of a pull request). Checking out the branch tip at
|
|
286
|
-
// execution time makes the commit parent current main; the implement-global queue
|
|
287
|
-
// already keeps sibling merges out of the window while the agent runs.
|
|
288
|
-
if (file === "agent-implement.lock.yml") {
|
|
289
|
-
const start = rewritten.indexOf("\n agent:\n");
|
|
290
|
-
const rest = start === -1 ? "" : rewritten.slice(start + 1);
|
|
291
|
-
const next = rest.search(/\n [a-z_][a-zA-Z_-]*:\n/);
|
|
292
|
-
if (start !== -1 && next !== -1) {
|
|
293
|
-
const end = start + 1 + next;
|
|
294
|
-
const span = rewritten.slice(start, end).replace(
|
|
295
|
-
/(uses: actions\/checkout@[^\n]*\n(\s+)with:\n(?:\2 [^\n]+\n)*)/,
|
|
296
|
-
(whole, _block, indent) =>
|
|
297
|
-
whole.includes("ref:") ? whole : whole + indent + " ref: ${{ github.event.repository.default_branch }}\n",
|
|
298
|
-
);
|
|
299
|
-
rewritten = rewritten.slice(0, start) + span + rewritten.slice(end);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Guard the two rewrites the compiled agent jobs cannot work without. The anchors are
|
|
304
|
-
// upstream template text: when a gh-aw upgrade reshapes either step, the silent
|
|
305
|
-
// failure mode returns (an artifact with no bundle, a skipped push, a green gate on
|
|
306
|
-
// an untouched pull request). Failing the compile is the only loud signal there is.
|
|
307
|
-
for (const check of [
|
|
308
|
-
{ name: "bundle upload glob", ok: /\n( +)- name: Upload agent artifacts\n\1 if: always\(\)\n\1 continue-on-error: true\n\1 uses: actions\/upload-artifact@[^\n]*\n\1 with:\n\1 name: \$\{\{ needs\.activation\.outputs\.artifact_prefix \}\}agent\n\1 path: \|\n(?:\1 [^\n]*\n)*\1 \/tmp\/gh-aw\/aw-\*\.bundle\n/ },
|
|
309
|
-
{ name: "placeholder step intact", ok: /\n( +)- name: Write agent output placeholder if missing\n\1 if: always\(\)\n\1 run: \|\n\1 if \[ ! -f \/tmp\/gh-aw\/agent_output\.json \]; then\n\1 echo '\{"items":\[\]\}' > \/tmp\/gh-aw\/agent_output\.json\n\1 fi\n/ },
|
|
310
|
-
{ name: "failed-jobs reporter disabled", ok: /- name: Report failed jobs\n[ \t]*id: report_failed_jobs\n[ \t]*if: false[^\n]*\n/ },
|
|
311
|
-
]) {
|
|
312
|
-
if (!check.ok.test(rewritten)) {
|
|
313
|
-
process.stderr.write(
|
|
314
|
-
`compile patch "${check.name}" no longer matches in ${file}: the gh-aw template changed. ` +
|
|
315
|
-
`Re-anchor the rewrite in loops/scripts/compile-agent-workflows.mjs, or agent pushes are silently dropped.\n`,
|
|
316
|
-
);
|
|
317
|
-
process.exitCode = 1;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (!rewritten.includes(SENTINEL)) {
|
|
322
|
-
process.stderr.write(
|
|
323
|
-
`${file}: the generated-file header changed and the post-processing sentinel was not placed; ` +
|
|
324
|
-
`re-anchor the SENTINEL insert in loops/scripts/compile-agent-workflows.mjs.\n`,
|
|
325
|
-
);
|
|
326
|
-
process.exitCode = 1;
|
|
327
|
-
}
|
|
328
|
-
lintLock(file, rewritten);
|
|
329
|
-
|
|
330
|
-
if (rewritten !== content) writeFileSync(path, rewritten);
|
|
331
|
-
}
|
|
1
|
+
// Managed by @plainconceptsplatform/workflows. Source: loops/scripts/compile-agent-workflows.mjs. Update with `workflows update --force`; consumer edits may be overwritten.
|
|
2
|
+
|
|
3
|
+
const OPENCODE_VERSION = '1.18.23'
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
const workflowDirectory = existsSync("loops/workflows") ? "loops/workflows" : ".github/workflows";
|
|
9
|
+
|
|
10
|
+
// On Windows, `gh` resolves to a shim that spawnSync cannot find without a shell.
|
|
11
|
+
// Resolve the full path via `where` so spawnSync works with shell: false (security-safe).
|
|
12
|
+
function resolveGhPath() {
|
|
13
|
+
if (process.platform !== "win32") return "gh";
|
|
14
|
+
const result = spawnSync("where", ["gh"], { encoding: "utf8", shell: false });
|
|
15
|
+
if (result.status === 0) {
|
|
16
|
+
const first = result.stdout.split("\n").map((s) => s.trim()).find(Boolean);
|
|
17
|
+
if (first) return first;
|
|
18
|
+
}
|
|
19
|
+
return "gh";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// gh-aw folds a workflow's top-level `if:` into the activation job but computes activation.needs
|
|
23
|
+
// on its own, so a compiled `if:` can read `needs.<job>` for a job activation never waits for.
|
|
24
|
+
// GitHub does not reject that: the reference resolves to '' at runtime and the clause is silently
|
|
25
|
+
// true (agent-merge-gate's protected_changes guard, Pliny-Bot run 34042143350). actionlint would
|
|
26
|
+
// flag it, but it is deliberately not run on generated files (it does not model concurrency.queue
|
|
27
|
+
// or job.workflow_*). This is the one check that reads the locks, and it needs no dependency:
|
|
28
|
+
// gh-aw emits jobs at two spaces, job keys at four, list items at six.
|
|
29
|
+
function undeclaredNeeds(lock) {
|
|
30
|
+
const violations = [];
|
|
31
|
+
let inJobs = false;
|
|
32
|
+
let job = null;
|
|
33
|
+
let inList = false;
|
|
34
|
+
let jobs = 0;
|
|
35
|
+
let needs = new Set();
|
|
36
|
+
let refs = new Set();
|
|
37
|
+
const flush = () => {
|
|
38
|
+
if (!job) return;
|
|
39
|
+
for (const ref of refs) if (!needs.has(ref)) violations.push({ job, ref, needs: [...needs].sort() });
|
|
40
|
+
};
|
|
41
|
+
for (const line of lock.split("\n")) {
|
|
42
|
+
if (/^jobs:\s*$/.test(line)) { inJobs = true; continue; }
|
|
43
|
+
if (inJobs && /^[^\s#]/.test(line)) inJobs = false;
|
|
44
|
+
if (!inJobs) continue;
|
|
45
|
+
const start = line.match(/^ ([a-z_][a-zA-Z0-9_-]*):\s*$/);
|
|
46
|
+
if (start) { flush(); job = start[1]; jobs += 1; needs = new Set(); refs = new Set(); inList = false; continue; }
|
|
47
|
+
if (!job) continue;
|
|
48
|
+
if (/^ needs:\s*$/.test(line)) { inList = true; continue; }
|
|
49
|
+
const inline = line.match(/^ needs:\s*(.+?)\s*$/);
|
|
50
|
+
if (inline) {
|
|
51
|
+
for (const n of inline[1].replace(/[\[\]]/g, "").split(",")) if (n.trim()) needs.add(n.trim());
|
|
52
|
+
inList = false;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (inList) {
|
|
56
|
+
const item = line.match(/^ - (\S+)\s*$/);
|
|
57
|
+
if (item) { needs.add(item[1]); continue; }
|
|
58
|
+
inList = false;
|
|
59
|
+
}
|
|
60
|
+
for (const m of line.matchAll(/needs\.([a-z_][a-zA-Z0-9_-]*)\./g)) refs.add(m[1]);
|
|
61
|
+
}
|
|
62
|
+
flush();
|
|
63
|
+
return { jobs, violations };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const compile = spawnSync(resolveGhPath(), ["aw", "compile", "--strict", "--dir", workflowDirectory], {
|
|
67
|
+
stdio: "inherit",
|
|
68
|
+
shell: false,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
if (compile.error?.code === "ENOENT" || compile.status === null) {
|
|
72
|
+
process.stderr.write("Could not run `gh aw compile`. Install githubnext/gh-aw first.\n");
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (compile.status !== 0) process.exit(compile.status ?? 1);
|
|
77
|
+
|
|
78
|
+
function lintLock(file, text) {
|
|
79
|
+
const lint = undeclaredNeeds(text);
|
|
80
|
+
if (lint.jobs === 0) {
|
|
81
|
+
process.stderr.write(
|
|
82
|
+
`${file}: the needs lint found no jobs; the gh-aw lock layout changed. ` +
|
|
83
|
+
`Re-anchor undeclaredNeeds() in loops/scripts/compile-agent-workflows.mjs.\n`,
|
|
84
|
+
);
|
|
85
|
+
process.exitCode = 1;
|
|
86
|
+
}
|
|
87
|
+
for (const v of lint.violations) {
|
|
88
|
+
process.stderr.write(
|
|
89
|
+
`${file}: job "${v.job}" reads needs.${v.ref} but its needs are [${v.needs.join(", ")}]; ` +
|
|
90
|
+
`the reference resolves to '' at runtime. For activation, list the job under on.needs in the ` +
|
|
91
|
+
`source frontmatter; for a custom job, add it to that job's needs.\n`,
|
|
92
|
+
);
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// gh aw compile leaves a lock alone when its frontmatter and body hashes still match the source.
|
|
98
|
+
// This script then ran over a lock it had already patched: AGENTMEMORY_URL was inserted a second
|
|
99
|
+
// time, the opencode install line was wrapped in itself, and the consumer freshness check could
|
|
100
|
+
// never be clean (Pliny-Bot agentics-checks run 33963600563). The sentinel marks a processed
|
|
101
|
+
// lock; a lock that carries it is linted and otherwise left as it is.
|
|
102
|
+
const SENTINEL = "# post-processed by scripts/compile-agent-workflows.mjs; run it again and nothing changes";
|
|
103
|
+
|
|
104
|
+
for (const file of readdirSync(workflowDirectory)) {
|
|
105
|
+
if (!file.endsWith(".lock.yml")) continue;
|
|
106
|
+
|
|
107
|
+
const path = join(workflowDirectory, file);
|
|
108
|
+
const content = readFileSync(path, "utf8");
|
|
109
|
+
if (content.includes(SENTINEL)) {
|
|
110
|
+
lintLock(file, content);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const patched = content
|
|
114
|
+
.replace(/^(# This file was automatically generated by gh-aw[^\n]*\n)/m, `$1${SENTINEL}\n`)
|
|
115
|
+
.replaceAll("opencode run --print-logs --log-level DEBUG", "opencode run --log-level ERROR")
|
|
116
|
+
.replaceAll("opencode run --print-logs --log-level ERROR", "opencode run --log-level ERROR")
|
|
117
|
+
.replaceAll("opencode run --log-level ERROR", "opencode run --log-level ERROR")
|
|
118
|
+
.replaceAll("--log-level DEBUG", "--log-level ERROR")
|
|
119
|
+
.replace(/GH_AW_INFO_MODEL: "[^"]*"/g, 'GH_AW_INFO_MODEL: "per-agent"')
|
|
120
|
+
.replace(/OPENCODE_MODEL: [^\n]+/g, "OPENCODE_MODEL: ''")
|
|
121
|
+
.replace(/GH_AW_INFO_MODEL_COSTS: '[^']*'/g, 'GH_AW_INFO_MODEL_COSTS: \'{"providers":{}}\'')
|
|
122
|
+
// The MCP gateway is the only thing the agent publishes on the host loopback, so it is the
|
|
123
|
+
// one thing two runners on the same machine cannot share. Honour an inherited port so each
|
|
124
|
+
// runner service can pick its own; everything else is namespaced by its Docker daemon.
|
|
125
|
+
// awf names its containers awf-agent, awf-squid and awf-api-proxy with no way to change
|
|
126
|
+
// them, so two agent jobs on one host recreate each other's containers and the first dies
|
|
127
|
+
// with exit 137. Giving each runner its own user and daemon isolated the containers but
|
|
128
|
+
// broke everything the runners share through the filesystem: awf and gh-aw both write
|
|
129
|
+
// fixed-name files into /tmp, and a file one user creates cannot be overwritten by the
|
|
130
|
+
// next. Six separate failures came from that. One host lock is the smaller trade: agent
|
|
131
|
+
// jobs run one at a time, every other job still uses all the runners, and every user is
|
|
132
|
+
// the same again. The chain is serial anyway, so in practice this only queues one consumer behind
|
|
133
|
+
// the other. Held for the whole agent run, which is deliberate. The lock lives outside the
|
|
134
|
+
// /tmp/gh-aw namespace on purpose: the keying rewrite below would otherwise make the lock
|
|
135
|
+
// file per job, which is silently no lock at all.
|
|
136
|
+
// Agent jobs run in parallel again. Each runner has its own Docker-in-Docker daemon, so
|
|
137
|
+
// awf's fixed container names (awf-agent, awf-squid, awf-api-proxy, awmg-mcpg) live in
|
|
138
|
+
// separate namespaces and cannot recreate each other. gh-aw detects the tcp DOCKER_HOST
|
|
139
|
+
// and switches to its ARC/DinD path by itself, so no flag is needed here. The host-wide
|
|
140
|
+
// flock this replaces made every agent job wait for the previous one.
|
|
141
|
+
// Three host-global resources were left, and concurrent agent jobs fought over all of them.
|
|
142
|
+
// The global npm install rewrote the opencode binary another job was executing and killed it
|
|
143
|
+
// with SIGKILL mid-run; the warm server and its data directory were shared by every runner.
|
|
144
|
+
//
|
|
145
|
+
// All of these sites are step-level run: or env:, where the runner context is available. It
|
|
146
|
+
// is not available at workflow level, which is what broke the staging path earlier.
|
|
147
|
+
//
|
|
148
|
+
// Install only when the pinned version is missing, and take a lock so two jobs starting at
|
|
149
|
+
// once cannot both write the global prefix.
|
|
150
|
+
// gh-aw pins opencode-ai 1.2.14 at every release checked, up to v0.87.5. That version is
|
|
151
|
+
// from 2026-02-25. The harness expects 1.18.9 and this is the current release, so a gh-aw
|
|
152
|
+
// upgrade does not move it and the pin is ours to choose.
|
|
153
|
+
// gh-aw defaults NPM_CONFIG_MIN_RELEASE_AGE to 3 days, which blocks any package
|
|
154
|
+
// published in the last three days with ETARGET "No matching version found ... with a
|
|
155
|
+
// date before". Lowered to 1 so a fix released yesterday is usable. This is a
|
|
156
|
+
// supply-chain cooldown: shortening it accepts a newer package sooner.
|
|
157
|
+
.replace(/NPM_CONFIG_MIN_RELEASE_AGE: ['\"]?3['\"]?/g, "NPM_CONFIG_MIN_RELEASE_AGE: '1'")
|
|
158
|
+
// The MCP gateway runs inside a per-runner Docker-in-Docker daemon. gh-aw publishes it on
|
|
159
|
+
// 127.0.0.1, which is the DinD container's own loopback, while the outer publish forwards to
|
|
160
|
+
// that container's eth0, so the two never meet and gh-aw's health check fails 120 times with
|
|
161
|
+
// ECONNREFUSED. Binding 0.0.0.0 inside the daemon connects them. The host still exposes the
|
|
162
|
+
// port on loopback only, because the DinD container is published as 127.0.0.1:<port>.
|
|
163
|
+
.replaceAll("-p 127.0.0.1:'\"${MCP_GATEWAY_PORT}\"':", "-p '\"${MCP_GATEWAY_PORT}\"':")
|
|
164
|
+
// Each runner needs its own gateway port: four DinD daemons publish through to one host
|
|
165
|
+
// loopback, so two jobs on 8080 would collide. The runner sets it in .env.
|
|
166
|
+
// awf chroots into the Docker daemon's filesystem and requires it to be the runner's own
|
|
167
|
+
// glibc host. A Docker-in-Docker daemon fails with "Detected Alpine/musl host filesystem
|
|
168
|
+
// under /host", and no dind image fixes it: the agent needs the runner's toolchain and
|
|
169
|
+
// workspace, which a separate daemon container never has. So every agent job shares one
|
|
170
|
+
// daemon, awf's container names are fixed, and the jobs must be serialised.
|
|
171
|
+
.replaceAll(' awf --config', ' flock /tmp/agentic-awf.lock awf --config')
|
|
172
|
+
.replaceAll('export MCP_GATEWAY_PORT="8080"', 'export MCP_GATEWAY_PORT="${MCP_GATEWAY_PORT:-8080}"')
|
|
173
|
+
// The agent's safe outputs land in safeoutputs.jsonl, but the collector reads
|
|
174
|
+
// agent_output.json, and nothing in the generated workflow converts one to the other.
|
|
175
|
+
// With the OpenCode engine the tool calls go through the MCP server rather than stdout,
|
|
176
|
+
// so the log parser never produces agent_output.json and the placeholder step writes
|
|
177
|
+
// {"items":[]} over a run that did real work: the job goes green and the pull request
|
|
178
|
+
// is silently dropped. Build the collector's input from what the agent actually emitted.
|
|
179
|
+
.replaceAll("echo '{\"items\":[]}' > /tmp/gh-aw-${{ github.run_id }}/agent_output.json", "if [ -s /tmp/gh-aw-${{ github.run_id }}/safeoutputs.jsonl ]; then jq -s '{items: .}' /tmp/gh-aw-${{ github.run_id }}/safeoutputs.jsonl > /tmp/gh-aw-${{ github.run_id }}/agent_output.json; else echo '{\"items\":[]}' > /tmp/gh-aw-${{ github.run_id }}/agent_output.json; fi")
|
|
180
|
+
// The "Copy Safe Outputs" step runs on the host after the awf container exits. At that
|
|
181
|
+
// point /tmp/gh-aw/ IS the host's /tmp/gh-aw/, where the safeoutputs MCP container wrote
|
|
182
|
+
// patch and bundle files (via the MCP gateway's -v /tmp:/tmp:rw mount). Extend the step
|
|
183
|
+
// to also copy those files to RUNNER_TEMP/gh-aw/ so the upload step can include them.
|
|
184
|
+
// Without this, the upload step's glob /tmp/gh-aw/aw-*.patch runs inside the awf chroot
|
|
185
|
+
// (where /tmp/gh-aw is a different path) and finds nothing. The safe_outputs and conclude
|
|
186
|
+
// jobs then receive no patches in the artifact and silently skip the push.
|
|
187
|
+
.replace(
|
|
188
|
+
' cp "$GH_AW_SAFE_OUTPUTS" /tmp/gh-aw/safeoutputs.jsonl 2>/dev/null || true\n',
|
|
189
|
+
' cp "$GH_AW_SAFE_OUTPUTS" /tmp/gh-aw/safeoutputs.jsonl 2>/dev/null || true\n' +
|
|
190
|
+
' # Copy patch/bundle files generated by the safeoutputs MCP container to\n' +
|
|
191
|
+
' # RUNNER_TEMP/gh-aw/ so the upload step includes them in the artifact.\n' +
|
|
192
|
+
' mkdir -p "${RUNNER_TEMP}/gh-aw"\n' +
|
|
193
|
+
' ls -la /tmp/gh-aw/ 2>/dev/null || true\n' +
|
|
194
|
+
' cp /tmp/gh-aw/aw-*.patch "${RUNNER_TEMP}/gh-aw/" 2>/dev/null || true\n' +
|
|
195
|
+
' cp /tmp/gh-aw/aw-*.bundle "${RUNNER_TEMP}/gh-aw/" 2>/dev/null || true\n' +
|
|
196
|
+
' ls -la "${RUNNER_TEMP}/gh-aw/"aw-* 2>/dev/null || true\n')
|
|
197
|
+
// Add patch/bundle paths to the upload glob so the agent artifact carries what
|
|
198
|
+
// push-agent-branch needs. The anchor is the two adjacent path lines of the
|
|
199
|
+
// "...agent" upload step; the "...agent-output-fallback" upload lists them in the
|
|
200
|
+
// opposite order, so it cannot match. Anchoring matters: the first bare
|
|
201
|
+
// '/tmp/gh-aw/agent_output.json\n' in the file is the placeholder step's echo line,
|
|
202
|
+
// and replacing there corrupted the placeholder into executing the globs as
|
|
203
|
+
// commands while the upload list stayed without bundles. The artifact then carried
|
|
204
|
+
// no bundle, push-agent-branch silently skipped the push, and the gate reported
|
|
205
|
+
// "remediated" on a pull request that was never touched.
|
|
206
|
+
// Only the /tmp/gh-aw globs may be added: a ${{ runner.temp }} path as well would
|
|
207
|
+
// move the upload's least-common-ancestor from /tmp/gh-aw to /, and every file in
|
|
208
|
+
// the artifact (agent_output.json included) would gain a prefix that
|
|
209
|
+
// download-agent-output does not look for.
|
|
210
|
+
.replace(
|
|
211
|
+
' /tmp/gh-aw/safeoutputs.jsonl\n /tmp/gh-aw/agent_output.json\n',
|
|
212
|
+
' /tmp/gh-aw/safeoutputs.jsonl\n' +
|
|
213
|
+
' /tmp/gh-aw/aw-*.patch\n' +
|
|
214
|
+
' /tmp/gh-aw/aw-*.bundle\n' +
|
|
215
|
+
' /tmp/gh-aw/agent_output.json\n')
|
|
216
|
+
// "A failed run is already a red run": report-failure-as-issue: false and
|
|
217
|
+
// GH_AW_REPORT_FAILED_JOBS: "false" were supposed to silence issue creation, but
|
|
218
|
+
// 0.87.5's engine-failure reporter files an "[aw] ... failed" issue anyway (seen as
|
|
219
|
+
// Pliny-Bot #57: an OOM-killed gate produced a fresh issue nobody needs, while the
|
|
220
|
+
// retry belt is the actual remediation). `if: false` keeps the step compiled but
|
|
221
|
+
// never runs it, so the failure stays visible in the run and in the belt's attempt
|
|
222
|
+
// comment, and out of the issue tracker.
|
|
223
|
+
.replace(
|
|
224
|
+
/^([ \t]+)- name: Report failed jobs\n([ \t]*)id: report_failed_jobs\n[ \t]*if: always\(\)\n/m,
|
|
225
|
+
'$1- name: Report failed jobs\n$2id: report_failed_jobs\n$2if: false # never: failures surface in the run and the retry belt\n')
|
|
226
|
+
|
|
227
|
+
// v0.87.5's arc-dind mode stages the engine CLI to a daemon-visible path but assumes the
|
|
228
|
+
// Copilot engine: command -v copilot is empty under engine: opencode and cp "" fails the
|
|
229
|
+
// job before the agent starts. OpenCode needs no staging, because npm -g installs it under
|
|
230
|
+
// the tool-cache prefix inside _work, which the dind daemon shares.
|
|
231
|
+
// Centralised AgentMemory: an always-on App Service; the shim proxies to it when the
|
|
232
|
+
// URL is set and authenticates with the HMAC secret. Local development leaves both
|
|
233
|
+
// unset and keeps the local per-run store.
|
|
234
|
+
.replace(/^env:\n/m, 'env:\n AGENTMEMORY_URL: https://agentmemory-pro-01.azurewebsites.net\n')
|
|
235
|
+
// the secret is scoped to the one step that runs the agent (semgrep: a secret in
|
|
236
|
+
// workflow-level env is visible to every job and step)
|
|
237
|
+
.replaceAll(' OPENAI_BASE_URL: https://forge.plainconcepts.com/v1',
|
|
238
|
+
' OPENAI_BASE_URL: https://forge.plainconcepts.com/v1' + '\n' +
|
|
239
|
+
' AGENTMEMORY_SECRET: ${{ secrets.AGENTMEMORY_SECRET }}')
|
|
240
|
+
// the router passes secrets explicitly (semgrep flags secrets: inherit as over-broad),
|
|
241
|
+
// so the callee must declare everything it accepts
|
|
242
|
+
.replace(/^ COPILOT_GITHUB_TOKEN:/m,
|
|
243
|
+
' AGENTMEMORY_SECRET:' + '\n' + ' required: false' + '\n' + ' COPILOT_GITHUB_TOKEN:')
|
|
244
|
+
.replaceAll(' COPILOT_SRC="$(command -v copilot)"',
|
|
245
|
+
' command -v copilot >/dev/null 2>&1 || { echo "no copilot binary (engine is opencode); skipping"; exit 0; }' + '\n' +
|
|
246
|
+
' COPILOT_SRC="$(command -v copilot)"')
|
|
247
|
+
// "A failed run is already a red run": report-failure-as-issue: false silences one
|
|
248
|
+
// reporter, but gh-aw hardcodes a second one (report_failed_jobs) that files an
|
|
249
|
+
// "[aw] Failed jobs" issue per red run. Same philosophy, same off switch.
|
|
250
|
+
.replaceAll('GH_AW_REPORT_FAILED_JOBS: "true"', 'GH_AW_REPORT_FAILED_JOBS: "false"')
|
|
251
|
+
// gh-aw sees a custom step calling dotnet and injects its own setup-dotnet, which carries
|
|
252
|
+
// no DOTNET_INSTALL_DIR and so tries to write /usr/share/dotnet. The runner user has no
|
|
253
|
+
// sudo, so the job dies with "Permission denied" before the agent starts. The shared
|
|
254
|
+
// baseline step already redirects to the tool cache; this gives every other one the same
|
|
255
|
+
// env, including ones a future gh-aw release injects.
|
|
256
|
+
.replace(
|
|
257
|
+
/^( +)- name: Setup \.NET\n\1 uses: actions\/setup-dotnet@[^\n]*\n\1 with:\n((?:\1 [^\n]*\n)+)(?!\1 env:)/gm,
|
|
258
|
+
(_m, indent, withBody) =>
|
|
259
|
+
indent + '- name: Setup .NET\n' + indent + ' uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0\n' +
|
|
260
|
+
indent + ' with:\n' + withBody +
|
|
261
|
+
indent + ' env:\n' + indent + ' DOTNET_INSTALL_DIR: ${{ runner.tool_cache }}/dotnet\n')
|
|
262
|
+
.replace(/opencode-ai@[0-9][0-9.]*/g, 'opencode-ai@' + OPENCODE_VERSION)
|
|
263
|
+
// gh-aw installs with --ignore-scripts, which blocks opencode's own postinstall. That
|
|
264
|
+
// script downloads the platform binary, so 1.18 fails at first use with "opencode-ai's
|
|
265
|
+
// postinstall script was not run". 1.2.14 did not need it. Run only opencode's postinstall
|
|
266
|
+
// explicitly, so every other package's scripts stay blocked.
|
|
267
|
+
.replace(
|
|
268
|
+
/npm install --ignore-scripts -g opencode-ai@([0-9][0-9.]*)/g,
|
|
269
|
+
(_m, v) =>
|
|
270
|
+
"opencode --version 2>/dev/null | grep -qF '" + v + "' || " +
|
|
271
|
+
"flock /tmp/opencode-install.lock sh -c 'npm install --ignore-scripts -g opencode-ai@" + v +
|
|
272
|
+
" && cd \"$(npm root -g)/opencode-ai\" && node postinstall.mjs' # opencode-ai@" + v)
|
|
273
|
+
// One warm server per runner, on its own port, with its own data directory. Keyed on the
|
|
274
|
+
// runner rather than the run so a runner keeps its server warm between its own jobs.
|
|
275
|
+
// No double quotes here: the enclosing run: is a double-quoted YAML scalar, so a quote
|
|
276
|
+
// would have to be escaped. The default has no spaces, so bare is safe shell.
|
|
277
|
+
.replace(/\/tmp\/opencode-data(?!-\$\{\{)/g, () => '/tmp/opencode-data-${{ runner.name }}');
|
|
278
|
+
|
|
279
|
+
let rewritten = patched;
|
|
280
|
+
// A queued implement executes hours after its run was created, but actions/checkout
|
|
281
|
+
// without a ref checks out github.sha, which GitHub pins at run creation. Five children
|
|
282
|
+
// queued together at 02:01 all carried the 02:01 base; once the first sibling merged,
|
|
283
|
+
// every later push became a rebase onto a moved parent, which gh-aw's signed-commit
|
|
284
|
+
// push cannot do (it dies with "cannot rebase: You have unstaged changes" and files the
|
|
285
|
+
// pull request as an issue instead of a pull request). Checking out the branch tip at
|
|
286
|
+
// execution time makes the commit parent current main; the implement-global queue
|
|
287
|
+
// already keeps sibling merges out of the window while the agent runs.
|
|
288
|
+
if (file === "agent-implement.lock.yml") {
|
|
289
|
+
const start = rewritten.indexOf("\n agent:\n");
|
|
290
|
+
const rest = start === -1 ? "" : rewritten.slice(start + 1);
|
|
291
|
+
const next = rest.search(/\n [a-z_][a-zA-Z_-]*:\n/);
|
|
292
|
+
if (start !== -1 && next !== -1) {
|
|
293
|
+
const end = start + 1 + next;
|
|
294
|
+
const span = rewritten.slice(start, end).replace(
|
|
295
|
+
/(uses: actions\/checkout@[^\n]*\n(\s+)with:\n(?:\2 [^\n]+\n)*)/,
|
|
296
|
+
(whole, _block, indent) =>
|
|
297
|
+
whole.includes("ref:") ? whole : whole + indent + " ref: ${{ github.event.repository.default_branch }}\n",
|
|
298
|
+
);
|
|
299
|
+
rewritten = rewritten.slice(0, start) + span + rewritten.slice(end);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Guard the two rewrites the compiled agent jobs cannot work without. The anchors are
|
|
304
|
+
// upstream template text: when a gh-aw upgrade reshapes either step, the silent
|
|
305
|
+
// failure mode returns (an artifact with no bundle, a skipped push, a green gate on
|
|
306
|
+
// an untouched pull request). Failing the compile is the only loud signal there is.
|
|
307
|
+
for (const check of [
|
|
308
|
+
{ name: "bundle upload glob", ok: /\n( +)- name: Upload agent artifacts\n\1 if: always\(\)\n\1 continue-on-error: true\n\1 uses: actions\/upload-artifact@[^\n]*\n\1 with:\n\1 name: \$\{\{ needs\.activation\.outputs\.artifact_prefix \}\}agent\n\1 path: \|\n(?:\1 [^\n]*\n)*\1 \/tmp\/gh-aw\/aw-\*\.bundle\n/ },
|
|
309
|
+
{ name: "placeholder step intact", ok: /\n( +)- name: Write agent output placeholder if missing\n\1 if: always\(\)\n\1 run: \|\n\1 if \[ ! -f \/tmp\/gh-aw\/agent_output\.json \]; then\n\1 echo '\{"items":\[\]\}' > \/tmp\/gh-aw\/agent_output\.json\n\1 fi\n/ },
|
|
310
|
+
{ name: "failed-jobs reporter disabled", ok: /- name: Report failed jobs\n[ \t]*id: report_failed_jobs\n[ \t]*if: false[^\n]*\n/ },
|
|
311
|
+
]) {
|
|
312
|
+
if (!check.ok.test(rewritten)) {
|
|
313
|
+
process.stderr.write(
|
|
314
|
+
`compile patch "${check.name}" no longer matches in ${file}: the gh-aw template changed. ` +
|
|
315
|
+
`Re-anchor the rewrite in loops/scripts/compile-agent-workflows.mjs, or agent pushes are silently dropped.\n`,
|
|
316
|
+
);
|
|
317
|
+
process.exitCode = 1;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (!rewritten.includes(SENTINEL)) {
|
|
322
|
+
process.stderr.write(
|
|
323
|
+
`${file}: the generated-file header changed and the post-processing sentinel was not placed; ` +
|
|
324
|
+
`re-anchor the SENTINEL insert in loops/scripts/compile-agent-workflows.mjs.\n`,
|
|
325
|
+
);
|
|
326
|
+
process.exitCode = 1;
|
|
327
|
+
}
|
|
328
|
+
lintLock(file, rewritten);
|
|
329
|
+
|
|
330
|
+
if (rewritten !== content) writeFileSync(path, rewritten);
|
|
331
|
+
}
|