@sagentlab/navarch-runtime 0.1.159 → 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 +28 -4
- package/dist/git-worktree.cjs +34 -2
- package/dist/prompt.cjs +7 -1
- package/dist/session.cjs +21 -3
- package/package.json +1 -1
package/dist/delivery.cjs
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
// gate existed. A verification mechanism that fails good sessions when its own
|
|
22
22
|
// dependency is unavailable is worse than no mechanism.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.captureDeliveryBaseline = captureDeliveryBaseline;
|
|
24
25
|
exports.probeWorktreeDelivery = probeWorktreeDelivery;
|
|
25
26
|
exports.evaluateDelivery = evaluateDelivery;
|
|
26
27
|
exports.renderDeliveryCorrectionPrompt = renderDeliveryCorrectionPrompt;
|
|
@@ -28,6 +29,26 @@ exports.renderResumedDeliveryCorrectionPrompt = renderResumedDeliveryCorrectionP
|
|
|
28
29
|
const sandbox_cjs_1 = require("./sandbox.cjs");
|
|
29
30
|
const prompt_cjs_1 = require("./prompt.cjs");
|
|
30
31
|
const GIT_TIMEOUT_MS = 30_000;
|
|
32
|
+
/** Empty ownership commits carry no task changes and may disappear on rebase. */
|
|
33
|
+
async function captureDeliveryBaseline(worktreePath, runner = sandbox_cjs_1.nodeCommandRunner) {
|
|
34
|
+
const read = async (...args) => {
|
|
35
|
+
const result = await runner.run("git", ["-C", worktreePath, ...args], { timeoutMs: GIT_TIMEOUT_MS });
|
|
36
|
+
if (result.code !== 0)
|
|
37
|
+
throw new Error("Cannot capture delivery baseline");
|
|
38
|
+
return result.stdout.trim();
|
|
39
|
+
};
|
|
40
|
+
const head = await read("rev-parse", "HEAD");
|
|
41
|
+
if (await read("show", "-s", "--format=%s", "HEAD") === "chore(navarch): claim task branch") {
|
|
42
|
+
const parents = (await read("rev-list", "--parents", "-n", "1", "HEAD")).split(/\s+/).slice(1);
|
|
43
|
+
const parent = parents[0];
|
|
44
|
+
if (parents.length === 1 && parent) {
|
|
45
|
+
const trees = (await read("rev-parse", "HEAD^{tree}", "HEAD^1^{tree}")).split("\n");
|
|
46
|
+
if (trees.length === 2 && trees[0] === trees[1])
|
|
47
|
+
return parent;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return head;
|
|
51
|
+
}
|
|
31
52
|
/**
|
|
32
53
|
* Reads the worktree's delivery state.
|
|
33
54
|
*
|
|
@@ -65,12 +86,12 @@ async function probeWorktreeDelivery(args) {
|
|
|
65
86
|
const [branchRaw, statusRaw, aheadRaw, unpushedRaw] = await Promise.all([
|
|
66
87
|
git(["rev-parse", "--abbrev-ref", "HEAD"]),
|
|
67
88
|
git(["status", "--porcelain"]),
|
|
68
|
-
args.baseRef
|
|
69
|
-
? git(["rev-list", "--count", "--full-history", `${args.baseRef}..HEAD`, "--", "."])
|
|
89
|
+
(args.claimBaselineSha ?? args.baseRef)
|
|
90
|
+
? git(["rev-list", "--count", "--full-history", `${args.claimBaselineSha ?? args.baseRef}..HEAD`, "--", "."])
|
|
70
91
|
: Promise.resolve(null),
|
|
71
92
|
// Commits no origin ref carries. Independent of the base ref, so it still
|
|
72
93
|
// answers "was this pushed?" when the base cannot be resolved at all.
|
|
73
|
-
git(["rev-list", "--count", "--full-history", "HEAD", "--not", "--remotes=origin", "--", "."]),
|
|
94
|
+
git(["rev-list", "--count", "--full-history", "HEAD", ...(args.claimBaselineSha ? [`^${args.claimBaselineSha}`] : []), "--not", "--remotes=origin", "--", "."]),
|
|
74
95
|
]);
|
|
75
96
|
const branch = branchRaw?.trim() ?? "";
|
|
76
97
|
return {
|
|
@@ -90,7 +111,10 @@ async function probeWorktreeDelivery(args) {
|
|
|
90
111
|
* pushed commits with no pull request — so the reason a session is failed
|
|
91
112
|
* names the earliest point the delivery chain broke.
|
|
92
113
|
*/
|
|
93
|
-
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
|
+
}
|
|
94
118
|
if (probe.dirty) {
|
|
95
119
|
return {
|
|
96
120
|
status: "incomplete",
|
package/dist/git-worktree.cjs
CHANGED
|
@@ -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
|
-
|
|
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,17 +39,21 @@ 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
|
}
|
|
51
54
|
const sections = [];
|
|
52
55
|
sections.push(`# Task: ${task.summary}`);
|
|
56
|
+
sections.push(`Delivery contract: ${task.deliverable_kind ?? "code"}`);
|
|
53
57
|
sections.push(`Type: ${task.task_type} | Repo: ${task.repo} | Environment: ${task.environment_scope}`);
|
|
54
58
|
sections.push(PROCESS_GUIDANCE);
|
|
55
59
|
if (bundle.repository) {
|
|
@@ -77,6 +81,8 @@ function renderPrompt(task, bundle) {
|
|
|
77
81
|
sections.push("## Playbook");
|
|
78
82
|
sections.push(bundle.playbook);
|
|
79
83
|
sections.push(CODE_GRAPH_GUIDANCE);
|
|
84
|
+
if (bindingNote)
|
|
85
|
+
sections.push(bindingNote);
|
|
80
86
|
return sections.join("\n\n");
|
|
81
87
|
}
|
|
82
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;
|
|
@@ -478,6 +485,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
478
485
|
log.warn(`checkpoint failed for ${leaseId}: ${String(error)}; retaining ${gitWorktree.worktreePath} for recovery.`);
|
|
479
486
|
}
|
|
480
487
|
};
|
|
488
|
+
let deliveryBaselineSha;
|
|
481
489
|
const pollLease = () => {
|
|
482
490
|
if (leaseLost || sessionClosing)
|
|
483
491
|
return Promise.resolve();
|
|
@@ -750,6 +758,15 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
750
758
|
}
|
|
751
759
|
steering?.start();
|
|
752
760
|
await gitWorktree.prepare();
|
|
761
|
+
// Capture once before agent work. The server returns the first baseline
|
|
762
|
+
// after a restart, so a retry cannot relabel inherited commits as output.
|
|
763
|
+
if (claimed.delivery_baseline_required) {
|
|
764
|
+
const initialHead = await (0, delivery_cjs_1.captureDeliveryBaseline)(gitWorktree.worktreePath);
|
|
765
|
+
const baseline = await api.heartbeatLease(leaseId, { delivery_baseline_sha: initialHead });
|
|
766
|
+
if (!baseline.delivery_baseline_sha)
|
|
767
|
+
throw new Error("The control plane did not persist the required delivery baseline");
|
|
768
|
+
deliveryBaselineSha = baseline.delivery_baseline_sha;
|
|
769
|
+
}
|
|
753
770
|
const { browserUse, playwrightSuites } = (0, browser_evidence_cjs_1.navarchBrowserTools)({
|
|
754
771
|
taskType: task.task_type, requiredCapabilities: task.required_capabilities, runtime,
|
|
755
772
|
platform: process.platform, sandboxMode: config.sandboxMode, mcpConfigPath: config.mcpConfigPath,
|
|
@@ -1271,11 +1288,12 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
1271
1288
|
const probe = await (0, delivery_cjs_1.probeWorktreeDelivery)({
|
|
1272
1289
|
worktreePath: gitWorktree.worktreePath,
|
|
1273
1290
|
baseRef: await gitWorktree.resolveDeliveryBase(),
|
|
1291
|
+
claimBaselineSha: deliveryBaselineSha,
|
|
1274
1292
|
});
|
|
1275
|
-
delivery = (0, delivery_cjs_1.evaluateDelivery)({ ...probe, pullRequestUrl, pullRequestLookupFailed });
|
|
1293
|
+
delivery = (0, delivery_cjs_1.evaluateDelivery)({ ...probe, pullRequestUrl, pullRequestLookupFailed }, deliveryBinding);
|
|
1276
1294
|
}
|
|
1277
1295
|
catch (err) {
|
|
1278
|
-
delivery = { status: "unknown", reason: `the delivery probe failed: ${String(err)}` };
|
|
1296
|
+
delivery = { status: deliveryBinding ? "incomplete" : "unknown", reason: `the delivery probe failed: ${String(err)}` };
|
|
1279
1297
|
}
|
|
1280
1298
|
deliveredPullRequest = delivery.status === "delivered";
|
|
1281
1299
|
if (delivery.status === "unknown") {
|
package/package.json
CHANGED