baton-issue-tracker 1.9.0 → 1.10.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 +1 -1
- package/source/cli.js +5 -0
- package/source/commands/submit.js +76 -0
- package/source/services/issuesService.js +36 -7
package/package.json
CHANGED
package/source/cli.js
CHANGED
|
@@ -29,6 +29,7 @@ import { run as runDelete } from './commands/delete.js';
|
|
|
29
29
|
import { run as runPriority } from './commands/priority.js';
|
|
30
30
|
import { run as runLog } from './commands/log.js';
|
|
31
31
|
import { run as runRegister } from './commands/register.js';
|
|
32
|
+
import { run as runSubmit } from './commands/submit.js';
|
|
32
33
|
|
|
33
34
|
import { authenticateContext } from './services/authService.js';
|
|
34
35
|
|
|
@@ -48,6 +49,7 @@ Commands:
|
|
|
48
49
|
list Lists issues filtered by status and priority
|
|
49
50
|
create Creates an issue with specified fields
|
|
50
51
|
approve Move an issue from in-review to closed
|
|
52
|
+
submit Submit finished work for human review
|
|
51
53
|
priority Set an issue's priority level
|
|
52
54
|
update Updates an issue's specified fields
|
|
53
55
|
delete Deletes an issue
|
|
@@ -79,6 +81,7 @@ Options:
|
|
|
79
81
|
create --token-limit <n> Optional token budget for this issue
|
|
80
82
|
create --json Output as JSON (for AI agents)
|
|
81
83
|
approve <id> [--json]
|
|
84
|
+
submit <id> [--json]
|
|
82
85
|
reject <id> --reason <text> Reject an issue with a given reason
|
|
83
86
|
priority <id> <level> [--json] low | medium | high
|
|
84
87
|
update --title <text> New title
|
|
@@ -107,6 +110,7 @@ Examples:
|
|
|
107
110
|
baton create --title "Fix login bug" --priority high
|
|
108
111
|
baton create --title "Refactor auth" --description "Clean up JWT logic" --token-limit 4000
|
|
109
112
|
baton approve 5
|
|
113
|
+
baton submit 14
|
|
110
114
|
baton priority 5 high
|
|
111
115
|
baton priority 3 low
|
|
112
116
|
baton update 3 --title "Revised title"
|
|
@@ -146,6 +150,7 @@ async function main() {
|
|
|
146
150
|
update: () => runUpdate(args),
|
|
147
151
|
delete: () => runDelete(args),
|
|
148
152
|
log: () => runLog(args),
|
|
153
|
+
submit: () => runSubmit(args),
|
|
149
154
|
};
|
|
150
155
|
|
|
151
156
|
const handler = handlers[command];
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// submit.js
|
|
2
|
+
// AI was consulted to generate the contents of the file. It was then reviewed and edited by a human.
|
|
3
|
+
// Allows an agent to submit "finished" work for human review.
|
|
4
|
+
// The issue must be in the in-progress status to be submitted for review.
|
|
5
|
+
// Usage: baton submit <id> [--json]
|
|
6
|
+
//
|
|
7
|
+
// Options:
|
|
8
|
+
// --json Output as JSON (for AI agents)
|
|
9
|
+
//
|
|
10
|
+
// Examples:
|
|
11
|
+
// baton submit 14
|
|
12
|
+
|
|
13
|
+
import { getIssue, submitForReview } from '../services/issuesService.js';
|
|
14
|
+
import { Status } from '../models/issue.js';
|
|
15
|
+
import {
|
|
16
|
+
hasFlag,
|
|
17
|
+
renderOutput,
|
|
18
|
+
renderError,
|
|
19
|
+
serializeIssue,
|
|
20
|
+
} from '../util.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Submits an in-progress issue for human review.
|
|
24
|
+
* @param {string[]} args - The command line arguments
|
|
25
|
+
* @returns {Promise<number>} The exit code: 0 is success, 1 is error
|
|
26
|
+
*/
|
|
27
|
+
export async function run(args) {
|
|
28
|
+
const isJson = hasFlag(args, '--json');
|
|
29
|
+
|
|
30
|
+
const idArgs = args.filter((arg) => arg !== '--json');
|
|
31
|
+
if (idArgs.length === 0) {
|
|
32
|
+
renderError(isJson, 'Missing issue ID.\nUsage: baton submit <id>', 'MISSING_ID');
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const id = Number(idArgs[0]);
|
|
37
|
+
if (!Number.isInteger(id)) {
|
|
38
|
+
renderError(isJson, `Invalid ID "${idArgs[0]}". ID must be an integer.`, 'INVALID_ID');
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let issue;
|
|
43
|
+
try {
|
|
44
|
+
issue = getIssue(id);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (error.message.includes('not found')) {
|
|
47
|
+
renderError(isJson, error.message, 'NOT_FOUND');
|
|
48
|
+
} else {
|
|
49
|
+
renderError(isJson, error.message);
|
|
50
|
+
}
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (issue.status !== Status.IN_PROGRESS) {
|
|
55
|
+
renderError(
|
|
56
|
+
isJson,
|
|
57
|
+
`Issue #${id} is currently "${issue.status}". Only issues in "${Status.IN_PROGRESS}" can be submitted for review.`,
|
|
58
|
+
'INVALID_STATE',
|
|
59
|
+
);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const updatedIssue = submitForReview(id);
|
|
65
|
+
const envelope = { status: 'success', issue: serializeIssue(updatedIssue) };
|
|
66
|
+
|
|
67
|
+
renderOutput(isJson, envelope, () => {
|
|
68
|
+
console.log(`Success: Issue #${id} submitted for review.`);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return 0;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
renderError(isJson, error.message);
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -33,6 +33,14 @@ function logActivity(db, issueId, action, details = null) {
|
|
|
33
33
|
.run();
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Returns the active actor ID set during authentication.
|
|
38
|
+
* @returns {number|null}
|
|
39
|
+
*/
|
|
40
|
+
export function getActiveActor() {
|
|
41
|
+
return currentActorId;
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
/**
|
|
37
45
|
* Convert a raw database row to an Issue instance.
|
|
38
46
|
* @private
|
|
@@ -280,16 +288,37 @@ export function rejectIssue(id, reason) {
|
|
|
280
288
|
}
|
|
281
289
|
|
|
282
290
|
/**
|
|
283
|
-
* Change the status of an issue to in-review.
|
|
284
|
-
* Logs a
|
|
285
|
-
* @param {number}
|
|
291
|
+
* Change the status of an issue from in-progress to in-review.
|
|
292
|
+
* Logs a state_change event attributed to the current actor.
|
|
293
|
+
* @param {number} issueId
|
|
286
294
|
* @returns {Issue}
|
|
295
|
+
* @throws {Error} If issueId is invalid, issue is not found, or status is not in-progress
|
|
287
296
|
*/
|
|
288
|
-
export function submitForReview(
|
|
297
|
+
export function submitForReview(issueId) {
|
|
298
|
+
if (!Number.isInteger(issueId)) {
|
|
299
|
+
throw new Error('issueId must be an integer');
|
|
300
|
+
}
|
|
301
|
+
|
|
289
302
|
const db = getDB();
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
303
|
+
const existing = findById(db, issueId);
|
|
304
|
+
|
|
305
|
+
if (existing.status !== Status.IN_PROGRESS) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
`Issue #${issueId} is currently "${existing.status}". Only issues in "${Status.IN_PROGRESS}" can be submitted for review.`,
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
db.update(issuesTable)
|
|
312
|
+
.set({ status: Status.IN_REVIEW })
|
|
313
|
+
.where(eq(issuesTable.id, issueId))
|
|
314
|
+
.run();
|
|
315
|
+
logActivity(
|
|
316
|
+
db,
|
|
317
|
+
issueId,
|
|
318
|
+
Action.STATE_CHANGE,
|
|
319
|
+
`Issue #${issueId} was submitted for review.`,
|
|
320
|
+
);
|
|
321
|
+
return getIssue(issueId);
|
|
293
322
|
}
|
|
294
323
|
|
|
295
324
|
/**
|