eve-hub 0.16.43 → 0.16.44
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eve-hub",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.44",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Bot-side code shared by every hub agent: registry tools, the roster hook, the eve channel, the host sandbox and browser, and model helpers.",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export const SCHEDULE_BOT: "main";
|
|
2
|
+
/** Runs `fn` as one run of the kit schedule `id` in the hub's run history; `fn` gets the run's id, undefined on a hub that keeps no history. A paused schedule's `fn` doesn't run. */
|
|
3
|
+
export function trackRun<T>(id: string, fn: (run: string | undefined) => Promise<T> | T, options?: { bot?: string; fetchImpl?: typeof fetch; base?: string; log?: Pick<Console, "log" | "error">; hosted?: boolean }): Promise<T | undefined>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Reports one dispatch of a kit schedule to the hub's run history (the Schedules pane reads it): the hub is told the run started
|
|
2
|
+
// (POST /api/schedules/<bot>/<id>/runs answers with the run's id and whether the schedule is paused, which skips `fn`) and how it
|
|
3
|
+
// ended (.../runs/<run>/end, with the error when `fn` threw). A commit that carries the id adds its posts to the run
|
|
4
|
+
// (PUT .../state { run }). A hub that keeps no run history (the local one) answers 404 to the start, and `fn` runs untracked; on the hosted hub
|
|
5
|
+
// (`VERCEL` set) a 404 means the schedule is unknown, which throws so the run is not lost silently.
|
|
6
|
+
//
|
|
7
|
+
// Plain JS on purpose: the schedules (TypeScript, bundled by eve) and the tests (plain node) import the same module.
|
|
8
|
+
import { registryFetch } from "../registry-fetch.mjs";
|
|
9
|
+
|
|
10
|
+
// The kit's schedules are installed on the coordinator, which the hub's own schedule paths already call `main`.
|
|
11
|
+
export const SCHEDULE_BOT = "main";
|
|
12
|
+
|
|
13
|
+
const path = (bot, id) => `/api/schedules/${encodeURIComponent(bot)}/${id.split("/").map(encodeURIComponent).join("/")}/runs`;
|
|
14
|
+
|
|
15
|
+
export async function trackRun(id, fn, { bot = SCHEDULE_BOT, fetchImpl = fetch, base, log = console, hosted = Boolean(process.env.VERCEL) } = {}) {
|
|
16
|
+
const call = async (suffix, body) => {
|
|
17
|
+
const res = await registryFetch(`${path(bot, id)}${suffix}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }, { deadlineMs: 10_000, fetchImpl, ...(base === undefined ? {} : { base }) });
|
|
18
|
+
if (res.status === 404 && !hosted) return null;
|
|
19
|
+
if (!res.ok) throw new Error(`POST ${path(bot, id)}${suffix}: ${res.status} ${(await res.text()).slice(0, 300)}`);
|
|
20
|
+
return res.json();
|
|
21
|
+
};
|
|
22
|
+
const started = await call("", {});
|
|
23
|
+
if (!started) return fn(undefined);
|
|
24
|
+
if (started.paused) {
|
|
25
|
+
log.log(`schedule ${bot}/${id} skipped: paused`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const end = `/${encodeURIComponent(started.run)}/end`;
|
|
29
|
+
let result;
|
|
30
|
+
try {
|
|
31
|
+
result = await fn(started.run);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
await call(end, { error: (String(error?.message ?? error) || "the run failed").slice(0, 2000) }).catch((endError) => log.error(`schedule ${bot}/${id}: the run's end was not recorded: ${endError.message}`));
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
await call(end, {});
|
|
37
|
+
return result;
|
|
38
|
+
}
|
package/schedules/tracker-prs.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// and to Dropped when it closed (schedules/tracker-prs-run.mjs).
|
|
3
3
|
import { defineSchedule } from "eve/schedules";
|
|
4
4
|
import { runTrackerPrs } from "./tracker-prs-run.mjs";
|
|
5
|
+
import { trackRun } from "./track.mjs";
|
|
5
6
|
export default defineSchedule({
|
|
6
7
|
cron: "*/10 * * * *",
|
|
7
|
-
async
|
|
8
|
+
run: () => trackRun("tracker-prs", async () => {
|
|
8
9
|
const { asked, moved } = await runTrackerPrs();
|
|
9
10
|
if (moved)
|
|
10
11
|
console.log(`[hub:tracker-prs] ${moved} of ${asked} rows moved`);
|
|
11
|
-
},
|
|
12
|
+
}),
|
|
12
13
|
});
|
|
@@ -4,13 +4,15 @@ export declare const workspaceReviewPost: (now: number) => {
|
|
|
4
4
|
text: string;
|
|
5
5
|
clientId: string;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
/** `run` is the id trackRun got for this firing, so the post counts toward that run. */
|
|
8
|
+
export declare function fireWorkspaceReview({ fetchImpl, base, now, run }?: {
|
|
8
9
|
fetchImpl?: typeof fetch;
|
|
9
10
|
base?: string;
|
|
10
11
|
now?: number;
|
|
12
|
+
run?: string;
|
|
11
13
|
}): Promise<void>;
|
|
12
14
|
declare const _default: {
|
|
13
15
|
cron: string;
|
|
14
|
-
run: () => Promise<void>;
|
|
16
|
+
run: () => Promise<void | undefined>;
|
|
15
17
|
};
|
|
16
18
|
export default _default;
|
|
@@ -6,19 +6,21 @@
|
|
|
6
6
|
// schedule in the app stops the post. The post is keyed on the UTC day, so a retry of the same firing posts once.
|
|
7
7
|
import { defineSchedule } from "eve/schedules";
|
|
8
8
|
import { registryFetch } from "../registry-fetch.mjs";
|
|
9
|
+
import { SCHEDULE_BOT, trackRun } from "./track.mjs";
|
|
9
10
|
export const WORKSPACE_REVIEW_PROMPT = "Load the `workspace-review` skill and follow it: score the last 7 days against the week before, open the draft PRs for the human's profile and memory and for the bots and schedules, and post the scorecard and proposals here.";
|
|
10
11
|
/** The one post a firing commits: to main, keyed on the day it fired. */
|
|
11
12
|
export const workspaceReviewPost = (now) => ({ text: `@main ${WORKSPACE_REVIEW_PROMPT}`, clientId: `workspace-review:${new Date(now).toISOString().slice(0, 10)}` });
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/** `run` is the id trackRun got for this firing, so the post counts toward that run. */
|
|
14
|
+
export async function fireWorkspaceReview({ fetchImpl = fetch, base, now = Date.now(), run } = {}) {
|
|
15
|
+
const res = await registryFetch(`/api/schedules/${SCHEDULE_BOT}/workspace-review/state`, {
|
|
14
16
|
method: "PUT",
|
|
15
17
|
headers: { "content-type": "application/json" },
|
|
16
|
-
body: JSON.stringify({ posts: [workspaceReviewPost(now)] }),
|
|
18
|
+
body: JSON.stringify({ posts: [workspaceReviewPost(now)], ...(run === undefined ? {} : { run }) }),
|
|
17
19
|
}, { fetchImpl, deadlineMs: 10_000, ...(base === undefined ? {} : { base }) });
|
|
18
20
|
if (!res.ok)
|
|
19
21
|
throw new Error(`PUT /api/schedules/main/workspace-review/state: ${res.status} ${(await res.text()).slice(0, 300)}`);
|
|
20
22
|
}
|
|
21
23
|
export default defineSchedule({
|
|
22
24
|
cron: "0 8 * * 1",
|
|
23
|
-
run: () => fireWorkspaceReview(),
|
|
25
|
+
run: () => trackRun("workspace-review", (run) => fireWorkspaceReview({ run })),
|
|
24
26
|
});
|