@h-rig/run-plugin 0.0.6-alpha.186
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/README.md +1 -0
- package/dist/src/plugin.d.ts +4 -0
- package/dist/src/plugin.js +4319 -0
- package/dist/src/read-model/inspect-command.d.ts +19 -0
- package/dist/src/read-model/inspect-command.js +341 -0
- package/dist/src/read-model/plugin.d.ts +4 -0
- package/dist/src/read-model/plugin.js +2550 -0
- package/dist/src/read-model/read-model-backend/diagnostics.d.ts +9 -0
- package/dist/src/read-model/read-model-backend/diagnostics.js +51 -0
- package/dist/src/read-model/read-model-backend/guard.d.ts +4 -0
- package/dist/src/read-model/read-model-backend/guard.js +25 -0
- package/dist/src/read-model/read-model-backend/inbox.d.ts +23 -0
- package/dist/src/read-model/read-model-backend/inbox.js +669 -0
- package/dist/src/read-model/read-model-backend/index.d.ts +8 -0
- package/dist/src/read-model/read-model-backend/index.js +1163 -0
- package/dist/src/read-model/read-model-backend/inspect.d.ts +26 -0
- package/dist/src/read-model/read-model-backend/inspect.js +770 -0
- package/dist/src/read-model/read-model-backend/projection.d.ts +39 -0
- package/dist/src/read-model/read-model-backend/projection.js +669 -0
- package/dist/src/read-model/read-model-backend/run-status.d.ts +27 -0
- package/dist/src/read-model/read-model-backend/run-status.js +237 -0
- package/dist/src/read-model/read-model-backend/stats.d.ts +12 -0
- package/dist/src/read-model/read-model-backend/stats.js +800 -0
- package/dist/src/read-model/read-model-service.d.ts +2 -0
- package/dist/src/read-model/read-model-service.js +1725 -0
- package/dist/src/read-model/reconcile.d.ts +23 -0
- package/dist/src/read-model/reconcile.js +306 -0
- package/dist/src/read-model/run-format.d.ts +23 -0
- package/dist/src/read-model/run-format.js +202 -0
- package/dist/src/read-model/runs-screen.d.ts +14 -0
- package/dist/src/read-model/runs-screen.js +217 -0
- package/dist/src/read-model/session-journal.d.ts +26 -0
- package/dist/src/read-model/session-journal.js +355 -0
- package/dist/src/read-model/stats-command.d.ts +16 -0
- package/dist/src/read-model/stats-command.js +88 -0
- package/dist/src/read-model/stats-format.d.ts +1 -0
- package/dist/src/read-model/stats-format.js +8 -0
- package/dist/src/worker/autohost.d.ts +11 -0
- package/dist/src/worker/autohost.js +858 -0
- package/dist/src/worker/constants.d.ts +3 -0
- package/dist/src/worker/constants.js +10 -0
- package/dist/src/worker/extension.d.ts +14 -0
- package/dist/src/worker/extension.js +881 -0
- package/dist/src/worker/host.d.ts +1 -0
- package/dist/src/worker/host.js +1 -0
- package/dist/src/worker/inbox-command.d.ts +23 -0
- package/dist/src/worker/inbox-command.js +163 -0
- package/dist/src/worker/index.d.ts +2 -0
- package/dist/src/worker/index.js +1767 -0
- package/dist/src/worker/local-run-changes.d.ts +3 -0
- package/dist/src/worker/local-run-changes.js +65 -0
- package/dist/src/worker/notifications.d.ts +1 -0
- package/dist/src/worker/notifications.js +27 -0
- package/dist/src/worker/notify-cap.d.ts +11 -0
- package/dist/src/worker/notify-cap.js +13 -0
- package/dist/src/worker/panel-plugin.d.ts +11 -0
- package/dist/src/worker/panel-plugin.js +37 -0
- package/dist/src/worker/plugin.d.ts +3 -0
- package/dist/src/worker/plugin.js +1761 -0
- package/dist/src/worker/run-control-service.d.ts +2 -0
- package/dist/src/worker/run-control-service.js +210 -0
- package/dist/src/worker/session-journal-writer.d.ts +4 -0
- package/dist/src/worker/session-journal-writer.js +184 -0
- package/dist/src/worker/stall.d.ts +21 -0
- package/dist/src/worker/stall.js +55 -0
- package/dist/src/worker/utils.d.ts +21 -0
- package/dist/src/worker/utils.js +29 -0
- package/dist/src/worker/workflow-journal-writer.d.ts +7 -0
- package/dist/src/worker/workflow-journal-writer.js +76 -0
- package/package.json +47 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/run-plugin/src/worker/local-run-changes.ts
|
|
3
|
+
import { existsSync, mkdirSync, watch } from "fs";
|
|
4
|
+
import { dirname, resolve } from "path";
|
|
5
|
+
import { Effect, Queue, Stream } from "effect";
|
|
6
|
+
function findNearestGitCheckoutRoot(startDir) {
|
|
7
|
+
let current = resolve(startDir);
|
|
8
|
+
for (;; ) {
|
|
9
|
+
if (existsSync(resolve(current, ".git")))
|
|
10
|
+
return current;
|
|
11
|
+
const parent = dirname(current);
|
|
12
|
+
if (parent === current)
|
|
13
|
+
return null;
|
|
14
|
+
current = parent;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function resolveCheckoutRoot(projectRoot) {
|
|
18
|
+
const normalizedProjectRoot = resolve(projectRoot);
|
|
19
|
+
const explicit = process.env.MONOREPO_ROOT?.trim();
|
|
20
|
+
if (explicit) {
|
|
21
|
+
const explicitRoot = resolve(explicit);
|
|
22
|
+
const gitRoot = findNearestGitCheckoutRoot(explicitRoot);
|
|
23
|
+
if (gitRoot)
|
|
24
|
+
return gitRoot;
|
|
25
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but no git checkout was found there or above it.`);
|
|
26
|
+
}
|
|
27
|
+
return findNearestGitCheckoutRoot(normalizedProjectRoot) ?? normalizedProjectRoot;
|
|
28
|
+
}
|
|
29
|
+
function isRelevantLocalRunChange(filename) {
|
|
30
|
+
if (filename === null || filename === undefined)
|
|
31
|
+
return true;
|
|
32
|
+
const raw = filename.toString();
|
|
33
|
+
if (!raw.trim())
|
|
34
|
+
return true;
|
|
35
|
+
const segments = raw.split(/[\\/]+/).filter(Boolean);
|
|
36
|
+
if (segments.some((segment) => segment === ".git" || segment === "node_modules" || segment === "build" || segment === "dist" || segment === "out" || segment === ".next" || segment === "coverage")) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const rigIndex = segments.lastIndexOf(".rig");
|
|
40
|
+
if (rigIndex < 0)
|
|
41
|
+
return false;
|
|
42
|
+
const rigChild = segments[rigIndex + 1];
|
|
43
|
+
if (rigChild === "session")
|
|
44
|
+
return true;
|
|
45
|
+
return rigChild === "runtime-context.json" && segments[rigIndex + 2] === undefined;
|
|
46
|
+
}
|
|
47
|
+
var localRunChanges = (projectRoot) => Stream.callback((queue) => Effect.gen(function* () {
|
|
48
|
+
const worktreesRoot = resolve(resolveCheckoutRoot(projectRoot), ".worktrees");
|
|
49
|
+
if (!existsSync(worktreesRoot)) {
|
|
50
|
+
try {
|
|
51
|
+
mkdirSync(worktreesRoot, { recursive: true });
|
|
52
|
+
} catch {}
|
|
53
|
+
}
|
|
54
|
+
const watcher = watch(worktreesRoot, { recursive: true }, (_event, filename) => {
|
|
55
|
+
if (!isRelevantLocalRunChange(filename))
|
|
56
|
+
return;
|
|
57
|
+
Queue.offerUnsafe(queue, undefined);
|
|
58
|
+
});
|
|
59
|
+
watcher.on("error", () => {});
|
|
60
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => watcher.close()));
|
|
61
|
+
}), { bufferSize: 1, strategy: "sliding" });
|
|
62
|
+
export {
|
|
63
|
+
localRunChanges,
|
|
64
|
+
isRelevantLocalRunChange
|
|
65
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function dispatchRunNotifications(projectRoot: string, runId: string, taskId: string, outcome: "completed" | "failed", detail: string | null): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/run-plugin/src/worker/notify-cap.ts
|
|
3
|
+
import { NOTIFY_SERVICE_CAPABILITY } from "@rig/contracts";
|
|
4
|
+
import { defineCapability } from "@rig/core/capability";
|
|
5
|
+
import { resolvePluginHost } from "@rig/core/project-plugins";
|
|
6
|
+
var NotifyCap = defineCapability(NOTIFY_SERVICE_CAPABILITY);
|
|
7
|
+
async function resolveNotifyService(projectRoot) {
|
|
8
|
+
const { host } = await resolvePluginHost(projectRoot);
|
|
9
|
+
return NotifyCap.resolve(host);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// packages/run-plugin/src/worker/notifications.ts
|
|
13
|
+
async function dispatchRunNotifications(projectRoot, runId, taskId, outcome, detail) {
|
|
14
|
+
try {
|
|
15
|
+
const notifier = await resolveNotifyService(projectRoot);
|
|
16
|
+
if (!notifier)
|
|
17
|
+
return;
|
|
18
|
+
const event = { runId, type: `run.${outcome}`, timestamp: new Date().toISOString(), payload: { taskId, detail } };
|
|
19
|
+
await Promise.race([
|
|
20
|
+
notifier.notify(event),
|
|
21
|
+
new Promise((resolveCap) => setTimeout(resolveCap, 5000))
|
|
22
|
+
]);
|
|
23
|
+
} catch {}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
dispatchRunNotifications
|
|
27
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-plugin seam: run-exec dispatches run notifications off the host's
|
|
3
|
+
* NOTIFY capability instead of importing `@rig/notifications-plugin`'s impl
|
|
4
|
+
* (`dispatchEventToTargets`/`loadNotificationConfig`). `@rig/notifications-plugin`
|
|
5
|
+
* OWNS the policy (target selection + `.rig/notifications.json` load) and
|
|
6
|
+
* registers it under {@link NOTIFY_SERVICE_CAPABILITY}; this module is the
|
|
7
|
+
* run-exec-side resolver so no run-exec file imports the provider impl.
|
|
8
|
+
*/
|
|
9
|
+
import { type NotifyService } from "@rig/contracts";
|
|
10
|
+
/** Resolve the notify service from the project's plugin host, or `null` if unregistered. */
|
|
11
|
+
export declare function resolveNotifyService(projectRoot: string): Promise<NotifyService | null>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/run-plugin/src/worker/notify-cap.ts
|
|
3
|
+
import { NOTIFY_SERVICE_CAPABILITY } from "@rig/contracts";
|
|
4
|
+
import { defineCapability } from "@rig/core/capability";
|
|
5
|
+
import { resolvePluginHost } from "@rig/core/project-plugins";
|
|
6
|
+
var NotifyCap = defineCapability(NOTIFY_SERVICE_CAPABILITY);
|
|
7
|
+
async function resolveNotifyService(projectRoot) {
|
|
8
|
+
const { host } = await resolvePluginHost(projectRoot);
|
|
9
|
+
return NotifyCap.resolve(host);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
resolveNotifyService
|
|
13
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RIG_RUN_STOP_PANEL_ACTION, RIG_SUPERVISOR_PANEL_ID, type PanelRegistration, type WorkerPanelProducerContext } from "@rig/contracts";
|
|
2
|
+
import type { Panel } from "@rig/core";
|
|
3
|
+
export { RIG_RUN_STOP_PANEL_ACTION, RIG_SUPERVISOR_PANEL_ID };
|
|
4
|
+
export type { WorkerPanelProducerContext };
|
|
5
|
+
export declare const RIG_PANELS_CUSTOM_MESSAGE_TYPE = "rig-panels";
|
|
6
|
+
export interface WorkerPanelRegistrySnapshot {
|
|
7
|
+
readonly registrations: readonly PanelRegistration[];
|
|
8
|
+
readonly producers: readonly Panel[];
|
|
9
|
+
}
|
|
10
|
+
export declare function produceWorkerPanelPayload(producer: Panel, context: WorkerPanelProducerContext): Promise<unknown>;
|
|
11
|
+
export declare function loadWorkerPanelRegistry(projectRoot: string): Promise<WorkerPanelRegistrySnapshot>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/run-plugin/src/worker/panel-plugin.ts
|
|
3
|
+
import { createProjectPluginHost } from "@rig/core/project-plugins";
|
|
4
|
+
import { RIG_CAPABILITY_PANEL_SLOT, RIG_RUN_STOP_PANEL_ACTION, RIG_SUPERVISOR_PANEL_ID } from "@rig/contracts";
|
|
5
|
+
var RIG_PANELS_CUSTOM_MESSAGE_TYPE = "rig-panels";
|
|
6
|
+
var PANEL_PRODUCER_TIMEOUT_MS = 2000;
|
|
7
|
+
async function produceWorkerPanelPayload(producer, context) {
|
|
8
|
+
if (!producer.produce)
|
|
9
|
+
return;
|
|
10
|
+
let timeout;
|
|
11
|
+
try {
|
|
12
|
+
return await Promise.race([
|
|
13
|
+
Promise.resolve(producer.produce(context)),
|
|
14
|
+
new Promise((resolve) => {
|
|
15
|
+
timeout = setTimeout(() => resolve(undefined), PANEL_PRODUCER_TIMEOUT_MS);
|
|
16
|
+
})
|
|
17
|
+
]);
|
|
18
|
+
} finally {
|
|
19
|
+
clearTimeout(timeout);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function loadWorkerPanelRegistry(projectRoot) {
|
|
23
|
+
const { host } = await createProjectPluginHost(projectRoot, {
|
|
24
|
+
mode: "strict-config-only"
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
registrations: host.listPanels().filter((registration) => registration.slot === RIG_CAPABILITY_PANEL_SLOT),
|
|
28
|
+
producers: host.listExecutablePanels().filter((registration) => registration.slot === RIG_CAPABILITY_PANEL_SLOT)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
produceWorkerPanelPayload,
|
|
33
|
+
loadWorkerPanelRegistry,
|
|
34
|
+
RIG_SUPERVISOR_PANEL_ID,
|
|
35
|
+
RIG_RUN_STOP_PANEL_ACTION,
|
|
36
|
+
RIG_PANELS_CUSTOM_MESSAGE_TYPE
|
|
37
|
+
};
|