next-issue 17.2.1 → 17.2.2

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
@@ -40,7 +40,7 @@ Give an issue the `status:todo` label to have it picked up. See [Issue format](h
40
40
 
41
41
  ### Skills for Claude Code
42
42
 
43
- `init` (see [Configuration](#configuration)) installs the `create-issue` skill, which writes an issue that the harness can claim, and the `answer-hand-over` skill, which helps you answer a hand-over. It asks whether to install them for your user or for the project; `--scope user|project` answers in advance. `start` updates an outdated copy and installs a missing skill for the project. See [Skills](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#skills).
43
+ `init` (see [Configuration](#configuration)) installs the `create-issue` skill, which writes an issue that the harness can claim, and the `answer-hand-over` skill, which helps you answer a hand-over. It asks whether to install them for your user or for the project; `--scope user|project` answers in advance. `start` updates an outdated copy and installs a missing skill for the project. next-issue keeps its project skill folders in `info/exclude`; when git tracks them, `start` asks to untrack them and commit and push the removal. See [Skills](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#skills).
44
44
 
45
45
  ## Configuration
46
46
 
@@ -1,12 +1,16 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { cp, readdir, readFile, rename, rm } from 'node:fs/promises';
3
- import { homedir } from 'node:os';
2
+ import { cp, mkdtemp, readdir, readFile, rename, rm } from 'node:fs/promises';
3
+ import { homedir, tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
5
  import { createInterface } from 'node:readline/promises';
6
6
  import { OWN_SKILLS } from '../shared/agents.mjs';
7
+ import { loadConfig } from '../shared/config.mjs';
7
8
  import { hasCode } from '../shared/errors.mjs';
9
+ import { must } from '../shared/exec.mjs';
8
10
  import { git, repoRoot } from '../shared/git.mjs';
9
11
  const SKILLS = join(import.meta.dirname, '..', '..', 'skills');
12
+ export const PROJECT_SKILL_FOLDERS = OWN_SKILLS.map((name) => `.claude/skills/${name}/`);
13
+ const UNTRACK_SUBJECT = 'chore: stop tracking the next-issue skills';
10
14
  const QUESTION = 'Install the skills for the user, in ~/.claude/skills, or for the project, in .claude/skills of the main worktree? (user/project) ';
11
15
  const ANSWERS = new Map([
12
16
  ['user', 'user'],
@@ -14,20 +18,23 @@ const ANSWERS = new Map([
14
18
  ['project', 'project'],
15
19
  ['p', 'project'],
16
20
  ]);
17
- async function askScope(input, output) {
18
- const prompt = createInterface({ input, output });
21
+ async function ask(question, output) {
22
+ const prompt = createInterface({ input: process.stdin, output });
19
23
  try {
20
- const answer = (await prompt.question(QUESTION)).trim().toLowerCase();
21
- const scope = ANSWERS.get(answer);
22
- if (scope === undefined) {
23
- throw new Error(`answer user or project, not ${JSON.stringify(answer)}`);
24
- }
25
- return scope;
24
+ return (await prompt.question(question)).trim().toLowerCase();
26
25
  }
27
26
  finally {
28
27
  prompt.close();
29
28
  }
30
29
  }
30
+ async function askScope() {
31
+ const answer = await ask(QUESTION, process.stdout);
32
+ const scope = ANSWERS.get(answer);
33
+ if (scope === undefined) {
34
+ throw new Error(`answer user or project, not ${JSON.stringify(answer)}`);
35
+ }
36
+ return scope;
37
+ }
31
38
  export async function chooseScope(scope) {
32
39
  if (scope !== undefined) {
33
40
  return scope;
@@ -35,7 +42,7 @@ export async function chooseScope(scope) {
35
42
  if (process.stdin.isTTY !== true) {
36
43
  throw new Error('`init` needs `--scope user|project` when there is no terminal to ask where to install the skills');
37
44
  }
38
- return askScope(process.stdin, process.stdout);
45
+ return askScope();
39
46
  }
40
47
  async function skillsFolder(scope) {
41
48
  const base = scope === 'user' ? homedir() : await repoRoot(process.cwd());
@@ -122,10 +129,7 @@ export async function refreshSkills(root) {
122
129
  if (hash === shipped) {
123
130
  continue;
124
131
  }
125
- if (folder === project && (await isTracked(root, join(folder, name)))) {
126
- notes.push(`kept ${join(folder, name)}: tracked by git`);
127
- }
128
- else if (await isOwnSkill(join(folder, name))) {
132
+ if (await isOwnSkill(join(folder, name))) {
129
133
  notes.push(`updated ${await replaceSkill(folder, name)}`);
130
134
  }
131
135
  else {
@@ -138,3 +142,57 @@ export async function refreshSkills(root) {
138
142
  }
139
143
  return notes;
140
144
  }
145
+ export async function untrackSkills(root) {
146
+ const folders = [];
147
+ for (const folder of PROJECT_SKILL_FOLDERS) {
148
+ if (await isTracked(root, folder)) {
149
+ folders.push(folder);
150
+ }
151
+ }
152
+ if (folders.length === 0) {
153
+ return [];
154
+ }
155
+ const { remote } = await loadConfig(root);
156
+ const tracked = `git tracks the next-issue skills in ${folders.join(', ')}`;
157
+ if (process.stdin.isTTY !== true) {
158
+ const commands = [
159
+ `git rm -r --cached -- ${folders.join(' ')}`,
160
+ `git commit -m "${UNTRACK_SUBJECT}"`,
161
+ `git push ${remote} HEAD`,
162
+ ];
163
+ throw new Error(`${tracked}; untrack them in ${root} with ${commands.map((command) => `\`${command}\``).join(', then ')}, and run \`npx -y next-issue@latest start\` again`);
164
+ }
165
+ const answer = await ask(`${tracked}. Untrack them, commit the removal and push it to ${remote}? (y/n) `, process.stderr);
166
+ if (answer !== 'y' && answer !== 'yes') {
167
+ throw new Error(`${tracked}; \`npx -y next-issue@latest start\` needs them untracked`);
168
+ }
169
+ const committed = (await git(root, ['ls-tree', '-r', '--name-only', 'HEAD', '--', ...folders])) !== '';
170
+ if (committed) {
171
+ await commitUntracked(root, folders);
172
+ try {
173
+ await git(root, ['push', '-q', remote, 'HEAD']);
174
+ }
175
+ catch (error) {
176
+ await git(root, ['reset', '-q', '--soft', 'HEAD~1']);
177
+ throw error;
178
+ }
179
+ }
180
+ await git(root, ['rm', '-r', '-q', '--cached', '-f', '--ignore-unmatch', '--', ...folders]);
181
+ return [
182
+ committed
183
+ ? `untracked ${folders.join(', ')} and pushed the commit to ${remote}`
184
+ : `untracked ${folders.join(', ')}`,
185
+ ];
186
+ }
187
+ async function commitUntracked(root, folders) {
188
+ const directory = await mkdtemp(join(tmpdir(), 'next-issue-'));
189
+ const options = { cwd: root, env: { GIT_INDEX_FILE: join(directory, 'index') } };
190
+ try {
191
+ await must('git', ['read-tree', 'HEAD'], options);
192
+ await must('git', ['rm', '-r', '-q', '--cached', '--ignore-unmatch', '--', ...folders], options);
193
+ await must('git', ['commit', '-q', '--no-verify', '-m', UNTRACK_SUBJECT], options);
194
+ }
195
+ finally {
196
+ await rm(directory, { recursive: true, force: true });
197
+ }
198
+ }
package/dist/cli.mjs CHANGED
@@ -11,7 +11,7 @@ import { serve } from './worker/serve.mjs';
11
11
  import { startInWorker } from './cli/start.mjs';
12
12
  import { STATE_DIR } from './shared/state.mjs';
13
13
  import { statusInWorker, stopInWorker, switchInWorker } from './cli/switch-run.mjs';
14
- import { chooseScope, installSkills, refreshSkills } from './cli/skills.mjs';
14
+ import { chooseScope, installSkills, PROJECT_SKILL_FOLDERS, refreshSkills, untrackSkills, } from './cli/skills.mjs';
15
15
  import { WORKTREE_DIR } from './shared/worktree.mjs';
16
16
  function write(stream, text) {
17
17
  return new Promise((resolve, reject) => {
@@ -56,7 +56,7 @@ async function main() {
56
56
  if (args.command === 'serve') {
57
57
  return serve(root);
58
58
  }
59
- for (const note of await refreshSkills(root)) {
59
+ for (const note of [...(await untrackSkills(root)), ...(await refreshSkills(root))]) {
60
60
  await write(process.stderr, `${note}\n`);
61
61
  }
62
62
  await write(process.stderr, await startInWorker(root, argv.slice(1)));
@@ -90,7 +90,10 @@ async function init(root, args) {
90
90
  }
91
91
  async function excludeStateDirectories(root, stream) {
92
92
  const exclude = await excludeFile(root);
93
- const entries = [STATE_DIR, WORKTREE_DIR].map((directory) => `${directory}/`);
93
+ const entries = [
94
+ ...[STATE_DIR, WORKTREE_DIR].map((directory) => `${directory}/`),
95
+ ...PROJECT_SKILL_FOLDERS,
96
+ ];
94
97
  for (const entry of entries) {
95
98
  if (await ensureExcluded(exclude, entry)) {
96
99
  await write(stream, `added ${entry} to ${exclude}\n`);
@@ -25,6 +25,7 @@ export function withDefaultTimeout(ms, body) {
25
25
  function spawnChild(command, args, options) {
26
26
  return spawn(command, args, {
27
27
  cwd: options.cwd,
28
+ env: options.env === undefined ? undefined : { ...process.env, ...options.env },
28
29
  detached: true,
29
30
  stdio: [
30
31
  options.input === undefined ? 'ignore' : 'pipe',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "17.2.1",
3
+ "version": "17.2.2",
4
4
  "description": "Autonomous issue harness driven by the Claude Agent SDK",
5
5
  "keywords": [
6
6
  "github",