@h-rig/run-worker 0.0.6-alpha.130
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/autohost.d.ts +34 -0
- package/dist/src/autohost.js +592 -0
- package/dist/src/constants.d.ts +4 -0
- package/dist/src/constants.js +12 -0
- package/dist/src/extension.d.ts +14 -0
- package/dist/src/extension.js +614 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +629 -0
- package/dist/src/journal.d.ts +31 -0
- package/dist/src/journal.js +14 -0
- package/dist/src/notifications.d.ts +1 -0
- package/dist/src/notifications.js +19 -0
- package/dist/src/stall.d.ts +16 -0
- package/dist/src/stall.js +56 -0
- package/dist/src/utils.d.ts +23 -0
- package/dist/src/utils.js +38 -0
- package/package.json +30 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/run-worker/src/notifications.ts
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
import { dispatchEventToTargets, loadNotificationConfig } from "@rig/runtime/control-plane/notifications";
|
|
5
|
+
async function dispatchRunNotifications(projectRoot, runId, taskId, outcome, detail) {
|
|
6
|
+
try {
|
|
7
|
+
const config = await loadNotificationConfig(resolve(projectRoot, ".rig", "notifications.json"));
|
|
8
|
+
if (config.targets.length === 0)
|
|
9
|
+
return;
|
|
10
|
+
const event = { runId, type: `run.${outcome}`, timestamp: new Date().toISOString(), payload: { taskId, detail } };
|
|
11
|
+
await Promise.race([
|
|
12
|
+
dispatchEventToTargets(event, config.targets),
|
|
13
|
+
new Promise((resolveCap) => setTimeout(resolveCap, 5000))
|
|
14
|
+
]);
|
|
15
|
+
} catch {}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
dispatchRunNotifications
|
|
19
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RunJournal } from "./journal";
|
|
2
|
+
export declare function timestampMs(value: number | string | Date | null | undefined): number | null;
|
|
3
|
+
export declare function computeRunStall(input: {
|
|
4
|
+
readonly lastActivityAt: number | string | Date | null | undefined;
|
|
5
|
+
readonly now: number | string | Date;
|
|
6
|
+
readonly thresholdMs: number;
|
|
7
|
+
}): boolean;
|
|
8
|
+
export declare function appendRunStallDetected(journal: RunJournal | null | undefined, detail?: string): boolean;
|
|
9
|
+
export declare function startRunProcessStallMonitor(opts: {
|
|
10
|
+
readonly journal: RunJournal | null | undefined;
|
|
11
|
+
readonly lastActivityAt: () => number;
|
|
12
|
+
readonly alreadyStalled?: boolean;
|
|
13
|
+
readonly thresholdMs?: number;
|
|
14
|
+
readonly intervalMs?: number;
|
|
15
|
+
readonly now?: () => number;
|
|
16
|
+
}): () => void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/run-worker/src/constants.ts
|
|
3
|
+
var RUN_PROCESS_STEER_TIMEOUT_MS = 10 * 60 * 1000;
|
|
4
|
+
var TRACKED_RUN_STALL_MS = 20 * 60 * 1000;
|
|
5
|
+
var RUN_PROCESS_STALL_SWEEP_MS = 60 * 1000;
|
|
6
|
+
var RUN_PROCESS_STALL_DETAIL = "Run process made no OMP session progress for 20+ minutes; recording a stall so recovery can requeue or resume the session.";
|
|
7
|
+
|
|
8
|
+
// packages/run-worker/src/stall.ts
|
|
9
|
+
function timestampMs(value) {
|
|
10
|
+
if (value === null || value === undefined)
|
|
11
|
+
return null;
|
|
12
|
+
const ms = value instanceof Date ? value.getTime() : typeof value === "number" ? value : Date.parse(value);
|
|
13
|
+
return Number.isFinite(ms) ? ms : null;
|
|
14
|
+
}
|
|
15
|
+
function computeRunStall(input) {
|
|
16
|
+
const lastActivityAt = timestampMs(input.lastActivityAt);
|
|
17
|
+
const now = timestampMs(input.now);
|
|
18
|
+
if (lastActivityAt === null || now === null || input.thresholdMs <= 0)
|
|
19
|
+
return false;
|
|
20
|
+
return now - lastActivityAt >= input.thresholdMs;
|
|
21
|
+
}
|
|
22
|
+
function appendRunStallDetected(journal, detail = RUN_PROCESS_STALL_DETAIL) {
|
|
23
|
+
if (!journal)
|
|
24
|
+
return false;
|
|
25
|
+
try {
|
|
26
|
+
journal.appendStall({ detail });
|
|
27
|
+
return true;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.warn(`[rig-run] stall-detected append failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function startRunProcessStallMonitor(opts) {
|
|
34
|
+
if (!opts.journal)
|
|
35
|
+
return () => {};
|
|
36
|
+
let stallDetected = opts.alreadyStalled === true;
|
|
37
|
+
const thresholdMs = opts.thresholdMs ?? TRACKED_RUN_STALL_MS;
|
|
38
|
+
const now = opts.now ?? (() => Date.now());
|
|
39
|
+
const timer = setInterval(() => {
|
|
40
|
+
if (stallDetected)
|
|
41
|
+
return;
|
|
42
|
+
if (!computeRunStall({ lastActivityAt: opts.lastActivityAt(), now: now(), thresholdMs }))
|
|
43
|
+
return;
|
|
44
|
+
stallDetected = true;
|
|
45
|
+
appendRunStallDetected(opts.journal);
|
|
46
|
+
}, opts.intervalMs ?? RUN_PROCESS_STALL_SWEEP_MS);
|
|
47
|
+
if (typeof timer.unref === "function")
|
|
48
|
+
timer.unref();
|
|
49
|
+
return () => clearInterval(timer);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
timestampMs,
|
|
53
|
+
startRunProcessStallMonitor,
|
|
54
|
+
computeRunStall,
|
|
55
|
+
appendRunStallDetected
|
|
56
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@oh-my-pi/pi-coding-agent";
|
|
2
|
+
import type { ExtensionCollabFacade, CollabRegistryFilter, CollabSessionProjection, ExtensionJoinCollabSessionInput, ExtensionStartCollabHostInput, LiveCollabProjection } from "@oh-my-pi/pi-coding-agent/collab/api";
|
|
3
|
+
import type { CustomEntry } from "@oh-my-pi/pi-coding-agent/session/session-entries";
|
|
4
|
+
import { type RigWorkflowStatus } from "@rig/contracts";
|
|
5
|
+
export type CompatCollabFacade = ExtensionCollabFacade & {
|
|
6
|
+
listActiveCollabSessions?: (filter?: CollabRegistryFilter) => Promise<readonly LiveCollabProjection[]>;
|
|
7
|
+
get?: (sessionId: string) => Promise<LiveCollabProjection | null>;
|
|
8
|
+
getCollabForSession?: (sessionId: string) => Promise<LiveCollabProjection | null>;
|
|
9
|
+
startCollabHost?: (input: ExtensionStartCollabHostInput) => Promise<LiveCollabProjection>;
|
|
10
|
+
joinCollabSession?: (input: ExtensionJoinCollabSessionInput) => Promise<void>;
|
|
11
|
+
listSessions?: (filter?: CollabRegistryFilter) => Promise<readonly CollabSessionProjection[]>;
|
|
12
|
+
};
|
|
13
|
+
export type RigCollabContext = ExtensionContext & {
|
|
14
|
+
collab?: CompatCollabFacade;
|
|
15
|
+
};
|
|
16
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
17
|
+
export declare function customEntries(entries: readonly {
|
|
18
|
+
type: string;
|
|
19
|
+
}[]): CustomEntry[];
|
|
20
|
+
export declare function appendStatus(api: ExtensionAPI, status: RigWorkflowStatus, detail?: string): void;
|
|
21
|
+
export declare function rigProjectRoot(): string;
|
|
22
|
+
export declare function registryBaseUrl(): string;
|
|
23
|
+
export declare function rigRelayUrl(): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/run-worker/src/utils.ts
|
|
3
|
+
import { createWorkflowStatusChanged, RIG_WORKFLOW_STATUS_CHANGED } from "@rig/contracts";
|
|
4
|
+
import { resolveRegistryBaseUrl, resolveRelayUrl } from "@rig/runtime/control-plane/remote-config";
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
7
|
+
}
|
|
8
|
+
function customEntries(entries) {
|
|
9
|
+
const customs = [];
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
if (entry.type === "custom")
|
|
12
|
+
customs.push(entry);
|
|
13
|
+
}
|
|
14
|
+
return customs;
|
|
15
|
+
}
|
|
16
|
+
function appendStatus(api, status, detail) {
|
|
17
|
+
api.appendEntry(RIG_WORKFLOW_STATUS_CHANGED, createWorkflowStatusChanged({
|
|
18
|
+
status,
|
|
19
|
+
...detail ? { detail } : {}
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
function rigProjectRoot() {
|
|
23
|
+
return process.env.PROJECT_RIG_ROOT?.trim() || process.env.RIG_HOST_PROJECT_ROOT?.trim() || process.cwd();
|
|
24
|
+
}
|
|
25
|
+
function registryBaseUrl() {
|
|
26
|
+
return resolveRegistryBaseUrl(rigProjectRoot());
|
|
27
|
+
}
|
|
28
|
+
function rigRelayUrl() {
|
|
29
|
+
return resolveRelayUrl();
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
rigRelayUrl,
|
|
33
|
+
rigProjectRoot,
|
|
34
|
+
registryBaseUrl,
|
|
35
|
+
isRecord,
|
|
36
|
+
customEntries,
|
|
37
|
+
appendStatus
|
|
38
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@h-rig/run-worker",
|
|
3
|
+
"version": "0.0.6-alpha.130",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Rig package",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/src/index.d.ts",
|
|
14
|
+
"import": "./dist/src/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"bun": ">=1.3.11"
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/src/extension.js",
|
|
21
|
+
"module": "./dist/src/index.js",
|
|
22
|
+
"types": "./dist/src/index.d.ts",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.130",
|
|
25
|
+
"@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.130",
|
|
26
|
+
"@rig/relay-registry": "npm:@h-rig/relay-registry@0.0.6-alpha.130",
|
|
27
|
+
"@oh-my-pi/pi-coding-agent": "16.0.4",
|
|
28
|
+
"effect": "4.0.0-beta.78"
|
|
29
|
+
}
|
|
30
|
+
}
|