@mnaimfaizy/agent-kit 1.0.0-beta.15 → 1.0.0-beta.17
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/README.md +2 -1
- package/package.json +1 -1
- package/src/cli.mjs +332 -5
- package/src/deep-scan/docker-driver.mjs +70 -3
- package/src/deep-scan/lifecycle.mjs +2 -2
- package/src/deep-scan/sbx-driver.mjs +34 -47
- package/src/doctor.mjs +53 -1
- package/src/exec.mjs +18 -5
- package/src/factory/budget/budget.mjs +260 -0
- package/src/factory/build/command.mjs +321 -0
- package/src/factory/build/factory.mjs +473 -0
- package/src/factory/build/findings.mjs +55 -0
- package/src/factory/build/host.mjs +230 -0
- package/src/factory/build/notes.mjs +191 -0
- package/src/factory/build/pull-request.mjs +74 -0
- package/src/factory/bundle.mjs +146 -0
- package/src/factory/checks/allowed-paths.mjs +50 -0
- package/src/factory/checks/plan-header.mjs +296 -0
- package/src/factory/checks/qa.mjs +85 -0
- package/src/factory/checks/review.mjs +73 -0
- package/src/factory/checks/security.mjs +50 -0
- package/src/factory/checks/stage-check.mjs +89 -0
- package/src/factory/claims/command.mjs +187 -0
- package/src/factory/claims/release.mjs +111 -0
- package/src/factory/decision/answers.mjs +103 -0
- package/src/factory/decision/command.mjs +64 -0
- package/src/factory/decision/plan.mjs +99 -0
- package/src/factory/decision/request.mjs +116 -0
- package/src/factory/doctor/files.mjs +349 -0
- package/src/factory/doctor/index.mjs +56 -0
- package/src/factory/doctor/local.mjs +513 -0
- package/src/factory/doctor/orchestrate.mjs +146 -0
- package/src/factory/engine/lease.mjs +146 -0
- package/src/factory/engine/local-engine.mjs +177 -0
- package/src/factory/engine/lockfile.mjs +64 -0
- package/src/factory/engine/workflow-engine.mjs +124 -0
- package/src/factory/gate/comment.mjs +88 -0
- package/src/factory/gate/config.mjs +57 -0
- package/src/factory/gate/gate-core.mjs +250 -0
- package/src/factory/gate/guarded.mjs +17 -0
- package/src/factory/gate/reads.mjs +105 -0
- package/src/factory/gate/task.mjs +193 -0
- package/src/factory/gate/trip-reads.mjs +82 -0
- package/src/factory/gate/trip.mjs +87 -0
- package/src/factory/init/blueprint.mjs +181 -0
- package/src/factory/init/index.mjs +338 -0
- package/src/factory/labels/evidence.mjs +162 -0
- package/src/factory/labels/moves.mjs +32 -0
- package/src/factory/labels/reconcile.mjs +267 -0
- package/src/factory/labels/revert.mjs +87 -0
- package/src/factory/labels/timeline.mjs +72 -0
- package/src/factory/labels/voided.mjs +59 -0
- package/src/factory/limits/harness.mjs +39 -0
- package/src/factory/limits/limits.mjs +131 -0
- package/src/factory/merge/command.mjs +172 -0
- package/src/factory/outbox/check.mjs +240 -0
- package/src/factory/outbox/rulings.mjs +195 -0
- package/src/factory/plan/command.mjs +66 -0
- package/src/factory/plan/comment.mjs +156 -0
- package/src/factory/plan/publish.mjs +149 -0
- package/src/factory/plan/risk.mjs +153 -0
- package/src/factory/qa/command.mjs +301 -0
- package/src/factory/qa/decide.mjs +86 -0
- package/src/factory/qa/report.mjs +50 -0
- package/src/factory/records/engine-record.mjs +133 -0
- package/src/factory/records/main.mjs +96 -0
- package/src/factory/records/record.mjs +226 -0
- package/src/factory/records/sink.mjs +57 -0
- package/src/factory/report/build.mjs +92 -0
- package/src/factory/report/command.mjs +80 -0
- package/src/factory/report/facts.mjs +226 -0
- package/src/factory/report/gate-section.mjs +122 -0
- package/src/factory/report/metrics.mjs +111 -0
- package/src/factory/report/reads.mjs +246 -0
- package/src/factory/report/render.mjs +121 -0
- package/src/factory/report/rollout.mjs +154 -0
- package/src/factory/review/brief.mjs +195 -0
- package/src/factory/review/command.mjs +182 -0
- package/src/factory/run/awake.mjs +70 -0
- package/src/factory/run/collect.mjs +77 -0
- package/src/factory/run/command.mjs +556 -0
- package/src/factory/run/gh.mjs +46 -0
- package/src/factory/run/launch.mjs +66 -0
- package/src/factory/run/pipelines.mjs +694 -0
- package/src/factory/run/raw.mjs +96 -0
- package/src/factory/run/restart.mjs +83 -0
- package/src/factory/run/s3.mjs +193 -0
- package/src/factory/run/secrets.mjs +142 -0
- package/src/factory/run/teardown.mjs +242 -0
- package/src/factory/run/token.mjs +70 -0
- package/src/factory/run/worktree.mjs +160 -0
- package/src/factory/security/audit.mjs +353 -0
- package/src/factory/security/command.mjs +157 -0
- package/src/factory/setup/app.mjs +122 -0
- package/src/factory/setup/command.mjs +472 -0
- package/src/factory/setup/labels.mjs +25 -0
- package/src/factory/setup/reads.mjs +159 -0
- package/src/factory/setup/writes.mjs +138 -0
- package/src/factory/snapshot/write.mjs +176 -0
- package/src/factory/stop/command.mjs +136 -0
- package/src/factory/sweep/actions-main.mjs +119 -0
- package/src/factory/sweep/command.mjs +65 -0
- package/src/factory/sweep/knobs.mjs +78 -0
- package/src/factory/sweep/marker-version.mjs +15 -0
- package/src/factory/sweep/markers.mjs +112 -0
- package/src/factory/sweep/overlap.mjs +24 -0
- package/src/factory/sweep/run.mjs +198 -0
- package/src/factory/sweep/shell.mjs +398 -0
- package/src/factory/sweep/split.mjs +104 -0
- package/src/factory/sweep/states.mjs +87 -0
- package/src/factory/sweep/sweep-core.mjs +2009 -0
- package/src/factory/tracker/github.mjs +713 -0
- package/src/factory/tracker/operations.mjs +153 -0
- package/src/factory/upgrade/index.mjs +83 -0
- package/src/init.mjs +62 -24
- package/src/kit-owned-paths.mjs +1 -1
- package/src/stage/build.mjs +100 -0
- package/src/stage/factory-live.mjs +288 -0
- package/src/stage.mjs +100 -4
- package/src/upgrade.mjs +39 -7
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// What `factory report` reads of the tracker: closed Factory issues with their
|
|
2
|
+
// comments, label events, cross-references and pull requests, the head statuses
|
|
3
|
+
// of those pull requests, the factory config, the Kill switch and who has write
|
|
4
|
+
// access. Every call is a `gh` read: `gh api` GET, or a GraphQL query (a `-f`
|
|
5
|
+
// field on `gh api graphql` is a query variable, not a write). Nothing is posted.
|
|
6
|
+
//
|
|
7
|
+
// `gh(args)` returns `{ status, stdout, stderr }`, as everywhere in the Factory.
|
|
8
|
+
|
|
9
|
+
import { STATES, stateLabel } from "../sweep/states.mjs";
|
|
10
|
+
import { createGithubTracker } from "../tracker/github.mjs";
|
|
11
|
+
import { bare } from "./facts.mjs";
|
|
12
|
+
|
|
13
|
+
export const FACTORY_CONFIG_PATH = ".github/factory/config.json";
|
|
14
|
+
const PAGE = 50;
|
|
15
|
+
const MAX_PAGES = 10;
|
|
16
|
+
|
|
17
|
+
const REF = `source { __typename
|
|
18
|
+
... on Issue { number createdAt labels(first: 20) { nodes { name } } }
|
|
19
|
+
... on PullRequest { number title body merged mergedAt createdAt } }`;
|
|
20
|
+
|
|
21
|
+
const ISSUE_QUERY = `query($q: String!, $cursor: String) {
|
|
22
|
+
search(query: $q, type: ISSUE, first: ${PAGE}, after: $cursor) {
|
|
23
|
+
pageInfo { hasNextPage endCursor }
|
|
24
|
+
nodes { ... on Issue {
|
|
25
|
+
number state closedAt createdAt
|
|
26
|
+
labels(first: 50) { nodes { name } }
|
|
27
|
+
comments(first: 100) { totalCount nodes { databaseId author { login } body createdAt lastEditedAt } }
|
|
28
|
+
timelineItems(first: 100, itemTypes: [LABELED_EVENT, CROSS_REFERENCED_EVENT]) { nodes { __typename
|
|
29
|
+
... on LabeledEvent { createdAt actor { login } label { name } }
|
|
30
|
+
... on CrossReferencedEvent { ${REF} } } }
|
|
31
|
+
closedByPullRequestsReferences(first: 10, includeClosedPrs: true) { nodes {
|
|
32
|
+
number state merged mergedAt mergedBy { login } headRefName headRefOid
|
|
33
|
+
comments(first: 50) { nodes { databaseId author { login } body createdAt lastEditedAt } }
|
|
34
|
+
timelineItems(first: 50, itemTypes: [CROSS_REFERENCED_EVENT]) { nodes { __typename ... on CrossReferencedEvent { ${REF} } } } } }
|
|
35
|
+
} }
|
|
36
|
+
}
|
|
37
|
+
}`;
|
|
38
|
+
|
|
39
|
+
const STATUS_QUERY = `query($owner: String!, $name: String!, $number: Int!) {
|
|
40
|
+
repository(owner: $owner, name: $name) { pullRequest(number: $number) {
|
|
41
|
+
commits(first: 100) { nodes { commit { oid status { contexts { context state creator { login } } } } } } } }
|
|
42
|
+
}`;
|
|
43
|
+
|
|
44
|
+
const comment = (c) => ({
|
|
45
|
+
id: c.databaseId,
|
|
46
|
+
author: c.author?.login ?? "",
|
|
47
|
+
body: c.body ?? "",
|
|
48
|
+
createdAt: c.createdAt,
|
|
49
|
+
editedAt: c.lastEditedAt ?? null,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function refOf(node) {
|
|
53
|
+
const s = node?.source;
|
|
54
|
+
if (!s) return null;
|
|
55
|
+
if (s.__typename === "PullRequest") {
|
|
56
|
+
return {
|
|
57
|
+
kind: "pull",
|
|
58
|
+
number: s.number,
|
|
59
|
+
title: s.title ?? "",
|
|
60
|
+
body: s.body ?? "",
|
|
61
|
+
merged: s.merged === true,
|
|
62
|
+
mergedAt: s.mergedAt ?? null,
|
|
63
|
+
createdAt: s.createdAt,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (s.__typename === "Issue") {
|
|
67
|
+
return {
|
|
68
|
+
kind: "issue",
|
|
69
|
+
number: s.number,
|
|
70
|
+
createdAt: s.createdAt,
|
|
71
|
+
labels: (s.labels?.nodes ?? []).map((l) => l.name),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** An issue, from the GraphQL node, in the shape `facts.mjs` reads. Exported for the suite. */
|
|
78
|
+
export function issueOf(node) {
|
|
79
|
+
const items = node.timelineItems?.nodes ?? [];
|
|
80
|
+
return {
|
|
81
|
+
number: node.number,
|
|
82
|
+
state: node.state,
|
|
83
|
+
closedAt: node.closedAt,
|
|
84
|
+
createdAt: node.createdAt,
|
|
85
|
+
labels: (node.labels?.nodes ?? []).map((l) => l.name),
|
|
86
|
+
commentsTruncated: (node.comments?.totalCount ?? 0) > 100,
|
|
87
|
+
comments: (node.comments?.nodes ?? []).map(comment),
|
|
88
|
+
events: items
|
|
89
|
+
.filter((i) => i.__typename === "LabeledEvent")
|
|
90
|
+
.map((i) => ({
|
|
91
|
+
type: "labeled",
|
|
92
|
+
label: i.label?.name,
|
|
93
|
+
actor: i.actor?.login ?? "",
|
|
94
|
+
createdAt: i.createdAt,
|
|
95
|
+
})),
|
|
96
|
+
refs: items
|
|
97
|
+
.filter((i) => i.__typename === "CrossReferencedEvent")
|
|
98
|
+
.map(refOf)
|
|
99
|
+
.filter(Boolean),
|
|
100
|
+
pulls: (node.closedByPullRequestsReferences?.nodes ?? []).map((p) => ({
|
|
101
|
+
number: p.number,
|
|
102
|
+
state: p.state,
|
|
103
|
+
merged: p.merged === true,
|
|
104
|
+
mergedAt: p.mergedAt ?? null,
|
|
105
|
+
mergedBy: p.mergedBy?.login ?? "",
|
|
106
|
+
branch: p.headRefName ?? "",
|
|
107
|
+
head: p.headRefOid,
|
|
108
|
+
comments: (p.comments?.nodes ?? []).map(comment),
|
|
109
|
+
refs: (p.timelineItems?.nodes ?? []).map(refOf).filter(Boolean),
|
|
110
|
+
statuses: [],
|
|
111
|
+
})),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {{
|
|
117
|
+
* gh: (args: string[]) => { status: number | null, stdout: string, stderr: string },
|
|
118
|
+
* repo: string, since: number, env: Record<string, string | undefined>,
|
|
119
|
+
* identity: string, log: (line: string) => void,
|
|
120
|
+
* }} input
|
|
121
|
+
*/
|
|
122
|
+
export function readTracker({ gh, repo, since, env, identity, log }) {
|
|
123
|
+
const [owner, name] = repo.split("/");
|
|
124
|
+
const tracker = createGithubTracker({ gh, repo });
|
|
125
|
+
const json = (args) => {
|
|
126
|
+
const r = gh(args);
|
|
127
|
+
if (r.status !== 0) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`gh ${args.slice(0, 3).join(" ")} failed: ${String(r.stderr).trim().slice(0, 300)}`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return JSON.parse(r.stdout || "null");
|
|
133
|
+
};
|
|
134
|
+
const warnings = [];
|
|
135
|
+
const day = new Date(since).toISOString().slice(0, 10);
|
|
136
|
+
|
|
137
|
+
// Closed issues carrying each Factory state label: a closed task keeps its last one.
|
|
138
|
+
const byNumber = new Map();
|
|
139
|
+
for (const state of STATES) {
|
|
140
|
+
let cursor = null;
|
|
141
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
142
|
+
const q = `repo:${repo} is:issue is:closed closed:>=${day} label:"${stateLabel(state)}"`;
|
|
143
|
+
const data = json([
|
|
144
|
+
"api",
|
|
145
|
+
"graphql",
|
|
146
|
+
"-f",
|
|
147
|
+
`query=${ISSUE_QUERY}`,
|
|
148
|
+
"-f",
|
|
149
|
+
`q=${q}`,
|
|
150
|
+
...(cursor ? ["-f", `cursor=${cursor}`] : []),
|
|
151
|
+
]);
|
|
152
|
+
const search = data?.data?.search;
|
|
153
|
+
if (!search) throw new Error("tracker read: the GraphQL response has no search");
|
|
154
|
+
for (const node of search.nodes ?? []) {
|
|
155
|
+
if (node?.number && !byNumber.has(node.number)) byNumber.set(node.number, issueOf(node));
|
|
156
|
+
}
|
|
157
|
+
if (!search.pageInfo?.hasNextPage) break;
|
|
158
|
+
cursor = search.pageInfo.endCursor;
|
|
159
|
+
if (page === MAX_PAGES - 1)
|
|
160
|
+
warnings.push(`${stateLabel(state)}: only the first ${MAX_PAGES * PAGE} issues were read`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const issues = [...byNumber.values()].sort((a, b) => a.number - b.number);
|
|
164
|
+
for (const i of issues) {
|
|
165
|
+
if (i.commentsTruncated) warnings.push(`#${i.number}: only the first 100 comments were read`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Each pull request's Stage checks on every head it has had.
|
|
169
|
+
for (const issue of issues) {
|
|
170
|
+
for (const pull of issue.pulls) {
|
|
171
|
+
try {
|
|
172
|
+
const data = json([
|
|
173
|
+
"api",
|
|
174
|
+
"graphql",
|
|
175
|
+
"-f",
|
|
176
|
+
`query=${STATUS_QUERY}`,
|
|
177
|
+
"-f",
|
|
178
|
+
`owner=${owner}`,
|
|
179
|
+
"-f",
|
|
180
|
+
`name=${name}`,
|
|
181
|
+
"-F",
|
|
182
|
+
`number=${Number(pull.number)}`,
|
|
183
|
+
]);
|
|
184
|
+
for (const node of data?.data?.repository?.pullRequest?.commits?.nodes ?? []) {
|
|
185
|
+
for (const c of node.commit?.status?.contexts ?? []) {
|
|
186
|
+
pull.statuses.push({
|
|
187
|
+
head: node.commit.oid,
|
|
188
|
+
context: c.context,
|
|
189
|
+
state: String(c.state).toLowerCase(),
|
|
190
|
+
creator: c.creator?.login ?? "",
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
warnings.push(
|
|
196
|
+
`#${issue.number}: pull request #${pull.number} checks unread (${error.message})`,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Who may move a label: the engine, and anyone with write access.
|
|
203
|
+
const actors = new Set();
|
|
204
|
+
for (const i of issues) {
|
|
205
|
+
for (const e of i.events) if (bare(e.actor) !== bare(identity) && e.actor) actors.add(e.actor);
|
|
206
|
+
}
|
|
207
|
+
let writers = [];
|
|
208
|
+
try {
|
|
209
|
+
writers = tracker.readWriters([...actors]);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
warnings.push(`write access unread (${error.message}): label moves by people do not count`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// The config, from the default branch, and the Kill switch.
|
|
215
|
+
let configText = null;
|
|
216
|
+
let configProblem = null;
|
|
217
|
+
try {
|
|
218
|
+
configText = tracker.readFile(FACTORY_CONFIG_PATH, tracker.defaultBranch());
|
|
219
|
+
} catch (error) {
|
|
220
|
+
configProblem = error.message;
|
|
221
|
+
warnings.push(`${FACTORY_CONFIG_PATH} unread (${error.message})`);
|
|
222
|
+
}
|
|
223
|
+
let killSwitch = env.AGENT_KIT_FACTORY_ENABLED ?? null;
|
|
224
|
+
if (killSwitch === null) {
|
|
225
|
+
const v = gh([
|
|
226
|
+
"api",
|
|
227
|
+
`repos/${repo}/actions/variables/AGENT_KIT_FACTORY_ENABLED`,
|
|
228
|
+
"--jq",
|
|
229
|
+
".value",
|
|
230
|
+
]);
|
|
231
|
+
if (v.status === 0) killSwitch = v.stdout.replace(/\n$/, "");
|
|
232
|
+
else
|
|
233
|
+
warnings.push(
|
|
234
|
+
"the Kill switch variable was not readable: Phase 0 and Phase 1 cannot be told apart",
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
log(`read ${issues.length} closed Factory issues`);
|
|
238
|
+
return {
|
|
239
|
+
issues,
|
|
240
|
+
writers,
|
|
241
|
+
configText,
|
|
242
|
+
configProblem,
|
|
243
|
+
killSwitch: killSwitch === null ? null : killSwitch === "true" ? "true" : "false",
|
|
244
|
+
warnings,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// The report as text for a person, and as stable JSON. Pure.
|
|
2
|
+
|
|
3
|
+
const pct = (r) => (r === null ? "n/a" : `${Math.round(r * 1000) / 10}%`);
|
|
4
|
+
const num = (n) => (n === null ? "n/a" : String(n));
|
|
5
|
+
|
|
6
|
+
function duration(seconds) {
|
|
7
|
+
if (seconds === null) return "n/a";
|
|
8
|
+
const h = seconds / 3600;
|
|
9
|
+
return h >= 48 ? `${Math.round((h / 24) * 10) / 10}d` : `${Math.round(h * 10) / 10}h`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function pad(rows) {
|
|
13
|
+
const widths = rows[0].map((_, i) => Math.max(...rows.map((r) => String(r[i]).length)));
|
|
14
|
+
return rows.map((r) =>
|
|
15
|
+
r
|
|
16
|
+
.map((c, i) => String(c).padEnd(widths[i]))
|
|
17
|
+
.join(" ")
|
|
18
|
+
.trimEnd(),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function metricRow(label, m) {
|
|
23
|
+
return [
|
|
24
|
+
label,
|
|
25
|
+
m.terminal,
|
|
26
|
+
pct(m.merge_rate),
|
|
27
|
+
pct(m.first_pass.rate),
|
|
28
|
+
`${duration(m.lead_time_seconds.median)} / ${duration(m.lead_time_seconds.p90)}`,
|
|
29
|
+
pct(m.escalation.rate),
|
|
30
|
+
pct(m.revert.rate),
|
|
31
|
+
`${num(m.tokens.median)} / ${m.tokens.total}`,
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const mark = (met) => (met === null ? "-" : met ? "met" : "not met");
|
|
36
|
+
|
|
37
|
+
/** The text report. */
|
|
38
|
+
export function renderText(report) {
|
|
39
|
+
const out = [];
|
|
40
|
+
out.push(
|
|
41
|
+
`Factory report for ${report.repo}: ${report.overall.terminal} terminal tasks in the last ${report.window.days} days (${report.window.since} to ${report.window.until})`,
|
|
42
|
+
"",
|
|
43
|
+
);
|
|
44
|
+
const head = [
|
|
45
|
+
"",
|
|
46
|
+
"tasks",
|
|
47
|
+
"merge",
|
|
48
|
+
"first-pass",
|
|
49
|
+
"lead median/p90",
|
|
50
|
+
"escalation",
|
|
51
|
+
"revert 7d",
|
|
52
|
+
"tokens median/total",
|
|
53
|
+
];
|
|
54
|
+
const rows = [head, metricRow("all", report.overall)];
|
|
55
|
+
for (const [tier, m] of Object.entries(report.tiers)) {
|
|
56
|
+
if (m.terminal) rows.push(metricRow(tier, m));
|
|
57
|
+
}
|
|
58
|
+
out.push(...pad(rows), "");
|
|
59
|
+
out.push("By merge path (merged tasks):");
|
|
60
|
+
out.push(
|
|
61
|
+
...pad(
|
|
62
|
+
Object.entries(report.merge_paths).map(([path, p]) => [
|
|
63
|
+
path,
|
|
64
|
+
p.merged,
|
|
65
|
+
`lead ${duration(p.lead_time_seconds.median)} / ${duration(p.lead_time_seconds.p90)}`,
|
|
66
|
+
`revert ${pct(p.revert.rate)} (${p.revert.reverted}/${p.revert.merged})`,
|
|
67
|
+
]),
|
|
68
|
+
),
|
|
69
|
+
"",
|
|
70
|
+
);
|
|
71
|
+
const t = report.token_totals;
|
|
72
|
+
out.push(
|
|
73
|
+
`Token totals over merged tasks: ${t.stage_runs} Stage runs, ${t.counted} counted, ${t.missing} missing, ${t.edited} edited (the last two at the Stage's cap).`,
|
|
74
|
+
"",
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const r = report.rollout;
|
|
78
|
+
if (r.problems?.length) {
|
|
79
|
+
out.push(`Rollout phase: unknown (${r.problems.join("; ")}).`);
|
|
80
|
+
} else if (r.phase === null) {
|
|
81
|
+
out.push(
|
|
82
|
+
r.candidates.length
|
|
83
|
+
? `Rollout phase: Phase ${r.candidates.join(" or ")} (the Kill switch could not be read).`
|
|
84
|
+
: "Rollout phase: the effective config matches no phase.",
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
out.push(`Rollout phase: Phase ${r.phase}, ${r.name}.`);
|
|
88
|
+
}
|
|
89
|
+
out.push(
|
|
90
|
+
` Kill switch ${r.effective.kill_switch ?? "unread"}, plan_approval ${r.effective.plan_approval}, merge.mode ${r.effective.merge_mode}, auto_tiers [${r.effective.auto_tiers.join(", ")}].`,
|
|
91
|
+
);
|
|
92
|
+
if (r.next) {
|
|
93
|
+
out.push(`Next, Phase ${r.next.phase}: ${r.next.bar}. Bar ${mark(r.next.met)}.`);
|
|
94
|
+
for (const c of r.next.checks) {
|
|
95
|
+
out.push(
|
|
96
|
+
` ${c.met ? "[x]" : "[ ]"} ${c.name}: ${c.value === null ? "n/a" : c.value}${c.want ? ` (want ${c.want})` : ""}`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (report.gate) {
|
|
101
|
+
const g = report.gate;
|
|
102
|
+
out.push(
|
|
103
|
+
"",
|
|
104
|
+
`Shadow-to-on bar (${g.bar.decisions} decisions over ${g.bar.days} days, none reverted within ${g.bar.revert_days}):`,
|
|
105
|
+
);
|
|
106
|
+
out.push(
|
|
107
|
+
` Latest trip: ${g.latest_trip ?? "none"}${g.latest_trip ? " (counted from here)" : ""}`,
|
|
108
|
+
);
|
|
109
|
+
for (const [tier, s] of Object.entries(g.tiers)) {
|
|
110
|
+
out.push(
|
|
111
|
+
` ${tier}: ${s.confirmed} confirmed of ${s.would_merge} would-merge and ${s.tier_only_holds} tier-only holds; ${s.diverged} diverged, ${s.reverted} reverted, ${s.pending} pending, ${s.days} days. Bar ${mark(s.met)}.`,
|
|
112
|
+
);
|
|
113
|
+
for (const c of s.checks) out.push(` ${c.met ? "[x]" : "[ ]"} ${c.name}: ${c.value}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (const w of report.warnings) out.push("", `warning: ${w}`);
|
|
117
|
+
return out.join("\n");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The JSON report: two-space indented, keys in the order `buildReport` builds them. */
|
|
121
|
+
export const renderJson = (report) => JSON.stringify(report, null, 2);
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// The Rollout phases (spec #500, Rollout phases) as documented sets of config
|
|
2
|
+
// values, which phase the effective config matches, and whether the next phase's
|
|
3
|
+
// bar is met. Pure. A phase is never a config key: it is read off these values.
|
|
4
|
+
//
|
|
5
|
+
// Phase | Kill switch | plan_approval | merge.mode | auto_tiers
|
|
6
|
+
// 0 | off | low | shadow | [low]
|
|
7
|
+
// 1 | on | low | shadow | [low]
|
|
8
|
+
// 2 | on | high | shadow | [low]
|
|
9
|
+
// 3 | on | high | on | [low]
|
|
10
|
+
// 4 | on | high | on | [low, medium]
|
|
11
|
+
//
|
|
12
|
+
// The Daily cap is the Consumer's choice in every phase, so it is not compared.
|
|
13
|
+
|
|
14
|
+
import { DAY } from "./facts.mjs";
|
|
15
|
+
|
|
16
|
+
export const PHASES = Object.freeze([
|
|
17
|
+
{ phase: 0, name: "Installed", kill: "false", plan: "low", mode: "shadow", tiers: ["low"] },
|
|
18
|
+
{ phase: 1, name: "Staged", kill: "true", plan: "low", mode: "shadow", tiers: ["low"] },
|
|
19
|
+
{
|
|
20
|
+
phase: 2,
|
|
21
|
+
name: "Unsupervised plans",
|
|
22
|
+
kill: "true",
|
|
23
|
+
plan: "high",
|
|
24
|
+
mode: "shadow",
|
|
25
|
+
tiers: ["low"],
|
|
26
|
+
},
|
|
27
|
+
{ phase: 3, name: "Auto-merge low", kill: "true", plan: "high", mode: "on", tiers: ["low"] },
|
|
28
|
+
{
|
|
29
|
+
phase: 4,
|
|
30
|
+
name: "Auto-merge medium",
|
|
31
|
+
kill: "true",
|
|
32
|
+
plan: "high",
|
|
33
|
+
mode: "on",
|
|
34
|
+
tiers: ["low", "medium"],
|
|
35
|
+
},
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
/** The 1 to 2 bar's defaults; a Consumer may tighten them. */
|
|
39
|
+
export const STAGED_BAR = Object.freeze({
|
|
40
|
+
terminal: 10,
|
|
41
|
+
days: 7,
|
|
42
|
+
merge_rate: 0.7,
|
|
43
|
+
first_pass: 0.5,
|
|
44
|
+
escalation: 0.3,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const sameSet = (a, b) => a.length === b.length && a.every((x) => b.includes(x));
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {{ killSwitch: "true" | "false" | null, planApproval: string, mergeMode: string, autoTiers: string[] }} effective
|
|
51
|
+
* `killSwitch` is null when the variable could not be read.
|
|
52
|
+
* @returns {{ phase: number | null, candidates: number[], name: string | null }}
|
|
53
|
+
*/
|
|
54
|
+
export function matchPhase(effective) {
|
|
55
|
+
const matches = PHASES.filter(
|
|
56
|
+
(p) =>
|
|
57
|
+
p.plan === effective.planApproval &&
|
|
58
|
+
p.mode === effective.mergeMode &&
|
|
59
|
+
sameSet(p.tiers, effective.autoTiers) &&
|
|
60
|
+
(effective.killSwitch === null || p.kill === effective.killSwitch),
|
|
61
|
+
);
|
|
62
|
+
const candidates = matches.map((p) => p.phase);
|
|
63
|
+
if (candidates.length === 1) return { phase: candidates[0], candidates, name: matches[0].name };
|
|
64
|
+
return { phase: null, candidates, name: null };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const check = (name, value, met, want) => ({ name, value, met, want });
|
|
68
|
+
|
|
69
|
+
/** 1 to 2: over `low` and `medium` terminal tasks. */
|
|
70
|
+
function stagedBar(tasks, bar = STAGED_BAR) {
|
|
71
|
+
const mine = tasks.filter((t) => ["low", "medium"].includes(t.tier));
|
|
72
|
+
const n = mine.length;
|
|
73
|
+
const merged = mine.filter((t) => t.merged);
|
|
74
|
+
const rate = (k) => (n === 0 ? null : k / n);
|
|
75
|
+
const mergeRate = rate(merged.length);
|
|
76
|
+
const firstPass = rate(mine.filter((t) => t.firstPass).length);
|
|
77
|
+
const escalation = rate(mine.filter((t) => t.escalated).length);
|
|
78
|
+
const reverted = merged.filter((t) => t.reverted).length;
|
|
79
|
+
const starts = mine.map((t) => t.queuedAt).filter((t) => t !== null);
|
|
80
|
+
const days =
|
|
81
|
+
starts.length === 0
|
|
82
|
+
? 0
|
|
83
|
+
: (Math.max(...mine.map((t) => t.closedAt)) - Math.min(...starts)) / DAY;
|
|
84
|
+
return [
|
|
85
|
+
check("terminal tasks", n, n >= bar.terminal, `at least ${bar.terminal}`),
|
|
86
|
+
check("days covered", Math.floor(days), days >= bar.days, `at least ${bar.days}`),
|
|
87
|
+
check(
|
|
88
|
+
"merge rate",
|
|
89
|
+
mergeRate,
|
|
90
|
+
mergeRate !== null && mergeRate >= bar.merge_rate,
|
|
91
|
+
`at least ${bar.merge_rate}`,
|
|
92
|
+
),
|
|
93
|
+
check(
|
|
94
|
+
"first-pass success",
|
|
95
|
+
firstPass,
|
|
96
|
+
firstPass !== null && firstPass >= bar.first_pass,
|
|
97
|
+
`at least ${bar.first_pass}`,
|
|
98
|
+
),
|
|
99
|
+
check(
|
|
100
|
+
"escalation rate",
|
|
101
|
+
escalation,
|
|
102
|
+
escalation !== null && escalation <= bar.escalation,
|
|
103
|
+
`at most ${bar.escalation}`,
|
|
104
|
+
),
|
|
105
|
+
check(
|
|
106
|
+
"revert rate",
|
|
107
|
+
merged.length ? reverted / merged.length : null,
|
|
108
|
+
// With nothing merged there is no revert rate to call 0.
|
|
109
|
+
merged.length > 0 && reverted === 0,
|
|
110
|
+
"0",
|
|
111
|
+
),
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 2 to 3 and 3 to 4: the shadow bar on a tier, and that tier's revert rate of 0. */
|
|
116
|
+
function shadowBar(gate, tier, tasks) {
|
|
117
|
+
const g = gate.tiers[tier];
|
|
118
|
+
const merged = tasks.filter((t) => t.merged && t.tier === tier);
|
|
119
|
+
const reverted = merged.filter((t) => t.reverted).length;
|
|
120
|
+
return [
|
|
121
|
+
...g.checks.map((c) => check(`${tier}: ${c.name}`, c.value, c.met, "")),
|
|
122
|
+
check(
|
|
123
|
+
`${tier}: revert rate`,
|
|
124
|
+
merged.length ? reverted / merged.length : null,
|
|
125
|
+
merged.length > 0 && reverted === 0,
|
|
126
|
+
"0",
|
|
127
|
+
),
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Which phase the config matches and whether the next bar is met.
|
|
133
|
+
* @param {{ effective: object, tasks: object[], gate: object }} input
|
|
134
|
+
*/
|
|
135
|
+
export function rolloutOf({ effective, tasks, gate }) {
|
|
136
|
+
const match = matchPhase(effective);
|
|
137
|
+
const out = { phase: match.phase, name: match.name, candidates: match.candidates, effective };
|
|
138
|
+
if (match.phase === null) return { ...out, next: null };
|
|
139
|
+
const to = match.phase + 1;
|
|
140
|
+
const tier = to === 3 ? "low" : "medium";
|
|
141
|
+
if (match.phase === 0) {
|
|
142
|
+
return {
|
|
143
|
+
...out,
|
|
144
|
+
next: { phase: 1, bar: "none: the owner turns the Kill switch on", met: null, checks: [] },
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (match.phase === 4) return { ...out, next: null };
|
|
148
|
+
const checks = match.phase === 1 ? stagedBar(tasks) : shadowBar(gate, tier, tasks);
|
|
149
|
+
const text =
|
|
150
|
+
match.phase === 1
|
|
151
|
+
? "10 terminal tasks over 7 days on low and medium; merge rate 70%, first-pass 50%, escalation 30%, revert 0"
|
|
152
|
+
: `the shadow bar on ${tier}, and a ${tier} revert rate of 0`;
|
|
153
|
+
return { ...out, next: { phase: to, bar: text, met: checks.every((c) => c.met), checks } };
|
|
154
|
+
}
|