@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
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Rig Server
|
|
2
|
+
|
|
3
|
+
`@rig/server` is the local server that powers desktop, web, and TUI flows.
|
|
4
|
+
|
|
5
|
+
## Responsibilities
|
|
6
|
+
|
|
7
|
+
- serve workspace snapshots and artifacts
|
|
8
|
+
- broker approvals and remote endpoint state
|
|
9
|
+
- expose websocket events for the UI
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
- `bun run rig server start`
|
|
14
|
+
- `bun test packages/server/src/server.test.ts`
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/server/src/bootstrap.ts
|
|
3
|
+
import { existsSync, mkdirSync, unlinkSync, writeFileSync } from "fs";
|
|
4
|
+
import { dirname, resolve } from "path";
|
|
5
|
+
import { RIG_DEFINITION_DIRNAME, resolveMonorepoRoot } from "@rig/runtime";
|
|
6
|
+
function normalizeOptionalString(value) {
|
|
7
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
8
|
+
}
|
|
9
|
+
function normalizeOptionalBoolean(value, fallback) {
|
|
10
|
+
if (typeof value !== "string") {
|
|
11
|
+
return fallback;
|
|
12
|
+
}
|
|
13
|
+
const normalized = value.trim().toLowerCase();
|
|
14
|
+
if (["1", "true", "yes", "on"].includes(normalized)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (["0", "false", "no", "off"].includes(normalized)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return fallback;
|
|
21
|
+
}
|
|
22
|
+
function parseRigServerArgs(args, env = process.env) {
|
|
23
|
+
const command = args[0] || "start";
|
|
24
|
+
if (command !== "start" && command !== "notify-test") {
|
|
25
|
+
throw new Error(`Unknown command: ${command}`);
|
|
26
|
+
}
|
|
27
|
+
let host = env.RIG_SERVER_HOST || "127.0.0.1";
|
|
28
|
+
let port = Number.parseInt(env.RIG_SERVER_PORT || "8787", 10);
|
|
29
|
+
let pollMs = Number.parseInt(env.RIG_SERVER_POLL_MS || "1000", 10);
|
|
30
|
+
let upstreamSyncMs = Number.parseInt(env.RIG_SERVER_UPSTREAM_SYNC_MS || "900000", 10);
|
|
31
|
+
let upstreamSyncOnStart = normalizeOptionalBoolean(env.RIG_SERVER_UPSTREAM_SYNC_ON_START, true);
|
|
32
|
+
let authToken = normalizeOptionalString(env.RIG_SERVER_AUTH_TOKEN);
|
|
33
|
+
let eventType = "manual.test";
|
|
34
|
+
for (let index = 1;index < args.length; index += 1) {
|
|
35
|
+
const current = args[index];
|
|
36
|
+
const next = args[index + 1];
|
|
37
|
+
if (current === "--host") {
|
|
38
|
+
if (!next)
|
|
39
|
+
throw new Error("Missing value for --host");
|
|
40
|
+
host = next;
|
|
41
|
+
index += 1;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (current === "--port") {
|
|
45
|
+
if (!next)
|
|
46
|
+
throw new Error("Missing value for --port");
|
|
47
|
+
port = Number.parseInt(next, 10);
|
|
48
|
+
index += 1;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (current === "--poll-ms") {
|
|
52
|
+
if (!next)
|
|
53
|
+
throw new Error("Missing value for --poll-ms");
|
|
54
|
+
pollMs = Number.parseInt(next, 10);
|
|
55
|
+
index += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (current === "--upstream-sync-ms") {
|
|
59
|
+
if (!next)
|
|
60
|
+
throw new Error("Missing value for --upstream-sync-ms");
|
|
61
|
+
upstreamSyncMs = Number.parseInt(next, 10);
|
|
62
|
+
index += 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (current === "--upstream-sync-on-start") {
|
|
66
|
+
upstreamSyncOnStart = true;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (current === "--no-upstream-sync-on-start") {
|
|
70
|
+
upstreamSyncOnStart = false;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (current === "--auth-token") {
|
|
74
|
+
if (!next)
|
|
75
|
+
throw new Error("Missing value for --auth-token");
|
|
76
|
+
authToken = normalizeOptionalString(next);
|
|
77
|
+
index += 1;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (current === "--event") {
|
|
81
|
+
if (!next)
|
|
82
|
+
throw new Error("Missing value for --event");
|
|
83
|
+
eventType = next;
|
|
84
|
+
index += 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`Unknown option: ${current}`);
|
|
88
|
+
}
|
|
89
|
+
if (!Number.isFinite(port) || port < 0) {
|
|
90
|
+
throw new Error(`Invalid --port: ${port}`);
|
|
91
|
+
}
|
|
92
|
+
if (!Number.isFinite(pollMs) || pollMs <= 0) {
|
|
93
|
+
throw new Error(`Invalid --poll-ms: ${pollMs}`);
|
|
94
|
+
}
|
|
95
|
+
if (!Number.isFinite(upstreamSyncMs) || upstreamSyncMs < 0) {
|
|
96
|
+
throw new Error(`Invalid --upstream-sync-ms: ${upstreamSyncMs}`);
|
|
97
|
+
}
|
|
98
|
+
return { command, host, port, pollMs, upstreamSyncMs, upstreamSyncOnStart, authToken, eventType };
|
|
99
|
+
}
|
|
100
|
+
function resolvePublishedRigServerStatePath(projectRoot) {
|
|
101
|
+
return resolve(resolveRigServerPaths(projectRoot).stateDir, "rig-server.json");
|
|
102
|
+
}
|
|
103
|
+
function publishRigServerState(projectRoot, payload) {
|
|
104
|
+
const filePath = resolvePublishedRigServerStatePath(projectRoot);
|
|
105
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
106
|
+
writeFileSync(filePath, `${JSON.stringify(payload, null, 2)}
|
|
107
|
+
`, "utf8");
|
|
108
|
+
}
|
|
109
|
+
function clearPublishedRigServerState(projectRoot) {
|
|
110
|
+
const filePath = resolvePublishedRigServerStatePath(projectRoot);
|
|
111
|
+
if (!existsSync(filePath)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
unlinkSync(filePath);
|
|
116
|
+
} catch {}
|
|
117
|
+
}
|
|
118
|
+
function resolveRigServerPaths(projectRoot) {
|
|
119
|
+
const taskWorkspace = normalizeOptionalString(process.env.RIG_TASK_WORKSPACE);
|
|
120
|
+
const explicitStateDir = normalizeOptionalString(process.env.RIG_STATE_DIR);
|
|
121
|
+
const explicitLogsDir = normalizeOptionalString(process.env.RIG_LOGS_DIR);
|
|
122
|
+
const explicitSessionFile = normalizeOptionalString(process.env.RIG_SESSION_FILE);
|
|
123
|
+
const hostStateRoot = resolve(projectRoot, ".rig");
|
|
124
|
+
const monorepoRoot = resolveMonorepoRoot(projectRoot);
|
|
125
|
+
const monorepoStateRoot = resolve(monorepoRoot, ".rig");
|
|
126
|
+
const stateRoot = taskWorkspace ? resolve(taskWorkspace, ".rig") : explicitStateDir ? dirname(resolve(explicitStateDir)) : explicitLogsDir ? dirname(resolve(explicitLogsDir)) : explicitSessionFile ? dirname(dirname(resolve(explicitSessionFile))) : existsSync(hostStateRoot) ? hostStateRoot : monorepoStateRoot;
|
|
127
|
+
const stateDir = explicitStateDir ? resolve(explicitStateDir) : resolve(stateRoot, "state");
|
|
128
|
+
const logsDir = explicitLogsDir ? resolve(explicitLogsDir) : resolve(stateRoot, "logs");
|
|
129
|
+
const taskConfigPath = taskWorkspace ? resolve(taskWorkspace, ".rig", "task-config.json") : existsSync(resolve(projectRoot, ".rig", "task-config.json")) ? resolve(projectRoot, ".rig", "task-config.json") : resolve(monorepoStateRoot, "task-config.json");
|
|
130
|
+
return {
|
|
131
|
+
stateRoot,
|
|
132
|
+
stateDir,
|
|
133
|
+
logsDir,
|
|
134
|
+
controlPlaneEventsFile: resolve(logsDir, "control-plane.events.jsonl"),
|
|
135
|
+
taskConfigPath,
|
|
136
|
+
notificationsFile: resolve(projectRoot, "rig", "notifications", "targets.json"),
|
|
137
|
+
keybindingsPath: resolve(projectRoot, "rig", "keybindings.json")
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function resolveRigProjectRoot(input) {
|
|
141
|
+
if (input?.envProjectRoot) {
|
|
142
|
+
return input.envProjectRoot;
|
|
143
|
+
}
|
|
144
|
+
const cwd = input?.cwd ?? process.cwd();
|
|
145
|
+
const fallbackRoot = input?.fallbackRoot ?? cwd;
|
|
146
|
+
const candidates = [cwd, fallbackRoot];
|
|
147
|
+
for (const candidate of candidates) {
|
|
148
|
+
if (existsSync(resolve(candidate, RIG_DEFINITION_DIRNAME))) {
|
|
149
|
+
return candidate;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return fallbackRoot;
|
|
153
|
+
}
|
|
154
|
+
export {
|
|
155
|
+
resolveRigServerPaths,
|
|
156
|
+
resolveRigProjectRoot,
|
|
157
|
+
resolvePublishedRigServerStatePath,
|
|
158
|
+
publishRigServerState,
|
|
159
|
+
parseRigServerArgs,
|
|
160
|
+
clearPublishedRigServerState
|
|
161
|
+
};
|