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.
Files changed (124) hide show
  1. package/config/default.yaml +119 -1
  2. package/dist/admin/routes.js +195 -38
  3. package/dist/admin/routes.js.map +1 -1
  4. package/dist/config/config-resolve.d.ts +38 -1
  5. package/dist/config/config-resolve.js +41 -17
  6. package/dist/config/config-resolve.js.map +1 -1
  7. package/dist/config/config.d.ts +114 -0
  8. package/dist/config/config.js +225 -7
  9. package/dist/config/config.js.map +1 -1
  10. package/dist/config/repo-config.d.ts +120 -0
  11. package/dist/config/repo-config.js +447 -0
  12. package/dist/config/repo-config.js.map +1 -0
  13. package/dist/connectors/github-webhook.d.ts +17 -0
  14. package/dist/connectors/github-webhook.js +150 -17
  15. package/dist/connectors/github-webhook.js.map +1 -1
  16. package/dist/connectors/types.d.ts +48 -1
  17. package/dist/cron/dependabot-discovery.d.ts +68 -11
  18. package/dist/cron/dependabot-discovery.js +78 -20
  19. package/dist/cron/dependabot-discovery.js.map +1 -1
  20. package/dist/cron/fanout.d.ts +10 -0
  21. package/dist/cron/fanout.js +35 -2
  22. package/dist/cron/fanout.js.map +1 -1
  23. package/dist/cron/jobs.d.ts +16 -2
  24. package/dist/cron/jobs.js +69 -9
  25. package/dist/cron/jobs.js.map +1 -1
  26. package/dist/cron/repo-crons.d.ts +110 -0
  27. package/dist/cron/repo-crons.js +169 -0
  28. package/dist/cron/repo-crons.js.map +1 -0
  29. package/dist/cron/review-discovery.d.ts +33 -20
  30. package/dist/cron/review-discovery.js +23 -30
  31. package/dist/cron/review-discovery.js.map +1 -1
  32. package/dist/engine/agent-executor.d.ts +1 -1
  33. package/dist/engine/agent-executor.js +1 -1
  34. package/dist/engine/agent-executor.js.map +1 -1
  35. package/dist/engine/dispatcher.d.ts +98 -1
  36. package/dist/engine/dispatcher.js +248 -231
  37. package/dist/engine/dispatcher.js.map +1 -1
  38. package/dist/engine/executors/orchestrator.js +39 -15
  39. package/dist/engine/executors/orchestrator.js.map +1 -1
  40. package/dist/engine/executors/shared.d.ts +43 -0
  41. package/dist/engine/executors/shared.js +65 -0
  42. package/dist/engine/executors/shared.js.map +1 -1
  43. package/dist/engine/fix-harvest.d.ts +169 -0
  44. package/dist/engine/fix-harvest.js +345 -0
  45. package/dist/engine/fix-harvest.js.map +1 -0
  46. package/dist/engine/fix-markers.d.ts +184 -0
  47. package/dist/engine/fix-markers.js +329 -0
  48. package/dist/engine/fix-markers.js.map +1 -0
  49. package/dist/engine/fix-scratch.d.ts +76 -0
  50. package/dist/engine/fix-scratch.js +77 -0
  51. package/dist/engine/fix-scratch.js.map +1 -0
  52. package/dist/engine/github/github.d.ts +302 -5
  53. package/dist/engine/github/github.js +614 -54
  54. package/dist/engine/github/github.js.map +1 -1
  55. package/dist/engine/github/profiles.d.ts +45 -1
  56. package/dist/engine/github/profiles.js +35 -0
  57. package/dist/engine/github/profiles.js.map +1 -1
  58. package/dist/engine/pr-decisions.d.ts +342 -0
  59. package/dist/engine/pr-decisions.js +721 -0
  60. package/dist/engine/pr-decisions.js.map +1 -0
  61. package/dist/engine/pr-escalation.d.ts +152 -0
  62. package/dist/engine/pr-escalation.js +320 -0
  63. package/dist/engine/pr-escalation.js.map +1 -0
  64. package/dist/engine/pr-notes.d.ts +175 -0
  65. package/dist/engine/pr-notes.js +315 -0
  66. package/dist/engine/pr-notes.js.map +1 -0
  67. package/dist/engine/pr-state.d.ts +313 -0
  68. package/dist/engine/pr-state.js +515 -0
  69. package/dist/engine/pr-state.js.map +1 -0
  70. package/dist/engine/review-check.d.ts +200 -0
  71. package/dist/engine/review-check.js +305 -0
  72. package/dist/engine/review-check.js.map +1 -0
  73. package/dist/engine/router.d.ts +27 -0
  74. package/dist/engine/router.js +156 -22
  75. package/dist/engine/router.js.map +1 -1
  76. package/dist/evals-api.d.ts +10 -0
  77. package/dist/evals-api.js +38 -0
  78. package/dist/evals-api.js.map +1 -1
  79. package/dist/index.js +313 -23
  80. package/dist/index.js.map +1 -1
  81. package/dist/sandbox/index.d.ts +13 -0
  82. package/dist/sandbox/index.js +30 -0
  83. package/dist/sandbox/index.js.map +1 -1
  84. package/dist/sandbox/k8s/init-clone.d.ts +5 -0
  85. package/dist/sandbox/k8s/init-clone.js +27 -0
  86. package/dist/sandbox/k8s/init-clone.js.map +1 -1
  87. package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +26 -1
  88. package/dist/sandbox/k8s/kubernetes-sandbox.js +30 -1
  89. package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
  90. package/dist/state/execution-store.d.ts +27 -0
  91. package/dist/state/execution-store.js +45 -0
  92. package/dist/state/execution-store.js.map +1 -1
  93. package/dist/state/workflow-run-store.d.ts +73 -0
  94. package/dist/state/workflow-run-store.js +106 -24
  95. package/dist/state/workflow-run-store.js.map +1 -1
  96. package/dist/workflows/pr-scope.d.ts +63 -0
  97. package/dist/workflows/pr-scope.js +113 -0
  98. package/dist/workflows/pr-scope.js.map +1 -0
  99. package/dist/workflows/resume.js +113 -8
  100. package/dist/workflows/resume.js.map +1 -1
  101. package/dist/workflows/runner.d.ts +2 -1
  102. package/dist/workflows/runner.js +143 -10
  103. package/dist/workflows/runner.js.map +1 -1
  104. package/dist/workflows/simple.d.ts +280 -1
  105. package/dist/workflows/simple.js +499 -8
  106. package/dist/workflows/simple.js.map +1 -1
  107. package/dist/workflows/target-policy.d.ts +0 -12
  108. package/dist/workflows/target-policy.js +9 -15
  109. package/dist/workflows/target-policy.js.map +1 -1
  110. package/package.json +4 -4
  111. package/skills/README.md +11 -5
  112. package/skills/dependency-impact/SKILL.md +83 -0
  113. package/skills/fixing/SKILL.md +190 -0
  114. package/skills/pr-review/SKILL.md +26 -9
  115. package/workflows/cron-dependabot-ci-fix.yaml +8 -5
  116. package/workflows/cron-review.yaml +14 -5
  117. package/workflows/dependabot-ci-fix.yaml +86 -2
  118. package/workflows/dependabot-pr-merge.yaml +13 -1
  119. package/workflows/pr-fix.yaml +84 -1
  120. package/workflows/pr-review.yaml +7 -0
  121. package/workflows/prompts/dependabot-ci-fix.md +70 -17
  122. package/workflows/prompts/dependabot-pr-merge.md +203 -80
  123. package/workflows/prompts/diagnose-ci.md +96 -0
  124. package/workflows/prompts/pr-fix.md +63 -4
@@ -22,9 +22,19 @@ models:
22
22
  # architect: anthropic/claude-opus-4-8
23
23
  # classifier: anthropic/claude-haiku-4-5-20251001 # the intent-routing helper
24
24
  # screener: anthropic/claude-haiku-4-5-20251001 # the prompt-injection screener
25
+ # diagnose: anthropic/claude-haiku-4-5-20251001 # the CI-failure classifier
26
+ # pr-fix-retry: anthropic/claude-opus-4-8 # used above fix.escalateModelAfterAttempt
25
27
  # A per-task entry wins over `default`. `classifier`/`screener` are the cheap
26
28
  # one-shot helpers (src/engine/llm.ts); when unset they fall back to the first
27
29
  # configured provider's fast model, NOT `default`.
30
+ #
31
+ # `diagnose` is worth pinning. It is the first phase of both fix workflows and
32
+ # it only reads logs and reproduces a command — it writes no code — so a cheap
33
+ # model is the point of splitting it out from `fix` at all. Left UNSET here
34
+ # because these examples name Anthropic models and a deployment that overrides
35
+ # only `default` to another provider would otherwise find this phase reaching
36
+ # for a provider it has no key for. Unset, it falls through to `default`, so
37
+ # each fix run costs one extra call at the default model until you pin it.
28
38
 
29
39
  variants: {}
30
40
 
@@ -87,6 +97,33 @@ deploy:
87
97
 
88
98
  approval: {}
89
99
 
100
+ # Per-repository configuration (issue #180). A managed repo may commit a
101
+ # `.lastlight/` directory — mirroring the instance overlay's on-disk shape
102
+ # (`lastlight.yml`, `workflows/prompts/*.md`, `skills/<name>/SKILL.md`,
103
+ # `agent-context/*.md`) — that overrides a BOUNDED subset of this config for
104
+ # runs against that repo. Precedence: default -> overlay -> env -> repo.
105
+ #
106
+ # The block below is the OPERATOR's bounds on that layer; a repo can never widen
107
+ # them. It is inert out of the box: nothing changes for an existing deployment
108
+ # until a repo actually commits `.lastlight/lastlight.yml`.
109
+ #
110
+ # SECURITY: the repo layer is ALWAYS read from the repo's DEFAULT BRANCH, never
111
+ # a PR head and never the sandbox checkout — otherwise a PR could rewrite the
112
+ # configuration of the agent reviewing it. See src/config/repo-config.ts.
113
+ repoConfig:
114
+ enabled: true # master switch; false ignores every repo's .lastlight/
115
+ # Config keys a repo may set, as dotted paths. Anything outside this list is
116
+ # dropped with a warning (the run still proceeds — a repo's config file can
117
+ # never fail a run). Narrow it to tighten the blast radius. Removing `crons`
118
+ # makes the operator's `crons:` block below un-overridable — the kill switch.
119
+ # `fix` / `dependencies` / `review` are clamped one-way (see those blocks): a
120
+ # repo can only ever be MORE conservative than the values set here.
121
+ allowKeys: [models, variants, crons, disabled.workflows, disabled.crons, approval,
122
+ fix, dependencies, review]
123
+ allowedModels: null # null = any model whose provider prefix is configured;
124
+ # a list restricts repos to exactly those model specs
125
+ allowAssets: true # allow the repo's prompt/skill/agent-context overrides
126
+
90
127
  bootstrap:
91
128
  label: "lastlight:bootstrap"
92
129
 
@@ -94,10 +131,83 @@ explore:
94
131
  defaultRepo: null
95
132
 
96
133
  review:
97
- postsCheck: false
134
+ postsCheck: false # post the `last-light/review` Check Run
135
+ # When a pr-review run is triggered:
136
+ # eager — on pr.opened / synchronize / reopened, in parallel with CI
137
+ # after-checks — once the head SHA's checks SETTLE, either colour (default:
138
+ # the review can then read and cite the CI result, and a
139
+ # push-storm collapses to one review per settled SHA)
140
+ # on-request — never automatically; only when explicitly asked for
141
+ trigger: after-checks
142
+ requestLabel: null # label that requests a review in `on-request` mode
143
+ skipDraft: true # skip draft PRs (what the review cron has always done)
144
+
145
+ # Retry policy for every PR_FIX_SHAPED workflow — pr-fix and dependabot-ci-fix
146
+ # (issue #251). The loop diagnoses a CI failure before it retries, and these are
147
+ # the budgets that bound it.
148
+ #
149
+ # Repo-settable (a repo may commit its own values in `.lastlight/lastlight.yml`),
150
+ # clamped ONE WAY — a repo can only ever be MORE conservative than this block:
151
+ # maxAttempts / localIterations / maxFlakyDeferrals min(repo, operator)
152
+ # maxCostUsd min, `null` = unbounded
153
+ # retryableClasses a subset of this list
154
+ # `escalateModelAfterAttempt` (spend) and `gateTimeoutSeconds` (shared resource)
155
+ # are OPERATOR-ONLY — a repo setting them is dropped with a warning.
156
+ fix:
157
+ maxAttempts: 3 # cross-run attempts per (repo, PR) before requires-human
158
+ localIterations: 2 # within-run gate-loop iterations inside ONE attempt
159
+ gateTimeoutSeconds: 900 # until_bash budget for the repo's build/test gate
160
+ escalateModelAfterAttempt: 1 # attempts above this use models["pr-fix-retry"] when set
161
+ maxCostUsd: 5.0 # cumulative ceiling across attempts for one PR; null = off
162
+ maxFlakyDeferrals: 2 # a `flaky` verdict defers this often, then counts as reproducible
163
+ # Diagnosis classes another attempt can help with; every other class escalates
164
+ # immediately instead of burning budget. The vocabulary is
165
+ # reproducible | env-mismatch | flaky | infra-dependent | upstream-broken.
166
+ retryableClasses: [reproducible, env-mismatch]
167
+
168
+ # How dependency PRs are merged (issue #252). Impact — not semver magnitude — is
169
+ # what gates a MAJOR bump: a @types/* major is not a framework rewrite.
170
+ #
171
+ # Repo-settable and clamped one way, as above:
172
+ # autoMergeMaxImpact the LOWER tier on none < low < medium < high
173
+ # requireSettledChecks add-only `true` (a `false` is dropped with a warning)
174
+ # auditComment free — cosmetic
175
+ # `minSettledChecks` is OPERATOR-ONLY: clamping it `max(repo, operator)` would
176
+ # weld the escape hatch shut for a repo with no CI at all.
177
+ dependencies:
178
+ autoMergeMaxImpact: medium # none | low | medium | high — ceiling for auto-merging a MAJOR
179
+ requireSettledChecks: true # enforce settled-"passing" on ALL routes (webhook, cron, comment)
180
+ minSettledChecks: 1 # an auto-merge decision needs >= N settled checks; 0 = legacy behaviour
181
+ auditComment: true # post the evidence comment when auto-merging a major
182
+
183
+ # Which crons participate (issue #180). The SAME block is valid here, in your
184
+ # overlay's config.yaml, and in a managed repo's .lastlight/lastlight.yml — the
185
+ # meaning depends on the layer:
186
+ #
187
+ # operator (here / overlay) disable: [x] → cron x is off globally
188
+ # enable: [x] → no-op; a cron is on by default
189
+ # repo (.lastlight/) disable: [x] → THIS repo drops out of x's fan-out
190
+ # enable: [x] → THIS repo opts in even when x is
191
+ # off globally
192
+ #
193
+ # A name in BOTH lists is disabled, at every layer — a cron that doesn't run is
194
+ # the safe reading of a contradictory config.
195
+ #
196
+ # `disabled.crons` below is the LEGACY spelling of `crons.disable` and still
197
+ # works exactly as before: it is unioned into this list (and additionally drops
198
+ # the cron's definition at asset-load time, so it is the harder kill).
199
+ #
200
+ # NOTE: `crons.disable` here means "off BY DEFAULT" — a repo listed in
201
+ # `repoConfig.allowKeys` can still opt itself back in. If you want a kill switch
202
+ # no repo can override, drop `crons` from repoConfig.allowKeys (below); that
203
+ # leaves this list as the only word on the subject.
204
+ crons:
205
+ enable: []
206
+ disable: []
98
207
 
99
208
  disabled:
100
209
  workflows: []
210
+ # Legacy alias for `crons.disable` above — kept working, not deprecated.
101
211
  crons: []
102
212
  prompts: []
103
213
  skills: []
@@ -111,6 +221,14 @@ routes:
111
221
  pr_opened: pr-review
112
222
  pr_synchronize: pr-review
113
223
  pr_reopened: pr-review
224
+ # `review.trigger: after-checks` — the head SHA's checks have settled on a
225
+ # PR that neither the fix nor the merge route claimed.
226
+ pr_checks_settled: pr-review
227
+ # `review.requestLabel` was applied (the `on-request` mechanism).
228
+ pr_labeled: pr-review
229
+ # A review was requested from the bot by name, or the `last-light/review`
230
+ # check's Re-run button was pressed.
231
+ pr_review_requested: pr-review
114
232
  approval_response: approval-response
115
233
  security_review: security-review
116
234
  verify: verify
@@ -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, } from "../config/config.js";
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: getManagedRepos(),
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
- context: { repos: getManagedRepos(), ...def.context },
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
- if (nextEnabled) {
1791
- // Re-register with the (possibly overridden) schedule
1792
- const schedule = override?.schedule || def.schedule;
1793
- if (config.cronScheduler.has(name)) {
1794
- config.cronScheduler.update({
1795
- name,
1796
- schedule,
1797
- workflow: def.workflow,
1798
- context: { repos: getManagedRepos(), ...def.context },
1799
- });
1800
- }
1801
- else {
1802
- config.cronScheduler.register({
1803
- name,
1804
- schedule,
1805
- workflow: def.workflow,
1806
- context: { repos: getManagedRepos(), ...def.context },
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.unregister(name);
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: { repos: getManagedRepos(), ...def.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
- const context = { repos: getManagedRepos(), sender: actorFromContext(c), ...def.context };
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
  });