lastlight-core 0.21.14 → 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/executors/orchestrator.js +39 -15
- package/dist/engine/executors/orchestrator.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/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 +3 -3
package/config/default.yaml
CHANGED
|
@@ -87,6 +87,30 @@ deploy:
|
|
|
87
87
|
|
|
88
88
|
approval: {}
|
|
89
89
|
|
|
90
|
+
# Per-repository configuration (issue #180). A managed repo may commit a
|
|
91
|
+
# `.lastlight/` directory — mirroring the instance overlay's on-disk shape
|
|
92
|
+
# (`lastlight.yml`, `workflows/prompts/*.md`, `skills/<name>/SKILL.md`,
|
|
93
|
+
# `agent-context/*.md`) — that overrides a BOUNDED subset of this config for
|
|
94
|
+
# runs against that repo. Precedence: default -> overlay -> env -> repo.
|
|
95
|
+
#
|
|
96
|
+
# The block below is the OPERATOR's bounds on that layer; a repo can never widen
|
|
97
|
+
# them. It is inert out of the box: nothing changes for an existing deployment
|
|
98
|
+
# until a repo actually commits `.lastlight/lastlight.yml`.
|
|
99
|
+
#
|
|
100
|
+
# SECURITY: the repo layer is ALWAYS read from the repo's DEFAULT BRANCH, never
|
|
101
|
+
# a PR head and never the sandbox checkout — otherwise a PR could rewrite the
|
|
102
|
+
# configuration of the agent reviewing it. See src/config/repo-config.ts.
|
|
103
|
+
repoConfig:
|
|
104
|
+
enabled: true # master switch; false ignores every repo's .lastlight/
|
|
105
|
+
# Config keys a repo may set, as dotted paths. Anything outside this list is
|
|
106
|
+
# dropped with a warning (the run still proceeds — a repo's config file can
|
|
107
|
+
# never fail a run). Narrow it to tighten the blast radius. Removing `crons`
|
|
108
|
+
# makes the operator's `crons:` block below un-overridable — the kill switch.
|
|
109
|
+
allowKeys: [models, variants, crons, disabled.workflows, disabled.crons, approval]
|
|
110
|
+
allowedModels: null # null = any model whose provider prefix is configured;
|
|
111
|
+
# a list restricts repos to exactly those model specs
|
|
112
|
+
allowAssets: true # allow the repo's prompt/skill/agent-context overrides
|
|
113
|
+
|
|
90
114
|
bootstrap:
|
|
91
115
|
label: "lastlight:bootstrap"
|
|
92
116
|
|
|
@@ -96,8 +120,34 @@ explore:
|
|
|
96
120
|
review:
|
|
97
121
|
postsCheck: false
|
|
98
122
|
|
|
123
|
+
# Which crons participate (issue #180). The SAME block is valid here, in your
|
|
124
|
+
# overlay's config.yaml, and in a managed repo's .lastlight/lastlight.yml — the
|
|
125
|
+
# meaning depends on the layer:
|
|
126
|
+
#
|
|
127
|
+
# operator (here / overlay) disable: [x] → cron x is off globally
|
|
128
|
+
# enable: [x] → no-op; a cron is on by default
|
|
129
|
+
# repo (.lastlight/) disable: [x] → THIS repo drops out of x's fan-out
|
|
130
|
+
# enable: [x] → THIS repo opts in even when x is
|
|
131
|
+
# off globally
|
|
132
|
+
#
|
|
133
|
+
# A name in BOTH lists is disabled, at every layer — a cron that doesn't run is
|
|
134
|
+
# the safe reading of a contradictory config.
|
|
135
|
+
#
|
|
136
|
+
# `disabled.crons` below is the LEGACY spelling of `crons.disable` and still
|
|
137
|
+
# works exactly as before: it is unioned into this list (and additionally drops
|
|
138
|
+
# the cron's definition at asset-load time, so it is the harder kill).
|
|
139
|
+
#
|
|
140
|
+
# NOTE: `crons.disable` here means "off BY DEFAULT" — a repo listed in
|
|
141
|
+
# `repoConfig.allowKeys` can still opt itself back in. If you want a kill switch
|
|
142
|
+
# no repo can override, drop `crons` from repoConfig.allowKeys (below); that
|
|
143
|
+
# leaves this list as the only word on the subject.
|
|
144
|
+
crons:
|
|
145
|
+
enable: []
|
|
146
|
+
disable: []
|
|
147
|
+
|
|
99
148
|
disabled:
|
|
100
149
|
workflows: []
|
|
150
|
+
# Legacy alias for `crons.disable` above — kept working, not deprecated.
|
|
101
151
|
crons: []
|
|
102
152
|
prompts: []
|
|
103
153
|
skills: []
|
package/dist/admin/routes.js
CHANGED
|
@@ -7,13 +7,21 @@ import { tailJsonl } from "./tail.js";
|
|
|
7
7
|
import { listRunningContainers, killContainer, getContainerStats, getHostStats, listServerContainers, resolveServerContainer, getContainerLogs, streamContainerLogs, } from "./docker.js";
|
|
8
8
|
import { authMiddleware, createToken, verifyTokenForRefresh, decodeToken, actorFromContext } from "./auth.js";
|
|
9
9
|
import { Cron } from "croner";
|
|
10
|
+
import { CRON_GLOBALLY_ENABLED_KEY, CRON_NAME_KEY, cronVote, repoCronPrefs, repoLayerMayVote, } from "../cron/repo-crons.js";
|
|
10
11
|
import { enumerateOverlayAssets } from "lastlight-shared/overlay-assets";
|
|
11
12
|
import { getCronWorkflows, getWorkflow, getWorkflowByIntent, listAgentWorkflows, loadWorkflowYamlRaw, loadPromptTemplate, loadSkillRaw, } from "../workflows/loader.js";
|
|
12
13
|
import { routeEvent } from "../engine/router.js";
|
|
13
14
|
import { classifyComment } from "../engine/screen/classifier.js";
|
|
14
15
|
import { getWorkflowTriggers, getWorkflowTriggerKinds, } from "../workflows/triggers.js";
|
|
15
|
-
import { getManagedRepos, getInstallationRepos, getInstallationReposRefreshedAt, } from "../managed-repos.js";
|
|
16
|
-
import { getRuntimeConfig, getRoutes, getBotName, resolveKubernetesConfig,
|
|
16
|
+
import { getManagedRepos, getInstallationRepos, getInstallationReposRefreshedAt, isManagedRepo, } from "../managed-repos.js";
|
|
17
|
+
import { getRuntimeConfig, getRoutes, getBotName, resolveKubernetesConfig,
|
|
18
|
+
// The redaction rule for every surface that echoes YAML back to the
|
|
19
|
+
// dashboard. IMPORTED, never mirrored: `GET /repos/:owner/:repo/config`
|
|
20
|
+
// returns a repo's UNTRUSTED `.lastlight/lastlight.yml` raw and
|
|
21
|
+
// pre-validation, so a copy that drifted behind config.ts's would leak a
|
|
22
|
+
// pasted credential. It must stay single-source (see config.ts).
|
|
23
|
+
redactPublic, } from "../config/config.js";
|
|
24
|
+
import { fetchRepoLayer, refreshRepoLayer, getCachedRepoLayer, repoConfigPolicy, repoConfigBaseFromRuntime, resolveRepoConfig, } from "../config/repo-config.js";
|
|
17
25
|
import { reapSandboxWorkspace } from "../sandbox/reap.js";
|
|
18
26
|
import { artifactStore } from "../sandbox/artifact-store.js";
|
|
19
27
|
import { reclaimSandbox } from "../sandbox/k8s/reclaim.js";
|
|
@@ -422,12 +430,21 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
422
430
|
// events (config wins when set, else installation). See src/managed-repos.ts.
|
|
423
431
|
app.get("/managed-repos", (c) => {
|
|
424
432
|
const configured = getRuntimeConfig()?.managedRepos ?? [];
|
|
433
|
+
const effective = getManagedRepos();
|
|
425
434
|
return c.json({
|
|
426
435
|
configured,
|
|
427
436
|
installation: getInstallationRepos(),
|
|
428
|
-
effective
|
|
437
|
+
effective,
|
|
429
438
|
source: configured.length > 0 ? "config" : "installation",
|
|
430
439
|
refreshedAt: getInstallationReposRefreshedAt(),
|
|
440
|
+
// Which of the effective repos have committed a `.lastlight/` layer.
|
|
441
|
+
// Read from the in-memory cache ONLY (`getCachedRepoLayer`) so this stays
|
|
442
|
+
// a cheap no-network list route — a repo not yet fetched simply reports
|
|
443
|
+
// false, and the per-repo endpoint below is what actually goes to GitHub.
|
|
444
|
+
repoConfig: effective.map((repo) => {
|
|
445
|
+
const layer = getCachedRepoLayer(repo);
|
|
446
|
+
return { repo, hasRepoConfig: Boolean(layer), fetchedAt: layer?.fetchedAt ?? null };
|
|
447
|
+
}),
|
|
431
448
|
});
|
|
432
449
|
});
|
|
433
450
|
// Forked/overridden assets the deployment overlay supplies — workflows,
|
|
@@ -1528,6 +1545,10 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1528
1545
|
runCount: activity.get(repo)?.runCount ?? 0,
|
|
1529
1546
|
lastRunAt: activity.get(repo)?.lastRunAt ?? null,
|
|
1530
1547
|
artifactKeyCount: artifactCounts.get(repo) ?? 0,
|
|
1548
|
+
// Cache-only (no network) so the index stays cheap — it just makes the
|
|
1549
|
+
// per-repo Config tab discoverable. False here means "nothing cached
|
|
1550
|
+
// yet", not "no .lastlight/"; opening the tab settles it.
|
|
1551
|
+
hasRepoConfig: Boolean(getCachedRepoLayer(repo)),
|
|
1531
1552
|
}))
|
|
1532
1553
|
.sort((a, b) => {
|
|
1533
1554
|
// Newest activity first; repos with no runs sink below active ones,
|
|
@@ -1542,6 +1563,75 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1542
1563
|
});
|
|
1543
1564
|
return c.json({ repos });
|
|
1544
1565
|
});
|
|
1566
|
+
/**
|
|
1567
|
+
* The prompts / skills / agent-context a repo's `.lastlight/` contributes,
|
|
1568
|
+
* each tagged with whether it shadows something the instance already has.
|
|
1569
|
+
*
|
|
1570
|
+
* A repo layer's unpacked root mirrors an overlay root exactly, so this is
|
|
1571
|
+
* the same enumerator `GET /overrides`, `lastlight fork` and `server status`
|
|
1572
|
+
* use — pointed at the repo's tree instead. It's run twice because a repo
|
|
1573
|
+
* asset can shadow either a built-in OR an overlay fork, and "shadows" should
|
|
1574
|
+
* mean "replaces something that was already in force".
|
|
1575
|
+
*/
|
|
1576
|
+
function repoLayerAssets(root) {
|
|
1577
|
+
const assets = enumerateOverlayAssets({ coreRoot: config.builtInRoot, overlayRoot: root });
|
|
1578
|
+
const shadowsOverlay = new Set(enumerateOverlayAssets({ coreRoot: config.overlayDir, overlayRoot: root })
|
|
1579
|
+
.filter((a) => a.shadowsDefault)
|
|
1580
|
+
.map((a) => `${a.type}:${a.name}`));
|
|
1581
|
+
return assets.map((a) => ({
|
|
1582
|
+
...a,
|
|
1583
|
+
shadowsDefault: a.shadowsDefault || shadowsOverlay.has(`${a.type}:${a.name}`),
|
|
1584
|
+
}));
|
|
1585
|
+
}
|
|
1586
|
+
// The effective config for ONE repo — the instance layers with that repo's
|
|
1587
|
+
// committed `.lastlight/` applied on top, within the operator's `repoConfig`
|
|
1588
|
+
// bounds (issue #180). Powers the Repos → Config tab and `lastlight repo
|
|
1589
|
+
// config show`.
|
|
1590
|
+
//
|
|
1591
|
+
// A repo with no `.lastlight/` is a perfectly normal 200: `repoLayer` is
|
|
1592
|
+
// absent and `merged`/`sources` are simply the inherited instance config.
|
|
1593
|
+
// That's the whole point of the view — "what does Last Light actually do for
|
|
1594
|
+
// this repo", not "does this repo have a config file".
|
|
1595
|
+
//
|
|
1596
|
+
// `?refresh=1` bypasses the 60s TTL (the operator has just merged a
|
|
1597
|
+
// `.lastlight/` change and doesn't want to wait it out).
|
|
1598
|
+
app.get("/repos/:owner/:repo/config", async (c) => {
|
|
1599
|
+
const { owner, repo: name } = c.req.param();
|
|
1600
|
+
const repo = `${owner}/${name}`;
|
|
1601
|
+
// Same allowlist that gates every other repo-touching path. Without it this
|
|
1602
|
+
// endpoint would be an unauthenticated-by-proxy way to make the harness
|
|
1603
|
+
// fetch from an arbitrary repo.
|
|
1604
|
+
if (!isManagedRepo(repo)) {
|
|
1605
|
+
return c.json({ error: `${repo} is not a managed repository` }, 404);
|
|
1606
|
+
}
|
|
1607
|
+
const runtime = getRuntimeConfig();
|
|
1608
|
+
if (!runtime)
|
|
1609
|
+
return c.json({ error: "Runtime config is not loaded" }, 503);
|
|
1610
|
+
const policy = repoConfigPolicy();
|
|
1611
|
+
const refresh = c.req.query("refresh");
|
|
1612
|
+
const force = refresh === "1" || refresh === "true";
|
|
1613
|
+
// Both calls degrade to `undefined` rather than throwing — a GitHub failure
|
|
1614
|
+
// must not turn this read-only view into a 500.
|
|
1615
|
+
const layer = force
|
|
1616
|
+
? await refreshRepoLayer(repo, { policy })
|
|
1617
|
+
: await fetchRepoLayer(repo, { policy });
|
|
1618
|
+
const { merged, sources, warnings } = resolveRepoConfig(repoConfigBaseFromRuntime(runtime), policy, layer);
|
|
1619
|
+
return c.json({
|
|
1620
|
+
repo,
|
|
1621
|
+
merged: redactPublic(merged),
|
|
1622
|
+
sources,
|
|
1623
|
+
// RAW and pre-validation on purpose: the repo needs to see what it wrote
|
|
1624
|
+
// next to the warnings explaining what was dropped. Redacted, since this
|
|
1625
|
+
// is untrusted YAML.
|
|
1626
|
+
repoLayer: layer?.config ? redactPublic(layer.config) : undefined,
|
|
1627
|
+
warnings,
|
|
1628
|
+
assets: layer ? repoLayerAssets(layer.root) : [],
|
|
1629
|
+
policy,
|
|
1630
|
+
fetchedAt: layer?.fetchedAt ?? null,
|
|
1631
|
+
treeSha: layer?.treeSha ?? null,
|
|
1632
|
+
defaultBranch: layer?.defaultBranch ?? null,
|
|
1633
|
+
});
|
|
1634
|
+
});
|
|
1545
1635
|
// List the repos that actually have stored artifacts (search + paginate).
|
|
1546
1636
|
// This replaces the old config-driven repo picker, which showed nothing when
|
|
1547
1637
|
// `managedRepos` was empty even though the store held artifacts.
|
|
@@ -1737,12 +1827,63 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1737
1827
|
return c.json({ status: body.decision });
|
|
1738
1828
|
});
|
|
1739
1829
|
// ── Crons ──────────────────────────────────────────────────────
|
|
1830
|
+
/**
|
|
1831
|
+
* The context a cron tick carries, built exactly as `src/cron/jobs.ts` builds
|
|
1832
|
+
* it at boot — including the two control keys the fan-out consumes
|
|
1833
|
+
* (`_cronName`, `_cronGloballyEnabled`) and strips before dispatch.
|
|
1834
|
+
*
|
|
1835
|
+
* They are not optional decoration. `_cronName` is the ONLY channel by which
|
|
1836
|
+
* the tick learns which cron it is (several crons can share one workflow), so
|
|
1837
|
+
* a context without it makes `resolveCronRepos` a no-op and the tick ignores
|
|
1838
|
+
* every repo's `.lastlight/` cron opt-out. These routes re-register jobs at
|
|
1839
|
+
* runtime, so a context built here that omitted them would silently drop
|
|
1840
|
+
* per-repo participation until the next restart re-registered from `jobs.ts` —
|
|
1841
|
+
* the worst kind of bug, one that fixes itself while you're looking at it.
|
|
1842
|
+
*/
|
|
1843
|
+
const cronContext = (def, globallyEnabled) => ({
|
|
1844
|
+
repos: getManagedRepos(),
|
|
1845
|
+
// Spread ahead of the control keys, deliberately: a cron YAML MAY pin its
|
|
1846
|
+
// own `context.repos`. It may NOT pin the control keys — those are injected
|
|
1847
|
+
// after it, so operator YAML can't spoof the cron's identity or its
|
|
1848
|
+
// globally-enabled state (same ordering as `jobs.ts`).
|
|
1849
|
+
...def.context,
|
|
1850
|
+
[CRON_NAME_KEY]: def.name,
|
|
1851
|
+
[CRON_GLOBALLY_ENABLED_KEY]: globallyEnabled,
|
|
1852
|
+
});
|
|
1853
|
+
/**
|
|
1854
|
+
* The managed repos that have opted INTO one cron from their own
|
|
1855
|
+
* `.lastlight/lastlight.yml` (`crons: { enable: [...] }`).
|
|
1856
|
+
*
|
|
1857
|
+
* Why the list endpoint needs this at all: a globally-OFF cron still keeps its
|
|
1858
|
+
* scheduler tick (see the toggle route below), so it reports a real
|
|
1859
|
+
* `registered`/`nextRun`. Without naming the repos that opted in, the dashboard
|
|
1860
|
+
* shows "next run in 20m" beside an off switch and the operator can't tell
|
|
1861
|
+
* whether that's a real firing or a leftover timer. With them, the two
|
|
1862
|
+
* disabled cases are distinguishable: nobody opted in → the tick is a no-op and
|
|
1863
|
+
* the UI can honestly say "—"; somebody did → the cron genuinely runs, for
|
|
1864
|
+
* exactly these repos.
|
|
1865
|
+
*
|
|
1866
|
+
* CACHE-ONLY, deliberately. `GET /crons` is a list endpoint polled every 10s by
|
|
1867
|
+
* the dashboard; resolving this the way a tick does (`resolveCronRepos`, which
|
|
1868
|
+
* falls through to `fetchRepoLayer`) would turn one page load into
|
|
1869
|
+
* crons × repos conditional GitHub requests. A repo with no cached layer is
|
|
1870
|
+
* simply not counted — the display is then merely conservative (it under-reports
|
|
1871
|
+
* an opt-in until the next tick warms the cache), never wrong about a repo it
|
|
1872
|
+
* does name.
|
|
1873
|
+
*/
|
|
1874
|
+
const optedInRepos = (cron, repos, policy) => repos.filter((repo) => cronVote(cron, repoCronPrefs(getCachedRepoLayer(repo)?.config, policy)) === "enable");
|
|
1740
1875
|
// List every cron defined in workflows/cron-*.yaml, merged with the
|
|
1741
1876
|
// override row (if any) and the live scheduler state.
|
|
1742
1877
|
app.get("/crons", (c) => {
|
|
1743
1878
|
const overrides = db.getAllCronOverrides();
|
|
1744
1879
|
const liveByName = new Map((config.cronScheduler?.list() ?? []).map((j) => [j.name, j]));
|
|
1745
1880
|
const defs = getCronWorkflows();
|
|
1881
|
+
const managedRepos = getManagedRepos();
|
|
1882
|
+
// The operator's kill switch (repo-config off, or `crons` dropped from
|
|
1883
|
+
// `allowKeys`) means no repo can opt into anything — short-circuit to zero
|
|
1884
|
+
// cache lookups rather than asking each repo a question with one answer.
|
|
1885
|
+
const policy = repoConfigPolicy();
|
|
1886
|
+
const mayVote = repoLayerMayVote(policy);
|
|
1746
1887
|
const crons = defs.map((def) => {
|
|
1747
1888
|
const override = overrides.get(def.name) ?? null;
|
|
1748
1889
|
const enabled = override ? override.enabled : true;
|
|
@@ -1761,7 +1902,8 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1761
1902
|
lastRun: recent?.startedAt ?? null,
|
|
1762
1903
|
lastStatus: recent?.status ?? null,
|
|
1763
1904
|
recentFailures,
|
|
1764
|
-
|
|
1905
|
+
optedInRepos: mayVote ? optedInRepos(def.name, managedRepos, policy) : [],
|
|
1906
|
+
context: { repos: managedRepos, ...def.context },
|
|
1765
1907
|
override: override
|
|
1766
1908
|
? {
|
|
1767
1909
|
updatedAt: override.updatedAt,
|
|
@@ -1787,28 +1929,26 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1787
1929
|
const currentlyEnabled = override ? override.enabled : true;
|
|
1788
1930
|
const nextEnabled = !currentlyEnabled;
|
|
1789
1931
|
db.setCronOverride(name, { enabled: nextEnabled, updatedBy: "admin" });
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
});
|
|
1808
|
-
}
|
|
1932
|
+
// Off is "off BY DEFAULT", not "unregistered" (issue #180): a managed repo
|
|
1933
|
+
// may opt itself back into a globally-off cron from its `.lastlight/`, and
|
|
1934
|
+
// that is resolved at TICK time — so the tick has to keep running. It just
|
|
1935
|
+
// carries `_cronGloballyEnabled: false`, which narrows the fan-out to the
|
|
1936
|
+
// repos that opted in (usually none, making it a cheap no-op tick). This
|
|
1937
|
+
// mirrors `jobs.ts`, which registers a globally-off cron the same way at
|
|
1938
|
+
// boot; unregistering here instead would make an opt-in do nothing until
|
|
1939
|
+
// the next restart, and then quietly start working.
|
|
1940
|
+
const schedule = override?.schedule || def.schedule;
|
|
1941
|
+
const job = {
|
|
1942
|
+
name,
|
|
1943
|
+
schedule,
|
|
1944
|
+
workflow: def.workflow,
|
|
1945
|
+
context: cronContext(def, nextEnabled),
|
|
1946
|
+
};
|
|
1947
|
+
if (config.cronScheduler.has(name)) {
|
|
1948
|
+
config.cronScheduler.update(job);
|
|
1809
1949
|
}
|
|
1810
1950
|
else {
|
|
1811
|
-
config.cronScheduler.
|
|
1951
|
+
config.cronScheduler.register(job);
|
|
1812
1952
|
}
|
|
1813
1953
|
return c.json({ name, enabled: nextEnabled });
|
|
1814
1954
|
});
|
|
@@ -1843,7 +1983,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1843
1983
|
name,
|
|
1844
1984
|
schedule,
|
|
1845
1985
|
workflow: def.workflow,
|
|
1846
|
-
context:
|
|
1986
|
+
context: cronContext(def, true),
|
|
1847
1987
|
});
|
|
1848
1988
|
}
|
|
1849
1989
|
return c.json({ name, schedule });
|
|
@@ -1858,21 +1998,19 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1858
1998
|
if (!def)
|
|
1859
1999
|
return c.json({ error: `cron not found: ${name}` }, 404);
|
|
1860
2000
|
db.clearCronOverride(name);
|
|
2001
|
+
const job = {
|
|
2002
|
+
name,
|
|
2003
|
+
schedule: def.schedule,
|
|
2004
|
+
workflow: def.workflow,
|
|
2005
|
+
// Dropping the override returns the cron to its YAML default, which is
|
|
2006
|
+
// globally on.
|
|
2007
|
+
context: cronContext(def, true),
|
|
2008
|
+
};
|
|
1861
2009
|
if (config.cronScheduler.has(name)) {
|
|
1862
|
-
config.cronScheduler.update(
|
|
1863
|
-
name,
|
|
1864
|
-
schedule: def.schedule,
|
|
1865
|
-
workflow: def.workflow,
|
|
1866
|
-
context: { repos: getManagedRepos(), ...def.context },
|
|
1867
|
-
});
|
|
2010
|
+
config.cronScheduler.update(job);
|
|
1868
2011
|
}
|
|
1869
2012
|
else {
|
|
1870
|
-
config.cronScheduler.register(
|
|
1871
|
-
name,
|
|
1872
|
-
schedule: def.schedule,
|
|
1873
|
-
workflow: def.workflow,
|
|
1874
|
-
context: { repos: getManagedRepos(), ...def.context },
|
|
1875
|
-
});
|
|
2013
|
+
config.cronScheduler.register(job);
|
|
1876
2014
|
}
|
|
1877
2015
|
return c.json({ name, schedule: def.schedule, enabled: true });
|
|
1878
2016
|
});
|
|
@@ -1895,7 +2033,26 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1895
2033
|
// acting user (issue #205) so a manually-fired cron attributes to the
|
|
1896
2034
|
// person who clicked "Run now" rather than the anonymous scheduler.
|
|
1897
2035
|
// `dispatchWorkflow` destructures `sender` for free.
|
|
1898
|
-
|
|
2036
|
+
//
|
|
2037
|
+
// `_cronName` is carried so a manual fire honours the same per-repo
|
|
2038
|
+
// participation a scheduled tick does — a repo that opted out of this cron
|
|
2039
|
+
// in its `.lastlight/` stays out, however the tick was started. What is
|
|
2040
|
+
// deliberately NOT carried is `_cronGloballyEnabled`: absent means "on", so
|
|
2041
|
+
// "Run now" keeps working for a cron that is globally disabled, which is
|
|
2042
|
+
// exactly what the button is for.
|
|
2043
|
+
//
|
|
2044
|
+
// Which is why the YAML's own context is spread ahead of `_cronName` AND has
|
|
2045
|
+
// `_cronGloballyEnabled` stripped out of it first: here absence is the
|
|
2046
|
+
// signal, so simply re-injecting the key after the spread would defeat the
|
|
2047
|
+
// button. A cron YAML pinning `context.repos` still overrides the managed
|
|
2048
|
+
// list, as everywhere else.
|
|
2049
|
+
const { [CRON_GLOBALLY_ENABLED_KEY]: _yamlEnabled, ...defContext } = def.context ?? {};
|
|
2050
|
+
const context = {
|
|
2051
|
+
repos: getManagedRepos(),
|
|
2052
|
+
...defContext,
|
|
2053
|
+
[CRON_NAME_KEY]: def.name,
|
|
2054
|
+
sender: actorFromContext(c),
|
|
2055
|
+
};
|
|
1899
2056
|
config.triggerCron(def.workflow, context).catch((err) => {
|
|
1900
2057
|
console.error(`[admin] cron trigger ${name} failed:`, err);
|
|
1901
2058
|
});
|