@h-rig/server 0.0.6-alpha.0
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 +14 -0
- package/dist/src/bootstrap.js +161 -0
- package/dist/src/index.js +13153 -0
- package/dist/src/inspector/agent-runtime.js +1077 -0
- package/dist/src/inspector/analysis.js +41 -0
- package/dist/src/inspector/discovery.js +137 -0
- package/dist/src/inspector/journal.js +518 -0
- package/dist/src/inspector/mission.js +562 -0
- package/dist/src/inspector/prompt.js +97 -0
- package/dist/src/inspector/provider-session.js +65 -0
- package/dist/src/inspector/reconcile.js +118 -0
- package/dist/src/inspector/review.js +13 -0
- package/dist/src/inspector/service.js +1759 -0
- package/dist/src/inspector/skills.js +155 -0
- package/dist/src/inspector/tools.js +1592 -0
- package/dist/src/inspector/types.js +1 -0
- package/dist/src/inspector/upstream-sync.js +479 -0
- package/dist/src/orchestration.js +402 -0
- package/dist/src/remote.js +123 -0
- package/dist/src/scheduler.js +84 -0
- package/dist/src/server-helpers/broadcasters.js +161 -0
- package/dist/src/server-helpers/conversation-snapshot.js +382 -0
- package/dist/src/server-helpers/event-emitter.js +41 -0
- package/dist/src/server-helpers/github-auth-store.js +155 -0
- package/dist/src/server-helpers/github-credentials.js +38 -0
- package/dist/src/server-helpers/github-project-status-sync.js +196 -0
- package/dist/src/server-helpers/github-projects.js +147 -0
- package/dist/src/server-helpers/github-reconciler.js +89 -0
- package/dist/src/server-helpers/http-router.js +3781 -0
- package/dist/src/server-helpers/http-utils.js +135 -0
- package/dist/src/server-helpers/inspector-agent-lifecycle.js +104 -0
- package/dist/src/server-helpers/inspector-jobs.js +4145 -0
- package/dist/src/server-helpers/issue-analysis.js +362 -0
- package/dist/src/server-helpers/normalizers.js +31 -0
- package/dist/src/server-helpers/notifications.js +96 -0
- package/dist/src/server-helpers/orchestration-ops.js +287 -0
- package/dist/src/server-helpers/orchestration.js +39 -0
- package/dist/src/server-helpers/plugin-host-cache.js +86 -0
- package/dist/src/server-helpers/project-fs-ops.js +194 -0
- package/dist/src/server-helpers/project-registry.js +124 -0
- package/dist/src/server-helpers/queue-state.js +78 -0
- package/dist/src/server-helpers/remote-checkout.js +140 -0
- package/dist/src/server-helpers/remote-snapshots.js +119 -0
- package/dist/src/server-helpers/run-io.js +262 -0
- package/dist/src/server-helpers/run-mutations.js +1784 -0
- package/dist/src/server-helpers/run-steering.js +176 -0
- package/dist/src/server-helpers/run-writers.js +75 -0
- package/dist/src/server-helpers/server-paths.js +27 -0
- package/dist/src/server-helpers/snapshot-orchestrator.js +832 -0
- package/dist/src/server-helpers/snapshot-service.js +1143 -0
- package/dist/src/server-helpers/summaries.js +126 -0
- package/dist/src/server-helpers/task-config.js +50 -0
- package/dist/src/server-helpers/task-projection.js +98 -0
- package/dist/src/server-helpers/terminal-runtime.js +156 -0
- package/dist/src/server-helpers/terminal-sessions.js +22 -0
- package/dist/src/server-helpers/validation-failure.js +31 -0
- package/dist/src/server-helpers/ws-router.js +1308 -0
- package/dist/src/server.js +12628 -0
- package/dist/src/websocket.js +63 -0
- package/package.json +33 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/server/src/server-helpers/run-steering.ts
|
|
3
|
+
import { dirname as dirname2, resolve as resolve3 } from "path";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync } from "fs";
|
|
5
|
+
import { appendJsonlRecord as appendJsonlRecord2, readAuthorityRun as readAuthorityRun3, resolveAuthorityRunDir as resolveAuthorityRunDir3 } from "@rig/runtime/control-plane/authority-files";
|
|
6
|
+
|
|
7
|
+
// packages/server/src/server-helpers/run-writers.ts
|
|
8
|
+
import { resolve as resolve2 } from "path";
|
|
9
|
+
import {
|
|
10
|
+
appendJsonlRecord,
|
|
11
|
+
readAuthorityRun as readAuthorityRun2,
|
|
12
|
+
resolveAuthorityRunDir as resolveAuthorityRunDir2,
|
|
13
|
+
writeJsonFile
|
|
14
|
+
} from "@rig/runtime/control-plane/authority-files";
|
|
15
|
+
|
|
16
|
+
// packages/server/src/server-helpers/normalizers.ts
|
|
17
|
+
function normalizeString(value) {
|
|
18
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// packages/server/src/server-helpers/run-io.ts
|
|
22
|
+
import { dirname, resolve } from "path";
|
|
23
|
+
import {
|
|
24
|
+
listAuthorityRuns,
|
|
25
|
+
readAuthorityRun,
|
|
26
|
+
readJsonlFile,
|
|
27
|
+
resolveAuthorityRunDir
|
|
28
|
+
} from "@rig/runtime/control-plane/authority-files";
|
|
29
|
+
function runTimelinePath(projectRoot, runId) {
|
|
30
|
+
return resolve(resolveAuthorityRunDir(projectRoot, runId), "timeline.jsonl");
|
|
31
|
+
}
|
|
32
|
+
var INITIAL_RUN_LOG_TAIL_MAX_BYTES = 8 * 1024 * 1024;
|
|
33
|
+
|
|
34
|
+
// packages/server/src/server-helpers/run-writers.ts
|
|
35
|
+
function appendRunTimelineEntry(projectRoot, runId, value) {
|
|
36
|
+
if (!readAuthorityRun2(projectRoot, runId)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
appendJsonlRecord(runTimelinePath(projectRoot, runId), value);
|
|
40
|
+
patchRunRecord(projectRoot, runId, {});
|
|
41
|
+
}
|
|
42
|
+
function patchRunRecord(projectRoot, runId, patch) {
|
|
43
|
+
const current = readAuthorityRun2(projectRoot, runId);
|
|
44
|
+
if (!current) {
|
|
45
|
+
throw new Error(`Run not found: ${runId}`);
|
|
46
|
+
}
|
|
47
|
+
const next = {
|
|
48
|
+
...current,
|
|
49
|
+
...patch,
|
|
50
|
+
updatedAt: normalizeString(patch.updatedAt) ?? new Date().toISOString()
|
|
51
|
+
};
|
|
52
|
+
writeJsonFile(resolve2(resolveAuthorityRunDir2(projectRoot, runId), "run.json"), next);
|
|
53
|
+
return next;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// packages/server/src/server-helpers/run-steering.ts
|
|
57
|
+
var steeringSequence = 0;
|
|
58
|
+
function runSteeringPath(projectRoot, runId) {
|
|
59
|
+
return resolve3(resolveAuthorityRunDir3(projectRoot, runId), "steering.jsonl");
|
|
60
|
+
}
|
|
61
|
+
function readJsonl(path) {
|
|
62
|
+
if (!existsSync(path))
|
|
63
|
+
return [];
|
|
64
|
+
return readFileSync(path, "utf8").split(/\r?\n/).map((line) => line.trim()).filter(Boolean).flatMap((line) => {
|
|
65
|
+
try {
|
|
66
|
+
const value = JSON.parse(line);
|
|
67
|
+
return value && typeof value === "object" && !Array.isArray(value) ? [value] : [];
|
|
68
|
+
} catch {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function normalizeQueuedMessage(record) {
|
|
74
|
+
const id = typeof record.id === "string" ? record.id : null;
|
|
75
|
+
const runId = typeof record.runId === "string" ? record.runId : null;
|
|
76
|
+
const message = typeof record.message === "string" ? record.message : null;
|
|
77
|
+
if (!id || !runId || !message)
|
|
78
|
+
return null;
|
|
79
|
+
return {
|
|
80
|
+
id,
|
|
81
|
+
runId,
|
|
82
|
+
message,
|
|
83
|
+
actor: typeof record.actor === "string" ? record.actor : "operator",
|
|
84
|
+
createdAt: typeof record.createdAt === "string" ? record.createdAt : new Date().toISOString(),
|
|
85
|
+
delivered: record.delivered === true
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function readQueuedRunSteeringMessages(projectRoot, runId) {
|
|
89
|
+
const latestById = new Map;
|
|
90
|
+
for (const record of readJsonl(runSteeringPath(projectRoot, runId))) {
|
|
91
|
+
const message = normalizeQueuedMessage(record);
|
|
92
|
+
if (message)
|
|
93
|
+
latestById.set(message.id, message);
|
|
94
|
+
}
|
|
95
|
+
return Array.from(latestById.values());
|
|
96
|
+
}
|
|
97
|
+
function markQueuedRunSteeringMessagesDelivered(projectRoot, runId, ids) {
|
|
98
|
+
const requested = new Set(ids.map((id) => id.trim()).filter(Boolean));
|
|
99
|
+
if (requested.size === 0)
|
|
100
|
+
return [];
|
|
101
|
+
const existing = readQueuedRunSteeringMessages(projectRoot, runId);
|
|
102
|
+
const deliveredAt = new Date().toISOString();
|
|
103
|
+
const path = runSteeringPath(projectRoot, runId);
|
|
104
|
+
const delivered = [];
|
|
105
|
+
for (const entry of existing) {
|
|
106
|
+
if (!requested.has(entry.id) || entry.delivered)
|
|
107
|
+
continue;
|
|
108
|
+
appendJsonlRecord2(path, { ...entry, delivered: true, deliveredAt });
|
|
109
|
+
delivered.push(entry.id);
|
|
110
|
+
}
|
|
111
|
+
if (delivered.length > 0) {
|
|
112
|
+
appendRunTimelineEntry(projectRoot, runId, {
|
|
113
|
+
id: `steering-ack:${runId}:${Date.now()}`,
|
|
114
|
+
type: "rig_bridge_event",
|
|
115
|
+
text: `Delivered ${delivered.length} steering message${delivered.length === 1 ? "" : "s"}`,
|
|
116
|
+
createdAt: deliveredAt,
|
|
117
|
+
state: "completed",
|
|
118
|
+
payload: { kind: "steering-delivered", messageIds: delivered }
|
|
119
|
+
});
|
|
120
|
+
patchRunRecord(projectRoot, runId, { latestSteeringDeliveredAt: deliveredAt });
|
|
121
|
+
}
|
|
122
|
+
return delivered;
|
|
123
|
+
}
|
|
124
|
+
function queueRunSteeringMessage(projectRoot, runId, input) {
|
|
125
|
+
const run = readAuthorityRun3(projectRoot, runId);
|
|
126
|
+
if (!run)
|
|
127
|
+
throw new Error(`Run not found: ${runId}`);
|
|
128
|
+
const text = input.message.trim();
|
|
129
|
+
if (!text)
|
|
130
|
+
throw new Error("message is required");
|
|
131
|
+
const createdAt = new Date().toISOString();
|
|
132
|
+
const entry = {
|
|
133
|
+
id: `steer:${runId}:${Date.now()}:${++steeringSequence}`,
|
|
134
|
+
runId,
|
|
135
|
+
message: text,
|
|
136
|
+
actor: input.actor?.trim() || "operator",
|
|
137
|
+
createdAt,
|
|
138
|
+
delivered: false
|
|
139
|
+
};
|
|
140
|
+
const path = runSteeringPath(projectRoot, runId);
|
|
141
|
+
mkdirSync(dirname2(path), { recursive: true });
|
|
142
|
+
appendJsonlRecord2(path, entry);
|
|
143
|
+
appendRunTimelineEntry(projectRoot, runId, {
|
|
144
|
+
id: entry.id,
|
|
145
|
+
type: "operator_message",
|
|
146
|
+
text,
|
|
147
|
+
createdAt,
|
|
148
|
+
state: "queued"
|
|
149
|
+
});
|
|
150
|
+
patchRunRecord(projectRoot, runId, { latestSteeringAt: createdAt });
|
|
151
|
+
return entry;
|
|
152
|
+
}
|
|
153
|
+
function appendRunBridgeEvent(projectRoot, runId, event) {
|
|
154
|
+
const kind = typeof event.kind === "string" ? event.kind : "event";
|
|
155
|
+
const createdAt = typeof event.createdAt === "string" ? event.createdAt : new Date().toISOString();
|
|
156
|
+
if (kind === "status") {
|
|
157
|
+
patchRunRecord(projectRoot, runId, { statusDetail: event.message ?? event.status ?? null, updatedAt: createdAt });
|
|
158
|
+
}
|
|
159
|
+
if (kind === "artifact" || kind === "task-metadata" || kind === "status") {
|
|
160
|
+
appendRunTimelineEntry(projectRoot, runId, {
|
|
161
|
+
id: `pi-rig:${kind}:${Date.now()}`,
|
|
162
|
+
type: "rig_bridge_event",
|
|
163
|
+
text: typeof event.message === "string" ? event.message : JSON.stringify(event),
|
|
164
|
+
createdAt,
|
|
165
|
+
state: "completed",
|
|
166
|
+
payload: event
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
runSteeringPath,
|
|
172
|
+
readQueuedRunSteeringMessages,
|
|
173
|
+
queueRunSteeringMessage,
|
|
174
|
+
markQueuedRunSteeringMessagesDelivered,
|
|
175
|
+
appendRunBridgeEvent
|
|
176
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/server/src/server-helpers/run-writers.ts
|
|
3
|
+
import { resolve as resolve2 } from "path";
|
|
4
|
+
import {
|
|
5
|
+
appendJsonlRecord,
|
|
6
|
+
readAuthorityRun as readAuthorityRun2,
|
|
7
|
+
resolveAuthorityRunDir as resolveAuthorityRunDir2,
|
|
8
|
+
writeJsonFile
|
|
9
|
+
} from "@rig/runtime/control-plane/authority-files";
|
|
10
|
+
|
|
11
|
+
// packages/server/src/server-helpers/normalizers.ts
|
|
12
|
+
function normalizeString(value) {
|
|
13
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// packages/server/src/server-helpers/run-io.ts
|
|
17
|
+
import { dirname, resolve } from "path";
|
|
18
|
+
import {
|
|
19
|
+
listAuthorityRuns,
|
|
20
|
+
readAuthorityRun,
|
|
21
|
+
readJsonlFile,
|
|
22
|
+
resolveAuthorityRunDir
|
|
23
|
+
} from "@rig/runtime/control-plane/authority-files";
|
|
24
|
+
function runTimelinePath(projectRoot, runId) {
|
|
25
|
+
return resolve(resolveAuthorityRunDir(projectRoot, runId), "timeline.jsonl");
|
|
26
|
+
}
|
|
27
|
+
function runLogsPath(projectRoot, runId) {
|
|
28
|
+
return resolve(resolveAuthorityRunDir(projectRoot, runId), "logs.jsonl");
|
|
29
|
+
}
|
|
30
|
+
var INITIAL_RUN_LOG_TAIL_MAX_BYTES = 8 * 1024 * 1024;
|
|
31
|
+
|
|
32
|
+
// packages/server/src/server-helpers/run-writers.ts
|
|
33
|
+
function appendRunTimelineEntry(projectRoot, runId, value) {
|
|
34
|
+
if (!readAuthorityRun2(projectRoot, runId)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
appendJsonlRecord(runTimelinePath(projectRoot, runId), value);
|
|
38
|
+
patchRunRecord(projectRoot, runId, {});
|
|
39
|
+
}
|
|
40
|
+
function appendRunLogEntry(projectRoot, runId, value) {
|
|
41
|
+
if (!readAuthorityRun2(projectRoot, runId)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
appendJsonlRecord(runLogsPath(projectRoot, runId), value);
|
|
45
|
+
patchRunRecord(projectRoot, runId, {});
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
function patchRunRecord(projectRoot, runId, patch) {
|
|
49
|
+
const current = readAuthorityRun2(projectRoot, runId);
|
|
50
|
+
if (!current) {
|
|
51
|
+
throw new Error(`Run not found: ${runId}`);
|
|
52
|
+
}
|
|
53
|
+
const next = {
|
|
54
|
+
...current,
|
|
55
|
+
...patch,
|
|
56
|
+
updatedAt: normalizeString(patch.updatedAt) ?? new Date().toISOString()
|
|
57
|
+
};
|
|
58
|
+
writeJsonFile(resolve2(resolveAuthorityRunDir2(projectRoot, runId), "run.json"), next);
|
|
59
|
+
return next;
|
|
60
|
+
}
|
|
61
|
+
function buildRunStartPatch(startedAt) {
|
|
62
|
+
return {
|
|
63
|
+
status: "preparing",
|
|
64
|
+
startedAt,
|
|
65
|
+
completedAt: null,
|
|
66
|
+
errorText: null,
|
|
67
|
+
serverPid: process.pid
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
patchRunRecord,
|
|
72
|
+
buildRunStartPatch,
|
|
73
|
+
appendRunTimelineEntry,
|
|
74
|
+
appendRunLogEntry
|
|
75
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/server/src/server-helpers/server-paths.ts
|
|
3
|
+
import { dirname, resolve } from "path";
|
|
4
|
+
import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
|
|
5
|
+
function resolveServerAuthorityPaths(projectRoot) {
|
|
6
|
+
const taskWorkspace = process.env.RIG_TASK_WORKSPACE?.trim();
|
|
7
|
+
const explicitStateDir = process.env.RIG_STATE_DIR?.trim();
|
|
8
|
+
const explicitLogsDir = process.env.RIG_LOGS_DIR?.trim();
|
|
9
|
+
const explicitSessionFile = process.env.RIG_SESSION_FILE?.trim();
|
|
10
|
+
const monorepoRoot = resolveMonorepoRoot(projectRoot);
|
|
11
|
+
const stateRoot = taskWorkspace ? resolve(taskWorkspace, ".rig") : explicitStateDir ? dirname(resolve(explicitStateDir)) : explicitLogsDir ? dirname(resolve(explicitLogsDir)) : explicitSessionFile ? dirname(dirname(resolve(explicitSessionFile))) : resolve(monorepoRoot, ".rig");
|
|
12
|
+
const stateDir = explicitStateDir ? resolve(explicitStateDir) : resolve(stateRoot, "state");
|
|
13
|
+
const logsDir = explicitLogsDir ? resolve(explicitLogsDir) : resolve(stateRoot, "logs");
|
|
14
|
+
const sessionFile = explicitSessionFile ? resolve(explicitSessionFile) : resolve(stateRoot, "session", "session.json");
|
|
15
|
+
const artifactsDir = taskWorkspace ? resolve(taskWorkspace, "artifacts") : resolve(monorepoRoot, "artifacts");
|
|
16
|
+
return {
|
|
17
|
+
stateRoot,
|
|
18
|
+
stateDir,
|
|
19
|
+
logsDir,
|
|
20
|
+
controlPlaneEventsFile: resolve(logsDir, "control-plane.events.jsonl"),
|
|
21
|
+
sessionFile,
|
|
22
|
+
artifactsDir
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
resolveServerAuthorityPaths
|
|
27
|
+
};
|