lastlight-core 0.21.14 → 0.23.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/config/default.yaml +119 -1
- package/dist/admin/routes.js +195 -38
- package/dist/admin/routes.js.map +1 -1
- package/dist/config/config-resolve.d.ts +38 -1
- package/dist/config/config-resolve.js +41 -17
- package/dist/config/config-resolve.js.map +1 -1
- package/dist/config/config.d.ts +114 -0
- package/dist/config/config.js +225 -7
- package/dist/config/config.js.map +1 -1
- package/dist/config/repo-config.d.ts +120 -0
- package/dist/config/repo-config.js +447 -0
- package/dist/config/repo-config.js.map +1 -0
- package/dist/connectors/github-webhook.d.ts +17 -0
- package/dist/connectors/github-webhook.js +150 -17
- package/dist/connectors/github-webhook.js.map +1 -1
- package/dist/connectors/types.d.ts +48 -1
- package/dist/cron/dependabot-discovery.d.ts +68 -11
- package/dist/cron/dependabot-discovery.js +78 -20
- package/dist/cron/dependabot-discovery.js.map +1 -1
- package/dist/cron/fanout.d.ts +10 -0
- package/dist/cron/fanout.js +35 -2
- package/dist/cron/fanout.js.map +1 -1
- package/dist/cron/jobs.d.ts +16 -2
- package/dist/cron/jobs.js +69 -9
- package/dist/cron/jobs.js.map +1 -1
- package/dist/cron/repo-crons.d.ts +110 -0
- package/dist/cron/repo-crons.js +169 -0
- package/dist/cron/repo-crons.js.map +1 -0
- package/dist/cron/review-discovery.d.ts +33 -20
- package/dist/cron/review-discovery.js +23 -30
- package/dist/cron/review-discovery.js.map +1 -1
- package/dist/engine/agent-executor.d.ts +1 -1
- package/dist/engine/agent-executor.js +1 -1
- package/dist/engine/agent-executor.js.map +1 -1
- package/dist/engine/dispatcher.d.ts +98 -1
- package/dist/engine/dispatcher.js +248 -231
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/executors/orchestrator.js +39 -15
- package/dist/engine/executors/orchestrator.js.map +1 -1
- package/dist/engine/executors/shared.d.ts +43 -0
- package/dist/engine/executors/shared.js +65 -0
- package/dist/engine/executors/shared.js.map +1 -1
- package/dist/engine/fix-harvest.d.ts +169 -0
- package/dist/engine/fix-harvest.js +345 -0
- package/dist/engine/fix-harvest.js.map +1 -0
- package/dist/engine/fix-markers.d.ts +184 -0
- package/dist/engine/fix-markers.js +329 -0
- package/dist/engine/fix-markers.js.map +1 -0
- package/dist/engine/fix-scratch.d.ts +76 -0
- package/dist/engine/fix-scratch.js +77 -0
- package/dist/engine/fix-scratch.js.map +1 -0
- package/dist/engine/github/github.d.ts +302 -5
- package/dist/engine/github/github.js +614 -54
- package/dist/engine/github/github.js.map +1 -1
- package/dist/engine/github/profiles.d.ts +45 -1
- package/dist/engine/github/profiles.js +35 -0
- package/dist/engine/github/profiles.js.map +1 -1
- package/dist/engine/pr-decisions.d.ts +342 -0
- package/dist/engine/pr-decisions.js +721 -0
- package/dist/engine/pr-decisions.js.map +1 -0
- package/dist/engine/pr-escalation.d.ts +152 -0
- package/dist/engine/pr-escalation.js +320 -0
- package/dist/engine/pr-escalation.js.map +1 -0
- package/dist/engine/pr-notes.d.ts +175 -0
- package/dist/engine/pr-notes.js +315 -0
- package/dist/engine/pr-notes.js.map +1 -0
- package/dist/engine/pr-state.d.ts +313 -0
- package/dist/engine/pr-state.js +515 -0
- package/dist/engine/pr-state.js.map +1 -0
- package/dist/engine/review-check.d.ts +200 -0
- package/dist/engine/review-check.js +305 -0
- package/dist/engine/review-check.js.map +1 -0
- package/dist/engine/router.d.ts +27 -0
- package/dist/engine/router.js +156 -22
- package/dist/engine/router.js.map +1 -1
- package/dist/evals-api.d.ts +10 -0
- package/dist/evals-api.js +38 -0
- package/dist/evals-api.js.map +1 -1
- package/dist/index.js +313 -23
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +13 -0
- package/dist/sandbox/index.js +30 -0
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/k8s/init-clone.d.ts +5 -0
- package/dist/sandbox/k8s/init-clone.js +27 -0
- package/dist/sandbox/k8s/init-clone.js.map +1 -1
- package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +26 -1
- package/dist/sandbox/k8s/kubernetes-sandbox.js +30 -1
- package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
- package/dist/state/execution-store.d.ts +27 -0
- package/dist/state/execution-store.js +45 -0
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +73 -0
- package/dist/state/workflow-run-store.js +106 -24
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/workflows/pr-scope.d.ts +63 -0
- package/dist/workflows/pr-scope.js +113 -0
- package/dist/workflows/pr-scope.js.map +1 -0
- package/dist/workflows/resume.js +113 -8
- package/dist/workflows/resume.js.map +1 -1
- package/dist/workflows/runner.d.ts +2 -1
- package/dist/workflows/runner.js +143 -10
- package/dist/workflows/runner.js.map +1 -1
- package/dist/workflows/simple.d.ts +280 -1
- package/dist/workflows/simple.js +499 -8
- package/dist/workflows/simple.js.map +1 -1
- package/dist/workflows/target-policy.d.ts +0 -12
- package/dist/workflows/target-policy.js +9 -15
- package/dist/workflows/target-policy.js.map +1 -1
- package/package.json +4 -4
- package/skills/README.md +11 -5
- package/skills/dependency-impact/SKILL.md +83 -0
- package/skills/fixing/SKILL.md +190 -0
- package/skills/pr-review/SKILL.md +26 -9
- package/workflows/cron-dependabot-ci-fix.yaml +8 -5
- package/workflows/cron-review.yaml +14 -5
- package/workflows/dependabot-ci-fix.yaml +86 -2
- package/workflows/dependabot-pr-merge.yaml +13 -1
- package/workflows/pr-fix.yaml +84 -1
- package/workflows/pr-review.yaml +7 -0
- package/workflows/prompts/dependabot-ci-fix.md +70 -17
- package/workflows/prompts/dependabot-pr-merge.md +203 -80
- package/workflows/prompts/diagnose-ci.md +96 -0
- package/workflows/prompts/pr-fix.md +63 -4
|
@@ -36,12 +36,15 @@
|
|
|
36
36
|
* `unknown` and kicks off the recompute; both sweeps re-poll it with a
|
|
37
37
|
* widening backoff (`resolveMergeableState`, issue #204) before giving up.
|
|
38
38
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
39
|
+
* **These are candidate finders, not policy** (09-state-machine.md → S1/S2).
|
|
40
|
+
* They answer "does this PR look like it needs this workflow?" — a fact about
|
|
41
|
+
* the pull request. Whether we may ACT on it (the `requires-human` escalation
|
|
42
|
+
* guard, the attempt counter, the cost cap, the per-SHA dedup, the fork guard)
|
|
43
|
+
* is decided once by `resolvePrState` + `resolveDispatchDisposition` at the
|
|
44
|
+
* `dispatchWorkflow` choke point, which the webhook route crosses too. The
|
|
45
|
+
* `requires-human` filter used to live here AND in the dispatcher, and the two
|
|
46
|
+
* disagreed by construction: the label was a one-way door on the cron side
|
|
47
|
+
* while the webhook cleared it on success. Now there is one answer.
|
|
45
48
|
*/
|
|
46
49
|
/**
|
|
47
50
|
* Last Light dependency-PR lifecycle labels. THE single source of truth for
|
|
@@ -54,6 +57,31 @@
|
|
|
54
57
|
export const DEP_TRIVIAL_LABEL = "dependency-trivial";
|
|
55
58
|
export const DEP_FUNCTIONAL_LABEL = "dependency-functional";
|
|
56
59
|
export const REQUIRES_HUMAN_LABEL = "requires-human";
|
|
60
|
+
/**
|
|
61
|
+
* MAJOR-bump impact tiers (issue #252, 05-impact.md §5.4). Additive: the two
|
|
62
|
+
* labels above keep their meaning, because both are load-bearing for discovery
|
|
63
|
+
* — `dependency-functional` + `requires-human` still means "high impact, a
|
|
64
|
+
* human decides", so nothing about the escalated case changed.
|
|
65
|
+
*
|
|
66
|
+
* These say what the trivial/functional pair cannot: WHY a major was safe to
|
|
67
|
+
* land, or why it was not. Exactly one is ever applied at a time; the merge
|
|
68
|
+
* prompt clears the other two in the same idempotent pass.
|
|
69
|
+
*
|
|
70
|
+
* The hex colours are part of the contract — `github_ensure_labels` creates a
|
|
71
|
+
* missing label with them, so a rename here without the same edit in
|
|
72
|
+
* `workflows/prompts/dependabot-pr-merge.md` produces two label vocabularies on
|
|
73
|
+
* the same repo. `tests/cron/label-vocab.test.ts` pins names and colours
|
|
74
|
+
* against that prompt.
|
|
75
|
+
*/
|
|
76
|
+
/** Green, matching `dependency-trivial` — a major that reads as trivial. */
|
|
77
|
+
export const DEP_MAJOR_LOW_LABEL = "dependency-major-low";
|
|
78
|
+
export const DEP_MAJOR_LOW_COLOR = "0e8a16";
|
|
79
|
+
/** Amber, matching `dependency-functional` — landed, but worth a glance. */
|
|
80
|
+
export const DEP_MAJOR_MEDIUM_LABEL = "dependency-major-medium";
|
|
81
|
+
export const DEP_MAJOR_MEDIUM_COLOR = "fbca04";
|
|
82
|
+
/** Red, matching `requires-human` — never auto-merged. */
|
|
83
|
+
export const DEP_MAJOR_HIGH_LABEL = "dependency-major-high";
|
|
84
|
+
export const DEP_MAJOR_HIGH_COLOR = "b60205";
|
|
57
85
|
/** Bot logins that open dependency-update PRs. */
|
|
58
86
|
const DEPENDENCY_BOT_LOGINS = new Set(["dependabot[bot]", "renovate[bot]"]);
|
|
59
87
|
/** Titles a dependency bot uses, for the rare case its login is proxied/squashed. */
|
|
@@ -88,11 +116,15 @@ const realSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
88
116
|
*/
|
|
89
117
|
const MERGE_BLOCKED_STATES = new Set(["behind", "dirty", "blocked"]);
|
|
90
118
|
/**
|
|
91
|
-
* List
|
|
92
|
-
*
|
|
93
|
-
* `
|
|
94
|
-
*
|
|
95
|
-
*
|
|
119
|
+
* List one repo's open dependency-PR candidates: is-dependency, non-draft,
|
|
120
|
+
* oldest-first, capped at `maxPerRepo`. Per-repo listing failures are logged
|
|
121
|
+
* and yield `[]`, never fatal, so one inaccessible repo doesn't sink the sweep.
|
|
122
|
+
* Shared by both the green and red sweeps.
|
|
123
|
+
*
|
|
124
|
+
* No `requires-human` filter: that is a POLICY question, and it is now answered
|
|
125
|
+
* once at dispatch off the snapshot's `escalatedBy` / `escalatedAtSha` — which
|
|
126
|
+
* is what lets a maintainer's push re-arm a PR we escalated, instead of the
|
|
127
|
+
* label being a permanent one-way door with no code path that removes it.
|
|
96
128
|
*/
|
|
97
129
|
async function listDependencyCandidates(full, gh, maxPerRepo, log) {
|
|
98
130
|
const [owner, repo] = full.split("/");
|
|
@@ -110,8 +142,6 @@ async function listDependencyCandidates(full, gh, maxPerRepo, log) {
|
|
|
110
142
|
}
|
|
111
143
|
return open
|
|
112
144
|
.filter(isDependencyPr)
|
|
113
|
-
// Don't re-attempt what we already flagged as needing a human.
|
|
114
|
-
.filter((p) => !p.labels.includes(REQUIRES_HUMAN_LABEL))
|
|
115
145
|
.sort((a, b) => a.number - b.number) // oldest first (the sweep's fairness order)
|
|
116
146
|
.slice(0, maxPerRepo)
|
|
117
147
|
.map((p) => ({
|
|
@@ -156,8 +186,10 @@ async function resolveMergeableState(gh, owner, repo, pullNumber, opts) {
|
|
|
156
186
|
}
|
|
157
187
|
/**
|
|
158
188
|
* Find every green (`mergeable_state: "clean"`) dependency PR across `repos`
|
|
159
|
-
* (`owner/repo` full names)
|
|
160
|
-
*
|
|
189
|
+
* (`owner/repo` full names). No `requires-human` filter — that is a POLICY
|
|
190
|
+
* question, answered once at the dispatch gate off the PR-state snapshot (see
|
|
191
|
+
* the module header), which is what lets a maintainer's push re-arm a PR we
|
|
192
|
+
* gave up on. A cold `unknown` read is re-polled (`resolveMergeableState`) before giving up,
|
|
161
193
|
* so a genuinely-mergeable-but-uncomputed PR isn't stranded for want of a second
|
|
162
194
|
* read (issue #204). Per-repo failures are logged and skipped, never fatal.
|
|
163
195
|
*/
|
|
@@ -177,17 +209,41 @@ export async function discoverGreenDependencyPrs(repos, gh, opts = {}) {
|
|
|
177
209
|
// Only genuinely-green PRs. `unstable`/`blocked`/`behind`/`dirty` (and a PR
|
|
178
210
|
// still `unknown` after the re-poll) are left for the real-time webhook or
|
|
179
211
|
// the next tick once they go clean.
|
|
180
|
-
if (state
|
|
181
|
-
|
|
212
|
+
if (state !== "clean")
|
|
213
|
+
continue;
|
|
214
|
+
// `clean` is GitHub's mergeability verdict, not a CI verdict — on a repo
|
|
215
|
+
// with no *required* checks a red PR is still "clean". Ask the checks
|
|
216
|
+
// directly so the cron's green means the same thing the webhook's does.
|
|
217
|
+
if (opts.requireSettledChecks) {
|
|
218
|
+
let conclusion;
|
|
219
|
+
try {
|
|
220
|
+
conclusion = await gh.getChecksConclusion(c.owner, c.repo, c.headSha || c.headRef, {
|
|
221
|
+
excludeApp: opts.botName,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
// Fail CLOSED here, uniquely: every other read in this module fails
|
|
226
|
+
// open because a dropped candidate costs one tick, whereas a
|
|
227
|
+
// wrongly-green candidate costs a merged red PR.
|
|
228
|
+
opts.log?.(`[dependabot-discovery] ${c.full}#${c.number}: checks read failed — ${String(err)}`);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (conclusion !== "passing") {
|
|
232
|
+
opts.log?.(`[dependabot-discovery] ${c.full}#${c.number}: mergeable_state=clean but checks are ${conclusion} — not green`);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
182
235
|
}
|
|
236
|
+
out.push({ repo: c.full, prNumber: c.number, title: c.title });
|
|
183
237
|
}
|
|
184
238
|
}
|
|
185
239
|
return out;
|
|
186
240
|
}
|
|
187
241
|
/**
|
|
188
242
|
* Find every RED dependency PR across `repos` (`owner/repo` full names) that
|
|
189
|
-
* `dependabot-ci-fix` can act on
|
|
190
|
-
*
|
|
243
|
+
* `dependabot-ci-fix` can act on. No `requires-human` filter — see
|
|
244
|
+
* `discoverGreenDependencyPrs` and the module header: whether we may act on an
|
|
245
|
+
* escalated PR is decided at the dispatch gate, not here.
|
|
246
|
+
* A PR qualifies when its checks are settled-FAILING, OR its
|
|
191
247
|
* `mergeable_state` is `behind` / `dirty` / `blocked` (a merge it can't make on
|
|
192
248
|
* its own but ci-fix can push toward — see `MERGE_BLOCKED_STATES`). Failing CI
|
|
193
249
|
* takes precedence in the reported `reason` (there's a concrete build to fix).
|
|
@@ -205,7 +261,9 @@ export async function discoverRedDependencyPrs(repos, gh, opts = {}) {
|
|
|
205
261
|
try {
|
|
206
262
|
// Query the exact commit we listed (headSha) so a mid-sweep push can't
|
|
207
263
|
// make us read a newer commit's checks; fall back to the ref if absent.
|
|
208
|
-
conclusion = await gh.getChecksConclusion(c.owner, c.repo, c.headSha || c.headRef
|
|
264
|
+
conclusion = await gh.getChecksConclusion(c.owner, c.repo, c.headSha || c.headRef, {
|
|
265
|
+
excludeApp: opts.botName,
|
|
266
|
+
});
|
|
209
267
|
// A settled-failing build is reason enough (and makes the mergeable
|
|
210
268
|
// signal moot), so skip the potentially-slow `unknown` re-poll for it;
|
|
211
269
|
// otherwise warm the read so a cold `unknown` that's really behind/dirty/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependabot-discovery.js","sourceRoot":"","sources":["../../src/cron/dependabot-discovery.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dependabot-discovery.js","sourceRoot":"","sources":["../../src/cron/dependabot-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AACtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAC5D,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AACH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,QAAQ,CAAC;AAC5C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAC;AAChE,MAAM,CAAC,MAAM,sBAAsB,GAAG,QAAQ,CAAC;AAC/C,0DAA0D;AAC1D,MAAM,CAAC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E,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC5F,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/cron/fanout.d.ts
CHANGED
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
* dispatch-side concurrency knob — a batcher on top of the run queue only
|
|
16
16
|
* serialized the fan-out, blocking each slice on completion while the queue
|
|
17
17
|
* sat under-used.
|
|
18
|
+
*
|
|
19
|
+
* WHICH repos the fan-out covers is resolved here, per tick, not when the job
|
|
20
|
+
* was registered: a managed repo may opt out of (or into) a cron in its
|
|
21
|
+
* `.lastlight/lastlight.yml` and that must take effect without re-registering
|
|
22
|
+
* croner jobs. See `repo-crons.ts` for that resolution and its cost model.
|
|
18
23
|
*/
|
|
19
24
|
export type CronDispatcher = (workflow: string, context: Record<string, unknown>) => Promise<{
|
|
20
25
|
success: boolean;
|
|
@@ -31,6 +36,11 @@ export interface FanOutResult {
|
|
|
31
36
|
* Dispatch a cron-scheduled workflow, fanning out over `context.repos` when
|
|
32
37
|
* present. When absent, behaves like a single dispatch. Always stamps
|
|
33
38
|
* `_triggerType: "cron"` on the outgoing context.
|
|
39
|
+
*
|
|
40
|
+
* When the context carries the cron's name (every scheduled tick does — see
|
|
41
|
+
* `jobs.ts`), the repo list is narrowed by each repo's own `crons:` block
|
|
42
|
+
* first. Without it — a manual "Run now", or any caller that builds its own
|
|
43
|
+
* context — the list is used verbatim, exactly as before.
|
|
34
44
|
*/
|
|
35
45
|
export declare function dispatchCronWorkflow(workflowName: string, context: Record<string, unknown>, dispatch: CronDispatcher): Promise<FanOutResult>;
|
|
36
46
|
/**
|
package/dist/cron/fanout.js
CHANGED
|
@@ -15,11 +15,22 @@
|
|
|
15
15
|
* dispatch-side concurrency knob — a batcher on top of the run queue only
|
|
16
16
|
* serialized the fan-out, blocking each slice on completion while the queue
|
|
17
17
|
* sat under-used.
|
|
18
|
+
*
|
|
19
|
+
* WHICH repos the fan-out covers is resolved here, per tick, not when the job
|
|
20
|
+
* was registered: a managed repo may opt out of (or into) a cron in its
|
|
21
|
+
* `.lastlight/lastlight.yml` and that must take effect without re-registering
|
|
22
|
+
* croner jobs. See `repo-crons.ts` for that resolution and its cost model.
|
|
18
23
|
*/
|
|
24
|
+
import { CRON_GLOBALLY_ENABLED_KEY, CRON_NAME_KEY, resolveCronRepos } from "./repo-crons.js";
|
|
19
25
|
/**
|
|
20
26
|
* Dispatch a cron-scheduled workflow, fanning out over `context.repos` when
|
|
21
27
|
* present. When absent, behaves like a single dispatch. Always stamps
|
|
22
28
|
* `_triggerType: "cron"` on the outgoing context.
|
|
29
|
+
*
|
|
30
|
+
* When the context carries the cron's name (every scheduled tick does — see
|
|
31
|
+
* `jobs.ts`), the repo list is narrowed by each repo's own `crons:` block
|
|
32
|
+
* first. Without it — a manual "Run now", or any caller that builds its own
|
|
33
|
+
* context — the list is used verbatim, exactly as before.
|
|
23
34
|
*/
|
|
24
35
|
export async function dispatchCronWorkflow(workflowName, context, dispatch) {
|
|
25
36
|
const base = { ...context, _triggerType: "cron" };
|
|
@@ -28,9 +39,31 @@ export async function dispatchCronWorkflow(workflowName, context, dispatch) {
|
|
|
28
39
|
const result = await runOne(dispatch, workflowName, base);
|
|
29
40
|
return { dispatched: 1, failures: result ? 0 : 1 };
|
|
30
41
|
}
|
|
31
|
-
|
|
42
|
+
// The two cron control keys are consumed here and dropped alongside `repos`,
|
|
43
|
+
// so a dispatched run's context is byte-for-byte what it was before per-repo
|
|
44
|
+
// participation existed.
|
|
45
|
+
const { repos: _drop, [CRON_NAME_KEY]: rawCron, [CRON_GLOBALLY_ENABLED_KEY]: rawEnabled, ...rest } = base;
|
|
32
46
|
const repos = rawRepos.filter((r) => typeof r === "string" && r.length > 0);
|
|
33
|
-
|
|
47
|
+
const cron = typeof rawCron === "string" && rawCron ? rawCron : undefined;
|
|
48
|
+
let targets = repos;
|
|
49
|
+
if (cron) {
|
|
50
|
+
const resolved = await resolveCronRepos({
|
|
51
|
+
cron,
|
|
52
|
+
repos,
|
|
53
|
+
// Absent means "on" — only jobs.ts marks a cron globally off.
|
|
54
|
+
globallyEnabled: rawEnabled !== false,
|
|
55
|
+
});
|
|
56
|
+
targets = resolved.repos;
|
|
57
|
+
if (resolved.optedOut.length || resolved.optedIn.length) {
|
|
58
|
+
console.log(`[cron-fanout] ${cron}: ${targets.length}/${repos.length} repo(s)` +
|
|
59
|
+
(resolved.optedOut.length ? ` — opted out: ${resolved.optedOut.join(", ")}` : "") +
|
|
60
|
+
(resolved.optedIn.length ? ` — opted in: ${resolved.optedIn.join(", ")}` : ""));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// An empty list is a legitimate outcome (a globally-off cron nobody opted
|
|
64
|
+
// into): fanOutContexts no-ops, so the tick costs nothing and reports no
|
|
65
|
+
// failure.
|
|
66
|
+
return fanOutContexts(workflowName, targets.map((repo) => ({ ...rest, repo })), dispatch);
|
|
34
67
|
}
|
|
35
68
|
/**
|
|
36
69
|
* Fan out one dispatch per pre-built context, ALL at once — no throttle. The
|
package/dist/cron/fanout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fanout.js","sourceRoot":"","sources":["../../src/cron/fanout.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"fanout.js","sourceRoot":"","sources":["../../src/cron/fanout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAc7F;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,YAAoB,EACpB,OAAgC,EAChC,QAAwB;IAExB,MAAM,IAAI,GAA4B,EAAE,GAAG,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IAC3E,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,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;AAClD,CAAC;AAED,KAAK,UAAU,MAAM,CACnB,QAAwB,EACxB,YAAoB,EACpB,OAAgC;IAEhC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CACX,iBAAiB,YAAY,uBAAuB,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,WAAW,CAAC,GAAG,EAC1F,GAAG,CACJ,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/cron/jobs.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { CronJob } from "./scheduler.js";
|
|
2
|
+
import type { CronsConfig } from "../config/config.js";
|
|
2
3
|
import type { StateDb } from "../state/db.js";
|
|
4
|
+
/** What a `condition.unless` predicate is evaluated against. */
|
|
5
|
+
export interface CronConditionContext {
|
|
6
|
+
webhooksEnabled: boolean;
|
|
7
|
+
}
|
|
3
8
|
/**
|
|
4
9
|
* Get cron jobs based on configuration.
|
|
5
10
|
*
|
|
@@ -9,10 +14,19 @@ import type { StateDb } from "../state/db.js";
|
|
|
9
14
|
* (WEBHOOK_SECRET is set), jobs with `condition.unless: webhooksEnabled`
|
|
10
15
|
* are filtered out — those are handled in real-time via webhook events.
|
|
11
16
|
*
|
|
12
|
-
* When `db` is supplied, cron_overrides rows applied:
|
|
13
|
-
*
|
|
17
|
+
* When `db` is supplied, cron_overrides rows applied: a schedule override
|
|
18
|
+
* replaces the YAML schedule, and a disabled row turns the cron off globally.
|
|
19
|
+
*
|
|
20
|
+
* "Off globally" is NOT "unregistered" (issue #180). A globally-off cron still
|
|
21
|
+
* gets a tick, marked `_cronGloballyEnabled: false`, because a managed repo may
|
|
22
|
+
* opt itself back in via its `.lastlight/lastlight.yml`. Resolving that at TICK
|
|
23
|
+
* time (see `fanout.ts` → `resolveCronRepos`) is what lets a repo's edit take
|
|
24
|
+
* effect without dynamically re-registering croner jobs; a tick whose repo list
|
|
25
|
+
* comes back empty is a cheap no-op — no dispatch, no run, no error.
|
|
14
26
|
*/
|
|
15
27
|
export declare function getJobs(opts?: {
|
|
16
28
|
webhooksEnabled?: boolean;
|
|
17
29
|
db?: StateDb;
|
|
30
|
+
/** Operator cron block. Defaults to runtime config — injectable for tests. */
|
|
31
|
+
crons?: CronsConfig;
|
|
18
32
|
}): CronJob[];
|
package/dist/cron/jobs.js
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
import { getAccessibleManagedRepos } from "../managed-repos.js";
|
|
2
2
|
import { getCronWorkflows } from "../workflows/loader.js";
|
|
3
|
+
import { CRON_GLOBALLY_ENABLED_KEY, CRON_NAME_KEY, operatorCrons } from "./repo-crons.js";
|
|
4
|
+
/**
|
|
5
|
+
* `condition.unless: <name>` → the predicate that name means.
|
|
6
|
+
*
|
|
7
|
+
* `jobs.ts` used to compare the field against the literal string
|
|
8
|
+
* `"webhooksEnabled"`, so a cron YAML could express exactly one condition and
|
|
9
|
+
* any other value was silently ignored — a typo turned a conditional cron into
|
|
10
|
+
* an unconditional one with no error. 07-review-triggers.md §7.4b asked for this
|
|
11
|
+
* generalisation and Phase 8 briefly made it moot by deleting the only consumer;
|
|
12
|
+
* 09-state-machine.md → S5 keeps the crons, so it is live again.
|
|
13
|
+
*
|
|
14
|
+
* **An unknown name keeps the cron.** Registration is the safe direction: a
|
|
15
|
+
* globally-off cron still ticks (a repo may opt back in), whereas a silently
|
|
16
|
+
* dropped one produces no ticks, no rows and no error — the exact failure the
|
|
17
|
+
* literal comparison already had.
|
|
18
|
+
*/
|
|
19
|
+
const CRON_CONDITION_PREDICATES = {
|
|
20
|
+
webhooksEnabled: (ctx) => ctx.webhooksEnabled,
|
|
21
|
+
};
|
|
22
|
+
/** Names already warned about, so a bad `condition.unless` logs once per boot. */
|
|
23
|
+
const warnedConditions = new Set();
|
|
24
|
+
/** Should this cron be REGISTERED, given its `condition.unless`? */
|
|
25
|
+
function conditionAllows(unless, ctx) {
|
|
26
|
+
if (!unless)
|
|
27
|
+
return true;
|
|
28
|
+
const predicate = CRON_CONDITION_PREDICATES[unless];
|
|
29
|
+
if (!predicate) {
|
|
30
|
+
if (!warnedConditions.has(unless)) {
|
|
31
|
+
warnedConditions.add(unless);
|
|
32
|
+
console.warn(`[cron] unknown condition.unless "${unless}" — registering the cron anyway ` +
|
|
33
|
+
`(known: ${Object.keys(CRON_CONDITION_PREDICATES).join(", ")})`);
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return !predicate(ctx);
|
|
38
|
+
}
|
|
3
39
|
/**
|
|
4
40
|
* Get cron jobs based on configuration.
|
|
5
41
|
*
|
|
@@ -9,21 +45,33 @@ import { getCronWorkflows } from "../workflows/loader.js";
|
|
|
9
45
|
* (WEBHOOK_SECRET is set), jobs with `condition.unless: webhooksEnabled`
|
|
10
46
|
* are filtered out — those are handled in real-time via webhook events.
|
|
11
47
|
*
|
|
12
|
-
* When `db` is supplied, cron_overrides rows applied:
|
|
13
|
-
*
|
|
48
|
+
* When `db` is supplied, cron_overrides rows applied: a schedule override
|
|
49
|
+
* replaces the YAML schedule, and a disabled row turns the cron off globally.
|
|
50
|
+
*
|
|
51
|
+
* "Off globally" is NOT "unregistered" (issue #180). A globally-off cron still
|
|
52
|
+
* gets a tick, marked `_cronGloballyEnabled: false`, because a managed repo may
|
|
53
|
+
* opt itself back in via its `.lastlight/lastlight.yml`. Resolving that at TICK
|
|
54
|
+
* time (see `fanout.ts` → `resolveCronRepos`) is what lets a repo's edit take
|
|
55
|
+
* effect without dynamically re-registering croner jobs; a tick whose repo list
|
|
56
|
+
* comes back empty is a cheap no-op — no dispatch, no run, no error.
|
|
14
57
|
*/
|
|
15
58
|
export function getJobs(opts) {
|
|
16
59
|
const jobs = [];
|
|
17
60
|
let cronDefs = getCronWorkflows();
|
|
18
|
-
// Apply conditions
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
61
|
+
// Apply conditions through the predicate map, not a literal string compare.
|
|
62
|
+
const conditionCtx = { webhooksEnabled: !!opts?.webhooksEnabled };
|
|
63
|
+
cronDefs = cronDefs.filter((def) => conditionAllows(def.condition?.unless, conditionCtx));
|
|
22
64
|
const overrides = opts?.db?.getAllCronOverrides() ?? new Map();
|
|
65
|
+
// Already includes the legacy `disabled.crons` names (unioned by the config
|
|
66
|
+
// normaliser). Those are additionally dropped by the asset loader before we
|
|
67
|
+
// ever see them here, so this is belt-and-braces for anything that reaches us.
|
|
68
|
+
const crons = opts?.crons ?? operatorCrons();
|
|
23
69
|
for (const def of cronDefs) {
|
|
24
70
|
const override = overrides.get(def.name);
|
|
25
|
-
|
|
26
|
-
|
|
71
|
+
// The dashboard toggle and the operator's `crons.disable` are the same
|
|
72
|
+
// lever spelled two ways — both mean "off by default", both leave the tick
|
|
73
|
+
// registered so a repo opt-in can still be honoured.
|
|
74
|
+
const globallyEnabled = (override ? override.enabled : true) && !crons.disable.includes(def.name);
|
|
27
75
|
jobs.push({
|
|
28
76
|
name: def.name,
|
|
29
77
|
schedule: override?.schedule || def.schedule,
|
|
@@ -32,7 +80,19 @@ export function getJobs(opts) {
|
|
|
32
80
|
// installation-filtered list so a stale managedRepos entry (repo deleted /
|
|
33
81
|
// transferred / access revoked) doesn't fan out into a doomed scan run
|
|
34
82
|
// whose scoped-token mint 422s.
|
|
35
|
-
context: {
|
|
83
|
+
context: {
|
|
84
|
+
repos: getAccessibleManagedRepos(),
|
|
85
|
+
// Spread ahead of the control keys, deliberately: a cron YAML MAY pin
|
|
86
|
+
// its own `context.repos` and override the managed-repo list.
|
|
87
|
+
...def.context,
|
|
88
|
+
// Control keys for the fan-out; stripped there, never reaching a run.
|
|
89
|
+
// Injected LAST so operator YAML can't spoof them — a `_cronName` from
|
|
90
|
+
// `context:` would make `resolveCronRepos` apply another cron's per-repo
|
|
91
|
+
// opt-in/opt-out rules to this tick, and a `_cronGloballyEnabled` would
|
|
92
|
+
// let a disabled cron fan out as enabled.
|
|
93
|
+
[CRON_NAME_KEY]: def.name,
|
|
94
|
+
[CRON_GLOBALLY_ENABLED_KEY]: globallyEnabled,
|
|
95
|
+
},
|
|
36
96
|
});
|
|
37
97
|
}
|
|
38
98
|
return jobs;
|
package/dist/cron/jobs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../src/cron/jobs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../src/cron/jobs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAS1F;;;;;;;;;;;;;;GAcG;AACH,MAAM,yBAAyB,GAA2D;IACxF,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,eAAe;CAC9C,CAAC;AAEF,kFAAkF;AAClF,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE3C,oEAAoE;AACpE,SAAS,eAAe,CAAC,MAA0B,EAAE,GAAyB;IAC5E,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,SAAS,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,IA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CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClG,IAAI,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,QAAQ,EAAE,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,QAAQ;YAC5C,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,sEAAsE;YACtE,2EAA2E;YAC3E,uEAAuE;YACvE,gCAAgC;YAChC,OAAO,EAAE;gBACP,KAAK,EAAE,yBAAyB,EAAE;gBAClC,sEAAsE;gBACtE,8DAA8D;gBAC9D,GAAG,GAAG,CAAC,OAAO;gBACd,sEAAsE;gBACtE,uEAAuE;gBACvE,yEAAyE;gBACzE,wEAAwE;gBACxE,0CAA0C;gBAC1C,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,IAAI;gBACzB,CAAC,yBAAyB,CAAC,EAAE,eAAe;aAC7C;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-repository cron participation (issue #180).
|
|
3
|
+
*
|
|
4
|
+
* A cron is scheduled ONCE globally but fans out into one run per managed repo
|
|
5
|
+
* (`src/cron/fanout.ts`). This module decides, at tick time, WHICH repos that
|
|
6
|
+
* fan-out covers — reading the `crons:` block each repo may commit to its
|
|
7
|
+
* `.lastlight/lastlight.yml`:
|
|
8
|
+
*
|
|
9
|
+
* crons:
|
|
10
|
+
* enable: [security-scan] # run this cron against me even when it's off globally
|
|
11
|
+
* disable: [repo-health] # skip me on this cron
|
|
12
|
+
*
|
|
13
|
+
* ── Why at tick time ──────────────────────────────────────────────────────
|
|
14
|
+
* The alternative — resolving participation when jobs are registered — would
|
|
15
|
+
* mean a repo editing its `lastlight.yml` needs the croner jobs re-registered
|
|
16
|
+
* to take effect (a config-change watcher, or a restart). Resolving here
|
|
17
|
+
* instead makes a repo's edit take effect on the next tick with no scheduler
|
|
18
|
+
* churn, at the cost of a cheap no-op tick when nothing resolves.
|
|
19
|
+
*
|
|
20
|
+
* ── Cost ──────────────────────────────────────────────────────────────────
|
|
21
|
+
* A fan-out over N repos must not become N blocking network calls. The cached
|
|
22
|
+
* layer is used when one is in memory; only cache misses go through
|
|
23
|
+
* {@link fetchRepoLayer}, concurrently, and that call is itself TTL'd +
|
|
24
|
+
* conditional (see `src/config/repo-config.ts`). One repo's failure never
|
|
25
|
+
* aborts the tick: an unreadable config falls back to the repo's inherited
|
|
26
|
+
* (global) behaviour.
|
|
27
|
+
*
|
|
28
|
+
* ── Bounds ────────────────────────────────────────────────────────────────
|
|
29
|
+
* The repo layer only gets a vote when the operator's `repoConfig.allowKeys`
|
|
30
|
+
* admits `crons` (or the legacy `disabled.crons`). Removing it is the operator's
|
|
31
|
+
* kill switch: `crons.disable` in the operator's config then cannot be
|
|
32
|
+
* overridden by any repo, and this module short-circuits with zero fetches.
|
|
33
|
+
*/
|
|
34
|
+
import { type CronsConfig, type RepoConfigPolicy } from "../config/config.js";
|
|
35
|
+
import { type RepoLayer } from "../config/repo-config.js";
|
|
36
|
+
/**
|
|
37
|
+
* Context keys the cron tick carries from {@link import("./jobs.js").getJobs}
|
|
38
|
+
* to the fan-out. Underscore-prefixed like `_triggerType`, and stripped by the
|
|
39
|
+
* fan-out before dispatch so a workflow run's context looks exactly as it did
|
|
40
|
+
* before this feature existed.
|
|
41
|
+
*
|
|
42
|
+
* They travel in the context because that's the only channel the scheduler
|
|
43
|
+
* gives a job (`runner(job.workflow, job.context)`) — the cron's own NAME isn't
|
|
44
|
+
* otherwise recoverable from the workflow name (several crons may share one
|
|
45
|
+
* workflow).
|
|
46
|
+
*/
|
|
47
|
+
export declare const CRON_NAME_KEY = "_cronName";
|
|
48
|
+
export declare const CRON_GLOBALLY_ENABLED_KEY = "_cronGloballyEnabled";
|
|
49
|
+
/** How a repo's resolved fan-out list was reached — used by the tick's log line. */
|
|
50
|
+
export interface CronRepoResolution {
|
|
51
|
+
repos: string[];
|
|
52
|
+
/** Repos dropped because they disabled this cron. */
|
|
53
|
+
optedOut: string[];
|
|
54
|
+
/** Repos kept only because they opted in to a globally-off cron. */
|
|
55
|
+
optedIn: string[];
|
|
56
|
+
}
|
|
57
|
+
export interface ResolveCronReposOptions {
|
|
58
|
+
/** The cron's name, as declared in its `cron-*.yaml` — the key repos list. */
|
|
59
|
+
cron: string;
|
|
60
|
+
/** The candidate repos (the cron context's `repos[]`). */
|
|
61
|
+
repos: readonly string[];
|
|
62
|
+
/** False when the operator has this cron off — repos may still opt in. */
|
|
63
|
+
globallyEnabled: boolean;
|
|
64
|
+
/** Operator bounds. Defaults to the runtime {@link repoConfigPolicy}. */
|
|
65
|
+
policy?: RepoConfigPolicy;
|
|
66
|
+
/**
|
|
67
|
+
* Layer lookup seam. Defaults to "cached if present, else fetch" — tests
|
|
68
|
+
* inject a map instead of touching the network.
|
|
69
|
+
*/
|
|
70
|
+
layerFor?: (repo: string) => RepoLayer | undefined | Promise<RepoLayer | undefined>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The repos a cron tick should actually fan out over.
|
|
74
|
+
*
|
|
75
|
+
* Never throws: every per-repo failure degrades to that repo's inherited
|
|
76
|
+
* behaviour. An empty result is a legitimate answer (a globally-off cron no
|
|
77
|
+
* repo opted into) and the caller treats it as a no-op tick.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveCronRepos(options: ResolveCronReposOptions): Promise<CronRepoResolution>;
|
|
80
|
+
/** A repo's vote on one cron. `undefined` = no opinion, inherit the global setting. */
|
|
81
|
+
export type CronVote = "enable" | "disable" | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Apply one layer's {@link CronsConfig} to one cron name. DISABLE WINS: a name
|
|
84
|
+
* in both lists doesn't run. Fail safe — a repo that contradicts itself gets
|
|
85
|
+
* the outcome that can't surprise anybody.
|
|
86
|
+
*/
|
|
87
|
+
export declare function cronVote(cron: string, prefs: CronsConfig): CronVote;
|
|
88
|
+
/**
|
|
89
|
+
* Read the `crons:` block (plus the legacy `disabled.crons` alias) out of a
|
|
90
|
+
* repo's RAW, unvalidated `lastlight.yml`, keeping only what the operator's
|
|
91
|
+
* `allowKeys` admits.
|
|
92
|
+
*
|
|
93
|
+
* Bounded here rather than by `resolveRepoConfig`'s sanitizer because cron
|
|
94
|
+
* participation isn't part of the merged per-run config shape — it's consumed
|
|
95
|
+
* by the scheduler, before any run exists. Same house rules as that sanitizer:
|
|
96
|
+
* pure, lenient, drop what doesn't fit and carry on.
|
|
97
|
+
*/
|
|
98
|
+
export declare function repoCronPrefs(raw: unknown, policy: RepoConfigPolicy): CronsConfig;
|
|
99
|
+
/**
|
|
100
|
+
* Whether any repo could influence cron participation at all. `false` short-
|
|
101
|
+
* circuits the whole resolution — no cache reads, no fetches, operator's word
|
|
102
|
+
* final. This is the documented kill switch: drop `crons` from
|
|
103
|
+
* `repoConfig.allowKeys`.
|
|
104
|
+
*/
|
|
105
|
+
export declare function repoLayerMayVote(policy: RepoConfigPolicy): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* The operator's cron block from runtime config, or an inert one when config
|
|
108
|
+
* isn't loaded (unit tests, pre-boot paths). Mirrors `repoConfigPolicy()`.
|
|
109
|
+
*/
|
|
110
|
+
export declare function operatorCrons(): CronsConfig;
|