@sagentlab/navarch-runtime 0.1.160 → 0.1.161

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/delivery.cjs CHANGED
@@ -111,7 +111,10 @@ async function probeWorktreeDelivery(args) {
111
111
  * pushed commits with no pull request — so the reason a session is failed
112
112
  * names the earliest point the delivery chain broke.
113
113
  */
114
- function evaluateDelivery(probe) {
114
+ function evaluateDelivery(probe, binding) {
115
+ if (binding && (probe.branch !== binding.head_ref || probe.pullRequestUrl !== binding.pr_url || probe.pullRequestLookupFailed)) {
116
+ return { status: "incomplete", reason: "delivery must use the owner-assigned branch and pull request" };
117
+ }
115
118
  if (probe.dirty) {
116
119
  return {
117
120
  status: "incomplete",
@@ -13,6 +13,15 @@ const worktree_janitor_cjs_1 = require("./worktree-janitor.cjs");
13
13
  const node_fs_1 = require("node:fs");
14
14
  const sandbox_cjs_1 = require("./sandbox.cjs");
15
15
  const commit_attribution_cjs_1 = require("./commit-attribution.cjs");
16
+ // Standalone runtime mirror of lib/navarch/branch-name.ts.
17
+ // delivery-branch-parity.test.cts checks ingress and both executors together.
18
+ function isValidBranchName(value) {
19
+ return typeof value === "string" &&
20
+ value.length >= 1 && value.length <= 255 &&
21
+ value.split("/").every((component) => component.length <= 250) &&
22
+ /^[A-Za-z0-9._/-]+$/.test(value) &&
23
+ !/(^[-./]|\/[-.]|\.\.|\/\/|\/$|\.$|\.lock(\/|$)|^HEAD$)/.test(value);
24
+ }
16
25
  const repositoryLocks = new Map();
17
26
  /** Rewrites a github.com HTTPS clone URL onto the proxy; other URLs are returned unchanged. */
18
27
  function proxyCloneUrl(cloneUrl, proxyBaseUrl) {
@@ -53,6 +62,7 @@ class GitWorktree {
53
62
  repoLocalTokenInstalled = false;
54
63
  gitGrant;
55
64
  workingBranch;
65
+ deliveryBinding;
56
66
  repoLocalGithubToken;
57
67
  prContinuation;
58
68
  ownershipCommitIdentity;
@@ -71,7 +81,9 @@ class GitWorktree {
71
81
  this.checkpointRoot = node_path_1.default.join(options.workspaceRoot, "checkpoints", projectKey, taskKey, sessionKey);
72
82
  this.sessionRoot = node_path_1.default.join(options.workspaceRoot, "sessions", sessionKey);
73
83
  this.worktreePath = node_path_1.default.join(this.sessionRoot, "repo");
74
- this.repositoryPath = options.repoLocalGithubToken
84
+ // An owner-assigned branch can have any name. Keep its local ref isolated
85
+ // from other tasks and abandoned sessions that use the shared project cache.
86
+ this.repositoryPath = options.repoLocalGithubToken || options.deliveryBinding
75
87
  ? node_path_1.default.join(this.sessionRoot, "repository.git")
76
88
  : node_path_1.default.join(options.workspaceRoot, "repositories", `${projectKey}.git`);
77
89
  // One delivery task owns one remote branch across every retry. A
@@ -87,6 +99,14 @@ class GitWorktree {
87
99
  // previous attempt's temporary branch in the bare cache.
88
100
  this.branch = `navarch/${branchSlug(options)}${this.taskBranchSuffix}` +
89
101
  (options.prContinuation ? `-${sessionKey}` : "");
102
+ this.deliveryBinding = options.deliveryBinding;
103
+ if (this.deliveryBinding) {
104
+ const { head_ref, head_sha } = this.deliveryBinding;
105
+ if (!isValidBranchName(head_ref) ||
106
+ !/^[a-f0-9]{40}$/.test(head_sha))
107
+ throw new Error("Invalid delivery binding");
108
+ this.branch = head_ref;
109
+ }
90
110
  this.runner = options.runner ?? sandbox_cjs_1.nodeCommandRunner;
91
111
  this.authRetryDelaysMs = options.authRetryDelaysMs ?? DEFAULT_AUTH_RETRY_DELAYS_MS;
92
112
  this.sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
@@ -395,7 +415,8 @@ class GitWorktree {
395
415
  if (tip.code !== 0 || !/^[0-9a-f]{40,64}$/i.test(staleSha))
396
416
  return null;
397
417
  const owned = this.branch.endsWith(this.legacyTaskBranchSuffix) ||
398
- this.adoptedUnmarkedBranch ||
418
+ (!this.deliveryBinding && this.adoptedUnmarkedBranch) ||
419
+ (this.deliveryBinding && await this.isAncestor(staleSha, `refs/remotes/origin/${this.deliveryBinding.head_ref}`)) ||
399
420
  (await this.hasTaskOwnershipMarker(localRef));
400
421
  if (!owned) {
401
422
  throw new Error(`Local branch ${this.branch} already exists in the cached repository but does not ` +
@@ -420,6 +441,9 @@ class GitWorktree {
420
441
  else if (line.startsWith("branch ") && line.slice("branch ".length).trim() === localRef && currentPath)
421
442
  holders.push(currentPath);
422
443
  }
444
+ if (this.deliveryBinding && holders.length > 0) {
445
+ throw new Error(`Assigned branch ${this.branch} is held by another worktree; refusing to remove it.`);
446
+ }
423
447
  for (const holder of holders) {
424
448
  if (await (0, worktree_janitor_cjs_1.hasRecoveryMarker)(node_path_1.default.dirname(holder))) {
425
449
  throw new Error(`Worktree ${holder} is retained for recovery; restore or remove it before reusing this branch.`);
@@ -447,6 +471,14 @@ class GitWorktree {
447
471
  }
448
472
  /** Returns the fetched task-owned remote branch when an earlier attempt pushed it. */
449
473
  async resolveTaskBranchRef() {
474
+ if (this.deliveryBinding) {
475
+ const ref = `refs/remotes/origin/${this.deliveryBinding.head_ref}`;
476
+ if (!(await this.isAncestor(this.deliveryBinding.head_sha, ref))) {
477
+ throw new Error("Delivery binding branch no longer preserves its commits");
478
+ }
479
+ this.adoptedUnmarkedBranch = !(await this.hasTaskOwnershipMarker(ref));
480
+ return ref;
481
+ }
450
482
  // A follow-up must check out the reviewed PR's head, not adopt a branch
451
483
  // bearing this task's short suffix. An earlier attempt may have pushed its
452
484
  // temporary branch after dropping the claim commit; that branch must not
package/dist/prompt.cjs CHANGED
@@ -39,12 +39,15 @@ function renderQaShard(assignment) {
39
39
  * WP-07 "write prompt file".
40
40
  */
41
41
  function renderPrompt(task, bundle) {
42
+ const binding = bundle.repository?.delivery_binding;
43
+ const bindingNote = binding
44
+ ? `Owner-assigned delivery: update ${binding.pr_url} on branch \`${binding.head_ref}\` with base \`${binding.base_ref}\`. Preserve existing commits and use this PR for delivery.` : "";
42
45
  if (bundle.task_context) {
43
46
  const repositoryContext = bundle.repository
44
47
  ? `Repository: ${bundle.repository.full_name} (${bundle.repository.url})\nLocal checkout: this session's isolated git worktree (current working directory).` +
45
48
  workingBranchNote(bundle.repository.working_branch)
46
49
  : null;
47
- return [repositoryContext, PROCESS_GUIDANCE, bundle.task_context.trim(), CODE_GRAPH_GUIDANCE, bundle.retry_context?.trim()]
50
+ return [repositoryContext, PROCESS_GUIDANCE, bundle.task_context.trim(), bindingNote, CODE_GRAPH_GUIDANCE, bundle.retry_context?.trim()]
48
51
  .filter((section) => Boolean(section))
49
52
  .join("\n\n") + "\n";
50
53
  }
@@ -78,6 +81,8 @@ function renderPrompt(task, bundle) {
78
81
  sections.push("## Playbook");
79
82
  sections.push(bundle.playbook);
80
83
  sections.push(CODE_GRAPH_GUIDANCE);
84
+ if (bindingNote)
85
+ sections.push(bindingNote);
81
86
  return sections.join("\n\n");
82
87
  }
83
88
  /**
package/dist/session.cjs CHANGED
@@ -337,6 +337,12 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
337
337
  // `navarch/...` branch. PR-continuation tasks are the exception: their agent
338
338
  // must check out and push the reviewed PR's existing head branch.
339
339
  const allowBranchRename = Boolean(task.review_of_task_id);
340
+ const deliveryBinding = bundle.repository?.delivery_binding;
341
+ if (deliveryBinding && (deliveryBinding.project_id !== task.project_id ||
342
+ deliveryBinding.repository.toLowerCase() !== task.repo.toLowerCase() ||
343
+ bundle.repository?.full_name.toLowerCase() !== task.repo.toLowerCase())) {
344
+ throw new Error("Delivery binding project or repository mismatch");
345
+ }
340
346
  let runnerPreparationSignal;
341
347
  const gitWorktree = new git_worktree_cjs_1.GitWorktree({
342
348
  workspaceRoot: config.workspaceRoot,
@@ -353,6 +359,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
353
359
  githubToken,
354
360
  githubTokenProvider: githubTokenRefresher ? () => githubTokenRefresher.current : undefined,
355
361
  workingBranch: bundle.repository?.working_branch,
362
+ deliveryBinding,
356
363
  // Grant modes never expose a GitHub token, so the Codex repo-local
357
364
  // github-pat bootstrap is not installed.
358
365
  repoLocalGithubToken: gitGrantMode ? undefined : secrets["github-pat"],
@@ -363,7 +370,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
363
370
  }
364
371
  : undefined,
365
372
  // Hosted runs skip checkpoints for verify tasks, which deliver a verdict.
366
- restoreHostedCheckpoint: !allowBranchRename && task.task_type !== "verify",
373
+ restoreHostedCheckpoint: !deliveryBinding && !allowBranchRename && task.task_type !== "verify",
367
374
  ...(commitIdentity ? { ownershipCommitIdentity: commitIdentity.committer } : {}),
368
375
  });
369
376
  credentialConsumer.worktree = gitWorktree;
@@ -1283,10 +1290,10 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
1283
1290
  baseRef: await gitWorktree.resolveDeliveryBase(),
1284
1291
  claimBaselineSha: deliveryBaselineSha,
1285
1292
  });
1286
- delivery = (0, delivery_cjs_1.evaluateDelivery)({ ...probe, pullRequestUrl, pullRequestLookupFailed });
1293
+ delivery = (0, delivery_cjs_1.evaluateDelivery)({ ...probe, pullRequestUrl, pullRequestLookupFailed }, deliveryBinding);
1287
1294
  }
1288
1295
  catch (err) {
1289
- delivery = { status: "unknown", reason: `the delivery probe failed: ${String(err)}` };
1296
+ delivery = { status: deliveryBinding ? "incomplete" : "unknown", reason: `the delivery probe failed: ${String(err)}` };
1290
1297
  }
1291
1298
  deliveredPullRequest = delivery.status === "delivered";
1292
1299
  if (delivery.status === "unknown") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagentlab/navarch-runtime",
3
- "version": "0.1.160",
3
+ "version": "0.1.161",
4
4
  "description": "Navarch machine-side session manager: claims delivery tasks and runs them through local coding agents.",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",