lastlight-core 0.40.2 → 0.40.4

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 (62) hide show
  1. package/config/default.yaml +2 -1
  2. package/dist/admin/routes.d.ts +1 -1
  3. package/dist/admin/routes.js +36 -20
  4. package/dist/admin/routes.js.map +1 -1
  5. package/dist/config/config.d.ts +12 -0
  6. package/dist/config/config.js +14 -0
  7. package/dist/config/config.js.map +1 -1
  8. package/dist/engine/agent-executor.js +1 -0
  9. package/dist/engine/agent-executor.js.map +1 -1
  10. package/dist/engine/build-gate.js +15 -11
  11. package/dist/engine/build-gate.js.map +1 -1
  12. package/dist/engine/dispatcher.d.ts +1 -1
  13. package/dist/engine/dispatcher.js +14 -0
  14. package/dist/engine/dispatcher.js.map +1 -1
  15. package/dist/engine/router.js +4 -5
  16. package/dist/engine/router.js.map +1 -1
  17. package/dist/engine/supersede.d.ts +1 -1
  18. package/dist/engine/supersede.js +14 -0
  19. package/dist/engine/supersede.js.map +1 -1
  20. package/dist/index.js +13 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/sandbox/index.d.ts +13 -0
  23. package/dist/sandbox/index.js +77 -2
  24. package/dist/sandbox/index.js.map +1 -1
  25. package/dist/sandbox/k8s/init-clone.d.ts +9 -2
  26. package/dist/sandbox/k8s/init-clone.js +28 -7
  27. package/dist/sandbox/k8s/init-clone.js.map +1 -1
  28. package/dist/sandbox/k8s/kubernetes-sandbox.js +1 -0
  29. package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
  30. package/dist/sandbox/sandbox.d.ts +6 -0
  31. package/dist/sandbox/sandbox.js.map +1 -1
  32. package/dist/state/db.d.ts +1 -0
  33. package/dist/state/db.js +1 -0
  34. package/dist/state/db.js.map +1 -1
  35. package/dist/state/schema/pg.d.ts +17 -0
  36. package/dist/state/schema/pg.js +1 -0
  37. package/dist/state/schema/pg.js.map +1 -1
  38. package/dist/state/schema/sqlite.d.ts +19 -0
  39. package/dist/state/schema/sqlite.js +5 -0
  40. package/dist/state/schema/sqlite.js.map +1 -1
  41. package/dist/state/workflow-run-store.d.ts +52 -2
  42. package/dist/state/workflow-run-store.js +93 -17
  43. package/dist/state/workflow-run-store.js.map +1 -1
  44. package/dist/workflows/handlers/post-review.d.ts +2 -0
  45. package/dist/workflows/handlers/post-review.js +29 -0
  46. package/dist/workflows/handlers/post-review.js.map +1 -1
  47. package/dist/workflows/resume.d.ts +1 -1
  48. package/dist/workflows/resume.js +24 -1
  49. package/dist/workflows/resume.js.map +1 -1
  50. package/dist/workflows/runner.d.ts +1 -1
  51. package/dist/workflows/runner.js +6 -2
  52. package/dist/workflows/runner.js.map +1 -1
  53. package/dist/workflows/simple.d.ts +1 -1
  54. package/dist/workflows/simple.js +14 -0
  55. package/dist/workflows/simple.js.map +1 -1
  56. package/drizzle/pg/0003_needy_obadiah_stane.sql +1 -0
  57. package/drizzle/pg/meta/0003_snapshot.json +1900 -0
  58. package/drizzle/pg/meta/_journal.json +7 -0
  59. package/drizzle/sqlite/0004_adorable_puck.sql +1 -0
  60. package/drizzle/sqlite/meta/0004_snapshot.json +1732 -0
  61. package/drizzle/sqlite/meta/_journal.json +7 -0
  62. package/package.json +4 -4
@@ -914,7 +914,8 @@ routes:
914
914
  # flow). The router drops every label that is not a configured
915
915
  # `autonomy.stages.*.enter`, so this is inert until `autonomy.repos` names
916
916
  # a repo — and it is guard 1 of the four that replace the bot-sender filter
917
- # we deliberately opened for `issues.labeled`.
917
+ # we deliberately opened for `issues.labeled`. A stage's own `workflow`
918
+ # wins over this route; it is only the fallback for a stage that names none.
918
919
  issue_labeled: build
919
920
  pr_opened: pr-review
920
921
  pr_synchronize: pr-review
@@ -1,6 +1,6 @@
1
1
  import { Hono } from "hono";
2
2
  import type { SessionSource } from "./sessions.js";
3
- import type { StateDb, WorkflowRun } from "../state/db.js";
3
+ import { type StateDb, type WorkflowRun } from "../state/db.js";
4
4
  import type { CronScheduler } from "../cron/scheduler.js";
5
5
  import { type PrPolicyConfig } from "../engine/pr-decisions.js";
6
6
  import type { GitHubClient } from "../engine/github/github.js";
@@ -3,6 +3,7 @@ import { timingSafeEqual, randomBytes, randomUUID } from "node:crypto";
3
3
  import { streamSSE } from "hono/streaming";
4
4
  import { getCookie, setCookie, deleteCookie } from "hono/cookie";
5
5
  import { Slack, GitHub } from "arctic";
6
+ import { foreignEngineMessage, isOwnedRun } from "../state/db.js";
6
7
  import { tailJsonl } from "./tail.js";
7
8
  import { listRunningContainers, killContainer, getContainerStats, getHostStats, listServerContainers, resolveServerContainer, getContainerLogs, streamContainerLogs, } from "./docker.js";
8
9
  import { authMiddleware, createToken, verifyTokenForRefresh, decodeToken, actorFromContext, actorTypeFromContext } from "./auth.js";
@@ -48,11 +49,14 @@ const MAX_BOARD_REPOS = 20;
48
49
  * is a much larger thing than the button says it is — and it already exists,
49
50
  * deliberately, as `POST /api/run` for operators who want it.
50
51
  *
51
- * So the workflow is resolved from `routes.github` — the operator's own route
52
- * map — and then CHECKED to be one of these three keys' values. An operator who
53
- * repoints `issue_build` at a different workflow moves this surface with it,
54
- * which is right; an operator who never configured the stage at all gets a
55
- * refusal rather than a dispatch, which is also right.
52
+ * So the workflow is resolved from operator config — the stage's own
53
+ * `workflow` (`stageWorkflow`) — and then CHECKED to be one the operator
54
+ * already points an issue trigger at: one of these three keys' values, or a
55
+ * configured stage's workflow. `autonomy.stages` is operator-only config, so a
56
+ * stage's workflow is as much the operator's decision as a route is; leaving it
57
+ * out refused every stage that names its own workflow (issue #452). An operator
58
+ * who never configured the workflow at all still gets a refusal rather than a
59
+ * dispatch.
56
60
  */
57
61
  const ISSUE_DISPATCH_ROUTE_KEYS = ["issue_opened", "issue_labeled", "issue_build"];
58
62
  const STAGE_SLOTS = ["enter", "running", "on_success", "on_failure"];
@@ -98,7 +102,10 @@ function stageSlotForLabel(label) {
98
102
  * drifts open is a "run anything against any managed repo" hole.
99
103
  */
100
104
  function isIssueRoutableWorkflow(workflow) {
101
- const routable = new Set(ISSUE_DISPATCH_ROUTE_KEYS.map((key) => getRoutes().github?.[key]).filter(Boolean));
105
+ const routable = new Set([
106
+ ...ISSUE_DISPATCH_ROUTE_KEYS.map((key) => getRoutes().github?.[key]).filter(Boolean),
107
+ ...Object.values(getAutonomyConfig().stages).map(stageWorkflow),
108
+ ]);
102
109
  return routable.has(workflow);
103
110
  }
104
111
  import { getRuntimeConfig, getRoutes, getBotName, resolveKubernetesConfig,
@@ -107,7 +114,7 @@ import { getRuntimeConfig, getRoutes, getBotName, resolveKubernetesConfig,
107
114
  // returns a repo's UNTRUSTED `.lastlight/lastlight.yml` raw and
108
115
  // pre-validation, so a copy that drifted behind config.ts's would leak a
109
116
  // pasted credential. It must stay single-source (see config.ts).
110
- redactPublic, getAutonomyConfig, getHoldLabel, } from "../config/config.js";
117
+ redactPublic, getAutonomyConfig, stageWorkflow, getHoldLabel, } from "../config/config.js";
111
118
  import { fetchRepoLayer, refreshRepoLayer, getCachedRepoLayer, repoConfigPolicy, repoConfigBaseFromRuntime, resolveRepoConfig, } from "../config/repo-config.js";
112
119
  import { issueTriggerId } from "../engine/build-decisions.js";
113
120
  import { applyBuildDispatchGate } from "../engine/build-gate.js";
@@ -1470,6 +1477,8 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
1470
1477
  if (run.status !== "running" && run.status !== "paused" && run.status !== "queued") {
1471
1478
  return c.json({ error: `cannot cancel a run with status '${run.status}'` }, 400);
1472
1479
  }
1480
+ if (!isOwnedRun(run))
1481
+ return c.json({ error: foreignEngineMessage(run) }, 409);
1473
1482
  // Actor logging (issue #205): the canceller lands on the append-only
1474
1483
  // executions ledger (via the finish error below), never overwriting the
1475
1484
  // run's original `triggered_by`.
@@ -1599,6 +1608,8 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
1599
1608
  if (run.status !== "failed" && run.status !== "cancelled") {
1600
1609
  return c.json({ error: `cannot retry a run with status '${run.status}'` }, 400);
1601
1610
  }
1611
+ if (!isOwnedRun(run))
1612
+ return c.json({ error: foreignEngineMessage(run) }, 409);
1602
1613
  if (!config.retryWorkflow) {
1603
1614
  return c.json({ error: "retry not available (runner not wired)" }, 503);
1604
1615
  }
@@ -2353,6 +2364,10 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
2353
2364
  return c.json({ error: "approval not found" }, 404);
2354
2365
  if (approval.status !== "pending")
2355
2366
  return c.json({ error: `already ${approval.status}` }, 400);
2367
+ // Another engine's gate stays pending for that engine (KNOWN_RUN_ENGINES).
2368
+ const gatedRun = await db.runs.getRun(approval.workflowRunId);
2369
+ if (gatedRun && !isOwnedRun(gatedRun))
2370
+ return c.json({ error: foreignEngineMessage(gatedRun) }, 409);
2356
2371
  // Actor logging (issue #205): attribute the approval to the authenticated
2357
2372
  // user, falling back to `admin` for password/anonymous sessions.
2358
2373
  const actor = actorFromContext(c) ?? "admin";
@@ -2934,11 +2949,12 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
2934
2949
  if (!stageName || !stage) {
2935
2950
  return c.json({ error: `unknown stage: \`${stageName ?? ""}\` is not in \`autonomy.stages\`` }, 400);
2936
2951
  }
2952
+ const workflow = stageWorkflow(stage);
2937
2953
  // THE ALLOW-LIST. See `ISSUE_DISPATCH_ROUTE_KEYS` — the workflow has to be
2938
2954
  // one the operator's own route map already points an issue trigger at.
2939
- if (!isIssueRoutableWorkflow(stage.workflow)) {
2955
+ if (!isIssueRoutableWorkflow(workflow)) {
2940
2956
  return c.json({
2941
- error: `workflow \`${stage.workflow}\` is not reachable from an issue route ` +
2957
+ error: `workflow \`${workflow}\` is not reachable from an issue route ` +
2942
2958
  `(${ISSUE_DISPATCH_ROUTE_KEYS.join(", ")}), so the board may not dispatch it`,
2943
2959
  }, 400);
2944
2960
  }
@@ -2997,7 +3013,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
2997
3013
  outcome: "denied",
2998
3014
  detail: {
2999
3015
  stage: stageName,
3000
- workflow: stage.workflow,
3016
+ workflow,
3001
3017
  dispatched: false,
3002
3018
  reason: String(gate.reason ?? "").slice(0, 200),
3003
3019
  ...(reason ? { note: reason } : {}),
@@ -3007,7 +3023,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
3007
3023
  repo,
3008
3024
  issueNumber,
3009
3025
  stage: stageName,
3010
- workflow: stage.workflow,
3026
+ workflow,
3011
3027
  dispatched: false,
3012
3028
  // The hold is the one skip that owes a human a sentence rather than a
3013
3029
  // reason string, and it is the SAME sentence every other surface
@@ -3018,8 +3034,8 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
3018
3034
  }
3019
3035
  // Fire-and-forget, exactly like `cron trigger` and the PR retry above: a
3020
3036
  // build takes minutes and the dashboard is waiting on this response.
3021
- log.info("board dispatch", { workflow: stage.workflow, repo, issueNumber, stage: stageName, by });
3022
- config.dispatchWorkflow(stage.workflow, {
3037
+ log.info("board dispatch", { workflow, repo, issueNumber, stage: stageName, by });
3038
+ config.dispatchWorkflow(workflow, {
3023
3039
  repo,
3024
3040
  issueNumber,
3025
3041
  title: live.title,
@@ -3036,7 +3052,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
3036
3052
  sender: by,
3037
3053
  triggeredBy: by,
3038
3054
  }).catch((err) => {
3039
- log.error("board dispatch failed", { workflow: stage.workflow, repo, issueNumber, err });
3055
+ log.error("board dispatch failed", { workflow, repo, issueNumber, err });
3040
3056
  });
3041
3057
  // The freshness lever that matters. Without this the card keeps rendering
3042
3058
  // its pre-dispatch stage for up to the full TTL, so the button appears to
@@ -3048,7 +3064,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
3048
3064
  targetId,
3049
3065
  detail: {
3050
3066
  stage: stageName,
3051
- workflow: stage.workflow,
3067
+ workflow,
3052
3068
  dispatched: true,
3053
3069
  ...(reason ? { note: reason } : {}),
3054
3070
  },
@@ -3057,7 +3073,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
3057
3073
  repo,
3058
3074
  issueNumber,
3059
3075
  stage: stageName,
3060
- workflow: stage.workflow,
3076
+ workflow,
3061
3077
  dispatched: true,
3062
3078
  reason: gate.reason,
3063
3079
  });
@@ -3317,8 +3333,8 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
3317
3333
  // bills.
3318
3334
  if (labels.includes(to))
3319
3335
  return `already-in-stage: ${repo}#${issueNumber} already carries \`${to}\``;
3320
- if (!isIssueRoutableWorkflow(matchedStage.workflow)) {
3321
- return (`unroutable-workflow: \`${matchedStage.workflow}\` is not reachable from an ` +
3336
+ if (!isIssueRoutableWorkflow(stageWorkflow(matchedStage))) {
3337
+ return (`unroutable-workflow: \`${stageWorkflow(matchedStage)}\` is not reachable from an ` +
3322
3338
  `issue route (${ISSUE_DISPATCH_ROUTE_KEYS.join(", ")})`);
3323
3339
  }
3324
3340
  return undefined;
@@ -3392,7 +3408,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
3392
3408
  });
3393
3409
  }
3394
3410
  }
3395
- fireDispatch(slotMatch.stage, matchedStage.workflow, gate.gates);
3411
+ fireDispatch(slotMatch.stage, stageWorkflow(matchedStage), gate.gates);
3396
3412
  invalidateBoard(repo);
3397
3413
  await recordActivityFor(c, db, {
3398
3414
  action: "issue.stage",
@@ -3453,7 +3469,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
3453
3469
  if (!gateFirst && dispatchRefusal === undefined && slotMatch?.kind === "match" && matchedStage) {
3454
3470
  const gate = await crossGate(slotMatch.stage);
3455
3471
  if (gate.decision === "dispatch") {
3456
- fireDispatch(slotMatch.stage, matchedStage.workflow, gate.gates);
3472
+ fireDispatch(slotMatch.stage, stageWorkflow(matchedStage), gate.gates);
3457
3473
  }
3458
3474
  }
3459
3475
  // A failed REMOVE is not an error. The issue now carries BOTH labels, which