@h-rig/server 0.0.6-alpha.35 → 0.0.6-alpha.37
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/index.js +121 -95
- package/dist/src/scheduler.js +1 -1
- package/dist/src/server-helpers/http-router.js +1 -3
- package/dist/src/server-helpers/run-mutations.js +20 -2
- package/dist/src/server-helpers/snapshot-orchestrator.js +24 -0
- package/dist/src/server-helpers/snapshot-service.js +26 -2
- package/dist/src/server-helpers/ws-router.js +1 -1
- package/dist/src/server.js +121 -95
- package/package.json +4 -4
package/dist/src/scheduler.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// packages/server/src/scheduler.ts
|
|
3
3
|
import { normalizeTaskLifecycleStatus } from "@rig/runtime/control-plane/state-sync/types";
|
|
4
4
|
var TERMINAL_RUN_STATUSES = new Set(["done", "completed", "error", "failed", "stopped", "cancelled"]);
|
|
5
|
-
var RUNNABLE_TASK_STATUSES = new Set(["draft", "open", "ready", "queued"]);
|
|
5
|
+
var RUNNABLE_TASK_STATUSES = new Set(["draft", "open", "ready", "queued", "in_progress"]);
|
|
6
6
|
var REMOTE_READY_STATUSES = new Set(["ready", "idle", "connected"]);
|
|
7
7
|
function resolveLocalSchedulerWorkerCount(env = process.env) {
|
|
8
8
|
const raw = env.RIG_SCHEDULER_LOCAL_WORKERS?.trim();
|
|
@@ -824,7 +824,7 @@ import {
|
|
|
824
824
|
// packages/server/src/scheduler.ts
|
|
825
825
|
import { normalizeTaskLifecycleStatus } from "@rig/runtime/control-plane/state-sync/types";
|
|
826
826
|
var TERMINAL_RUN_STATUSES = new Set(["done", "completed", "error", "failed", "stopped", "cancelled"]);
|
|
827
|
-
var RUNNABLE_TASK_STATUSES = new Set(["draft", "open", "ready", "queued"]);
|
|
827
|
+
var RUNNABLE_TASK_STATUSES = new Set(["draft", "open", "ready", "queued", "in_progress"]);
|
|
828
828
|
var REMOTE_READY_STATUSES = new Set(["ready", "idle", "connected"]);
|
|
829
829
|
|
|
830
830
|
// packages/server/src/server-helpers/validation-failure.ts
|
|
@@ -4902,8 +4902,6 @@ data: ${JSON.stringify({ connectedAt: new Date().toISOString() })}
|
|
|
4902
4902
|
return `${sessionPath}/shell`;
|
|
4903
4903
|
if (action === "commands/run" && req.method === "POST")
|
|
4904
4904
|
return `${sessionPath}/commands/run`;
|
|
4905
|
-
if (action === "commands/respond" && req.method === "POST")
|
|
4906
|
-
return `${sessionPath}/commands/respond`;
|
|
4907
4905
|
if (action === "extension-ui/respond" && req.method === "POST")
|
|
4908
4906
|
return `${sessionPath}/extension-ui/respond`;
|
|
4909
4907
|
if (action === "abort" && req.method === "POST")
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
// packages/server/src/scheduler.ts
|
|
26
26
|
import { normalizeTaskLifecycleStatus } from "@rig/runtime/control-plane/state-sync/types";
|
|
27
27
|
var TERMINAL_RUN_STATUSES = new Set(["done", "completed", "error", "failed", "stopped", "cancelled"]);
|
|
28
|
-
var RUNNABLE_TASK_STATUSES = new Set(["draft", "open", "ready", "queued"]);
|
|
28
|
+
var RUNNABLE_TASK_STATUSES = new Set(["draft", "open", "ready", "queued", "in_progress"]);
|
|
29
29
|
var REMOTE_READY_STATUSES = new Set(["ready", "idle", "connected"]);
|
|
30
30
|
function resolveLocalSchedulerWorkerCount(env = process.env) {
|
|
31
31
|
const raw = env.RIG_SCHEDULER_LOCAL_WORKERS?.trim();
|
|
@@ -281,6 +281,20 @@ function readQueueState(projectRoot) {
|
|
|
281
281
|
function writeQueueState(projectRoot, queue) {
|
|
282
282
|
writeJsonFile(resolveQueueStatePath(projectRoot), queue);
|
|
283
283
|
}
|
|
284
|
+
function enqueueTaskState(projectRoot, taskId, score) {
|
|
285
|
+
const queue = readQueueState(projectRoot).filter((entry) => entry.taskId !== taskId);
|
|
286
|
+
const next = [
|
|
287
|
+
...queue,
|
|
288
|
+
{
|
|
289
|
+
taskId,
|
|
290
|
+
score: Math.max(0, Math.trunc(score)),
|
|
291
|
+
unblockCount: 0,
|
|
292
|
+
position: queue.length
|
|
293
|
+
}
|
|
294
|
+
].sort((left, right) => right.score - left.score || left.position - right.position).map((entry, index) => ({ ...entry, position: index }));
|
|
295
|
+
writeQueueState(projectRoot, next);
|
|
296
|
+
return next;
|
|
297
|
+
}
|
|
284
298
|
|
|
285
299
|
// packages/server/src/server-helpers/remote-snapshots.ts
|
|
286
300
|
import { listAuthorityRemoteEndpoints } from "@rig/runtime/control-plane/authority-files";
|
|
@@ -2283,10 +2297,14 @@ function recoverStaleLocalRun(projectRoot, run) {
|
|
|
2283
2297
|
if (hasLiveRecordedProcess && serverPid === process.pid)
|
|
2284
2298
|
return false;
|
|
2285
2299
|
const completedAt = new Date().toISOString();
|
|
2300
|
+
const taskId = normalizeString(record.taskId);
|
|
2301
|
+
if (taskId) {
|
|
2302
|
+
enqueueTaskState(projectRoot, taskId, 0);
|
|
2303
|
+
}
|
|
2286
2304
|
patchRunRecord(projectRoot, run.runId, {
|
|
2287
2305
|
status: "failed",
|
|
2288
2306
|
completedAt,
|
|
2289
|
-
errorText: `Recovered stale local run ${run.runId} after server startup; no active server-owned process was tracking it.`
|
|
2307
|
+
errorText: taskId ? `Recovered stale local run ${run.runId} after server startup; no active server-owned process was tracking it. Task ${taskId} was re-queued for automatic restart.` : `Recovered stale local run ${run.runId} after server startup; no active server-owned process was tracking it.`
|
|
2290
2308
|
});
|
|
2291
2309
|
return true;
|
|
2292
2310
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/server/src/server-helpers/snapshot-orchestrator.ts
|
|
3
|
+
import { existsSync as existsSync3, readFileSync } from "fs";
|
|
3
4
|
import { dirname as dirname4, resolve as resolve5 } from "path";
|
|
4
5
|
import {
|
|
5
6
|
listAuthorityRuns as listAuthorityRuns3,
|
|
@@ -668,6 +669,28 @@ function buildConversationSnapshot(projectRoot, options = {}) {
|
|
|
668
669
|
}
|
|
669
670
|
|
|
670
671
|
// packages/server/src/server-helpers/snapshot-orchestrator.ts
|
|
672
|
+
function readPriorPrProgress(projectRoot, taskId) {
|
|
673
|
+
for (const candidate of [
|
|
674
|
+
resolve5(projectRoot, ".worktrees", taskId, "artifacts", taskId, "pr-state.json"),
|
|
675
|
+
resolve5(projectRoot, "artifacts", taskId, "pr-state.json")
|
|
676
|
+
]) {
|
|
677
|
+
if (!existsSync3(candidate))
|
|
678
|
+
continue;
|
|
679
|
+
try {
|
|
680
|
+
const raw = JSON.parse(readFileSync(candidate, "utf-8"));
|
|
681
|
+
const entries = Array.isArray(raw) ? raw : [raw];
|
|
682
|
+
const first = entries.find((entry) => entry && typeof entry === "object" && typeof entry.url === "string");
|
|
683
|
+
if (!first)
|
|
684
|
+
continue;
|
|
685
|
+
return [
|
|
686
|
+
`Prior progress exists for this task: PR ${first.url}${first.branch ? ` (branch ${first.branch})` : ""} was opened by an earlier run.`,
|
|
687
|
+
"Check its current state first (diff, checks, review). If the work is already complete and checks are green,",
|
|
688
|
+
"run `rig-agent completion-verification` to merge and close instead of re-implementing anything."
|
|
689
|
+
].join(" ");
|
|
690
|
+
} catch {}
|
|
691
|
+
}
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
671
694
|
async function buildTaskPrompt(projectRoot, taskId, readers) {
|
|
672
695
|
const task = (await readers.readWorkspaceTasks(projectRoot)).find((entry) => entry.id === taskId);
|
|
673
696
|
if (!task) {
|
|
@@ -685,6 +708,7 @@ ${task.acceptanceCriteria}` : null,
|
|
|
685
708
|
task.validation.length > 0 ? `Validation:
|
|
686
709
|
- ${task.validation.join(`
|
|
687
710
|
- `)}` : null,
|
|
711
|
+
readPriorPrProgress(projectRoot, String(task.id)),
|
|
688
712
|
"Work directly in the assigned runtime workspace and leave the result in a reviewable state."
|
|
689
713
|
];
|
|
690
714
|
return sections.filter((value) => Boolean(value)).join(`
|
|
@@ -5,6 +5,7 @@ var __require = import.meta.require;
|
|
|
5
5
|
import { listAgentRuntimes } from "@rig/runtime/control-plane/runtime/isolation";
|
|
6
6
|
|
|
7
7
|
// packages/server/src/server-helpers/snapshot-orchestrator.ts
|
|
8
|
+
import { existsSync as existsSync3, readFileSync } from "fs";
|
|
8
9
|
import { dirname as dirname4, resolve as resolve5 } from "path";
|
|
9
10
|
import {
|
|
10
11
|
listAuthorityRuns as listAuthorityRuns3,
|
|
@@ -680,6 +681,28 @@ function buildConversationSnapshot(projectRoot, options = {}) {
|
|
|
680
681
|
}
|
|
681
682
|
|
|
682
683
|
// packages/server/src/server-helpers/snapshot-orchestrator.ts
|
|
684
|
+
function readPriorPrProgress(projectRoot, taskId) {
|
|
685
|
+
for (const candidate of [
|
|
686
|
+
resolve5(projectRoot, ".worktrees", taskId, "artifacts", taskId, "pr-state.json"),
|
|
687
|
+
resolve5(projectRoot, "artifacts", taskId, "pr-state.json")
|
|
688
|
+
]) {
|
|
689
|
+
if (!existsSync3(candidate))
|
|
690
|
+
continue;
|
|
691
|
+
try {
|
|
692
|
+
const raw = JSON.parse(readFileSync(candidate, "utf-8"));
|
|
693
|
+
const entries = Array.isArray(raw) ? raw : [raw];
|
|
694
|
+
const first = entries.find((entry) => entry && typeof entry === "object" && typeof entry.url === "string");
|
|
695
|
+
if (!first)
|
|
696
|
+
continue;
|
|
697
|
+
return [
|
|
698
|
+
`Prior progress exists for this task: PR ${first.url}${first.branch ? ` (branch ${first.branch})` : ""} was opened by an earlier run.`,
|
|
699
|
+
"Check its current state first (diff, checks, review). If the work is already complete and checks are green,",
|
|
700
|
+
"run `rig-agent completion-verification` to merge and close instead of re-implementing anything."
|
|
701
|
+
].join(" ");
|
|
702
|
+
} catch {}
|
|
703
|
+
}
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
683
706
|
async function buildTaskPrompt(projectRoot, taskId, readers) {
|
|
684
707
|
const task = (await readers.readWorkspaceTasks(projectRoot)).find((entry) => entry.id === taskId);
|
|
685
708
|
if (!task) {
|
|
@@ -697,6 +720,7 @@ ${task.acceptanceCriteria}` : null,
|
|
|
697
720
|
task.validation.length > 0 ? `Validation:
|
|
698
721
|
- ${task.validation.join(`
|
|
699
722
|
- `)}` : null,
|
|
723
|
+
readPriorPrProgress(projectRoot, String(task.id)),
|
|
700
724
|
"Work directly in the assigned runtime workspace and leave the result in a reviewable state."
|
|
701
725
|
];
|
|
702
726
|
return sections.filter((value) => Boolean(value)).join(`
|
|
@@ -838,7 +862,7 @@ async function buildEngineSnapshotPayload(inputs) {
|
|
|
838
862
|
}
|
|
839
863
|
|
|
840
864
|
// packages/server/src/server-helpers/plugin-host-cache.ts
|
|
841
|
-
import { existsSync as
|
|
865
|
+
import { existsSync as existsSync4, statSync as statSync3 } from "fs";
|
|
842
866
|
import { resolve as resolve6 } from "path";
|
|
843
867
|
var contextCache = new Map;
|
|
844
868
|
var taskListCache = new Map;
|
|
@@ -846,7 +870,7 @@ var DEFAULT_TASK_LIST_TTL_MS = 2000;
|
|
|
846
870
|
function getPluginHostConfigMtime(projectRoot) {
|
|
847
871
|
for (const name of ["rig.config.ts", "rig.config.json"]) {
|
|
848
872
|
const path = resolve6(projectRoot, name);
|
|
849
|
-
if (
|
|
873
|
+
if (existsSync4(path)) {
|
|
850
874
|
try {
|
|
851
875
|
return statSync3(path).mtimeMs;
|
|
852
876
|
} catch {
|
|
@@ -385,7 +385,7 @@ import {
|
|
|
385
385
|
// packages/server/src/scheduler.ts
|
|
386
386
|
import { normalizeTaskLifecycleStatus } from "@rig/runtime/control-plane/state-sync/types";
|
|
387
387
|
var TERMINAL_RUN_STATUSES = new Set(["done", "completed", "error", "failed", "stopped", "cancelled"]);
|
|
388
|
-
var RUNNABLE_TASK_STATUSES = new Set(["draft", "open", "ready", "queued"]);
|
|
388
|
+
var RUNNABLE_TASK_STATUSES = new Set(["draft", "open", "ready", "queued", "in_progress"]);
|
|
389
389
|
var REMOTE_READY_STATUSES = new Set(["ready", "idle", "connected"]);
|
|
390
390
|
|
|
391
391
|
// packages/server/src/server-helpers/validation-failure.ts
|