@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.
Files changed (238) hide show
  1. package/README.md +33 -69
  2. package/assets/skills/burst/SKILL.md +64 -0
  3. package/dist/agent-efficiency/backend-observer.d.ts +13 -0
  4. package/dist/agent-efficiency/backend-observer.js +77 -0
  5. package/dist/agent-efficiency/backend-observer.js.map +1 -0
  6. package/dist/agent-efficiency/handoff.d.ts +9 -0
  7. package/dist/agent-efficiency/handoff.js +42 -0
  8. package/dist/agent-efficiency/handoff.js.map +1 -0
  9. package/dist/agent-efficiency/index.d.ts +11 -0
  10. package/dist/agent-efficiency/index.js +7 -0
  11. package/dist/agent-efficiency/index.js.map +1 -0
  12. package/dist/agent-efficiency/lessons.d.ts +55 -0
  13. package/dist/agent-efficiency/lessons.js +107 -0
  14. package/dist/agent-efficiency/lessons.js.map +1 -0
  15. package/dist/agent-efficiency/privacy.d.ts +6 -0
  16. package/dist/agent-efficiency/privacy.js +28 -0
  17. package/dist/agent-efficiency/privacy.js.map +1 -0
  18. package/dist/agent-efficiency/production.d.ts +16 -0
  19. package/dist/agent-efficiency/production.js +120 -0
  20. package/dist/agent-efficiency/production.js.map +1 -0
  21. package/dist/agent-efficiency/storage.d.ts +3 -0
  22. package/dist/agent-efficiency/storage.js +28 -0
  23. package/dist/agent-efficiency/storage.js.map +1 -0
  24. package/dist/agent-efficiency/telemetry.d.ts +59 -0
  25. package/dist/agent-efficiency/telemetry.js +143 -0
  26. package/dist/agent-efficiency/telemetry.js.map +1 -0
  27. package/dist/agent-efficiency/trace-lessons.d.ts +21 -0
  28. package/dist/agent-efficiency/trace-lessons.js +36 -0
  29. package/dist/agent-efficiency/trace-lessons.js.map +1 -0
  30. package/dist/agent-efficiency/waits.d.ts +52 -0
  31. package/dist/agent-efficiency/waits.js +131 -0
  32. package/dist/agent-efficiency/waits.js.map +1 -0
  33. package/dist/backends.js +14 -8
  34. package/dist/backends.js.map +1 -1
  35. package/dist/board/authority.d.ts +48 -0
  36. package/dist/board/authority.js +125 -0
  37. package/dist/board/authority.js.map +1 -0
  38. package/dist/board/board.js +6 -2
  39. package/dist/board/daemon.d.ts +3 -6
  40. package/dist/board/daemon.js +242 -222
  41. package/dist/board/daemon.js.map +1 -1
  42. package/dist/board/host-access.d.ts +8 -0
  43. package/dist/board/host-access.js +222 -0
  44. package/dist/board/host-access.js.map +1 -0
  45. package/dist/board/project-files.d.ts +12 -0
  46. package/dist/board/project-files.js +78 -0
  47. package/dist/board/project-files.js.map +1 -0
  48. package/dist/brain.d.ts +2 -1
  49. package/dist/brain.js +15 -21
  50. package/dist/brain.js.map +1 -1
  51. package/dist/claude-sdk-protocol.js +10 -7
  52. package/dist/claude-sdk-protocol.js.map +1 -1
  53. package/dist/cloud-build-profile.d.ts +22 -0
  54. package/dist/cloud-build-profile.js +160 -0
  55. package/dist/cloud-build-profile.js.map +1 -0
  56. package/dist/cloud.js +23 -470
  57. package/dist/cloud.js.map +1 -1
  58. package/dist/codex-binary.d.ts +1 -0
  59. package/dist/codex-binary.js +8 -1
  60. package/dist/codex-binary.js.map +1 -1
  61. package/dist/daemon.d.ts +2 -0
  62. package/dist/daemon.js +14 -2
  63. package/dist/daemon.js.map +1 -1
  64. package/dist/effort.d.ts +8 -0
  65. package/dist/effort.js +15 -2
  66. package/dist/effort.js.map +1 -1
  67. package/dist/engine-authority.js +16 -0
  68. package/dist/engine-authority.js.map +1 -1
  69. package/dist/engine.d.ts +1 -1
  70. package/dist/engine.js +11 -2
  71. package/dist/engine.js.map +1 -1
  72. package/dist/fabric-fetch.d.ts +25 -0
  73. package/dist/fabric-fetch.js +402 -0
  74. package/dist/fabric-fetch.js.map +1 -0
  75. package/dist/fabric-local.d.ts +5 -2
  76. package/dist/fabric-local.js +36 -1
  77. package/dist/fabric-local.js.map +1 -1
  78. package/dist/fabric-remote.d.ts +76 -1
  79. package/dist/fabric-remote.js +333 -61
  80. package/dist/fabric-remote.js.map +1 -1
  81. package/dist/git.js +23 -0
  82. package/dist/git.js.map +1 -1
  83. package/dist/graph.js +9 -1
  84. package/dist/graph.js.map +1 -1
  85. package/dist/jj.d.ts +3 -1
  86. package/dist/jj.js +34 -2
  87. package/dist/jj.js.map +1 -1
  88. package/dist/main.js +115 -311
  89. package/dist/main.js.map +1 -1
  90. package/dist/migration.d.ts +2 -0
  91. package/dist/migration.js +3 -0
  92. package/dist/migration.js.map +1 -1
  93. package/dist/models.js +11 -6
  94. package/dist/models.js.map +1 -1
  95. package/dist/native/darwin-arm64/native-manifest.json +19 -0
  96. package/dist/native/darwin-arm64/rudder-jj +0 -0
  97. package/dist/native/darwin-arm64/rudder-native +0 -0
  98. package/dist/native/linux-x64/native-manifest.json +19 -0
  99. package/dist/native/linux-x64/rudder-jj +0 -0
  100. package/dist/native/linux-x64/rudder-native +0 -0
  101. package/dist/native-agents.js +3 -7
  102. package/dist/native-agents.js.map +1 -1
  103. package/dist/native-binary.js +11 -1
  104. package/dist/native-binary.js.map +1 -1
  105. package/dist/operations/cli.d.ts +23 -0
  106. package/dist/operations/cli.js +110 -0
  107. package/dist/operations/cli.js.map +1 -0
  108. package/dist/operations/registry.d.ts +1076 -0
  109. package/dist/operations/registry.js +69 -0
  110. package/dist/operations/registry.js.map +1 -0
  111. package/dist/operations/registry.json +124 -0
  112. package/dist/operations/requests.d.ts +167 -0
  113. package/dist/operations/requests.js +223 -0
  114. package/dist/operations/requests.js.map +1 -0
  115. package/dist/planning-ownership/index.d.ts +134 -0
  116. package/dist/planning-ownership/index.js +291 -0
  117. package/dist/planning-ownership/index.js.map +1 -0
  118. package/dist/planning-ownership/ingress.d.ts +30 -0
  119. package/dist/planning-ownership/ingress.js +41 -0
  120. package/dist/planning-ownership/ingress.js.map +1 -0
  121. package/dist/planning-ownership/store.d.ts +19 -0
  122. package/dist/planning-ownership/store.js +30 -0
  123. package/dist/planning-ownership/store.js.map +1 -0
  124. package/dist/private-access/cli.d.ts +22 -0
  125. package/dist/private-access/cli.js +76 -0
  126. package/dist/private-access/cli.js.map +1 -0
  127. package/dist/private-access/engine.d.ts +20 -0
  128. package/dist/private-access/engine.js +47 -0
  129. package/dist/private-access/engine.js.map +1 -0
  130. package/dist/private-access/home.d.ts +21 -0
  131. package/dist/private-access/home.js +80 -0
  132. package/dist/private-access/home.js.map +1 -0
  133. package/dist/private-access/previews.d.ts +101 -0
  134. package/dist/private-access/previews.js +447 -0
  135. package/dist/private-access/previews.js.map +1 -0
  136. package/dist/project-files/cli.d.ts +7 -0
  137. package/dist/project-files/cli.js +22 -0
  138. package/dist/project-files/cli.js.map +1 -0
  139. package/dist/project-files/engine.d.ts +14 -0
  140. package/dist/project-files/engine.js +52 -0
  141. package/dist/project-files/engine.js.map +1 -0
  142. package/dist/project-files/home.d.ts +13 -0
  143. package/dist/project-files/home.js +46 -0
  144. package/dist/project-files/home.js.map +1 -0
  145. package/dist/project-files/http.d.ts +9 -0
  146. package/dist/project-files/http.js +54 -0
  147. package/dist/project-files/http.js.map +1 -0
  148. package/dist/project-files/open.d.ts +10 -0
  149. package/dist/project-files/open.js +37 -0
  150. package/dist/project-files/open.js.map +1 -0
  151. package/dist/project-files/references.d.ts +9 -0
  152. package/dist/project-files/references.js +29 -0
  153. package/dist/project-files/references.js.map +1 -0
  154. package/dist/project-files/service.d.ts +32 -0
  155. package/dist/project-files/service.js +236 -0
  156. package/dist/project-files/service.js.map +1 -0
  157. package/dist/project-files/types.d.ts +40 -0
  158. package/dist/project-files/types.js +2 -0
  159. package/dist/project-files/types.js.map +1 -0
  160. package/dist/run-manager.d.ts +8 -0
  161. package/dist/run-manager.js +193 -13
  162. package/dist/run-manager.js.map +1 -1
  163. package/dist/run-timeline.d.ts +31 -0
  164. package/dist/run-timeline.js +116 -0
  165. package/dist/run-timeline.js.map +1 -0
  166. package/dist/scheduler.js +72 -13
  167. package/dist/scheduler.js.map +1 -1
  168. package/dist/surfaces.js +3 -8
  169. package/dist/surfaces.js.map +1 -1
  170. package/dist/tailscale-preview.d.ts +6 -2
  171. package/dist/tailscale-preview.js +58 -13
  172. package/dist/tailscale-preview.js.map +1 -1
  173. package/dist/task-routing.d.ts +2 -0
  174. package/dist/task-routing.js +42 -25
  175. package/dist/task-routing.js.map +1 -1
  176. package/dist/terminal-screen.d.ts +6 -0
  177. package/dist/terminal-screen.js +23 -0
  178. package/dist/terminal-screen.js.map +1 -0
  179. package/dist/tool-cache.d.ts +23 -0
  180. package/dist/tool-cache.js +144 -0
  181. package/dist/tool-cache.js.map +1 -0
  182. package/dist/types.d.ts +0 -17
  183. package/dist/types.js.map +1 -1
  184. package/dist/util.d.ts +8 -0
  185. package/dist/util.js +38 -2
  186. package/dist/util.js.map +1 -1
  187. package/dist/v4-migration/capture.d.ts +53 -0
  188. package/dist/v4-migration/capture.js +197 -0
  189. package/dist/v4-migration/capture.js.map +1 -0
  190. package/dist/v4-migration/cli.d.ts +4 -0
  191. package/dist/v4-migration/cli.js +38 -0
  192. package/dist/v4-migration/cli.js.map +1 -0
  193. package/dist/v4-migration/recovery.d.ts +43 -0
  194. package/dist/v4-migration/recovery.js +180 -0
  195. package/dist/v4-migration/recovery.js.map +1 -0
  196. package/dist/version-check.d.ts +2 -0
  197. package/dist/version-check.js +23 -0
  198. package/dist/version-check.js.map +1 -1
  199. package/dist/warm-snapshot.d.ts +55 -0
  200. package/dist/warm-snapshot.js +382 -0
  201. package/dist/warm-snapshot.js.map +1 -0
  202. package/package.json +4 -3
  203. package/scripts/copy-native.mjs +35 -48
  204. package/scripts/native-artifacts.mjs +248 -0
  205. package/dist/improve/advisor.d.ts +0 -10
  206. package/dist/improve/advisor.js +0 -115
  207. package/dist/improve/advisor.js.map +0 -1
  208. package/dist/improve/collect.d.ts +0 -49
  209. package/dist/improve/collect.js +0 -274
  210. package/dist/improve/collect.js.map +0 -1
  211. package/dist/improve/gate.d.ts +0 -17
  212. package/dist/improve/gate.js +0 -60
  213. package/dist/improve/gate.js.map +0 -1
  214. package/dist/improve/index.d.ts +0 -9
  215. package/dist/improve/index.js +0 -376
  216. package/dist/improve/index.js.map +0 -1
  217. package/dist/improve/judge.d.ts +0 -32
  218. package/dist/improve/judge.js +0 -114
  219. package/dist/improve/judge.js.map +0 -1
  220. package/dist/improve/mine.d.ts +0 -31
  221. package/dist/improve/mine.js +0 -192
  222. package/dist/improve/mine.js.map +0 -1
  223. package/dist/improve/propose.d.ts +0 -51
  224. package/dist/improve/propose.js +0 -150
  225. package/dist/improve/propose.js.map +0 -1
  226. package/dist/improve/rank.d.ts +0 -16
  227. package/dist/improve/rank.js +0 -49
  228. package/dist/improve/rank.js.map +0 -1
  229. package/dist/improve/schedule.d.ts +0 -1
  230. package/dist/improve/schedule.js +0 -95
  231. package/dist/improve/schedule.js.map +0 -1
  232. package/dist/improve/ship.d.ts +0 -25
  233. package/dist/improve/ship.js +0 -82
  234. package/dist/improve/ship.js.map +0 -1
  235. package/dist/improve/state.d.ts +0 -157
  236. package/dist/improve/state.js +0 -264
  237. package/dist/improve/state.js.map +0 -1
  238. package/dist/native/darwin-x64/rudder-native +0 -0
@@ -1,4 +1,6 @@
1
- import { spawn } from "node:child_process";
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