@plainconceptsplatform/workflows 1.3.0 → 1.4.0
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/worker-env.js +2 -3
- package/loops/actions/apply-agent-output/action.yml +113 -108
- package/loops/actions/create-agent-issues/action.yml +113 -52
- package/loops/actions/housekeeping/action.yml +95 -1
- package/loops/actions/validate-merge-gate-output/action.yml +6 -1
- package/loops/actions/validate-merge-gate-output/validate-merge-gate-output.sh +9 -2
- package/loops/actions/validate-refine-output/validate-refine-output.sh +30 -1
- package/loops/actions/verify-refine-output/verify-refine-output.sh +17 -0
- package/loops/actions/verify-route-matrix/verify-route-matrix.sh +224 -9
- package/loops/docs/diagrams.md +90 -12
- package/loops/scripts/compile-agent-workflows.mjs +76 -2
- package/loops/workflows/agent-apply-review.md +5 -0
- package/loops/workflows/agent-implement.md +43 -7
- package/loops/workflows/agent-merge-gate.md +136 -8
- package/loops/workflows/agent-refine.md +152 -5
- package/loops/workflows/work-router.yml +330 -2
- package/package.json +1 -1
package/dist/worker-env.js
CHANGED
|
@@ -139,9 +139,8 @@ function engineEndpoint(content) {
|
|
|
139
139
|
// triage, refine, implement, apply-review and audit on RunnerLandingZone while its merge-gate
|
|
140
140
|
// and release stayed on agents-arc -- the pool was applied to the workers installed at the time
|
|
141
141
|
// and never to the ones added later, and nothing reported the split. The pool is package-owned
|
|
142
|
-
// now:
|
|
143
|
-
//
|
|
144
|
-
// cannot drift back without a red run. Per the standing rule for this package, anything a
|
|
142
|
+
// now: every job, router and release included, belongs on the Azure fleet (agents-arc, runner
|
|
143
|
+
// group `agentic`). The route matrix asserts it, so a repo cannot drift back without a red run. Per the standing rule for this package, anything a
|
|
145
144
|
// consumer really must vary belongs in `env:` at the top of the file, not in `runs-on`.
|
|
146
145
|
// GitHub evaluates no expression in a `workflow_run.workflows:` list or in a `cron:`, so the two
|
|
147
146
|
// router values that are also needed there cannot be read from `env:` at those two lines. The
|
|
@@ -1,108 +1,113 @@
|
|
|
1
|
-
# Managed by @plainconceptsplatform/workflows. Source: loops/actions/apply-agent-output/action.yml. Update with workflows update --force; consumer edits may be overwritten.
|
|
2
|
-
name: Apply agent output
|
|
3
|
-
description: Download the agent artifact and apply its safe outputs in one fixed order, so every worker concludes the same way.
|
|
4
|
-
inputs:
|
|
5
|
-
token:
|
|
6
|
-
description: GitHub token the writes are made with.
|
|
7
|
-
required: true
|
|
8
|
-
artifact-name:
|
|
9
|
-
description: >-
|
|
10
|
-
Name of the agent artifact. Callers pass the activation job's artifact_prefix output
|
|
11
|
-
followed by "agent"; gh-aw derives that prefix from the workflow's inputs, so it is
|
|
12
|
-
non-empty for every workflow_call worker and the bare name never resolves.
|
|
13
|
-
required: true
|
|
14
|
-
merge-pull-request:
|
|
15
|
-
description: Apply merge_pull_request items.
|
|
16
|
-
required: false
|
|
17
|
-
default: 'false'
|
|
18
|
-
push-to-branch:
|
|
19
|
-
description: Apply push_to_pull_request_branch items.
|
|
20
|
-
required: false
|
|
21
|
-
default: 'false'
|
|
22
|
-
close-issues:
|
|
23
|
-
description: Apply close_issue items.
|
|
24
|
-
required: false
|
|
25
|
-
default: 'false'
|
|
26
|
-
create-issues:
|
|
27
|
-
description: Apply create_issue items.
|
|
28
|
-
required: false
|
|
29
|
-
default: 'false'
|
|
30
|
-
update-issues:
|
|
31
|
-
description: Apply update_issue items.
|
|
32
|
-
required: false
|
|
33
|
-
default: 'false'
|
|
34
|
-
apply-labels:
|
|
35
|
-
description: Apply add_labels and remove_labels items.
|
|
36
|
-
required: false
|
|
37
|
-
default: 'true'
|
|
38
|
-
fallback-issue-number:
|
|
39
|
-
description: Issue an update_issue item targets when it names none.
|
|
40
|
-
required: false
|
|
41
|
-
default: ''
|
|
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
|
-
|
|
1
|
+
# Managed by @plainconceptsplatform/workflows. Source: loops/actions/apply-agent-output/action.yml. Update with workflows update --force; consumer edits may be overwritten.
|
|
2
|
+
name: Apply agent output
|
|
3
|
+
description: Download the agent artifact and apply its safe outputs in one fixed order, so every worker concludes the same way.
|
|
4
|
+
inputs:
|
|
5
|
+
token:
|
|
6
|
+
description: GitHub token the writes are made with.
|
|
7
|
+
required: true
|
|
8
|
+
artifact-name:
|
|
9
|
+
description: >-
|
|
10
|
+
Name of the agent artifact. Callers pass the activation job's artifact_prefix output
|
|
11
|
+
followed by "agent"; gh-aw derives that prefix from the workflow's inputs, so it is
|
|
12
|
+
non-empty for every workflow_call worker and the bare name never resolves.
|
|
13
|
+
required: true
|
|
14
|
+
merge-pull-request:
|
|
15
|
+
description: Apply merge_pull_request items.
|
|
16
|
+
required: false
|
|
17
|
+
default: 'false'
|
|
18
|
+
push-to-branch:
|
|
19
|
+
description: Apply push_to_pull_request_branch items.
|
|
20
|
+
required: false
|
|
21
|
+
default: 'false'
|
|
22
|
+
close-issues:
|
|
23
|
+
description: Apply close_issue items.
|
|
24
|
+
required: false
|
|
25
|
+
default: 'false'
|
|
26
|
+
create-issues:
|
|
27
|
+
description: Apply create_issue items.
|
|
28
|
+
required: false
|
|
29
|
+
default: 'false'
|
|
30
|
+
update-issues:
|
|
31
|
+
description: Apply update_issue items.
|
|
32
|
+
required: false
|
|
33
|
+
default: 'false'
|
|
34
|
+
apply-labels:
|
|
35
|
+
description: Apply add_labels and remove_labels items.
|
|
36
|
+
required: false
|
|
37
|
+
default: 'true'
|
|
38
|
+
fallback-issue-number:
|
|
39
|
+
description: Issue an update_issue item targets when it names none.
|
|
40
|
+
required: false
|
|
41
|
+
default: ''
|
|
42
|
+
parent-issue:
|
|
43
|
+
description: The split parent; see create-agent-issues. Empty for anything but a split.
|
|
44
|
+
required: false
|
|
45
|
+
default: ''
|
|
46
|
+
outputs:
|
|
47
|
+
item-count:
|
|
48
|
+
description: Number of items the agent produced.
|
|
49
|
+
value: ${{ steps.output.outputs.item-count }}
|
|
50
|
+
first-issue-number:
|
|
51
|
+
description: Issue number of the first issue created, or empty.
|
|
52
|
+
value: ${{ steps.create-issues.outputs.first-issue-number }}
|
|
53
|
+
runs:
|
|
54
|
+
using: composite
|
|
55
|
+
steps:
|
|
56
|
+
- name: Download agent output
|
|
57
|
+
id: output
|
|
58
|
+
uses: ./.github/actions/download-agent-output
|
|
59
|
+
with:
|
|
60
|
+
artifact-name: ${{ inputs.artifact-name }}
|
|
61
|
+
|
|
62
|
+
- name: Merge pull request
|
|
63
|
+
if: inputs.merge-pull-request == 'true' && steps.output.outputs.item-count != '0'
|
|
64
|
+
uses: ./.github/actions/merge-agent-pr
|
|
65
|
+
with:
|
|
66
|
+
output-file: ${{ steps.output.outputs.output-file }}
|
|
67
|
+
token: ${{ inputs.token }}
|
|
68
|
+
|
|
69
|
+
- name: Push to pull request branch
|
|
70
|
+
if: inputs.push-to-branch == 'true' && steps.output.outputs.item-count != '0'
|
|
71
|
+
uses: ./.github/actions/push-agent-branch
|
|
72
|
+
with:
|
|
73
|
+
output-file: ${{ steps.output.outputs.output-file }}
|
|
74
|
+
bundle-file: ${{ steps.output.outputs.bundle-file }}
|
|
75
|
+
token: ${{ inputs.token }}
|
|
76
|
+
|
|
77
|
+
- name: Close issues
|
|
78
|
+
if: inputs.close-issues == 'true' && steps.output.outputs.item-count != '0'
|
|
79
|
+
uses: ./.github/actions/close-agent-issues
|
|
80
|
+
with:
|
|
81
|
+
output-file: ${{ steps.output.outputs.output-file }}
|
|
82
|
+
token: ${{ inputs.token }}
|
|
83
|
+
|
|
84
|
+
- name: Update issues
|
|
85
|
+
if: inputs.update-issues == 'true' && steps.output.outputs.item-count != '0'
|
|
86
|
+
uses: ./.github/actions/update-agent-issues
|
|
87
|
+
with:
|
|
88
|
+
output-file: ${{ steps.output.outputs.output-file }}
|
|
89
|
+
token: ${{ inputs.token }}
|
|
90
|
+
fallback-issue-number: ${{ inputs.fallback-issue-number }}
|
|
91
|
+
|
|
92
|
+
- name: Create issues
|
|
93
|
+
id: create-issues
|
|
94
|
+
if: inputs.create-issues == 'true' && steps.output.outputs.item-count != '0'
|
|
95
|
+
uses: ./.github/actions/create-agent-issues
|
|
96
|
+
with:
|
|
97
|
+
output-file: ${{ steps.output.outputs.output-file }}
|
|
98
|
+
token: ${{ inputs.token }}
|
|
99
|
+
parent-issue: ${{ inputs.parent-issue }}
|
|
100
|
+
|
|
101
|
+
- name: Post agent comments
|
|
102
|
+
if: steps.output.outputs.item-count != '0'
|
|
103
|
+
uses: ./.github/actions/apply-agent-comments
|
|
104
|
+
with:
|
|
105
|
+
output-file: ${{ steps.output.outputs.output-file }}
|
|
106
|
+
token: ${{ inputs.token }}
|
|
107
|
+
|
|
108
|
+
- name: Apply agent label changes
|
|
109
|
+
if: inputs.apply-labels == 'true' && steps.output.outputs.item-count != '0'
|
|
110
|
+
uses: ./.github/actions/apply-agent-labels
|
|
111
|
+
with:
|
|
112
|
+
output-file: ${{ steps.output.outputs.output-file }}
|
|
113
|
+
token: ${{ inputs.token }}
|
|
@@ -1,52 +1,113 @@
|
|
|
1
|
-
# Managed by @plainconceptsplatform/workflows. Source: loops/actions/create-agent-issues/action.yml. Update with workflows update --force; consumer edits may be overwritten.
|
|
2
|
-
name: Create agent issues
|
|
3
|
-
description: Create every create_issue item from agent_output.json.
|
|
4
|
-
inputs:
|
|
5
|
-
output-file:
|
|
6
|
-
description: Path to agent_output.json.
|
|
7
|
-
required: true
|
|
8
|
-
token:
|
|
9
|
-
description: GitHub token with issues:write.
|
|
10
|
-
required: true
|
|
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
|
-
|
|
1
|
+
# Managed by @plainconceptsplatform/workflows. Source: loops/actions/create-agent-issues/action.yml. Update with workflows update --force; consumer edits may be overwritten.
|
|
2
|
+
name: Create agent issues
|
|
3
|
+
description: Create every create_issue item from agent_output.json.
|
|
4
|
+
inputs:
|
|
5
|
+
output-file:
|
|
6
|
+
description: Path to agent_output.json.
|
|
7
|
+
required: true
|
|
8
|
+
token:
|
|
9
|
+
description: GitHub token with issues:write.
|
|
10
|
+
required: true
|
|
11
|
+
parent-issue:
|
|
12
|
+
description: >-
|
|
13
|
+
The split parent, set only when the run is a split. Each created issue is stamped with the
|
|
14
|
+
split-parent marker and linked as a sub-issue of it, and temporary ids are resolved.
|
|
15
|
+
required: false
|
|
16
|
+
default: ''
|
|
17
|
+
outputs:
|
|
18
|
+
created-count:
|
|
19
|
+
description: Number of issues created.
|
|
20
|
+
value: ${{ steps.create.outputs.created-count }}
|
|
21
|
+
first-issue-number:
|
|
22
|
+
description: Issue number of the first issue created, or empty.
|
|
23
|
+
value: ${{ steps.create.outputs.first-issue-number }}
|
|
24
|
+
created-numbers:
|
|
25
|
+
description: Space-separated numbers of every issue created, in order.
|
|
26
|
+
value: ${{ steps.create.outputs.created-numbers }}
|
|
27
|
+
runs:
|
|
28
|
+
using: composite
|
|
29
|
+
steps:
|
|
30
|
+
- name: Create issues
|
|
31
|
+
id: create
|
|
32
|
+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
|
33
|
+
env:
|
|
34
|
+
AGENT_OUTPUT_LIB: ${{ github.action_path }}/../agent-output.cjs
|
|
35
|
+
OUTPUT_FILE: ${{ inputs.output-file }}
|
|
36
|
+
PARENT_ISSUE: ${{ inputs.parent-issue }}
|
|
37
|
+
with:
|
|
38
|
+
github-token: ${{ inputs.token }}
|
|
39
|
+
script: |
|
|
40
|
+
const { readAgentItems } = require(process.env.AGENT_OUTPUT_LIB);
|
|
41
|
+
const items = readAgentItems(process.env.OUTPUT_FILE, 'create_issue');
|
|
42
|
+
// Set only for a split. The agent writes `<!-- split-parent: N -->` in every child, but
|
|
43
|
+
// gh-aw's sanitizer strips HTML comments before agent_output.json is written, so the
|
|
44
|
+
// marker never reaches this file (Lyceum #45, run 38747143251: three markers in
|
|
45
|
+
// safeoutputs.jsonl, none in agent_output.json). gh-aw used to link the children as
|
|
46
|
+
// sub-issues itself; staged, nothing does, and the hand-over found no children. So the
|
|
47
|
+
// workflow stamps the marker and links the sub-issue here, from a value it owns.
|
|
48
|
+
const parent = /^[0-9]+$/.test(process.env.PARENT_ISSUE || '') ? Number(process.env.PARENT_ISSUE) : null;
|
|
49
|
+
const marker = parent ? `<!-- split-parent: ${parent} -->` : '';
|
|
50
|
+
|
|
51
|
+
const created = [];
|
|
52
|
+
const temporaryIds = {};
|
|
53
|
+
|
|
54
|
+
for (const item of items) {
|
|
55
|
+
if (!item.title) {
|
|
56
|
+
core.warning(`create_issue item has no title, skipping: ${JSON.stringify(item)}`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let body = item.body ?? '';
|
|
61
|
+
if (parent && !body.includes(marker)) body = `${body}\n\n${marker}`;
|
|
62
|
+
|
|
63
|
+
const { data } = await github.rest.issues.create({
|
|
64
|
+
...context.repo,
|
|
65
|
+
title: item.title,
|
|
66
|
+
body,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
created.push({ number: data.number, body });
|
|
70
|
+
const tid = String(item.temporary_id ?? '').replace(/^#/, '');
|
|
71
|
+
if (tid) temporaryIds[tid] = data.number;
|
|
72
|
+
core.info(`Created #${data.number}: ${item.title}`);
|
|
73
|
+
|
|
74
|
+
if (parent) {
|
|
75
|
+
try {
|
|
76
|
+
await github.request('POST /repos/{owner}/{repo}/issues/{issue_number}/sub_issues', {
|
|
77
|
+
...context.repo,
|
|
78
|
+
issue_number: parent,
|
|
79
|
+
sub_issue_id: data.id,
|
|
80
|
+
});
|
|
81
|
+
core.info(`Linked #${data.number} under #${parent}`);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
// The marker above is the fallback the hand-over searches, so a failed link is
|
|
84
|
+
// degraded, not lost.
|
|
85
|
+
core.warning(`Could not link #${data.number} under #${parent}: ${error.message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The agent references siblings by the temporary id it gave them, because their numbers
|
|
91
|
+
// do not exist until now: "Blocked by #aw_struct_modules". gh-aw resolves these when it
|
|
92
|
+
// creates the issues; staged, they reached the issues unresolved. Rewrite them in the
|
|
93
|
+
// children and in the parent's checklist, which was updated before this step ran.
|
|
94
|
+
const resolve = text => text.replace(/#(aw_[A-Za-z0-9_]+)/g, (whole, id) => (temporaryIds[id] ? `#${temporaryIds[id]}` : whole));
|
|
95
|
+
if (Object.keys(temporaryIds).length > 0) {
|
|
96
|
+
for (const issue of created) {
|
|
97
|
+
const next = resolve(issue.body);
|
|
98
|
+
if (next !== issue.body) {
|
|
99
|
+
await github.rest.issues.update({ ...context.repo, issue_number: issue.number, body: next });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (parent) {
|
|
103
|
+
const { data: current } = await github.rest.issues.get({ ...context.repo, issue_number: parent });
|
|
104
|
+
const next = resolve(current.body ?? '');
|
|
105
|
+
if (next !== (current.body ?? '')) {
|
|
106
|
+
await github.rest.issues.update({ ...context.repo, issue_number: parent, body: next });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
core.setOutput('created-count', String(created.length));
|
|
112
|
+
core.setOutput('first-issue-number', created.length > 0 ? String(created[0].number) : '');
|
|
113
|
+
core.setOutput('created-numbers', created.map(issue => issue.number).join(' '));
|
|
@@ -220,6 +220,14 @@ runs:
|
|
|
220
220
|
for (const [parent, children] of childrenOf) {
|
|
221
221
|
const open = children.filter((c) => c.state === 'open');
|
|
222
222
|
if (open.length > 0 || !issues.some((i) => i.number === parent)) continue;
|
|
223
|
+
// A stack feature issue. Its root pull request closing the issue is what ends it, not
|
|
224
|
+
// this sweep: closing the tracker here would close a feature whose root pull request
|
|
225
|
+
// is still open and holding a branch with real work on it. Refine stamps the root
|
|
226
|
+
// markers on the parent before the first child is ever handed over, so the marker
|
|
227
|
+
// is there from birth; finding none means flat mode, and the original rule applies.
|
|
228
|
+
// Everything stack-specific about these parents is decided in section 3b below,
|
|
229
|
+
// which sees the whole stack, not just the child count.
|
|
230
|
+
if (issues.some((i) => i.number === parent && /<!-- stack-root-branch: \S+ -->/.test(i.body ?? ''))) continue;
|
|
223
231
|
await act(`#${parent}: closing split parent, all ${children.length} children are done`, async () => {
|
|
224
232
|
await github.rest.issues.createComment({
|
|
225
233
|
...context.repo, issue_number: parent,
|
|
@@ -229,6 +237,87 @@ runs:
|
|
|
229
237
|
});
|
|
230
238
|
}
|
|
231
239
|
|
|
240
|
+
// The stack and branch sections both need every pull request the repository has ever
|
|
241
|
+
// seen, closed included, so it is paginated once here rather than once per section.
|
|
242
|
+
const allPulls = await github.paginate(github.rest.pulls.list, { ...context.repo, state: 'all', per_page: 100 });
|
|
243
|
+
|
|
244
|
+
// 3b. Stacks. Section 3 refused to close stack feature issues; this is what happens to
|
|
245
|
+
// them instead. The whole stack state is on the feature issue (root pull request) plus
|
|
246
|
+
// the children of the split, and both are already in memory, so a repository without
|
|
247
|
+
// stacks pays nothing: the marker test below fails first and the loop body never runs.
|
|
248
|
+
// No polling is added -- this runs on the same cadence the janitor already has, and it
|
|
249
|
+
// is the backstop for the one event the router can miss: a child issue that closes
|
|
250
|
+
// seconds after a router run already counted it as open.
|
|
251
|
+
for (const issue of issues) {
|
|
252
|
+
if (issue.pull_request) continue;
|
|
253
|
+
const marker = /<!-- stack-root-pr: (\d+) -->/.exec(issue.body ?? '');
|
|
254
|
+
if (!marker) continue;
|
|
255
|
+
const rootPr = Number(marker[1]);
|
|
256
|
+
const root = allPulls.find((p) => p.number === rootPr);
|
|
257
|
+
const children = childrenOf.get(issue.number) ?? [];
|
|
258
|
+
// A child only means work in progress while its pull request is still open.
|
|
259
|
+
// merge-gate closes the child issue the moment its pull request lands on the
|
|
260
|
+
// feature branch; if that close was lost -- an API blip, a run that died between
|
|
261
|
+
// the merge and the close -- the child stays open here for ever and the stack
|
|
262
|
+
// never reads as finished, which is the stall this sweep exists to prevent. The
|
|
263
|
+
// child's own `implement-pr` marker names its pull request, so the test is exact:
|
|
264
|
+
// an open child whose named pull request has merged has landed, whatever its issue
|
|
265
|
+
// state still claims. Closing it here is the same idempotent backstop section 3 is
|
|
266
|
+
// for flat splits, and the App token this sweep runs on is what raises the event.
|
|
267
|
+
let openChildren = 0;
|
|
268
|
+
for (const child of children) {
|
|
269
|
+
if (child.state !== 'open') continue;
|
|
270
|
+
const prMarker = /<!-- implement-pr: (\d+) -->/.exec(child.body ?? '');
|
|
271
|
+
const landed = prMarker && allPulls.some((p) => p.number === Number(prMarker[1]) && p.merged_at);
|
|
272
|
+
if (!landed) { openChildren += 1; continue; }
|
|
273
|
+
await act(`#${child.number}: closing child, its pull request #${prMarker[1]} merged into the stack`, async () => {
|
|
274
|
+
await github.rest.issues.createComment({
|
|
275
|
+
...context.repo, issue_number: child.number,
|
|
276
|
+
body: `${DIGEST_MARKER}\nClosed automatically: its pull request #${prMarker[1]} merged into the feature branch, so this child is done.`,
|
|
277
|
+
});
|
|
278
|
+
await github.rest.issues.update({ ...context.repo, issue_number: child.number, state: 'closed', state_reason: 'completed' });
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
if (!root) {
|
|
282
|
+
needsHuman.push({ kind: 'stack-root-missing', issue, rootPr, waited: age(issue.updated_at) });
|
|
283
|
+
} else if (root.state === 'open') {
|
|
284
|
+
if (openChildren > 0) continue; // mid-stack: the normal state, not worth a line
|
|
285
|
+
// Every child is done, so the completion announcement should exist on the root
|
|
286
|
+
// pull request. Its absence is the lost race above; a person is told here rather
|
|
287
|
+
// than the stack sitting finished and silent. When the announcement exists but
|
|
288
|
+
// nobody has merged for days, that is staleness worth one line too.
|
|
289
|
+
const comments = await github.paginate(github.rest.issues.listComments, {
|
|
290
|
+
...context.repo, issue_number: rootPr, per_page: 100,
|
|
291
|
+
});
|
|
292
|
+
const told = comments.find((c) => (c.body ?? '').includes('<!-- stack-complete -->'));
|
|
293
|
+
if (!told) {
|
|
294
|
+
needsHuman.push({ kind: 'stack-ready', issue, pull: root, waited: age(issue.updated_at) });
|
|
295
|
+
} else if (age(told.created_at) > stalePrMs) {
|
|
296
|
+
needsHuman.push({ kind: 'stack-held', issue, pull: root, waited: age(told.created_at) });
|
|
297
|
+
}
|
|
298
|
+
} else if (root.merged_at) {
|
|
299
|
+
// The root merged to the default branch and its closing keyword should have
|
|
300
|
+
// closed this issue with it. If something raced that, the same rule section 3
|
|
301
|
+
// applies to flat splits closes it here: every child done, root landed, done.
|
|
302
|
+
if (openChildren === 0) {
|
|
303
|
+
await act(`#${issue.number}: closing stack feature, its root PR #${rootPr} merged`, async () => {
|
|
304
|
+
await github.rest.issues.createComment({
|
|
305
|
+
...context.repo, issue_number: issue.number,
|
|
306
|
+
body: `${DIGEST_MARKER}\nClosed automatically: the stack's root pull request #${rootPr} merged with every child landed (${children.map((c) => `#${c.number}`).join(', ')}).`,
|
|
307
|
+
});
|
|
308
|
+
await github.rest.issues.update({ ...context.repo, issue_number: issue.number, state: 'closed', state_reason: 'completed' });
|
|
309
|
+
});
|
|
310
|
+
} else {
|
|
311
|
+
needsHuman.push({ kind: 'stack-orphaned', issue, pull: root, waited: age(root.merged_at), openChildren });
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
// Closed without merging. That is a person's decision or an accident, and the
|
|
315
|
+
// landed child work only exists on the feature branch, which section 4 may have
|
|
316
|
+
// already deleted -- restorable through refs/pull/<n>/head, but a person decides.
|
|
317
|
+
needsHuman.push({ kind: 'stack-root-closed', issue, pull: root, waited: age(root.closed_at), openChildren });
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
232
321
|
// 4. Branches. Nothing in the fleet has ever deleted one, so they accumulate for ever
|
|
233
322
|
// after a merge and after a close alike. Only ever touch a branch whose pull request is
|
|
234
323
|
// finished; never the default branch, and never one with a pull request still open.
|
|
@@ -241,7 +330,6 @@ runs:
|
|
|
241
330
|
// back, and the pull request page still shows the diff.
|
|
242
331
|
const branches = await github.paginate(github.rest.repos.listBranches, { ...context.repo, per_page: 100 });
|
|
243
332
|
const defaultBranch = context.payload.repository.default_branch;
|
|
244
|
-
const allPulls = await github.paginate(github.rest.pulls.list, { ...context.repo, state: 'all', per_page: 100 });
|
|
245
333
|
const byHead = new Map();
|
|
246
334
|
for (const pull of allPulls) {
|
|
247
335
|
if (!byHead.has(pull.head.ref)) byHead.set(pull.head.ref, []);
|
|
@@ -319,6 +407,11 @@ runs:
|
|
|
319
407
|
const line = (entry) => {
|
|
320
408
|
if (entry.kind === 'pr-parked') return `- PR #${entry.pull.number} · parked ${days(entry.waited)}d · gate verdict \`${entry.verdict}\` · ${entry.pull.title}`;
|
|
321
409
|
if (entry.kind === 'pr-stale') return `- PR #${entry.pull.number} · ${days(entry.waited)}d old · no gate verdict yet · ${entry.pull.title}`;
|
|
410
|
+
if (entry.kind === 'stack-ready') return `- PR #${entry.pull.number} · stack finished ${days(entry.waited)}d ago, never announced · human merge needed · ${entry.pull.title}`;
|
|
411
|
+
if (entry.kind === 'stack-held') return `- PR #${entry.pull.number} · stack ready and waiting on a human merge for ${days(entry.waited)}d · ${entry.pull.title}`;
|
|
412
|
+
if (entry.kind === 'stack-root-missing') return `- #${entry.issue.number} · names root PR #${entry.rootPr}, which does not exist · ${entry.issue.title}`;
|
|
413
|
+
if (entry.kind === 'stack-root-closed') return `- PR #${entry.pull.number} · stack root closed unmerged, ${entry.openChildren} child(ren) still open · ${entry.issue.title} · restore the branch from refs/pull/${entry.pull.number}/head if accidental`;
|
|
414
|
+
if (entry.kind === 'stack-orphaned') return `- #${entry.issue.number} · root merged but ${entry.openChildren} child(ren) still open · ${entry.issue.title}`;
|
|
322
415
|
if (entry.kind === 'retries-exhausted') return `- #${entry.issue.number} · stalled ${days(entry.waited)}d · retried ${entry.attempts}× and still stalling · ${entry.issue.title}`;
|
|
323
416
|
if (entry.kind === 'no-work-label') return `- #${entry.issue.number} · stalled ${days(entry.waited)}d · no work label to retry with · ${entry.issue.title}`;
|
|
324
417
|
if (entry.kind === 'stale-audit') return `- #${entry.issue.number} · open ${days(entry.waited)}d · audit report nobody actioned · ${entry.issue.title}`;
|
|
@@ -356,6 +449,7 @@ runs:
|
|
|
356
449
|
DIGEST_MARKER,
|
|
357
450
|
`_Updated ${new Date().toISOString().slice(0, 16).replace('T', ' ')} UTC. This issue is rewritten by the housekeeping job; edits to it are lost._`,
|
|
358
451
|
section('Waiting on a decision', ['decided']),
|
|
452
|
+
section('Stacked features waiting on a human', ['stack-ready', 'stack-held', 'stack-root-missing', 'stack-root-closed', 'stack-orphaned']),
|
|
359
453
|
section('Pull requests parked by the gate', ['pr-parked', 'pr-stale']),
|
|
360
454
|
section('Stalled beyond the retry budget', ['retries-exhausted', 'no-work-label']),
|
|
361
455
|
section('Audit reports nobody actioned', ['stale-audit']),
|
|
@@ -27,6 +27,10 @@ inputs:
|
|
|
27
27
|
description: Agent confidence below which the pull request goes to a human.
|
|
28
28
|
required: false
|
|
29
29
|
default: '0.8'
|
|
30
|
+
code-rules:
|
|
31
|
+
description: "check-diff result on the pull request: pass, fail or absent. Empty means it did not report."
|
|
32
|
+
required: false
|
|
33
|
+
default: absent
|
|
30
34
|
outputs:
|
|
31
35
|
valid:
|
|
32
36
|
description: Whether the output produced a usable disposition.
|
|
@@ -48,12 +52,13 @@ runs:
|
|
|
48
52
|
PROTECTED_HIT: ${{ inputs.protected-hit }}
|
|
49
53
|
OWNER_HIT: ${{ inputs.owner-hit }}
|
|
50
54
|
CONFIDENCE_THRESHOLD: ${{ inputs.confidence-threshold }}
|
|
55
|
+
CODE_RULES: ${{ inputs.code-rules }}
|
|
51
56
|
run: |
|
|
52
57
|
set -euo pipefail
|
|
53
58
|
|
|
54
59
|
outcome="$(bash "${{ github.action_path }}/validate-merge-gate-output.sh" \
|
|
55
60
|
"$OUTPUT_FILE" "$ISSUE_NUMBER" "$CI_CONCLUSION" \
|
|
56
|
-
"$BLAST_LEVEL" "$PROTECTED_HIT" "$OWNER_HIT" "$CONFIDENCE_THRESHOLD")"
|
|
61
|
+
"$BLAST_LEVEL" "$PROTECTED_HIT" "$OWNER_HIT" "$CONFIDENCE_THRESHOLD" "$CODE_RULES")"
|
|
57
62
|
echo "outcome=$outcome" >> "$GITHUB_OUTPUT"
|
|
58
63
|
echo "valid=$([ "$outcome" != 'invalid' ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
|
|
59
64
|
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
#
|
|
19
19
|
# Usage:
|
|
20
20
|
# validate-merge-gate-output.sh OUTPUT_FILE ISSUE CI_CONCLUSION \
|
|
21
|
-
# BLAST_LEVEL PROTECTED_HIT OWNER_HIT CONFIDENCE_THRESHOLD
|
|
21
|
+
# BLAST_LEVEL PROTECTED_HIT OWNER_HIT CONFIDENCE_THRESHOLD \
|
|
22
|
+
# CODE_RULES
|
|
22
23
|
|
|
23
24
|
set -euo pipefail
|
|
24
25
|
|
|
@@ -33,6 +34,9 @@ blast_level="${4-low}"
|
|
|
33
34
|
protected_hit="${5-false}"
|
|
34
35
|
owner_hit="${6-false}"
|
|
35
36
|
confidence_threshold="${7-0.8}"
|
|
37
|
+
# pass, fail or absent (the repository has no check-diff). An empty value is a job that did not
|
|
38
|
+
# report, and like every other unmeasured fact it goes to a person.
|
|
39
|
+
code_rules="${8-absent}"
|
|
36
40
|
|
|
37
41
|
# An empty measured level is not a low-risk pull request, it is a job that did not report. The
|
|
38
42
|
# defaults above exist for a caller that genuinely has nothing to say; an empty string arriving
|
|
@@ -56,7 +60,8 @@ jq -r \
|
|
|
56
60
|
--arg blast "$blast_level" \
|
|
57
61
|
--arg protected "$protected_hit" \
|
|
58
62
|
--arg owner "$owner_hit" \
|
|
59
|
-
--arg threshold "$confidence_threshold"
|
|
63
|
+
--arg threshold "$confidence_threshold" \
|
|
64
|
+
--arg code "$code_rules" '
|
|
60
65
|
|
|
61
66
|
def level_rank: {"low": 0, "medium": 1, "high": 2}[.];
|
|
62
67
|
def is_bool: type == "boolean";
|
|
@@ -143,11 +148,13 @@ jq -r \
|
|
|
143
148
|
|
|
144
149
|
| if $conclusion != "success" then "blocked"
|
|
145
150
|
elif $blockers > 0 then "blocked"
|
|
151
|
+
elif $code == "fail" then "blocked"
|
|
146
152
|
elif $protected == "true" or $owner == "true" or $level == 2 then "owner-review"
|
|
147
153
|
# A fact the workflow could not measure is not a fact. Anything other than a
|
|
148
154
|
# clean true or false here means protected_changes did not report, and the
|
|
149
155
|
# pull request goes to a person rather than through on a default.
|
|
150
156
|
elif $protected != "false" or $owner != "false" then "human-review"
|
|
157
|
+
elif $code != "pass" and $code != "absent" then "human-review"
|
|
151
158
|
elif $level == 1 and $recoverability == "low" then "human-review"
|
|
152
159
|
elif ($report | has("acceptanceCriteriaMet")) and $report.acceptanceCriteriaMet == false then "human-review"
|
|
153
160
|
elif $confidence < ($threshold | tonumber) then "human-review"
|