baton-issue-tracker 1.4.0 → 1.6.0
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/package.json +2 -1
- package/source/cli.js +37 -15
- package/source/commands/approve.js +13 -5
- package/source/commands/create.js +218 -29
- package/source/commands/init.js +22 -10
- package/source/commands/list.js +30 -16
- package/source/commands/log.js +85 -0
- package/source/commands/loop.js +7 -3
- package/source/commands/next.js +20 -13
- package/source/commands/priority.js +102 -0
- package/source/commands/search.js +24 -14
- package/source/commands/status.js +47 -17
- package/source/commands/update.js +231 -41
- package/source/commands/view.js +23 -13
- package/source/util.js +61 -0
package/source/commands/loop.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// baton loop -n 5
|
|
12
12
|
|
|
13
13
|
import { isTrackerReady } from '../services/issuesService.js';
|
|
14
|
-
import { getNumericFlag, reportTrackerNotReady } from '../util.js';
|
|
14
|
+
import { getNumericFlag, hasFlag, renderOutput, reportTrackerNotReady } from '../util.js';
|
|
15
15
|
import { run as runNext } from './next.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -30,7 +30,9 @@ function parseLoopFlags(args) {
|
|
|
30
30
|
* @returns {Promise<number>}
|
|
31
31
|
*/
|
|
32
32
|
export async function run(args = []) {
|
|
33
|
-
const
|
|
33
|
+
const isJson = hasFlag(args, '--json');
|
|
34
|
+
const loopArgs = args.filter((arg) => arg !== '--json');
|
|
35
|
+
const { steps } = parseLoopFlags(loopArgs);
|
|
34
36
|
|
|
35
37
|
if (!isTrackerReady()) {
|
|
36
38
|
reportTrackerNotReady();
|
|
@@ -58,6 +60,8 @@ export async function run(args = []) {
|
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
renderOutput(isJson, { status: 'success', steps, completed }, () => {
|
|
64
|
+
console.log(`\nCompleted ${completed} autonomous step(s).`);
|
|
65
|
+
});
|
|
62
66
|
return 0;
|
|
63
67
|
}
|
package/source/commands/next.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
selectNextIssue,
|
|
9
9
|
workOnIssue,
|
|
10
10
|
} from '../services/issuesService.js';
|
|
11
|
-
import { formatTimestamp, reportTrackerNotReady } from '../util.js';
|
|
11
|
+
import { formatTimestamp, hasFlag, renderOutput, reportTrackerNotReady, serializeIssue } from '../util.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Moves the AI agent to work on the next issue.
|
|
@@ -17,7 +17,9 @@ import { formatTimestamp, reportTrackerNotReady } from '../util.js';
|
|
|
17
17
|
* Stats are updated on the issue through workOnIssue function from init.js.
|
|
18
18
|
* @returns {Promise<number>} The exit code: 0 is success, 1 is error.
|
|
19
19
|
*/
|
|
20
|
-
export async function run() {
|
|
20
|
+
export async function run(args = []) {
|
|
21
|
+
const isJson = hasFlag(args, '--json');
|
|
22
|
+
|
|
21
23
|
if (!isTrackerReady()) {
|
|
22
24
|
reportTrackerNotReady();
|
|
23
25
|
return 1;
|
|
@@ -25,22 +27,27 @@ export async function run() {
|
|
|
25
27
|
|
|
26
28
|
const issue = selectNextIssue();
|
|
27
29
|
if (!issue) {
|
|
28
|
-
|
|
30
|
+
renderOutput(isJson, { status: 'success', issue: null }, () => {
|
|
31
|
+
console.log('No open issues available. All work is complete or the backlog is empty.');
|
|
32
|
+
});
|
|
29
33
|
return 0;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
const updated = workOnIssue(issue.id);
|
|
37
|
+
const envelope = { status: 'success', issue: serializeIssue(updated) };
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
39
|
+
renderOutput(isJson, envelope, () => {
|
|
40
|
+
console.log('Working on next issue:');
|
|
41
|
+
console.log(` ID: #${updated.id}`);
|
|
42
|
+
console.log(` Title: ${updated.title}`);
|
|
43
|
+
console.log(` Priority: ${updated.priority}`);
|
|
44
|
+
console.log(` Status: ${updated.status}`);
|
|
45
|
+
console.log(` Attempts: ${updated.attemptNum}`);
|
|
46
|
+
console.log(` Created: ${formatTimestamp(updated.createdAt)}`);
|
|
47
|
+
if (updated.description) {
|
|
48
|
+
console.log(` Description: ${updated.description}`);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
44
51
|
|
|
45
52
|
return 0;
|
|
46
53
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// AI was consulted for some portions of this file.
|
|
2
|
+
// priority.js
|
|
3
|
+
// Sets the priority of an issue.
|
|
4
|
+
// Usage: baton priority <id> <priority>
|
|
5
|
+
//
|
|
6
|
+
// Options:
|
|
7
|
+
// -h, --help Show this help
|
|
8
|
+
// --json Output as JSON (for AI agents)
|
|
9
|
+
//
|
|
10
|
+
// Examples:
|
|
11
|
+
// baton priority 5 high
|
|
12
|
+
// baton priority 3 low
|
|
13
|
+
|
|
14
|
+
import { Priority } from '../models/issue.js';
|
|
15
|
+
import { setPriority } from '../services/issuesService.js';
|
|
16
|
+
import { hasFlag, renderOutput, serializeIssue, wantsHelp } from '../util.js';
|
|
17
|
+
|
|
18
|
+
const HELP = `Usage:
|
|
19
|
+
baton priority <id> <priority>
|
|
20
|
+
|
|
21
|
+
Options:
|
|
22
|
+
-h, --help Show this help
|
|
23
|
+
--json Output as JSON (for AI agents)
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
26
|
+
baton priority 5 high
|
|
27
|
+
baton priority 3 low
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Normalize CLI priority input to a canonical Priority enum value.
|
|
32
|
+
* @param {string} input
|
|
33
|
+
* @returns {string | null}
|
|
34
|
+
*/
|
|
35
|
+
function normalizePriority(input) {
|
|
36
|
+
const values = Object.values(Priority);
|
|
37
|
+
return values.find((v) => v.toLowerCase() === input.trim().toLowerCase()) ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Sets the priority of an issue.
|
|
42
|
+
* @param {string[]} args - The command line arguments.
|
|
43
|
+
* @returns {Promise<number>} The exit code: 0 is success, 1 is error.
|
|
44
|
+
*/
|
|
45
|
+
export async function run(args) {
|
|
46
|
+
if (wantsHelp(args)) {
|
|
47
|
+
console.log(HELP);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const isJson = hasFlag(args, '--json');
|
|
52
|
+
const cmdArgs = args.filter((arg) => arg !== '--json');
|
|
53
|
+
|
|
54
|
+
if (cmdArgs.length < 2) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'Invalid input: Missing issue ID or priority.\nUsage: baton priority <id> <priority>'
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (cmdArgs.length > 2) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
'Invalid input: Too many arguments.\nUsage: baton priority <id> <priority>'
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const arg of cmdArgs) {
|
|
67
|
+
if (arg.startsWith('--')) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
'Unknown flag provided.\nUsage: baton priority <id> <priority>\nPriority: low | medium | high'
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const id = parseInt(cmdArgs[0], 10);
|
|
75
|
+
if (Number.isNaN(id)) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
'Invalid input: ID must be a number.\nUsage: baton priority <id> <priority>'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const priority = normalizePriority(cmdArgs[1]);
|
|
82
|
+
if (!priority) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Invalid priority "${cmdArgs[1]}". Must be one of: low, medium, high.\nUsage: baton priority <id> <priority>`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const issue = setPriority(id, priority);
|
|
90
|
+
const envelope = { status: 'success', issue: serializeIssue(issue) };
|
|
91
|
+
|
|
92
|
+
renderOutput(isJson, envelope, () => {
|
|
93
|
+
console.log(`Issue #${issue.id} priority set to ${issue.priority}.`);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return 0;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error('Error: Failed to set issue priority.');
|
|
99
|
+
console.error(error.message);
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -4,7 +4,13 @@
|
|
|
4
4
|
// Usage: baton search "login bug"
|
|
5
5
|
|
|
6
6
|
import { searchIssues } from "../services/issuesService.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
hasFlag,
|
|
9
|
+
printIssueTable,
|
|
10
|
+
printTableHeader,
|
|
11
|
+
renderOutput,
|
|
12
|
+
serializeIssue,
|
|
13
|
+
} from '../util.js';
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
16
|
* Searches for a title or description matching the command line argument
|
|
@@ -12,27 +18,31 @@ import { printIssueTable, printTableHeader } from '../util.js';
|
|
|
12
18
|
* @returns {Promise<number>} The exit code: 0 is success, 1 is error.
|
|
13
19
|
*/
|
|
14
20
|
export async function run(args) {
|
|
15
|
-
|
|
21
|
+
const isJson = hasFlag(args, '--json');
|
|
22
|
+
const queryArgs = args.filter((arg) => arg !== '--json');
|
|
23
|
+
|
|
24
|
+
if (queryArgs.length === 0 || queryArgs === '') {
|
|
16
25
|
throw new Error("Invalid input: No search term entered.\nUsage: baton search <query>");
|
|
17
26
|
}
|
|
18
27
|
|
|
19
28
|
try {
|
|
20
|
-
const query =
|
|
29
|
+
const query = queryArgs.join(' ');
|
|
21
30
|
const result = await searchIssues(query);
|
|
31
|
+
const issues = result.map(serializeIssue);
|
|
32
|
+
const envelope = { status: 'success', count: issues.length, issues };
|
|
22
33
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log(`\nFound ${result.length} issue(s) containing "${query}":\n`);
|
|
34
|
+
renderOutput(isJson, envelope, (data) => {
|
|
35
|
+
if (data.count === 0) {
|
|
36
|
+
console.log(`No issues containing "${query}" were found.`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
console.log(`\nFound ${data.count} issue(s) containing "${query}":\n`);
|
|
41
|
+
printTableHeader();
|
|
42
|
+
result.forEach((issue) => printIssueTable(issue));
|
|
43
|
+
console.log('');
|
|
44
|
+
});
|
|
34
45
|
|
|
35
|
-
console.log("");
|
|
36
46
|
return 0;
|
|
37
47
|
} catch (error) {
|
|
38
48
|
// Failed to query database
|
|
@@ -8,13 +8,15 @@ import {
|
|
|
8
8
|
getIssueStats,
|
|
9
9
|
getAllIssues,
|
|
10
10
|
} from '../services/issuesService.js';
|
|
11
|
-
import { reportTrackerNotReady } from '../util.js';
|
|
11
|
+
import { hasFlag, renderOutput, reportTrackerNotReady } from '../util.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Main function that runs the status command.
|
|
15
15
|
* @returns {Promise<number>} The exit code: 0 is success, 1 is error.
|
|
16
16
|
*/
|
|
17
|
-
export async function run() {
|
|
17
|
+
export async function run(args = []) {
|
|
18
|
+
const isJson = hasFlag(args, '--json');
|
|
19
|
+
|
|
18
20
|
if (!isTrackerReady()) {
|
|
19
21
|
reportTrackerNotReady();
|
|
20
22
|
return 1;
|
|
@@ -29,27 +31,55 @@ export async function run() {
|
|
|
29
31
|
progress = Math.round((stats.closed / stats.total) * 100);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
console.log(`Total issues: ${stats.total}`);
|
|
35
|
-
console.log(`Open: ${stats.open}`);
|
|
36
|
-
console.log(`In progress: ${stats.inProgress}`);
|
|
37
|
-
console.log(`In review: ${stats.inReview}`);
|
|
38
|
-
console.log(`Closed: ${stats.closed}`);
|
|
39
|
-
console.log(`Overall progress: ${progress}% complete`);
|
|
40
|
-
|
|
41
|
-
if (issues.length > 0) {
|
|
42
|
-
console.log('\nOpen issues by priority:');
|
|
43
|
-
const byPriority = { High: 0, Medium: 0, Low: 0 };
|
|
34
|
+
const byPriority = { High: 0, Medium: 0, Low: 0 };
|
|
35
|
+
if (isJson) {
|
|
44
36
|
for (const issue of issues) {
|
|
45
37
|
if (issue.status === 'Open') {
|
|
46
38
|
byPriority[issue.priority] += 1;
|
|
47
39
|
}
|
|
48
40
|
}
|
|
49
|
-
console.log(` High: ${byPriority.High}`);
|
|
50
|
-
console.log(` Medium: ${byPriority.Medium}`);
|
|
51
|
-
console.log(` Low: ${byPriority.Low}`);
|
|
52
41
|
}
|
|
53
42
|
|
|
43
|
+
const envelope = {
|
|
44
|
+
status: 'success',
|
|
45
|
+
stats: {
|
|
46
|
+
total: stats.total,
|
|
47
|
+
open: stats.open,
|
|
48
|
+
in_progress: stats.inProgress,
|
|
49
|
+
in_review: stats.inReview,
|
|
50
|
+
closed: stats.closed,
|
|
51
|
+
progress_percent: progress,
|
|
52
|
+
},
|
|
53
|
+
open_by_priority: {
|
|
54
|
+
high: byPriority.High,
|
|
55
|
+
medium: byPriority.Medium,
|
|
56
|
+
low: byPriority.Low,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
renderOutput(isJson, envelope, () => {
|
|
61
|
+
console.log('Issue Tracker Status');
|
|
62
|
+
console.log('──────────────────────────────────────────');
|
|
63
|
+
console.log(`Total issues: ${stats.total}`);
|
|
64
|
+
console.log(`Open: ${stats.open}`);
|
|
65
|
+
console.log(`In progress: ${stats.inProgress}`);
|
|
66
|
+
console.log(`In review: ${stats.inReview}`);
|
|
67
|
+
console.log(`Closed: ${stats.closed}`);
|
|
68
|
+
console.log(`Overall progress: ${progress}% complete`);
|
|
69
|
+
|
|
70
|
+
if (issues.length > 0) {
|
|
71
|
+
console.log('\nOpen issues by priority:');
|
|
72
|
+
const byPriority = { High: 0, Medium: 0, Low: 0 };
|
|
73
|
+
for (const issue of issues) {
|
|
74
|
+
if (issue.status === 'Open') {
|
|
75
|
+
byPriority[issue.priority] += 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
console.log(` High: ${byPriority.High}`);
|
|
79
|
+
console.log(` Medium: ${byPriority.Medium}`);
|
|
80
|
+
console.log(` Low: ${byPriority.Low}`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
54
84
|
return 0;
|
|
55
85
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// update.js
|
|
2
2
|
// AI was consulted for some portions of this file.
|
|
3
|
-
// update command allows the user to update data fields for an issue
|
|
3
|
+
// update command allows the user to update data fields for an issue
|
|
4
4
|
// Usage: baton update <id> [options]
|
|
5
|
+
// baton update <id> (launches interactive mode pre-filled with current values)
|
|
5
6
|
//
|
|
6
7
|
// Options:
|
|
7
8
|
// --title <text> New title
|
|
@@ -12,63 +13,252 @@
|
|
|
12
13
|
// -h, --help Show this help
|
|
13
14
|
//
|
|
14
15
|
// Examples:
|
|
15
|
-
//
|
|
16
|
-
//
|
|
16
|
+
// baton update 3 # interactive mode
|
|
17
|
+
// baton update 3 --title "Revised title"
|
|
18
|
+
// baton update 7 --status closed --priority medium
|
|
17
19
|
|
|
18
20
|
import { updateIssue, getIssue } from "../services/issuesService.js";
|
|
19
|
-
import { parseArgs } from
|
|
21
|
+
import { hasFlag, parseArgs, renderOutput, serializeIssue } from "../util.js";
|
|
22
|
+
import { issueSchema } from "../models/schema.js";
|
|
23
|
+
import { input, select, confirm, editor } from "@inquirer/prompts";
|
|
24
|
+
import { spawnSync } from "child_process";
|
|
25
|
+
import { writeFileSync, readFileSync, unlinkSync } from "fs";
|
|
26
|
+
import { tmpdir } from "os";
|
|
27
|
+
import { join } from "path";
|
|
20
28
|
|
|
29
|
+
const ALLOWED_UPDATE_FIELDS = ['title', 'status', 'priority', 'tokenLimit', 'description'];
|
|
30
|
+
|
|
31
|
+
const VALID_FLAGS = new Set([
|
|
32
|
+
...ALLOWED_UPDATE_FIELDS.map(key => issueSchema[key].flag),
|
|
33
|
+
"--json",
|
|
34
|
+
]);
|
|
35
|
+
const FLAGS_HINT = [...VALID_FLAGS].join(", ");
|
|
36
|
+
const USAGE = "Usage: baton update <id> [options]";
|
|
37
|
+
|
|
38
|
+
// Build select choices from issueSchema enums so they stay in sync automatically.
|
|
39
|
+
const PRIORITY_HINTS = {
|
|
40
|
+
Low: "routine work, no urgency",
|
|
41
|
+
Medium: "should be resolved this week",
|
|
42
|
+
High: "blocking or time-sensitive",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const PRIORITY_CHOICES = issueSchema.priority.values.map((v) => ({
|
|
46
|
+
name: `${v.padEnd(6)} -- ${PRIORITY_HINTS[v] ?? v}`,
|
|
47
|
+
value: v,
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
const STATUS_CHOICES = issueSchema.status.values.map((v) => ({
|
|
51
|
+
name: v,
|
|
52
|
+
value: v,
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Opens the user's $EDITOR pre-filled with existing content.
|
|
57
|
+
* Falls back to the inquirer built-in editor widget if $EDITOR is not set.
|
|
58
|
+
* Returns null if the user saves without making any changes.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} existing Current description to pre-fill.
|
|
61
|
+
* @returns {Promise<string|null>}
|
|
62
|
+
*/
|
|
63
|
+
async function openEditorForDescription(existing = "") {
|
|
64
|
+
const editorBin = process.env.EDITOR || process.env.VISUAL;
|
|
65
|
+
|
|
66
|
+
if (!editorBin) {
|
|
67
|
+
const result = await editor({
|
|
68
|
+
message: "Description (save & quit when done):",
|
|
69
|
+
default: existing,
|
|
70
|
+
waitForUseInput: false,
|
|
71
|
+
});
|
|
72
|
+
const cleaned = result.trim();
|
|
73
|
+
return cleaned !== existing.trim() ? cleaned : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const tmpPath = join(tmpdir(), `baton-issue-${Date.now()}.md`);
|
|
77
|
+
writeFileSync(tmpPath, existing, "utf8");
|
|
78
|
+
|
|
79
|
+
const result = spawnSync(editorBin, [tmpPath], { stdio: "inherit" });
|
|
80
|
+
if (result.error) {
|
|
81
|
+
unlinkSync(tmpPath);
|
|
82
|
+
throw new Error(
|
|
83
|
+
`Could not open $EDITOR (${editorBin}): ${result.error.message}`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const saved = readFileSync(tmpPath, "utf8");
|
|
88
|
+
unlinkSync(tmpPath);
|
|
89
|
+
|
|
90
|
+
const cleaned = saved.trim();
|
|
91
|
+
return cleaned !== existing.trim() ? cleaned : null;
|
|
92
|
+
}
|
|
21
93
|
|
|
22
94
|
/**
|
|
23
|
-
*
|
|
95
|
+
* Prompts the user to edit each field of an existing issue.
|
|
96
|
+
* Every prompt is pre-filled with the issue's current value so the user
|
|
97
|
+
* only needs to change what they care about.
|
|
98
|
+
*
|
|
99
|
+
* @param {object} issue The current issue object from the database.
|
|
100
|
+
* @returns {Promise<object>} Partial options object containing only changed fields.
|
|
101
|
+
*/
|
|
102
|
+
async function runInteractiveMode(issue) {
|
|
103
|
+
console.log(`\n Baton -- editing issue #${issue.id}: "${issue.title}"\n`);
|
|
104
|
+
|
|
105
|
+
// Collect all prompt results into one object keyed by schema field name.
|
|
106
|
+
// The diff at the end loops over this -- no field names hardcoded there.
|
|
107
|
+
const results = {};
|
|
108
|
+
|
|
109
|
+
// Title
|
|
110
|
+
results.title = await input({
|
|
111
|
+
message: "Title:",
|
|
112
|
+
default: issue.title,
|
|
113
|
+
validate: (val) => val.trim().length > 0 || "Title cannot be empty.",
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Status
|
|
117
|
+
results.status = await select({
|
|
118
|
+
message: "Status:",
|
|
119
|
+
choices: STATUS_CHOICES,
|
|
120
|
+
default: issue.status,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Priority
|
|
124
|
+
results.priority = await select({
|
|
125
|
+
message: "Priority:",
|
|
126
|
+
choices: PRIORITY_CHOICES,
|
|
127
|
+
default: issue.priority,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Token limit -- confirm-gated since it is optional
|
|
131
|
+
const currentLimit = issue.tokenLimit ?? null;
|
|
132
|
+
const wantsTokenLimit = await confirm({
|
|
133
|
+
message: `Set a token limit?${currentLimit ? ` (currently ${currentLimit})` : ""}`,
|
|
134
|
+
default: currentLimit !== null,
|
|
135
|
+
});
|
|
136
|
+
if (wantsTokenLimit) {
|
|
137
|
+
const raw = await input({
|
|
138
|
+
message: "Token limit (positive integer):",
|
|
139
|
+
default: currentLimit ? String(currentLimit) : undefined,
|
|
140
|
+
validate: (val) => {
|
|
141
|
+
const n = Number(val);
|
|
142
|
+
return (Number.isInteger(n) && n > 0) || "Must be a positive integer.";
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
results.tokenLimit = Number(raw);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Description - $EDITOR flow, keep original if the user makes no changes
|
|
149
|
+
const wantsDescription = await confirm({
|
|
150
|
+
message: "Edit description?",
|
|
151
|
+
default: true,
|
|
152
|
+
});
|
|
153
|
+
if (wantsDescription) {
|
|
154
|
+
const editorBin = process.env.EDITOR || process.env.VISUAL;
|
|
155
|
+
const hint = editorBin ? `opens ${editorBin}` : "in-terminal editor";
|
|
156
|
+
console.log(
|
|
157
|
+
` -> ${hint} -- edit the description, save and quit when done.\n`,
|
|
158
|
+
);
|
|
159
|
+
const edited = await openEditorForDescription(issue.description ?? "");
|
|
160
|
+
// Only write to results if the user actually changed something
|
|
161
|
+
if (edited !== null) results.description = edited;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Diff: loop over results and collect only what changed.
|
|
165
|
+
// Adding a new prompt above is all that is needed -- nothing to update here.
|
|
166
|
+
const pending = Object.fromEntries(
|
|
167
|
+
Object.entries(results).filter(([key, val]) => val !== issue[key]),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
if (Object.keys(pending).length === 0) {
|
|
171
|
+
console.log("\nNo changes made.");
|
|
172
|
+
process.exit(0);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
console.log("\n" + "-".repeat(48));
|
|
176
|
+
for (const [key, val] of Object.entries(pending)) {
|
|
177
|
+
const old = issue[key] ?? "(none)";
|
|
178
|
+
const preview = String(val).split("\n").slice(0, 2).join(" ").slice(0, 60);
|
|
179
|
+
console.log(
|
|
180
|
+
` ${key}: "${old}" -> "${preview}${String(val).length > 60 ? "..." : ""}"`,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
console.log("-".repeat(48) + "\n");
|
|
184
|
+
|
|
185
|
+
const confirmed = await confirm({ message: "Save changes?", default: true });
|
|
186
|
+
if (!confirmed) {
|
|
187
|
+
console.log("Aborted -- no changes saved.");
|
|
188
|
+
process.exit(0);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return pending;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Updates the specified fields for a given issue ID.
|
|
196
|
+
* Drops into interactive mode when only an ID is provided and no field flags follow.
|
|
197
|
+
*
|
|
24
198
|
* @param {string[]} args - The command line arguments
|
|
25
199
|
* @returns {Promise<number>} The exit code: 0 is success, 1 is error.
|
|
26
200
|
*/
|
|
27
201
|
export async function run(args) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
202
|
+
const isJson = hasFlag(args, "--json");
|
|
203
|
+
const cmdArgs = args.filter((arg) => arg !== "--json");
|
|
31
204
|
|
|
32
|
-
|
|
33
|
-
|
|
205
|
+
if (cmdArgs.length === 0 || cmdArgs === "") {
|
|
206
|
+
throw new Error(
|
|
207
|
+
`Invalid input: No arguments entered.\n${USAGE}\nOptions: ${FLAGS_HINT}`,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
34
210
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
211
|
+
// Convert id argument from string to base-10 integer
|
|
212
|
+
const id = parseInt(cmdArgs[0], 10);
|
|
38
213
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
214
|
+
if (isNaN(id)) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`Invalid input: No ID entered.\n${USAGE}\nOptions: ${FLAGS_HINT}`,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Check if user misspelled a flag
|
|
221
|
+
for (const arg of cmdArgs) {
|
|
222
|
+
if (arg.startsWith("--") && !VALID_FLAGS.has(arg)) {
|
|
223
|
+
throw new Error(`Unknown flag: ${arg}\nValid flags: ${FLAGS_HINT}`);
|
|
47
224
|
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
const oldIssue = await getIssue(id);
|
|
48
229
|
|
|
49
|
-
|
|
50
|
-
|
|
230
|
+
// Interactive mode: only the ID was passed, no field flags.
|
|
231
|
+
// Flag mode: at least one flag follows the ID.
|
|
232
|
+
const providedFlags = cmdArgs.slice(1).filter((a) => a.startsWith("--"));
|
|
233
|
+
const isInteractive = providedFlags.length === 0;
|
|
51
234
|
|
|
52
|
-
|
|
53
|
-
|
|
235
|
+
const options = isInteractive
|
|
236
|
+
? await runInteractiveMode(oldIssue)
|
|
237
|
+
: parseArgs(cmdArgs.slice(1));
|
|
54
238
|
|
|
55
|
-
|
|
239
|
+
const newIssue = await updateIssue(id, oldIssue, options);
|
|
240
|
+
const envelope = { status: "success", issue: serializeIssue(newIssue) };
|
|
56
241
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
console.log(` ${key}: No change (already set to "${newIssue[key]}")`);
|
|
66
|
-
}
|
|
242
|
+
renderOutput(isJson, envelope, () => {
|
|
243
|
+
console.log("");
|
|
244
|
+
console.log(`Successfully updated issue #${id}:`);
|
|
245
|
+
for (const key in options) {
|
|
246
|
+
if (oldIssue[key] !== newIssue[key]) {
|
|
247
|
+
console.log(` ${key}: "${oldIssue[key]}" -> "${newIssue[key]}"`);
|
|
248
|
+
} else {
|
|
249
|
+
console.log(` ${key}: No change (already set to "${newIssue[key]}")`);
|
|
67
250
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
251
|
+
}
|
|
252
|
+
console.log("");
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
return 0;
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (error.name === "ExitPromptError") {
|
|
258
|
+
console.log("\nAborted.");
|
|
259
|
+
return 0;
|
|
73
260
|
}
|
|
261
|
+
console.error(`Failed to update issue: ${error.message}`);
|
|
262
|
+
return 1;
|
|
263
|
+
}
|
|
74
264
|
}
|