lastlight-core 0.23.7 → 0.24.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 (131) hide show
  1. package/deploy/.env.production.example +3 -1
  2. package/deploy/k8s/harness-deployment.yaml +1 -0
  3. package/deploy/native/lastlight.env.example +3 -1
  4. package/dist/admin/routes.js +54 -24
  5. package/dist/admin/routes.js.map +1 -1
  6. package/dist/admin/tail.js +3 -1
  7. package/dist/admin/tail.js.map +1 -1
  8. package/dist/config/config.d.ts +11 -2
  9. package/dist/config/config.js +17 -10
  10. package/dist/config/config.js.map +1 -1
  11. package/dist/config/repo-config.js +6 -4
  12. package/dist/config/repo-config.js.map +1 -1
  13. package/dist/connectors/github-webhook.d.ts +12 -0
  14. package/dist/connectors/github-webhook.js +59 -17
  15. package/dist/connectors/github-webhook.js.map +1 -1
  16. package/dist/connectors/index.js +5 -3
  17. package/dist/connectors/index.js.map +1 -1
  18. package/dist/connectors/messaging/base.js +7 -1
  19. package/dist/connectors/messaging/base.js.map +1 -1
  20. package/dist/connectors/messaging/delivery.d.ts +0 -4
  21. package/dist/connectors/messaging/delivery.js +5 -3
  22. package/dist/connectors/messaging/delivery.js.map +1 -1
  23. package/dist/connectors/messaging/session-manager.js +3 -1
  24. package/dist/connectors/messaging/session-manager.js.map +1 -1
  25. package/dist/connectors/slack/connector.js +24 -15
  26. package/dist/connectors/slack/connector.js.map +1 -1
  27. package/dist/cron/fanout.js +14 -4
  28. package/dist/cron/fanout.js.map +1 -1
  29. package/dist/cron/jobs.js +6 -2
  30. package/dist/cron/jobs.js.map +1 -1
  31. package/dist/cron/repo-crons.js +7 -2
  32. package/dist/cron/repo-crons.js.map +1 -1
  33. package/dist/cron/sandbox-sweep.js +3 -1
  34. package/dist/cron/sandbox-sweep.js.map +1 -1
  35. package/dist/cron/scheduler.js +11 -9
  36. package/dist/cron/scheduler.js.map +1 -1
  37. package/dist/engine/agent-executor.js +85 -36
  38. package/dist/engine/agent-executor.js.map +1 -1
  39. package/dist/engine/chat/chat-runner.js +9 -3
  40. package/dist/engine/chat/chat-runner.js.map +1 -1
  41. package/dist/engine/chat/chat.js +12 -5
  42. package/dist/engine/chat/chat.js.map +1 -1
  43. package/dist/engine/chat/message-batcher.js +3 -1
  44. package/dist/engine/chat/message-batcher.js.map +1 -1
  45. package/dist/engine/dispatcher.js +35 -26
  46. package/dist/engine/dispatcher.js.map +1 -1
  47. package/dist/engine/event-shim.js +3 -2
  48. package/dist/engine/event-shim.js.map +1 -1
  49. package/dist/engine/executors/orchestrator.js +5 -5
  50. package/dist/engine/executors/orchestrator.js.map +1 -1
  51. package/dist/engine/executors/shared.js +16 -14
  52. package/dist/engine/executors/shared.js.map +1 -1
  53. package/dist/engine/fix-harvest.js +3 -2
  54. package/dist/engine/fix-harvest.js.map +1 -1
  55. package/dist/engine/github/app-jwt.d.ts +12 -0
  56. package/dist/engine/github/app-jwt.js +25 -0
  57. package/dist/engine/github/app-jwt.js.map +1 -0
  58. package/dist/engine/github/git-auth.js +14 -19
  59. package/dist/engine/github/git-auth.js.map +1 -1
  60. package/dist/engine/github/github-app-client.js +14 -5
  61. package/dist/engine/github/github-app-client.js.map +1 -1
  62. package/dist/engine/github/github-tools.d.ts +16 -4
  63. package/dist/engine/github/github-tools.js +58 -3
  64. package/dist/engine/github/github-tools.js.map +1 -1
  65. package/dist/engine/github/github.d.ts +68 -9
  66. package/dist/engine/github/github.js +167 -42
  67. package/dist/engine/github/github.js.map +1 -1
  68. package/dist/engine/github/installations.d.ts +129 -0
  69. package/dist/engine/github/installations.js +264 -0
  70. package/dist/engine/github/installations.js.map +1 -0
  71. package/dist/engine/pr-escalation.js +42 -22
  72. package/dist/engine/pr-escalation.js.map +1 -1
  73. package/dist/engine/pr-state.js +4 -2
  74. package/dist/engine/pr-state.js.map +1 -1
  75. package/dist/engine/review-check.js +21 -16
  76. package/dist/engine/review-check.js.map +1 -1
  77. package/dist/engine/router.js +38 -15
  78. package/dist/engine/router.js.map +1 -1
  79. package/dist/engine/screen/classifier.js +7 -6
  80. package/dist/engine/screen/classifier.js.map +1 -1
  81. package/dist/engine/screen/screen.js +3 -2
  82. package/dist/engine/screen/screen.js.map +1 -1
  83. package/dist/index.js +218 -115
  84. package/dist/index.js.map +1 -1
  85. package/dist/logging/logger.d.ts +7 -0
  86. package/dist/logging/logger.js +55 -0
  87. package/dist/logging/logger.js.map +1 -0
  88. package/dist/managed-repos.d.ts +14 -7
  89. package/dist/managed-repos.js +48 -22
  90. package/dist/managed-repos.js.map +1 -1
  91. package/dist/notify/notifier.js +5 -6
  92. package/dist/notify/notifier.js.map +1 -1
  93. package/dist/sandbox/docker.js +7 -5
  94. package/dist/sandbox/docker.js.map +1 -1
  95. package/dist/sandbox/index.js +65 -32
  96. package/dist/sandbox/index.js.map +1 -1
  97. package/dist/sandbox/k8s/artifact-upload-route.js +3 -1
  98. package/dist/sandbox/k8s/artifact-upload-route.js.map +1 -1
  99. package/dist/sandbox/k8s/egress-ensurer.js +4 -3
  100. package/dist/sandbox/k8s/egress-ensurer.js.map +1 -1
  101. package/dist/sandbox/k8s/pod-lifecycle.js +4 -2
  102. package/dist/sandbox/k8s/pod-lifecycle.js.map +1 -1
  103. package/dist/sandbox/k8s/reclaim.js +14 -5
  104. package/dist/sandbox/k8s/reclaim.js.map +1 -1
  105. package/dist/sandbox/k8s/sweep.js +3 -2
  106. package/dist/sandbox/k8s/sweep.js.map +1 -1
  107. package/dist/sandbox/reap.js +5 -4
  108. package/dist/sandbox/reap.js.map +1 -1
  109. package/dist/sandbox/sandbox.js +2 -1
  110. package/dist/sandbox/sandbox.js.map +1 -1
  111. package/dist/sandbox/smol.js +12 -9
  112. package/dist/sandbox/smol.js.map +1 -1
  113. package/dist/state/workflow-run-store.js +3 -2
  114. package/dist/state/workflow-run-store.js.map +1 -1
  115. package/dist/telemetry/index.js +7 -7
  116. package/dist/telemetry/index.js.map +1 -1
  117. package/dist/workflows/admission.js +6 -8
  118. package/dist/workflows/admission.js.map +1 -1
  119. package/dist/workflows/handlers/post-review.js +5 -4
  120. package/dist/workflows/handlers/post-review.js.map +1 -1
  121. package/dist/workflows/pr-scope.js +8 -6
  122. package/dist/workflows/pr-scope.js.map +1 -1
  123. package/dist/workflows/resume.js +27 -28
  124. package/dist/workflows/resume.js.map +1 -1
  125. package/dist/workflows/runner.js +9 -8
  126. package/dist/workflows/runner.js.map +1 -1
  127. package/dist/workflows/simple.js +28 -16
  128. package/dist/workflows/simple.js.map +1 -1
  129. package/dist/worktree/manager.js +6 -4
  130. package/dist/worktree/manager.js.map +1 -1
  131. package/package.json +7 -3
@@ -25,7 +25,9 @@ LASTLIGHT_OVERLAY_DIR=/app/instance
25
25
 
26
26
  GITHUB_APP_ID=
27
27
  GITHUB_APP_PRIVATE_KEY_PATH=./app.pem
28
- GITHUB_APP_INSTALLATION_ID=
28
+ # Optional — installations are discovered from the App JWT and resolved per
29
+ # repository owner, so an App installed on several accounts needs nothing here.
30
+ # GITHUB_APP_INSTALLATION_ID=
29
31
 
30
32
  # =================================================================
31
33
  # WEBHOOK (required)
@@ -64,6 +64,7 @@ spec:
64
64
  env:
65
65
  - { name: LASTLIGHT_OVERLAY_DIR, value: /app/instance }
66
66
  - { name: STATE_DIR, value: /app/data }
67
+ - { name: LOG_LEVEL, value: info }
67
68
  resources:
68
69
  requests:
69
70
  cpu: "500m"
@@ -7,7 +7,9 @@
7
7
 
8
8
  # ── GitHub App (required) ─────────────────────────────────────────────────
9
9
  GITHUB_APP_ID=CHANGE_ME
10
- GITHUB_APP_INSTALLATION_ID=CHANGE_ME
10
+ # Optional — installations are discovered from the App JWT and resolved per
11
+ # repository owner, so an App installed on several accounts needs nothing here.
12
+ # GITHUB_APP_INSTALLATION_ID=CHANGE_ME
11
13
  # PEM is read by the harness at boot. install.sh locks down permissions if
12
14
  # you place it at /etc/lastlight/app.pem before running.
13
15
  GITHUB_APP_PRIVATE_KEY_PATH=/etc/lastlight/app.pem
@@ -17,7 +17,8 @@ import { holdReply } from "../engine/pr-decisions.js";
17
17
  import { PR_FIX_SHAPED_WORKFLOWS } from "../workflows/target-policy.js";
18
18
  import { classifyComment } from "../engine/screen/classifier.js";
19
19
  import { getWorkflowTriggers, getWorkflowTriggerKinds, } from "../workflows/triggers.js";
20
- import { getManagedRepos, getInstallationRepos, getInstallationReposRefreshedAt, isManagedRepo, } from "../managed-repos.js";
20
+ import { getManagedRepos, getInstallationRepoBreakdown, getInstallationRepos, getInstallationReposRefreshedAt, isManagedRepo, } from "../managed-repos.js";
21
+ import { getInstallationDirectory } from "../engine/github/installations.js";
21
22
  import { getRuntimeConfig, getRoutes, getBotName, resolveKubernetesConfig,
22
23
  // The redaction rule for every surface that echoes YAML back to the
23
24
  // dashboard. IMPORTED, never mirrored: `GET /repos/:owner/:repo/config`
@@ -33,6 +34,9 @@ import { makeK8sApis } from "../sandbox/k8s/client.js";
33
34
  import { RunId } from "../sandbox/k8s/run-id.js";
34
35
  import { getServerVersion } from "./version.js";
35
36
  import { BuildAssetStore, buildAssetIssueKey } from "../state/build-assets.js";
37
+ import { logger } from "../logging/logger.js";
38
+ const log = logger("admin");
39
+ const oauthLog = logger("oauth");
36
40
  /**
37
41
  * Map a build-asset filename extension to a binary MIME type, or null when the
38
42
  * file should be served as text/plain (markdown handoff docs). Binary artifacts
@@ -415,7 +419,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
415
419
  const githubCredsSet = Boolean(config.githubOAuthClientId && config.githubOAuthClientSecret);
416
420
  const githubOAuthEnabled = githubCredsSet && Boolean(config.githubAllowedOrg);
417
421
  if (githubCredsSet && !config.githubAllowedOrg) {
418
- console.error("[oauth] GitHub OAuth client id/secret are set but GITHUB_ALLOWED_ORG is empty. " +
422
+ oauthLog.error("GitHub OAuth client id/secret are set but GITHUB_ALLOWED_ORG is empty. " +
419
423
  "Set it to a GitHub org slug to restrict login to that org, or to \"*\" to " +
420
424
  "explicitly allow any GitHub user. GitHub OAuth is disabled until this is set.");
421
425
  }
@@ -435,12 +439,34 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
435
439
  app.get("/managed-repos", (c) => {
436
440
  const configured = getRuntimeConfig()?.managedRepos ?? [];
437
441
  const effective = getManagedRepos();
442
+ // Every ACCOUNT the App is installed on, with its repo grant. A GitHub App
443
+ // is installed per account and each installation mints its own tokens, so a
444
+ // `managedRepos` entry whose owner has no installation cannot be acted on —
445
+ // `uninstalledOwners` names them here, where an operator can see it, rather
446
+ // than letting it surface as a 422 mid-run.
447
+ const repoCounts = new Map(getInstallationRepoBreakdown().map((g) => [g.installationId, g.repos.length]));
448
+ const installations = getInstallationDirectory()?.list() ?? [];
449
+ const installedOwners = new Set(installations.map((i) => i.account.toLowerCase()));
450
+ const uninstalledOwners = [
451
+ ...new Set(effective
452
+ .map((r) => r.split("/")[0] ?? "")
453
+ .filter((owner) => owner && !installedOwners.has(owner.toLowerCase()))),
454
+ ];
438
455
  return c.json({
439
456
  configured,
440
457
  installation: getInstallationRepos(),
441
458
  effective,
442
459
  source: configured.length > 0 ? "config" : "installation",
443
460
  refreshedAt: getInstallationReposRefreshedAt(),
461
+ installations: installations.map((i) => ({
462
+ id: i.id,
463
+ account: i.account,
464
+ accountType: i.accountType,
465
+ repositorySelection: i.repositorySelection,
466
+ suspended: i.suspended,
467
+ repoCount: repoCounts.get(i.id) ?? 0,
468
+ })),
469
+ uninstalledOwners,
444
470
  // Which of the effective repos have committed a `.lastlight/` layer.
445
471
  // Read from the in-memory cache ONLY (`getCachedRepoLayer`) so this stays
446
472
  // a cheap no-network list route — a repo not yet fetched simply reports
@@ -682,7 +708,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
682
708
  });
683
709
  const userInfo = (await res.json());
684
710
  if (userInfo.ok === false) {
685
- console.error("Slack openid.connect.userInfo failed:", userInfo.error);
711
+ oauthLog.error("Slack openid.connect.userInfo failed", { error: userInfo.error });
686
712
  return c.json({ error: "Slack userInfo failed" }, 502);
687
713
  }
688
714
  const teamId = userInfo["https://slack.com/team_id"];
@@ -693,7 +719,10 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
693
719
  const matchesId = teamId === allowed;
694
720
  const matchesDomain = teamDomain === allowed;
695
721
  if (!matchesId && !matchesDomain) {
696
- console.warn(`[oauth] Slack login rejected: workspace ${teamDomain ?? teamId ?? "unknown"} not in allowlist (${allowed})`);
722
+ oauthLog.warn("Slack login rejected: workspace not in allowlist", {
723
+ workspace: teamDomain ?? teamId ?? "unknown",
724
+ allowed,
725
+ });
697
726
  return c.json({ error: "workspace not allowed" }, 403);
698
727
  }
699
728
  }
@@ -714,8 +743,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
714
743
  matchedLogin = user.login;
715
744
  }
716
745
  catch (err) {
717
- const msg = err instanceof Error ? err.message : String(err);
718
- console.warn(`[oauth] failed to persist Slack user ${slackUserId}: ${msg}`);
746
+ oauthLog.warn("Failed to persist Slack user", { slackUserId, err });
719
747
  }
720
748
  }
721
749
  const token = createToken(config.adminSecret, "slack", matchedLogin);
@@ -725,7 +753,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
725
753
  return c.redirect(`/admin/?token=${encodeURIComponent(token)}`);
726
754
  }
727
755
  catch (err) {
728
- console.error("OAuth exchange failed:", err);
756
+ oauthLog.error("Slack OAuth exchange failed", { err });
729
757
  return c.json({ error: "OAuth exchange failed" }, 502);
730
758
  }
731
759
  });
@@ -796,14 +824,18 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
796
824
  memberStatus = memberRes.status;
797
825
  }
798
826
  if (!userInfo.login) {
799
- console.error("GitHub /user failed: missing login field");
827
+ oauthLog.error("GitHub /user failed: missing login field");
800
828
  return fail("github_userinfo");
801
829
  }
802
830
  const login = userInfo.login;
803
831
  // Only 204 No Content means confirmed member. 302 means caller lacks
804
832
  // read:org visibility; 404 means not a member. Both cases are rejected.
805
833
  if (!githubAllowAnyUser && memberStatus !== 204) {
806
- console.warn(`[oauth] GitHub login rejected: ${login} not a confirmed member of ${config.githubAllowedOrg} (status ${memberStatus})`);
834
+ oauthLog.warn("GitHub login rejected: not a confirmed org member", {
835
+ login,
836
+ org: config.githubAllowedOrg,
837
+ memberStatus,
838
+ });
807
839
  return fail("github_org");
808
840
  }
809
841
  // Capture a first-class user identity (issue #205). A public GitHub
@@ -828,8 +860,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
828
860
  }
829
861
  }
830
862
  catch (err) {
831
- const msg = err instanceof Error ? err.message : String(err);
832
- console.warn(`[oauth] GitHub /user/emails lookup failed for ${login}: ${msg}`);
863
+ oauthLog.warn("GitHub /user/emails lookup failed", { login, err });
833
864
  }
834
865
  }
835
866
  if (typeof userInfo.id === "number") {
@@ -844,8 +875,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
844
875
  }
845
876
  catch (err) {
846
877
  // Identity capture is best-effort — never block a valid login on it.
847
- const msg = err instanceof Error ? err.message : String(err);
848
- console.warn(`[oauth] failed to persist user ${login}: ${msg}`);
878
+ oauthLog.warn("Failed to persist user", { login, err });
849
879
  }
850
880
  }
851
881
  // Carry the verified login in the token so actor-hardcoded routes
@@ -854,7 +884,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
854
884
  return c.redirect(`/admin/?token=${encodeURIComponent(token)}`);
855
885
  }
856
886
  catch (err) {
857
- console.error("GitHub OAuth exchange failed:", err);
887
+ oauthLog.error("GitHub OAuth exchange failed", { err });
858
888
  return fail("oauth_exchange");
859
889
  }
860
890
  });
@@ -1183,7 +1213,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
1183
1213
  killed.push(ctr.name);
1184
1214
  }
1185
1215
  catch (err) {
1186
- console.warn(`[cancel] failed to kill ${ctr.name}:`, err);
1216
+ log.warn("Cancel: failed to kill container", { container: ctr.name, err });
1187
1217
  }
1188
1218
  }));
1189
1219
  // Mark execution rows belonging to THIS cancelled run as failed.
@@ -1198,7 +1228,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
1198
1228
  }
1199
1229
  }
1200
1230
  catch (err) {
1201
- console.warn(`[cancel] container enumeration failed:`, err);
1231
+ log.warn("Cancel: container enumeration failed", { err });
1202
1232
  }
1203
1233
  }
1204
1234
  // Reap the workspace too (issue #106) — the kills above stop the in-flight
@@ -1227,7 +1257,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
1227
1257
  });
1228
1258
  }
1229
1259
  catch (err) {
1230
- console.warn(`[cancel] k8s reclaim failed for run ${run.id}:`, err);
1260
+ log.warn("Cancel: k8s reclaim failed", { runId: run.id, err });
1231
1261
  }
1232
1262
  // The pod's uploaded `.lastlight/` artifacts live host-side under
1233
1263
  // `<sandboxDir>/<taskId>` even on k8s (the artifact store is host-local
@@ -1241,7 +1271,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
1241
1271
  await artifactStore.gc(storedTaskId);
1242
1272
  }
1243
1273
  catch (err) {
1244
- console.warn(`[cancel] artifact gc failed for ${storedTaskId}:`, err);
1274
+ log.warn("Cancel: artifact gc failed", { taskId: storedTaskId, err });
1245
1275
  }
1246
1276
  }
1247
1277
  else {
@@ -1261,7 +1291,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
1261
1291
  await artifactStore.gc(storedTaskId);
1262
1292
  }
1263
1293
  catch (err) {
1264
- console.warn(`[cancel] artifact gc failed for ${storedTaskId}:`, err);
1294
+ log.warn("Cancel: artifact gc failed", { taskId: storedTaskId, err });
1265
1295
  }
1266
1296
  }
1267
1297
  }
@@ -1287,7 +1317,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
1287
1317
  }
1288
1318
  // Fire-and-forget: restartRun (inside the callback) flips status→running
1289
1319
  // atomically, so a second immediate retry click 400s on the status guard.
1290
- config.retryWorkflow(run, actorFromContext(c) ?? "admin").catch((err) => console.error(`[admin] retry ${id} failed:`, err));
1320
+ config.retryWorkflow(run, actorFromContext(c) ?? "admin").catch((err) => log.error("Retry failed", { id, err }));
1291
1321
  return c.json({ retrying: id });
1292
1322
  });
1293
1323
  // ── Workflow definitions ─────────────────────────────────────────
@@ -1824,7 +1854,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
1824
1854
  const workflowRun = db.runs.getRun(approval.workflowRunId);
1825
1855
  if (workflowRun && config.resumeWorkflow) {
1826
1856
  config.resumeWorkflow(workflowRun, actor).catch((err) => {
1827
- console.error(`[admin] Failed to resume workflow ${workflowRun.id}:`, err);
1857
+ log.error("Failed to resume workflow", { workflowRunId: workflowRun.id, err });
1828
1858
  });
1829
1859
  }
1830
1860
  }
@@ -2058,7 +2088,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
2058
2088
  sender: actorFromContext(c),
2059
2089
  };
2060
2090
  config.triggerCron(def.workflow, context).catch((err) => {
2061
- console.error(`[admin] cron trigger ${name} failed:`, err);
2091
+ log.error("Cron trigger failed", { name, err });
2062
2092
  });
2063
2093
  return c.json({ name, workflow: def.workflow, triggered: true });
2064
2094
  });
@@ -2174,7 +2204,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
2174
2204
  // takes minutes. `_prState` carries the armed snapshot down so the run
2175
2205
  // persists the intervention on its own `context.prState` — which is where
2176
2206
  // the record normally lives, and why no standalone row is written here.
2177
- console.log(`[admin] retry ${workflowName} ${repo}#${prNumber} by ${by} — ${disposition.reason}`);
2207
+ log.info("retry", { workflow: workflowName, repo, prNumber, by, reason: disposition.reason });
2178
2208
  config.dispatchWorkflow(workflowName, {
2179
2209
  ...context,
2180
2210
  body: state.body,
@@ -2182,7 +2212,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
2182
2212
  sender: by,
2183
2213
  triggeredBy: by,
2184
2214
  }).catch((err) => {
2185
- console.error(`[admin] retry ${workflowName} ${repo}#${prNumber} failed:`, err);
2215
+ log.error("retry failed", { workflow: workflowName, repo, prNumber, err });
2186
2216
  });
2187
2217
  return c.json({
2188
2218
  repo,