@h-rig/product-entrypoint-plugin 0.0.6-alpha.155 → 0.0.6-alpha.157
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/dist/src/plugin.d.ts +3 -3
- package/dist/src/plugin.js +1 -3
- package/dist/src/product-entrypoint.js +102 -1
- package/dist/src/reconcile.d.ts +35 -0
- package/dist/src/reconcile.js +104 -0
- package/package.json +4 -5
package/dist/src/plugin.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function createStandardProductEntrypointPlugin():
|
|
3
|
-
export declare const standardProductEntrypointPlugin:
|
|
1
|
+
import { type RigPlugin } from "@rig/core/config";
|
|
2
|
+
export declare function createStandardProductEntrypointPlugin(): RigPlugin;
|
|
3
|
+
export declare const standardProductEntrypointPlugin: RigPlugin;
|
package/dist/src/plugin.js
CHANGED
|
@@ -47,10 +47,8 @@ function createStandardProductEntrypointPlugin() {
|
|
|
47
47
|
name: "@rig/product-entrypoint-plugin",
|
|
48
48
|
version: "0.1.0",
|
|
49
49
|
contributes: {
|
|
50
|
-
cliCommands: STANDARD_PRODUCT_COMMANDS.map(
|
|
50
|
+
cliCommands: STANDARD_PRODUCT_COMMANDS.map(createStandardProductCliCommand)
|
|
51
51
|
}
|
|
52
|
-
}, {
|
|
53
|
-
cliCommands: STANDARD_PRODUCT_COMMANDS.map(createStandardProductCliCommand)
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
54
|
var standardProductEntrypointPlugin = createStandardProductEntrypointPlugin();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
2
4
|
// packages/product-entrypoint-plugin/src/product-entrypoint.ts
|
|
3
5
|
import { resolve } from "path";
|
|
4
6
|
import { runCli } from "@oh-my-pi/pi-coding-agent/cli";
|
|
@@ -7,7 +9,106 @@ import { resolveCliArgv } from "@oh-my-pi/pi-coding-agent/cli-commands";
|
|
|
7
9
|
import { prepareAcpTerminalAuthArgs } from "@oh-my-pi/pi-coding-agent/modes/acp/terminal-auth";
|
|
8
10
|
import { runRootCommand } from "@oh-my-pi/pi-coding-agent/main";
|
|
9
11
|
import { createAgentSession } from "@oh-my-pi/pi-coding-agent/sdk";
|
|
10
|
-
import { applyIdentityEnv, identityFilterFromEnv
|
|
12
|
+
import { applyIdentityEnv, identityFilterFromEnv } from "@rig/runtime/control-plane/identity-env";
|
|
13
|
+
|
|
14
|
+
// packages/product-entrypoint-plugin/src/reconcile.ts
|
|
15
|
+
import {
|
|
16
|
+
CUSTOM_TYPE_FOR,
|
|
17
|
+
foldRunSessionEntries,
|
|
18
|
+
isTerminalRunStatus
|
|
19
|
+
} from "@rig/contracts";
|
|
20
|
+
async function loadCollabApi() {
|
|
21
|
+
return await import("@oh-my-pi/pi-coding-agent/collab/api");
|
|
22
|
+
}
|
|
23
|
+
async function loadSessionManager() {
|
|
24
|
+
return await import("@oh-my-pi/pi-coding-agent/session/session-manager");
|
|
25
|
+
}
|
|
26
|
+
function projectRunFromEntries(source, runId) {
|
|
27
|
+
const entries = typeof source === "object" && source !== null && "getEntries" in source ? source.getEntries() : source;
|
|
28
|
+
return foldRunSessionEntries(entries, runId);
|
|
29
|
+
}
|
|
30
|
+
var ACTIVE_LOCAL_RUN_STATUSES = new Set([
|
|
31
|
+
"created",
|
|
32
|
+
"preparing",
|
|
33
|
+
"running",
|
|
34
|
+
"validating",
|
|
35
|
+
"reviewing",
|
|
36
|
+
"closing-out"
|
|
37
|
+
]);
|
|
38
|
+
function pidExists(pid) {
|
|
39
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
40
|
+
return false;
|
|
41
|
+
try {
|
|
42
|
+
process.kill(pid, 0);
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function defaultOpenSession(sessionPath) {
|
|
49
|
+
const { SessionManager } = await loadSessionManager();
|
|
50
|
+
return await SessionManager.open(sessionPath, undefined, undefined, { suppressBreadcrumb: true });
|
|
51
|
+
}
|
|
52
|
+
function projectionRunId(item) {
|
|
53
|
+
if (item.runId?.trim())
|
|
54
|
+
return item.runId.trim();
|
|
55
|
+
if (item.collab?.sessionId?.trim())
|
|
56
|
+
return item.collab.sessionId.trim();
|
|
57
|
+
if (item.session.id?.trim())
|
|
58
|
+
return item.session.id.trim();
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function isLocallyDiscovered(item) {
|
|
62
|
+
return item.source === "session-list";
|
|
63
|
+
}
|
|
64
|
+
function isActiveStatus(status) {
|
|
65
|
+
if (status === null)
|
|
66
|
+
return false;
|
|
67
|
+
return !isTerminalRunStatus(status);
|
|
68
|
+
}
|
|
69
|
+
function shouldFlip(item, status, exists) {
|
|
70
|
+
if (!isActiveStatus(status))
|
|
71
|
+
return false;
|
|
72
|
+
if (item.collab?.stale === true)
|
|
73
|
+
return true;
|
|
74
|
+
const pid = item.collab?.pid;
|
|
75
|
+
return isLocallyDiscovered(item) && pid !== undefined && ACTIVE_LOCAL_RUN_STATUSES.has(status) && !exists(pid);
|
|
76
|
+
}
|
|
77
|
+
function failedStatusData(status, at) {
|
|
78
|
+
return {
|
|
79
|
+
type: "status-changed",
|
|
80
|
+
from: status,
|
|
81
|
+
to: "failed",
|
|
82
|
+
reason: "lazy-reconcile:dead-pid",
|
|
83
|
+
actor: { kind: "agent" },
|
|
84
|
+
at
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async function reconcileRuns(input, deps = {}) {
|
|
88
|
+
const listProjections = deps.listCollabSessionProjections ?? (await loadCollabApi()).listCollabSessionProjections;
|
|
89
|
+
const projectRun = deps.projectRunFromSession ?? projectRunFromEntries;
|
|
90
|
+
const exists = deps.processExists ?? pidExists;
|
|
91
|
+
const openSession = deps.openSession ?? defaultOpenSession;
|
|
92
|
+
const nowIso = deps.nowIso ?? (() => new Date().toISOString());
|
|
93
|
+
const projections = await listProjections(input.identityFilter);
|
|
94
|
+
const flipped = [];
|
|
95
|
+
for (const item of projections) {
|
|
96
|
+
const runId = projectionRunId(item);
|
|
97
|
+
const sessionPath = item.session.path || item.collab?.sessionPath || "";
|
|
98
|
+
if (!runId || !sessionPath)
|
|
99
|
+
continue;
|
|
100
|
+
const projection = await projectRun(item.customEntries, runId);
|
|
101
|
+
const status = projection.status;
|
|
102
|
+
if (status === null || !shouldFlip(item, status, exists))
|
|
103
|
+
continue;
|
|
104
|
+
const session = await openSession(sessionPath);
|
|
105
|
+
session.appendCustomEntry(CUSTOM_TYPE_FOR["status-changed"], failedStatusData(status, nowIso()));
|
|
106
|
+
flipped.push({ runId, sessionPath, reason: "lazy-reconcile:dead-pid" });
|
|
107
|
+
}
|
|
108
|
+
return { flipped, resumable: flipped };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// packages/product-entrypoint-plugin/src/product-entrypoint.ts
|
|
11
112
|
import rigExtension from "@rig/rig-extension";
|
|
12
113
|
import { resolveRigOmpConfigOverlayPath } from "@rig/runtime/control-plane/remote-config";
|
|
13
114
|
function withRigDefaultConfig(projectRoot, argv) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SessionManager } from "@oh-my-pi/pi-coding-agent/session/session-manager";
|
|
2
|
+
import { type RunJournalProjection, type RunSessionCustomEntry } from "@rig/contracts";
|
|
3
|
+
import type { CollabRegistryFilter, CollabSessionProjection } from "@oh-my-pi/pi-coding-agent/collab/api";
|
|
4
|
+
type SessionWriter = {
|
|
5
|
+
appendCustomEntry(customType: string, data: unknown): void;
|
|
6
|
+
};
|
|
7
|
+
export type CollabSessionProjectionLike = Pick<CollabSessionProjection, "collab" | "customEntries" | "source"> & {
|
|
8
|
+
readonly runId?: string;
|
|
9
|
+
readonly session: Pick<CollabSessionProjection["session"], "path" | "id">;
|
|
10
|
+
};
|
|
11
|
+
export type ProjectRunProjection = Pick<RunJournalProjection, "status">;
|
|
12
|
+
export type ProjectRunFromSession = (source: Pick<SessionManager, "getEntries"> | ReadonlyArray<RunSessionCustomEntry> | readonly unknown[], runId: string) => ProjectRunProjection;
|
|
13
|
+
export type LazyReconcileFlippedRun = {
|
|
14
|
+
readonly runId: string;
|
|
15
|
+
readonly sessionPath: string;
|
|
16
|
+
readonly reason: "lazy-reconcile:dead-pid";
|
|
17
|
+
};
|
|
18
|
+
export type LazyReconcileResult = {
|
|
19
|
+
readonly flipped: readonly LazyReconcileFlippedRun[];
|
|
20
|
+
readonly resumable: readonly LazyReconcileFlippedRun[];
|
|
21
|
+
};
|
|
22
|
+
type LazyReconcileDeps = {
|
|
23
|
+
readonly listCollabSessionProjections?: (filter: CollabRegistryFilter) => Promise<readonly CollabSessionProjectionLike[]>;
|
|
24
|
+
readonly projectRunFromSession?: ProjectRunFromSession;
|
|
25
|
+
readonly processExists?: (pid: number) => boolean;
|
|
26
|
+
readonly openSession?: (sessionPath: string) => Promise<SessionWriter>;
|
|
27
|
+
readonly nowIso?: () => string;
|
|
28
|
+
};
|
|
29
|
+
export type LazyReconcileInput = {
|
|
30
|
+
readonly workspaceRoot: string;
|
|
31
|
+
readonly identityFilter: CollabRegistryFilter;
|
|
32
|
+
};
|
|
33
|
+
export declare function reconcileRuns(input: LazyReconcileInput, deps?: LazyReconcileDeps): Promise<LazyReconcileResult>;
|
|
34
|
+
export declare const runLazyReconcile: typeof reconcileRuns;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
4
|
+
// packages/product-entrypoint-plugin/src/reconcile.ts
|
|
5
|
+
import {
|
|
6
|
+
CUSTOM_TYPE_FOR,
|
|
7
|
+
foldRunSessionEntries,
|
|
8
|
+
isTerminalRunStatus
|
|
9
|
+
} from "@rig/contracts";
|
|
10
|
+
async function loadCollabApi() {
|
|
11
|
+
return await import("@oh-my-pi/pi-coding-agent/collab/api");
|
|
12
|
+
}
|
|
13
|
+
async function loadSessionManager() {
|
|
14
|
+
return await import("@oh-my-pi/pi-coding-agent/session/session-manager");
|
|
15
|
+
}
|
|
16
|
+
function projectRunFromEntries(source, runId) {
|
|
17
|
+
const entries = typeof source === "object" && source !== null && "getEntries" in source ? source.getEntries() : source;
|
|
18
|
+
return foldRunSessionEntries(entries, runId);
|
|
19
|
+
}
|
|
20
|
+
var ACTIVE_LOCAL_RUN_STATUSES = new Set([
|
|
21
|
+
"created",
|
|
22
|
+
"preparing",
|
|
23
|
+
"running",
|
|
24
|
+
"validating",
|
|
25
|
+
"reviewing",
|
|
26
|
+
"closing-out"
|
|
27
|
+
]);
|
|
28
|
+
function pidExists(pid) {
|
|
29
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
30
|
+
return false;
|
|
31
|
+
try {
|
|
32
|
+
process.kill(pid, 0);
|
|
33
|
+
return true;
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function defaultOpenSession(sessionPath) {
|
|
39
|
+
const { SessionManager } = await loadSessionManager();
|
|
40
|
+
return await SessionManager.open(sessionPath, undefined, undefined, { suppressBreadcrumb: true });
|
|
41
|
+
}
|
|
42
|
+
function projectionRunId(item) {
|
|
43
|
+
if (item.runId?.trim())
|
|
44
|
+
return item.runId.trim();
|
|
45
|
+
if (item.collab?.sessionId?.trim())
|
|
46
|
+
return item.collab.sessionId.trim();
|
|
47
|
+
if (item.session.id?.trim())
|
|
48
|
+
return item.session.id.trim();
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function isLocallyDiscovered(item) {
|
|
52
|
+
return item.source === "session-list";
|
|
53
|
+
}
|
|
54
|
+
function isActiveStatus(status) {
|
|
55
|
+
if (status === null)
|
|
56
|
+
return false;
|
|
57
|
+
return !isTerminalRunStatus(status);
|
|
58
|
+
}
|
|
59
|
+
function shouldFlip(item, status, exists) {
|
|
60
|
+
if (!isActiveStatus(status))
|
|
61
|
+
return false;
|
|
62
|
+
if (item.collab?.stale === true)
|
|
63
|
+
return true;
|
|
64
|
+
const pid = item.collab?.pid;
|
|
65
|
+
return isLocallyDiscovered(item) && pid !== undefined && ACTIVE_LOCAL_RUN_STATUSES.has(status) && !exists(pid);
|
|
66
|
+
}
|
|
67
|
+
function failedStatusData(status, at) {
|
|
68
|
+
return {
|
|
69
|
+
type: "status-changed",
|
|
70
|
+
from: status,
|
|
71
|
+
to: "failed",
|
|
72
|
+
reason: "lazy-reconcile:dead-pid",
|
|
73
|
+
actor: { kind: "agent" },
|
|
74
|
+
at
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
async function reconcileRuns(input, deps = {}) {
|
|
78
|
+
const listProjections = deps.listCollabSessionProjections ?? (await loadCollabApi()).listCollabSessionProjections;
|
|
79
|
+
const projectRun = deps.projectRunFromSession ?? projectRunFromEntries;
|
|
80
|
+
const exists = deps.processExists ?? pidExists;
|
|
81
|
+
const openSession = deps.openSession ?? defaultOpenSession;
|
|
82
|
+
const nowIso = deps.nowIso ?? (() => new Date().toISOString());
|
|
83
|
+
const projections = await listProjections(input.identityFilter);
|
|
84
|
+
const flipped = [];
|
|
85
|
+
for (const item of projections) {
|
|
86
|
+
const runId = projectionRunId(item);
|
|
87
|
+
const sessionPath = item.session.path || item.collab?.sessionPath || "";
|
|
88
|
+
if (!runId || !sessionPath)
|
|
89
|
+
continue;
|
|
90
|
+
const projection = await projectRun(item.customEntries, runId);
|
|
91
|
+
const status = projection.status;
|
|
92
|
+
if (status === null || !shouldFlip(item, status, exists))
|
|
93
|
+
continue;
|
|
94
|
+
const session = await openSession(sessionPath);
|
|
95
|
+
session.appendCustomEntry(CUSTOM_TYPE_FOR["status-changed"], failedStatusData(status, nowIso()));
|
|
96
|
+
flipped.push({ runId, sessionPath, reason: "lazy-reconcile:dead-pid" });
|
|
97
|
+
}
|
|
98
|
+
return { flipped, resumable: flipped };
|
|
99
|
+
}
|
|
100
|
+
var runLazyReconcile = reconcileRuns;
|
|
101
|
+
export {
|
|
102
|
+
runLazyReconcile,
|
|
103
|
+
reconcileRuns
|
|
104
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-rig/product-entrypoint-plugin",
|
|
3
|
-
"version": "0.0.6-alpha.
|
|
3
|
+
"version": "0.0.6-alpha.157",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Standard Rig product entrypoint plugin boundary for OMP-backed product commands.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -31,9 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@oh-my-pi/pi-coding-agent": "16.0.4",
|
|
34
|
-
"@rig/
|
|
35
|
-
"@rig/
|
|
36
|
-
"@rig/
|
|
37
|
-
"@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.155"
|
|
34
|
+
"@rig/core": "npm:@h-rig/core@0.0.6-alpha.157",
|
|
35
|
+
"@rig/rig-extension": "npm:@h-rig/rig-extension@0.0.6-alpha.157",
|
|
36
|
+
"@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.157"
|
|
38
37
|
}
|
|
39
38
|
}
|