@h-rig/server 0.0.6-alpha.2 → 0.0.6-alpha.21
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 +23 -0
- package/dist/src/index.js +1513 -331
- package/dist/src/server-helpers/github-api-session-index.js +107 -0
- package/dist/src/server-helpers/github-auth-store.js +68 -24
- package/dist/src/server-helpers/github-project-status-sync.js +3 -0
- package/dist/src/server-helpers/github-user-namespace.js +102 -0
- package/dist/src/server-helpers/http-router.js +1207 -185
- package/dist/src/server-helpers/issue-analysis.js +30 -11
- package/dist/src/server-helpers/project-registry.js +5 -0
- package/dist/src/server-helpers/run-io.js +13 -0
- package/dist/src/server-helpers/run-mutations.js +599 -114
- package/dist/src/server-helpers/run-writers.js +1 -2
- package/dist/src/server-helpers/ws-router.js +7 -1
- package/dist/src/server.js +1512 -331
- package/package.json +4 -4
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/server/src/server-helpers/issue-analysis.ts
|
|
3
|
-
import { execFile } from "child_process";
|
|
4
3
|
import { createHash } from "crypto";
|
|
5
4
|
function stableIssueHash(issue) {
|
|
6
5
|
const labels = Array.isArray(issue.labels) ? [...issue.labels].map(String).sort() : [];
|
|
@@ -134,16 +133,33 @@ function parseIssueAnalysisResult(raw) {
|
|
|
134
133
|
return result;
|
|
135
134
|
}
|
|
136
135
|
function createDefaultPiIssueAnalysisCommandRunner() {
|
|
137
|
-
return (command, args, options) =>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const exitCode = typeof error?.code === "number" ? error.code : error ? 1 : 0;
|
|
144
|
-
resolve({ exitCode, stdout: String(stdout ?? ""), stderr: String(stderr ?? "") });
|
|
136
|
+
return async (command, args, options) => {
|
|
137
|
+
const env = options.env ? { ...process.env, ...options.env } : process.env;
|
|
138
|
+
const proc = Bun.spawn([command, ...args], {
|
|
139
|
+
stdout: "pipe",
|
|
140
|
+
stderr: "pipe",
|
|
141
|
+
env
|
|
145
142
|
});
|
|
146
|
-
|
|
143
|
+
let timedOut = false;
|
|
144
|
+
const timer = setTimeout(() => {
|
|
145
|
+
timedOut = true;
|
|
146
|
+
proc.kill();
|
|
147
|
+
}, options.timeoutMs);
|
|
148
|
+
try {
|
|
149
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
150
|
+
new Response(proc.stdout).text(),
|
|
151
|
+
new Response(proc.stderr).text(),
|
|
152
|
+
proc.exited
|
|
153
|
+
]);
|
|
154
|
+
return {
|
|
155
|
+
exitCode: timedOut && exitCode === 0 ? 1 : exitCode,
|
|
156
|
+
stdout,
|
|
157
|
+
stderr: timedOut && stderr.trim().length === 0 ? `Pi issue analysis timed out after ${options.timeoutMs}ms` : stderr
|
|
158
|
+
};
|
|
159
|
+
} finally {
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
147
163
|
}
|
|
148
164
|
function createPiIssueAnalyzer(input = {}) {
|
|
149
165
|
const piBinary = input.piBinary ?? process.env.RIG_ISSUE_ANALYSIS_PI_BINARY ?? "pi";
|
|
@@ -151,7 +167,10 @@ function createPiIssueAnalyzer(input = {}) {
|
|
|
151
167
|
const runCommand = input.runCommand ?? createDefaultPiIssueAnalysisCommandRunner();
|
|
152
168
|
return async ({ prompt }) => {
|
|
153
169
|
const args = ["--print", "--mode", "json", "--no-session"];
|
|
154
|
-
const
|
|
170
|
+
const provider = input.provider?.trim() || process.env.RIG_ISSUE_ANALYSIS_PROVIDER?.trim() || process.env.RIG_PI_PROVIDER?.trim();
|
|
171
|
+
const model = input.model?.trim() || process.env.RIG_ISSUE_ANALYSIS_MODEL?.trim() || process.env.RIG_PI_MODEL?.trim() || "openai-codex/gpt-5.5";
|
|
172
|
+
if (provider)
|
|
173
|
+
args.push("--provider", provider);
|
|
155
174
|
if (model)
|
|
156
175
|
args.push("--model", model);
|
|
157
176
|
args.push(prompt);
|
|
@@ -115,8 +115,13 @@ function upsertProjectRecord(projectRoot, input) {
|
|
|
115
115
|
function linkProjectCheckout(projectRoot, repoSlug, checkout) {
|
|
116
116
|
return upsertProjectRecord(projectRoot, { repoSlug, checkout });
|
|
117
117
|
}
|
|
118
|
+
function projectRegistryContainsCheckout(projectRoot, checkoutPath) {
|
|
119
|
+
const target = resolve(checkoutPath);
|
|
120
|
+
return Object.values(readRegistry(projectRoot)).some((project) => project.checkouts.some((checkout) => checkout.path ? resolve(checkout.path) === target : false));
|
|
121
|
+
}
|
|
118
122
|
export {
|
|
119
123
|
upsertProjectRecord,
|
|
124
|
+
projectRegistryContainsCheckout,
|
|
120
125
|
normalizeRepoSlug,
|
|
121
126
|
linkProjectCheckout,
|
|
122
127
|
getProjectRecord,
|
|
@@ -167,6 +167,18 @@ function readJsonlFileTail(path, options) {
|
|
|
167
167
|
function readRawRunLogs(projectRoot, runId) {
|
|
168
168
|
return readJsonlFile(runLogsPath(projectRoot, runId)).filter((entry) => Boolean(entry && typeof entry === "object"));
|
|
169
169
|
}
|
|
170
|
+
async function readRunTimelinePage(projectRoot, runId, options = {}) {
|
|
171
|
+
const limit = Math.max(1, Math.min(Math.trunc(options.limit ?? 200), 500));
|
|
172
|
+
const cursor = options.cursor == null ? 0 : Number.parseInt(options.cursor, 10);
|
|
173
|
+
const entries = readJsonlFile(runTimelinePath(projectRoot, runId)).filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry)));
|
|
174
|
+
const startInclusive = Number.isFinite(cursor) ? Math.max(0, Math.min(cursor, entries.length)) : 0;
|
|
175
|
+
const endExclusive = Math.min(entries.length, startInclusive + limit);
|
|
176
|
+
return {
|
|
177
|
+
entries: entries.slice(startInclusive, endExclusive).map((entry, offset) => ({ ...entry, cursor: startInclusive + offset + 1 })),
|
|
178
|
+
nextCursor: String(endExclusive),
|
|
179
|
+
hasMore: endExclusive < entries.length
|
|
180
|
+
};
|
|
181
|
+
}
|
|
170
182
|
var INITIAL_RUN_LOG_TAIL_MAX_BYTES = 8 * 1024 * 1024;
|
|
171
183
|
async function readRunLogsPage(projectRoot, runId, options = {}) {
|
|
172
184
|
const limit = Math.max(1, Math.min(Math.trunc(options.limit ?? 200), 500));
|
|
@@ -252,6 +264,7 @@ export {
|
|
|
252
264
|
remoteArtifactsRoot,
|
|
253
265
|
readUserInputsForRuns,
|
|
254
266
|
readUserInputs,
|
|
267
|
+
readRunTimelinePage,
|
|
255
268
|
readRunLogsPage,
|
|
256
269
|
readRunDetails,
|
|
257
270
|
readRawRunLogs,
|