@plainconceptsplatform/workflows 0.6.1 → 0.16.2

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.
Files changed (58) hide show
  1. package/README.md +107 -88
  2. package/dist/catalog-installation.d.ts +39 -2
  3. package/dist/catalog-installation.js +172 -109
  4. package/dist/index.js +128 -73
  5. package/dist/package-baseline.d.ts +25 -0
  6. package/dist/package-baseline.js +138 -0
  7. package/dist/route-processing.d.ts +0 -2
  8. package/dist/route-processing.js +22 -91
  9. package/dist/stack-defaults.js +18 -12
  10. package/dist/tui.js +27 -43
  11. package/dist/worker-env.d.ts +46 -0
  12. package/dist/worker-env.js +179 -0
  13. package/dist/workflow-catalog.d.ts +4 -2
  14. package/dist/workflow-catalog.js +5 -3
  15. package/loops/actions/add-issue-labels/action.yml +20 -0
  16. package/loops/actions/audit-close/action.yml +180 -128
  17. package/loops/actions/classify-route/classify-route.sh +8 -2
  18. package/loops/actions/housekeeping/action.yml +251 -0
  19. package/loops/actions/merge-agent-pr/action.yml +13 -0
  20. package/loops/actions/report-workflow-errors/action.yml +414 -0
  21. package/loops/actions/validate-merge-gate-output/validate-merge-gate-output.sh +13 -1
  22. package/loops/actions/validate-triage-output/action.yml +1 -1
  23. package/loops/actions/validate-triage-output/validate-triage-output.sh +9 -5
  24. package/loops/actions/verify-composite-actions/verify-composite-actions.sh +53 -0
  25. package/loops/actions/verify-route-matrix/verify-route-matrix.sh +911 -170
  26. package/loops/templates/agentics/agentics-error-report.yml +98 -0
  27. package/loops/templates/opencode/opencode.ci.json +1 -1
  28. package/loops/workflows/agent-apply-review.md +438 -469
  29. package/loops/workflows/agent-audit.md +200 -213
  30. package/loops/workflows/agent-implement.md +591 -640
  31. package/loops/workflows/agent-merge-gate.md +826 -844
  32. package/loops/workflows/agent-refine.md +590 -633
  33. package/loops/workflows/agent-release.md +244 -258
  34. package/loops/workflows/agent-triage.md +476 -447
  35. package/loops/workflows/authorize-bot-work.yml +26 -6
  36. package/loops/workflows/shared/platform-defaults.md +18 -1
  37. package/loops/workflows/work-router.yml +1185 -1038
  38. package/package.json +9 -8
  39. package/dist/action-validation.test.d.ts +0 -1
  40. package/dist/action-validation.test.js +0 -87
  41. package/dist/catalog-installation.test.d.ts +0 -1
  42. package/dist/catalog-installation.test.js +0 -485
  43. package/dist/catalog-listing.test.d.ts +0 -1
  44. package/dist/catalog-listing.test.js +0 -150
  45. package/dist/index.test.d.ts +0 -1
  46. package/dist/index.test.js +0 -273
  47. package/dist/repository-inspection.test.d.ts +0 -1
  48. package/dist/repository-inspection.test.js +0 -77
  49. package/dist/route-processing.test.d.ts +0 -1
  50. package/dist/route-processing.test.js +0 -283
  51. package/dist/stack-defaults.test.d.ts +0 -1
  52. package/dist/stack-defaults.test.js +0 -266
  53. package/dist/tui.test.d.ts +0 -1
  54. package/dist/tui.test.js +0 -249
  55. package/dist/workflow-catalog.test.d.ts +0 -1
  56. package/dist/workflow-catalog.test.js +0 -29
  57. package/loops/actions/stale-recovery/action.yml +0 -288
  58. package/loops/actions/update-changelog/action.yml +0 -113
@@ -0,0 +1,414 @@
1
+ # Managed by @plainconceptsplatform/workflows. Source: loops/actions/report-workflow-errors/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
+ name: Report workflow errors upstream
3
+ description: >-
4
+ Summarise the last day of failures in the workflows this package ships and file the summary
5
+ upstream so the package can be improved. Deterministic: no model runs, and nothing that could
6
+ identify this repository or its contents leaves it.
7
+
8
+ inputs:
9
+ token:
10
+ description: Token for THIS repository. Read-only; used to list runs and jobs.
11
+ required: true
12
+ upstream-token:
13
+ description: >-
14
+ Token that can open an issue in the upstream repository. Empty means compute the report,
15
+ attach it to the run, and file nothing.
16
+ required: false
17
+ default: ''
18
+ upstream-repo:
19
+ description: The repository the report is filed in, as owner/name.
20
+ required: false
21
+ default: PlainConceptsPlatform/Agentic-Workflows
22
+ lookback-hours:
23
+ description: How far back to look for failures.
24
+ required: false
25
+ default: '24'
26
+ dry-run:
27
+ description: Compute and print the report, file nothing.
28
+ required: false
29
+ default: 'false'
30
+
31
+ outputs:
32
+ filed:
33
+ description: The upstream issue number, or empty if nothing was filed.
34
+ value: ${{ steps.report.outputs.filed }}
35
+
36
+ runs:
37
+ using: composite
38
+ steps:
39
+ - name: Collect and file
40
+ id: report
41
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
42
+ env:
43
+ UPSTREAM_TOKEN: ${{ inputs.upstream-token }}
44
+ UPSTREAM_REPO: ${{ inputs.upstream-repo }}
45
+ LOOKBACK_HOURS: ${{ inputs.lookback-hours }}
46
+ DRY_RUN: ${{ inputs.dry-run }}
47
+ with:
48
+ github-token: ${{ inputs.token }}
49
+ script: |
50
+ // Every consumer of this package is a private repository, and this is the one job that
51
+ // sends anything out of one. The rule it is built around: no free text ever leaves
52
+ // here. Not a log line, not a branch name, not an issue title, not a file path. What
53
+ // leaves is a fixed set of enumerable facts about workflows this package itself
54
+ // ships -- their names, their job and step names, conclusions, timings and counts --
55
+ // plus the NAME of a matched error pattern from the catalogue below. The final body
56
+ // is checked against a leak scanner and the job fails rather than files if the
57
+ // scanner trips.
58
+
59
+ const dryRun = process.env.DRY_RUN === 'true';
60
+ const upstreamToken = process.env.UPSTREAM_TOKEN;
61
+ const [upstreamOwner, upstreamName] = process.env.UPSTREAM_REPO.split('/');
62
+ const since = new Date(Date.now() - Number(process.env.LOOKBACK_HOURS) * 3600 * 1000);
63
+
64
+ // Only workflows this package ships. A consumer's own workflow name is theirs and can
65
+ // describe a product, a customer or an environment -- Lyceum really does have
66
+ // `name: Deploy app to ${{ inputs.environment }}` -- so an allowlist by filename is the
67
+ // boundary, and it is the only thing keeping those names out. Anything not matching is
68
+ // counted and otherwise ignored.
69
+ //
70
+ // Exactly the filenames the package installs, and no pattern that admits a name it does
71
+ // not. The previous version was written as a shape (`\.(yml|lock\.yml)$` over a group of
72
+ // stems) and so admitted 22 names of which 11 are never shipped: the seven workers exist
73
+ // as `.md` sources compiled to `.lock.yml`, never as `agent-refine.yml`, and there is no
74
+ // `work-router.lock.yml`. A consumer writing their own `agent-release.yml` would have had
75
+ // its job and step names read and reported.
76
+ const OWNED = new Set([
77
+ 'work-router.yml',
78
+ 'authorize-bot-work.yml',
79
+ 'agentics-checks.yml',
80
+ 'agentics-maintenance.yml',
81
+ ...['refine', 'implement', 'triage', 'apply-review', 'merge-gate', 'audit', 'release']
82
+ .map((route) => `agent-${route}.lock.yml`),
83
+ ]);
84
+ const ownedName = (path) => (path ?? '').split('/').pop() ?? '';
85
+
86
+ // The catalogue. Each entry is a failure shape worth fixing in the package. Only the
87
+ // `id` is ever reported -- never the text that matched it, because the surrounding log
88
+ // line carries repository paths, branch names and issue titles.
89
+ const CATALOGUE = [
90
+ { id: 'runner-never-assigned', test: /waiting for a runner|no runner matching|requested labels/i, note: 'A job waited for a self-hosted runner that never arrived.' },
91
+ { id: 'runner-lost-mid-job', test: /lost communication with the server|runner has received a shutdown signal|The self-hosted runner:.*lost/i, note: 'The runner disappeared while a job was running.' },
92
+ { id: 'job-cancelled-by-timeout', test: /The job running on runner .* has exceeded the maximum execution time|timeout-minutes/i, note: 'A job hit its timeout instead of finishing.' },
93
+ { id: 'out-of-disk', test: /no space left on device|You are running out of disk space/i, note: 'The runner ran out of disk.' },
94
+ { id: 'out-of-memory', test: /JavaScript heap out of memory|Killed\s+process|OOMKilled/i, note: 'A step was killed for memory.' },
95
+ { id: 'jq-error', test: /^jq: error|jq: error \(at/im, note: 'A jq filter in the router or an action died on its input.' },
96
+ { id: 'gh-api-403', test: /HTTP 403|Resource not accessible by integration/i, note: 'A step called an endpoint its token has no scope for.' },
97
+ { id: 'gh-api-404', test: /HTTP 404/i, note: 'A step called an endpoint or resource that does not exist.' },
98
+ { id: 'gh-api-rate-limit', test: /API rate limit exceeded|secondary rate limit/i, note: 'A step was rate limited.' },
99
+ { id: 'gh-api-409-conflict', test: /HTTP 409|Update is not a fast forward/i, note: 'A push or merge raced another writer.' },
100
+ { id: 'model-quota', test: /quota|insufficient_quota|429 Too Many Requests/i, note: 'The model gateway refused the request for quota reasons.' },
101
+ { id: 'model-gateway-unreachable', test: /ECONNREFUSED|ETIMEDOUT|getaddrinfo|502 Bad Gateway|503 Service Unavailable/i, note: 'The model gateway or another network dependency was unreachable.' },
102
+ { id: 'agent-produced-no-output', test: /no agent output|output file (is )?(missing|empty)|safe.outputs.*empty/i, note: 'The agent finished without emitting any safe output.' },
103
+ { id: 'lock-out-of-date', test: /lock file is out of date|recompile|\.lock\.yml.*differs/i, note: 'A compiled lock file did not match its source.' },
104
+ { id: 'action-not-found', test: /Can't find '.*' in|Unable to resolve action/i, note: 'A workflow referenced an action or path that is not present.' },
105
+ { id: 'yaml-or-expression-invalid', test: /Invalid workflow file|Unrecognized named-value|Unexpected symbol/i, note: 'A workflow failed to parse or an expression did not evaluate.' },
106
+ ];
107
+
108
+ // The leak scanner. Runs on the finished body, and its failure is fatal: a report that
109
+ // might carry private information is not filed at all. Deliberately paranoid, because
110
+ // the cost of a false positive is one missing daily report and the cost of a false
111
+ // negative is a private repository described in a public-facing issue.
112
+ const owner = context.repo.owner;
113
+ const repo = context.repo.repo;
114
+ const leakChecks = [
115
+ { what: 'the repository name', test: new RegExp(`\\b${repo.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'i') },
116
+ { what: 'the owner name', test: new RegExp(`\\b${owner.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'i') },
117
+ { what: 'a github.com URL', test: /https?:\/\/[^\s)]*github\.com\/[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+/ },
118
+ { what: 'an email address', test: /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/ },
119
+ { what: 'an absolute path', test: /(?:^|\s)(?:\/(?:home|Users|github|runner|mnt)\/|[A-Za-z]:\\)/m },
120
+ { what: 'a long hex or base64 blob that could be a token or a commit', test: /\b(?:gh[pousr]_[A-Za-z0-9]{16,}|[A-Za-z0-9+/]{40,}={0,2}|[0-9a-f]{32,})\b/ },
121
+ { what: 'an issue or pull request reference', test: /(?:^|[^A-Za-z0-9_/])#\d+/ },
122
+ { what: 'a branch or ref path', test: /\brefs\/heads\/|\b(?:feature|fix|chore|bot)\/[A-Za-z0-9._-]+/ },
123
+ ];
124
+
125
+ // Which version of the package is reporting. Without this a bug fixed weeks ago keeps
126
+ // arriving upstream with no way to tell it is stale: the first report filed by this
127
+ // job was 19 occurrences of a jq bug that a release had already fixed, and nothing in
128
+ // it said so. The version is the package's own name for itself, read from the
129
+ // ownership header the installer stamps, so it carries nothing of the repository.
130
+ let packageVersion = 'unknown';
131
+ try {
132
+ const header = require('node:fs')
133
+ .readFileSync('.github/workflows/work-router.yml', 'utf8')
134
+ .split('\n')[0];
135
+ packageVersion = /@plainconceptsplatform\/workflows@([0-9][0-9A-Za-z.\-+]*)/.exec(header)?.[1] ?? 'unknown';
136
+ } catch {
137
+ core.info('could not read the installed package version from the router header');
138
+ }
139
+
140
+ const runs = await github.paginate(github.rest.actions.listWorkflowRunsForRepo, {
141
+ ...context.repo, created: `>=${since.toISOString()}`, per_page: 100,
142
+ });
143
+
144
+ // signature -> what we know about it. The signature is the dedup key both here and
145
+ // upstream, and every part of it is package-owned or an enumerated value.
146
+ //
147
+ // THE FINDING SHAPE IS THE PRIVACY BOUNDARY. bodyFor() renders a finding, so a field
148
+ // added here is a field sent to another repository. These eight are all
149
+ // package-owned names or enumerated values; nothing derived from a log, a branch, a
150
+ // path or an issue belongs on this object. The route matrix asserts this exact list,
151
+ // so adding a ninth field fails the build rather than leaking on the next cron.
152
+ const FINDING_FIELDS = ['workflow', 'job', 'step', 'conclusion', 'patternId', 'count', 'runnerLabels', 'attempts'];
153
+ const findings = new Map();
154
+ let ownedRuns = 0;
155
+ let ownedFailures = 0;
156
+ let skippedForeign = 0;
157
+ let queueWaitTotal = 0;
158
+ let queueWaitCount = 0;
159
+ let queueWaitWorst = 0;
160
+
161
+ // A run that never gets a runner never fails: it sits queued until GitHub expires it
162
+ // a day later. On a two-VM fleet that is the most common way work disappears, and it
163
+ // is invisible in every failure count, so it is detected by state and age instead.
164
+ const STUCK_AFTER_MS = 45 * 60 * 1000;
165
+ let stuckInQueue = 0;
166
+
167
+ for (const run of runs) {
168
+ const file = ownedName(run.path);
169
+ if (!OWNED.has(file)) { skippedForeign += 1; continue; }
170
+ ownedRuns += 1;
171
+
172
+ if (['queued', 'waiting', 'pending'].includes(run.status) &&
173
+ Date.now() - new Date(run.created_at).getTime() > STUCK_AFTER_MS) {
174
+ stuckInQueue += 1;
175
+ const signature = `${file} · (whole run) · (never started) · queued · runner-never-assigned`;
176
+ const seen = findings.get(signature) ?? {
177
+ workflow: file, job: '(whole run)', step: '(never started)',
178
+ conclusion: 'queued', patternId: 'runner-never-assigned', count: 0,
179
+ runnerLabels: new Set(), attempts: new Set(),
180
+ };
181
+ seen.count += 1;
182
+ seen.attempts.add(run.run_attempt ?? 1);
183
+ findings.set(signature, seen);
184
+ continue;
185
+ }
186
+
187
+ if (!['failure', 'cancelled', 'timed_out', 'startup_failure'].includes(run.conclusion)) continue;
188
+ ownedFailures += 1;
189
+
190
+ let jobs = [];
191
+ try {
192
+ jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRunAttempt, {
193
+ ...context.repo, run_id: run.id, attempt_number: run.run_attempt ?? 1, per_page: 100,
194
+ });
195
+ } catch { continue; }
196
+
197
+ for (const job of jobs) {
198
+ if (job.started_at && job.created_at) {
199
+ const wait = (new Date(job.started_at) - new Date(job.created_at)) / 1000;
200
+ if (wait >= 0) {
201
+ queueWaitTotal += wait; queueWaitCount += 1;
202
+ queueWaitWorst = Math.max(queueWaitWorst, Math.round(wait));
203
+ }
204
+ }
205
+ if (!['failure', 'cancelled', 'timed_out'].includes(job.conclusion)) continue;
206
+
207
+ const step = (job.steps ?? []).find((s) => ['failure', 'timed_out'].includes(s.conclusion));
208
+ // Job and step names come from files this package ships, so they are the
209
+ // package's own words. A `run-name` is not: it interpolates issue titles.
210
+ const stepName = step?.name ?? '(no failing step recorded)';
211
+
212
+ let patternId = 'unrecognised';
213
+ try {
214
+ const { data: log } = await github.rest.actions.downloadJobLogsForWorkflowRun({
215
+ ...context.repo, job_id: job.id,
216
+ });
217
+ const text = typeof log === 'string' ? log : Buffer.from(log).toString('utf8');
218
+ // The tail is where the failure is, and reading less of the log is less to get
219
+ // wrong. Only the matched entry's id crosses into the report.
220
+ const tail = text.slice(-20000);
221
+ patternId = CATALOGUE.find((entry) => entry.test.test(tail))?.id ?? 'unrecognised';
222
+ } catch {
223
+ patternId = 'log-unavailable';
224
+ }
225
+
226
+ const signature = `${file} · ${job.name} · ${stepName} · ${job.conclusion} · ${patternId}`;
227
+ const seen = findings.get(signature) ?? {
228
+ workflow: file, job: job.name, step: stepName,
229
+ conclusion: job.conclusion, patternId, count: 0,
230
+ runnerLabels: new Set(), attempts: new Set(),
231
+ };
232
+ seen.count += 1;
233
+ seen.attempts.add(run.run_attempt ?? 1);
234
+ // A pool label is the one value on a finding that the CONSUMER writes, and the
235
+ // installer deliberately preserves theirs across updates (preserveRunnerPool in
236
+ // cli/src/worker-env.ts). A pool named for a customer, a tenant or an environment --
237
+ // `contoso-prod-arc`, `retail-eu-runners` -- would have been filed upstream verbatim,
238
+ // and no leak check would have caught it: the scanner looks for this repository's
239
+ // name, its owner, URLs, emails, paths and token shapes, and a pool name is none of
240
+ // those. Bucket it. The catalogue asks whether the self-hosted fleet was involved,
241
+ // never what it is called, so the bucket loses no diagnostic value.
242
+ for (const label of job.labels ?? []) {
243
+ seen.runnerLabels.add(label === 'ubuntu-latest' ? 'github-hosted' : 'self-hosted');
244
+ }
245
+ findings.set(signature, seen);
246
+ }
247
+ }
248
+
249
+ const catalogueNote = (id) => CATALOGUE.find((entry) => entry.id === id)?.note
250
+ ?? (id === 'log-unavailable' ? 'The job log could not be read, so the failure could not be classified.'
251
+ : 'The log matched no known failure shape. Worth adding one to the catalogue.');
252
+
253
+ const ranked = [...findings.values()].sort((a, b) => b.count - a.count);
254
+ const hours = process.env.LOOKBACK_HOURS;
255
+
256
+ // Enforce the boundary at run time as well as in the build. A field that reached a
257
+ // finding by some path the static check did not see stops the job here rather than
258
+ // being rendered into an issue in another repository.
259
+ for (const finding of ranked) {
260
+ const unexpected = Object.keys(finding).filter((key) => !FINDING_FIELDS.includes(key));
261
+ if (unexpected.length > 0) {
262
+ core.setFailed(`a finding carries ${unexpected.join(', ')}, which is not in the reportable field list. Nothing was filed.`);
263
+ return;
264
+ }
265
+ }
266
+
267
+ const bodyFor = (finding) => [
268
+ `<!-- pcp-error-report: ${finding.workflow}|${finding.job}|${finding.step}|${finding.patternId} -->`,
269
+ '',
270
+ 'Filed automatically by the `report-workflow-errors` job in a repository that installs',
271
+ 'this package. It carries no information about that repository: only the names this',
272
+ 'package gives its own workflows, jobs and steps, and a classification of the failure.',
273
+ '',
274
+ '| | |',
275
+ '|---|---|',
276
+ `| Workflow | \`${finding.workflow}\` |`,
277
+ `| Job | \`${finding.job}\` |`,
278
+ `| Failing step | \`${finding.step}\` |`,
279
+ `| Conclusion | \`${finding.conclusion}\` |`,
280
+ `| Classification | \`${finding.patternId}\` |`,
281
+ `| Runner labels | ${[...finding.runnerLabels].map((l) => `\`${l}\``).join(', ') || 'not reported'} |`,
282
+ `| Occurrences in the last ${hours}h | ${finding.count} |`,
283
+ `| Re-run attempts involved | ${[...finding.attempts].sort().join(', ')} |`,
284
+ `| Package version reporting | \`${packageVersion}\` |`,
285
+ '',
286
+ `**What this classification means.** ${catalogueNote(finding.patternId)}`,
287
+ '',
288
+ '### Occurrences',
289
+ '',
290
+ `- ${new Date().toISOString().slice(0, 10)}: ${finding.count} in ${hours}h, on \`${packageVersion}\``,
291
+ ].join('\n');
292
+
293
+ const titleFor = (finding) =>
294
+ `${finding.workflow}: ${finding.patternId} in "${finding.step}"`;
295
+
296
+ // The scanner. A body that trips it is never filed, and the job goes red so the
297
+ // pattern that produced it gets fixed rather than quietly dropped every night.
298
+ const scan = (text, label) => {
299
+ const tripped = leakChecks.filter((check) => check.test.test(text));
300
+ if (tripped.length === 0) return true;
301
+ core.error(`${label} was withheld: the leak scanner matched ${tripped.map((t) => t.what).join('; ')}`);
302
+ return false;
303
+ };
304
+
305
+ const summaryRows = ranked.map((f) => [
306
+ `\`${f.workflow}\``, `\`${f.job}\``, `\`${f.patternId}\``, String(f.count),
307
+ ]);
308
+ await core.summary
309
+ .addHeading('Workflow error report', 2)
310
+ .addList([
311
+ `Runs from workflows this package ships: ${ownedRuns}`,
312
+ `Of those, failed: ${ownedFailures}`,
313
+ `Runs from the repository's own workflows, not inspected: ${skippedForeign}`,
314
+ // This job's own workflow is not on the allowlist, which is right -- it would be
315
+ // reporting on itself -- but it means a failure here reaches nobody upstream. Say so
316
+ // where someone reading a run will see it, rather than leaving it to be found out.
317
+ 'This report does not cover itself: a failure in this job shows up in this repository only.',
318
+ `Runs still queued after 45 minutes, so no runner ever took them: ${stuckInQueue}`,
319
+ `Distinct failure signatures: ${ranked.length}`,
320
+ queueWaitCount > 0
321
+ ? `Runner queue wait: ${Math.round(queueWaitTotal / queueWaitCount)}s mean, ${queueWaitWorst}s worst`
322
+ : 'Runner queue wait: no jobs started in the window',
323
+ ])
324
+ .addTable([
325
+ [{ data: 'Workflow', header: true }, { data: 'Job', header: true }, { data: 'Classification', header: true }, { data: 'Count', header: true }],
326
+ ...summaryRows,
327
+ ])
328
+ .write();
329
+
330
+ if (ranked.length === 0) {
331
+ core.info('No failures in the window for any workflow this package ships.');
332
+ core.setOutput('filed', '');
333
+ return;
334
+ }
335
+
336
+ // Build every report first and scan them all, so a leak is reported once with the
337
+ // full picture rather than one night at a time.
338
+ const reports = [];
339
+ let leaked = 0;
340
+ for (const finding of ranked) {
341
+ const title = titleFor(finding);
342
+ const body = bodyFor(finding);
343
+ if (!scan(`${title}\n${body}`, `The report for ${finding.patternId}`)) { leaked += 1; continue; }
344
+ reports.push({ finding, title, body });
345
+ core.info(`report ready: ${title} (${finding.count})`);
346
+ }
347
+
348
+ if (!upstreamToken) {
349
+ // Not silent and not red: the report exists in the job summary, and the run says
350
+ // plainly why it went no further.
351
+ core.warning(`${reports.length} report(s) computed but not filed: no upstream token is configured. The full report is in this job summary.`);
352
+ core.setOutput('filed', '');
353
+ if (leaked > 0) core.setFailed(`${leaked} report(s) were withheld by the leak scanner; fix the field that carried private text.`);
354
+ return;
355
+ }
356
+
357
+ const upstream = getOctokit(upstreamToken);
358
+ const filed = [];
359
+
360
+ for (const { finding, title, body } of reports) {
361
+ const marker = body.split('\n')[0];
362
+ // One issue per signature, updated rather than repeated. Searching by the marker
363
+ // keeps that true across every consumer: two repositories hitting the same package
364
+ // bug land on the same issue and its count is the number that matters.
365
+ let existing;
366
+ try {
367
+ const { data } = await upstream.rest.search.issuesAndPullRequests({
368
+ q: `repo:${upstreamOwner}/${upstreamName} is:issue is:open in:body "${marker}"`,
369
+ per_page: 5,
370
+ });
371
+ existing = data.items.find((item) => (item.body ?? '').includes(marker));
372
+ } catch (error) {
373
+ core.warning(`could not search upstream for an existing report: HTTP ${error.status ?? '?'}`);
374
+ }
375
+
376
+ if (dryRun) {
377
+ core.info(`[dry-run] would ${existing ? `append to #${existing.number}` : 'open an issue'}: ${title}`);
378
+ continue;
379
+ }
380
+
381
+ try {
382
+ if (existing) {
383
+ // Append one dated line rather than rewriting the body, so the history of how
384
+ // often this fires stays readable.
385
+ const line = `- ${new Date().toISOString().slice(0, 10)}: ${finding.count} in ${hours}h, on \`${packageVersion}\``;
386
+ const updated = (existing.body ?? '').includes(line)
387
+ ? existing.body
388
+ : `${existing.body}\n${line}`;
389
+ if (!scan(updated, `The appended report for ${finding.patternId}`)) { leaked += 1; continue; }
390
+ await upstream.rest.issues.update({
391
+ owner: upstreamOwner, repo: upstreamName,
392
+ issue_number: existing.number, body: updated,
393
+ });
394
+ filed.push(existing.number);
395
+ core.info(`appended to ${upstreamOwner}/${upstreamName}#${existing.number}`);
396
+ } else {
397
+ const { data: created } = await upstream.rest.issues.create({
398
+ owner: upstreamOwner, repo: upstreamName, title, body,
399
+ labels: ['fleet-error-report'],
400
+ });
401
+ filed.push(created.number);
402
+ core.info(`opened ${upstreamOwner}/${upstreamName}#${created.number}`);
403
+ }
404
+ } catch (error) {
405
+ // A missing label, a token without issues:write, a repository that moved. Say so;
406
+ // do not fail the whole report for one signature.
407
+ core.warning(`could not file the report for ${finding.patternId}: HTTP ${error.status ?? '?'} ${error.message ?? ''}`);
408
+ }
409
+ }
410
+
411
+ core.setOutput('filed', filed.join(','));
412
+ if (leaked > 0) {
413
+ core.setFailed(`${leaked} report(s) were withheld by the leak scanner. Nothing was filed for them; fix the field that carried private text.`);
414
+ }
@@ -26,8 +26,20 @@ jq -r --arg issue "$issue_number" --arg conclusion "$ci_conclusion" '
26
26
  )
27
27
  | .[0] // "invalid") as $outcome
28
28
  | ([$items[] | select(.type == "push_to_pull_request_branch")] | length) as $pushes
29
+ # remediated used to require conclusion == "failure", which threw correct work away. The prompt
30
+ # tells the agent to merge main in, verify and push when CI is green but the pull request
31
+ # conflicts. That is a real and common state: a conflicting pull request has no merge ref, so
32
+ # GitHub can never run CI on that head, and the belt falls back to the last verdict on the
33
+ # branch, which is usually success. The agent did the job, the validator called it invalid,
34
+ # conclude was skipped, and because this worker stages its outputs the resolved merge commit
35
+ # was discarded. The belt then dispatched again on the same verdict, up to six times, each a
36
+ # full run on the single-slot merge belt. A push carrying a remediated verdict is remediation
37
+ # whatever CI last said; what still matters is that exactly one push comes with it.
38
+ #
39
+ # No apostrophes in here. This block sits inside the single-quoted jq program, and one
40
+ # apostrophe closes that string and breaks the script.
29
41
  | if $outcome == "merge" and $conclusion == "success" and $pushes == 0 then "merge"
30
- elif $outcome == "remediated" and $conclusion == "failure" and $pushes == 1 then "remediated"
42
+ elif $outcome == "remediated" and $pushes == 1 then "remediated"
31
43
  elif $outcome == "review" and $pushes == 0 then "review"
32
44
  else "invalid"
33
45
  end
@@ -13,7 +13,7 @@ outputs:
13
13
  description: Whether the output contains a usable triage comment with a verdict.
14
14
  value: ${{ steps.validate.outputs.valid }}
15
15
  outcome:
16
- description: "Deterministic triage outcome: pass, needs-info, block, or invalid."
16
+ description: "Deterministic triage outcome: pass, needs-info, needs-maintainer, block, or invalid."
17
17
  value: ${{ steps.validate.outputs.outcome }}
18
18
  runs:
19
19
  using: composite
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env bash
2
2
  # Managed by @plainconceptsplatform/workflows. Source: loops/actions/validate-triage-output/validate-triage-output.sh. Update with `workflows update --force`; consumer edits may be overwritten.
3
- # Print the deterministic triage outcome: pass, needs-info, block, or invalid.
3
+ # Print the deterministic triage outcome: pass, needs-info, needs-maintainer, block, or invalid.
4
+ #
5
+ # needs-maintainer and block are both refusals of product-owner intake, and they part company on what
6
+ # happens next: needs-maintainer keeps the issue open with the review label so a maintainer can take it
7
+ # on, block closes it. Neither value is a substring of another, so the alternation order below is free.
4
8
 
5
9
  set -euo pipefail
6
10
 
@@ -13,21 +17,21 @@ if [ ! -f "$output_file" ] || ! jq -e '.items | arrays' "$output_file" >/dev/nul
13
17
  fi
14
18
 
15
19
  # The agent emits exactly one add_comment on the source issue. The comment body
16
- # must contain a verdict line matching **Verdict:** pass|needs-info|block.
20
+ # must contain a verdict line matching **Verdict:** pass|needs-info|needs-maintainer|block.
17
21
  # capture() returns an object — use a named group (?<v>...) to extract the value.
18
22
  # test() before capture() avoids jq errors on non-matching bodies.
19
23
  jq -r --arg issue "$issue_number" '
20
24
  def extract_verdict:
21
25
  [.items[] | select(.type == "add_comment" and (.item_number | tostring) == $issue and (.body | type == "string"))]
22
26
  | map(.body |
23
- if test("\\*\\*Verdict:\\*\\*\\s*(pass|needs-info|block)"; "i") then
24
- capture("\\*\\*Verdict:\\*\\*\\s*(?<v>pass|needs-info|block)"; "i").v | ascii_downcase
27
+ if test("\\*\\*Verdict:\\*\\*\\s*(pass|needs-info|needs-maintainer|block)"; "i") then
28
+ capture("\\*\\*Verdict:\\*\\*\\s*(?<v>pass|needs-info|needs-maintainer|block)"; "i").v | ascii_downcase
25
29
  else empty end
26
30
  )
27
31
  | .[0] // "none";
28
32
 
29
33
  extract_verdict as $verdict |
30
- if $verdict == "pass" or $verdict == "needs-info" or $verdict == "block" then
34
+ if $verdict == "pass" or $verdict == "needs-info" or $verdict == "needs-maintainer" or $verdict == "block" then
31
35
  $verdict
32
36
  else
33
37
  "invalid"
@@ -38,6 +38,59 @@ while IFS= read -r manifest; do
38
38
  continue
39
39
  fi
40
40
 
41
+ # `actions/github-script` steps carry real JavaScript inside a YAML string, and nothing on
42
+ # the way to production parses it: not the YAML check above, not actionlint, not gh aw
43
+ # compile. A typo there is a green push and a red run at whatever hour the schedule fires.
44
+ # The same shape of bug shipped in a jq filter in the router and broke an hourly job in a
45
+ # consumer for a day, so every inline script gets syntax-checked here.
46
+ #
47
+ # `${{ }}` is substituted before checking: it is a runner expression, not JavaScript, and
48
+ # standing in a string literal keeps the surrounding syntax intact.
49
+ scripts="$(python3 - "$manifest" <<'PY' 2>/dev/null || true
50
+ import re, sys, yaml, pathlib, tempfile, os
51
+
52
+ manifest = pathlib.Path(sys.argv[1])
53
+ doc = yaml.safe_load(manifest.read_text(encoding='utf-8')) or {}
54
+ out = []
55
+ for index, step in enumerate(((doc.get('runs') or {}).get('steps') or [])):
56
+ if not isinstance(step, dict):
57
+ continue
58
+ if 'github-script' not in str(step.get('uses', '')):
59
+ continue
60
+ body = ((step.get('with') or {}).get('script'))
61
+ if not isinstance(body, str):
62
+ continue
63
+ body = re.sub(r'\$\{\{[^}]*\}\}', '"__expr__"', body)
64
+ # github-script runs the body as the content of an async function, so a top-level `return`
65
+ # and a top-level `await` are both legal there. Wrap it the same way or every early return
66
+ # reads as a syntax error.
67
+ handle, path = tempfile.mkstemp(suffix='.mjs')
68
+ with os.fdopen(handle, 'w', encoding='utf-8') as sink:
69
+ sink.write('async function __ghScript(github, context, core, exec, io, glob, require, getOctokit) {\n')
70
+ sink.write(body)
71
+ sink.write('\n}\n')
72
+ out.append('%s\t%s' % (step.get('name', 'step %d' % index), path))
73
+ print('\n'.join(out))
74
+ PY
75
+ )"
76
+
77
+ script_ok=1
78
+ while IFS=$'\t' read -r step_name script_file; do
79
+ [ -n "${script_file:-}" ] || continue
80
+ if ! node --check "$script_file" 2>/tmp/node-check.err; then
81
+ script_ok=0
82
+ echo "FAIL: ${rel} step '${step_name}' has a JavaScript syntax error:" >&2
83
+ sed -n '1,6p' /tmp/node-check.err >&2
84
+ fi
85
+ rm -f "$script_file"
86
+ done <<<"$scripts"
87
+ rm -f /tmp/node-check.err
88
+
89
+ if [ "$script_ok" -eq 0 ]; then
90
+ FAIL=$((FAIL + 1))
91
+ continue
92
+ fi
93
+
41
94
  PASS=$((PASS + 1))
42
95
  done < <(find "$ACTIONS_DIR" -name 'action.yml' | sort)
43
96