@exla/rudder 4.0.0-alpha.7 → 4.1.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 +33 -69
- package/assets/skills/burst/SKILL.md +64 -0
- package/dist/agent-efficiency/backend-observer.d.ts +13 -0
- package/dist/agent-efficiency/backend-observer.js +77 -0
- package/dist/agent-efficiency/backend-observer.js.map +1 -0
- package/dist/agent-efficiency/handoff.d.ts +9 -0
- package/dist/agent-efficiency/handoff.js +42 -0
- package/dist/agent-efficiency/handoff.js.map +1 -0
- package/dist/agent-efficiency/index.d.ts +11 -0
- package/dist/agent-efficiency/index.js +7 -0
- package/dist/agent-efficiency/index.js.map +1 -0
- package/dist/agent-efficiency/lessons.d.ts +55 -0
- package/dist/agent-efficiency/lessons.js +107 -0
- package/dist/agent-efficiency/lessons.js.map +1 -0
- package/dist/agent-efficiency/privacy.d.ts +6 -0
- package/dist/agent-efficiency/privacy.js +28 -0
- package/dist/agent-efficiency/privacy.js.map +1 -0
- package/dist/agent-efficiency/production.d.ts +16 -0
- package/dist/agent-efficiency/production.js +120 -0
- package/dist/agent-efficiency/production.js.map +1 -0
- package/dist/agent-efficiency/storage.d.ts +3 -0
- package/dist/agent-efficiency/storage.js +28 -0
- package/dist/agent-efficiency/storage.js.map +1 -0
- package/dist/agent-efficiency/telemetry.d.ts +59 -0
- package/dist/agent-efficiency/telemetry.js +143 -0
- package/dist/agent-efficiency/telemetry.js.map +1 -0
- package/dist/agent-efficiency/trace-lessons.d.ts +21 -0
- package/dist/agent-efficiency/trace-lessons.js +36 -0
- package/dist/agent-efficiency/trace-lessons.js.map +1 -0
- package/dist/agent-efficiency/waits.d.ts +52 -0
- package/dist/agent-efficiency/waits.js +131 -0
- package/dist/agent-efficiency/waits.js.map +1 -0
- package/dist/backends.js +14 -8
- package/dist/backends.js.map +1 -1
- package/dist/board/authority.d.ts +48 -0
- package/dist/board/authority.js +125 -0
- package/dist/board/authority.js.map +1 -0
- package/dist/board/board.js +6 -2
- package/dist/board/daemon.d.ts +3 -6
- package/dist/board/daemon.js +242 -222
- package/dist/board/daemon.js.map +1 -1
- package/dist/board/host-access.d.ts +8 -0
- package/dist/board/host-access.js +222 -0
- package/dist/board/host-access.js.map +1 -0
- package/dist/board/project-files.d.ts +12 -0
- package/dist/board/project-files.js +78 -0
- package/dist/board/project-files.js.map +1 -0
- package/dist/brain.d.ts +2 -1
- package/dist/brain.js +15 -21
- package/dist/brain.js.map +1 -1
- package/dist/claude-sdk-protocol.js +10 -7
- package/dist/claude-sdk-protocol.js.map +1 -1
- package/dist/cloud-build-profile.d.ts +22 -0
- package/dist/cloud-build-profile.js +160 -0
- package/dist/cloud-build-profile.js.map +1 -0
- package/dist/cloud.js +23 -470
- package/dist/cloud.js.map +1 -1
- package/dist/codex-binary.d.ts +1 -0
- package/dist/codex-binary.js +8 -1
- package/dist/codex-binary.js.map +1 -1
- package/dist/daemon.d.ts +2 -0
- package/dist/daemon.js +14 -2
- package/dist/daemon.js.map +1 -1
- package/dist/effort.d.ts +8 -0
- package/dist/effort.js +15 -2
- package/dist/effort.js.map +1 -1
- package/dist/engine-authority.js +16 -0
- package/dist/engine-authority.js.map +1 -1
- package/dist/engine.d.ts +1 -1
- package/dist/engine.js +11 -2
- package/dist/engine.js.map +1 -1
- package/dist/fabric-fetch.d.ts +25 -0
- package/dist/fabric-fetch.js +402 -0
- package/dist/fabric-fetch.js.map +1 -0
- package/dist/fabric-local.d.ts +5 -2
- package/dist/fabric-local.js +36 -1
- package/dist/fabric-local.js.map +1 -1
- package/dist/fabric-remote.d.ts +76 -1
- package/dist/fabric-remote.js +333 -61
- package/dist/fabric-remote.js.map +1 -1
- package/dist/git.js +23 -0
- package/dist/git.js.map +1 -1
- package/dist/graph.js +9 -1
- package/dist/graph.js.map +1 -1
- package/dist/jj.d.ts +3 -1
- package/dist/jj.js +34 -2
- package/dist/jj.js.map +1 -1
- package/dist/main.js +115 -311
- package/dist/main.js.map +1 -1
- package/dist/migration.d.ts +2 -0
- package/dist/migration.js +3 -0
- package/dist/migration.js.map +1 -1
- package/dist/models.js +11 -6
- package/dist/models.js.map +1 -1
- package/dist/native/darwin-arm64/native-manifest.json +19 -0
- package/dist/native/darwin-arm64/rudder-jj +0 -0
- package/dist/native/darwin-arm64/rudder-native +0 -0
- package/dist/native/linux-x64/native-manifest.json +19 -0
- package/dist/native/linux-x64/rudder-jj +0 -0
- package/dist/native/linux-x64/rudder-native +0 -0
- package/dist/native-agents.js +3 -7
- package/dist/native-agents.js.map +1 -1
- package/dist/native-binary.js +11 -1
- package/dist/native-binary.js.map +1 -1
- package/dist/operations/cli.d.ts +23 -0
- package/dist/operations/cli.js +110 -0
- package/dist/operations/cli.js.map +1 -0
- package/dist/operations/registry.d.ts +1076 -0
- package/dist/operations/registry.js +69 -0
- package/dist/operations/registry.js.map +1 -0
- package/dist/operations/registry.json +124 -0
- package/dist/operations/requests.d.ts +167 -0
- package/dist/operations/requests.js +223 -0
- package/dist/operations/requests.js.map +1 -0
- package/dist/planning-ownership/index.d.ts +134 -0
- package/dist/planning-ownership/index.js +291 -0
- package/dist/planning-ownership/index.js.map +1 -0
- package/dist/planning-ownership/ingress.d.ts +30 -0
- package/dist/planning-ownership/ingress.js +41 -0
- package/dist/planning-ownership/ingress.js.map +1 -0
- package/dist/planning-ownership/store.d.ts +19 -0
- package/dist/planning-ownership/store.js +30 -0
- package/dist/planning-ownership/store.js.map +1 -0
- package/dist/private-access/cli.d.ts +22 -0
- package/dist/private-access/cli.js +76 -0
- package/dist/private-access/cli.js.map +1 -0
- package/dist/private-access/engine.d.ts +20 -0
- package/dist/private-access/engine.js +47 -0
- package/dist/private-access/engine.js.map +1 -0
- package/dist/private-access/home.d.ts +21 -0
- package/dist/private-access/home.js +80 -0
- package/dist/private-access/home.js.map +1 -0
- package/dist/private-access/previews.d.ts +101 -0
- package/dist/private-access/previews.js +447 -0
- package/dist/private-access/previews.js.map +1 -0
- package/dist/project-files/cli.d.ts +7 -0
- package/dist/project-files/cli.js +22 -0
- package/dist/project-files/cli.js.map +1 -0
- package/dist/project-files/engine.d.ts +14 -0
- package/dist/project-files/engine.js +52 -0
- package/dist/project-files/engine.js.map +1 -0
- package/dist/project-files/home.d.ts +13 -0
- package/dist/project-files/home.js +46 -0
- package/dist/project-files/home.js.map +1 -0
- package/dist/project-files/http.d.ts +9 -0
- package/dist/project-files/http.js +54 -0
- package/dist/project-files/http.js.map +1 -0
- package/dist/project-files/open.d.ts +10 -0
- package/dist/project-files/open.js +37 -0
- package/dist/project-files/open.js.map +1 -0
- package/dist/project-files/references.d.ts +9 -0
- package/dist/project-files/references.js +29 -0
- package/dist/project-files/references.js.map +1 -0
- package/dist/project-files/service.d.ts +32 -0
- package/dist/project-files/service.js +236 -0
- package/dist/project-files/service.js.map +1 -0
- package/dist/project-files/types.d.ts +40 -0
- package/dist/project-files/types.js +2 -0
- package/dist/project-files/types.js.map +1 -0
- package/dist/run-manager.d.ts +8 -0
- package/dist/run-manager.js +193 -13
- package/dist/run-manager.js.map +1 -1
- package/dist/run-timeline.d.ts +31 -0
- package/dist/run-timeline.js +116 -0
- package/dist/run-timeline.js.map +1 -0
- package/dist/scheduler.js +72 -13
- package/dist/scheduler.js.map +1 -1
- package/dist/surfaces.js +3 -8
- package/dist/surfaces.js.map +1 -1
- package/dist/tailscale-preview.d.ts +6 -2
- package/dist/tailscale-preview.js +58 -13
- package/dist/tailscale-preview.js.map +1 -1
- package/dist/task-routing.d.ts +2 -0
- package/dist/task-routing.js +42 -25
- package/dist/task-routing.js.map +1 -1
- package/dist/terminal-screen.d.ts +6 -0
- package/dist/terminal-screen.js +23 -0
- package/dist/terminal-screen.js.map +1 -0
- package/dist/tool-cache.d.ts +23 -0
- package/dist/tool-cache.js +144 -0
- package/dist/tool-cache.js.map +1 -0
- package/dist/types.d.ts +0 -17
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +8 -0
- package/dist/util.js +38 -2
- package/dist/util.js.map +1 -1
- package/dist/v4-migration/capture.d.ts +53 -0
- package/dist/v4-migration/capture.js +197 -0
- package/dist/v4-migration/capture.js.map +1 -0
- package/dist/v4-migration/cli.d.ts +4 -0
- package/dist/v4-migration/cli.js +38 -0
- package/dist/v4-migration/cli.js.map +1 -0
- package/dist/v4-migration/recovery.d.ts +43 -0
- package/dist/v4-migration/recovery.js +180 -0
- package/dist/v4-migration/recovery.js.map +1 -0
- package/dist/version-check.d.ts +2 -0
- package/dist/version-check.js +23 -0
- package/dist/version-check.js.map +1 -1
- package/dist/warm-snapshot.d.ts +55 -0
- package/dist/warm-snapshot.js +382 -0
- package/dist/warm-snapshot.js.map +1 -0
- package/package.json +4 -3
- package/scripts/copy-native.mjs +35 -48
- package/scripts/native-artifacts.mjs +248 -0
- package/dist/improve/advisor.d.ts +0 -10
- package/dist/improve/advisor.js +0 -115
- package/dist/improve/advisor.js.map +0 -1
- package/dist/improve/collect.d.ts +0 -49
- package/dist/improve/collect.js +0 -274
- package/dist/improve/collect.js.map +0 -1
- package/dist/improve/gate.d.ts +0 -17
- package/dist/improve/gate.js +0 -60
- package/dist/improve/gate.js.map +0 -1
- package/dist/improve/index.d.ts +0 -9
- package/dist/improve/index.js +0 -376
- package/dist/improve/index.js.map +0 -1
- package/dist/improve/judge.d.ts +0 -32
- package/dist/improve/judge.js +0 -114
- package/dist/improve/judge.js.map +0 -1
- package/dist/improve/mine.d.ts +0 -31
- package/dist/improve/mine.js +0 -192
- package/dist/improve/mine.js.map +0 -1
- package/dist/improve/propose.d.ts +0 -51
- package/dist/improve/propose.js +0 -150
- package/dist/improve/propose.js.map +0 -1
- package/dist/improve/rank.d.ts +0 -16
- package/dist/improve/rank.js +0 -49
- package/dist/improve/rank.js.map +0 -1
- package/dist/improve/schedule.d.ts +0 -1
- package/dist/improve/schedule.js +0 -95
- package/dist/improve/schedule.js.map +0 -1
- package/dist/improve/ship.d.ts +0 -25
- package/dist/improve/ship.js +0 -82
- package/dist/improve/ship.js.map +0 -1
- package/dist/improve/state.d.ts +0 -157
- package/dist/improve/state.js +0 -264
- package/dist/improve/state.js.map +0 -1
- package/dist/native/darwin-x64/rudder-native +0 -0
package/dist/run-manager.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { appendTimelineEvent, formatTimeline, readRunTimeline } from "./run-timeline.js";
|
|
2
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
3
|
+
import { inFork } from "./warm-snapshot.js";
|
|
2
4
|
import { assertLegacyWriterAllowed } from "./engine-authority.js";
|
|
3
5
|
import { randomUUID } from "node:crypto";
|
|
4
6
|
import fs from "node:fs";
|
|
@@ -6,9 +8,11 @@ import fsp from "node:fs/promises";
|
|
|
6
8
|
import path from "node:path";
|
|
7
9
|
import { createSpec, renderContract, verifyRun } from "./brain.js";
|
|
8
10
|
import { getBackend } from "./backends.js";
|
|
11
|
+
import { efficiencyContext, learnIntegratedRun } from "./agent-efficiency/production.js";
|
|
12
|
+
import { toolCacheEnv } from "./tool-cache.js";
|
|
9
13
|
import { mergeGeneratedRudderMd, withRudderMdLock } from "./rudder-md.js";
|
|
10
|
-
import { createRunRecord, agentContextPath, ensureProjectRuntimeIgnored, eventsPath, listRuns, loadConfig, loadRunRecord, outputPath, AGENT_WORKSPACES_DIR, LEGACY_AGENT_WORKSPACES_DIR, registerProject, rememberBackendSelection, resolveRun, runDir, saveRunRecord, stopRequestPath, } from "./state.js";
|
|
11
|
-
import { updateGraph } from "./graph.js";
|
|
14
|
+
import { createRunRecord, agentContextPath, ensureProjectRuntimeIgnored, eventsPath, listRuns, loadConfig, loadRunRecord, outputPath, AGENT_WORKSPACES_DIR, LEGACY_AGENT_WORKSPACES_DIR, registerProject, rememberBackendSelection, resolveRun, runDir, runRecordPath, saveRunRecord, stopRequestPath, } from "./state.js";
|
|
15
|
+
import { readGraph, updateGraph } from "./graph.js";
|
|
12
16
|
import { appendEvent, } from "./state.js";
|
|
13
17
|
import { activeRunsForCheckout, currentBranch, findRepoRoot, mergeGitRunIntoCurrentBranch, processAlive, runProcessAlive, removeGitWorktree, syncGitRunWorktree, } from "./git.js";
|
|
14
18
|
import { createRunJjWorkspace, closestLocalBookmark, currentJjChangeId, ensureColocated, ensureJj, exportToGit, mergeJjRunIntoCurrentWorkspace, removeRunWorkspace as removeJjRunWorkspace, syncRunWorkspace as syncJjRunWorkspace, } from "./jj.js";
|
|
@@ -19,6 +23,28 @@ import { captureSharedContextFromInput, redactSharedSecretValues, SHARED_CONTEXT
|
|
|
19
23
|
// RUDDER_AUTO_STEER_DELAY_MS so the end-to-end test can drain a DAG quickly
|
|
20
24
|
// instead of waiting 10s per node; defaults to 10s for real runs.
|
|
21
25
|
const AUTO_STEER_DELAY_MS = Number(process.env.RUDDER_AUTO_STEER_DELAY_MS) || 10_000;
|
|
26
|
+
// Native managed markers are recovery evidence, including malformed/quarantined
|
|
27
|
+
// projections. Their durable sidecar can precede run.json, so neither a missing
|
|
28
|
+
// project owner nor old branch/workspace fields authorize a legacy fallback.
|
|
29
|
+
function hasManagedSource(run, repoRoot = run.repoRoot, runId = run.id) {
|
|
30
|
+
const raw = run;
|
|
31
|
+
if (Object.hasOwn(raw, "managedLocal") || (raw.vcs !== undefined && raw.vcs !== "git" && raw.vcs !== "jj"))
|
|
32
|
+
return true;
|
|
33
|
+
try {
|
|
34
|
+
fs.lstatSync(path.join(runDir(repoRoot, runId), "managed-local.json"));
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
// Unknown/unreadable recovery evidence must never become permission to
|
|
39
|
+
// mutate a checkout. lstat also protects corrupt directories and symlinks.
|
|
40
|
+
return error.code !== "ENOENT";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function assertLegacyRunAllowed(run, repoRoot = run.repoRoot, runId = run.id) {
|
|
44
|
+
if (hasManagedSource(run, repoRoot, runId)) {
|
|
45
|
+
throw new Error(`Run ${runId} has managed or unsupported workspace recovery state. Use its owning engine for recovery or authenticated shutdown; legacy run commands cannot resume, integrate, stop or delete it.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
22
48
|
function missingBackendError(backend, healthMessage) {
|
|
23
49
|
return new MissingToolError(backend, healthMessage);
|
|
24
50
|
}
|
|
@@ -52,9 +78,13 @@ export async function startRun(params) {
|
|
|
52
78
|
const baseCommit = await baseRevision(repoRoot);
|
|
53
79
|
const targetBranch = await targetRevision(repoRoot);
|
|
54
80
|
const id = newRunId(params.task);
|
|
81
|
+
const workspaceStarted = Date.now();
|
|
55
82
|
const workspaceInfo = useWorkspace
|
|
56
83
|
? await createRunWorkspace({ repoRoot, runId: id, task: params.task })
|
|
57
84
|
: { path: repoRoot, workspaceName: undefined, jjChangeId: undefined };
|
|
85
|
+
if (useWorkspace) {
|
|
86
|
+
await appendTimelineEvent(repoRoot, id, { kind: "workspace", ms: Date.now() - workspaceStarted });
|
|
87
|
+
}
|
|
58
88
|
const run = await createRunRecord({
|
|
59
89
|
id,
|
|
60
90
|
repoRoot,
|
|
@@ -134,6 +164,7 @@ export async function continueRun(params) {
|
|
|
134
164
|
if (!run) {
|
|
135
165
|
throw new Error(`Run not found: ${params.runId}`);
|
|
136
166
|
}
|
|
167
|
+
assertLegacyRunAllowed(run, repoRoot, params.runId);
|
|
137
168
|
if (run.mode && run.mode !== "execute") {
|
|
138
169
|
throw new Error("Only headless execute runs can be continued from the standalone board.");
|
|
139
170
|
}
|
|
@@ -176,6 +207,8 @@ export async function continueRun(params) {
|
|
|
176
207
|
return run;
|
|
177
208
|
}
|
|
178
209
|
async function interruptWorkerAttempt(repoRoot, owned) {
|
|
210
|
+
// This is the legacy process-kill path, not managed App authenticated stop.
|
|
211
|
+
assertLegacyRunAllowed(owned, repoRoot);
|
|
179
212
|
const known = new Set();
|
|
180
213
|
const controllerGroups = new Set();
|
|
181
214
|
const collect = (run) => {
|
|
@@ -196,6 +229,8 @@ async function interruptWorkerAttempt(repoRoot, owned) {
|
|
|
196
229
|
[...controllerGroups].every((pid) => !processGroupAlive(pid));
|
|
197
230
|
while (Date.now() < deadline) {
|
|
198
231
|
const latest = await loadRunRecord(repoRoot, owned.id);
|
|
232
|
+
if (latest)
|
|
233
|
+
assertLegacyRunAllowed(latest, repoRoot);
|
|
199
234
|
if (latest && sameAttempt(latest, owned))
|
|
200
235
|
collect(latest);
|
|
201
236
|
for (const pid of controllerGroups) {
|
|
@@ -220,6 +255,8 @@ async function interruptWorkerAttempt(repoRoot, owned) {
|
|
|
220
255
|
// declaring the old attempt fully quiesced.
|
|
221
256
|
await delay(75);
|
|
222
257
|
const settled = await loadRunRecord(repoRoot, owned.id);
|
|
258
|
+
if (settled)
|
|
259
|
+
assertLegacyRunAllowed(settled, repoRoot);
|
|
223
260
|
if (settled && sameAttempt(settled, owned))
|
|
224
261
|
collect(settled);
|
|
225
262
|
if (stopped())
|
|
@@ -262,6 +299,30 @@ function signalProcessGroup(controllerPid, signal) {
|
|
|
262
299
|
*/
|
|
263
300
|
export function spawnWorker(repoRoot, runId, attemptId) {
|
|
264
301
|
assertLegacyWriterAllowed(repoRoot);
|
|
302
|
+
let stored;
|
|
303
|
+
try {
|
|
304
|
+
stored = fs.readFileSync(runRecordPath(repoRoot, runId), "utf8");
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
if (error.code !== "ENOENT")
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
if (stored !== undefined) {
|
|
311
|
+
let record;
|
|
312
|
+
try {
|
|
313
|
+
record = JSON.parse(stored);
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
throw new Error("Run record is unreadable; legacy worker was not started.");
|
|
317
|
+
}
|
|
318
|
+
if (!isRecord(record))
|
|
319
|
+
throw new Error("Run record is invalid; legacy worker was not started.");
|
|
320
|
+
assertLegacyRunAllowed(record, repoRoot, runId);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
// The launch handoff can precede its JSON save; a sidecar still wins.
|
|
324
|
+
assertLegacyRunAllowed({ id: runId, repoRoot }, repoRoot, runId);
|
|
325
|
+
}
|
|
265
326
|
let stderrFd;
|
|
266
327
|
try {
|
|
267
328
|
fs.mkdirSync(runDir(repoRoot, runId), { recursive: true });
|
|
@@ -282,6 +343,7 @@ export function spawnWorker(repoRoot, runId, attemptId) {
|
|
|
282
343
|
], {
|
|
283
344
|
cwd: repoRoot,
|
|
284
345
|
detached: true,
|
|
346
|
+
env: { ...process.env, ...toolCacheEnv("agent") },
|
|
285
347
|
stdio: stderrFd === undefined ? "ignore" : ["ignore", "ignore", stderrFd],
|
|
286
348
|
});
|
|
287
349
|
worker.unref();
|
|
@@ -306,6 +368,7 @@ async function loadOwnedAttempt(repoRoot, runId, attemptId) {
|
|
|
306
368
|
const run = await loadRunRecord(repoRoot, runId);
|
|
307
369
|
if (!run)
|
|
308
370
|
return null;
|
|
371
|
+
assertLegacyRunAllowed(run, repoRoot, runId);
|
|
309
372
|
if (!attemptId || run.process?.attemptId === attemptId)
|
|
310
373
|
return run;
|
|
311
374
|
// startRun/continueRun spawn immediately before their atomic run.json save.
|
|
@@ -324,9 +387,14 @@ function sameAttempt(left, right) {
|
|
|
324
387
|
}
|
|
325
388
|
async function attemptOwnsRun(repoRoot, run) {
|
|
326
389
|
const latest = await loadRunRecord(repoRoot, run.id);
|
|
327
|
-
return Boolean(latest && sameAttempt(latest, run));
|
|
390
|
+
return Boolean(latest && !hasManagedSource(latest, repoRoot) && sameAttempt(latest, run));
|
|
328
391
|
}
|
|
329
|
-
function saveOwnedRun(run) {
|
|
392
|
+
async function saveOwnedRun(run) {
|
|
393
|
+
// This recovery check precedes the atomic attempt CAS, so migration must
|
|
394
|
+
// still quiesce legacy writers before publishing managed ownership.
|
|
395
|
+
const latest = await loadRunRecord(run.repoRoot, run.id);
|
|
396
|
+
if (hasManagedSource(run) || (latest && hasManagedSource(latest)))
|
|
397
|
+
return false;
|
|
330
398
|
const expectedAttemptId = run.process?.attemptId;
|
|
331
399
|
const expectedStartedAt = run.process?.startedAt;
|
|
332
400
|
return saveRunRecord(run, expectedAttemptId
|
|
@@ -465,6 +533,8 @@ export async function workerRun(repoRoot, runId, attemptId) {
|
|
|
465
533
|
: `Run failed verification: ${verification.missing.join("; ")}`,
|
|
466
534
|
});
|
|
467
535
|
await writeAgentContext(repoRoot);
|
|
536
|
+
if (current.status === "completed")
|
|
537
|
+
await autoIntegrateFinishedWorker(repoRoot, current);
|
|
468
538
|
return;
|
|
469
539
|
}
|
|
470
540
|
}
|
|
@@ -494,6 +564,8 @@ export async function workerRun(repoRoot, runId, attemptId) {
|
|
|
494
564
|
}
|
|
495
565
|
async function newerWorkerOwnsRun(repoRoot, staleRun) {
|
|
496
566
|
const latest = await loadRunRecord(repoRoot, staleRun.id);
|
|
567
|
+
if (latest && hasManagedSource(latest, repoRoot))
|
|
568
|
+
return true;
|
|
497
569
|
if (latest?.process?.attemptId && staleRun.process?.attemptId) {
|
|
498
570
|
return latest.process.attemptId !== staleRun.process.attemptId;
|
|
499
571
|
}
|
|
@@ -504,6 +576,7 @@ async function newerWorkerOwnsRun(repoRoot, staleRun) {
|
|
|
504
576
|
latest.process.startedAt !== staleRun.process.startedAt);
|
|
505
577
|
}
|
|
506
578
|
async function runBackendPass(run) {
|
|
579
|
+
assertLegacyRunAllowed(run);
|
|
507
580
|
if (run.mode && run.mode !== "execute") {
|
|
508
581
|
throw new Error("Only execute runs use the background worker.");
|
|
509
582
|
}
|
|
@@ -523,7 +596,7 @@ async function runBackendPass(run) {
|
|
|
523
596
|
const exitCode = await backend.run({
|
|
524
597
|
run,
|
|
525
598
|
prompt: run.currentPrompt ?? run.task,
|
|
526
|
-
contract: renderContract(spec),
|
|
599
|
+
contract: renderContract(spec) + await efficiencyContext(run).catch(() => ""),
|
|
527
600
|
}, async (event) => {
|
|
528
601
|
await emit(run, event);
|
|
529
602
|
});
|
|
@@ -678,6 +751,28 @@ function previewAgentContext(value, max) {
|
|
|
678
751
|
return normalized.length > max ? `${normalized.slice(0, max)}...` : normalized;
|
|
679
752
|
}
|
|
680
753
|
async function writeRudderContextFiles(repoRoot, runs, content) {
|
|
754
|
+
const normalizedPath = (value) => {
|
|
755
|
+
try {
|
|
756
|
+
return fs.realpathSync(value);
|
|
757
|
+
}
|
|
758
|
+
catch {
|
|
759
|
+
return path.resolve(value);
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
const protectedPaths = runs
|
|
763
|
+
.filter((run) => hasManagedSource(run, repoRoot))
|
|
764
|
+
.map((run) => run.workspace?.path)
|
|
765
|
+
.filter((value) => typeof value === "string" && Boolean(value))
|
|
766
|
+
.map(normalizedPath);
|
|
767
|
+
const writable = (value) => {
|
|
768
|
+
const resolved = normalizedPath(value);
|
|
769
|
+
return !protectedPaths.some((protectedPath) => {
|
|
770
|
+
const relative = path.relative(protectedPath, resolved);
|
|
771
|
+
return relative === "" || (!path.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${path.sep}`));
|
|
772
|
+
});
|
|
773
|
+
};
|
|
774
|
+
if (!writable(repoRoot))
|
|
775
|
+
return;
|
|
681
776
|
await ensureLine(path.join(repoRoot, ".gitignore"), "RUDDER.md");
|
|
682
777
|
await ensureLine(path.join(repoRoot, ".gitignore"), SHARED_CONTEXT_FILE);
|
|
683
778
|
// Workspaces live INSIDE the project at <repo>/<agent-workspaces-dir>; ignore them in the
|
|
@@ -687,7 +782,7 @@ async function writeRudderContextFiles(repoRoot, runs, content) {
|
|
|
687
782
|
await ensureLine(path.join(repoRoot, ".gitignore"), `${LEGACY_AGENT_WORKSPACES_DIR}/`);
|
|
688
783
|
const workspaces = new Set([repoRoot]);
|
|
689
784
|
for (const run of runs) {
|
|
690
|
-
if (run.workspace.path && await pathExists(run.workspace.path)) {
|
|
785
|
+
if (!hasManagedSource(run, repoRoot) && run.workspace.path && writable(run.workspace.path) && await pathExists(run.workspace.path)) {
|
|
691
786
|
workspaces.add(run.workspace.path);
|
|
692
787
|
}
|
|
693
788
|
}
|
|
@@ -740,19 +835,22 @@ async function createRunWorkspace(params) {
|
|
|
740
835
|
}
|
|
741
836
|
// Route through the run's recorded vcs. New runs are always jj; legacy git
|
|
742
837
|
// workspace runs (run.vcs === "git") still merge/sync through the git helpers.
|
|
743
|
-
async function mergeRunIntoCurrentBranch(run, allowDirty, strategy) {
|
|
838
|
+
async function mergeRunIntoCurrentBranch(run, allowDirty, strategy, abortOnConflict = false) {
|
|
839
|
+
assertLegacyRunAllowed(run);
|
|
744
840
|
if ((run.vcs ?? "git") === "jj") {
|
|
745
|
-
return await mergeJjRunIntoCurrentWorkspace(run, allowDirty);
|
|
841
|
+
return await mergeJjRunIntoCurrentWorkspace(run, allowDirty, { abortOnConflict });
|
|
746
842
|
}
|
|
747
843
|
return await mergeGitRunIntoCurrentBranch(run, allowDirty, strategy);
|
|
748
844
|
}
|
|
749
845
|
async function syncRunWorkspace(run, baseBranch) {
|
|
846
|
+
assertLegacyRunAllowed(run);
|
|
750
847
|
if ((run.vcs ?? "git") === "jj") {
|
|
751
848
|
return await syncJjRunWorkspace(run, baseBranch);
|
|
752
849
|
}
|
|
753
850
|
return await syncGitRunWorktree(run, baseBranch);
|
|
754
851
|
}
|
|
755
852
|
async function removeRunWorkspace(run, force = true) {
|
|
853
|
+
assertLegacyRunAllowed(run);
|
|
756
854
|
if ((run.vcs ?? "git") === "jj") {
|
|
757
855
|
await removeJjRunWorkspace(run);
|
|
758
856
|
return;
|
|
@@ -788,6 +886,8 @@ function shortRunTask(run) {
|
|
|
788
886
|
return taskDisplayLabel(run, 34) || "agent";
|
|
789
887
|
}
|
|
790
888
|
function workspaceKind(run) {
|
|
889
|
+
if (hasManagedSource(run))
|
|
890
|
+
return "managed workspace";
|
|
791
891
|
return (run.vcs ?? "git") === "jj" ? "jj-workspace" : "git-worktree";
|
|
792
892
|
}
|
|
793
893
|
export async function statusRuns(options) {
|
|
@@ -810,7 +910,7 @@ export async function statusRuns(options) {
|
|
|
810
910
|
}
|
|
811
911
|
export async function listProjectRuns(options) {
|
|
812
912
|
const repoRoot = findRepoRoot();
|
|
813
|
-
const runs = await listRuns(repoRoot);
|
|
913
|
+
const runs = (await listRuns(repoRoot)).map((run) => ({ ...run, timeline: readRunTimeline(repoRoot, run) }));
|
|
814
914
|
if (options?.json) {
|
|
815
915
|
console.log(JSON.stringify(runs, null, 2));
|
|
816
916
|
return;
|
|
@@ -818,6 +918,8 @@ export async function listProjectRuns(options) {
|
|
|
818
918
|
for (const run of runs) {
|
|
819
919
|
const wt = run.workspace.enabled ? ` ${workspaceKind(run)}=${shortenHome(run.workspace.path)}` : "";
|
|
820
920
|
console.log(`${run.id} ${run.status} ${run.backend}${wt} ${run.task}`);
|
|
921
|
+
if (run.timeline)
|
|
922
|
+
console.log(` ${formatTimeline(run.timeline)}`);
|
|
821
923
|
}
|
|
822
924
|
}
|
|
823
925
|
export async function watchRun(params) {
|
|
@@ -895,6 +997,7 @@ export async function stopRun(runId, options) {
|
|
|
895
997
|
if (!run) {
|
|
896
998
|
throw new Error(`Run not found: ${runId}`);
|
|
897
999
|
}
|
|
1000
|
+
assertLegacyRunAllowed(run, repoRoot, runId);
|
|
898
1001
|
// The native dashboard owns interactive PTYs in another process. Record the
|
|
899
1002
|
// stop intent first so its poll loop observes cancellation before child-exit
|
|
900
1003
|
// handling can classify our SIGTERM/SIGKILL as a failure. Headless workers
|
|
@@ -917,12 +1020,13 @@ export async function stopRun(runId, options) {
|
|
|
917
1020
|
}
|
|
918
1021
|
}
|
|
919
1022
|
export async function mergeRun(runId, allowDirty = false, options) {
|
|
920
|
-
const repoRoot = findRepoRoot();
|
|
1023
|
+
const repoRoot = options?.repoRoot ?? findRepoRoot();
|
|
921
1024
|
assertLegacyWriterAllowed(repoRoot);
|
|
922
1025
|
const run = await loadRunRecord(repoRoot, runId);
|
|
923
1026
|
if (!run) {
|
|
924
1027
|
throw new Error(`Run not found: ${runId}`);
|
|
925
1028
|
}
|
|
1029
|
+
assertLegacyRunAllowed(run, repoRoot, runId);
|
|
926
1030
|
if (run.status === "merged") {
|
|
927
1031
|
// SELF-HEAL before refusing. A run can be merged while the graph node it owns
|
|
928
1032
|
// still reads review — the run merged through a path that did not reconcile
|
|
@@ -936,7 +1040,7 @@ export async function mergeRun(runId, allowDirty = false, options) {
|
|
|
936
1040
|
throw new Error(`Run ${runId} is still active; stop it or wait for it to finish before merging.`);
|
|
937
1041
|
}
|
|
938
1042
|
const config = await loadConfig();
|
|
939
|
-
const merged = await mergeRunIntoCurrentBranch(run, allowDirty, config.mergeStrategy);
|
|
1043
|
+
const merged = await mergeRunIntoCurrentBranch(run, allowDirty, config.mergeStrategy, Boolean(options?.abortOnConflict));
|
|
940
1044
|
await emit(merged, {
|
|
941
1045
|
ts: nowIso(),
|
|
942
1046
|
runId,
|
|
@@ -954,6 +1058,7 @@ export async function mergeRun(runId, allowDirty = false, options) {
|
|
|
954
1058
|
// work sitting in review. That is how a whole plan's back half went dark
|
|
955
1059
|
// behind five already-merged nodes.
|
|
956
1060
|
await markGraphNodeMerged(repoRoot, merged);
|
|
1061
|
+
await learnIntegratedRun(merged).catch(() => undefined);
|
|
957
1062
|
await writeAgentContext(repoRoot);
|
|
958
1063
|
if (!options?.silent) {
|
|
959
1064
|
console.log(`Merged ${runId}`);
|
|
@@ -985,6 +1090,7 @@ export async function syncRun(runId, options) {
|
|
|
985
1090
|
if (!run) {
|
|
986
1091
|
throw new Error("No runs found.");
|
|
987
1092
|
}
|
|
1093
|
+
assertLegacyRunAllowed(run, repoRoot);
|
|
988
1094
|
const hasIsolation = run.workspace.enabled && (run.workspace.workspaceName || run.workspace.branch);
|
|
989
1095
|
if (!hasIsolation) {
|
|
990
1096
|
throw new Error(`Run ${run.id} has no workspace to sync.`);
|
|
@@ -1030,6 +1136,7 @@ export async function deleteRun(runId, options) {
|
|
|
1030
1136
|
if (!run) {
|
|
1031
1137
|
throw new Error(`Run not found: ${runId}`);
|
|
1032
1138
|
}
|
|
1139
|
+
assertLegacyRunAllowed(run, repoRoot, runId);
|
|
1033
1140
|
let mergeError;
|
|
1034
1141
|
if (options?.mergeFirst) {
|
|
1035
1142
|
try {
|
|
@@ -1040,6 +1147,7 @@ export async function deleteRun(runId, options) {
|
|
|
1040
1147
|
}
|
|
1041
1148
|
}
|
|
1042
1149
|
const latest = await loadRunRecord(repoRoot, runId) ?? run;
|
|
1150
|
+
assertLegacyRunAllowed(latest, repoRoot, runId);
|
|
1043
1151
|
if (options?.mergeFirst && latest.merge?.status === "conflict") {
|
|
1044
1152
|
throw new Error(`Merge conflict for ${runId}; resolve it before deleting the run.`);
|
|
1045
1153
|
}
|
|
@@ -1107,6 +1215,8 @@ export async function cleanupRuns(force = false) {
|
|
|
1107
1215
|
await writeAgentContext(repoRoot);
|
|
1108
1216
|
}
|
|
1109
1217
|
function canCleanupRun(run, force) {
|
|
1218
|
+
if (hasManagedSource(run))
|
|
1219
|
+
return false;
|
|
1110
1220
|
if (!run.workspace.enabled) {
|
|
1111
1221
|
return false;
|
|
1112
1222
|
}
|
|
@@ -1401,10 +1511,80 @@ function isContextCompletedStatus(status) {
|
|
|
1401
1511
|
return status === "merged" || status === "failed" || status === "cancelled";
|
|
1402
1512
|
}
|
|
1403
1513
|
function runHasMergeSource(run) {
|
|
1404
|
-
return Boolean(run.workspace.enabled &&
|
|
1514
|
+
return Boolean(!hasManagedSource(run) && run.workspace.enabled &&
|
|
1405
1515
|
(run.workspace.path || run.workspace.branch || run.workspace.workspaceName || run.workspace.jjChangeId));
|
|
1406
1516
|
}
|
|
1407
1517
|
function terminalExitCode(status) {
|
|
1408
1518
|
return status === "completed" || status === "merged" ? 0 : 1;
|
|
1409
1519
|
}
|
|
1520
|
+
/**
|
|
1521
|
+
* A finished isolated worker lands on its own, like the dashboard does: run the
|
|
1522
|
+
* project's quick check (rudder.toml [verification] command) inside the
|
|
1523
|
+
* worker's workspace, then merge with abort-on-conflict. A failed check or a
|
|
1524
|
+
* conflict leaves nothing merged and records why on the run.
|
|
1525
|
+
*/
|
|
1526
|
+
async function autoIntegrateFinishedWorker(repoRoot, run) {
|
|
1527
|
+
if (run.mode !== "execute" || !run.workspace?.enabled || !run.workspace.path)
|
|
1528
|
+
return;
|
|
1529
|
+
if (process.env.RUDDER_NO_AUTO_INTEGRATE === "1")
|
|
1530
|
+
return;
|
|
1531
|
+
try {
|
|
1532
|
+
// Planned nodes integrate through the scheduler's trunk, not here.
|
|
1533
|
+
const graph = await readGraph(repoRoot).catch(() => undefined);
|
|
1534
|
+
if (graph && Object.values(graph.nodes ?? {}).some((node) => node.runId === run.id))
|
|
1535
|
+
return;
|
|
1536
|
+
const failed = runProjectCheck(repoRoot, run);
|
|
1537
|
+
if (failed !== undefined) {
|
|
1538
|
+
await emit(run, { ts: nowIso(), runId: run.id, type: "merge.result", message: `needs you: checks failed\n${failed}` });
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
await mergeRun(run.id, true, { silent: true, abortOnConflict: true, repoRoot });
|
|
1542
|
+
}
|
|
1543
|
+
catch (error) {
|
|
1544
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1545
|
+
await emit(run, { ts: nowIso(), runId: run.id, type: "merge.result", message: `needs you: ${message}` }).catch(() => undefined);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Runs the project's quick check (rudder.toml [verification] command) inside
|
|
1550
|
+
* the run's workspace. Returns undefined when it passes or there is none, else
|
|
1551
|
+
* the last lines of its output.
|
|
1552
|
+
*/
|
|
1553
|
+
export function runProjectCheck(repoRoot, run) {
|
|
1554
|
+
const command = projectCheckCommand(repoRoot);
|
|
1555
|
+
if (!command || !run.workspace?.path || !fs.existsSync(run.workspace.path))
|
|
1556
|
+
return undefined;
|
|
1557
|
+
const check = inFork(run.workspace.path, "sh", ["-c", `${command} 2>&1`]);
|
|
1558
|
+
const result = spawnSync(check.command, check.args, {
|
|
1559
|
+
cwd: run.workspace.path, encoding: "utf8", timeout: 15 * 60_000, maxBuffer: 16 * 1024 * 1024,
|
|
1560
|
+
});
|
|
1561
|
+
if (result.status === 0)
|
|
1562
|
+
return undefined;
|
|
1563
|
+
return String(result.stdout ?? result.error?.message ?? "").trim().split("\n").slice(-40).join("\n");
|
|
1564
|
+
}
|
|
1565
|
+
function projectCheckCommand(repoRoot) {
|
|
1566
|
+
let raw;
|
|
1567
|
+
try {
|
|
1568
|
+
raw = fs.readFileSync(path.join(repoRoot, "rudder.toml"), "utf8");
|
|
1569
|
+
}
|
|
1570
|
+
catch {
|
|
1571
|
+
return undefined;
|
|
1572
|
+
}
|
|
1573
|
+
let inSection = false;
|
|
1574
|
+
for (const line0 of raw.split("\n")) {
|
|
1575
|
+
const line = line0.trim();
|
|
1576
|
+
if (line.startsWith("[")) {
|
|
1577
|
+
inSection = line === "[verification]";
|
|
1578
|
+
continue;
|
|
1579
|
+
}
|
|
1580
|
+
if (!inSection)
|
|
1581
|
+
continue;
|
|
1582
|
+
const match = /^command\s*=\s*(?:"((?:[^"\\]|\\.)*)"|'([^']*)')\s*$/.exec(line);
|
|
1583
|
+
if (match) {
|
|
1584
|
+
const value = (match[1] ?? match[2] ?? "").replace(/\\"/g, '"');
|
|
1585
|
+
return value.trim() ? value : undefined;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
return undefined;
|
|
1589
|
+
}
|
|
1410
1590
|
//# sourceMappingURL=run-manager.js.map
|