lastlight-core 0.21.7 → 0.21.9
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 +19 -2
- package/deploy/k8s/README.md +61 -0
- package/deploy/k8s/configmap.yaml +13 -0
- package/deploy/k8s/deployment.yaml +63 -0
- package/deploy/k8s/generic-device-plugin.yaml +63 -0
- package/deploy/k8s/kustomization.yaml +12 -0
- package/deploy/k8s/namespace.yaml +10 -0
- package/deploy/k8s/pvc.yaml +13 -0
- package/deploy/k8s/service.yaml +12 -0
- package/dist/admin/routes.js +218 -4
- package/dist/admin/routes.js.map +1 -1
- package/dist/config/config.d.ts +23 -0
- package/dist/config/config.js +19 -2
- package/dist/config/config.js.map +1 -1
- package/dist/cron/sandbox-sweep.d.ts +30 -0
- package/dist/cron/sandbox-sweep.js +59 -0
- package/dist/cron/sandbox-sweep.js.map +1 -0
- package/dist/engine/agent-executor.js +1 -0
- package/dist/engine/agent-executor.js.map +1 -1
- package/dist/engine/dispatcher.js +4 -5
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/github/github.d.ts +12 -0
- package/dist/engine/github/github.js +105 -45
- package/dist/engine/github/github.js.map +1 -1
- package/dist/engine/router.js +2 -2
- package/dist/engine/router.js.map +1 -1
- package/dist/engine/screen/classifier.d.ts +10 -0
- package/dist/engine/screen/classifier.js +38 -7
- package/dist/engine/screen/classifier.js.map +1 -1
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +14 -0
- package/dist/sandbox/index.js +66 -0
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/reap.d.ts +49 -0
- package/dist/sandbox/reap.js +74 -0
- package/dist/sandbox/reap.js.map +1 -0
- package/dist/workflows/handlers/post-review.d.ts +1 -0
- package/dist/workflows/handlers/post-review.js +56 -28
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/runner.d.ts +1 -1
- package/dist/workflows/runner.js +7 -2
- package/dist/workflows/runner.js.map +1 -1
- package/dist/workflows/simple.d.ts +10 -0
- package/dist/workflows/simple.js +30 -1
- package/dist/workflows/simple.js.map +1 -1
- package/dist/workflows/triggers.js +1 -2
- package/dist/workflows/triggers.js.map +1 -1
- package/package.json +4 -4
- package/skills/building/SKILL.md +35 -8
- package/workflows/prompts/dependabot-ci-fix.md +16 -3
- package/workflows/prompts/executor.md +2 -2
- package/workflows/prompts/fix.md +2 -2
- package/workflows/prompts/pr-fix.md +1 -1
package/config/default.yaml
CHANGED
|
@@ -59,6 +59,23 @@ concurrency:
|
|
|
59
59
|
maxWorkflows: 4 # env override: MAX_CONCURRENT_WORKFLOWS
|
|
60
60
|
maxQueueWaitMs: 3600000 # 1 hr; env override: MAX_QUEUE_WAIT_MS
|
|
61
61
|
|
|
62
|
+
# Sandbox-workspace reaping (issue #106). Every task clones the target repo into
|
|
63
|
+
# $STATE_DIR/sandboxes/<taskId>/; the harness now owns cleanup of those clones so
|
|
64
|
+
# the disk stays bounded under cron-review churn (this replaces the out-of-band
|
|
65
|
+
# host cron). `reapOnCompletion` deletes an ephemeral run's workspace the moment
|
|
66
|
+
# it finishes successfully; reusable per-PR workspaces (pr-review/pr-fix/build)
|
|
67
|
+
# are kept as a warm cache and bounded only by the sweep below. The sweep is the
|
|
68
|
+
# backstop for failed/crashed leftovers: it removes non-live dirs older than
|
|
69
|
+
# retentionHours and, if more than maxDirs remain, evicts the oldest (LRU). A dir
|
|
70
|
+
# whose sandbox container is still running is never removed.
|
|
71
|
+
cleanup:
|
|
72
|
+
sandbox:
|
|
73
|
+
enabled: true # master switch for the TTL/LRU sweep
|
|
74
|
+
reapOnCompletion: true # reap ephemeral workspaces on terminal success
|
|
75
|
+
sweepSchedule: "0 * * * *" # hourly
|
|
76
|
+
retentionHours: 12 # sweep dirs older than this
|
|
77
|
+
maxDirs: 40 # LRU cap on total workspace dirs
|
|
78
|
+
|
|
62
79
|
# Pin which core version an instance runs. Set `deploy.version` to a git tag/ref
|
|
63
80
|
# (e.g. v0.10.6) in your private overlay's config.yaml — `lastlight server
|
|
64
81
|
# update|setup` then checks core out at that tag and rebuilds, instead of
|
|
@@ -102,7 +119,7 @@ routes:
|
|
|
102
119
|
pr_fix: pr-fix
|
|
103
120
|
pr_review: pr-review
|
|
104
121
|
pr_comment: pr-comment
|
|
105
|
-
issue_build:
|
|
122
|
+
issue_build: build
|
|
106
123
|
issue_explore: explore
|
|
107
124
|
issue_comment: issue-comment
|
|
108
125
|
security_feedback: security-feedback
|
|
@@ -112,7 +129,7 @@ routes:
|
|
|
112
129
|
status: status-report
|
|
113
130
|
approve: approval-response
|
|
114
131
|
reject: approval-response
|
|
115
|
-
build:
|
|
132
|
+
build: build
|
|
116
133
|
triage: issue-triage
|
|
117
134
|
review: pr-review
|
|
118
135
|
security: security-review
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Running Last Light on Kubernetes (gondolin backend)
|
|
2
|
+
|
|
3
|
+
A complete, `kubectl apply -k`-able example for the **default gondolin** sandbox
|
|
4
|
+
backend, which runs each workflow phase in a QEMU micro-VM. It uses the
|
|
5
|
+
`lastlight-agent-qemu` image (the base `lastlight-agent` image ships no QEMU).
|
|
6
|
+
|
|
7
|
+
## Cluster prerequisites
|
|
8
|
+
|
|
9
|
+
- Nodes with **`/dev/kvm`** present — bare metal, or a VM/cloud instance with
|
|
10
|
+
nested virtualization enabled — and the `kvm` kernel module active. Most
|
|
11
|
+
managed shared-CPU hosts (Cloud Run, Fly shared VMs) do **not** qualify.
|
|
12
|
+
- A block/local StorageClass (not NFS) so the embedded SQLite DB locks safely.
|
|
13
|
+
|
|
14
|
+
## What this set contains
|
|
15
|
+
|
|
16
|
+
- `namespace.yaml` — the `lastlight` namespace at `privileged` PodSecurity
|
|
17
|
+
(required: `SYS_RESOURCE` exceeds `baseline`).
|
|
18
|
+
- `generic-device-plugin.yaml` — `squat/generic-device-plugin` DaemonSet
|
|
19
|
+
advertising `devic.es/kvm`, so the pod gets `/dev/kvm` without being
|
|
20
|
+
privileged. **The only privileged component here.**
|
|
21
|
+
- `deployment.yaml`, `pvc.yaml`, `service.yaml`, `configmap.yaml` — the harness.
|
|
22
|
+
|
|
23
|
+
## The edits it needs
|
|
24
|
+
|
|
25
|
+
1. **Image** (`deployment.yaml`) — pin `ghcr.io/nearform/lastlight-agent-qemu`
|
|
26
|
+
to a release tag.
|
|
27
|
+
2. **Secret** — create it (see below); the Deployment mounts `lastlight-secrets`.
|
|
28
|
+
3. **StorageClass** (`pvc.yaml`) — set `storageClassName`, or rely on the
|
|
29
|
+
cluster default.
|
|
30
|
+
4. **Ingress** — add your own Ingress/Gateway to reach the `lastlight` Service on
|
|
31
|
+
port 8644 (the GitHub webhook needs to reach it). Not shipped — cluster-specific.
|
|
32
|
+
5. **Managed repos** (`configmap.yaml`) — set `managedRepos`.
|
|
33
|
+
|
|
34
|
+
## Create the Secret
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
kubectl create secret generic lastlight-secrets \
|
|
38
|
+
--namespace lastlight \
|
|
39
|
+
--from-file=.env=instance/secrets/.env \
|
|
40
|
+
--from-file=app.pem=instance/secrets/app.pem
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
(The namespace must exist first: `kubectl apply -f namespace.yaml`, or apply the
|
|
44
|
+
whole set and re-create the Secret — the pod stays pending until it exists.)
|
|
45
|
+
|
|
46
|
+
## Apply
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
kubectl apply -k .
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
On the first apply the pod may sit `Pending` for a minute or two with an
|
|
53
|
+
`Insufficient devic.es/kvm` event while the device-plugin DaemonSet starts and
|
|
54
|
+
registers the resource on each node. Kubernetes reschedules automatically once
|
|
55
|
+
it's advertised — no action needed.
|
|
56
|
+
|
|
57
|
+
## Known limitation
|
|
58
|
+
|
|
59
|
+
Until [nearform/lastlight#210](https://github.com/nearform/lastlight/issues/210)
|
|
60
|
+
Gap 2 lands, the gondolin guest image lacks `gitleaks`/`semgrep`, so the
|
|
61
|
+
`security-review` task falls back to a manual (Claude-only) pass.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
apiVersion: v1
|
|
2
|
+
kind: ConfigMap
|
|
3
|
+
metadata:
|
|
4
|
+
name: lastlight-config
|
|
5
|
+
namespace: lastlight
|
|
6
|
+
data:
|
|
7
|
+
# Overlay layered over the image's config/default.yaml. At minimum set the
|
|
8
|
+
# repos the bot manages. EDIT managedRepos before applying.
|
|
9
|
+
config.yaml: |
|
|
10
|
+
managedRepos:
|
|
11
|
+
- your-org/your-repo
|
|
12
|
+
sandbox:
|
|
13
|
+
backend: gondolin
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
apiVersion: apps/v1
|
|
2
|
+
kind: Deployment
|
|
3
|
+
metadata:
|
|
4
|
+
name: lastlight
|
|
5
|
+
namespace: lastlight
|
|
6
|
+
labels: { app: lastlight }
|
|
7
|
+
spec:
|
|
8
|
+
replicas: 1
|
|
9
|
+
strategy: { type: Recreate } # single embedded-SQLite writer on an RWO PVC
|
|
10
|
+
selector:
|
|
11
|
+
matchLabels: { app: lastlight }
|
|
12
|
+
template:
|
|
13
|
+
metadata:
|
|
14
|
+
labels: { app: lastlight }
|
|
15
|
+
spec:
|
|
16
|
+
containers:
|
|
17
|
+
- name: agent
|
|
18
|
+
# EDIT: pin to a release tag, e.g. :v0.21.8, once you cut a deploy.
|
|
19
|
+
image: ghcr.io/nearform/lastlight-agent-qemu:latest
|
|
20
|
+
# No runAsUser/runAsNonRoot — the entrypoint starts as root then
|
|
21
|
+
# `exec gosu lastlight` (UID 10001). SYS_RESOURCE is the one added
|
|
22
|
+
# capability gondolin's QEMU needs; still no privileged:true / hostPath.
|
|
23
|
+
securityContext:
|
|
24
|
+
capabilities:
|
|
25
|
+
add: ["SYS_RESOURCE"]
|
|
26
|
+
ports:
|
|
27
|
+
- { name: http, containerPort: 8644 }
|
|
28
|
+
env:
|
|
29
|
+
- { name: LASTLIGHT_OVERLAY_DIR, value: /app/instance }
|
|
30
|
+
- { name: STATE_DIR, value: /app/data }
|
|
31
|
+
# Persist gondolin's downloaded guest VM image on the PVC
|
|
32
|
+
# ($HOME/.cache/agentic-pi/images) so it survives restarts.
|
|
33
|
+
- { name: HOME, value: /app/data/home }
|
|
34
|
+
resources:
|
|
35
|
+
requests:
|
|
36
|
+
cpu: "500m"
|
|
37
|
+
memory: 1Gi
|
|
38
|
+
limits:
|
|
39
|
+
cpu: "4"
|
|
40
|
+
memory: 6Gi
|
|
41
|
+
devic.es/kvm: "1" # unprivileged /dev/kvm via the device plugin
|
|
42
|
+
volumeMounts:
|
|
43
|
+
- { name: data, mountPath: /app/data }
|
|
44
|
+
- { name: secrets, mountPath: /app/instance/secrets, readOnly: true }
|
|
45
|
+
- { name: config, mountPath: /app/instance/config.yaml, subPath: config.yaml, readOnly: true }
|
|
46
|
+
startupProbe: # first boot downloads the guest image — be patient
|
|
47
|
+
httpGet: { path: /health, port: 8644 }
|
|
48
|
+
periodSeconds: 10
|
|
49
|
+
failureThreshold: 60 # up to 10 min
|
|
50
|
+
readinessProbe:
|
|
51
|
+
httpGet: { path: /health, port: 8644 }
|
|
52
|
+
periodSeconds: 15
|
|
53
|
+
livenessProbe:
|
|
54
|
+
httpGet: { path: /health, port: 8644 }
|
|
55
|
+
periodSeconds: 30
|
|
56
|
+
failureThreshold: 4
|
|
57
|
+
volumes:
|
|
58
|
+
- name: data
|
|
59
|
+
persistentVolumeClaim: { claimName: lastlight-data }
|
|
60
|
+
- name: secrets
|
|
61
|
+
secret: { secretName: lastlight-secrets }
|
|
62
|
+
- name: config
|
|
63
|
+
configMap: { name: lastlight-config }
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Exposes /dev/kvm to unprivileged pods as the schedulable resource
|
|
2
|
+
# `devic.es/kvm`, so the harness can run gondolin QEMU micro-VMs without being
|
|
3
|
+
# privileged. Talos/siderolabs-recommended pattern. This DaemonSet is the only
|
|
4
|
+
# privileged component in this example.
|
|
5
|
+
apiVersion: apps/v1
|
|
6
|
+
kind: DaemonSet
|
|
7
|
+
metadata:
|
|
8
|
+
name: generic-device-plugin
|
|
9
|
+
namespace: kube-system
|
|
10
|
+
labels:
|
|
11
|
+
app.kubernetes.io/name: generic-device-plugin
|
|
12
|
+
spec:
|
|
13
|
+
selector:
|
|
14
|
+
matchLabels:
|
|
15
|
+
app.kubernetes.io/name: generic-device-plugin
|
|
16
|
+
template:
|
|
17
|
+
metadata:
|
|
18
|
+
labels:
|
|
19
|
+
app.kubernetes.io/name: generic-device-plugin
|
|
20
|
+
spec:
|
|
21
|
+
priorityClassName: system-node-critical
|
|
22
|
+
tolerations:
|
|
23
|
+
- operator: "Exists"
|
|
24
|
+
effect: "NoExecute"
|
|
25
|
+
- operator: "Exists"
|
|
26
|
+
effect: "NoSchedule"
|
|
27
|
+
containers:
|
|
28
|
+
- name: generic-device-plugin
|
|
29
|
+
image: squat/generic-device-plugin:0.2.0
|
|
30
|
+
args:
|
|
31
|
+
- --device
|
|
32
|
+
- |
|
|
33
|
+
name: kvm
|
|
34
|
+
groups:
|
|
35
|
+
- count: 1000
|
|
36
|
+
paths:
|
|
37
|
+
- path: /dev/kvm
|
|
38
|
+
resources:
|
|
39
|
+
requests:
|
|
40
|
+
cpu: 50m
|
|
41
|
+
memory: 10Mi
|
|
42
|
+
limits:
|
|
43
|
+
cpu: 50m
|
|
44
|
+
memory: 20Mi
|
|
45
|
+
ports:
|
|
46
|
+
- containerPort: 8080
|
|
47
|
+
name: http
|
|
48
|
+
securityContext:
|
|
49
|
+
privileged: true
|
|
50
|
+
volumeMounts:
|
|
51
|
+
- name: device-plugin
|
|
52
|
+
mountPath: /var/lib/kubelet/device-plugins
|
|
53
|
+
- name: dev
|
|
54
|
+
mountPath: /dev
|
|
55
|
+
volumes:
|
|
56
|
+
- name: device-plugin
|
|
57
|
+
hostPath:
|
|
58
|
+
path: /var/lib/kubelet/device-plugins
|
|
59
|
+
- name: dev
|
|
60
|
+
hostPath:
|
|
61
|
+
path: /dev
|
|
62
|
+
updateStrategy:
|
|
63
|
+
type: RollingUpdate
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
apiVersion: kustomize.config.k8s.io/v1beta1
|
|
2
|
+
kind: Kustomization
|
|
3
|
+
# The Secret is intentionally NOT here — it carries the GitHub App key + .env and
|
|
4
|
+
# is created out-of-band (see README). Everything the pod otherwise depends on,
|
|
5
|
+
# including the KVM device plugin, ships in this set.
|
|
6
|
+
resources:
|
|
7
|
+
- namespace.yaml
|
|
8
|
+
- generic-device-plugin.yaml
|
|
9
|
+
- configmap.yaml
|
|
10
|
+
- pvc.yaml
|
|
11
|
+
- deployment.yaml
|
|
12
|
+
- service.yaml
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
apiVersion: v1
|
|
2
|
+
kind: Namespace
|
|
3
|
+
metadata:
|
|
4
|
+
name: lastlight
|
|
5
|
+
labels:
|
|
6
|
+
# gondolin's QEMU needs the SYS_RESOURCE capability, which exceeds the
|
|
7
|
+
# cluster-default "baseline" PSA — so this namespace runs at "privileged".
|
|
8
|
+
# The pod itself is NOT privileged: one added capability + the KVM device,
|
|
9
|
+
# no privileged:true, no hostPath, no host namespaces.
|
|
10
|
+
pod-security.kubernetes.io/enforce: privileged
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
apiVersion: v1
|
|
2
|
+
kind: PersistentVolumeClaim
|
|
3
|
+
metadata:
|
|
4
|
+
name: lastlight-data
|
|
5
|
+
namespace: lastlight
|
|
6
|
+
spec:
|
|
7
|
+
accessModes: ["ReadWriteOnce"] # single embedded-SQLite writer
|
|
8
|
+
resources:
|
|
9
|
+
requests:
|
|
10
|
+
storage: 20Gi
|
|
11
|
+
# EDIT: a local/block StorageClass so SQLite file locking is safe (not NFS).
|
|
12
|
+
# Leaving this unset uses the cluster default StorageClass.
|
|
13
|
+
# storageClassName: your-block-storage-class
|
package/dist/admin/routes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
-
import { timingSafeEqual, randomBytes } from "node:crypto";
|
|
2
|
+
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";
|
|
@@ -8,10 +8,13 @@ import { listRunningContainers, killContainer, getContainerStats, getHostStats,
|
|
|
8
8
|
import { authMiddleware, createToken, verifyTokenForRefresh, decodeToken, actorFromContext } from "./auth.js";
|
|
9
9
|
import { Cron } from "croner";
|
|
10
10
|
import { enumerateOverlayAssets } from "lastlight-shared/overlay-assets";
|
|
11
|
-
import { getCronWorkflows, getWorkflow, listAgentWorkflows, loadWorkflowYamlRaw, loadPromptTemplate, loadSkillRaw, } from "../workflows/loader.js";
|
|
11
|
+
import { getCronWorkflows, getWorkflow, getWorkflowByIntent, listAgentWorkflows, loadWorkflowYamlRaw, loadPromptTemplate, loadSkillRaw, } from "../workflows/loader.js";
|
|
12
|
+
import { routeEvent } from "../engine/router.js";
|
|
13
|
+
import { classifyComment } from "../engine/screen/classifier.js";
|
|
12
14
|
import { getWorkflowTriggers, getWorkflowTriggerKinds, } from "../workflows/triggers.js";
|
|
13
15
|
import { getManagedRepos, getInstallationRepos, getInstallationReposRefreshedAt, } from "../managed-repos.js";
|
|
14
|
-
import { getRuntimeConfig } from "../config/config.js";
|
|
16
|
+
import { getRuntimeConfig, getRoutes, getBotName } from "../config/config.js";
|
|
17
|
+
import { reapSandboxWorkspace } from "../sandbox/reap.js";
|
|
15
18
|
import { getServerVersion } from "./version.js";
|
|
16
19
|
import { BuildAssetStore, buildAssetIssueKey } from "../state/build-assets.js";
|
|
17
20
|
/**
|
|
@@ -317,6 +320,79 @@ export async function exchangeOAuth2Code(opts) {
|
|
|
317
320
|
}
|
|
318
321
|
return accessToken;
|
|
319
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* The event-type taxonomy for the playground graph — GitHub + Slack only (cron
|
|
325
|
+
* and CLI bypass the router). `routing` mirrors the branches in router.ts:
|
|
326
|
+
* `deterministic` = a fixed code branch; `classifier` = a real LLM intent call.
|
|
327
|
+
*/
|
|
328
|
+
const PLAYGROUND_EVENT_TYPES = [
|
|
329
|
+
// `issue.opened` runs `classifyIssueIntent` (question vs work) to pick between
|
|
330
|
+
// the `answer` workflow and `issue-triage` — an LLM decides the handler, so it
|
|
331
|
+
// is classifier-routed, not deterministic (even though it needs no @mention).
|
|
332
|
+
{ input: "github", type: "issue.opened", routing: "classifier", label: "Issue opened" },
|
|
333
|
+
{ input: "github", type: "issue.reopened", routing: "deterministic", label: "Issue reopened" },
|
|
334
|
+
{ input: "github", type: "pr.opened", routing: "deterministic", label: "PR opened" },
|
|
335
|
+
{ input: "github", type: "pr.synchronize", routing: "deterministic", label: "PR synchronized" },
|
|
336
|
+
{ input: "github", type: "pr.reopened", routing: "deterministic", label: "PR reopened" },
|
|
337
|
+
{ input: "github", type: "pr.checks_passed", routing: "deterministic", label: "PR checks passed" },
|
|
338
|
+
{ input: "github", type: "pr.checks_failed", routing: "classifier", label: "PR checks failed" },
|
|
339
|
+
{ input: "github", type: "comment.created", routing: "classifier", label: "Comment created" },
|
|
340
|
+
{ input: "github", type: "pr_review.submitted", routing: "classifier", label: "PR review submitted" },
|
|
341
|
+
{ input: "slack", type: "message", routing: "classifier", label: "Message" },
|
|
342
|
+
];
|
|
343
|
+
/**
|
|
344
|
+
* Event types whose intent comes from `classifyComment` on free-form text — the
|
|
345
|
+
* ones the playground re-classifies (with `explain`) to surface the model's
|
|
346
|
+
* reasoning. `pr.checks_failed` is classifier-routed too, but via a check-state
|
|
347
|
+
* branch inside routeEvent, not comment text — so it isn't re-classified here.
|
|
348
|
+
*/
|
|
349
|
+
const COMMENT_CLASSIFIER_TYPES = new Set([
|
|
350
|
+
"comment.created",
|
|
351
|
+
"message",
|
|
352
|
+
"pr_review.submitted",
|
|
353
|
+
]);
|
|
354
|
+
function playgroundRouting(type) {
|
|
355
|
+
return PLAYGROUND_EVENT_TYPES.find((e) => e.type === type)?.routing ?? "deterministic";
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Resolve a classifier intent to the handler the router would pick, using the
|
|
359
|
+
* same `routes` map the router consults (slack keys use `_`, intents use `-`),
|
|
360
|
+
* falling back to the workflow that claims the intent, then the intent itself.
|
|
361
|
+
*/
|
|
362
|
+
function resolveIntentHandler(intent) {
|
|
363
|
+
const routes = getRoutes();
|
|
364
|
+
const key = intent.replace(/-/g, "_");
|
|
365
|
+
return routes.slack[intent] ?? routes.slack[key] ?? getWorkflowByIntent(intent)?.name ?? intent;
|
|
366
|
+
}
|
|
367
|
+
/** Compose a human-readable "why" from the event type, classifier result, and route. */
|
|
368
|
+
function buildExplanation(type, classification, route) {
|
|
369
|
+
const routingKind = playgroundRouting(type);
|
|
370
|
+
const notes = [];
|
|
371
|
+
let handler;
|
|
372
|
+
let routeKey;
|
|
373
|
+
if (route.action === "handler") {
|
|
374
|
+
handler = route.handler;
|
|
375
|
+
const rk = route.context?._routeKey;
|
|
376
|
+
routeKey = typeof rk === "string" ? rk : undefined;
|
|
377
|
+
}
|
|
378
|
+
else if (route.action === "reply") {
|
|
379
|
+
notes.push(`Replied directly: ${route.message}`);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
notes.push(`Ignored: ${route.reason}`);
|
|
383
|
+
}
|
|
384
|
+
let branchLabel;
|
|
385
|
+
if (classification) {
|
|
386
|
+
branchLabel = `classified as '${classification.intent}'` + (handler ? ` → ${handler}` : "");
|
|
387
|
+
}
|
|
388
|
+
else if (route.action === "handler") {
|
|
389
|
+
branchLabel = `${type} → ${handler}`;
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
branchLabel = `${type} → ${route.action}`;
|
|
393
|
+
}
|
|
394
|
+
return { routingKind, branchLabel, handler, routeKey, reason: classification?.reason, notes };
|
|
395
|
+
}
|
|
320
396
|
export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
321
397
|
const app = new Hono();
|
|
322
398
|
const slackOAuthEnabled = Boolean(config.slackOAuthClientId && config.slackOAuthClientSecret);
|
|
@@ -358,6 +434,131 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
358
434
|
overlayDir: config.overlayDir ?? null,
|
|
359
435
|
overrides: enumerateOverlayAssets({ coreRoot: config.builtInRoot, overlayRoot: config.overlayDir }),
|
|
360
436
|
}));
|
|
437
|
+
// ── Event Router Playground ────────────────────────────────────────────────
|
|
438
|
+
// Static graph description: inputs → event types → router → handlers. Built
|
|
439
|
+
// from the same sources the router uses (getRoutes + listAgentWorkflows) so the
|
|
440
|
+
// taxonomy isn't duplicated in the frontend.
|
|
441
|
+
app.get("/route-graph", (c) => {
|
|
442
|
+
const routes = getRoutes();
|
|
443
|
+
const defs = listAgentWorkflows();
|
|
444
|
+
const inputs = [
|
|
445
|
+
{ id: "github", label: "GitHub" },
|
|
446
|
+
{ id: "slack", label: "Slack" },
|
|
447
|
+
];
|
|
448
|
+
const eventTypes = PLAYGROUND_EVENT_TYPES.map((e) => ({
|
|
449
|
+
input: e.input,
|
|
450
|
+
type: e.type,
|
|
451
|
+
routing: e.routing,
|
|
452
|
+
label: e.label,
|
|
453
|
+
}));
|
|
454
|
+
const handlers = defs.map((def) => ({
|
|
455
|
+
name: def.name,
|
|
456
|
+
claimedIntent: def.classification?.intent,
|
|
457
|
+
kind: "workflow",
|
|
458
|
+
}));
|
|
459
|
+
// In-process handlers the router can dispatch to (not YAML workflows).
|
|
460
|
+
for (const name of ["chat", "chat-reset", "status-report", "approval-response", "explore-reply"]) {
|
|
461
|
+
handlers.push({ name, kind: "in-process" });
|
|
462
|
+
}
|
|
463
|
+
// Classifier intent → handler fan-out edges: each workflow's claimed intent,
|
|
464
|
+
// then any remaining slack-route intents (reserved controls, question, …).
|
|
465
|
+
const intentEdges = [];
|
|
466
|
+
const seenIntent = new Set();
|
|
467
|
+
for (const def of defs) {
|
|
468
|
+
const intent = def.classification?.intent;
|
|
469
|
+
if (!intent || seenIntent.has(intent))
|
|
470
|
+
continue;
|
|
471
|
+
seenIntent.add(intent);
|
|
472
|
+
intentEdges.push({ intent, to: resolveIntentHandler(intent) });
|
|
473
|
+
}
|
|
474
|
+
for (const [key, to] of Object.entries(routes.slack)) {
|
|
475
|
+
const intent = key.replace(/_/g, "-");
|
|
476
|
+
if (seenIntent.has(intent))
|
|
477
|
+
continue;
|
|
478
|
+
seenIntent.add(intent);
|
|
479
|
+
intentEdges.push({ intent, to });
|
|
480
|
+
}
|
|
481
|
+
// Deterministic event-type → handler edges, straight from the github routes.
|
|
482
|
+
const gh = routes.github;
|
|
483
|
+
const deterministicEdges = [
|
|
484
|
+
{ from: "issue.opened", to: gh.issue_opened, via: "issue_opened" },
|
|
485
|
+
{ from: "issue.reopened", to: gh.issue_reopened, via: "issue_reopened" },
|
|
486
|
+
{ from: "pr.opened", to: gh.pr_opened, via: "pr_opened" },
|
|
487
|
+
{ from: "pr.synchronize", to: gh.pr_synchronize, via: "pr_synchronize" },
|
|
488
|
+
{ from: "pr.reopened", to: gh.pr_reopened, via: "pr_reopened" },
|
|
489
|
+
{ from: "pr.checks_passed", to: getWorkflowByIntent("dependabot-pr-merge")?.name, via: "checks_passed" },
|
|
490
|
+
].filter((e) => Boolean(e.to));
|
|
491
|
+
// Ensure every edge target has a handler node (a route may point at a
|
|
492
|
+
// workflow not in the def list, e.g. a bare fallback name).
|
|
493
|
+
const handlerNames = new Set(handlers.map((h) => h.name));
|
|
494
|
+
for (const to of [...intentEdges.map((e) => e.to), ...deterministicEdges.map((e) => e.to)]) {
|
|
495
|
+
if (to && !handlerNames.has(to)) {
|
|
496
|
+
handlerNames.add(to);
|
|
497
|
+
handlers.push({ name: to, kind: "workflow" });
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return c.json({ botName: getBotName(), inputs, eventTypes, handlers, deterministicEdges, intentEdges });
|
|
501
|
+
});
|
|
502
|
+
// Hermetic dry-run: thread a synthetic event through the REAL classifier +
|
|
503
|
+
// router and return the decision — WITHOUT starting any workflow. Calls
|
|
504
|
+
// routeEvent({}) (no db, no github → zero external reads/writes) and, for
|
|
505
|
+
// comment-text types, classifyComment(..., {explain:true}) for the reasoning.
|
|
506
|
+
// NEVER touches dispatch/dispatchWorkflow (structurally out of scope here).
|
|
507
|
+
app.post("/route-test", async (c) => {
|
|
508
|
+
const body = (await c.req.json().catch(() => null));
|
|
509
|
+
if (!body || typeof body.type !== "string") {
|
|
510
|
+
return c.json({ error: "type is required" }, 400);
|
|
511
|
+
}
|
|
512
|
+
const type = body.type;
|
|
513
|
+
const isPr = body.isPullRequest ?? type.startsWith("pr");
|
|
514
|
+
const envelope = {
|
|
515
|
+
id: `route-test-${randomUUID()}`,
|
|
516
|
+
source: body.source ?? "github",
|
|
517
|
+
type,
|
|
518
|
+
repo: body.repo,
|
|
519
|
+
issueNumber: body.issueNumber,
|
|
520
|
+
prNumber: isPr ? body.prNumber ?? 1 : body.prNumber,
|
|
521
|
+
sender: body.sender || "playground-user",
|
|
522
|
+
// The PR/issue author — for PR events (e.g. pr.checks_failed) the router
|
|
523
|
+
// classifies "…by <issueAuthor>…", so a dependency PR needs the bot author.
|
|
524
|
+
issueAuthor: body.issueAuthor ?? (isPr ? body.prAuthor : undefined),
|
|
525
|
+
senderIsBot: false,
|
|
526
|
+
body: body.body ?? "",
|
|
527
|
+
title: body.title,
|
|
528
|
+
labels: body.labels ?? [],
|
|
529
|
+
authorAssociation: body.authorAssociation ?? "OWNER",
|
|
530
|
+
raw: {}, // empty → no Slack thread lookup
|
|
531
|
+
reply: async () => { }, // inert no-op — nothing is ever posted
|
|
532
|
+
timestamp: new Date(),
|
|
533
|
+
};
|
|
534
|
+
let classification;
|
|
535
|
+
if (COMMENT_CLASSIFIER_TYPES.has(type)) {
|
|
536
|
+
classification = await classifyComment(envelope.body, {
|
|
537
|
+
issueTitle: body.title,
|
|
538
|
+
isPullRequest: isPr,
|
|
539
|
+
prAuthor: body.prAuthor,
|
|
540
|
+
checksState: body.checksState,
|
|
541
|
+
}, { explain: true });
|
|
542
|
+
}
|
|
543
|
+
else if (type === "pr.checks_failed") {
|
|
544
|
+
// The router classifies a SYNTHESIZED description for this event (not the
|
|
545
|
+
// body) — replicate it so the playground surfaces the same intent/reason
|
|
546
|
+
// (or a classifier error) the router's internal call would produce.
|
|
547
|
+
const text = `Pull request #${envelope.prNumber} "${envelope.title || ""}" ` +
|
|
548
|
+
`by ${envelope.issueAuthor || "unknown"} — its CI checks have failed.`;
|
|
549
|
+
classification = await classifyComment(text, { issueTitle: envelope.title, isPullRequest: true }, { explain: true });
|
|
550
|
+
}
|
|
551
|
+
else if (type === "issue.opened") {
|
|
552
|
+
// `classifyIssueIntent` classifies the combined title + body (question vs
|
|
553
|
+
// work) to choose `answer` vs `issue-triage` — mirror it so the why-panel
|
|
554
|
+
// shows the same intent/reason the router's internal call produced.
|
|
555
|
+
const combined = `${envelope.title || ""}\n\n${envelope.body || ""}`.trim();
|
|
556
|
+
classification = await classifyComment(combined, { issueTitle: envelope.title }, { explain: true });
|
|
557
|
+
}
|
|
558
|
+
const route = await routeEvent(envelope, {});
|
|
559
|
+
const explanation = buildExplanation(type, classification, route);
|
|
560
|
+
return c.json({ route, classification, explanation });
|
|
561
|
+
});
|
|
361
562
|
// Auth endpoints
|
|
362
563
|
app.get("/auth-required", (c) => {
|
|
363
564
|
return c.json({
|
|
@@ -975,7 +1176,20 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
975
1176
|
console.warn(`[cancel] container enumeration failed:`, err);
|
|
976
1177
|
}
|
|
977
1178
|
}
|
|
978
|
-
|
|
1179
|
+
// Reap the on-disk workspace too (issue #106) — the kills above stop the
|
|
1180
|
+
// in-flight phase but leave the clone behind. Cancel is explicit and leaves
|
|
1181
|
+
// a dirty checkout, so reap regardless of workflow class (a reusable per-PR
|
|
1182
|
+
// dir just re-clones next time). The live-container guard defaults on, so a
|
|
1183
|
+
// container still dying from the kills above is not raced.
|
|
1184
|
+
let reaped = false;
|
|
1185
|
+
if (typeof storedTaskId === "string" && storedTaskId) {
|
|
1186
|
+
reaped = reapSandboxWorkspace({
|
|
1187
|
+
taskId: storedTaskId,
|
|
1188
|
+
stateDir: config.stateDir,
|
|
1189
|
+
sandboxDir: getRuntimeConfig()?.sandboxDir,
|
|
1190
|
+
}).removed;
|
|
1191
|
+
}
|
|
1192
|
+
return c.json({ cancelled: id, killedContainers: killed, reapedWorkspace: reaped });
|
|
979
1193
|
});
|
|
980
1194
|
// Retry a FAILED or CANCELLED workflow run — resume from where it stopped with
|
|
981
1195
|
// the same context. `cancelled` covers a queue-drop after a server death and a
|