@sagentlab/navarch-runtime 0.1.65 → 0.1.67

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.
@@ -36,11 +36,30 @@ async function runOpenCodeAdapter(options) {
36
36
  };
37
37
  }
38
38
  const env = { ...options.env };
39
+ // V2 resolves its workspace from PWD. spawn({ cwd }) alone leaves the
40
+ // supervisor's PWD in the inherited environment (often the home directory).
41
+ if (!options.dockerExec && options.cwd)
42
+ env.PWD = node_path_1.default.resolve(options.cwd);
39
43
  await prepareOpenCodeConfig(options.mcpConfigPath, env, Boolean(options.dockerExec));
44
+ // V2's default background service owns its own cwd, environment and MCP
45
+ // configuration. A client process's isolated config does not isolate that
46
+ // service. Probe help without starting a turn, so older in-process CLIs
47
+ // remain supported and upgrades are detected on the next session.
48
+ const runOptions = { ...options, env };
49
+ const probeOptions = { ...runOptions, timeoutMs: 10_000, onProcessStarted: undefined };
50
+ const help = options.dockerExec
51
+ ? await runViaDocker(probeOptions, ["run", "--help"])
52
+ : await runOnHost(probeOptions, ["run", "--help"]);
53
+ if (help.exitCode !== 0 || help.timedOut || help.killedByLeaseLoss) {
54
+ return { ...help, stderr: `OpenCode CLI capability check failed. ${help.stderr}` };
55
+ }
40
56
  const binaryKey = `${options.dockerExec ? "docker:" : ""}${options.bin ?? "opencode"}`;
41
57
  const defaultLogLevel = !hasArg(options.extraArgs, "--log-level");
42
58
  const logLevel = defaultLogLevel ? (openCodeLogLevels.get(binaryKey) ?? "ERROR") : null;
43
59
  const args = ["run", options.prompt];
60
+ if (/^\s*--standalone\b/m.test(help.stdout) && !hasArg(options.extraArgs, "--standalone")) {
61
+ args.push("--standalone");
62
+ }
44
63
  // Provider failures may only appear in logs, absent from assistant events.
45
64
  if (!hasArg(options.extraArgs, "--print-logs"))
46
65
  args.push("--print-logs");
@@ -57,7 +76,6 @@ async function runOpenCodeAdapter(options) {
57
76
  // use the model's own default.
58
77
  args.push("--model", options.reasoningEffort ? `${options.model}#${options.reasoningEffort}` : options.model);
59
78
  }
60
- const runOptions = { ...options, env };
61
79
  const run = (runArgs) => runOptions.dockerExec ? runViaDocker(runOptions, runArgs) : runOnHost(runOptions, runArgs);
62
80
  let raw = await run(args);
63
81
  if (logLevel && raw.exitCode !== 0 && isLogLevelRejection(raw.stderr)) {
package/dist/delivery.cjs CHANGED
@@ -110,6 +110,13 @@ function evaluateDelivery(probe) {
110
110
  }
111
111
  return { status: "no_changes" };
112
112
  }
113
+ // A failed GitHub lookup also means we cannot distinguish a genuinely
114
+ // unpushed commit from a successful push whose remote-tracking ref was not
115
+ // fetched after the agent turn. Do not fail and delete a delivered worktree
116
+ // based only on the cache in that state.
117
+ if (probe.pullRequestLookupFailed) {
118
+ return { status: "unknown", reason: "the pull request lookup could not run, so delivery cannot be confirmed" };
119
+ }
113
120
  if (probe.unpushedCommits > 0) {
114
121
  const plural = probe.unpushedCommits === 1 ? "commit" : "commits";
115
122
  return {
@@ -118,10 +125,7 @@ function evaluateDelivery(probe) {
118
125
  "were never pushed, so the work exists only in this session's worktree",
119
126
  };
120
127
  }
121
- // Pushed, but nothing carries it. Only gate when GitHub actually answered.
122
- if (probe.pullRequestLookupFailed) {
123
- return { status: "unknown", reason: "the pull request lookup could not run, so delivery cannot be confirmed" };
124
- }
128
+ // Pushed, but nothing carries it. GitHub answered the lookup above.
125
129
  const plural = probe.commitsAhead === 1 ? "commit" : "commits";
126
130
  return {
127
131
  status: "incomplete",
@@ -31,6 +31,7 @@ class GitWorktree {
31
31
  cloneUrl;
32
32
  githubToken;
33
33
  repoLocalGithubToken;
34
+ prContinuation;
34
35
  taskBranchSuffix;
35
36
  legacyTaskBranchSuffix;
36
37
  taskOwnershipTrailer;
@@ -57,11 +58,16 @@ class GitWorktree {
57
58
  this.legacyTaskBranchSuffix = `-${normalizedTaskId}`;
58
59
  this.taskOwnershipTrailer = `Navarch-Task-ID: ${normalizedTaskId}`;
59
60
  this.sessionTokenMarker = `navarch-session-github-token:${sessionKey}`;
60
- this.branch = `navarch/${branchSlug(options)}${this.taskBranchSuffix}`;
61
+ // A continuation delivers on the reviewed PR's existing branch. Its
62
+ // initial worktree branch is disposable and must not collide with a
63
+ // previous attempt's temporary branch in the bare cache.
64
+ this.branch = `navarch/${branchSlug(options)}${this.taskBranchSuffix}` +
65
+ (options.prContinuation ? `-${sessionKey}` : "");
61
66
  this.runner = options.runner ?? sandbox_cjs_1.nodeCommandRunner;
62
67
  this.cloneUrl = options.cloneUrl;
63
68
  this.githubToken = options.githubToken;
64
69
  this.repoLocalGithubToken = options.repoLocalGithubToken;
70
+ this.prContinuation = options.prContinuation ?? false;
65
71
  this.hostedCheckpointRef = options.restoreHostedCheckpoint ? hostedCheckpointRef(options.taskId) : null;
66
72
  this.hostedCheckpointLocalRef = `refs/navarch/restored-checkpoints/${taskKey}`;
67
73
  }
@@ -349,6 +355,12 @@ class GitWorktree {
349
355
  }
350
356
  /** Returns the fetched task-owned remote branch when an earlier attempt pushed it. */
351
357
  async resolveTaskBranchRef() {
358
+ // A follow-up must check out the reviewed PR's head, not adopt a branch
359
+ // bearing this task's short suffix. An earlier attempt may have pushed its
360
+ // temporary branch after dropping the claim commit; that branch must not
361
+ // prevent later attempts from reaching the actual PR.
362
+ if (this.prContinuation)
363
+ return null;
352
364
  const refs = await this.runGit(["--git-dir", this.repositoryPath, "for-each-ref", "--format=%(refname)", "refs/remotes/origin/navarch"], false);
353
365
  const suffixMatches = refs.stdout
354
366
  .split("\n")
package/dist/prompt.cjs CHANGED
@@ -4,6 +4,7 @@ exports.renderPrompt = renderPrompt;
4
4
  exports.renderGuidanceCorrectionPrompt = renderGuidanceCorrectionPrompt;
5
5
  exports.renderHostedCheckpointNote = renderHostedCheckpointNote;
6
6
  const CODE_GRAPH_GUIDANCE = "For JS/TS dependency inspection, the runtime provides `navarch-runtime code-graph --query <symbol-or-file> --mode search|callers|callees|impact --commit HEAD`. If the runtime is not on PATH, use its installed entry point; do not install another copy mid-task. Results describe committed source and include commit/freshness warnings; inspect current files for uncommitted changes and unresolved dependencies.";
7
+ const PROCESS_GUIDANCE = "Process management: this host may run other agent sessions. Keep the PID or tool handle of each preview server you start and stop only that owned process. Never use broad process-name or command-line matching (pkill, killall) to clean up servers: the agent launcher carries the task prompt in its arguments and can match those patterns, terminating your own session. Use a different port when a port is occupied by a process you do not own. Keep scratch files in the current worktree; paths in previous transcripts belong to earlier sessions.";
7
8
  /**
8
9
  * Renders the four-layer context bundle (project-plan.md §3.8: steering docs,
9
10
  * task itself, task-type playbook, depends_on reports) into the single prompt
@@ -16,13 +17,14 @@ function renderPrompt(task, bundle) {
16
17
  const repositoryContext = bundle.repository
17
18
  ? `Repository: ${bundle.repository.full_name} (${bundle.repository.url})\nLocal checkout: this session's isolated git worktree (current working directory).`
18
19
  : null;
19
- return [repositoryContext, bundle.task_context.trim(), CODE_GRAPH_GUIDANCE, bundle.retry_context?.trim()]
20
+ return [repositoryContext, PROCESS_GUIDANCE, bundle.task_context.trim(), CODE_GRAPH_GUIDANCE, bundle.retry_context?.trim()]
20
21
  .filter((section) => Boolean(section))
21
22
  .join("\n\n") + "\n";
22
23
  }
23
24
  const sections = [];
24
25
  sections.push(`# Task: ${task.summary}`);
25
26
  sections.push(`Type: ${task.task_type} | Repo: ${task.repo} | Environment: ${task.environment_scope}`);
27
+ sections.push(PROCESS_GUIDANCE);
26
28
  if (bundle.repository) {
27
29
  sections.push(`Repository URL: ${bundle.repository.url}\nLocal checkout: this session's isolated git worktree (current working directory).`);
28
30
  }
package/dist/session.cjs CHANGED
@@ -199,6 +199,7 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
199
199
  taskId: task.id,
200
200
  taskSummary: task.summary,
201
201
  taskType: task.task_type,
202
+ prContinuation: allowBranchRename,
202
203
  sessionId,
203
204
  cloneUrl,
204
205
  githubToken,
@@ -622,7 +623,8 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
622
623
  deliveryFailureSummary =
623
624
  `Session ended without delivering the task: ${delivery.reason}. ` +
624
625
  `${deliveryCorrectionRetries} correction turn(s) did not recover it. ` +
625
- "The session worktree is deleted at teardown, so the work is gone; the task needs another attempt.";
626
+ "The session worktree is deleted at teardown. Pushed commits remain on origin; " +
627
+ "uncommitted or unpushed work may be lost. The task needs another attempt.";
626
628
  log.warn(`failing ${leaseId}: ${deliveryFailureSummary}`);
627
629
  mapping.leaseOutcome = "failed";
628
630
  mapping.exitStatus = "failed";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagentlab/navarch-runtime",
3
- "version": "0.1.65",
3
+ "version": "0.1.67",
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",