lastlight-core 0.21.13 → 0.22.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 +50 -0
- 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 +79 -0
- package/dist/config/config.js +73 -4
- package/dist/config/config.js.map +1 -1
- package/dist/config/repo-config.d.ts +113 -0
- package/dist/config/repo-config.js +432 -0
- package/dist/config/repo-config.js.map +1 -0
- 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 +12 -2
- package/dist/cron/jobs.js +31 -5
- 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/engine/agent-executor.js +64 -28
- package/dist/engine/agent-executor.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 +9 -2
- package/dist/engine/executors/shared.js +35 -14
- package/dist/engine/executors/shared.js.map +1 -1
- package/dist/engine/github/github.d.ts +90 -0
- package/dist/engine/github/github.js +133 -0
- 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/evals-api.d.ts +3 -0
- package/dist/evals-api.js +8 -0
- package/dist/evals-api.js.map +1 -1
- package/dist/index.js +45 -3
- package/dist/index.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/sandbox/sandbox.js +51 -35
- package/dist/sandbox/sandbox.js.map +1 -1
- package/dist/workflows/handlers/post-review.d.ts +12 -8
- package/dist/workflows/handlers/post-review.js +34 -15
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/resume.js +96 -4
- 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 +187 -1
- package/dist/workflows/simple.js +295 -7
- package/dist/workflows/simple.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-repository configuration — the `repo` config layer (issue #180).
|
|
3
|
+
*
|
|
4
|
+
* A managed repo may commit a `.lastlight/` directory that overrides a BOUNDED
|
|
5
|
+
* subset of Last Light's config for runs against that repo. The directory
|
|
6
|
+
* mirrors a deployment overlay's on-disk shape exactly:
|
|
7
|
+
*
|
|
8
|
+
* .lastlight/
|
|
9
|
+
* lastlight.yml # the config override
|
|
10
|
+
* workflows/prompts/*.md # prompt overrides
|
|
11
|
+
* skills/<name>/SKILL.md # skill overrides
|
|
12
|
+
* agent-context/*.md # persona/rules additions
|
|
13
|
+
*
|
|
14
|
+
* so the unpacked cache directory can be handed to the same layer-aware asset
|
|
15
|
+
* loader the instance overlay uses, with no second code path.
|
|
16
|
+
*
|
|
17
|
+
* ── The trust rule ────────────────────────────────────────────────────────
|
|
18
|
+
* The layer is ALWAYS read from the repo's **default branch**, resolved live
|
|
19
|
+
* from the repo metadata. Never a PR head. Never the sandbox checkout. This is
|
|
20
|
+
* the entire security model: without it, a pull request could commit a
|
|
21
|
+
* `.lastlight/lastlight.yml` that re-points the model, disables the review
|
|
22
|
+
* workflow and drops the approval gates of the very agent reviewing it. The
|
|
23
|
+
* default branch is the one ref that has already passed the repo's own review
|
|
24
|
+
* and branch-protection rules.
|
|
25
|
+
*
|
|
26
|
+
* ── The failure rule ──────────────────────────────────────────────────────
|
|
27
|
+
* Warn, drop the bad bits, run anyway. A repo's config file must never fail a
|
|
28
|
+
* run. Invalid YAML drops the whole file; an unknown or out-of-bounds key drops
|
|
29
|
+
* just that key; a fetch error falls back to the last good cached copy (or to
|
|
30
|
+
* no layer at all). Every rejection becomes a structured `RepoConfigWarning`
|
|
31
|
+
* so the dashboard/CLI can report it back to the repo's owners.
|
|
32
|
+
*
|
|
33
|
+
* ── Layout ────────────────────────────────────────────────────────────────
|
|
34
|
+
* This module owns the IMPURE half: the GitHub round-trip, the on-disk unpack
|
|
35
|
+
* and the TTL cache. The pure half — the schema, the operator bounds, and every
|
|
36
|
+
* validator/merger that enforces them — lives in
|
|
37
|
+
* `packages/shared/src/repo-config-schema.ts`, because the `lastlight` CLI
|
|
38
|
+
* needs exactly the same answers offline (`lastlight repo config validate`)
|
|
39
|
+
* and may never gain a dependency edge to core. It is **re-exported wholesale**
|
|
40
|
+
* below, so `src/config/repo-config.js` remains the single import surface for
|
|
41
|
+
* everything about the repo layer.
|
|
42
|
+
*/
|
|
43
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
|
|
44
|
+
import { dirname, join, resolve, sep } from "path";
|
|
45
|
+
import { DEFAULT_REPO_CONFIG_ALLOW_KEYS, REPO_CONFIG_FILE, REPO_CONFIG_MAX_BYTES, REPO_CONFIG_MAX_FILES, isConfigSource, isRepoWorkflowPath, parseRepoConfigYaml, repoLayerPathKind, sanitizeRepoFiles, } from "lastlight-shared/repo-config-schema";
|
|
46
|
+
import { GitHubClient } from "../engine/github/github.js";
|
|
47
|
+
import { getRuntimeConfig } from "./config.js";
|
|
48
|
+
/**
|
|
49
|
+
* The pure half, re-exported so every existing `src/config/repo-config.js`
|
|
50
|
+
* import (`resolveRepoConfig`, `sanitizeRepoFiles`, `RepoConfigWarning`, the
|
|
51
|
+
* bounds constants, …) keeps resolving unchanged after the move to
|
|
52
|
+
* `lastlight-shared`.
|
|
53
|
+
*/
|
|
54
|
+
export * from "lastlight-shared/repo-config-schema";
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Bounds (cache-only — the rest live with the schema in lastlight-shared)
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
/** How long a fetched layer is trusted before we re-check with a conditional request. */
|
|
59
|
+
export const REPO_CONFIG_TTL_MS = 60_000;
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// Policy access
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
/**
|
|
64
|
+
* The operator's bounds from runtime config, with the shipped defaults when
|
|
65
|
+
* config isn't loaded (unit tests, pre-boot code paths). Never throws.
|
|
66
|
+
*/
|
|
67
|
+
export function repoConfigPolicy() {
|
|
68
|
+
return (getRuntimeConfig()?.repoConfig ?? {
|
|
69
|
+
enabled: true,
|
|
70
|
+
allowKeys: [...DEFAULT_REPO_CONFIG_ALLOW_KEYS],
|
|
71
|
+
allowedModels: null,
|
|
72
|
+
allowAssets: true,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Project the boot config into the {@link RepoConfigBase} the pure resolver
|
|
77
|
+
* takes. `publicConfig.sources` is the provenance tree `loadConfig` already
|
|
78
|
+
* built, so a leaf the repo does NOT override keeps its real boot provenance
|
|
79
|
+
* ("overlay", "env", …) rather than being flattened to "default".
|
|
80
|
+
*/
|
|
81
|
+
export function repoConfigBaseFromRuntime(config) {
|
|
82
|
+
const bootSources = isPlainObject(config.publicConfig?.sources) ? config.publicConfig.sources : {};
|
|
83
|
+
return {
|
|
84
|
+
value: {
|
|
85
|
+
models: { ...config.models },
|
|
86
|
+
variants: { ...config.variants },
|
|
87
|
+
disabled: { ...config.disabled },
|
|
88
|
+
approval: { ...(config.approval ?? {}) },
|
|
89
|
+
},
|
|
90
|
+
sources: {
|
|
91
|
+
models: expandSourceNode(bootSources.models, Object.keys(config.models)),
|
|
92
|
+
variants: expandSourceNode(bootSources.variants, Object.keys(config.variants)),
|
|
93
|
+
disabled: expandSourceNode(bootSources.disabled, Object.keys(config.disabled)),
|
|
94
|
+
approval: expandSourceNode(bootSources.approval, Object.keys(config.approval ?? {})),
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Normalize one provenance sub-tree. `loadConfig` collapses a node to a single
|
|
100
|
+
* source string when env replaced it wholesale (APPROVAL_GATES does exactly
|
|
101
|
+
* this) — expand that back to per-key leaves so the repo merge attributes
|
|
102
|
+
* key-by-key like every other node.
|
|
103
|
+
*/
|
|
104
|
+
function expandSourceNode(node, keys) {
|
|
105
|
+
const out = {};
|
|
106
|
+
const flat = isConfigSource(node) ? node : undefined;
|
|
107
|
+
for (const key of keys)
|
|
108
|
+
out[key] = flat ?? "default";
|
|
109
|
+
if (!flat && isPlainObject(node)) {
|
|
110
|
+
for (const [k, v] of Object.entries(node))
|
|
111
|
+
if (isConfigSource(v))
|
|
112
|
+
out[k] = v;
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
function isPlainObject(value) {
|
|
117
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
118
|
+
}
|
|
119
|
+
/** True when `filePath` resolves inside `root`. The last gate before {@link unpack} writes. */
|
|
120
|
+
function isInside(filePath, root) {
|
|
121
|
+
const r = resolve(root);
|
|
122
|
+
const f = resolve(filePath);
|
|
123
|
+
return f === r || f.startsWith(r + sep);
|
|
124
|
+
}
|
|
125
|
+
const memoryCache = new Map();
|
|
126
|
+
/**
|
|
127
|
+
* Fetch (or serve from cache) a repo's `.lastlight/` layer.
|
|
128
|
+
*
|
|
129
|
+
* Never throws and never rejects: a GitHub failure degrades to the last good
|
|
130
|
+
* cached layer, or to `undefined`. `undefined` means "no repo layer applies" —
|
|
131
|
+
* the feature is off, the repo has no `.lastlight/`, there's no GitHub auth, or
|
|
132
|
+
* the fetch failed with nothing cached.
|
|
133
|
+
*
|
|
134
|
+
* Cache behaviour: within {@link REPO_CONFIG_TTL_MS} the cached answer is
|
|
135
|
+
* returned untouched. After that a CONDITIONAL request goes out; a
|
|
136
|
+
* "not modified" answer just refreshes the timestamp, so the steady-state cost
|
|
137
|
+
* of a cron fanning out over N repos is N conditional requests and zero
|
|
138
|
+
* downloads.
|
|
139
|
+
*/
|
|
140
|
+
export async function fetchRepoLayer(repo, options = {}) {
|
|
141
|
+
const policy = options.policy ?? repoConfigPolicy();
|
|
142
|
+
if (!policy.enabled)
|
|
143
|
+
return undefined;
|
|
144
|
+
const slug = parseRepoSlug(repo);
|
|
145
|
+
if (!slug) {
|
|
146
|
+
console.warn(`[repo-config] Ignoring malformed repo name: ${repo}`);
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
const now = Date.now();
|
|
150
|
+
const cached = memoryCache.get(repo);
|
|
151
|
+
if (cached && !options.force && now - cached.checkedAt < REPO_CONFIG_TTL_MS)
|
|
152
|
+
return cached.layer;
|
|
153
|
+
const dir = repoCacheDir(repo, options.cacheRoot);
|
|
154
|
+
// On a cold process the in-memory cache is empty but the sidecar isn't — read
|
|
155
|
+
// it so the first request after a restart is still conditional.
|
|
156
|
+
const prior = cached?.layer ?? readSidecar(dir);
|
|
157
|
+
// Chat-only mode (no App, no PAT): there's nothing to fetch through. Serve
|
|
158
|
+
// whatever is already unpacked rather than silently dropping the layer.
|
|
159
|
+
const client = options.client ?? resolveRepoConfigClient();
|
|
160
|
+
if (!client)
|
|
161
|
+
return hydrate(repo, dir, prior);
|
|
162
|
+
let result;
|
|
163
|
+
try {
|
|
164
|
+
result = await client.fetchRepoConfigTree(slug.owner, slug.repo, {
|
|
165
|
+
etag: prior?.etag,
|
|
166
|
+
treeSha: prior?.treeSha,
|
|
167
|
+
maxFiles: REPO_CONFIG_MAX_FILES,
|
|
168
|
+
maxBytes: REPO_CONFIG_MAX_BYTES,
|
|
169
|
+
// Don't spend the byte budget on build-handoff docs, which share
|
|
170
|
+
// `.lastlight/` in `buildAssets.location: repo` mode. Workflow YAML is
|
|
171
|
+
// pulled in deliberately: it's rejected with a warning, not ignored.
|
|
172
|
+
includePath: (p) => repoLayerPathKind(p) !== null || isRepoWorkflowPath(p),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
// Warn, keep the last good layer, run anyway.
|
|
177
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
178
|
+
console.warn(`[repo-config] ${repo}: .lastlight/ fetch failed (${message}) — using the cached layer if any`);
|
|
179
|
+
const fallback = hydrate(repo, dir, prior);
|
|
180
|
+
if (fallback) {
|
|
181
|
+
fallback.warnings = [
|
|
182
|
+
...fallback.warnings,
|
|
183
|
+
{
|
|
184
|
+
code: "fetch-failed",
|
|
185
|
+
repo,
|
|
186
|
+
path: ".lastlight",
|
|
187
|
+
message: `Could not refresh .lastlight/ from the default branch (${message}); using the last cached copy.`,
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
memoryCache.set(repo, { layer: fallback, checkedAt: now });
|
|
192
|
+
return fallback;
|
|
193
|
+
}
|
|
194
|
+
if (result.status === "absent") {
|
|
195
|
+
clearRepoCacheDir(dir);
|
|
196
|
+
memoryCache.set(repo, { layer: undefined, checkedAt: now });
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
if (result.status === "not-modified") {
|
|
200
|
+
const layer = hydrate(repo, dir, prior);
|
|
201
|
+
memoryCache.set(repo, { layer, checkedAt: now });
|
|
202
|
+
return layer;
|
|
203
|
+
}
|
|
204
|
+
const { accepted, warnings } = sanitizeRepoFiles(result.files, policy, repo);
|
|
205
|
+
if (result.truncated) {
|
|
206
|
+
warnings.push({
|
|
207
|
+
code: "size-cap",
|
|
208
|
+
repo,
|
|
209
|
+
path: ".lastlight",
|
|
210
|
+
message: `.lastlight/ was truncated at ${REPO_CONFIG_MAX_FILES} files / ${REPO_CONFIG_MAX_BYTES} bytes — ` +
|
|
211
|
+
`some of it was not read.`,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
const root = unpack(dir, accepted);
|
|
215
|
+
const configFile = accepted.find((f) => f.path === REPO_CONFIG_FILE);
|
|
216
|
+
const parsed = configFile
|
|
217
|
+
? parseRepoConfigYaml(configFile.content.toString("utf-8"), repo)
|
|
218
|
+
: { warnings: [] };
|
|
219
|
+
warnings.push(...parsed.warnings);
|
|
220
|
+
const layer = {
|
|
221
|
+
repo,
|
|
222
|
+
defaultBranch: result.defaultBranch,
|
|
223
|
+
treeSha: result.treeSha,
|
|
224
|
+
etag: result.etag,
|
|
225
|
+
fetchedAt: new Date().toISOString(),
|
|
226
|
+
root,
|
|
227
|
+
config: parsed.config,
|
|
228
|
+
assets: accepted.filter((f) => f.path !== REPO_CONFIG_FILE).map((f) => f.path),
|
|
229
|
+
warnings,
|
|
230
|
+
};
|
|
231
|
+
writeSidecar(dir, layer);
|
|
232
|
+
memoryCache.set(repo, { layer, checkedAt: now });
|
|
233
|
+
return layer;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Force a refresh now, bypassing the TTL. `GET /admin/api/repos/:owner/:repo/config?refresh=1`
|
|
237
|
+
* (and so `lastlight repo config show --refresh`) hangs off this — an operator
|
|
238
|
+
* who has just merged a `.lastlight/` change shouldn't wait out the TTL.
|
|
239
|
+
*/
|
|
240
|
+
export function refreshRepoLayer(repo, options = {}) {
|
|
241
|
+
return fetchRepoLayer(repo, { ...options, force: true });
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Drop a repo's cached layer (or every repo's, with no argument). The next
|
|
245
|
+
* {@link fetchRepoLayer} re-checks. Cheap — the unpacked files and sidecar stay
|
|
246
|
+
* on disk, so the re-check is still conditional.
|
|
247
|
+
*/
|
|
248
|
+
export function invalidateRepoLayer(repo) {
|
|
249
|
+
if (repo)
|
|
250
|
+
memoryCache.delete(repo);
|
|
251
|
+
else
|
|
252
|
+
memoryCache.clear();
|
|
253
|
+
}
|
|
254
|
+
/** The cached layer without touching the network — for read-only surfaces (dashboard, CLI). */
|
|
255
|
+
export function getCachedRepoLayer(repo) {
|
|
256
|
+
return memoryCache.get(repo)?.layer;
|
|
257
|
+
}
|
|
258
|
+
/** Test-only: clear the in-memory cache. Matches the `resetXForTests()` convention. */
|
|
259
|
+
export function resetRepoConfigForTests() {
|
|
260
|
+
memoryCache.clear();
|
|
261
|
+
}
|
|
262
|
+
// ---------------------------------------------------------------------------
|
|
263
|
+
// Fetch/cache internals
|
|
264
|
+
// ---------------------------------------------------------------------------
|
|
265
|
+
/**
|
|
266
|
+
* The harness GitHub client, or `undefined` in chat-only mode. Config-first
|
|
267
|
+
* (never live `process.env`) for the same reason `resolveReviewGitHubClient` is:
|
|
268
|
+
* boot config can't be raced by anything mutating the env mid-run.
|
|
269
|
+
*/
|
|
270
|
+
function resolveRepoConfigClient() {
|
|
271
|
+
const cfg = getRuntimeConfig();
|
|
272
|
+
if (cfg?.githubApp)
|
|
273
|
+
return new GitHubClient(cfg.githubApp);
|
|
274
|
+
if (cfg?.githubToken)
|
|
275
|
+
return GitHubClient.withToken(cfg.githubToken);
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
/** Split `owner/repo`, rejecting anything that couldn't be a path segment. */
|
|
279
|
+
function parseRepoSlug(repo) {
|
|
280
|
+
const parts = repo.split("/");
|
|
281
|
+
if (parts.length !== 2)
|
|
282
|
+
return undefined;
|
|
283
|
+
const [owner, name] = parts;
|
|
284
|
+
const safe = /^[A-Za-z0-9._-]+$/;
|
|
285
|
+
if (!safe.test(owner) || !safe.test(name) || owner === "." || owner === ".." || name === "." || name === "..") {
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
return { owner, repo: name };
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* On-disk cache root. `<stateDir>/repo-config/<owner>/<repo>/` holds
|
|
292
|
+
* `meta.json` (the sidecar) beside `files/` (the unpacked `.lastlight/` tree).
|
|
293
|
+
* Keeping the sidecar OUT of `files/` means a repo can't shadow it by
|
|
294
|
+
* committing its own `meta.json`.
|
|
295
|
+
*/
|
|
296
|
+
function repoCacheDir(repo, cacheRoot) {
|
|
297
|
+
const root = cacheRoot ?? join(getRuntimeConfig()?.stateDir ?? resolve(process.env.STATE_DIR || "./data"), "repo-config");
|
|
298
|
+
return join(root, repo);
|
|
299
|
+
}
|
|
300
|
+
function readSidecar(dir) {
|
|
301
|
+
const file = join(dir, "meta.json");
|
|
302
|
+
try {
|
|
303
|
+
if (!existsSync(file))
|
|
304
|
+
return undefined;
|
|
305
|
+
const parsed = JSON.parse(readFileSync(file, "utf-8"));
|
|
306
|
+
return typeof parsed?.treeSha === "string" ? parsed : undefined;
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function writeSidecar(dir, layer) {
|
|
313
|
+
const sidecar = {
|
|
314
|
+
repo: layer.repo,
|
|
315
|
+
defaultBranch: layer.defaultBranch,
|
|
316
|
+
treeSha: layer.treeSha,
|
|
317
|
+
etag: layer.etag,
|
|
318
|
+
fetchedAt: layer.fetchedAt,
|
|
319
|
+
assets: layer.assets,
|
|
320
|
+
warnings: layer.warnings,
|
|
321
|
+
};
|
|
322
|
+
try {
|
|
323
|
+
mkdirSync(dir, { recursive: true });
|
|
324
|
+
writeFileSync(join(dir, "meta.json"), JSON.stringify(sidecar, null, 2));
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
console.warn(`[repo-config] Could not persist ${layer.repo} cache sidecar: ${err.message}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Rebuild a {@link RepoLayer} from the on-disk cache — the "not modified" path,
|
|
332
|
+
* and the path a restarted process takes before anything has changed upstream.
|
|
333
|
+
* Re-parses `lastlight.yml` from disk rather than trusting a serialized copy, so
|
|
334
|
+
* the cache holds bytes, not decisions.
|
|
335
|
+
*/
|
|
336
|
+
function hydrate(repo, dir, sidecar) {
|
|
337
|
+
if (!sidecar)
|
|
338
|
+
return undefined;
|
|
339
|
+
const root = join(dir, "files");
|
|
340
|
+
if (!existsSync(root))
|
|
341
|
+
return undefined;
|
|
342
|
+
const configPath = join(root, REPO_CONFIG_FILE);
|
|
343
|
+
let config;
|
|
344
|
+
const warnings = [...(sidecar.warnings ?? [])];
|
|
345
|
+
if (existsSync(configPath)) {
|
|
346
|
+
const parsed = parseRepoConfigYaml(readFileSync(configPath, "utf-8"), repo);
|
|
347
|
+
config = parsed.config;
|
|
348
|
+
// The sidecar already carries the parse warning from the original fetch —
|
|
349
|
+
// don't double-report it.
|
|
350
|
+
if (!warnings.some((w) => w.code === "invalid-yaml" || w.code === "not-a-mapping")) {
|
|
351
|
+
warnings.push(...parsed.warnings);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
repo,
|
|
356
|
+
defaultBranch: sidecar.defaultBranch,
|
|
357
|
+
treeSha: sidecar.treeSha,
|
|
358
|
+
etag: sidecar.etag,
|
|
359
|
+
fetchedAt: sidecar.fetchedAt,
|
|
360
|
+
root,
|
|
361
|
+
config,
|
|
362
|
+
assets: sidecar.assets ?? [],
|
|
363
|
+
warnings,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Materialize the accepted files under `<dir>/files/`, replacing whatever was
|
|
368
|
+
* there. Built in a sibling `files.tmp` and renamed into place so a crash
|
|
369
|
+
* mid-unpack can never leave a half-written layer that a run would then read.
|
|
370
|
+
* Every write is re-checked against the root — the belt to `sanitizeRepoFiles`'s
|
|
371
|
+
* braces, since this is the moment a bad path would actually escape.
|
|
372
|
+
*/
|
|
373
|
+
function unpack(dir, files) {
|
|
374
|
+
const root = join(dir, "files");
|
|
375
|
+
const tmp = join(dir, "files.tmp");
|
|
376
|
+
try {
|
|
377
|
+
mkdirSync(dir, { recursive: true });
|
|
378
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
379
|
+
mkdirSync(tmp, { recursive: true });
|
|
380
|
+
for (const file of files) {
|
|
381
|
+
const target = join(tmp, file.path);
|
|
382
|
+
if (!isInside(target, tmp))
|
|
383
|
+
continue;
|
|
384
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
385
|
+
writeFileSync(target, file.content);
|
|
386
|
+
}
|
|
387
|
+
rmSync(root, { recursive: true, force: true });
|
|
388
|
+
renameSync(tmp, root);
|
|
389
|
+
}
|
|
390
|
+
catch (err) {
|
|
391
|
+
console.warn(`[repo-config] Could not unpack ${dir}: ${err.message}`);
|
|
392
|
+
}
|
|
393
|
+
return root;
|
|
394
|
+
}
|
|
395
|
+
function clearRepoCacheDir(dir) {
|
|
396
|
+
try {
|
|
397
|
+
if (existsSync(dir) && statSync(dir).isDirectory())
|
|
398
|
+
rmSync(dir, { recursive: true, force: true });
|
|
399
|
+
}
|
|
400
|
+
catch {
|
|
401
|
+
// Best-effort — a stale cache dir is harmless once the memory entry is negative.
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* List the unpacked layer's asset paths (relative to `root`). Handy for the
|
|
406
|
+
* admin/CLI views that show what a repo actually contributed.
|
|
407
|
+
*/
|
|
408
|
+
export function listRepoLayerAssets(root) {
|
|
409
|
+
const out = [];
|
|
410
|
+
const walk = (dir, prefix) => {
|
|
411
|
+
let entries;
|
|
412
|
+
try {
|
|
413
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
414
|
+
}
|
|
415
|
+
catch {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
for (const entry of entries) {
|
|
419
|
+
// Never follow a symlink out of the cache, even one we didn't write.
|
|
420
|
+
if (entry.isSymbolicLink())
|
|
421
|
+
continue;
|
|
422
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
423
|
+
if (entry.isDirectory())
|
|
424
|
+
walk(join(dir, entry.name), rel);
|
|
425
|
+
else if (entry.isFile() && rel !== REPO_CONFIG_FILE)
|
|
426
|
+
out.push(rel);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
walk(root, "");
|
|
430
|
+
return out.sort();
|
|
431
|
+
}
|
|
432
|
+
//# sourceMappingURL=repo-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-config.js","sourceRoot":"","sources":["../../src/config/repo-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,GAMlB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAuB,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAwB,MAAM,aAAa,CAAC;AAErE;;;;;GAKG;AACH,cAAc,qCAAqC,CAAC;AAEpD,8EAA8E;AAC9E,0EAA0E;AAC1E,8EAA8E;AAE9E,yFAAyF;AACzF,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAczC,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,CACL,gBAAgB,EAAE,EAAE,UAAU,IAAI;QAChC,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,CAAC,GAAG,8BAA8B,CAAC;QAC9C,aAAa,EAAE,IAAI;QACnB,WAAW,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AAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;YAC5D,IAAI,KAAK,CAAC,WAAW,EAAE;gBAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;iBACrD,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,GAAG,KAAK,gBAAgB;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC;IACF,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACf,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;AACpB,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/c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O,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CACnE,CAAC;IAEF,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC;YAAE,QAAQ,EAAE,CAAC;IAClE,CAAC;IAED,OAAO,EAAE,UAAU,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,4 +1,5 @@
|
|
|
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";
|
|
3
4
|
/**
|
|
4
5
|
* Get cron jobs based on configuration.
|
|
@@ -9,10 +10,19 @@ import type { StateDb } from "../state/db.js";
|
|
|
9
10
|
* (WEBHOOK_SECRET is set), jobs with `condition.unless: webhooksEnabled`
|
|
10
11
|
* are filtered out — those are handled in real-time via webhook events.
|
|
11
12
|
*
|
|
12
|
-
* When `db` is supplied, cron_overrides rows applied:
|
|
13
|
-
*
|
|
13
|
+
* When `db` is supplied, cron_overrides rows applied: a schedule override
|
|
14
|
+
* replaces the YAML schedule, and a disabled row turns the cron off globally.
|
|
15
|
+
*
|
|
16
|
+
* "Off globally" is NOT "unregistered" (issue #180). A globally-off cron still
|
|
17
|
+
* gets a tick, marked `_cronGloballyEnabled: false`, because a managed repo may
|
|
18
|
+
* opt itself back in via its `.lastlight/lastlight.yml`. Resolving that at TICK
|
|
19
|
+
* time (see `fanout.ts` → `resolveCronRepos`) is what lets a repo's edit take
|
|
20
|
+
* effect without dynamically re-registering croner jobs; a tick whose repo list
|
|
21
|
+
* comes back empty is a cheap no-op — no dispatch, no run, no error.
|
|
14
22
|
*/
|
|
15
23
|
export declare function getJobs(opts?: {
|
|
16
24
|
webhooksEnabled?: boolean;
|
|
17
25
|
db?: StateDb;
|
|
26
|
+
/** Operator cron block. Defaults to runtime config — injectable for tests. */
|
|
27
|
+
crons?: CronsConfig;
|
|
18
28
|
}): CronJob[];
|
package/dist/cron/jobs.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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";
|
|
3
4
|
/**
|
|
4
5
|
* Get cron jobs based on configuration.
|
|
5
6
|
*
|
|
@@ -9,8 +10,15 @@ import { getCronWorkflows } from "../workflows/loader.js";
|
|
|
9
10
|
* (WEBHOOK_SECRET is set), jobs with `condition.unless: webhooksEnabled`
|
|
10
11
|
* are filtered out — those are handled in real-time via webhook events.
|
|
11
12
|
*
|
|
12
|
-
* When `db` is supplied, cron_overrides rows applied:
|
|
13
|
-
*
|
|
13
|
+
* When `db` is supplied, cron_overrides rows applied: a schedule override
|
|
14
|
+
* replaces the YAML schedule, and a disabled row turns the cron off globally.
|
|
15
|
+
*
|
|
16
|
+
* "Off globally" is NOT "unregistered" (issue #180). A globally-off cron still
|
|
17
|
+
* gets a tick, marked `_cronGloballyEnabled: false`, because a managed repo may
|
|
18
|
+
* opt itself back in via its `.lastlight/lastlight.yml`. Resolving that at TICK
|
|
19
|
+
* time (see `fanout.ts` → `resolveCronRepos`) is what lets a repo's edit take
|
|
20
|
+
* effect without dynamically re-registering croner jobs; a tick whose repo list
|
|
21
|
+
* comes back empty is a cheap no-op — no dispatch, no run, no error.
|
|
14
22
|
*/
|
|
15
23
|
export function getJobs(opts) {
|
|
16
24
|
const jobs = [];
|
|
@@ -20,10 +28,16 @@ export function getJobs(opts) {
|
|
|
20
28
|
cronDefs = cronDefs.filter((def) => def.condition?.unless !== "webhooksEnabled");
|
|
21
29
|
}
|
|
22
30
|
const overrides = opts?.db?.getAllCronOverrides() ?? new Map();
|
|
31
|
+
// Already includes the legacy `disabled.crons` names (unioned by the config
|
|
32
|
+
// normaliser). Those are additionally dropped by the asset loader before we
|
|
33
|
+
// ever see them here, so this is belt-and-braces for anything that reaches us.
|
|
34
|
+
const crons = opts?.crons ?? operatorCrons();
|
|
23
35
|
for (const def of cronDefs) {
|
|
24
36
|
const override = overrides.get(def.name);
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
// The dashboard toggle and the operator's `crons.disable` are the same
|
|
38
|
+
// lever spelled two ways — both mean "off by default", both leave the tick
|
|
39
|
+
// registered so a repo opt-in can still be honoured.
|
|
40
|
+
const globallyEnabled = (override ? override.enabled : true) && !crons.disable.includes(def.name);
|
|
27
41
|
jobs.push({
|
|
28
42
|
name: def.name,
|
|
29
43
|
schedule: override?.schedule || def.schedule,
|
|
@@ -32,7 +46,19 @@ export function getJobs(opts) {
|
|
|
32
46
|
// installation-filtered list so a stale managedRepos entry (repo deleted /
|
|
33
47
|
// transferred / access revoked) doesn't fan out into a doomed scan run
|
|
34
48
|
// whose scoped-token mint 422s.
|
|
35
|
-
context: {
|
|
49
|
+
context: {
|
|
50
|
+
repos: getAccessibleManagedRepos(),
|
|
51
|
+
// Spread ahead of the control keys, deliberately: a cron YAML MAY pin
|
|
52
|
+
// its own `context.repos` and override the managed-repo list.
|
|
53
|
+
...def.context,
|
|
54
|
+
// Control keys for the fan-out; stripped there, never reaching a run.
|
|
55
|
+
// Injected LAST so operator YAML can't spoof them — a `_cronName` from
|
|
56
|
+
// `context:` would make `resolveCronRepos` apply another cron's per-repo
|
|
57
|
+
// opt-in/opt-out rules to this tick, and a `_cronGloballyEnabled` would
|
|
58
|
+
// let a disabled cron fan out as enabled.
|
|
59
|
+
[CRON_NAME_KEY]: def.name,
|
|
60
|
+
[CRON_GLOBALLY_ENABLED_KEY]: globallyEnabled,
|
|
61
|
+
},
|
|
36
62
|
});
|
|
37
63
|
}
|
|
38
64
|
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;AAI1F;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,OAAO,CAAC,IAKvB;IACC,MAAM,IAAI,GAAc,EAAE,CAAC;IAE3B,IAAI,QAAQ,GAAG,gBAAgB,EAAE,CAAC;IAElC,mBAAmB;IACnB,IAAI,IAAI,EAAE,eAAe,EAAE,CAAC;QAC1B,QAAQ,GAAG,QAAQ,CAAC,MAA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