lastlight-core 0.25.5 → 0.25.7
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 +52 -1
- package/dist/admin/routes.d.ts +8 -0
- package/dist/admin/routes.js +41 -7
- package/dist/admin/routes.js.map +1 -1
- package/dist/config/config.d.ts +29 -2
- package/dist/config/config.js +28 -1
- package/dist/config/config.js.map +1 -1
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.js +1 -1
- package/dist/connectors/index.js.map +1 -1
- package/dist/connectors/messaging/index.d.ts +0 -1
- package/dist/connectors/messaging/index.js +0 -1
- package/dist/connectors/messaging/index.js.map +1 -1
- package/dist/connectors/slack/connector.d.ts +0 -2
- package/dist/connectors/slack/connector.js +0 -11
- package/dist/connectors/slack/connector.js.map +1 -1
- package/dist/cron/handlers.d.ts +62 -0
- package/dist/cron/handlers.js +90 -0
- package/dist/cron/handlers.js.map +1 -0
- package/dist/cron/jobs.d.ts +7 -0
- package/dist/cron/jobs.js +18 -0
- package/dist/cron/jobs.js.map +1 -1
- package/dist/cron/repo-digest.d.ts +81 -0
- package/dist/cron/repo-digest.js +239 -0
- package/dist/cron/repo-digest.js.map +1 -0
- package/dist/cron/scheduler.d.ts +12 -4
- package/dist/cron/scheduler.js +23 -5
- package/dist/cron/scheduler.js.map +1 -1
- package/dist/engine/github/github.d.ts +44 -0
- package/dist/engine/github/github.js +61 -0
- package/dist/engine/github/github.js.map +1 -1
- package/dist/index.js +50 -9
- package/dist/index.js.map +1 -1
- package/dist/notify/digest-blocks.d.ts +55 -0
- package/dist/notify/digest-blocks.js +128 -0
- package/dist/notify/digest-blocks.js.map +1 -0
- package/dist/notify/repo-channel.d.ts +56 -0
- package/dist/notify/repo-channel.js +68 -0
- package/dist/notify/repo-channel.js.map +1 -0
- package/dist/state/execution-store.d.ts +58 -11
- package/dist/state/execution-store.js +72 -11
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +15 -0
- package/dist/state/workflow-run-store.js +20 -0
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/workflows/simple.d.ts +16 -1
- package/dist/workflows/simple.js +13 -0
- package/dist/workflows/simple.js.map +1 -1
- package/package.json +4 -4
- package/skills/repo-health/SKILL.md +8 -2
- package/skills/security-review/SKILL.md +5 -13
- package/workflows/cron-digest.yaml +11 -0
- package/workflows/cron-security.yaml +0 -2
- package/dist/connectors/messaging/delivery.d.ts +0 -10
- package/dist/connectors/messaging/delivery.js +0 -40
- package/dist/connectors/messaging/delivery.js.map +0 -1
package/dist/cron/jobs.js
CHANGED
|
@@ -71,6 +71,23 @@ export function getJobs(opts) {
|
|
|
71
71
|
// ever see them here, so this is belt-and-braces for anything that reaches us.
|
|
72
72
|
const crons = opts?.crons ?? operatorCrons();
|
|
73
73
|
for (const def of cronDefs) {
|
|
74
|
+
// Resolve a `handler:` cron against the registry BEFORE anything else. An
|
|
75
|
+
// unresolvable name DROPS the cron — the opposite of `condition.unless`,
|
|
76
|
+
// where registering is the safe direction because there is still a workflow
|
|
77
|
+
// to run. Here there is nothing to run, so a registered tick would just
|
|
78
|
+
// throw once a week; the boot-time warning is the useful signal.
|
|
79
|
+
let handler;
|
|
80
|
+
if (def.handler) {
|
|
81
|
+
handler = opts?.handlers?.[def.handler];
|
|
82
|
+
if (!handler) {
|
|
83
|
+
log.warn("Unknown cron handler — cron not registered", {
|
|
84
|
+
cron: def.name,
|
|
85
|
+
handler: def.handler,
|
|
86
|
+
known: Object.keys(opts?.handlers ?? {}),
|
|
87
|
+
});
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
74
91
|
const override = overrides.get(def.name);
|
|
75
92
|
// The dashboard toggle and the operator's `crons.disable` are the same
|
|
76
93
|
// lever spelled two ways — both mean "off by default", both leave the tick
|
|
@@ -80,6 +97,7 @@ export function getJobs(opts) {
|
|
|
80
97
|
name: def.name,
|
|
81
98
|
schedule: override?.schedule || def.schedule,
|
|
82
99
|
workflow: def.workflow,
|
|
100
|
+
handler,
|
|
83
101
|
// Merge managed repos into the context the workflow receives. Use the
|
|
84
102
|
// installation-filtered list so a stale managedRepos entry (repo deleted /
|
|
85
103
|
// transferred / access revoked) doesn't fan out into a doomed scan run
|
package/dist/cron/jobs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../src/cron/jobs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../src/cron/jobs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAG1F,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAO3B;;;;;;;;;;;;;;GAcG;AACH,MAAM,yBAAyB,GAA2D;IACxF,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,eAAe;CAC9C,CAAC;AAEF,kFAAkF;AAClF,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE3C,oEAAoE;AACpE,SAAS,eAAe,CAAC,MAA0B,EAAE,GAAyB;IAC5E,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,SAAS,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC7B,GAAG,CAAC,IAAI,CAAC,wDAAwD,EAAE;g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KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,IAAI,EAAE,CAAC;iBACzC,CAAC,CAAC;gBACH,SAAS;YACX,CAAC;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzC,uEAAuE;QACvE,2EAA2E;QAC3E,qDAAqD;QACrD,MAAM,eAAe,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClG,IAAI,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,QAAQ,EAAE,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,QAAQ;YAC5C,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,OAAO;YACP,sEAAsE;YACtE,2EAA2E;YAC3E,uEAAuE;YACvE,gCAAgC;YAChC,OAAO,EAAE;gBACP,KAAK,EAAE,yBAAyB,EAAE;gBAClC,sEAAsE;gBACtE,8DAA8D;gBAC9D,GAAG,GAAG,CAAC,OAAO;gBACd,sEAAsE;gBACtE,uEAAuE;gBACvE,yEAAyE;gBACzE,wEAAwE;gBACxE,0CAA0C;gBAC1C,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,IAAI;gBACzB,CAAC,yBAAyB,CAAC,EAAE,eAAe;aAC7C;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The weekly repo digest — what happened in a repo, and what Last Light did
|
|
3
|
+
* about it, posted to that repo's Slack channel.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this is code and not a workflow
|
|
6
|
+
*
|
|
7
|
+
* Every other periodic report in the harness is an agent workflow, and both of
|
|
8
|
+
* them (`repo-health`, `security-review`) write an excellent report that
|
|
9
|
+
* reaches nobody: a repo-scoped cron run has no issue and no Slack thread, so
|
|
10
|
+
* the runner's `postComment` callback is undefined and the output dies in an
|
|
11
|
+
* `executions` row. Three structural facts say a digest cannot be fixed by
|
|
12
|
+
* routing that output somewhere:
|
|
13
|
+
*
|
|
14
|
+
* 1. Half the interesting content — runs, failures, escalations, spend —
|
|
15
|
+
* lives in the harness's own SQLite, which a sandboxed phase cannot reach.
|
|
16
|
+
* 2. There is no Slack tool in the sandbox, and `slack.com` is not on the
|
|
17
|
+
* egress allowlist, so an agent cannot post even if it knew what to say.
|
|
18
|
+
* 3. A digest is arithmetic. Asking a model to count merged PRs buys
|
|
19
|
+
* plausible numbers instead of correct ones, at a sandbox per repo.
|
|
20
|
+
*
|
|
21
|
+
* So the facts are gathered here, in the harness process, from the GitHub API
|
|
22
|
+
* and the state DB. The model gets exactly one job — turn those facts into a
|
|
23
|
+
* sentence of English — and if it fails, the digest goes out without it.
|
|
24
|
+
*
|
|
25
|
+
* ## Two invariants
|
|
26
|
+
*
|
|
27
|
+
* **No channel, no post.** A repo with no channel configured is skipped
|
|
28
|
+
* silently. This is what keeps a fresh install quiet: the feature ships on, and
|
|
29
|
+
* does nothing, until somebody names a channel.
|
|
30
|
+
*
|
|
31
|
+
* **One repo's bad day costs only that repo.** Every per-repo step is wrapped;
|
|
32
|
+
* a failure is logged and the loop continues.
|
|
33
|
+
*/
|
|
34
|
+
import type { StateDb } from "../state/db.js";
|
|
35
|
+
import type { GitHubClient, RepoActivityItem } from "../engine/github/github.js";
|
|
36
|
+
import type { DigestConfig } from "../config/config.js";
|
|
37
|
+
import { type ChannelRoutingConfig } from "../notify/repo-channel.js";
|
|
38
|
+
import { type DigestFacts, type RepoFacts } from "../notify/digest-blocks.js";
|
|
39
|
+
/** The slice of {@link GitHubClient} a digest needs — narrow, so tests need no mock of the rest. */
|
|
40
|
+
export interface DigestGitHubClient {
|
|
41
|
+
listRepoActivitySince: GitHubClient["listRepoActivitySince"];
|
|
42
|
+
listOpenPullRequests: GitHubClient["listOpenPullRequests"];
|
|
43
|
+
}
|
|
44
|
+
/** How a rendered digest reaches Slack. Injected so the tests assert on calls, not on Slack. */
|
|
45
|
+
export type DigestPoster = (channel: string, text: string, blocks: unknown[]) => Promise<void>;
|
|
46
|
+
export interface RepoDigestDeps {
|
|
47
|
+
db: StateDb;
|
|
48
|
+
github: DigestGitHubClient;
|
|
49
|
+
/** The GitHub client the repo-config layer is fetched through. Null in chat-only mode. */
|
|
50
|
+
configClient: GitHubClient | null;
|
|
51
|
+
routing: ChannelRoutingConfig | undefined;
|
|
52
|
+
config: DigestConfig;
|
|
53
|
+
post: DigestPoster;
|
|
54
|
+
/** Injectable for tests; defaults to the real one-shot LLM helper. */
|
|
55
|
+
summarize?: (facts: DigestFacts) => Promise<string | undefined>;
|
|
56
|
+
/** Injectable for deterministic tests. */
|
|
57
|
+
now?: () => Date;
|
|
58
|
+
/** The label a terminal skip applies. Digest surfaces these as "needs a human". */
|
|
59
|
+
escalationLabel?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* One tick. `context` is what the scheduler built — `repos` plus the two cron
|
|
63
|
+
* control keys.
|
|
64
|
+
*/
|
|
65
|
+
export declare function runRepoDigest(deps: RepoDigestDeps, context: Record<string, unknown>): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Turn the raw dated items into the counts a digest shows.
|
|
68
|
+
*
|
|
69
|
+
* The window arithmetic lives here rather than in the GitHub client because
|
|
70
|
+
* `listRepoActivitySince` filters on `updated_at`: an issue opened months ago
|
|
71
|
+
* and commented on yesterday is in that response, and counting it as "opened
|
|
72
|
+
* this week" is the obvious wrong answer. Every count below therefore tests the
|
|
73
|
+
* event's OWN timestamp against the window.
|
|
74
|
+
*/
|
|
75
|
+
export declare function summarizeRepo(activity: RepoActivityItem[], openPrs: Array<{
|
|
76
|
+
number: number;
|
|
77
|
+
title: string;
|
|
78
|
+
draft: boolean;
|
|
79
|
+
labels: string[];
|
|
80
|
+
createdAt: string;
|
|
81
|
+
}>, since: Date, now: Date, maxItems: number, escalationLabel?: string): RepoFacts;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The weekly repo digest — what happened in a repo, and what Last Light did
|
|
3
|
+
* about it, posted to that repo's Slack channel.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this is code and not a workflow
|
|
6
|
+
*
|
|
7
|
+
* Every other periodic report in the harness is an agent workflow, and both of
|
|
8
|
+
* them (`repo-health`, `security-review`) write an excellent report that
|
|
9
|
+
* reaches nobody: a repo-scoped cron run has no issue and no Slack thread, so
|
|
10
|
+
* the runner's `postComment` callback is undefined and the output dies in an
|
|
11
|
+
* `executions` row. Three structural facts say a digest cannot be fixed by
|
|
12
|
+
* routing that output somewhere:
|
|
13
|
+
*
|
|
14
|
+
* 1. Half the interesting content — runs, failures, escalations, spend —
|
|
15
|
+
* lives in the harness's own SQLite, which a sandboxed phase cannot reach.
|
|
16
|
+
* 2. There is no Slack tool in the sandbox, and `slack.com` is not on the
|
|
17
|
+
* egress allowlist, so an agent cannot post even if it knew what to say.
|
|
18
|
+
* 3. A digest is arithmetic. Asking a model to count merged PRs buys
|
|
19
|
+
* plausible numbers instead of correct ones, at a sandbox per repo.
|
|
20
|
+
*
|
|
21
|
+
* So the facts are gathered here, in the harness process, from the GitHub API
|
|
22
|
+
* and the state DB. The model gets exactly one job — turn those facts into a
|
|
23
|
+
* sentence of English — and if it fails, the digest goes out without it.
|
|
24
|
+
*
|
|
25
|
+
* ## Two invariants
|
|
26
|
+
*
|
|
27
|
+
* **No channel, no post.** A repo with no channel configured is skipped
|
|
28
|
+
* silently. This is what keeps a fresh install quiet: the feature ships on, and
|
|
29
|
+
* does nothing, until somebody names a channel.
|
|
30
|
+
*
|
|
31
|
+
* **One repo's bad day costs only that repo.** Every per-repo step is wrapped;
|
|
32
|
+
* a failure is logged and the loop continues.
|
|
33
|
+
*/
|
|
34
|
+
import { resolveRepoRunConfig } from "../workflows/simple.js";
|
|
35
|
+
import { resolveRepoChannel } from "../notify/repo-channel.js";
|
|
36
|
+
import { renderDigest } from "../notify/digest-blocks.js";
|
|
37
|
+
import { resolveCronRepos, CRON_GLOBALLY_ENABLED_KEY, CRON_NAME_KEY } from "./repo-crons.js";
|
|
38
|
+
import { callLlm, defaultFastModel } from "../engine/llm.js";
|
|
39
|
+
import { logger } from "../logging/logger.js";
|
|
40
|
+
const log = logger("repo-digest");
|
|
41
|
+
/**
|
|
42
|
+
* One tick. `context` is what the scheduler built — `repos` plus the two cron
|
|
43
|
+
* control keys.
|
|
44
|
+
*/
|
|
45
|
+
export async function runRepoDigest(deps, context) {
|
|
46
|
+
const rawRepos = context.repos;
|
|
47
|
+
if (!Array.isArray(rawRepos)) {
|
|
48
|
+
log.warn("Tick carried no repo list — nothing to digest");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const repos = rawRepos.filter((r) => typeof r === "string" && !!r);
|
|
52
|
+
// Per-repo cron participation. NOTHING upstream does this for a handler cron
|
|
53
|
+
// — `dispatchCronWorkflow` is the workflow path — so a repo's
|
|
54
|
+
// `crons.disable: [repo-digest]` is honoured only because of this call.
|
|
55
|
+
const cron = typeof context[CRON_NAME_KEY] === "string" ? context[CRON_NAME_KEY] : undefined;
|
|
56
|
+
let targets = repos;
|
|
57
|
+
if (cron) {
|
|
58
|
+
const resolution = await resolveCronRepos({
|
|
59
|
+
cron,
|
|
60
|
+
repos,
|
|
61
|
+
// Absent means "on" — the manual "Run now" deliberately omits the key so
|
|
62
|
+
// a globally-disabled digest can still be fired by hand.
|
|
63
|
+
globallyEnabled: context[CRON_GLOBALLY_ENABLED_KEY] !== false,
|
|
64
|
+
});
|
|
65
|
+
targets = resolution.repos;
|
|
66
|
+
}
|
|
67
|
+
if (targets.length === 0) {
|
|
68
|
+
log.debug("No repos participate in this tick", { cron });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const now = deps.now?.() ?? new Date();
|
|
72
|
+
const since = new Date(now.getTime() - deps.config.windowDays * 24 * 60 * 60 * 1000);
|
|
73
|
+
let posted = 0;
|
|
74
|
+
const failed = [];
|
|
75
|
+
for (const target of targets) {
|
|
76
|
+
try {
|
|
77
|
+
posted += (await digestOneRepo(deps, target, since, now)) ? 1 : 0;
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
failed.push(target);
|
|
81
|
+
log.error("Digest failed for repo", { repo: target, err });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
log.info("Digest tick complete", { considered: targets.length, posted, failed: failed.length });
|
|
85
|
+
// One repo's bad day must not cost the others their digest — hence the
|
|
86
|
+
// per-repo catch above. But a tick that swallowed every failure and returned
|
|
87
|
+
// normally would report SUCCESS, and the failures that matter here are not
|
|
88
|
+
// per-repo accidents: a revoked bot token or a bot removed from its channels
|
|
89
|
+
// fails every repo at once, silently, once a week. So the tick fails if any
|
|
90
|
+
// repo did, AFTER the others have been served.
|
|
91
|
+
//
|
|
92
|
+
// Deliberately not conditioned on `posted === 0`: a repo with no channel is
|
|
93
|
+
// skipped, not failed, so "considered 10, posted 0" is the correct and quiet
|
|
94
|
+
// outcome for a deployment that has configured nothing.
|
|
95
|
+
if (failed.length > 0) {
|
|
96
|
+
throw new Error(`Digest failed for ${failed.length} of ${targets.length} repos (${failed.join(", ")}) — ` +
|
|
97
|
+
`see the per-repo errors above. ${posted} posted.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** @returns whether a digest was actually posted. */
|
|
101
|
+
async function digestOneRepo(deps, target, since, now) {
|
|
102
|
+
const slash = target.indexOf("/");
|
|
103
|
+
if (slash <= 0) {
|
|
104
|
+
log.warn("Skipping malformed repo ref", { repo: target });
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const owner = target.slice(0, slash);
|
|
108
|
+
const repo = target.slice(slash + 1);
|
|
109
|
+
// Resolve the channel FIRST. Everything below costs GitHub requests and
|
|
110
|
+
// possibly a model call; there is no point paying for a digest nobody will
|
|
111
|
+
// read. `resolveRepoRunConfig` is the same seam every dispatch uses, so this
|
|
112
|
+
// rides the existing TTL+ETag cache rather than adding a second fetch path.
|
|
113
|
+
const { repoConfig } = await resolveRepoRunConfig("repo-digest", { repo: target }, { client: deps.configClient });
|
|
114
|
+
const { channel, source } = resolveRepoChannel(target, deps.routing, repoConfig);
|
|
115
|
+
if (!channel) {
|
|
116
|
+
log.debug("No Slack channel for repo — skipping", { repo: target });
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const sinceIso = since.toISOString();
|
|
120
|
+
const [activity, openPrs] = await Promise.all([
|
|
121
|
+
deps.github.listRepoActivitySince(owner, repo, sinceIso),
|
|
122
|
+
deps.github.listOpenPullRequests(owner, repo),
|
|
123
|
+
]);
|
|
124
|
+
const facts = {
|
|
125
|
+
repo: target,
|
|
126
|
+
since: sinceIso,
|
|
127
|
+
until: now.toISOString(),
|
|
128
|
+
windowDays: deps.config.windowDays,
|
|
129
|
+
repoFacts: summarizeRepo(activity, openPrs, since, now, deps.config.maxItems, deps.escalationLabel),
|
|
130
|
+
botFacts: summarizeBot(deps, owner, repo, sinceIso),
|
|
131
|
+
};
|
|
132
|
+
const narrative = deps.config.narrative ? await summarizeSafely(deps, facts) : undefined;
|
|
133
|
+
const { text, blocks } = renderDigest(facts, narrative);
|
|
134
|
+
await deps.post(channel, text, blocks);
|
|
135
|
+
log.info("Posted digest", { repo: target, channel, channelSource: source, narrative: !!narrative });
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
// Facts
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
/**
|
|
142
|
+
* Turn the raw dated items into the counts a digest shows.
|
|
143
|
+
*
|
|
144
|
+
* The window arithmetic lives here rather than in the GitHub client because
|
|
145
|
+
* `listRepoActivitySince` filters on `updated_at`: an issue opened months ago
|
|
146
|
+
* and commented on yesterday is in that response, and counting it as "opened
|
|
147
|
+
* this week" is the obvious wrong answer. Every count below therefore tests the
|
|
148
|
+
* event's OWN timestamp against the window.
|
|
149
|
+
*/
|
|
150
|
+
export function summarizeRepo(activity, openPrs, since, now, maxItems, escalationLabel = "requires-human") {
|
|
151
|
+
const inWindow = (iso) => {
|
|
152
|
+
if (!iso)
|
|
153
|
+
return false;
|
|
154
|
+
const t = Date.parse(iso);
|
|
155
|
+
return Number.isFinite(t) && t >= since.getTime() && t <= now.getTime();
|
|
156
|
+
};
|
|
157
|
+
const prs = activity.filter((i) => i.isPr);
|
|
158
|
+
const issues = activity.filter((i) => !i.isPr);
|
|
159
|
+
// "Awaiting review" excludes drafts, matching what every other surface in the
|
|
160
|
+
// harness means by it (`skills/repo-health`, the review cron's discoverer).
|
|
161
|
+
const awaiting = openPrs
|
|
162
|
+
.filter((p) => !p.draft)
|
|
163
|
+
.sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
|
|
164
|
+
const escalated = openPrs
|
|
165
|
+
.filter((p) => p.labels.includes(escalationLabel))
|
|
166
|
+
.slice(0, maxItems)
|
|
167
|
+
.map((p) => ({ number: p.number, title: p.title }));
|
|
168
|
+
return {
|
|
169
|
+
prsOpened: prs.filter((p) => inWindow(p.createdAt)).length,
|
|
170
|
+
prsMerged: prs.filter((p) => inWindow(p.mergedAt)).length,
|
|
171
|
+
// Closed-not-merged is its own fact: a digest that folds it into "closed"
|
|
172
|
+
// reads an abandoned PR as delivered work.
|
|
173
|
+
prsClosedUnmerged: prs.filter((p) => !p.mergedAt && inWindow(p.closedAt)).length,
|
|
174
|
+
issuesOpened: issues.filter((i) => inWindow(i.createdAt)).length,
|
|
175
|
+
issuesClosed: issues.filter((i) => inWindow(i.closedAt)).length,
|
|
176
|
+
openPrs: openPrs.length,
|
|
177
|
+
awaitingReview: awaiting.length,
|
|
178
|
+
oldestAwaiting: awaiting[0]
|
|
179
|
+
? {
|
|
180
|
+
number: awaiting[0].number,
|
|
181
|
+
title: awaiting[0].title,
|
|
182
|
+
ageDays: Math.floor((now.getTime() - Date.parse(awaiting[0].createdAt)) / 86_400_000),
|
|
183
|
+
}
|
|
184
|
+
: undefined,
|
|
185
|
+
escalated,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/** The bot half — pure state-DB reads, no network. */
|
|
189
|
+
function summarizeBot(deps, owner, repo, sinceIso) {
|
|
190
|
+
const rows = deps.db.runs.summarizeRepoActivity(owner, repo, sinceIso);
|
|
191
|
+
const cost = deps.db.executions.repoCostSince(owner, repo, sinceIso);
|
|
192
|
+
const byWorkflow = {};
|
|
193
|
+
let runs = 0;
|
|
194
|
+
let failed = 0;
|
|
195
|
+
for (const row of rows) {
|
|
196
|
+
runs += row.count;
|
|
197
|
+
byWorkflow[row.workflowName] = (byWorkflow[row.workflowName] ?? 0) + row.count;
|
|
198
|
+
if (row.status === "failed")
|
|
199
|
+
failed += row.count;
|
|
200
|
+
}
|
|
201
|
+
return { runs, failed, byWorkflow, costUsd: cost.costUsd, phases: cost.phases };
|
|
202
|
+
}
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
// Narrative
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
const NARRATIVE_SYSTEM = [
|
|
207
|
+
"You write the one-sentence opening line of a weekly engineering digest for a single repository.",
|
|
208
|
+
"",
|
|
209
|
+
"You are given the week's facts as JSON. They are already correct — do NOT restate the numbers;",
|
|
210
|
+
"the digest prints them directly underneath you. Your job is to say what the week MEANT:",
|
|
211
|
+
"whether it was busy or quiet, whether the review queue is growing or shrinking, and whether",
|
|
212
|
+
"anything needs a human's attention.",
|
|
213
|
+
"",
|
|
214
|
+
"Rules:",
|
|
215
|
+
"- One or two sentences. No greeting, no sign-off, no bullet points, no headings.",
|
|
216
|
+
"- Plain prose. No Slack formatting, no emoji.",
|
|
217
|
+
"- If the week was uneventful, say so plainly in one short sentence.",
|
|
218
|
+
"- Never invent a fact that is not in the JSON.",
|
|
219
|
+
].join("\n");
|
|
220
|
+
/**
|
|
221
|
+
* The narrative is the ONLY part of a digest that can be wrong, so it is the
|
|
222
|
+
* only part allowed to fail. A model error, a missing API key, a timeout — all
|
|
223
|
+
* of them drop the sentence and keep the digest.
|
|
224
|
+
*/
|
|
225
|
+
async function summarizeSafely(deps, facts) {
|
|
226
|
+
try {
|
|
227
|
+
if (deps.summarize)
|
|
228
|
+
return await deps.summarize(facts);
|
|
229
|
+
const model = defaultFastModel("digest");
|
|
230
|
+
const text = await callLlm(model, NARRATIVE_SYSTEM, JSON.stringify(facts), { timeoutMs: 20_000 });
|
|
231
|
+
const trimmed = text.trim();
|
|
232
|
+
return trimmed || undefined;
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
log.warn("Narrative failed — posting the digest without it", { repo: facts.repo, err });
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=repo-digest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-digest.js","sourceRoot":"","sources":["../../src/cron/repo-digest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAKH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAA6B,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAmD,MAAM,4BAA4B,CAAC;AAC3G,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AA2BlC;;;GAGG;AACH,MAAM,CAAC,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IAAI,EAAE,CAAC;QAC5B,OAAO,OAAO,IAAI,SAAS,CAAC;IAC9B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,GAAG,CAAC,IAAI,CAAC,kDAAkD,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;QACxF,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/cron/scheduler.d.ts
CHANGED
|
@@ -2,11 +2,19 @@ import type { StateDb } from "../state/db.js";
|
|
|
2
2
|
export interface CronJob {
|
|
3
3
|
name: string;
|
|
4
4
|
schedule: string;
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Name of an agent workflow (workflows/<name>.yaml) to invoke on each tick.
|
|
7
|
+
* Absent for a `handler:` cron — see {@link CronJob.handler}.
|
|
8
|
+
*/
|
|
9
|
+
workflow?: string;
|
|
10
|
+
/**
|
|
11
|
+
* A HOST-SIDE handler to run instead of dispatching a workflow (the cron
|
|
12
|
+
* YAML's `handler:` key, resolved to a function by `jobs.ts`). Takes the same
|
|
13
|
+
* tick context a workflow dispatch would have received, so per-repo
|
|
14
|
+
* participation and the control keys reach it unchanged.
|
|
15
|
+
*/
|
|
16
|
+
handler?: (context: Record<string, unknown>) => Promise<void>;
|
|
7
17
|
context: Record<string, unknown>;
|
|
8
|
-
/** Maximum consecutive failures before alerting */
|
|
9
|
-
maxFailures?: number;
|
|
10
18
|
}
|
|
11
19
|
/** A lightweight direct job — runs a function, not a workflow */
|
|
12
20
|
export interface DirectCronJob {
|
package/dist/cron/scheduler.js
CHANGED
|
@@ -3,6 +3,15 @@ import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
|
3
3
|
import { logger } from "../logging/logger.js";
|
|
4
4
|
const log = logger("cron");
|
|
5
5
|
const tracer = () => trace.getTracer("lastlight");
|
|
6
|
+
/**
|
|
7
|
+
* Consecutive failed ticks before the scheduler shouts.
|
|
8
|
+
*
|
|
9
|
+
* A constant, not a per-job field: `CronJob.maxFailures` existed for a year,
|
|
10
|
+
* was read once as `job.maxFailures || 3`, and was **never set by anything** —
|
|
11
|
+
* not the cron YAML schema (it has no such key), not `getJobs`. So it always
|
|
12
|
+
* resolved to 3 while reading like a knob an operator could turn.
|
|
13
|
+
*/
|
|
14
|
+
const MAX_CONSECUTIVE_FAILURES = 3;
|
|
6
15
|
/**
|
|
7
16
|
* Cron scheduler with overlap protection and failure tracking.
|
|
8
17
|
* Each job runs a workflow via the agent runner, tracked in SQLite.
|
|
@@ -29,14 +38,23 @@ export class CronScheduler {
|
|
|
29
38
|
this.running.add(job.name);
|
|
30
39
|
log.info("Running", { job: job.name });
|
|
31
40
|
try {
|
|
32
|
-
|
|
41
|
+
if (job.handler)
|
|
42
|
+
await job.handler(job.context);
|
|
43
|
+
else
|
|
44
|
+
await this.runner(job.workflow, job.context);
|
|
33
45
|
}
|
|
34
46
|
catch (err) {
|
|
35
47
|
log.error("Job failed", { job: job.name, err });
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
// Consecutive failures, counted off the `executions` ledger. A workflow
|
|
49
|
+
// cron's rows are written per phase under the WORKFLOW name; a handler
|
|
50
|
+
// cron's are written per tick under the CRON name by `withLedger`
|
|
51
|
+
// (`cron/handlers.ts`) — which exists so this branch applies to both.
|
|
52
|
+
// It used to be gated on `job.workflow`, so a handler cron failing every
|
|
53
|
+
// tick produced one log line and nothing else: no count, and an admin
|
|
54
|
+
// dashboard reporting zero failures beside it.
|
|
55
|
+
const ledgerKey = job.workflow ?? job.name;
|
|
56
|
+
const failures = this.db.executions.consecutiveFailures(ledgerKey);
|
|
57
|
+
if (failures >= MAX_CONSECUTIVE_FAILURES) {
|
|
40
58
|
log.error("ALERT: job has failed consecutively", { job: job.name, failures });
|
|
41
59
|
// TODO: send alert (Slack webhook, email, etc.)
|
|
42
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/cron/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAC3B,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/cron/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAC3B,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;AAoBlD;;;;;;;GAOG;AACH,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAWnC;;;GAGG;AACH,MAAM,OAAO,aAAa;IAChB,IAAI,GAAsB,IAAI,GAAG,EAAE,CAAC;IACpC,OAAO,GAAgB,IAAI,GAAG,EAAE,CAAC;IACjC,EAAE,CAAU;IACZ,MAAM,CAAiB;IAE/B,YAAY,EAAW,EAAE,MAAsB;QAC7C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,QAAQ,CAAC,GAAY;QACnB,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,MAAM,IAA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or pull request as the repo-digest sees it — a dated item, not a
|
|
131
|
+
* count. See {@link GitHubClient.listRepoActivitySince} for why the window
|
|
132
|
+
* arithmetic is deliberately left to the caller.
|
|
133
|
+
*/
|
|
134
|
+
export interface RepoActivityItem {
|
|
135
|
+
number: number;
|
|
136
|
+
title: string;
|
|
137
|
+
/** True when this "issue" is really a pull request. */
|
|
138
|
+
isPr: boolean;
|
|
139
|
+
/** Non-null only for a PR that was actually merged (vs closed unmerged). */
|
|
140
|
+
mergedAt: string | null;
|
|
141
|
+
createdAt: string;
|
|
142
|
+
closedAt: string | null;
|
|
143
|
+
draft: boolean;
|
|
144
|
+
authorLogin: string;
|
|
145
|
+
labels: string[];
|
|
146
|
+
htmlUrl: string;
|
|
147
|
+
}
|
|
129
148
|
/** Options shared by the three settle-aware check queries. */
|
|
130
149
|
export interface ChecksQueryOptions {
|
|
131
150
|
/**
|
|
@@ -1441,7 +1460,32 @@ export declare class GitHubClient {
|
|
|
1441
1460
|
labels: string[];
|
|
1442
1461
|
headRef: string;
|
|
1443
1462
|
headSha: string;
|
|
1463
|
+
createdAt: string;
|
|
1444
1464
|
}>>;
|
|
1465
|
+
/**
|
|
1466
|
+
* What happened in a repo between `sinceIso` and now — issues AND pull
|
|
1467
|
+
* requests, opened / closed / merged.
|
|
1468
|
+
*
|
|
1469
|
+
* ONE endpoint answers all of it. `GET /repos/{o}/{r}/issues` returns pull
|
|
1470
|
+
* requests alongside issues (a PR *is* an issue to this API), and each PR
|
|
1471
|
+
* carries `pull_request.merged_at`, so "merged this week" needs no second
|
|
1472
|
+
* call and no `pulls.list` pass.
|
|
1473
|
+
*
|
|
1474
|
+
* **`since` filters on `updated_at`, not `created_at`.** So the response also
|
|
1475
|
+
* contains items created long ago and merely touched inside the window; the
|
|
1476
|
+
* caller's counts must come from the per-item `createdAt` / `closedAt` /
|
|
1477
|
+
* `mergedAt` fields below, not from the length of this array. That is exactly
|
|
1478
|
+
* why this returns raw dated items rather than counts — the window arithmetic
|
|
1479
|
+
* belongs to one place (`repo-digest.ts`) that can be unit-tested against it.
|
|
1480
|
+
*
|
|
1481
|
+
* Bounded to `maxPages` (3 × 100 = 300 items) because a digest is a summary:
|
|
1482
|
+
* a repo busy enough to overflow that is better served by the ordering than
|
|
1483
|
+
* by an exhaustive walk, and an unbounded paginate here would be a per-repo
|
|
1484
|
+
* rate-limit hazard on every tick.
|
|
1485
|
+
*/
|
|
1486
|
+
listRepoActivitySince(owner: string, repo: string, sinceIso: string, opts?: {
|
|
1487
|
+
maxPages?: number;
|
|
1488
|
+
}): Promise<RepoActivityItem[]>;
|
|
1445
1489
|
/**
|
|
1446
1490
|
* The repo's default branch (e.g. `main`, `master`, `develop`). Used to
|
|
1447
1491
|
* scope build runs to the real base branch instead of assuming `main` — a
|
|
@@ -577,8 +577,69 @@ export class GitHubClient {
|
|
|
577
577
|
.filter(Boolean),
|
|
578
578
|
headRef: p.head?.ref ?? "",
|
|
579
579
|
headSha: p.head?.sha ?? "",
|
|
580
|
+
createdAt: p.created_at ?? "",
|
|
580
581
|
}));
|
|
581
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* What happened in a repo between `sinceIso` and now — issues AND pull
|
|
585
|
+
* requests, opened / closed / merged.
|
|
586
|
+
*
|
|
587
|
+
* ONE endpoint answers all of it. `GET /repos/{o}/{r}/issues` returns pull
|
|
588
|
+
* requests alongside issues (a PR *is* an issue to this API), and each PR
|
|
589
|
+
* carries `pull_request.merged_at`, so "merged this week" needs no second
|
|
590
|
+
* call and no `pulls.list` pass.
|
|
591
|
+
*
|
|
592
|
+
* **`since` filters on `updated_at`, not `created_at`.** So the response also
|
|
593
|
+
* contains items created long ago and merely touched inside the window; the
|
|
594
|
+
* caller's counts must come from the per-item `createdAt` / `closedAt` /
|
|
595
|
+
* `mergedAt` fields below, not from the length of this array. That is exactly
|
|
596
|
+
* why this returns raw dated items rather than counts — the window arithmetic
|
|
597
|
+
* belongs to one place (`repo-digest.ts`) that can be unit-tested against it.
|
|
598
|
+
*
|
|
599
|
+
* Bounded to `maxPages` (3 × 100 = 300 items) because a digest is a summary:
|
|
600
|
+
* a repo busy enough to overflow that is better served by the ordering than
|
|
601
|
+
* by an exhaustive walk, and an unbounded paginate here would be a per-repo
|
|
602
|
+
* rate-limit hazard on every tick.
|
|
603
|
+
*/
|
|
604
|
+
async listRepoActivitySince(owner, repo, sinceIso, opts = {}) {
|
|
605
|
+
const kit = await this.kit(owner);
|
|
606
|
+
const maxPages = opts.maxPages ?? 3;
|
|
607
|
+
const items = [];
|
|
608
|
+
for (let page = 1; page <= maxPages; page++) {
|
|
609
|
+
const { data } = await kit.rest.issues.listForRepo({
|
|
610
|
+
owner,
|
|
611
|
+
repo,
|
|
612
|
+
state: "all",
|
|
613
|
+
since: sinceIso,
|
|
614
|
+
sort: "updated",
|
|
615
|
+
direction: "desc",
|
|
616
|
+
per_page: 100,
|
|
617
|
+
page,
|
|
618
|
+
});
|
|
619
|
+
for (const item of data) {
|
|
620
|
+
items.push({
|
|
621
|
+
number: item.number,
|
|
622
|
+
title: item.title ?? "",
|
|
623
|
+
isPr: !!item.pull_request,
|
|
624
|
+
// `pull_request.merged_at` is the ONLY place this endpoint reveals a
|
|
625
|
+
// merge; `state: "closed"` alone cannot distinguish merged from
|
|
626
|
+
// abandoned, and those are opposite facts in a digest.
|
|
627
|
+
mergedAt: item.pull_request?.merged_at ?? null,
|
|
628
|
+
createdAt: item.created_at,
|
|
629
|
+
closedAt: item.closed_at ?? null,
|
|
630
|
+
draft: !!item.draft,
|
|
631
|
+
authorLogin: item.user?.login ?? "",
|
|
632
|
+
labels: (item.labels ?? [])
|
|
633
|
+
.map((l) => (typeof l === "string" ? l : l.name ?? ""))
|
|
634
|
+
.filter(Boolean),
|
|
635
|
+
htmlUrl: item.html_url ?? "",
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
if (data.length < 100)
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
return items;
|
|
642
|
+
}
|
|
582
643
|
/**
|
|
583
644
|
* The repo's default branch (e.g. `main`, `master`, `develop`). Used to
|
|
584
645
|
* scope build runs to the real base branch instead of assuming `main` — a
|