lastlight-core 0.25.9 → 0.27.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.
- package/config/default.yaml +317 -1
- package/dist/admin/chat-session-reader.d.ts +3 -3
- package/dist/admin/chat-session-reader.js +8 -8
- package/dist/admin/chat-session-reader.js.map +1 -1
- package/dist/admin/docker.js.map +1 -1
- package/dist/admin/routes.js +97 -99
- package/dist/admin/routes.js.map +1 -1
- package/dist/admin/sessions.d.ts +7 -7
- package/dist/admin/sessions.js +6 -4
- package/dist/admin/sessions.js.map +1 -1
- package/dist/admin/tail.js.map +1 -1
- package/dist/config/config.d.ts +29 -0
- package/dist/config/config.js +141 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/repo-config.js +6 -7
- package/dist/config/repo-config.js.map +1 -1
- package/dist/connectors/messaging/base.js +2 -2
- package/dist/connectors/messaging/base.js.map +1 -1
- package/dist/connectors/messaging/session-manager.d.ts +29 -31
- package/dist/connectors/messaging/session-manager.js +156 -189
- package/dist/connectors/messaging/session-manager.js.map +1 -1
- package/dist/connectors/messaging/thread-transcript.d.ts +2 -2
- package/dist/connectors/messaging/thread-transcript.js +14 -8
- package/dist/connectors/messaging/thread-transcript.js.map +1 -1
- package/dist/connectors/slack/connector.js +5 -5
- package/dist/connectors/slack/connector.js.map +1 -1
- package/dist/cron/dependabot-discovery.js.map +1 -1
- package/dist/cron/feedback-poll.js +6 -6
- package/dist/cron/feedback-poll.js.map +1 -1
- package/dist/cron/handlers.js +3 -3
- package/dist/cron/handlers.js.map +1 -1
- package/dist/cron/jobs.d.ts +1 -1
- package/dist/cron/jobs.js +2 -2
- package/dist/cron/jobs.js.map +1 -1
- package/dist/cron/repo-digest.js +4 -4
- package/dist/cron/repo-digest.js.map +1 -1
- package/dist/cron/review-discovery.js.map +1 -1
- package/dist/cron/runner.js +2 -2
- package/dist/cron/runner.js.map +1 -1
- package/dist/cron/scheduler.js +1 -1
- package/dist/cron/scheduler.js.map +1 -1
- package/dist/engine/agent-executor.d.ts +25 -1
- package/dist/engine/agent-executor.js +41 -1
- package/dist/engine/agent-executor.js.map +1 -1
- package/dist/engine/chat/chat-prompt.d.ts +11 -4
- package/dist/engine/chat/chat-prompt.js.map +1 -1
- package/dist/engine/chat/chat-runner.d.ts +3 -2
- package/dist/engine/chat/chat-runner.js +9 -7
- package/dist/engine/chat/chat-runner.js.map +1 -1
- package/dist/engine/dispatcher.js +29 -25
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/event-shim.d.ts +18 -0
- package/dist/engine/event-shim.js +2 -0
- package/dist/engine/event-shim.js.map +1 -1
- package/dist/engine/executors/orchestrator.d.ts +120 -1
- package/dist/engine/executors/orchestrator.js +214 -47
- package/dist/engine/executors/orchestrator.js.map +1 -1
- package/dist/engine/executors/shared.js.map +1 -1
- package/dist/engine/feedback/ingest.d.ts +4 -4
- package/dist/engine/feedback/ingest.js +13 -13
- package/dist/engine/feedback/ingest.js.map +1 -1
- package/dist/engine/feedback/slack.d.ts +2 -2
- package/dist/engine/feedback/slack.js +6 -6
- package/dist/engine/feedback/slack.js.map +1 -1
- package/dist/engine/fix-harvest.d.ts +1 -1
- package/dist/engine/fix-harvest.js +3 -3
- package/dist/engine/fix-harvest.js.map +1 -1
- package/dist/engine/github/github.d.ts +59 -0
- package/dist/engine/github/github.js +72 -0
- package/dist/engine/github/github.js.map +1 -1
- package/dist/engine/github/installations.js.map +1 -1
- package/dist/engine/github/review-poster.d.ts +388 -9
- package/dist/engine/github/review-poster.js +550 -50
- package/dist/engine/github/review-poster.js.map +1 -1
- package/dist/engine/github/team-visibility.js +7 -7
- package/dist/engine/github/team-visibility.js.map +1 -1
- package/dist/engine/llm.js.map +1 -1
- package/dist/engine/pr-decisions.d.ts +13 -5
- package/dist/engine/pr-decisions.js +204 -5
- package/dist/engine/pr-decisions.js.map +1 -1
- package/dist/engine/pr-escalation.js +7 -7
- package/dist/engine/pr-escalation.js.map +1 -1
- package/dist/engine/pr-state.d.ts +59 -1
- package/dist/engine/pr-state.js +76 -10
- package/dist/engine/pr-state.js.map +1 -1
- package/dist/engine/review-check.d.ts +1 -1
- package/dist/engine/review-check.js +5 -5
- package/dist/engine/review-check.js.map +1 -1
- package/dist/engine/review-spec.d.ts +264 -0
- package/dist/engine/review-spec.js +723 -0
- package/dist/engine/review-spec.js.map +1 -0
- package/dist/engine/router.js +3 -3
- package/dist/engine/router.js.map +1 -1
- package/dist/engine/screen/classifier.js.map +1 -1
- package/dist/engine/screen/screen.js.map +1 -1
- package/dist/evals-api.d.ts +3 -0
- package/dist/evals-api.js +20 -0
- package/dist/evals-api.js.map +1 -1
- package/dist/index.js +145 -67
- package/dist/index.js.map +1 -1
- package/dist/notify/digest-blocks.js.map +1 -1
- package/dist/notify/model.js.map +1 -1
- package/dist/notify/transports/github.js.map +1 -1
- package/dist/notify/transports/slack.js.map +1 -1
- package/dist/sandbox/artifact-backend.js.map +1 -1
- package/dist/sandbox/artifact-store.js.map +1 -1
- package/dist/sandbox/docker.d.ts +56 -5
- package/dist/sandbox/docker.js +96 -2
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/egress-allowlist.js.map +1 -1
- package/dist/sandbox/k8s/agent-context-registry.js.map +1 -1
- package/dist/sandbox/k8s/client.js.map +1 -1
- package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +3 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js +9 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
- package/dist/sandbox/k8s/pod.d.ts +11 -0
- package/dist/sandbox/k8s/pod.js +11 -6
- package/dist/sandbox/k8s/pod.js.map +1 -1
- package/dist/sandbox/k8s/resource-name.js.map +1 -1
- package/dist/sandbox/k8s/run-id.js.map +1 -1
- package/dist/sandbox/k8s/run-secrets.js.map +1 -1
- package/dist/sandbox/k8s/service-containers.d.ts +43 -0
- package/dist/sandbox/k8s/service-containers.js +87 -0
- package/dist/sandbox/k8s/service-containers.js.map +1 -0
- package/dist/sandbox/k8s/skill-bundle.js.map +1 -1
- package/dist/sandbox/k8s/workspace-provisioner.js +10 -2
- package/dist/sandbox/k8s/workspace-provisioner.js.map +1 -1
- package/dist/sandbox/reap.d.ts +9 -0
- package/dist/sandbox/reap.js +36 -0
- package/dist/sandbox/reap.js.map +1 -1
- package/dist/sandbox/sandbox.d.ts +34 -0
- package/dist/sandbox/sandbox.js +36 -6
- package/dist/sandbox/sandbox.js.map +1 -1
- package/dist/sandbox/service-containers-docker.d.ts +45 -0
- package/dist/sandbox/service-containers-docker.js +78 -0
- package/dist/sandbox/service-containers-docker.js.map +1 -0
- package/dist/session-log.js.map +1 -1
- package/dist/state/approval-store.d.ts +23 -14
- package/dist/state/approval-store.js +137 -86
- package/dist/state/approval-store.js.map +1 -1
- package/dist/state/build-assets.js.map +1 -1
- package/dist/state/client.d.ts +105 -0
- package/dist/state/client.js +68 -0
- package/dist/state/client.js.map +1 -0
- package/dist/state/cron-run-store.d.ts +32 -12
- package/dist/state/cron-run-store.js +105 -39
- package/dist/state/cron-run-store.js.map +1 -1
- package/dist/state/data-migrate.d.ts +135 -0
- package/dist/state/data-migrate.js +309 -0
- package/dist/state/data-migrate.js.map +1 -0
- package/dist/state/db.d.ts +82 -23
- package/dist/state/db.js +201 -105
- package/dist/state/db.js.map +1 -1
- package/dist/state/dialect.d.ts +77 -0
- package/dist/state/dialect.js +129 -0
- package/dist/state/dialect.js.map +1 -0
- package/dist/state/execution-store.d.ts +124 -103
- package/dist/state/execution-store.js +569 -374
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/feedback-store.d.ts +20 -20
- package/dist/state/feedback-store.js +241 -187
- package/dist/state/feedback-store.js.map +1 -1
- package/dist/state/legacy-sqlite.d.ts +15 -0
- package/dist/state/legacy-sqlite.js +131 -0
- package/dist/state/legacy-sqlite.js.map +1 -0
- package/dist/state/pg-client.d.ts +44 -0
- package/dist/state/pg-client.js +81 -0
- package/dist/state/pg-client.js.map +1 -0
- package/dist/state/repo-ref.d.ts +9 -4
- package/dist/state/repo-ref.js +12 -6
- package/dist/state/repo-ref.js.map +1 -1
- package/dist/state/schema/pg.d.ts +2788 -0
- package/dist/state/schema/pg.js +301 -0
- package/dist/state/schema/pg.js.map +1 -0
- package/dist/state/schema/sqlite.d.ts +3063 -0
- package/dist/state/schema/sqlite.js +391 -0
- package/dist/state/schema/sqlite.js.map +1 -0
- package/dist/state/state-cli.d.ts +8 -0
- package/dist/state/state-cli.js +247 -0
- package/dist/state/state-cli.js.map +1 -0
- package/dist/state/team-store.d.ts +26 -13
- package/dist/state/team-store.js +140 -93
- package/dist/state/team-store.js.map +1 -1
- package/dist/state/user-store.d.ts +31 -13
- package/dist/state/user-store.js +180 -80
- package/dist/state/user-store.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +95 -56
- package/dist/state/workflow-run-store.js +419 -314
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/telemetry/index.js.map +1 -1
- package/dist/workflows/admission.d.ts +4 -3
- package/dist/workflows/admission.js +34 -10
- package/dist/workflows/admission.js.map +1 -1
- package/dist/workflows/handlers/fanout.d.ts +157 -0
- package/dist/workflows/handlers/fanout.js +663 -0
- package/dist/workflows/handlers/fanout.js.map +1 -0
- package/dist/workflows/handlers/post-review.d.ts +98 -8
- package/dist/workflows/handlers/post-review.js +394 -23
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/resume.js +22 -15
- package/dist/workflows/resume.js.map +1 -1
- package/dist/workflows/runner.js +60 -12
- package/dist/workflows/runner.js.map +1 -1
- package/dist/workflows/simple.d.ts +23 -0
- package/dist/workflows/simple.js +40 -16
- package/dist/workflows/simple.js.map +1 -1
- package/docker-compose.yml +50 -0
- package/drizzle/pg/0000_init.sql +235 -0
- package/drizzle/pg/meta/0000_snapshot.json +1751 -0
- package/drizzle/pg/meta/_journal.json +13 -0
- package/drizzle/sqlite/0000_baseline.sql +257 -0
- package/drizzle/sqlite/0001_backfill_repo_refs.sql +74 -0
- package/drizzle/sqlite/meta/0000_snapshot.json +1593 -0
- package/drizzle/sqlite/meta/0001_snapshot.json +1593 -0
- package/drizzle/sqlite/meta/_journal.json +20 -0
- package/package.json +31 -15
- package/sandbox.Dockerfile +54 -0
- package/skills/code-review/SKILL.md +98 -13
- package/skills/pr-review/SKILL.md +97 -21
- package/skills/pr-review/references/findings-schema.md +37 -6
- package/workflows/pr-review.yaml +567 -0
- package/workflows/prompts/dependabot-pr-merge.md +22 -2
- package/workflows/prompts/review-adjudicate.md +323 -0
- package/workflows/prompts/review-falsify.md +149 -0
- package/workflows/prompts/review.md +80 -0
- package/workflows/prompts/survey-contract.md +109 -0
- package/workflows/prompts/survey-enforcement.md +126 -0
- package/workflows/prompts/survey-security.md +118 -0
- package/workflows/prompts/survey-spec.md +110 -0
- package/workflows/prompts/survey-state.md +143 -0
- package/workflows/prompts/survey-tests.md +99 -0
- package/dist/state/migrate.d.ts +0 -15
- package/dist/state/migrate.js +0 -518
- package/dist/state/migrate.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { buildReadSkillTool, loadChatSkillCatalogue } from "./engine/chat/chat-s
|
|
|
14
14
|
import { configureGitAuth } from "./engine/github/git-auth.js";
|
|
15
15
|
import { getInstallationDirectory, initInstallationDirectory, } from "./engine/github/installations.js";
|
|
16
16
|
import { StateDb, isTriggerActorType } from "./state/db.js";
|
|
17
|
+
import { redactDbUrl } from "lastlight-shared/database-url";
|
|
17
18
|
import { CronScheduler } from "./cron/scheduler.js";
|
|
18
19
|
import { getJobs } from "./cron/jobs.js";
|
|
19
20
|
import { makeCronRunner } from "./cron/runner.js";
|
|
@@ -38,7 +39,7 @@ import { GitHubClient } from "./engine/github/github.js";
|
|
|
38
39
|
import { setInstallationRepos, isManagedRepo, unmanagedReposInContext } from "./managed-repos.js";
|
|
39
40
|
import { screenForInjection, flagPrefix } from "./engine/screen/screen.js";
|
|
40
41
|
import { runSimpleWorkflow, resolveRepoRunConfig, PR_HEADREF_PREPOPULATE_WORKFLOWS, PR_FIX_SHAPED_WORKFLOWS, } from "./workflows/simple.js";
|
|
41
|
-
import { resolvePrState, prScopedWorkflows } from "./engine/pr-state.js";
|
|
42
|
+
import { resolvePrState, resolveSpecContext, prScopedWorkflows, } from "./engine/pr-state.js";
|
|
42
43
|
import { renderContext } from "./engine/pr-decisions.js";
|
|
43
44
|
import { REVIEW_WORKFLOW, bindQueuedReviewCheck, installReviewCheckObserver, openAndBindReviewCheck, } from "./engine/review-check.js";
|
|
44
45
|
import { runDashboardUrl } from "./notify/model.js";
|
|
@@ -177,10 +178,19 @@ async function main() {
|
|
|
177
178
|
});
|
|
178
179
|
// Initialize state database first — ChatRunner needs SessionManager
|
|
179
180
|
// (DB-backed) at construction time.
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
// open() normalizes both forms (plan locked decision 9): a DATABASE_URL like
|
|
182
|
+
// "file:/app/data/lastlight.db" passes through untouched; the bare dbPath
|
|
183
|
+
// fallback gets resolved + `file:`-prefixed inside open(). Do NOT prefix here.
|
|
184
|
+
const dbTarget = config.database.url ?? config.dbPath;
|
|
185
|
+
const db = await StateDb.open(dbTarget, {
|
|
186
|
+
driver: config.database.driver,
|
|
187
|
+
poolMax: config.database.poolMax,
|
|
188
|
+
});
|
|
189
|
+
// NEVER log dbTarget raw: on the Postgres runtime it carries the userinfo,
|
|
190
|
+
// and operational logs go to a sink that outlives the process.
|
|
191
|
+
configLog.info("Database", { path: redactDbUrl(dbTarget), dialect: db.dialect });
|
|
182
192
|
// Session manager for messaging connectors (shared across Slack, Discord, etc.)
|
|
183
|
-
const sessionManager = new SessionManager(db.
|
|
193
|
+
const sessionManager = new SessionManager(db.client, db.dialect);
|
|
184
194
|
// In-process chat runner backs the messaging chat skill. One pi-ai
|
|
185
195
|
// conversation per Slack/Discord thread; locked down to read-only
|
|
186
196
|
// GitHub tools plus a `read_skill` tool that exposes the curated
|
|
@@ -211,11 +221,20 @@ async function main() {
|
|
|
211
221
|
// and the dashboard's per-workflow kill switch changes that without a
|
|
212
222
|
// restart. The persona and skill catalogue are boot-stable, so only the
|
|
213
223
|
// suffix is re-derived (and it caches on the loader's asset version).
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
224
|
+
// The kill-switch predicate `chatSystemSuffix` takes stays SYNCHRONOUS
|
|
225
|
+
// (it is applied inside `.filter()` callbacks), so the enabled set is
|
|
226
|
+
// resolved ONCE per turn here and closed over — one read rather than one
|
|
227
|
+
// per workflow.
|
|
228
|
+
systemPrompt: async () => {
|
|
229
|
+
const overrides = await db.getAllWorkflowOverrides();
|
|
230
|
+
return (agentContext +
|
|
231
|
+
chatSystemSuffix(githubAuth !== undefined, {
|
|
232
|
+
// Same rule as `db.isWorkflowEnabled`: enabled unless an explicit
|
|
233
|
+
// row says otherwise.
|
|
234
|
+
isWorkflowEnabled: (name) => overrides.get(name)?.enabled ?? true,
|
|
235
|
+
}) +
|
|
236
|
+
chatSkills.catalogueXml);
|
|
237
|
+
},
|
|
219
238
|
github: chatGithubAuth,
|
|
220
239
|
extraTools: chatSkills.skills.length > 0
|
|
221
240
|
? { tools: [readSkill.tool], execute: readSkill.execute }
|
|
@@ -262,7 +281,7 @@ async function main() {
|
|
|
262
281
|
// grade instead of starting the backend from zero. Bounded per boot; a no-op
|
|
263
282
|
// when telemetry is disabled or there is no backlog.
|
|
264
283
|
if (config.feedback.enabled && config.feedback.otel)
|
|
265
|
-
drainFeedbackExport(db);
|
|
284
|
+
await drainFeedbackExport(db);
|
|
266
285
|
// Discover the repos the App can access — across EVERY installation — and seed
|
|
267
286
|
// the managed-repo list. When the overlay's `managedRepos` is empty this
|
|
268
287
|
// becomes the effective allowlist (getManagedRepos falls back to the union); a
|
|
@@ -555,7 +574,36 @@ async function main() {
|
|
|
555
574
|
// moved on. One projection at one choke point is what makes the webhook and
|
|
556
575
|
// cron dispatches of a `pr-fix`-shaped workflow carry identical context.
|
|
557
576
|
if (prState) {
|
|
558
|
-
|
|
577
|
+
const reviewConfig = repoConfig?.review ?? config.review;
|
|
578
|
+
// The `spec` axis's two live reads — the issues this PR closes, and its
|
|
579
|
+
// changed-file list (`docs/plans/deterministic-pr-levers.md` §Decisions,
|
|
580
|
+
// D7). Gated on
|
|
581
|
+
// `review.analysis.enabled`, which is operator-only, so a repo can neither
|
|
582
|
+
// buy itself the extra reads nor opt out of the operator's pipeline.
|
|
583
|
+
//
|
|
584
|
+
// HERE rather than inside `resolvePrState` for two reasons: the reads cost
|
|
585
|
+
// something and nothing but the reviewer consumes them, and locked
|
|
586
|
+
// decision 8 wants the disabled path to fetch nothing at all so the
|
|
587
|
+
// projection has nothing to project. Enriching at the choke point covers
|
|
588
|
+
// every route — including the webhook's, whose snapshot arrives on
|
|
589
|
+
// `_prState` already resolved and is enriched in place before it is
|
|
590
|
+
// persisted below.
|
|
591
|
+
//
|
|
592
|
+
// Never throws; a failed read degrades the obligation set and says so in
|
|
593
|
+
// the block rather than failing the dispatch.
|
|
594
|
+
//
|
|
595
|
+
// Scoped to `REVIEW_WORKFLOW` — the same constant `review-check.ts` gates
|
|
596
|
+
// its own check-run projection on — rather than to every PR-scoped
|
|
597
|
+
// workflow. The reviewer is the only consumer, and the fix family's
|
|
598
|
+
// prompts are template files that would render none of these variables
|
|
599
|
+
// while still paying for the reads. The cost of naming the workflow is
|
|
600
|
+
// that a deployment which remaps `routes.github.pr_opened` to a FORK of
|
|
601
|
+
// `pr-review` gets the plumbing but no obligations; that is a degradation
|
|
602
|
+
// the block announces, not a silent one.
|
|
603
|
+
if (reviewConfig.analysis.enabled && workflowName === REVIEW_WORKFLOW) {
|
|
604
|
+
await resolveSpecContext(prState, { github });
|
|
605
|
+
}
|
|
606
|
+
Object.assign(extra, renderContext(prState, repoConfig?.fix ?? config.fix, repoConfig?.dependencies ?? config.dependencies, reviewConfig));
|
|
559
607
|
extra.prState = prState;
|
|
560
608
|
}
|
|
561
609
|
// For PR-scoped read workflows, resolve the PR head ref and ask the
|
|
@@ -730,7 +778,7 @@ async function main() {
|
|
|
730
778
|
// what lets a reaction minutes later resolve to this exact run
|
|
731
779
|
// rather than merely to the thread.
|
|
732
780
|
if (typeof ts === "string" && config.feedback.enabled) {
|
|
733
|
-
registerSlackAnchor(db, {
|
|
781
|
+
await registerSlackAnchor(db, {
|
|
734
782
|
channelId,
|
|
735
783
|
threadId,
|
|
736
784
|
messageId: ts,
|
|
@@ -748,7 +796,7 @@ async function main() {
|
|
|
748
796
|
// failure, so recording outside it would write a message the user
|
|
749
797
|
// never saw and have the next chat turn rehydrate it as fact —
|
|
750
798
|
// the exact context drift the transcript exists to prevent.
|
|
751
|
-
recordThreadMessageForThread(sessionManager, "slack", channelId, threadId, "assistant", msg);
|
|
799
|
+
await recordThreadMessageForThread(sessionManager, "slack", channelId, threadId, "assistant", msg);
|
|
752
800
|
}
|
|
753
801
|
catch (err) {
|
|
754
802
|
log.warn("Failed to post to Slack thread", { err });
|
|
@@ -761,10 +809,11 @@ async function main() {
|
|
|
761
809
|
// the runner a ProgressNotifier instead of letting it post a comment per
|
|
762
810
|
// phase. The notifier is created inside onRunStart because it needs the
|
|
763
811
|
// workflow-run id (only known once simple.ts creates the row) to persist
|
|
764
|
-
// its in-place update handles to scratch.notifier.
|
|
765
|
-
//
|
|
766
|
-
//
|
|
767
|
-
// the
|
|
812
|
+
// its in-place update handles to scratch.notifier. It is ready in time
|
|
813
|
+
// because **simple.ts AWAITS onRunStart** before dispatching — the
|
|
814
|
+
// guarantee used to come from the driver being synchronous, which it no
|
|
815
|
+
// longer is, so the ordering is now explicit rather than incidental. The
|
|
816
|
+
// proxy still guards the brief window before assignment.
|
|
768
817
|
// Which in-place surface(s) can the checklist edit? Knowable synchronously
|
|
769
818
|
// (transport existence needs only github/issue or slack/channel/thread —
|
|
770
819
|
// the run id is needed solely for persistence + resume handles).
|
|
@@ -795,12 +844,22 @@ async function main() {
|
|
|
795
844
|
}
|
|
796
845
|
: undefined;
|
|
797
846
|
const notifierOnRunStart = statusChecklist
|
|
798
|
-
? (runId) => {
|
|
847
|
+
? async (runId) => {
|
|
799
848
|
try {
|
|
800
|
-
const saved = ((db.runs.getRun(runId)?.scratch?.notifier) ?? {});
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
849
|
+
const saved = (((await db.runs.getRun(runId))?.scratch?.notifier) ?? {});
|
|
850
|
+
// Read-modify-write of the notifier handles. The transports' `save`
|
|
851
|
+
// hooks stay SYNCHRONOUS on purpose — they fire from inside
|
|
852
|
+
// `publish()`, mid-post — so this is invoked fire-and-forget there.
|
|
853
|
+
// Losing a handle is cosmetic: a fresh status comment after a
|
|
854
|
+
// restart, never a lost run.
|
|
855
|
+
const persist = async (patch) => {
|
|
856
|
+
const cur = (((await db.runs.getRun(runId))?.scratch?.notifier) ?? {});
|
|
857
|
+
await db.runs.mergeScratch(runId, { notifier: { ...cur, ...patch } });
|
|
858
|
+
};
|
|
859
|
+
const persistHandle = (patch) => {
|
|
860
|
+
void persist(patch).catch((err) => {
|
|
861
|
+
log.warn("Failed to persist notifier handle", { runId, err });
|
|
862
|
+
});
|
|
804
863
|
};
|
|
805
864
|
const transports = [];
|
|
806
865
|
if (ghChecklist && github && typeof issueNumber === "number") {
|
|
@@ -810,7 +869,7 @@ async function main() {
|
|
|
810
869
|
repo,
|
|
811
870
|
issueNumber,
|
|
812
871
|
commentId: saved.githubCommentId,
|
|
813
|
-
save: (id) =>
|
|
872
|
+
save: (id) => persistHandle({ githubCommentId: id }),
|
|
814
873
|
}));
|
|
815
874
|
}
|
|
816
875
|
if (slackChecklist && slackConnector && typeof channelId === "string" && typeof threadId === "string") {
|
|
@@ -819,18 +878,24 @@ async function main() {
|
|
|
819
878
|
channel: channelId,
|
|
820
879
|
thread: threadId,
|
|
821
880
|
ts: saved.slackTs,
|
|
822
|
-
save: (ts) =>
|
|
881
|
+
save: (ts) => persistHandle({ slackTs: ts, slackChannel: channelId, slackThread: threadId }),
|
|
823
882
|
// Every message the notifier posts is reactable: the status
|
|
824
883
|
// checklist, the terminal summary, an approval prompt
|
|
825
884
|
// (issue #255).
|
|
826
885
|
onPost: config.feedback.enabled
|
|
827
|
-
? (ts) =>
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
886
|
+
? (ts) => {
|
|
887
|
+
// Synchronous hook (nothing awaits it), so the anchor
|
|
888
|
+
// write is fired and its failure logged here.
|
|
889
|
+
void registerSlackAnchor(db, {
|
|
890
|
+
channelId,
|
|
891
|
+
threadId,
|
|
892
|
+
messageId: ts,
|
|
893
|
+
workflowRunId: runId,
|
|
894
|
+
workflowName,
|
|
895
|
+
}).catch((err) => {
|
|
896
|
+
log.warn("Failed to register a Slack feedback anchor", { runId, err });
|
|
897
|
+
});
|
|
898
|
+
}
|
|
834
899
|
: undefined,
|
|
835
900
|
}));
|
|
836
901
|
}
|
|
@@ -874,7 +939,7 @@ async function main() {
|
|
|
874
939
|
// boundary and the shared per-PR workspace is `reset --hard`-ed between
|
|
875
940
|
// runs, so a marker not persisted here is gone for good.
|
|
876
941
|
if (harvestRunId)
|
|
877
|
-
harvestFixMarkers(db, harvestRunId, workflowName, phase, result.output);
|
|
942
|
+
await harvestFixMarkers(db, harvestRunId, workflowName, phase, result.output);
|
|
878
943
|
},
|
|
879
944
|
onRunStart: async (runId) => {
|
|
880
945
|
// The run id is not knowable when this object is built — the row is
|
|
@@ -882,12 +947,11 @@ async function main() {
|
|
|
882
947
|
// write the harvest. This callback fires synchronously before the first
|
|
883
948
|
// phase, so the assignment is always in place by the time it is read.
|
|
884
949
|
harvestRunId = runId;
|
|
885
|
-
//
|
|
886
|
-
//
|
|
887
|
-
//
|
|
888
|
-
// the check creation below.
|
|
950
|
+
// Notifier setup must finish before simple.ts calls reporter.start()
|
|
951
|
+
// (the next statement after it invokes this), so it runs FIRST — and is
|
|
952
|
+
// awaited, since its scratch read is no longer synchronous.
|
|
889
953
|
if (notifierOnRunStart)
|
|
890
|
-
notifierOnRunStart(runId);
|
|
954
|
+
await notifierOnRunStart(runId);
|
|
891
955
|
// Create AND bind the review check the moment the row exists — this is
|
|
892
956
|
// what makes it a projection of run state rather than of an in-memory
|
|
893
957
|
// promise, and it is why every terminal path resolves it for free.
|
|
@@ -1006,19 +1070,23 @@ async function main() {
|
|
|
1006
1070
|
// response: the cache is filled on demand per logged-in user, so the next
|
|
1007
1071
|
// dashboard request re-resolves, and only for people who actually use it.
|
|
1008
1072
|
onTeamChanged: ({ org, teamSlug, login }) => {
|
|
1073
|
+
// The hook's contract is synchronous — the webhook connector never
|
|
1074
|
+
// awaits it — so the invalidation is fired and its failure logged here
|
|
1075
|
+
// rather than propagated. The cache refills on demand either way.
|
|
1076
|
+
const warn = (err) => logger("team-visibility").warn("Failed to invalidate team visibility cache", {
|
|
1077
|
+
org,
|
|
1078
|
+
teamSlug,
|
|
1079
|
+
login,
|
|
1080
|
+
err,
|
|
1081
|
+
});
|
|
1009
1082
|
try {
|
|
1010
1083
|
if (login)
|
|
1011
|
-
db.teams.invalidateLogin(login);
|
|
1084
|
+
void db.teams.invalidateLogin(login).catch(warn);
|
|
1012
1085
|
else if (teamSlug)
|
|
1013
|
-
db.teams.invalidateTeam(org, teamSlug);
|
|
1086
|
+
void db.teams.invalidateTeam(org, teamSlug).catch(warn);
|
|
1014
1087
|
}
|
|
1015
1088
|
catch (err) {
|
|
1016
|
-
|
|
1017
|
-
org,
|
|
1018
|
-
teamSlug,
|
|
1019
|
-
login,
|
|
1020
|
-
err,
|
|
1021
|
-
});
|
|
1089
|
+
warn(err);
|
|
1022
1090
|
}
|
|
1023
1091
|
},
|
|
1024
1092
|
});
|
|
@@ -1050,12 +1118,18 @@ async function main() {
|
|
|
1050
1118
|
// precisely; it just isn't a workflow. Matches how the executions
|
|
1051
1119
|
// ledger already names this surface (`skill: "chat"`).
|
|
1052
1120
|
onBotMessage: config.feedback.enabled
|
|
1053
|
-
? ({ channelId, messageId, sessionId }) =>
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1121
|
+
? ({ channelId, messageId, sessionId }) => {
|
|
1122
|
+
// Synchronous hook (the connector never awaits it), so the anchor
|
|
1123
|
+
// write is fired and its failure logged here.
|
|
1124
|
+
void registerSlackAnchor(db, {
|
|
1125
|
+
channelId,
|
|
1126
|
+
messageId,
|
|
1127
|
+
messagingSessionId: sessionId,
|
|
1128
|
+
workflowName: "chat",
|
|
1129
|
+
}).catch((err) => {
|
|
1130
|
+
logger("feedback").warn("Failed to register a Slack feedback anchor", { err });
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1059
1133
|
: undefined,
|
|
1060
1134
|
}, sessionManager);
|
|
1061
1135
|
registry.register(slackConnector);
|
|
@@ -1063,12 +1137,18 @@ async function main() {
|
|
|
1063
1137
|
// `reactions:read` bot scope + the reaction_added/removed subscriptions;
|
|
1064
1138
|
// without them Slack never delivers and this is simply dormant.
|
|
1065
1139
|
if (config.feedback.enabled) {
|
|
1066
|
-
slackConnector.onReactionAction((event) =>
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1140
|
+
slackConnector.onReactionAction((event) => {
|
|
1141
|
+
// The connector's handler slot is synchronous and nothing awaits it, so
|
|
1142
|
+
// the ingest is fired here and a failure logged rather than propagated.
|
|
1143
|
+
void handleSlackReaction({
|
|
1144
|
+
db,
|
|
1145
|
+
botLogin: config.botLogin,
|
|
1146
|
+
otel: config.feedback.otel,
|
|
1147
|
+
allowedUsers: config.slack?.allowedUsers,
|
|
1148
|
+
}, event).catch((err) => {
|
|
1149
|
+
logger("feedback").warn("Failed to handle a Slack reaction", { err });
|
|
1150
|
+
});
|
|
1151
|
+
});
|
|
1072
1152
|
}
|
|
1073
1153
|
}
|
|
1074
1154
|
// Host-side cron handlers — what a `cron-*.yaml` may name in `handler:`.
|
|
@@ -1103,7 +1183,7 @@ async function main() {
|
|
|
1103
1183
|
// exists only in this response — a send site that drops it makes
|
|
1104
1184
|
// the reaction unattributable.
|
|
1105
1185
|
if (typeof ts === "string" && config.feedback.enabled) {
|
|
1106
|
-
registerSlackAnchor(db, { channelId: channel, messageId: ts, workflowName: "repo-digest" });
|
|
1186
|
+
await registerSlackAnchor(db, { channelId: channel, messageId: ts, workflowName: "repo-digest" });
|
|
1107
1187
|
}
|
|
1108
1188
|
},
|
|
1109
1189
|
}
|
|
@@ -1175,9 +1255,7 @@ async function main() {
|
|
|
1175
1255
|
// for the same reason the live `slackPost` above does — a run that finished
|
|
1176
1256
|
// after a restart still owes its thread a transcript.
|
|
1177
1257
|
slackPoster: slackConnector
|
|
1178
|
-
? (channelId, threadId, msg) => slackConnector.sendMessage(channelId, threadId, msg).then(() =>
|
|
1179
|
-
recordThreadMessageForThread(sessionManager, "slack", channelId, threadId, "assistant", msg);
|
|
1180
|
-
})
|
|
1258
|
+
? (channelId, threadId, msg) => slackConnector.sendMessage(channelId, threadId, msg).then(() => recordThreadMessageForThread(sessionManager, "slack", channelId, threadId, "assistant", msg))
|
|
1181
1259
|
: undefined,
|
|
1182
1260
|
};
|
|
1183
1261
|
// Construct the admission controller now that resumeOpts is ready.
|
|
@@ -1259,7 +1337,7 @@ async function main() {
|
|
|
1259
1337
|
adminLog.warn("Cannot resume workflow: missing owner/repo/issueNumber", { runId: workflowRun.id });
|
|
1260
1338
|
return;
|
|
1261
1339
|
}
|
|
1262
|
-
db.runs.setRunning(workflowRun.id);
|
|
1340
|
+
await db.runs.setRunning(workflowRun.id);
|
|
1263
1341
|
adminLog.info("Resuming after dashboard approval", {
|
|
1264
1342
|
workflowName: workflowRun.workflowName,
|
|
1265
1343
|
repo: `${owner}/${repo}`,
|
|
@@ -1295,14 +1373,14 @@ async function main() {
|
|
|
1295
1373
|
// Compare-and-set: flip failed/cancelled→running and clear the terminal
|
|
1296
1374
|
// markers. If a racing retry already flipped it, changes===0 and we don't
|
|
1297
1375
|
// dispatch.
|
|
1298
|
-
const changed = db.runs.restartRun(workflowRun.id);
|
|
1376
|
+
const changed = await db.runs.restartRun(workflowRun.id);
|
|
1299
1377
|
if (changed !== 1) {
|
|
1300
1378
|
adminLog.warn("Retry: run is no longer retryable (raced) — skipping dispatch", {
|
|
1301
1379
|
runId: workflowRun.id,
|
|
1302
1380
|
});
|
|
1303
1381
|
return;
|
|
1304
1382
|
}
|
|
1305
|
-
const fresh = db.runs.getRun(workflowRun.id);
|
|
1383
|
+
const fresh = await db.runs.getRun(workflowRun.id);
|
|
1306
1384
|
if (!fresh)
|
|
1307
1385
|
return;
|
|
1308
1386
|
adminLog.info("Retrying", {
|
|
@@ -1470,7 +1548,7 @@ async function main() {
|
|
|
1470
1548
|
return c.json({ error: "Missing 'message'" }, 400);
|
|
1471
1549
|
const user = typeof body.user === "string" && body.user ? body.user : "cli";
|
|
1472
1550
|
const threadId = typeof body.thread === "string" && body.thread ? body.thread : null;
|
|
1473
|
-
const session = sessionManager.getOrCreateSession({
|
|
1551
|
+
const session = await sessionManager.getOrCreateSession({
|
|
1474
1552
|
platform: "cli", channelId: user, threadId, userId: user,
|
|
1475
1553
|
});
|
|
1476
1554
|
let reply = "";
|
|
@@ -1542,7 +1620,7 @@ async function main() {
|
|
|
1542
1620
|
// otherwise fire periodic no-op dispatch failures.
|
|
1543
1621
|
const webhooksEnabled = !!(config.webhookSecret && config.githubApp);
|
|
1544
1622
|
if (github) {
|
|
1545
|
-
const jobs = getJobs({ webhooksEnabled, db, handlers: cronHandlers });
|
|
1623
|
+
const jobs = await getJobs({ webhooksEnabled, db, handlers: cronHandlers });
|
|
1546
1624
|
for (const job of jobs) {
|
|
1547
1625
|
cron.register(job);
|
|
1548
1626
|
}
|
|
@@ -1654,7 +1732,7 @@ async function main() {
|
|
|
1654
1732
|
telemetryShutdownStarted = true;
|
|
1655
1733
|
await shutdownTelemetry();
|
|
1656
1734
|
}
|
|
1657
|
-
db.close();
|
|
1735
|
+
await db.close();
|
|
1658
1736
|
process.exit(0);
|
|
1659
1737
|
};
|
|
1660
1738
|
process.on("SIGINT", shutdown);
|