next-issue 6.6.24 → 6.6.26

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 CHANGED
@@ -64,7 +64,10 @@ the run handles one issue. For each issue:
64
64
  no commits of its own starts again from the remote base. An issue with no
65
65
  saved state does not reuse a local `<n>` branch: it resets that branch,
66
66
  and any worktree that holds it, to the remote branch, or to the remote
67
- base when there is none. A fast-forward of the base that is not safe
67
+ base when there is none. The main worktree of the repository is never
68
+ used, reset or cleaned: when it has the branch of the issue checked out,
69
+ the issue fails and is handed over, and the reason asks you to check out
70
+ another branch there. A fast-forward of the base that is not safe
68
71
  leaves the local base branch as it is and writes a `base.behind` event. A
69
72
  new branch then starts from the remote base.
70
73
  4. Let the implementer agent do the work, then commit it. For a behaviour
package/dist/children.mjs CHANGED
@@ -28,6 +28,9 @@ export function stopRunChildren(children) {
28
28
  export function runStopped() {
29
29
  return current.getStore()?.stopped === true;
30
30
  }
31
+ export function evenWhenStopped(body) {
32
+ return current.run(runChildren(), body);
33
+ }
31
34
  export function refuseWhenStopped() {
32
35
  if (runStopped()) {
33
36
  throw new Error('The run stopped.');
package/dist/fix.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { parseCommitSubject, parseResolved, parseUnrelated, withoutClosingReferences, } from './agent-reply.mjs';
2
2
  import { CODING } from './agents.mjs';
3
3
  import { budgetUse } from './budget.mjs';
4
+ import { runStopped } from './children.mjs';
4
5
  import { message } from './errors.mjs';
5
6
  import { HookError } from './git-commit.mjs';
6
7
  import { escalateAndFinish } from './handover.mjs';
@@ -67,10 +68,11 @@ export async function commitWork(job, before, subject, role, commit) {
67
68
  for (;;) {
68
69
  subject = withoutClosingReferences(subject, fallbackTitle(issue));
69
70
  try {
70
- if (await commitChanges(worktree, `${subject}\n\nRefs #${issue.number}`)) {
71
+ const committed = await commitChanges(worktree, `${subject}\n\nRefs #${issue.number}`);
72
+ if (committed) {
71
73
  log.event('commit', { subject });
72
74
  }
73
- if ((await ports.revision(worktree)) === before) {
75
+ if (!committed && (await ports.revision(worktree)) === before) {
74
76
  return false;
75
77
  }
76
78
  state.title = subject;
@@ -85,7 +87,7 @@ async function hookFix(job, error, subject, role) {
85
87
  const { context, issue, log, state, comments } = job;
86
88
  const { repo, config } = context;
87
89
  const used = state.commitFixes ?? 0;
88
- if (!(error instanceof HookError) || used >= config.maxCommitFixes) {
90
+ if (!(error instanceof HookError) || runStopped() || used >= config.maxCommitFixes) {
89
91
  throw error;
90
92
  }
91
93
  state.commitFixes = used + 1;
package/dist/git-land.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { evenWhenStopped } from './children.mjs';
1
2
  import { fetchBase, git, isOnBase, oneFetchAtATime, remoteRef, revision, succeeds, } from './git.mjs';
2
3
  import { commitEverything } from './git-commit.mjs';
3
4
  export const PUSH_TRIES = 3;
@@ -12,7 +13,7 @@ export async function squashOnto(cwd, base, remote, message) {
12
13
  await commitEverything(cwd, message);
13
14
  }
14
15
  catch (error) {
15
- await git(cwd, ['reset', '--soft', head]);
16
+ await evenWhenStopped(() => git(cwd, ['reset', '--soft', head]));
16
17
  throw error;
17
18
  }
18
19
  return true;
package/dist/worktree.mjs CHANGED
@@ -14,6 +14,7 @@ export async function addWorktree(repo, issue, branch, base, remote, start) {
14
14
  const baseUpdated = await fastForwardBase(repo, base, remote);
15
15
  await git(repo.root, ['worktree', 'prune']);
16
16
  await releaseFromHunt(repo, branch);
17
+ await refuseMainWorktree(repo, branch);
17
18
  const pushed = await hasBranch(repo, upstream, '--remotes');
18
19
  const existing = await findWorktree(repo, branch);
19
20
  const path = existing ?? worktreePath(repo, issue);
@@ -55,13 +56,22 @@ async function updateBase(repo, base, remote) {
55
56
  return oneFetchAtATime(() => succeeds(repo.root, args));
56
57
  }
57
58
  export async function findWorktree(repo, branch) {
58
- const path = await holder(repo, branch);
59
- return path !== undefined && (await isHunt(repo, path)) ? undefined : path;
59
+ const found = await holder(repo, branch);
60
+ if (found === undefined || found.main || (await isHunt(repo, found.path))) {
61
+ return undefined;
62
+ }
63
+ return found.path;
64
+ }
65
+ async function refuseMainWorktree(repo, branch) {
66
+ const found = await holder(repo, branch);
67
+ if (found?.main) {
68
+ throw new Error(`the main worktree at ${found.path} has branch ${branch} checked out, so the issue cannot have its own worktree; check out another branch there and try again`);
69
+ }
60
70
  }
61
71
  async function releaseFromHunt(repo, branch) {
62
- const path = await holder(repo, branch);
63
- if (path !== undefined && (await isHunt(repo, path))) {
64
- await git(path, ['checkout', '--detach']);
72
+ const found = await holder(repo, branch);
73
+ if (found !== undefined && !found.main && (await isHunt(repo, found.path))) {
74
+ await git(found.path, ['checkout', '--detach']);
65
75
  }
66
76
  }
67
77
  async function isHunt(repo, path) {
@@ -70,11 +80,12 @@ async function isHunt(repo, path) {
70
80
  }
71
81
  async function holder(repo, branch) {
72
82
  const list = await git(repo.root, ['worktree', 'list', '--porcelain']);
73
- const entry = list
74
- .split('\n\n')
75
- .map((block) => block.split('\n'))
76
- .find((lines) => lines.includes(`branch refs/heads/${branch}`));
77
- return entry?.find((line) => line.startsWith('worktree '))?.slice('worktree '.length);
83
+ const blocks = list.split('\n\n').map((block) => block.split('\n'));
84
+ const index = blocks.findIndex((lines) => lines.includes(`branch refs/heads/${branch}`));
85
+ const path = blocks[index]
86
+ ?.find((line) => line.startsWith('worktree '))
87
+ ?.slice('worktree '.length);
88
+ return path === undefined ? undefined : { path, main: index === 0 };
78
89
  }
79
90
  export async function removeWorktree(repo, path) {
80
91
  return succeeds(repo.root, ['worktree', 'remove', path]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.24",
3
+ "version": "6.6.26",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",