@mnaimfaizy/agent-kit 1.0.0-beta.14 → 1.0.0-beta.16
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 +22 -4
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +244 -6
- package/package.json +3 -2
- package/src/checks/ci-workflow.mjs +105 -0
- package/src/checks/claude-app.mjs +11 -2
- package/src/checks/custom-harness.mjs +157 -0
- package/src/checks/github-app.mjs +214 -0
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +27 -8
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +583 -36
- package/src/deep-scan/agent.mjs +88 -21
- package/src/deep-scan/credential.mjs +81 -32
- package/src/deep-scan/docker-driver.mjs +105 -42
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +68 -178
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +21 -10
- package/src/deep-scan/preflight.mjs +19 -6
- package/src/deep-scan/recipe.mjs +4 -0
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +224 -39
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +73 -13
- package/src/doctor.mjs +166 -5
- package/src/exec.mjs +14 -5
- package/src/factory/budget/budget.mjs +259 -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 +329 -0
- package/src/factory/doctor/index.mjs +56 -0
- package/src/factory/doctor/local.mjs +497 -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 +174 -0
- package/src/factory/init/index.mjs +337 -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 +123 -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 +163 -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/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 +490 -0
- package/src/factory/run/gh.mjs +46 -0
- package/src/factory/run/launch.mjs +47 -0
- package/src/factory/run/pipelines.mjs +261 -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 +68 -0
- package/src/factory/security/command.mjs +157 -0
- package/src/factory/setup/app.mjs +122 -0
- package/src/factory/setup/command.mjs +409 -0
- package/src/factory/setup/labels.mjs +25 -0
- package/src/factory/setup/reads.mjs +129 -0
- package/src/factory/setup/writes.mjs +126 -0
- package/src/factory/snapshot/write.mjs +176 -0
- package/src/factory/stop/command.mjs +136 -0
- package/src/factory/sweep/actions-main.mjs +117 -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 +394 -0
- package/src/factory/sweep/split.mjs +104 -0
- package/src/factory/sweep/states.mjs +87 -0
- package/src/factory/sweep/sweep-core.mjs +1781 -0
- package/src/factory/tracker/github.mjs +674 -0
- package/src/factory/tracker/operations.mjs +153 -0
- package/src/factory/upgrade/index.mjs +83 -0
- package/src/harness/adapters.mjs +30 -0
- package/src/harness/antigravity.mjs +187 -0
- package/src/harness/claude-code.mjs +8 -1
- package/src/harness/codex.mjs +219 -0
- package/src/harness/cursor.mjs +199 -0
- package/src/harness/custom/registry.mjs +21 -0
- package/src/harness/custom/schema.mjs +90 -0
- package/src/harness/custom.mjs +299 -0
- package/src/harness/facts.mjs +44 -7
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +86 -3
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +151 -3
- package/src/harness-live/assess.mjs +29 -6
- package/src/harness-live/cursor-real.mjs +146 -0
- package/src/harness-live/cursor-version.mjs +70 -0
- package/src/harness-live/cursor.mjs +80 -0
- package/src/harness-live/custom.mjs +91 -0
- package/src/harness-live/fixture-harness.mjs +45 -0
- package/src/harness-live/harnesses.mjs +263 -0
- package/src/harness-live/host.mjs +113 -4
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +87 -7
- package/src/harness-live/run.mjs +101 -20
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +25 -15
- package/src/harness-live/suite.mjs +276 -95
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +374 -36
- package/src/kit-owned-paths.mjs +1 -1
- package/src/model-proxy/core.mjs +128 -20
- package/src/model-proxy/profiles/anthropic.mjs +54 -10
- package/src/model-proxy/profiles/gemini-api.mjs +311 -0
- package/src/model-proxy/profiles/openai.mjs +327 -0
- package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
- package/src/model-proxy/stub-dialects/openai.mjs +173 -0
- package/src/model-proxy/stub.mjs +9 -1
- package/src/stage/audit.mjs +79 -0
- package/src/stage/egress-route.mjs +207 -0
- package/src/stage/implement/carry.mjs +308 -0
- package/src/stage/implement/sandbox.mjs +271 -0
- package/src/stage/implement/verify.mjs +70 -0
- package/src/stage/implement.mjs +218 -0
- package/src/stage/plan.mjs +115 -0
- package/src/stage/review-response.mjs +172 -0
- package/src/stage/review.mjs +185 -0
- package/src/stage/workspace.mjs +274 -0
- package/src/stage.mjs +1087 -0
- package/src/upgrade.mjs +39 -7
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// The merge gate's decision core (spec #500, Merge gate specifics; ADR 0035,
|
|
2
|
+
// ADR 0041): a pure function from the facts read for one `ready-to-merge`
|
|
3
|
+
// task's exact head to one decision. It does no IO. A fact the shell could not
|
|
4
|
+
// read arrives as `null` or `undefined`, and an unreadable fact holds: the gate
|
|
5
|
+
// fails closed. Contract suite: scripts/factory-gate-core.test.mjs over
|
|
6
|
+
// scripts/fixtures/factory/gate/.
|
|
7
|
+
//
|
|
8
|
+
// Decisions:
|
|
9
|
+
// { decision: "merge", head } every fact holds (acted on only in `on`: the sweep dispatches factory-merge)
|
|
10
|
+
// { decision: "update" } only the branch being behind stands in the way
|
|
11
|
+
// { decision: "hold", reasons } at least one fact fails or is unreadable
|
|
12
|
+
// { decision: "back-to-checking" } the head has no passing QA and security checks: it moved
|
|
13
|
+
// { decision: "merged" } a person merged the pull request
|
|
14
|
+
// Every decision also carries `tier` and `tierReasons`, and `mode`: the mode the
|
|
15
|
+
// gate acted in, which is `shadow` for a configured `on` while the gate is tripped
|
|
16
|
+
// (a revert or regression of one of its merges), or has left the trip by a cleared
|
|
17
|
+
// marker but not yet met the shadow bar again, or cannot read the trip (ADR 0041).
|
|
18
|
+
// A hold or a merge carries `tierOnly` when the Risk tier is the only thing in the way.
|
|
19
|
+
|
|
20
|
+
import { checkAllowedPaths } from "../checks/allowed-paths.mjs";
|
|
21
|
+
import { QA_CONTEXT } from "../checks/qa.mjs";
|
|
22
|
+
import { REVIEW_CONTEXT } from "../checks/review.mjs";
|
|
23
|
+
import { SECURITY_CONTEXT } from "../checks/security.mjs";
|
|
24
|
+
import { engineStageCheck } from "../checks/stage-check.mjs";
|
|
25
|
+
import { parseRiskRules, riskTier } from "../plan/risk.mjs";
|
|
26
|
+
import { guardedTouched } from "./guarded.mjs";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The newest check of `name` among a head's checks. A re-run adds a check of the same name, so the
|
|
30
|
+
* first one found may be an older failure that a newer success has replaced: the one with the
|
|
31
|
+
* latest `at` stands (a check with a time beats one without), and where both lack it or tie the later one in the list does.
|
|
32
|
+
*/
|
|
33
|
+
export function newestCheck(checks, name) {
|
|
34
|
+
let best;
|
|
35
|
+
for (const check of checks) {
|
|
36
|
+
if (check.name !== name) continue;
|
|
37
|
+
if (best === undefined) best = check;
|
|
38
|
+
else if (Number.isNaN(Date.parse(check.at)))
|
|
39
|
+
best = Number.isNaN(Date.parse(best.at)) ? check : best;
|
|
40
|
+
else if (!(Date.parse(best.at) > Date.parse(check.at))) best = check;
|
|
41
|
+
}
|
|
42
|
+
return best;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const MERGE_MODES = Object.freeze(["off", "shadow", "on"]);
|
|
46
|
+
export const RISK_TIERS = Object.freeze(["low", "medium", "high"]);
|
|
47
|
+
export const DEFAULT_AUTO_TIERS = Object.freeze(["low"]);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The mode the gate acts in. `off` and `shadow` are themselves. `on` needs the trip
|
|
51
|
+
* fact: `none` (no trip on the control issue and none in the evidence), or `cleared`
|
|
52
|
+
* with the shadow bar met again counted from the trip. A trip that stands, a cleared
|
|
53
|
+
* one whose bar is not met, and a trip that could not be read all act as `shadow`.
|
|
54
|
+
* @param {string | null | undefined} mode
|
|
55
|
+
* @param {{ state: string, barMet?: boolean | null } | null | undefined} trip
|
|
56
|
+
* @returns {{ mode: string | null | undefined, why: string | null }}
|
|
57
|
+
*/
|
|
58
|
+
export function gateMode(mode, trip) {
|
|
59
|
+
if (mode !== "on") return { mode, why: null };
|
|
60
|
+
if (!trip || !["none", "tripped", "cleared"].includes(trip.state)) {
|
|
61
|
+
return { mode: "shadow", why: "trip unreadable" };
|
|
62
|
+
}
|
|
63
|
+
if (trip.state === "none") return { mode: "on", why: null };
|
|
64
|
+
if (trip.state === "tripped") return { mode: "shadow", why: "tripped" };
|
|
65
|
+
if (trip.barMet === true) return { mode: "on", why: null };
|
|
66
|
+
return {
|
|
67
|
+
mode: "shadow",
|
|
68
|
+
why: trip.barMet === false ? "shadow bar not met since the trip" : "shadow bar unreadable",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const rank = (tier) => RISK_TIERS.indexOf(tier);
|
|
73
|
+
const known = (v) => v !== null && v !== undefined;
|
|
74
|
+
|
|
75
|
+
/** The tiers the gate may merge: `high` is never one, whatever the config says. */
|
|
76
|
+
export const autoTiersOf = (tiers) =>
|
|
77
|
+
Array.isArray(tiers)
|
|
78
|
+
? tiers.filter((t) => t === "low" || t === "medium")
|
|
79
|
+
: [...DEFAULT_AUTO_TIERS];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A Stage check's description with one trailing ` (carried from <sha7>)` removed,
|
|
83
|
+
* and only when that sha7 is the head the gate itself updated from (ADR 0035).
|
|
84
|
+
* Any other suffix is left on, so the description then matches nothing.
|
|
85
|
+
*/
|
|
86
|
+
export function stripCarried(description, carriedFrom) {
|
|
87
|
+
const m = /^(.*) \(carried from ([0-9a-f]{7})\)$/.exec(String(description));
|
|
88
|
+
if (!m) return String(description);
|
|
89
|
+
return carriedFrom && carriedFrom.startsWith(m[2]) && /^[0-9a-f]{40}$/.test(carriedFrom)
|
|
90
|
+
? m[1]
|
|
91
|
+
: String(description);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The Risk tier: the highest of the plan's, the risk rules on the final diff (the
|
|
96
|
+
* rules file as the base branch has it) and a person's `risk:<tier>` label. A
|
|
97
|
+
* missing or unreadable rules file, or a plan that cannot be read, is `high`.
|
|
98
|
+
*/
|
|
99
|
+
export function gateTier({ plan, rulesText, files, lines, labels = [] }) {
|
|
100
|
+
const reasons = [];
|
|
101
|
+
if (!plan || !RISK_TIERS.includes(plan.risk))
|
|
102
|
+
return { tier: "high", reasons: ["plan unreadable"] };
|
|
103
|
+
let tier = plan.risk;
|
|
104
|
+
const raise = (to, why) => {
|
|
105
|
+
if (rank(to) > rank(tier)) tier = to;
|
|
106
|
+
if (rank(to) >= rank(plan.risk) && why) reasons.push(why);
|
|
107
|
+
};
|
|
108
|
+
const ruled = riskTier({
|
|
109
|
+
planner: plan.risk,
|
|
110
|
+
parsed: parseRiskRules(rulesText),
|
|
111
|
+
// The final diff's real paths, or the plan's Allowed paths when it was not read.
|
|
112
|
+
allowedPaths: known(files) ? files : (plan.allowed_paths ?? []),
|
|
113
|
+
// The plan's Task size, or `l` when the real diff is over 400 lines (the gate measures it).
|
|
114
|
+
size: known(lines) && lines > 400 ? "l" : plan.size,
|
|
115
|
+
labels,
|
|
116
|
+
});
|
|
117
|
+
raise(ruled.risk, ruled.raisedBy.length ? `rules ${ruled.raisedBy.join(", ")}` : null);
|
|
118
|
+
for (const t of RISK_TIERS) if (labels.includes(`risk:${t}`)) raise(t, `label risk:${t}`);
|
|
119
|
+
if (!known(files)) raise("high", "diff unreadable");
|
|
120
|
+
// Guarded paths are always `high` (spec #500), whatever the rules file says.
|
|
121
|
+
else if (guardedTouched(files).length) raise("high", "Guarded path");
|
|
122
|
+
if (!known(lines)) raise("high", "diff size unreadable");
|
|
123
|
+
return { tier, reasons };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @param {{
|
|
128
|
+
* mode: string | null | undefined,
|
|
129
|
+
* trip?: { state: "none" | "tripped" | "cleared", barMet?: boolean | null } | null,
|
|
130
|
+
* autoTiers?: string[] | null,
|
|
131
|
+
* killSwitch?: string,
|
|
132
|
+
* paused?: boolean,
|
|
133
|
+
* mergeTaken?: boolean,
|
|
134
|
+
* pull: { state: string, head: string } | null | undefined,
|
|
135
|
+
* isEngine: (login: string) => boolean,
|
|
136
|
+
* statuses: object[] | null | undefined,
|
|
137
|
+
* carriedFrom?: string | null,
|
|
138
|
+
* plan: { risk: string, allowed_paths: string[], size?: string } | null | undefined,
|
|
139
|
+
* rulesText: string | null | undefined,
|
|
140
|
+
* labels?: string[],
|
|
141
|
+
* files: string[] | null | undefined,
|
|
142
|
+
* lines: number | null | undefined,
|
|
143
|
+
* required: string[] | null | undefined,
|
|
144
|
+
* headChecks: Array<{ name: string, state: string }> | null | undefined,
|
|
145
|
+
* baseGreen: boolean | null | undefined,
|
|
146
|
+
* behind: boolean | null | undefined,
|
|
147
|
+
* conflict: boolean | null | undefined,
|
|
148
|
+
* }} facts
|
|
149
|
+
*/
|
|
150
|
+
export function decideGate(facts) {
|
|
151
|
+
const { pull } = facts;
|
|
152
|
+
const acting = gateMode(facts.mode, facts.trip);
|
|
153
|
+
const mode = acting.mode;
|
|
154
|
+
const labels = facts.labels ?? [];
|
|
155
|
+
const { tier, reasons: tierReasons } = gateTier({
|
|
156
|
+
plan: facts.plan,
|
|
157
|
+
rulesText: facts.rulesText,
|
|
158
|
+
files: facts.files,
|
|
159
|
+
lines: facts.lines,
|
|
160
|
+
labels,
|
|
161
|
+
});
|
|
162
|
+
const base = { tier, tierReasons, mode, ...(acting.why ? { tripped: acting.why } : {}) };
|
|
163
|
+
if (pull?.state === "MERGED") return { ...base, decision: "merged" };
|
|
164
|
+
const hold = (reasons) => ({ ...base, decision: "hold", reasons });
|
|
165
|
+
if (!pull || pull.state !== "OPEN" || !/^[0-9a-f]{40}$/.test(pull.head ?? "")) {
|
|
166
|
+
return hold(["pull request unreadable"]);
|
|
167
|
+
}
|
|
168
|
+
const head = pull.head;
|
|
169
|
+
if (!known(facts.statuses)) return hold(["Stage checks unreadable"]);
|
|
170
|
+
|
|
171
|
+
// The three Stage checks, by creator. A head with none that passes has moved.
|
|
172
|
+
const review = engineStageCheck(facts.statuses, REVIEW_CONTEXT, facts.isEngine);
|
|
173
|
+
const qa = engineStageCheck(facts.statuses, QA_CONTEXT, facts.isEngine);
|
|
174
|
+
const security = engineStageCheck(facts.statuses, SECURITY_CONTEXT, facts.isEngine);
|
|
175
|
+
// QA and security are what take a task out of `checking`, so one that is not a
|
|
176
|
+
// success sends it back there; a review that is not a success only holds (the
|
|
177
|
+
// sweep would otherwise move the task straight out of `checking` again).
|
|
178
|
+
if (qa?.state !== "success" || security?.state !== "success") {
|
|
179
|
+
return { ...base, decision: "back-to-checking" };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const reasons = [];
|
|
183
|
+
if (review?.state !== "success") reasons.push("review not passed");
|
|
184
|
+
const carriedFrom = facts.carriedFrom ?? null;
|
|
185
|
+
const qaText = stripCarried(qa.description, carriedFrom);
|
|
186
|
+
if (qaText !== "passed") {
|
|
187
|
+
const held = /^passed; held ([0-9]+)$/.exec(qaText);
|
|
188
|
+
reasons.push(held ? `qa held ${held[1]}` : "qa not exactly passed");
|
|
189
|
+
}
|
|
190
|
+
if (stripCarried(security.description, carriedFrom) !== "passed") {
|
|
191
|
+
reasons.push("security not passed");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!known(facts.required)) reasons.push("required CI unreadable");
|
|
195
|
+
else if (facts.required.length === 0) reasons.push("no required CI in the ruleset");
|
|
196
|
+
else if (!known(facts.headChecks)) reasons.push("CI on the head unreadable");
|
|
197
|
+
else {
|
|
198
|
+
const bad = facts.required.filter(
|
|
199
|
+
(name) => newestCheck(facts.headChecks, name)?.state !== "success",
|
|
200
|
+
);
|
|
201
|
+
if (bad.length) reasons.push(`required CI not green: ${bad.join(", ")}`);
|
|
202
|
+
}
|
|
203
|
+
if (!known(facts.baseGreen)) reasons.push("base CI unreadable");
|
|
204
|
+
else if (!facts.baseGreen) reasons.push("base not green");
|
|
205
|
+
|
|
206
|
+
const changed = facts.files;
|
|
207
|
+
if (known(changed)) {
|
|
208
|
+
const allowed = facts.plan?.allowed_paths;
|
|
209
|
+
if (!Array.isArray(allowed)) reasons.push("Allowed paths unreadable");
|
|
210
|
+
else {
|
|
211
|
+
const outside = checkAllowedPaths({ allowedPaths: allowed, changedPaths: changed }).outside;
|
|
212
|
+
if (outside.length) reasons.push(`outside Allowed paths: ${outside.join(", ")}`);
|
|
213
|
+
}
|
|
214
|
+
const guarded = guardedTouched(changed);
|
|
215
|
+
if (guarded.length) reasons.push(`Guarded path: ${guarded.join(", ")}`);
|
|
216
|
+
} else reasons.push("changed files unreadable");
|
|
217
|
+
|
|
218
|
+
if (facts.paused) reasons.push("paused");
|
|
219
|
+
if (facts.killSwitch !== undefined && facts.killSwitch !== "true")
|
|
220
|
+
reasons.push("Kill switch off");
|
|
221
|
+
|
|
222
|
+
const tierBlocks =
|
|
223
|
+
mode !== "off" && !autoTiersOf(facts.autoTiers).includes(tier) ? `tier ${tier}` : null;
|
|
224
|
+
const behindReason = !known(facts.behind)
|
|
225
|
+
? "up to date unreadable"
|
|
226
|
+
: facts.behind
|
|
227
|
+
? facts.conflict === true
|
|
228
|
+
? "behind with a conflict"
|
|
229
|
+
: !known(facts.conflict)
|
|
230
|
+
? "conflict unreadable"
|
|
231
|
+
: "behind the base"
|
|
232
|
+
: null;
|
|
233
|
+
const modeReason = !MERGE_MODES.includes(mode)
|
|
234
|
+
? "mode unreadable"
|
|
235
|
+
: mode === "off"
|
|
236
|
+
? "mode off"
|
|
237
|
+
: null;
|
|
238
|
+
|
|
239
|
+
const all = [...reasons, ...[tierBlocks, behindReason, modeReason].filter(Boolean)];
|
|
240
|
+
// Only the branch being behind, with no conflict, is mended by an update.
|
|
241
|
+
if (behindReason === "behind the base" && reasons.length === 0 && !tierBlocks && !modeReason) {
|
|
242
|
+
return { ...base, decision: "update", head };
|
|
243
|
+
}
|
|
244
|
+
if (all.length === 0) {
|
|
245
|
+
if (facts.mergeTaken) return hold(["another merge goes first in this sweep"]);
|
|
246
|
+
return { ...base, decision: "merge", head };
|
|
247
|
+
}
|
|
248
|
+
const tierOnly = tierBlocks !== null && all.length === 1;
|
|
249
|
+
return { ...hold(all), head, ...(tierOnly ? { tierOnly: true } : {}) };
|
|
250
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The Guarded paths (spec #500, Risk rules): the gate mode, the risk rules, the
|
|
2
|
+
// factory config and the workflows, plus the Kit-owned bundle that runs the
|
|
3
|
+
// sweep. A pull request that touches one is always `high` and never auto-merges.
|
|
4
|
+
// The list is the Kit's, fixed here, so a pull request cannot shorten it; the
|
|
5
|
+
// files it names are judged as the base branch has them.
|
|
6
|
+
|
|
7
|
+
import { pathMatchesGlob } from "../plan/risk.mjs";
|
|
8
|
+
|
|
9
|
+
export const GUARDED_PATHS = Object.freeze([
|
|
10
|
+
".github/factory/**",
|
|
11
|
+
".github/workflows/**",
|
|
12
|
+
".github/agent-factory/**",
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
/** The changed paths that fall under a Guarded path. */
|
|
16
|
+
export const guardedTouched = (changedPaths) =>
|
|
17
|
+
changedPaths.filter((path) => GUARDED_PATHS.some((glob) => pathMatchesGlob(glob, path)));
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// The merge gate's reads (the shell side of the gate): for each `ready-to-merge`
|
|
2
|
+
// task that has an open pull request, the facts the decision core needs, read
|
|
3
|
+
// through the tracker adapter's named operations and attached to the sweep's
|
|
4
|
+
// read as `read.gate`. Every read is its own try: one that fails leaves that
|
|
5
|
+
// fact `null`, which the core holds on (spec #500: a fact it cannot read holds).
|
|
6
|
+
// A tracker without these operations (a fake in a suite) leaves every fact unread.
|
|
7
|
+
//
|
|
8
|
+
// read.gate = { byIssue: { [issue]: { pull, rulesText, gateComment, required,
|
|
9
|
+
// headChecks, baseGreen, behind, conflict, carry } } }
|
|
10
|
+
|
|
11
|
+
import { parseGateComment } from "./comment.mjs";
|
|
12
|
+
|
|
13
|
+
/** The risk rules, read from the base branch only, never from a pull request. */
|
|
14
|
+
export const RISK_RULES_FILE = ".github/factory/risk-rules.json";
|
|
15
|
+
|
|
16
|
+
const gateLogin = (login) =>
|
|
17
|
+
String(login ?? "")
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.replace(/\[bot\]$/, "");
|
|
20
|
+
|
|
21
|
+
/** The open pull request of the newest build Attempt's branch (`factory/<issue>/attempt-<n>`). */
|
|
22
|
+
function pullOf(issue) {
|
|
23
|
+
const attempt = (p) =>
|
|
24
|
+
Number(new RegExp(`^factory/${issue.number}/attempt-(\\d+)$`).exec(p.branch)?.[1] ?? -1);
|
|
25
|
+
return (
|
|
26
|
+
(issue.pulls ?? [])
|
|
27
|
+
.filter((p) => p.state === "OPEN" && attempt(p) >= 0)
|
|
28
|
+
.sort((x, y) => attempt(y) - attempt(x))[0] ?? null
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {object} read the sweep's read, changed in place
|
|
34
|
+
* @param {object} tracker
|
|
35
|
+
* @param {{ identity: string }} engine
|
|
36
|
+
* @param {(line: string) => void} log
|
|
37
|
+
*/
|
|
38
|
+
export function attachGateFacts(read, tracker, engine, log) {
|
|
39
|
+
const tasks = (read.issues ?? []).filter(
|
|
40
|
+
(i) => (i.labels ?? []).includes("factory:ready-to-merge") && i.state !== "CLOSED",
|
|
41
|
+
);
|
|
42
|
+
read.gate = { byIssue: {} };
|
|
43
|
+
const tried = (what, fn) => {
|
|
44
|
+
try {
|
|
45
|
+
return fn();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
log(
|
|
48
|
+
`notice: merge gate could not read ${what} (${error instanceof Error ? error.message : error})`,
|
|
49
|
+
);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const rules = new Map();
|
|
54
|
+
for (const issue of tasks) {
|
|
55
|
+
const open = pullOf(issue);
|
|
56
|
+
if (!open || !tracker.readPull) continue;
|
|
57
|
+
const g = (read.gate.byIssue[issue.number] = {});
|
|
58
|
+
g.pull = tried(`pull request #${open.number}`, () => tracker.readPull(open.number));
|
|
59
|
+
if (!g.pull || g.pull.state !== "OPEN") continue;
|
|
60
|
+
const { base, head } = g.pull;
|
|
61
|
+
g.gateComment = tried(`the comments of #${open.number}`, () => {
|
|
62
|
+
const mine = tracker
|
|
63
|
+
.readComments(open.number)
|
|
64
|
+
.filter(
|
|
65
|
+
(c) => gateLogin(c.author) === gateLogin(engine.identity) && parseGateComment(c.body),
|
|
66
|
+
);
|
|
67
|
+
return mine.at(-1) ?? null;
|
|
68
|
+
});
|
|
69
|
+
if (!rules.has(base)) {
|
|
70
|
+
try {
|
|
71
|
+
rules.set(base, tracker.readFile(RISK_RULES_FILE, base));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
log(
|
|
74
|
+
`notice: merge gate could not read ${RISK_RULES_FILE} on ${base} (${error instanceof Error ? error.message : error})`,
|
|
75
|
+
);
|
|
76
|
+
// Not JSON, so the rules are unreadable and the tier is `high`.
|
|
77
|
+
rules.set(base, "unreadable");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
g.rulesText = rules.get(base);
|
|
81
|
+
const compare = tried(`${base}...${head}`, () => tracker.readCompare(base, head));
|
|
82
|
+
g.behind = compare ? compare.behindBy > 0 : null;
|
|
83
|
+
g.conflict = g.pull.mergeable === true ? false : g.pull.mergeable === false ? true : null;
|
|
84
|
+
g.required = tried(`the ruleset of ${base}`, () => tracker.readRequiredContexts(base));
|
|
85
|
+
g.headChecks = tried(`the checks of ${head}`, () => tracker.readChecks(head).contexts);
|
|
86
|
+
g.baseGreen = tried(
|
|
87
|
+
`the checks of ${base}`,
|
|
88
|
+
() => tracker.readChecks(`refs/heads/${base}`).state === "success",
|
|
89
|
+
);
|
|
90
|
+
const marker = g.gateComment ? parseGateComment(g.gateComment.body) : null;
|
|
91
|
+
if (marker?.updating && marker.head !== head) {
|
|
92
|
+
const since = tried(`${marker.head}...${head}`, () => tracker.readCompare(marker.head, head));
|
|
93
|
+
const oldStatuses = tried(
|
|
94
|
+
`the checks of ${marker.head}`,
|
|
95
|
+
() => tracker.readHeadStatuses([marker.head])[marker.head],
|
|
96
|
+
);
|
|
97
|
+
g.carry = {
|
|
98
|
+
descends: since ? since.aheadBy >= 1 && since.behindBy === 0 : null,
|
|
99
|
+
// Files the update brought in are the base side's; none may be one of the pull request's.
|
|
100
|
+
overlap: since ? since.files.some((f) => g.pull.files.includes(f)) : null,
|
|
101
|
+
oldStatuses,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// The gate for one `ready-to-merge` task, as the sweep core runs it: the facts
|
|
2
|
+
// the shell read (`read.gate`), the task's plan and labels and the Stage checks
|
|
3
|
+
// on its head go to the decision core, and the decision becomes actions. Pure.
|
|
4
|
+
//
|
|
5
|
+
// merged -> set-state merged (a person merged it)
|
|
6
|
+
// back-to-checking -> gate-comment, set-state checking
|
|
7
|
+
// update -> gate-comment (updating), gate-update (in `shadow` and `on`, never `off`)
|
|
8
|
+
// hold -> gate-comment (edited in place; unchanged text is not written)
|
|
9
|
+
// merge -> gate-comment, then in `on` a `merge` action (the sweep dispatches the
|
|
10
|
+
// factory-merge job); in `shadow` the comment alone ("would merge")
|
|
11
|
+
//
|
|
12
|
+
// And before the decision, the carry-over (ADR 0035, ADR 0041): a head the gate
|
|
13
|
+
// itself asked GitHub to update, with no Stage checks of its own, gets the old
|
|
14
|
+
// head's three checks copied with ` (carried from <sha7>)`, but only when the
|
|
15
|
+
// new head descends from the old one and the base side changed none of this
|
|
16
|
+
// pull request's files. Anything else has no checks, so the decision is
|
|
17
|
+
// `back-to-checking` and all three Stages run again.
|
|
18
|
+
//
|
|
19
|
+
// `on` merges only while the gate is not tripped: a trip that stands, a cleared one
|
|
20
|
+
// whose shadow bar is not met again, or a trip that cannot be read act as `shadow`
|
|
21
|
+
// (gate-core `gateMode`, ADR 0041). The decision carries the mode it acted in.
|
|
22
|
+
|
|
23
|
+
import { checkPlanHeader } from "../checks/plan-header.mjs";
|
|
24
|
+
import { QA_CONTEXT } from "../checks/qa.mjs";
|
|
25
|
+
import { REVIEW_CONTEXT } from "../checks/review.mjs";
|
|
26
|
+
import { SECURITY_CONTEXT } from "../checks/security.mjs";
|
|
27
|
+
import { engineStageCheck } from "../checks/stage-check.mjs";
|
|
28
|
+
import { latestPlan } from "../plan/comment.mjs";
|
|
29
|
+
import { parseGateComment, renderGateComment } from "./comment.mjs";
|
|
30
|
+
import { decideGate, stripCarried } from "./gate-core.mjs";
|
|
31
|
+
|
|
32
|
+
const CONTEXTS = [REVIEW_CONTEXT, QA_CONTEXT, SECURITY_CONTEXT];
|
|
33
|
+
|
|
34
|
+
/** The carried copies of the old head's three checks, or null when carrying is not allowed. */
|
|
35
|
+
export function carriedChecks({ marker, head, carry, isEngine }) {
|
|
36
|
+
if (!marker?.updating || marker.head === head || !carry) return null;
|
|
37
|
+
if (carry.descends !== true || carry.overlap !== false || !carry.oldStatuses) return null;
|
|
38
|
+
const old7 = marker.head.slice(0, 7);
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const context of CONTEXTS) {
|
|
41
|
+
const check = engineStageCheck(carry.oldStatuses, context, isEngine);
|
|
42
|
+
if (check?.state !== "success") return null;
|
|
43
|
+
const plain = stripCarried(check.description, marker.carriedFrom);
|
|
44
|
+
out.push({ context, state: "success", description: `${plain} (carried from ${old7})` });
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @returns {{ actions: object[], merges: boolean }} `merges` is true when this task took the sweep's one merge
|
|
51
|
+
*/
|
|
52
|
+
export function gateActions(input) {
|
|
53
|
+
const { issue, pull, mergedPull, read, cfg, ctx, isEngine, mergeTaken, trip } = input;
|
|
54
|
+
const n = issue.number;
|
|
55
|
+
const actions = [];
|
|
56
|
+
if (mergedPull || pull?.state === "MERGED") {
|
|
57
|
+
actions.push({
|
|
58
|
+
type: "set-state",
|
|
59
|
+
issue: n,
|
|
60
|
+
from: "ready-to-merge",
|
|
61
|
+
to: "merged",
|
|
62
|
+
reason: "merged-by-a-person",
|
|
63
|
+
});
|
|
64
|
+
return { actions, merges: false };
|
|
65
|
+
}
|
|
66
|
+
// A closed issue with no merged pull request is not a task to judge.
|
|
67
|
+
if (issue.state === "CLOSED") return { actions, merges: false };
|
|
68
|
+
if (!pull) {
|
|
69
|
+
actions.push({
|
|
70
|
+
type: "notice",
|
|
71
|
+
issue: n,
|
|
72
|
+
code: "ready-to-merge-without-a-pull-request",
|
|
73
|
+
message:
|
|
74
|
+
"In factory:ready-to-merge with no pull request on the build Attempt's branch: left alone.",
|
|
75
|
+
});
|
|
76
|
+
return { actions, merges: false };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const g = read.gate?.byIssue?.[n] ?? {};
|
|
80
|
+
// The facts must be of the pull request the sweep is judging; otherwise they are unread.
|
|
81
|
+
const facts = g.pull && g.pull.number === pull.number ? g.pull : null;
|
|
82
|
+
const head = facts?.head ?? null;
|
|
83
|
+
const marker = g.gateComment ? parseGateComment(g.gateComment.body) : null;
|
|
84
|
+
|
|
85
|
+
let statuses = head ? (read.statuses?.[head] ?? null) : null;
|
|
86
|
+
let carriedFrom = marker && marker.head === head ? marker.carriedFrom : null;
|
|
87
|
+
if (head && statuses) {
|
|
88
|
+
const bare = CONTEXTS.every((c) => engineStageCheck(statuses, c, isEngine) === null);
|
|
89
|
+
const copies = bare ? carriedChecks({ marker, head, carry: g.carry, isEngine }) : null;
|
|
90
|
+
if (copies) {
|
|
91
|
+
actions.push({
|
|
92
|
+
type: "copy-stage-checks",
|
|
93
|
+
issue: n,
|
|
94
|
+
head,
|
|
95
|
+
from: marker.head,
|
|
96
|
+
checks: copies,
|
|
97
|
+
});
|
|
98
|
+
statuses = [...copies.map((c) => ({ ...c, creator: ctx.engine.identity })), ...statuses];
|
|
99
|
+
carriedFrom = marker.head;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const plan = latestPlan(issue.comments, isEngine);
|
|
104
|
+
const checked = plan ? checkPlanHeader(plan.data, { trusted: true }) : null;
|
|
105
|
+
const decision = decideGate({
|
|
106
|
+
mode: cfg.merge.mode,
|
|
107
|
+
trip: cfg.merge.mode === "on" ? trip : undefined,
|
|
108
|
+
autoTiers: cfg.merge.auto_tiers,
|
|
109
|
+
killSwitch: "true",
|
|
110
|
+
paused: false,
|
|
111
|
+
mergeTaken,
|
|
112
|
+
pull: facts ? { state: facts.state, head } : null,
|
|
113
|
+
isEngine,
|
|
114
|
+
statuses,
|
|
115
|
+
carriedFrom,
|
|
116
|
+
plan: checked?.ok
|
|
117
|
+
? {
|
|
118
|
+
risk: checked.header.risk,
|
|
119
|
+
allowed_paths: checked.header.allowed_paths,
|
|
120
|
+
size: checked.header.size,
|
|
121
|
+
}
|
|
122
|
+
: null,
|
|
123
|
+
rulesText: g.rulesText,
|
|
124
|
+
labels: issue.labels ?? [],
|
|
125
|
+
files: facts?.files ?? null,
|
|
126
|
+
lines: facts?.lines ?? null,
|
|
127
|
+
required: g.required ?? null,
|
|
128
|
+
headChecks: g.headChecks ?? null,
|
|
129
|
+
baseGreen: g.baseGreen ?? null,
|
|
130
|
+
behind: g.behind ?? null,
|
|
131
|
+
conflict: g.conflict ?? null,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if (decision.decision === "merged") {
|
|
135
|
+
actions.push({
|
|
136
|
+
type: "set-state",
|
|
137
|
+
issue: n,
|
|
138
|
+
from: "ready-to-merge",
|
|
139
|
+
to: "merged",
|
|
140
|
+
reason: "merged-by-a-person",
|
|
141
|
+
});
|
|
142
|
+
return { actions, merges: false };
|
|
143
|
+
}
|
|
144
|
+
if (!head) {
|
|
145
|
+
actions.push({
|
|
146
|
+
type: "notice",
|
|
147
|
+
issue: n,
|
|
148
|
+
code: "gate-pull-unreadable",
|
|
149
|
+
message:
|
|
150
|
+
"The pull request's head could not be read: the merge gate holds and writes no comment.",
|
|
151
|
+
});
|
|
152
|
+
return { actions, merges: false };
|
|
153
|
+
}
|
|
154
|
+
const updating = decision.decision === "update";
|
|
155
|
+
const body = renderGateComment({
|
|
156
|
+
mode: decision.mode === "shadow" || decision.mode === "on" ? decision.mode : "off",
|
|
157
|
+
decision,
|
|
158
|
+
head,
|
|
159
|
+
updating,
|
|
160
|
+
carriedFrom: updating ? null : carriedFrom,
|
|
161
|
+
});
|
|
162
|
+
if (g.gateComment?.body !== body) {
|
|
163
|
+
actions.push({
|
|
164
|
+
type: "gate-comment",
|
|
165
|
+
issue: n,
|
|
166
|
+
pull: facts.number ?? pull.number,
|
|
167
|
+
commentId: g.gateComment?.id ?? null,
|
|
168
|
+
body,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
if (decision.decision === "back-to-checking") {
|
|
172
|
+
actions.push({
|
|
173
|
+
type: "set-state",
|
|
174
|
+
issue: n,
|
|
175
|
+
from: "ready-to-merge",
|
|
176
|
+
to: "checking",
|
|
177
|
+
reason: "head-moved",
|
|
178
|
+
});
|
|
179
|
+
} else if (updating) {
|
|
180
|
+
actions.push({ type: "gate-update", issue: n, pull: facts.number ?? pull.number, head });
|
|
181
|
+
}
|
|
182
|
+
const merges = decision.decision === "merge" && decision.mode === "on";
|
|
183
|
+
if (merges) {
|
|
184
|
+
actions.push({
|
|
185
|
+
type: "merge",
|
|
186
|
+
issue: n,
|
|
187
|
+
pull: facts.number ?? pull.number,
|
|
188
|
+
head,
|
|
189
|
+
method: cfg.merge.method,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return { actions, merges };
|
|
193
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// The shell side of the gate's trip (ADR 0041): in `merge.mode: on` it reads the
|
|
2
|
+
// Factory control issue's comments, the evidence of a revert or regression of one
|
|
3
|
+
// of the gate's merges, and (only while a person's clearing is being judged) who
|
|
4
|
+
// has write access and whether the shadow bar is met again since the trip. It
|
|
5
|
+
// attaches the answer to the sweep's read as `read.trip`. Any read that fails
|
|
6
|
+
// leaves the trip `unreadable`, which makes the gate act as `shadow`.
|
|
7
|
+
//
|
|
8
|
+
// read.trip = { state, at, barMet?, why?, write?, controlIssue, body? }
|
|
9
|
+
|
|
10
|
+
import { autoTiersOf } from "./gate-core.mjs";
|
|
11
|
+
import { isoOf } from "../report/facts.mjs";
|
|
12
|
+
import { shadowBarOf } from "../report/gate-section.mjs";
|
|
13
|
+
import { renderTripComment, tripState } from "./trip.mjs";
|
|
14
|
+
|
|
15
|
+
/** The shadow bar's window in days: the report's own default. */
|
|
16
|
+
export const TRIP_EVIDENCE_DAYS = 30;
|
|
17
|
+
|
|
18
|
+
const tripLogin = (login) =>
|
|
19
|
+
String(login ?? "")
|
|
20
|
+
.toLowerCase()
|
|
21
|
+
.replace(/\[bot\]$/, "");
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {object} read the sweep's read, changed in place
|
|
25
|
+
* @param {{
|
|
26
|
+
* tracker: { readControl: Function, readWriters?: Function },
|
|
27
|
+
* engine: { identity: string },
|
|
28
|
+
* readEvidence: () => { issues: object[] },
|
|
29
|
+
* autoTiers: string[],
|
|
30
|
+
* now: number,
|
|
31
|
+
* log: (line: string) => void,
|
|
32
|
+
* }} deps
|
|
33
|
+
*/
|
|
34
|
+
export function attachTrip(read, { tracker, engine, readEvidence, autoTiers, now, log }) {
|
|
35
|
+
const isEngine = (login) => tripLogin(login) === tripLogin(engine.identity);
|
|
36
|
+
const unreadable = (why) => {
|
|
37
|
+
log(`notice: merge gate could not read its trip (${why}): it acts as shadow`);
|
|
38
|
+
read.trip = { state: "unreadable", at: null, why, controlIssue: null };
|
|
39
|
+
};
|
|
40
|
+
let control;
|
|
41
|
+
let evidence;
|
|
42
|
+
try {
|
|
43
|
+
control = tracker.readControl();
|
|
44
|
+
evidence = readEvidence();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return unreadable(error instanceof Error ? error.message : String(error));
|
|
47
|
+
}
|
|
48
|
+
const bar = (tripAt) =>
|
|
49
|
+
shadowBarOf(evidence.issues, { isEngine }, { now, days: TRIP_EVIDENCE_DAYS, tripAt });
|
|
50
|
+
const seen = bar(null).trip;
|
|
51
|
+
const comments = control?.comments ?? [];
|
|
52
|
+
const editors = [...new Set(comments.map((c) => c.editor).filter((e) => e && !isEngine(e)))];
|
|
53
|
+
let writers = [];
|
|
54
|
+
if (editors.length) {
|
|
55
|
+
try {
|
|
56
|
+
writers = tracker.readWriters(editors);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
log(
|
|
59
|
+
`notice: merge gate could not read who has write access (${error instanceof Error ? error.message : error}): a cleared trip marker does not count this sweep`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const facts = { evidenceAt: seen?.at ?? null, comments, writers, isEngine, barMet: null };
|
|
64
|
+
let state = tripState(facts);
|
|
65
|
+
if (state.state === "cleared") {
|
|
66
|
+
const tiers = autoTiersOf(autoTiers);
|
|
67
|
+
const met = tiers.length
|
|
68
|
+
? tiers.every((t) => bar(state.at).section.tiers[t]?.met === true)
|
|
69
|
+
: false;
|
|
70
|
+
state = tripState({ ...facts, barMet: met });
|
|
71
|
+
}
|
|
72
|
+
read.trip = {
|
|
73
|
+
...state,
|
|
74
|
+
controlIssue: control?.number ?? null,
|
|
75
|
+
...(state.write && control
|
|
76
|
+
? { body: renderTripComment({ atIso: isoOf(state.at), pull: seen?.pull ?? null }) }
|
|
77
|
+
: { write: false }),
|
|
78
|
+
};
|
|
79
|
+
if (state.write && !control) {
|
|
80
|
+
read.trip.why = "no Factory control issue to hold the marker";
|
|
81
|
+
}
|
|
82
|
+
}
|