next-issue 17.0.3 → 17.0.5

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.
@@ -66,11 +66,13 @@ export async function finishClosing(context, issue, log, state, started) {
66
66
  };
67
67
  return (await finishDone(job)).report;
68
68
  }
69
- export async function dropClosed(context, log, issue, branch) {
69
+ export async function dropClosed(context, log, issue, saved) {
70
70
  log.event('issue.drop', { title: issue.title, reason: 'closed' });
71
71
  try {
72
- await cleanUp(context, log, branch);
73
- await deleteBranches(context, log, branch);
72
+ if (openedOwnWorktree(saved)) {
73
+ await cleanUp(context, log, saved.branch);
74
+ await deleteBranches(context, log, saved.branch);
75
+ }
74
76
  await dropState(context.repo, issue.number);
75
77
  }
76
78
  catch (error) {
@@ -134,6 +136,9 @@ async function removeOrKeep(context, log, kind, fields, remove) {
134
136
  log.event(kind, fields);
135
137
  }
136
138
  }
139
+ function openedOwnWorktree(state) {
140
+ return state !== undefined && state.fresh !== true;
141
+ }
137
142
  async function cleanUp(context, log, branch) {
138
143
  const { repo, ports } = context;
139
144
  try {
@@ -207,7 +212,9 @@ export async function claimedError(context, log, issue, state, error, started) {
207
212
  log.event('hand-over.error', { error: message(failure) });
208
213
  }
209
214
  logIssueError(log, error, started);
210
- await cleanUp(context, log, state.branch);
215
+ if (openedOwnWorktree(state)) {
216
+ await cleanUp(context, log, state.branch);
217
+ }
211
218
  const report = {
212
219
  ...issueReport(issue.number, 'error', state, started, reason),
213
220
  ...(handedOver ? { handedOver } : {}),
@@ -1,7 +1,6 @@
1
1
  import { runStopped } from './children.mjs';
2
2
  import { elapsedMs } from './durations.mjs';
3
3
  import { message } from './errors.mjs';
4
- import { branchName } from './git.mjs';
5
4
  import { handOverReply } from './hand-over-comments.mjs';
6
5
  import { dropClosed, stopNow } from './handover.mjs';
7
6
  import { hasLabel } from './labels.mjs';
@@ -88,9 +87,7 @@ export async function closedReport(context, log, issue, saved, started) {
88
87
  catch (error) {
89
88
  return readError(log, issue, saved, error, started);
90
89
  }
91
- return open
92
- ? undefined
93
- : dropClosed(context, log, issue, saved?.branch ?? branchName(issue.number));
90
+ return open ? undefined : dropClosed(context, log, issue, saved);
94
91
  }
95
92
  /**
96
93
  * A person gave up on a halted issue: it never resumes to check the base while it has the skip label, so its halt
@@ -77,7 +77,8 @@ function isState(value) {
77
77
  isOptional(value.handedOver, 'boolean') &&
78
78
  (value.pendingHandOver === undefined || isPending(value.pendingHandOver)) &&
79
79
  isOptional(value.closing, 'boolean') &&
80
- isOptional(value.halted, 'boolean'));
80
+ isOptional(value.halted, 'boolean') &&
81
+ isOptional(value.fresh, 'boolean'));
81
82
  }
82
83
  export async function savedIssues(repo) {
83
84
  const names = (await unlessMissing(() => readdir(stateDir(repo.root)))) ?? [];
@@ -15,7 +15,7 @@ export async function addWorktree(repo, issue, branch, base, remote, start) {
15
15
  const baseUpdated = await fastForwardBase(repo, base, remote);
16
16
  await git(repo.root, ['worktree', 'prune']);
17
17
  await releaseFromHunt(repo, branch);
18
- await refuseMainWorktree(repo, branch);
18
+ await refuseOwnWorktree(repo, issue, branch, start);
19
19
  const pushed = await hasBranch(repo, upstream, '--remotes');
20
20
  const existing = await findWorktree(repo, branch);
21
21
  const path = existing ?? worktreePath(repo, issue);
@@ -70,11 +70,14 @@ export async function findWorktree(repo, branch) {
70
70
  }
71
71
  return found.path;
72
72
  }
73
- async function refuseMainWorktree(repo, branch) {
73
+ async function refuseOwnWorktree(repo, issue, branch, start) {
74
74
  const found = await holder(repo, branch);
75
75
  if (found?.main) {
76
76
  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`);
77
77
  }
78
+ if (start && found !== undefined && !(await samePath(found.path, worktreePath(repo, issue)))) {
79
+ throw new Error(`the 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`);
80
+ }
78
81
  }
79
82
  async function releaseFromHunt(repo, branch) {
80
83
  const found = await holder(repo, branch);
@@ -83,8 +86,11 @@ async function releaseFromHunt(repo, branch) {
83
86
  }
84
87
  }
85
88
  async function isHunt(repo, path) {
89
+ return samePath(path, huntPath(repo));
90
+ }
91
+ async function samePath(first, second) {
86
92
  const real = (target) => realpath(target).catch(() => target);
87
- return (await real(path)) === (await real(huntPath(repo)));
93
+ return (await real(first)) === (await real(second));
88
94
  }
89
95
  async function holder(repo, branch) {
90
96
  const list = await git(repo.root, ['worktree', 'list', '--porcelain']);
@@ -18,6 +18,10 @@ export async function openJob(context, issue, log, state, start, handedOver, pen
18
18
  ? await log.step('reply', {}, () => handOverReply(context, issue.number, pending))
19
19
  : [];
20
20
  const worktree = await openWorktree(context, issue, log, branch, start);
21
+ if (state.fresh === true) {
22
+ delete state.fresh;
23
+ await writeState(repo, state);
24
+ }
21
25
  return {
22
26
  context,
23
27
  issue,
@@ -26,7 +26,7 @@ export async function processIssue(context, issue, slot) {
26
26
  // A hand-over takes a closing issue back: its resume may revert or add to the change.
27
27
  const closing = saved?.closing === true && !handedOver;
28
28
  if (issue.closed === true && !closing) {
29
- return dropClosed(context, log, issue, saved?.branch ?? branchName(issue.number));
29
+ return dropClosed(context, log, issue, saved);
30
30
  }
31
31
  const skip = closing
32
32
  ? undefined
@@ -41,7 +41,7 @@ export async function processIssue(context, issue, slot) {
41
41
  try {
42
42
  report = closing
43
43
  ? await finishClosing(context, issue, log, state, started)
44
- : await work(context, issue, log, state, saved === undefined, handedOver, saved?.pendingHandOver, slot);
44
+ : await work(context, issue, log, state, state.fresh === true, handedOver, saved?.pendingHandOver, slot);
45
45
  }
46
46
  catch (error) {
47
47
  if (!runStopped()) {
@@ -66,7 +66,7 @@ function wasHandedOver(context, issue, saved) {
66
66
  }
67
67
  function startState(issue, saved, handedOver) {
68
68
  if (saved === undefined) {
69
- return newState(issue.number, branchName(issue.number));
69
+ return { ...newState(issue.number, branchName(issue.number)), fresh: true };
70
70
  }
71
71
  const { pendingHandOver: _pending, ...rest } = saved;
72
72
  return handedOver ? resetState(saved) : rest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "17.0.3",
3
+ "version": "17.0.5",
4
4
  "description": "Autonomous issue harness driven by the Claude Agent SDK",
5
5
  "keywords": [
6
6
  "github",