lastlight-core 0.16.1
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/LICENSE +21 -0
- package/README.md +10 -0
- package/agent-context/rules.md +80 -0
- package/agent-context/security.md +69 -0
- package/agent-context/soul.md +21 -0
- package/config/default.yaml +119 -0
- package/deploy/.env.production.example +100 -0
- package/deploy/entrypoint.sh +82 -0
- package/deploy/native/README.md +160 -0
- package/deploy/native/install.sh +110 -0
- package/deploy/native/lastlight.env.example +95 -0
- package/deploy/native/lastlight.service +50 -0
- package/deploy/sandbox-entrypoint.sh +93 -0
- package/deploy/slack/README.md +92 -0
- package/deploy/slack/slack-manifest.json +55 -0
- package/dist/admin/auth.d.ts +51 -0
- package/dist/admin/auth.js +121 -0
- package/dist/admin/auth.js.map +1 -0
- package/dist/admin/chat-session-reader.d.ts +39 -0
- package/dist/admin/chat-session-reader.js +84 -0
- package/dist/admin/chat-session-reader.js.map +1 -0
- package/dist/admin/docker.d.ts +61 -0
- package/dist/admin/docker.js +187 -0
- package/dist/admin/docker.js.map +1 -0
- package/dist/admin/index.d.ts +9 -0
- package/dist/admin/index.js +59 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/routes.d.ts +81 -0
- package/dist/admin/routes.js +1381 -0
- package/dist/admin/routes.js.map +1 -0
- package/dist/admin/sessions.d.ts +89 -0
- package/dist/admin/sessions.js +204 -0
- package/dist/admin/sessions.js.map +1 -0
- package/dist/admin/tail.d.ts +12 -0
- package/dist/admin/tail.js +145 -0
- package/dist/admin/tail.js.map +1 -0
- package/dist/admin/version.d.ts +22 -0
- package/dist/admin/version.js +92 -0
- package/dist/admin/version.js.map +1 -0
- package/dist/config/config-resolve.d.ts +28 -0
- package/dist/config/config-resolve.js +47 -0
- package/dist/config/config-resolve.js.map +1 -0
- package/dist/config/config.d.ts +140 -0
- package/dist/config/config.js +581 -0
- package/dist/config/config.js.map +1 -0
- package/dist/connectors/github-webhook.d.ts +45 -0
- package/dist/connectors/github-webhook.js +321 -0
- package/dist/connectors/github-webhook.js.map +1 -0
- package/dist/connectors/index.d.ts +18 -0
- package/dist/connectors/index.js +41 -0
- package/dist/connectors/index.js.map +1 -0
- package/dist/connectors/messaging/base.d.ts +42 -0
- package/dist/connectors/messaging/base.js +139 -0
- package/dist/connectors/messaging/base.js.map +1 -0
- package/dist/connectors/messaging/delivery.d.ts +14 -0
- package/dist/connectors/messaging/delivery.js +38 -0
- package/dist/connectors/messaging/delivery.js.map +1 -0
- package/dist/connectors/messaging/index.d.ts +4 -0
- package/dist/connectors/messaging/index.js +4 -0
- package/dist/connectors/messaging/index.js.map +1 -0
- package/dist/connectors/messaging/session-manager.d.ts +53 -0
- package/dist/connectors/messaging/session-manager.js +255 -0
- package/dist/connectors/messaging/session-manager.js.map +1 -0
- package/dist/connectors/messaging/types.d.ts +58 -0
- package/dist/connectors/messaging/types.js +7 -0
- package/dist/connectors/messaging/types.js.map +1 -0
- package/dist/connectors/slack/connector.d.ts +142 -0
- package/dist/connectors/slack/connector.js +494 -0
- package/dist/connectors/slack/connector.js.map +1 -0
- package/dist/connectors/slack/index.d.ts +2 -0
- package/dist/connectors/slack/index.js +3 -0
- package/dist/connectors/slack/index.js.map +1 -0
- package/dist/connectors/slack/mrkdwn.d.ts +19 -0
- package/dist/connectors/slack/mrkdwn.js +240 -0
- package/dist/connectors/slack/mrkdwn.js.map +1 -0
- package/dist/connectors/types.d.ts +61 -0
- package/dist/connectors/types.js +2 -0
- package/dist/connectors/types.js.map +1 -0
- package/dist/cron/fanout.d.ts +33 -0
- package/dist/cron/fanout.js +55 -0
- package/dist/cron/fanout.js.map +1 -0
- package/dist/cron/jobs.d.ts +18 -0
- package/dist/cron/jobs.js +37 -0
- package/dist/cron/jobs.js.map +1 -0
- package/dist/cron/scheduler.d.ts +45 -0
- package/dist/cron/scheduler.js +105 -0
- package/dist/cron/scheduler.js.map +1 -0
- package/dist/engine/agent-executor.d.ts +34 -0
- package/dist/engine/agent-executor.js +246 -0
- package/dist/engine/agent-executor.js.map +1 -0
- package/dist/engine/chat/chat-runner.d.ts +132 -0
- package/dist/engine/chat/chat-runner.js +424 -0
- package/dist/engine/chat/chat-runner.js.map +1 -0
- package/dist/engine/chat/chat-skills.d.ts +45 -0
- package/dist/engine/chat/chat-skills.js +184 -0
- package/dist/engine/chat/chat-skills.js.map +1 -0
- package/dist/engine/chat/chat.d.ts +54 -0
- package/dist/engine/chat/chat.js +316 -0
- package/dist/engine/chat/chat.js.map +1 -0
- package/dist/engine/chat/message-batcher.d.ts +32 -0
- package/dist/engine/chat/message-batcher.js +109 -0
- package/dist/engine/chat/message-batcher.js.map +1 -0
- package/dist/engine/dispatcher.d.ts +73 -0
- package/dist/engine/dispatcher.js +663 -0
- package/dist/engine/dispatcher.js.map +1 -0
- package/dist/engine/event-shim.d.ts +117 -0
- package/dist/engine/event-shim.js +435 -0
- package/dist/engine/event-shim.js.map +1 -0
- package/dist/engine/executors/orchestrator.d.ts +74 -0
- package/dist/engine/executors/orchestrator.js +365 -0
- package/dist/engine/executors/orchestrator.js.map +1 -0
- package/dist/engine/executors/shared.d.ts +189 -0
- package/dist/engine/executors/shared.js +616 -0
- package/dist/engine/executors/shared.js.map +1 -0
- package/dist/engine/github/git-auth.d.ts +62 -0
- package/dist/engine/github/git-auth.js +161 -0
- package/dist/engine/github/git-auth.js.map +1 -0
- package/dist/engine/github/github-app-client.d.ts +23 -0
- package/dist/engine/github/github-app-client.js +33 -0
- package/dist/engine/github/github-app-client.js.map +1 -0
- package/dist/engine/github/github-tools.d.ts +18 -0
- package/dist/engine/github/github-tools.js +263 -0
- package/dist/engine/github/github-tools.js.map +1 -0
- package/dist/engine/github/github.d.ts +1193 -0
- package/dist/engine/github/github.js +357 -0
- package/dist/engine/github/github.js.map +1 -0
- package/dist/engine/github/profiles.d.ts +11 -0
- package/dist/engine/github/profiles.js +42 -0
- package/dist/engine/github/profiles.js.map +1 -0
- package/dist/engine/github/review-poster.d.ts +98 -0
- package/dist/engine/github/review-poster.js +177 -0
- package/dist/engine/github/review-poster.js.map +1 -0
- package/dist/engine/llm.d.ts +79 -0
- package/dist/engine/llm.js +269 -0
- package/dist/engine/llm.js.map +1 -0
- package/dist/engine/oauth.d.ts +8 -0
- package/dist/engine/oauth.js +9 -0
- package/dist/engine/oauth.js.map +1 -0
- package/dist/engine/router.d.ts +29 -0
- package/dist/engine/router.js +680 -0
- package/dist/engine/router.js.map +1 -0
- package/dist/engine/screen/classifier.d.ts +93 -0
- package/dist/engine/screen/classifier.js +215 -0
- package/dist/engine/screen/classifier.js.map +1 -0
- package/dist/engine/screen/screen.d.ts +41 -0
- package/dist/engine/screen/screen.js +93 -0
- package/dist/engine/screen/screen.js.map +1 -0
- package/dist/evals-api.d.ts +24 -0
- package/dist/evals-api.js +22 -0
- package/dist/evals-api.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +940 -0
- package/dist/index.js.map +1 -0
- package/dist/managed-repos.d.ts +30 -0
- package/dist/managed-repos.js +72 -0
- package/dist/managed-repos.js.map +1 -0
- package/dist/notify/blocks.d.ts +23 -0
- package/dist/notify/blocks.js +118 -0
- package/dist/notify/blocks.js.map +1 -0
- package/dist/notify/index.d.ts +17 -0
- package/dist/notify/index.js +7 -0
- package/dist/notify/index.js.map +1 -0
- package/dist/notify/model.d.ts +57 -0
- package/dist/notify/model.js +89 -0
- package/dist/notify/model.js.map +1 -0
- package/dist/notify/notifier.d.ts +18 -0
- package/dist/notify/notifier.js +100 -0
- package/dist/notify/notifier.js.map +1 -0
- package/dist/notify/render.d.ts +21 -0
- package/dist/notify/render.js +59 -0
- package/dist/notify/render.js.map +1 -0
- package/dist/notify/transports/github.d.ts +26 -0
- package/dist/notify/transports/github.js +27 -0
- package/dist/notify/transports/github.js.map +1 -0
- package/dist/notify/transports/slack.d.ts +27 -0
- package/dist/notify/transports/slack.js +37 -0
- package/dist/notify/transports/slack.js.map +1 -0
- package/dist/notify/types.d.ts +111 -0
- package/dist/notify/types.js +16 -0
- package/dist/notify/types.js.map +1 -0
- package/dist/sandbox/docker.d.ts +180 -0
- package/dist/sandbox/docker.js +517 -0
- package/dist/sandbox/docker.js.map +1 -0
- package/dist/sandbox/egress-allowlist.d.ts +74 -0
- package/dist/sandbox/egress-allowlist.js +164 -0
- package/dist/sandbox/egress-allowlist.js.map +1 -0
- package/dist/sandbox/egress-firewall-config.d.ts +127 -0
- package/dist/sandbox/egress-firewall-config.js +434 -0
- package/dist/sandbox/egress-firewall-config.js.map +1 -0
- package/dist/sandbox/images.d.ts +23 -0
- package/dist/sandbox/images.js +55 -0
- package/dist/sandbox/images.js.map +1 -0
- package/dist/sandbox/index.d.ts +112 -0
- package/dist/sandbox/index.js +332 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/sandbox.d.ts +214 -0
- package/dist/sandbox/sandbox.js +453 -0
- package/dist/sandbox/sandbox.js.map +1 -0
- package/dist/sandbox/smol.d.ts +162 -0
- package/dist/sandbox/smol.js +485 -0
- package/dist/sandbox/smol.js.map +1 -0
- package/dist/session-log.d.ts +63 -0
- package/dist/session-log.js +290 -0
- package/dist/session-log.js.map +1 -0
- package/dist/state/approval-store.d.ts +88 -0
- package/dist/state/approval-store.js +149 -0
- package/dist/state/approval-store.js.map +1 -0
- package/dist/state/build-assets.d.ts +50 -0
- package/dist/state/build-assets.js +154 -0
- package/dist/state/build-assets.js.map +1 -0
- package/dist/state/db.d.ts +81 -0
- package/dist/state/db.js +155 -0
- package/dist/state/db.js.map +1 -0
- package/dist/state/execution-store.d.ts +257 -0
- package/dist/state/execution-store.js +527 -0
- package/dist/state/execution-store.js.map +1 -0
- package/dist/state/migrate.d.ts +15 -0
- package/dist/state/migrate.js +175 -0
- package/dist/state/migrate.js.map +1 -0
- package/dist/state/workflow-run-store.d.ts +216 -0
- package/dist/state/workflow-run-store.js +403 -0
- package/dist/state/workflow-run-store.js.map +1 -0
- package/dist/telemetry/index.d.ts +38 -0
- package/dist/telemetry/index.js +253 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/pi-events.d.ts +12 -0
- package/dist/telemetry/pi-events.js +134 -0
- package/dist/telemetry/pi-events.js.map +1 -0
- package/dist/workflows/dag.d.ts +1 -0
- package/dist/workflows/dag.js +2 -0
- package/dist/workflows/dag.js.map +1 -0
- package/dist/workflows/handlers/post-review.d.ts +45 -0
- package/dist/workflows/handlers/post-review.js +220 -0
- package/dist/workflows/handlers/post-review.js.map +1 -0
- package/dist/workflows/handlers/verdict-reader.d.ts +14 -0
- package/dist/workflows/handlers/verdict-reader.js +55 -0
- package/dist/workflows/handlers/verdict-reader.js.map +1 -0
- package/dist/workflows/loader.d.ts +9 -0
- package/dist/workflows/loader.js +10 -0
- package/dist/workflows/loader.js.map +1 -0
- package/dist/workflows/loop-eval.d.ts +1 -0
- package/dist/workflows/loop-eval.js +2 -0
- package/dist/workflows/loop-eval.js.map +1 -0
- package/dist/workflows/phase-executor.d.ts +1 -0
- package/dist/workflows/phase-executor.js +6 -0
- package/dist/workflows/phase-executor.js.map +1 -0
- package/dist/workflows/phase-ref.d.ts +1 -0
- package/dist/workflows/phase-ref.js +2 -0
- package/dist/workflows/phase-ref.js.map +1 -0
- package/dist/workflows/resume.d.ts +58 -0
- package/dist/workflows/resume.js +313 -0
- package/dist/workflows/resume.js.map +1 -0
- package/dist/workflows/runner.d.ts +47 -0
- package/dist/workflows/runner.js +278 -0
- package/dist/workflows/runner.js.map +1 -0
- package/dist/workflows/schema.d.ts +1 -0
- package/dist/workflows/schema.js +2 -0
- package/dist/workflows/schema.js.map +1 -0
- package/dist/workflows/simple.d.ts +90 -0
- package/dist/workflows/simple.js +393 -0
- package/dist/workflows/simple.js.map +1 -0
- package/dist/workflows/target-policy.d.ts +74 -0
- package/dist/workflows/target-policy.js +80 -0
- package/dist/workflows/target-policy.js.map +1 -0
- package/dist/workflows/templates.d.ts +1 -0
- package/dist/workflows/templates.js +2 -0
- package/dist/workflows/templates.js.map +1 -0
- package/dist/workflows/triggers.d.ts +21 -0
- package/dist/workflows/triggers.js +45 -0
- package/dist/workflows/triggers.js.map +1 -0
- package/dist/workflows/verdict.d.ts +1 -0
- package/dist/workflows/verdict.js +2 -0
- package/dist/workflows/verdict.js.map +1 -0
- package/dist/worktree/manager.d.ts +43 -0
- package/dist/worktree/manager.js +127 -0
- package/dist/worktree/manager.js.map +1 -0
- package/docker-compose.yml +280 -0
- package/package.json +93 -0
- package/sandbox.Dockerfile +68 -0
- package/skills/README.md +42 -0
- package/skills/browser-qa/SKILL.md +208 -0
- package/skills/browser-qa/scripts/agent-browser.mjs +531 -0
- package/skills/building/SKILL.md +95 -0
- package/skills/chat/SKILL.md +36 -0
- package/skills/code-review/SKILL.md +82 -0
- package/skills/debug-production/SKILL.md +108 -0
- package/skills/demo/SKILL.md +228 -0
- package/skills/demo/scripts/compose-demo.sh +243 -0
- package/skills/issue-answer/SKILL.md +91 -0
- package/skills/issue-comment/SKILL.md +49 -0
- package/skills/issue-triage/SKILL.md +149 -0
- package/skills/issue-triage/references/AGENT-BRIEF.md +65 -0
- package/skills/pr-comment/SKILL.md +64 -0
- package/skills/pr-review/SKILL.md +148 -0
- package/skills/pr-review/references/findings-schema.md +89 -0
- package/skills/qa-test/SKILL.md +97 -0
- package/skills/repo-health/SKILL.md +67 -0
- package/skills/security-feedback/SKILL.md +173 -0
- package/skills/security-feedback/references/templates.md +77 -0
- package/skills/security-review/SKILL.md +215 -0
- package/skills/security-review/references/issue-format.md +302 -0
- package/skills/verify/SKILL.md +118 -0
- package/workflows/answer.yaml +44 -0
- package/workflows/build.yaml +129 -0
- package/workflows/cron-health.yaml +6 -0
- package/workflows/cron-review.yaml +8 -0
- package/workflows/cron-security.yaml +6 -0
- package/workflows/cron-triage.yaml +8 -0
- package/workflows/demo.yaml +62 -0
- package/workflows/examples/bash-smoke.yaml +41 -0
- package/workflows/examples/parallel-review.yaml +36 -0
- package/workflows/examples/tdd-loop.yaml +17 -0
- package/workflows/explore.yaml +80 -0
- package/workflows/issue-comment.yaml +15 -0
- package/workflows/issue-triage.yaml +22 -0
- package/workflows/pr-comment.yaml +16 -0
- package/workflows/pr-fix.yaml +17 -0
- package/workflows/pr-review.yaml +50 -0
- package/workflows/prompts/answer.md +68 -0
- package/workflows/prompts/architect.md +44 -0
- package/workflows/prompts/classifier.md +60 -0
- package/workflows/prompts/classify-adds-info.md +17 -0
- package/workflows/prompts/demo.md +125 -0
- package/workflows/prompts/executor.md +42 -0
- package/workflows/prompts/explore-ask.md +99 -0
- package/workflows/prompts/explore-publish.md +31 -0
- package/workflows/prompts/explore-read.md +120 -0
- package/workflows/prompts/explore-synthesize.md +88 -0
- package/workflows/prompts/fix.md +18 -0
- package/workflows/prompts/guardrails.md +96 -0
- package/workflows/prompts/pr-fix.md +26 -0
- package/workflows/prompts/pr.md +39 -0
- package/workflows/prompts/qa-browser.md +95 -0
- package/workflows/prompts/qa-synth.md +44 -0
- package/workflows/prompts/qa-test.md +60 -0
- package/workflows/prompts/re-reviewer.md +33 -0
- package/workflows/prompts/reviewer.md +60 -0
- package/workflows/prompts/verify-browser.md +93 -0
- package/workflows/prompts/verify-synth.md +44 -0
- package/workflows/prompts/verify.md +63 -0
- package/workflows/qa-test.yaml +94 -0
- package/workflows/repo-health.yaml +15 -0
- package/workflows/security-feedback.yaml +25 -0
- package/workflows/security-review.yaml +37 -0
- package/workflows/verify.yaml +93 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { GitHubClient } from "../../engine/github/github.js";
|
|
5
|
+
import { buildReview, buildBodyOnlyReview, parseDiff, } from "../../engine/github/review-poster.js";
|
|
6
|
+
import { getRuntimeConfig } from "../../config/config.js";
|
|
7
|
+
/**
|
|
8
|
+
* The `type: post-review` phase — the one workflow body genuinely coupled to
|
|
9
|
+
* GitHub, lifted out of the engine into an app-registered {@link PhaseTypeHandler}.
|
|
10
|
+
*
|
|
11
|
+
* First-class, in-process PR-review submission. The reviewer agent writes only
|
|
12
|
+
* *content* to `.lastlight/pr-review/findings.json` (`{ skip?, summary, event,
|
|
13
|
+
* findings[] }`); THIS handler supplies every fact the harness already knows —
|
|
14
|
+
* the PR number (run context), the base ref, head SHA and diff (pre-cloned
|
|
15
|
+
* checkout) — anchors each finding to a changed line, and posts one formal
|
|
16
|
+
* review via `GitHubClient`.
|
|
17
|
+
*
|
|
18
|
+
* A genuine failure — missing findings after a real review, or a GitHub error
|
|
19
|
+
* that survives the body-only retry — FAILS the phase visibly; only a
|
|
20
|
+
* legitimate `skip` succeeds without posting. Idempotent on resume: it no-ops
|
|
21
|
+
* when a bot review already exists on the current head SHA.
|
|
22
|
+
*/
|
|
23
|
+
export class GitHubPostReviewHandler {
|
|
24
|
+
run;
|
|
25
|
+
reporter;
|
|
26
|
+
constructor(run, reporter) {
|
|
27
|
+
this.run = run;
|
|
28
|
+
this.reporter = reporter;
|
|
29
|
+
}
|
|
30
|
+
async execute(phase, _node, _outputs) {
|
|
31
|
+
const phaseName = phase.name;
|
|
32
|
+
await this.reporter.onStart(phaseName);
|
|
33
|
+
await this.reporter.step(phaseName, "running", phase.messages?.on_start);
|
|
34
|
+
const succeed = async (summary) => {
|
|
35
|
+
const result = { phase: phaseName, success: true, output: summary };
|
|
36
|
+
this.reporter.persistPhase(phaseName, summary);
|
|
37
|
+
await this.reporter.onEnd(phaseName, result);
|
|
38
|
+
await this.reporter.step(phaseName, "done", phase.messages?.on_success);
|
|
39
|
+
return { results: [result], status: "succeeded" };
|
|
40
|
+
};
|
|
41
|
+
const fail = async (error) => {
|
|
42
|
+
const result = { phase: phaseName, success: false, output: "", error };
|
|
43
|
+
await this.reporter.onEnd(phaseName, result);
|
|
44
|
+
await this.reporter.step(phaseName, "failed", phase.messages?.on_failure);
|
|
45
|
+
// Record a failed phase_history entry so the dashboard pipeline renders
|
|
46
|
+
// this node red — the handler has no `executions` row (it runs in-process),
|
|
47
|
+
// and `persistPhase` only writes success entries, so without this a failed
|
|
48
|
+
// post-review would show as "pending" despite the run being marked failed.
|
|
49
|
+
if (this.run.store && this.run.workflowId) {
|
|
50
|
+
this.run.store.runs.appendPhase(this.run.workflowId, phaseName, {
|
|
51
|
+
phase: phaseName,
|
|
52
|
+
timestamp: new Date().toISOString(),
|
|
53
|
+
success: false,
|
|
54
|
+
summary: error,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
this.reporter.failWorkflow(error);
|
|
58
|
+
console.error(`[post-review] ${error}`);
|
|
59
|
+
return { results: [result], status: "failed" };
|
|
60
|
+
};
|
|
61
|
+
const ctx = this.run.ctx;
|
|
62
|
+
const owner = String(ctx.owner);
|
|
63
|
+
const repo = String(ctx.repo);
|
|
64
|
+
const prNumber = (typeof ctx.prNumber === "number" ? ctx.prNumber : undefined) ??
|
|
65
|
+
(typeof ctx.issueNumber === "number" && ctx.issueNumber > 0 ? ctx.issueNumber : undefined);
|
|
66
|
+
if (!prNumber)
|
|
67
|
+
return fail("post-review: no PR number in run context; cannot post review");
|
|
68
|
+
// Read the agent's findings from the host checkout. The review phase writes
|
|
69
|
+
// it at `.lastlight/pr-review/findings.json` relative to the repo cwd; the
|
|
70
|
+
// workspace persists on the host between phases (see sandbox/index.ts).
|
|
71
|
+
const hostRepoDir = this.resolveHostRepoDir(repo);
|
|
72
|
+
const findingsPath = join(hostRepoDir, ".lastlight", "pr-review", "findings.json");
|
|
73
|
+
let doc;
|
|
74
|
+
try {
|
|
75
|
+
doc = JSON.parse(readFileSync(findingsPath, "utf8"));
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
79
|
+
// A missing/unreadable file after a completed review means the review
|
|
80
|
+
// phase didn't honour its contract — surface it, don't post silently.
|
|
81
|
+
return fail(`post-review: could not read findings (${findingsPath}): ${msg}`);
|
|
82
|
+
}
|
|
83
|
+
if (doc.skip) {
|
|
84
|
+
return succeed(`skipped: ${doc.summary || "agent skipped review"}`);
|
|
85
|
+
}
|
|
86
|
+
const github = this.buildReviewClient();
|
|
87
|
+
// Head SHA + base ref come from the checkout / run context, never the agent.
|
|
88
|
+
const baseRef = typeof ctx.baseBranch === "string" && ctx.baseBranch ? ctx.baseBranch : undefined;
|
|
89
|
+
const headSha = this.gitHeadSha(hostRepoDir);
|
|
90
|
+
// Idempotency: skip if a bot review already exists on this head SHA (guards
|
|
91
|
+
// resume / re-entry from double-posting).
|
|
92
|
+
if (headSha) {
|
|
93
|
+
try {
|
|
94
|
+
const existing = await github.getLatestBotReview(owner, repo, prNumber, headSha, getRuntimeConfig()?.botLogin);
|
|
95
|
+
if (existing)
|
|
96
|
+
return succeed(`already reviewed head ${headSha.slice(0, 7)} (${existing.state})`);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
/* best-effort — fall through and attempt the post */
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Commentable line set from the local checkout diff. Failure → null → all
|
|
103
|
+
// findings demoted to the body (the review still posts).
|
|
104
|
+
const commentable = baseRef ? this.gitCommentableDiff(hostRepoDir, baseRef) : null;
|
|
105
|
+
const review = buildReview(doc, commentable);
|
|
106
|
+
try {
|
|
107
|
+
await github.createPullRequestReview(owner, repo, prNumber, {
|
|
108
|
+
body: review.body,
|
|
109
|
+
event: review.event,
|
|
110
|
+
comments: review.comments,
|
|
111
|
+
commitId: headSha,
|
|
112
|
+
});
|
|
113
|
+
return succeed(`posted review: ${review.inlineCount} inline, ${review.demotedCount} in body, event=${review.event}`);
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
117
|
+
console.warn(`[post-review] inline review POST failed: ${msg}; retrying body-only`);
|
|
118
|
+
// Off-diff anchors (e.g. a stale diff) 422 — retry with everything in the
|
|
119
|
+
// body so the review still lands.
|
|
120
|
+
const bodyOnly = buildBodyOnlyReview(doc);
|
|
121
|
+
try {
|
|
122
|
+
await github.createPullRequestReview(owner, repo, prNumber, {
|
|
123
|
+
body: bodyOnly.body,
|
|
124
|
+
event: bodyOnly.event,
|
|
125
|
+
commitId: headSha,
|
|
126
|
+
});
|
|
127
|
+
return succeed(`posted review (body-only fallback): ${bodyOnly.demotedCount} findings, event=${bodyOnly.event}`);
|
|
128
|
+
}
|
|
129
|
+
catch (err2) {
|
|
130
|
+
const msg2 = err2 instanceof Error ? err2.message : String(err2);
|
|
131
|
+
return fail(`post-review: GitHub rejected the review (inline: ${msg}; body-only: ${msg2})`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** Host path of the run's repo checkout — mirrors sandbox/index.ts layout. */
|
|
136
|
+
resolveHostRepoDir(repo) {
|
|
137
|
+
const config = this.run.config;
|
|
138
|
+
const sandboxBase = resolve(config.sandboxDir || join(config.stateDir || "data", "sandboxes"));
|
|
139
|
+
const workDir = join(sandboxBase, this.run.taskId);
|
|
140
|
+
// pr-review pre-clones into a `<repo>/` subdir (a sibling of the workspace
|
|
141
|
+
// root's AGENTS.md / skill bundle). Fall back to the workspace root if the
|
|
142
|
+
// repo subdir has no findings (defensive — should not happen for pr-review).
|
|
143
|
+
const repoDir = join(workDir, repo);
|
|
144
|
+
if (existsSync(join(repoDir, ".lastlight", "pr-review")))
|
|
145
|
+
return repoDir;
|
|
146
|
+
if (existsSync(join(workDir, ".lastlight", "pr-review")))
|
|
147
|
+
return workDir;
|
|
148
|
+
return repoDir;
|
|
149
|
+
}
|
|
150
|
+
/** Build the GitHub client for the post: token+baseUrl in evals, App auth in prod. */
|
|
151
|
+
buildReviewClient() {
|
|
152
|
+
const baseUrl = this.run.config.githubApiBaseUrl;
|
|
153
|
+
if (baseUrl) {
|
|
154
|
+
// Eval / test path: the mock ignores auth; any bearer token works.
|
|
155
|
+
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN || "eval-fake-token";
|
|
156
|
+
return GitHubClient.withToken(token, baseUrl);
|
|
157
|
+
}
|
|
158
|
+
return new GitHubClient({
|
|
159
|
+
appId: process.env.GITHUB_APP_ID || "",
|
|
160
|
+
privateKeyPath: process.env.GITHUB_APP_PRIVATE_KEY_PATH || "",
|
|
161
|
+
installationId: process.env.GITHUB_APP_INSTALLATION_ID || "",
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
gitHeadSha(repoDir) {
|
|
165
|
+
try {
|
|
166
|
+
return execFileSync("git", ["-C", repoDir, "rev-parse", "HEAD"], { encoding: "utf8" }).trim();
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** Compute the base…head diff locally and parse it into a commentable set. */
|
|
173
|
+
gitCommentableDiff(repoDir, baseRef) {
|
|
174
|
+
const diff = () => execFileSync("git", ["-C", repoDir, "diff", `origin/${baseRef}...HEAD`], {
|
|
175
|
+
encoding: "utf8",
|
|
176
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
177
|
+
});
|
|
178
|
+
try {
|
|
179
|
+
try {
|
|
180
|
+
execFileSync("git", ["-C", repoDir, "fetch", "origin", baseRef, "--depth", "50"], { stdio: "ignore" });
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
/* offline / already present — fall through to diff */
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
return parseDiff(diff());
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
// The `--depth 50` fetch above shallow-clones the base branch. When a PR
|
|
190
|
+
// forked far behind the branch's current tip (a long-lived / stale PR),
|
|
191
|
+
// the merge-base sits beyond that shallow boundary and the three-dot
|
|
192
|
+
// diff dies with "no merge base" — which would demote EVERY finding to
|
|
193
|
+
// the body. Deepen the base history and retry once so the review still
|
|
194
|
+
// anchors inline. Only on this rare failure path do we pay the full
|
|
195
|
+
// fetch. (`--unshallow` no-ops-then-throws on an already-complete repo,
|
|
196
|
+
// hence best-effort.)
|
|
197
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
198
|
+
if (!/no merge base|shallow/i.test(msg))
|
|
199
|
+
throw err;
|
|
200
|
+
try {
|
|
201
|
+
execFileSync("git", ["-C", repoDir, "fetch", "origin", baseRef, "--unshallow"], { stdio: "ignore" });
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
/* already complete / offline — retry the diff regardless */
|
|
205
|
+
}
|
|
206
|
+
return parseDiff(diff());
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
211
|
+
console.warn(`[post-review] git diff failed (${msg}); demoting all findings to the body`);
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** Build the app-registered `post-review` phase-type handler for a run. */
|
|
217
|
+
export function makePostReviewHandler(run, reporter) {
|
|
218
|
+
return new GitHubPostReviewHandler(run, reporter);
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=post-review.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-review.js","sourceRoot":"","sources":["../../../src/workflows/handlers/post-review.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,SAAS,GAEV,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAuB1D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,uBAAuB;IAEf;IACA;IAFnB,YACmB,GAAuB,EACvB,QAAuB;QADvB,QAAG,GAAH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BAAqB,CAAC,GAAuB,EAAE,QAAuB;IACpF,OAAO,IAAI,uBAAuB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { VerdictArtifactReader } from "lastlight-workflow-engine";
|
|
2
|
+
/**
|
|
3
|
+
* App-side {@link VerdictArtifactReader}: the reviewer loop's on-disk verdict
|
|
4
|
+
* fallback. The reviewer's authoritative verdict lives in `reviewer-verdict.md`
|
|
5
|
+
* (its OUTPUT CONTRACT), so recover it when the stdout `VERDICT:` marker is
|
|
6
|
+
* missing. Server mode reads the harvested doc from the build-asset store; repo
|
|
7
|
+
* mode reads the committed doc from the host checkout under `issueDir`. Returns
|
|
8
|
+
* the parsed verdict only when the file actually carries a `VERDICT:` marker
|
|
9
|
+
* (else undefined — we don't launder the same fragile fallback through a
|
|
10
|
+
* different source).
|
|
11
|
+
*
|
|
12
|
+
* Coupled to the filesystem + build-asset store, hence app-side and injected.
|
|
13
|
+
*/
|
|
14
|
+
export declare const fileVerdictReader: VerdictArtifactReader;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { BuildAssetStore } from "../../state/build-assets.js";
|
|
4
|
+
import { parseReviewerVerdict } from "lastlight-workflow-engine";
|
|
5
|
+
/**
|
|
6
|
+
* App-side {@link VerdictArtifactReader}: the reviewer loop's on-disk verdict
|
|
7
|
+
* fallback. The reviewer's authoritative verdict lives in `reviewer-verdict.md`
|
|
8
|
+
* (its OUTPUT CONTRACT), so recover it when the stdout `VERDICT:` marker is
|
|
9
|
+
* missing. Server mode reads the harvested doc from the build-asset store; repo
|
|
10
|
+
* mode reads the committed doc from the host checkout under `issueDir`. Returns
|
|
11
|
+
* the parsed verdict only when the file actually carries a `VERDICT:` marker
|
|
12
|
+
* (else undefined — we don't launder the same fragile fallback through a
|
|
13
|
+
* different source).
|
|
14
|
+
*
|
|
15
|
+
* Coupled to the filesystem + build-asset store, hence app-side and injected.
|
|
16
|
+
*/
|
|
17
|
+
export const fileVerdictReader = {
|
|
18
|
+
read({ config, repo, issueDir, taskId }) {
|
|
19
|
+
let text;
|
|
20
|
+
if (config.buildAssets === "server" && config.buildAssetsDir && config.buildAssetsKey) {
|
|
21
|
+
try {
|
|
22
|
+
text = new BuildAssetStore(config.buildAssetsDir).read(config.buildAssetsKey, "reviewer-verdict.md");
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
/* fall through to the workspace copy */
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!text && issueDir) {
|
|
29
|
+
const path = join(resolveHostRepoDir(config, taskId, repo), issueDir, "reviewer-verdict.md");
|
|
30
|
+
try {
|
|
31
|
+
if (existsSync(path))
|
|
32
|
+
text = readFileSync(path, "utf8");
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* ignore — no recoverable verdict */
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!text)
|
|
39
|
+
return undefined;
|
|
40
|
+
const parsed = parseReviewerVerdict(text);
|
|
41
|
+
return parsed.viaFallback ? undefined : parsed;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/** Host path of the run's repo checkout — mirrors sandbox/index.ts layout. */
|
|
45
|
+
function resolveHostRepoDir(config, taskId, repo) {
|
|
46
|
+
const sandboxBase = resolve(config.sandboxDir || join(config.stateDir || "data", "sandboxes"));
|
|
47
|
+
const workDir = join(sandboxBase, taskId);
|
|
48
|
+
const repoDir = join(workDir, repo);
|
|
49
|
+
if (existsSync(join(repoDir, ".lastlight", "pr-review")))
|
|
50
|
+
return repoDir;
|
|
51
|
+
if (existsSync(join(workDir, ".lastlight", "pr-review")))
|
|
52
|
+
return workDir;
|
|
53
|
+
return repoDir;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=verdict-reader.js.map
|
|
@@ -0,0 +1 @@
|
|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B,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;IACjD,CAAC;CACF,CAAC;AAEF,8EAA8E;AAC9E,SAAS,kBAAkB,CAAC,MAAsB,EAAE,MAAc,EAAE,IAAY;IAC9E,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC/F,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACpC,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;QAAE,OAAO,OAAO,CAAC;IACzE,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;QAAE,OAAO,OAAO,CAAC;IACzE,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export shim. The workflow/asset loader now lives in `lastlight-shared`
|
|
3
|
+
* (both the CLI's `fork` and the harness use it). This file preserves the
|
|
4
|
+
* original `#src/workflows/loader.js` import path so the many in-tree importers
|
|
5
|
+
* — and the `vi.mock("#src/workflows/loader.js")` targets in the test suite —
|
|
6
|
+
* keep resolving to the same module singleton (its layer/cache state is
|
|
7
|
+
* process-global). See docs/plans/monorepo-migration Phase 4.
|
|
8
|
+
*/
|
|
9
|
+
export * from "lastlight-shared/workflow-loader";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export shim. The workflow/asset loader now lives in `lastlight-shared`
|
|
3
|
+
* (both the CLI's `fork` and the harness use it). This file preserves the
|
|
4
|
+
* original `#src/workflows/loader.js` import path so the many in-tree importers
|
|
5
|
+
* — and the `vi.mock("#src/workflows/loader.js")` targets in the test suite —
|
|
6
|
+
* keep resolving to the same module singleton (its layer/cache state is
|
|
7
|
+
* process-global). See docs/plans/monorepo-migration Phase 4.
|
|
8
|
+
*/
|
|
9
|
+
export * from "lastlight-shared/workflow-loader";
|
|
10
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/workflows/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "lastlight-workflow-engine";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-eval.js","sourceRoot":"","sources":["../../src/workflows/loop-eval.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "lastlight-workflow-engine";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The PhaseExecutor now lives in the workflow engine
|
|
2
|
+
// (`workflow-engine/core/phase-executor.ts`). This one-line re-export keeps the
|
|
3
|
+
// old `src/workflows/phase-executor.js` import path (runner, tests via the
|
|
4
|
+
// `#src/workflows/phase-executor.js` alias) resolving unchanged.
|
|
5
|
+
export * from "lastlight-workflow-engine";
|
|
6
|
+
//# sourceMappingURL=phase-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phase-executor.js","sourceRoot":"","sources":["../../src/workflows/phase-executor.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,gFAAgF;AAChF,2EAA2E;AAC3E,iEAAiE;AACjE,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "lastlight-workflow-engine";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phase-ref.js","sourceRoot":"","sources":["../../src/workflows/phase-ref.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { StateDb, WorkflowRun } from "../state/db.js";
|
|
2
|
+
import type { ExecutorConfig } from "../engine/github/profiles.js";
|
|
3
|
+
import type { GitHubClient } from "../engine/github/github.js";
|
|
4
|
+
import type { ModelConfig, VariantConfig } from "../config/config.js";
|
|
5
|
+
import { type ApprovalGateConfig } from "./runner.js";
|
|
6
|
+
export interface ResumeOptions {
|
|
7
|
+
db: StateDb;
|
|
8
|
+
github: GitHubClient | null;
|
|
9
|
+
config: ExecutorConfig;
|
|
10
|
+
models?: ModelConfig;
|
|
11
|
+
variants?: VariantConfig;
|
|
12
|
+
approvalConfig?: ApprovalGateConfig;
|
|
13
|
+
bootstrapLabel?: string;
|
|
14
|
+
/** Post a message to a Slack channel/thread. Used to resume Slack-originated workflows. */
|
|
15
|
+
slackPoster?: (channelId: string, threadId: string, msg: string) => Promise<void>;
|
|
16
|
+
/** Public base URL of the admin dashboard — for the checklist's live-run link. */
|
|
17
|
+
publicUrl?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse `cliftonc/drizby#18` (or `cliftonc/drizby::workflow-name`) into
|
|
21
|
+
* its components. Returns null for Slack/chat-originated trigger ids —
|
|
22
|
+
* those runs resume via the messaging connector, not GitHub refetch.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseTriggerId(triggerId: string): {
|
|
25
|
+
owner: string;
|
|
26
|
+
repo: string;
|
|
27
|
+
} | null;
|
|
28
|
+
/**
|
|
29
|
+
* Parse a Slack trigger id of the form `slack:{teamId}:{channel}:{thread}`.
|
|
30
|
+
* Returns null for anything else. Used by the runner bridge to reconstruct
|
|
31
|
+
* channel/thread coordinates when resuming a Slack-initiated explore run.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseSlackTriggerId(triggerId: string): {
|
|
34
|
+
teamId: string;
|
|
35
|
+
channelId: string;
|
|
36
|
+
threadTs: string;
|
|
37
|
+
} | null;
|
|
38
|
+
/**
|
|
39
|
+
* Resume a workflow run by calling runWorkflow directly with the existing
|
|
40
|
+
* workflowId. We bypass runSimpleWorkflow because that wrapper always creates a
|
|
41
|
+
* fresh workflow_runs row — we want to keep the existing one and let the
|
|
42
|
+
* runner's per-phase dedup (`shouldRunPhase`) handle "what's already done".
|
|
43
|
+
*
|
|
44
|
+
* Two callers, same machinery:
|
|
45
|
+
* - `resumeOrphanedWorkflows` — boot recovery of `running` runs after a crash.
|
|
46
|
+
* - the admin/CLI **retry** path (`config.retryWorkflow` in `src/index.ts`) —
|
|
47
|
+
* a user retrying a `failed` run. The failed phase's ledger row is
|
|
48
|
+
* `success=0`, so it re-runs while already-succeeded phases skip; context is
|
|
49
|
+
* reconstructed here from the stored `run.context` + `run.scratch`, which is
|
|
50
|
+
* why retry works for Slack-thread-scoped runs the lossy `resumeWorkflow`
|
|
51
|
+
* (owner/repo/issueNumber) path can't handle.
|
|
52
|
+
*
|
|
53
|
+
* The caller MUST have already flipped the row to `running` (`setRunning` /
|
|
54
|
+
* `restartRun`) — this function does not change the pre-run status, only the
|
|
55
|
+
* terminal `finishRun` at the end.
|
|
56
|
+
*/
|
|
57
|
+
export declare function resumeSimpleRun(run: WorkflowRun, opts: ResumeOptions): Promise<void>;
|
|
58
|
+
export declare function resumeOrphanedWorkflows(opts: ResumeOptions): Promise<void>;
|