@gonovus-ai/spec-flow-cli 2.5.1 → 2.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/README.md +16 -3
- package/dist/acceptance-commands.js +20 -2
- package/dist/acceptance-commands.js.map +1 -1
- package/dist/agent-commands.js +2 -0
- package/dist/agent-commands.js.map +1 -1
- package/dist/agent-preference-commands.d.ts +12 -0
- package/dist/agent-preference-commands.js +126 -0
- package/dist/agent-preference-commands.js.map +1 -0
- package/dist/capability-commands.d.ts +3 -0
- package/dist/capability-commands.js +92 -0
- package/dist/capability-commands.js.map +1 -0
- package/dist/cli-command-context.d.ts +31 -0
- package/dist/cli-command-context.js +2 -0
- package/dist/cli-command-context.js.map +1 -0
- package/dist/cli-command-support.d.ts +62 -0
- package/dist/cli-command-support.js +118 -0
- package/dist/cli-command-support.js.map +1 -0
- package/dist/cli.js +68 -3817
- package/dist/cli.js.map +1 -1
- package/dist/global-search-commands.d.ts +4 -0
- package/dist/global-search-commands.js +23 -0
- package/dist/global-search-commands.js.map +1 -0
- package/dist/notification-commands.d.ts +3 -0
- package/dist/notification-commands.js +184 -0
- package/dist/notification-commands.js.map +1 -0
- package/dist/project-commands.d.ts +4 -0
- package/dist/project-commands.js +127 -0
- package/dist/project-commands.js.map +1 -0
- package/dist/proposal-commands.d.ts +3 -0
- package/dist/proposal-commands.js +165 -0
- package/dist/proposal-commands.js.map +1 -0
- package/dist/resource-command-runtime.d.ts +2 -0
- package/dist/runner/orchestrator.js +3 -1
- package/dist/runner/orchestrator.js.map +1 -1
- package/dist/runner/telemetry-bridge.d.ts +13 -1
- package/dist/runner/telemetry-bridge.js +29 -2
- package/dist/runner/telemetry-bridge.js.map +1 -1
- package/dist/runner/types.d.ts +2 -0
- package/dist/runner/workflow.js +6 -0
- package/dist/runner/workflow.js.map +1 -1
- package/dist/spec-commands.d.ts +4 -0
- package/dist/spec-commands.js +347 -0
- package/dist/spec-commands.js.map +1 -0
- package/dist/token-commands.d.ts +3 -0
- package/dist/token-commands.js +79 -0
- package/dist/token-commands.js.map +1 -0
- package/dist/work-item-commands.d.ts +4 -0
- package/dist/work-item-commands.js +978 -0
- package/dist/work-item-commands.js.map +1 -0
- package/dist/work-item-comment-commands.d.ts +4 -0
- package/dist/work-item-comment-commands.js +160 -0
- package/dist/work-item-comment-commands.js.map +1 -0
- package/dist/work-item-custom-field-commands.d.ts +3 -0
- package/dist/work-item-custom-field-commands.js +209 -0
- package/dist/work-item-custom-field-commands.js.map +1 -0
- package/dist/work-item-label-commands.d.ts +3 -0
- package/dist/work-item-label-commands.js +224 -0
- package/dist/work-item-label-commands.js.map +1 -0
- package/dist/work-item-relation-commands.d.ts +4 -0
- package/dist/work-item-relation-commands.js +209 -0
- package/dist/work-item-relation-commands.js.map +1 -0
- package/dist/workflow-column-commands.d.ts +3 -0
- package/dist/workflow-column-commands.js +206 -0
- package/dist/workflow-column-commands.js.map +1 -0
- package/dist/workspace-commands.d.ts +4 -0
- package/dist/workspace-commands.js +299 -0
- package/dist/workspace-commands.js.map +1 -0
- package/dist/workspace-finding-commands.d.ts +4 -0
- package/dist/workspace-finding-commands.js +303 -0
- package/dist/workspace-finding-commands.js.map +1 -0
- package/dist/workspace-glossary-commands.d.ts +4 -0
- package/dist/workspace-glossary-commands.js +121 -0
- package/dist/workspace-glossary-commands.js.map +1 -0
- package/dist/workspace-review-commands.d.ts +4 -0
- package/dist/workspace-review-commands.js +108 -0
- package/dist/workspace-review-commands.js.map +1 -0
- package/guides/acceptance.md +8 -1
- package/guides/agent-sessions.md +34 -0
- package/guides/versions.md +5 -1
- package/guides/work-items.md +26 -2
- package/package.json +1 -1
|
@@ -0,0 +1,978 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { collectOption, invalidArgument, parseOpaqueVersion, parseProjectId, parseSearchLimit, parseStringArray, parseWorkItemId, rejectTokenWrite, withSuccessData, } from "./cli-command-support.js";
|
|
4
|
+
import { formatResourceDiagnostic } from "./cli.js";
|
|
5
|
+
import { itemListOutput, itemOutput } from "./commands/work-item-output.js";
|
|
6
|
+
import { readDescription, singleDescriptionSource } from "./input/text-source.js";
|
|
7
|
+
import { substituteMemberReferences } from "./member-references.js";
|
|
8
|
+
import { writeSkillError } from "./runtime/errors.js";
|
|
9
|
+
import { hasWorkspaceReadToken } from "./runtime/session.js";
|
|
10
|
+
import { resolveProjectVersion } from "./version-commands.js";
|
|
11
|
+
import { readWorkItemImportFile } from "./work-item-exchange-file.js";
|
|
12
|
+
import { moveWithSubtasks, subtaskCascadeHint } from "./work-item-subtask-cascade.js";
|
|
13
|
+
const workItemCompletedFilters = ["all", "pastDay", "pastWeek", "pastMonth", "none"];
|
|
14
|
+
const workItemBulkActions = [
|
|
15
|
+
"updateStatus",
|
|
16
|
+
"updatePriority",
|
|
17
|
+
"updateAssignee",
|
|
18
|
+
"updateAssignedAgent",
|
|
19
|
+
"delete",
|
|
20
|
+
"addLabel",
|
|
21
|
+
"removeLabel",
|
|
22
|
+
"updateDueDate",
|
|
23
|
+
];
|
|
24
|
+
function parseVersionId(value) {
|
|
25
|
+
const normalized = value.trim();
|
|
26
|
+
if (normalized.length > 0 && normalized.length <= 200)
|
|
27
|
+
return normalized;
|
|
28
|
+
throw invalidArgument("--version-id takes a Version id or name, such as v2.4");
|
|
29
|
+
}
|
|
30
|
+
const workItemPriorities = ["no-priority", "low", "medium", "high", "urgent"];
|
|
31
|
+
function parseWorkItemPriority(value) {
|
|
32
|
+
const normalized = value.trim().toLowerCase();
|
|
33
|
+
if (workItemPriorities.includes(normalized)) {
|
|
34
|
+
return normalized;
|
|
35
|
+
}
|
|
36
|
+
throw invalidArgument("Work Item priority must be no-priority, low, medium, high, or urgent");
|
|
37
|
+
}
|
|
38
|
+
function parseWorkItemDate(value) {
|
|
39
|
+
if (z.iso.date().safeParse(value).success || z.iso.datetime().safeParse(value).success) {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
throw invalidArgument("Work Item dates must be an ISO 8601 date or date-time");
|
|
43
|
+
}
|
|
44
|
+
const workItemDueDateFilters = ["dueThisWeek", "dueNextWeek", "noDueDate"];
|
|
45
|
+
const workItemQuerySortFields = [
|
|
46
|
+
"status",
|
|
47
|
+
"startDate",
|
|
48
|
+
"updatedAt",
|
|
49
|
+
"assignee",
|
|
50
|
+
"createdAt",
|
|
51
|
+
"dueDate",
|
|
52
|
+
"number",
|
|
53
|
+
"position",
|
|
54
|
+
"priority",
|
|
55
|
+
"title",
|
|
56
|
+
];
|
|
57
|
+
const workItemSortOrders = ["asc", "desc"];
|
|
58
|
+
function parseWorkItemDueFilter(value) {
|
|
59
|
+
if (workItemDueDateFilters.includes(value)) {
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
throw invalidArgument("Due filter must be dueThisWeek, dueNextWeek, or noDueDate");
|
|
63
|
+
}
|
|
64
|
+
function parseWorkItemSortField(value) {
|
|
65
|
+
if (workItemQuerySortFields.includes(value)) {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
throw invalidArgument("Work Item sort must be createdAt, dueDate, number, position, priority, or title");
|
|
69
|
+
}
|
|
70
|
+
function parseWorkItemSortOrder(value) {
|
|
71
|
+
if (workItemSortOrders.includes(value)) {
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
throw invalidArgument("Work Item sort order must be asc or desc");
|
|
75
|
+
}
|
|
76
|
+
/** The member-filter values of a selection that may name Members by Alias or name. */
|
|
77
|
+
function selectionMemberReferences(options) {
|
|
78
|
+
return {
|
|
79
|
+
projectId: options.projectId,
|
|
80
|
+
values: [...options.assignee, ...(options.creator ?? []), ...options.watcher],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function withResolvedMembers(options, members) {
|
|
84
|
+
if (members === undefined || members.size === 0)
|
|
85
|
+
return options;
|
|
86
|
+
return {
|
|
87
|
+
...options,
|
|
88
|
+
assignee: substituteMemberReferences(options.assignee, members),
|
|
89
|
+
...(options.creator === undefined
|
|
90
|
+
? {}
|
|
91
|
+
: { creator: substituteMemberReferences(options.creator, members) }),
|
|
92
|
+
watcher: substituteMemberReferences(options.watcher, members),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Builds the wire selection query shared by `work-item list` and
|
|
97
|
+
* `work-item board`: repeatable flags become the API's CSV fields and
|
|
98
|
+
* repeated `fieldId=value` pairs merge into the `customFields` JSON map.
|
|
99
|
+
*/
|
|
100
|
+
function workItemSelectionQuery(options) {
|
|
101
|
+
const customFields = {};
|
|
102
|
+
for (const entry of options.customField) {
|
|
103
|
+
const { fieldId, value } = parseCustomFieldAssignment(entry);
|
|
104
|
+
customFields[fieldId] = [...(customFields[fieldId] ?? []), value];
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
...(options.creator === undefined || options.creator.length === 0
|
|
108
|
+
? {}
|
|
109
|
+
: { creator: options.creator.join(",") }),
|
|
110
|
+
...Object.fromEntries(["operators", "created", "updated", "relations", "specs", "pullRequests"].flatMap((key) => (options[key] === undefined ? [] : [[key, options[key]]]))),
|
|
111
|
+
...(options.assignee.length === 0 ? {} : { assignee: options.assignee.join(",") }),
|
|
112
|
+
...(options.assignedAgent.length === 0
|
|
113
|
+
? {}
|
|
114
|
+
: { assignedAgent: options.assignedAgent.join(",") }),
|
|
115
|
+
...(options.watcher.length === 0 ? {} : { watcher: options.watcher.join(",") }),
|
|
116
|
+
...(Object.keys(customFields).length === 0
|
|
117
|
+
? {}
|
|
118
|
+
: { customFields: JSON.stringify(customFields) }),
|
|
119
|
+
...(options.due.length === 0 ? {} : { due: options.due.join(",") }),
|
|
120
|
+
...(options.dueAfter === undefined ? {} : { dueAfter: options.dueAfter }),
|
|
121
|
+
...(options.dueBefore === undefined ? {} : { dueBefore: options.dueBefore }),
|
|
122
|
+
...(options.label.length === 0 ? {} : { label: options.label.join(",") }),
|
|
123
|
+
...(options.priority.length === 0 ? {} : { priority: options.priority.join(",") }),
|
|
124
|
+
...(options.repositoryConnectionId === undefined
|
|
125
|
+
? {}
|
|
126
|
+
: { repositoryConnectionId: options.repositoryConnectionId }),
|
|
127
|
+
...(options.search === undefined ? {} : { search: options.search }),
|
|
128
|
+
...(options.sort === undefined ? {} : { sortBy: options.sort }),
|
|
129
|
+
...(options.order === undefined ? {} : { sortOrder: options.order }),
|
|
130
|
+
...(options.startAfter === undefined ? {} : { startAfter: options.startAfter }),
|
|
131
|
+
...(options.startBefore === undefined ? {} : { startBefore: options.startBefore }),
|
|
132
|
+
...(options.status.length === 0 ? {} : { status: options.status.join(",") }),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/** List and board only: which completed Work Items to keep. */
|
|
136
|
+
function workItemCompletedFlag(command) {
|
|
137
|
+
return command.option("--completed <filter>", "Completed Work Items to keep: all (default), pastDay, pastWeek, pastMonth, or none", (value) => {
|
|
138
|
+
if (workItemCompletedFilters.includes(value))
|
|
139
|
+
return value;
|
|
140
|
+
throw invalidArgument(`Completed filter must be ${workItemCompletedFilters.join(", ")}`);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The selection options `work-item list` and `work-item board` share.
|
|
145
|
+
* Attach with `workItemSelectionFlags(command)`.
|
|
146
|
+
*/
|
|
147
|
+
function workItemSelectionFlags(command) {
|
|
148
|
+
return command
|
|
149
|
+
.option("--creator <id>", "Creator User ID, me, or an exact Member Alias or name; repeat for several", collectOption, [])
|
|
150
|
+
.option("--operators <json>", "Category -> include|exclude; custom fields use customField:<id>")
|
|
151
|
+
.option("--created <filter>", "today|pastWeek|past2Weeks|pastMonth|past3Months or YYYY-MM-DD (UTC inclusive)")
|
|
152
|
+
.option("--updated <filter>", "Same time choices as --created")
|
|
153
|
+
.option("--relations <csv>", "blocked,blocking,hasParent,hasChildren,related")
|
|
154
|
+
.option("--specs <csv>", "Linked Spec IDs, or none")
|
|
155
|
+
.option("--pull-requests <csv>", "none,draft,open,merged,closed; synchronized state only")
|
|
156
|
+
.option("--assignee <assignee>", "Filter by assignee User ID, me, unassigned, or an exact Member Alias or name; repeat for several", collectOption, [])
|
|
157
|
+
.option("--assigned-agent <agentId>", "Filter by executing Agent ID or unassigned; repeat for several", collectOption, [])
|
|
158
|
+
.option("--watcher <userId>", "Filter by watcher User ID, me, or an exact Member Alias or name; repeat for several", collectOption, [])
|
|
159
|
+
.option("--custom-field <fieldId=value>", "Filter by Custom Field value; repeat to OR values or combine fields", collectOption, [])
|
|
160
|
+
.option("--due <filter>", "Filter by due bucket: dueThisWeek, dueNextWeek, or noDueDate; repeat for several", (value, previous) => [
|
|
161
|
+
...previous,
|
|
162
|
+
parseWorkItemDueFilter(value),
|
|
163
|
+
], [])
|
|
164
|
+
.option("--due-after <date>", "Filter due on/after", parseWorkItemDate)
|
|
165
|
+
.option("--due-before <date>", "Filter due on/before", parseWorkItemDate)
|
|
166
|
+
.option("--label <labelId>", "Filter by Work Item Label ID; repeat for several", collectOption, [])
|
|
167
|
+
.option("--priority <priority>", "Filter by priority; repeat for several", (value, previous) => [...previous, parseWorkItemPriority(value)], [])
|
|
168
|
+
.option("--repository-connection-id <id>", "Filter by an explicit GitHub repository connection")
|
|
169
|
+
.option("--search <search>", "Filter by title search text")
|
|
170
|
+
.option("--sort <field>", "Sort by field", parseWorkItemSortField)
|
|
171
|
+
.option("--order <order>", "Sort order", parseWorkItemSortOrder)
|
|
172
|
+
.option("--start-after <date>", "Filter start on/after", parseWorkItemDate)
|
|
173
|
+
.option("--start-before <date>", "Filter start on/before", parseWorkItemDate)
|
|
174
|
+
.option("--status <status>", "Filter by Workflow Column slug or virtual status; repeat for several", collectOption, []);
|
|
175
|
+
}
|
|
176
|
+
function parseWorkItemBulkAction(value) {
|
|
177
|
+
if (workItemBulkActions.includes(value)) {
|
|
178
|
+
return value;
|
|
179
|
+
}
|
|
180
|
+
throw invalidArgument(`Bulk action must be ${workItemBulkActions.join(", ")}`);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Targets default to the route Project; an explicit `projectId/` selects
|
|
184
|
+
* another owner without inferring Project identity from Workspace numbering.
|
|
185
|
+
*/
|
|
186
|
+
function parseWorkItemBulkTarget(value, previous) {
|
|
187
|
+
const [identity, version, extra] = value.split("@");
|
|
188
|
+
const segments = identity?.split("/") ?? [];
|
|
189
|
+
const id = segments.length === 2 ? segments[1] : segments[0];
|
|
190
|
+
const projectId = segments.length === 2 ? parseProjectId(segments[0] ?? "") : undefined;
|
|
191
|
+
if (segments.length > 2 ||
|
|
192
|
+
id === undefined ||
|
|
193
|
+
version === undefined ||
|
|
194
|
+
extra !== undefined ||
|
|
195
|
+
!/^[A-Z]{2,10}-[1-9]\d*$/u.test(id.trim().toUpperCase()) ||
|
|
196
|
+
!/^[1-9]\d*$/u.test(version)) {
|
|
197
|
+
throw invalidArgument(`Bulk target "${value}" must be a WORK-ITEM-ID@version pair`);
|
|
198
|
+
}
|
|
199
|
+
const numericVersion = Number(version);
|
|
200
|
+
if (!Number.isSafeInteger(numericVersion) || numericVersion > 2_147_483_647) {
|
|
201
|
+
throw invalidArgument(`Bulk target "${value}" has a version outside the supported range`);
|
|
202
|
+
}
|
|
203
|
+
return [
|
|
204
|
+
...previous,
|
|
205
|
+
{
|
|
206
|
+
expectedVersion: `"${version}"`,
|
|
207
|
+
id: id.trim().toUpperCase(),
|
|
208
|
+
...(projectId === undefined ? {} : { projectId }),
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
}
|
|
212
|
+
function parseBoardPosition(value) {
|
|
213
|
+
const position = Number(value);
|
|
214
|
+
if (!Number.isInteger(position) || position < 0 || position > 2_147_483_646) {
|
|
215
|
+
throw invalidArgument("Board position must be a nonnegative integer within the supported range");
|
|
216
|
+
}
|
|
217
|
+
return position;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* A `fieldId=value` assignment splits on the first `=` so values may carry
|
|
221
|
+
* the separator; the field id itself is an opaque server identity.
|
|
222
|
+
*/
|
|
223
|
+
function parseCustomFieldAssignment(value) {
|
|
224
|
+
const separator = value.indexOf("=");
|
|
225
|
+
const fieldId = separator === -1 ? "" : value.slice(0, separator).trim();
|
|
226
|
+
if (fieldId.length === 0 || fieldId.length > 200) {
|
|
227
|
+
throw invalidArgument("Custom Field values must be written as fieldId=value");
|
|
228
|
+
}
|
|
229
|
+
const fieldValue = value.slice(separator + 1);
|
|
230
|
+
if (fieldValue.length > 2_000) {
|
|
231
|
+
throw invalidArgument("Custom Field values must stay within the supported length");
|
|
232
|
+
}
|
|
233
|
+
return { fieldId, value: fieldValue };
|
|
234
|
+
}
|
|
235
|
+
/** Registers work Item list, read, create, update, assignment, bulk, import, transfer, move, archive and completion. */
|
|
236
|
+
export function registerWorkItemCommands(context, workItem) {
|
|
237
|
+
const { dependencies, run, setExitCode, outputMode, warnMissingUrl } = context;
|
|
238
|
+
workItemCompletedFlag(workItemSelectionFlags(workItem.command("list")))
|
|
239
|
+
.requiredOption("--project-id <projectId>")
|
|
240
|
+
.option("--limit <limit>", "Maximum results", parseSearchLimit, 20)
|
|
241
|
+
.option("--cursor <cursor>")
|
|
242
|
+
.option("--group-by <field>", "Group the page by field (status)", (value) => {
|
|
243
|
+
if (value === "status") {
|
|
244
|
+
return "status";
|
|
245
|
+
}
|
|
246
|
+
throw invalidArgument("Work Items can only be grouped by status");
|
|
247
|
+
})
|
|
248
|
+
.action(async (options) => {
|
|
249
|
+
setExitCode(await run((client, _me, _credentialKind, members) => client.GET("/v1/projects/{projectId}/work-items", {
|
|
250
|
+
params: {
|
|
251
|
+
path: { projectId: options.projectId },
|
|
252
|
+
query: {
|
|
253
|
+
...workItemSelectionQuery(withResolvedMembers(options, members)),
|
|
254
|
+
...(options.completed === undefined ? {} : { completed: options.completed }),
|
|
255
|
+
...(options.cursor === undefined ? {} : { cursor: options.cursor }),
|
|
256
|
+
...(options.groupBy === undefined ? {} : { groupBy: options.groupBy }),
|
|
257
|
+
limit: options.limit,
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
}), {
|
|
261
|
+
memberReferences: selectionMemberReferences(options),
|
|
262
|
+
project: (data) => itemListOutput(data, outputMode(), warnMissingUrl),
|
|
263
|
+
}));
|
|
264
|
+
});
|
|
265
|
+
workItem
|
|
266
|
+
.command("read")
|
|
267
|
+
.requiredOption("--project-id <projectId>")
|
|
268
|
+
.requiredOption("--work-item-id <workItemId>")
|
|
269
|
+
.action(async (options) => {
|
|
270
|
+
setExitCode(await run((client) => client.GET("/v1/projects/{projectId}/work-items/{workItemId}", {
|
|
271
|
+
params: { path: options },
|
|
272
|
+
}), { project: (data) => itemOutput(data, outputMode(), warnMissingUrl) }));
|
|
273
|
+
});
|
|
274
|
+
workItem
|
|
275
|
+
.command("assignees")
|
|
276
|
+
.requiredOption("--project-id <projectId>")
|
|
277
|
+
.action(async (options) => {
|
|
278
|
+
setExitCode(await run((client) => client.GET("/v1/projects/{projectId}/work-item-assignees", {
|
|
279
|
+
params: { path: options },
|
|
280
|
+
})));
|
|
281
|
+
});
|
|
282
|
+
workItem
|
|
283
|
+
.command("agents")
|
|
284
|
+
.description("List active Agents granted to this Project")
|
|
285
|
+
.requiredOption("--project-id <projectId>")
|
|
286
|
+
.action(async (options) => {
|
|
287
|
+
setExitCode(await run((client) => client.GET("/v1/projects/{projectId}/agents", {
|
|
288
|
+
params: { path: options },
|
|
289
|
+
}), { rejectWorkspaceReadToken: true }));
|
|
290
|
+
});
|
|
291
|
+
workItem
|
|
292
|
+
.command("create")
|
|
293
|
+
.requiredOption("--project-id <projectId>")
|
|
294
|
+
.requiredOption("--title <title>")
|
|
295
|
+
.option("--description <description>", "Inline description text", singleDescriptionSource)
|
|
296
|
+
.option("--description-file <path>", "Read description from a UTF-8 regular file, or - for piped stdin", singleDescriptionSource)
|
|
297
|
+
.option("--label <labelId>", "Workspace label definition ID; repeat for several labels", collectOption, [])
|
|
298
|
+
.option("--assignee <assignee>", "Workspace member User ID, me for the selected credential, or an exact Member Alias or name")
|
|
299
|
+
.option("--assigned-agent <agentId>", "Eligible Workspace Agent ID to assign for execution")
|
|
300
|
+
.option("--custom-field <fieldId=value>", "Custom Field value as fieldId=value; repeat for several fields", collectOption, [])
|
|
301
|
+
.option("--priority <priority>", "Work Item priority", parseWorkItemPriority)
|
|
302
|
+
.option("--start-date <startDate>", "ISO 8601 date", parseWorkItemDate)
|
|
303
|
+
.option("--due-date <dueDate>", "ISO 8601 date", parseWorkItemDate)
|
|
304
|
+
.option("--status <status>", "Workflow Column slug or virtual status to create the Work Item in")
|
|
305
|
+
.option("--relation-direction <direction>", "Create one relation atomically: related, subtask, parent, blocks or blocked-by", (value) => {
|
|
306
|
+
const result = z
|
|
307
|
+
.enum(["related", "subtask", "parent", "blocks", "blocked-by"])
|
|
308
|
+
.safeParse(value);
|
|
309
|
+
if (!result.success)
|
|
310
|
+
throw invalidArgument("Invalid relation direction");
|
|
311
|
+
return result.data;
|
|
312
|
+
})
|
|
313
|
+
.option("--relation-target-project-id <projectId>", "Project containing the related task")
|
|
314
|
+
.option("--relation-target-work-item-id <workItemId>", "Public identity of the related task", parseWorkItemId)
|
|
315
|
+
.option("--replace-parent", "Replace an existing parent when creating a subtask relation")
|
|
316
|
+
.option("--initial-watcher-ids <json>", "Initial watcher User IDs as a JSON array; [] explicitly mutes the creator", (value) => parseStringArray(value, "initial-watcher-ids"))
|
|
317
|
+
.option("--version-id <versionId>", "Plan the Work Item in this unsealed Version: its id or name, such as v2.4", parseVersionId)
|
|
318
|
+
.option("--without-version", "Keep the Work Item out of any Version, including the parent's Version a new subtask joins by default")
|
|
319
|
+
.action(async (options) => {
|
|
320
|
+
if (options.withoutVersion === true && options.versionId !== undefined)
|
|
321
|
+
throw invalidArgument("Work Item create cannot set a Version and --without-version together");
|
|
322
|
+
const description = (await readDescription(options)) ?? undefined;
|
|
323
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
324
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const relationFlags = [
|
|
328
|
+
options.relationDirection,
|
|
329
|
+
options.relationTargetProjectId,
|
|
330
|
+
options.relationTargetWorkItemId,
|
|
331
|
+
];
|
|
332
|
+
if (relationFlags.some((value) => value !== undefined) &&
|
|
333
|
+
relationFlags.some((value) => value === undefined))
|
|
334
|
+
throw invalidArgument("Atomic relation creation requires --relation-direction, --relation-target-project-id and --relation-target-work-item-id together");
|
|
335
|
+
const relation = options.relationDirection === undefined
|
|
336
|
+
? undefined
|
|
337
|
+
: options.relationTargetProjectId === undefined ||
|
|
338
|
+
options.relationTargetWorkItemId === undefined
|
|
339
|
+
? (() => {
|
|
340
|
+
throw invalidArgument("Atomic relation creation requires a relation target");
|
|
341
|
+
})()
|
|
342
|
+
: {
|
|
343
|
+
direction: options.relationDirection,
|
|
344
|
+
targetProjectId: options.relationTargetProjectId,
|
|
345
|
+
targetWorkItemId: options.relationTargetWorkItemId,
|
|
346
|
+
...(options.replaceParent === undefined
|
|
347
|
+
? {}
|
|
348
|
+
: { replaceParent: options.replaceParent }),
|
|
349
|
+
};
|
|
350
|
+
const customFields = options.customField.map(parseCustomFieldAssignment);
|
|
351
|
+
const idempotencyKey = randomUUID();
|
|
352
|
+
setExitCode(await run(async (client, me, _credentialKind, members) => {
|
|
353
|
+
const plannedVersion = options.versionId === undefined
|
|
354
|
+
? undefined
|
|
355
|
+
: await resolveProjectVersion(client, options.projectId, options.versionId);
|
|
356
|
+
if (plannedVersion !== undefined && "failure" in plannedVersion)
|
|
357
|
+
return plannedVersion.failure;
|
|
358
|
+
return await client.POST("/v1/projects/{projectId}/work-items", {
|
|
359
|
+
body: {
|
|
360
|
+
...(options.assignee === undefined
|
|
361
|
+
? {}
|
|
362
|
+
: { assigneeId: me ?? members?.get(options.assignee) ?? options.assignee }),
|
|
363
|
+
...(options.assignedAgent === undefined
|
|
364
|
+
? {}
|
|
365
|
+
: { assignedAgentId: options.assignedAgent }),
|
|
366
|
+
...(options.customField.length === 0
|
|
367
|
+
? {}
|
|
368
|
+
: {
|
|
369
|
+
customFields,
|
|
370
|
+
}),
|
|
371
|
+
...(description === undefined ? {} : { description }),
|
|
372
|
+
...(options.label.length === 0 ? {} : { labelIds: [...new Set(options.label)] }),
|
|
373
|
+
...(options.initialWatcherIds === undefined
|
|
374
|
+
? {}
|
|
375
|
+
: { initialWatcherIds: options.initialWatcherIds }),
|
|
376
|
+
...(options.dueDate === undefined ? {} : { dueDate: options.dueDate }),
|
|
377
|
+
...(options.priority === undefined ? {} : { priority: options.priority }),
|
|
378
|
+
...(options.startDate === undefined ? {} : { startDate: options.startDate }),
|
|
379
|
+
...(options.status === undefined ? {} : { status: options.status }),
|
|
380
|
+
...(relation === undefined ? {} : { relation }),
|
|
381
|
+
title: options.title,
|
|
382
|
+
...(plannedVersion === undefined ? {} : { versionId: plannedVersion.id }),
|
|
383
|
+
...(options.withoutVersion === true ? { versionId: null } : {}),
|
|
384
|
+
},
|
|
385
|
+
params: {
|
|
386
|
+
header: { "idempotency-key": idempotencyKey },
|
|
387
|
+
path: { projectId: options.projectId },
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
}, {
|
|
391
|
+
resolveMe: options.assignee === "me",
|
|
392
|
+
...(options.assignee === undefined
|
|
393
|
+
? {}
|
|
394
|
+
: {
|
|
395
|
+
memberReferences: { projectId: options.projectId, values: [options.assignee] },
|
|
396
|
+
}),
|
|
397
|
+
project: (data) => itemOutput(data, outputMode(), warnMissingUrl),
|
|
398
|
+
ambiguousOutcomeMessage: "Work Item creation outcome is unknown; list Work Items before retrying",
|
|
399
|
+
retryTransportOnce: true,
|
|
400
|
+
}));
|
|
401
|
+
});
|
|
402
|
+
workItem
|
|
403
|
+
.command("update")
|
|
404
|
+
.requiredOption("--project-id <projectId>")
|
|
405
|
+
.requiredOption("--work-item-id <workItemId>")
|
|
406
|
+
.requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
|
|
407
|
+
.option("--title <title>")
|
|
408
|
+
.option("--description <description>", "Inline description text", singleDescriptionSource)
|
|
409
|
+
.option("--description-file <path>", "Read description from a UTF-8 regular file, or - for piped stdin", singleDescriptionSource)
|
|
410
|
+
.option("--clear-description", "Remove the Work Item description")
|
|
411
|
+
.option("--priority <priority>", "Work Item priority", parseWorkItemPriority)
|
|
412
|
+
.option("--start-date <startDate>", "ISO 8601 date", parseWorkItemDate)
|
|
413
|
+
.option("--due-date <dueDate>", "ISO 8601 date", parseWorkItemDate)
|
|
414
|
+
.option("--clear-start-date", "Remove the Work Item start date")
|
|
415
|
+
.option("--clear-due-date", "Remove the Work Item due date")
|
|
416
|
+
.option("--version-id <versionId>", "Move the Work Item into this unsealed Version: its id or name, such as v2.4", parseVersionId)
|
|
417
|
+
.option("--clear-version", "Take the Work Item out of its Version")
|
|
418
|
+
.action(async (options) => {
|
|
419
|
+
const description = (await readDescription(options)) ?? undefined;
|
|
420
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
421
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (options.title === undefined &&
|
|
425
|
+
description === undefined &&
|
|
426
|
+
options.clearDescription !== true &&
|
|
427
|
+
options.priority === undefined &&
|
|
428
|
+
options.startDate === undefined &&
|
|
429
|
+
options.dueDate === undefined &&
|
|
430
|
+
options.clearStartDate !== true &&
|
|
431
|
+
options.clearDueDate !== true &&
|
|
432
|
+
options.versionId === undefined &&
|
|
433
|
+
options.clearVersion !== true) {
|
|
434
|
+
throw invalidArgument("Work Item update requires a field change");
|
|
435
|
+
}
|
|
436
|
+
if (options.clearVersion === true && options.versionId !== undefined) {
|
|
437
|
+
throw invalidArgument("Work Item update cannot set and clear the Version together");
|
|
438
|
+
}
|
|
439
|
+
if (options.clearStartDate === true && options.startDate !== undefined) {
|
|
440
|
+
throw invalidArgument("Work Item update cannot set and clear the start date together");
|
|
441
|
+
}
|
|
442
|
+
if (options.clearDueDate === true && options.dueDate !== undefined) {
|
|
443
|
+
throw invalidArgument("Work Item update cannot set and clear the due date together");
|
|
444
|
+
}
|
|
445
|
+
const idempotencyKey = randomUUID();
|
|
446
|
+
setExitCode(await run(async (client) => {
|
|
447
|
+
const plannedVersion = options.versionId === undefined
|
|
448
|
+
? undefined
|
|
449
|
+
: await resolveProjectVersion(client, options.projectId, options.versionId);
|
|
450
|
+
if (plannedVersion !== undefined && "failure" in plannedVersion)
|
|
451
|
+
return plannedVersion.failure;
|
|
452
|
+
return await client.PATCH("/v1/projects/{projectId}/work-items/{workItemId}", {
|
|
453
|
+
body: {
|
|
454
|
+
...(options.clearDescription === true
|
|
455
|
+
? { description: null }
|
|
456
|
+
: description === undefined
|
|
457
|
+
? {}
|
|
458
|
+
: { description }),
|
|
459
|
+
...(options.clearDueDate === true
|
|
460
|
+
? { dueDate: null }
|
|
461
|
+
: options.dueDate === undefined
|
|
462
|
+
? {}
|
|
463
|
+
: { dueDate: options.dueDate }),
|
|
464
|
+
...(options.clearStartDate === true
|
|
465
|
+
? { startDate: null }
|
|
466
|
+
: options.startDate === undefined
|
|
467
|
+
? {}
|
|
468
|
+
: { startDate: options.startDate }),
|
|
469
|
+
...(options.priority === undefined ? {} : { priority: options.priority }),
|
|
470
|
+
...(options.title === undefined ? {} : { title: options.title }),
|
|
471
|
+
...(options.clearVersion === true
|
|
472
|
+
? { versionId: null }
|
|
473
|
+
: plannedVersion === undefined
|
|
474
|
+
? {}
|
|
475
|
+
: { versionId: plannedVersion.id }),
|
|
476
|
+
},
|
|
477
|
+
params: {
|
|
478
|
+
header: {
|
|
479
|
+
"idempotency-key": idempotencyKey,
|
|
480
|
+
"if-match": options.expectedVersion,
|
|
481
|
+
},
|
|
482
|
+
path: {
|
|
483
|
+
projectId: options.projectId,
|
|
484
|
+
workItemId: options.workItemId,
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
});
|
|
488
|
+
}, {
|
|
489
|
+
project: (data) => itemOutput(data, outputMode(), warnMissingUrl),
|
|
490
|
+
ambiguousOutcomeMessage: "Work Item update outcome is unknown; read the Work Item before retrying",
|
|
491
|
+
retryTransportOnce: true,
|
|
492
|
+
}));
|
|
493
|
+
});
|
|
494
|
+
workItem
|
|
495
|
+
.command("assign")
|
|
496
|
+
.requiredOption("--project-id <projectId>")
|
|
497
|
+
.requiredOption("--work-item-id <workItemId>")
|
|
498
|
+
.requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
|
|
499
|
+
.option("--assignee <assignee>", "Workspace member User ID, me for the selected credential, or an exact Member Alias or name")
|
|
500
|
+
.option("--unassign", "Remove the Work Item assignee")
|
|
501
|
+
.action(async (options) => {
|
|
502
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
503
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (options.assignee === undefined && options.unassign !== true) {
|
|
507
|
+
throw invalidArgument("Work Item assign requires an assignee or --unassign");
|
|
508
|
+
}
|
|
509
|
+
if (options.assignee !== undefined && options.unassign === true) {
|
|
510
|
+
throw invalidArgument("Work Item assign cannot set and clear the assignee together");
|
|
511
|
+
}
|
|
512
|
+
const idempotencyKey = randomUUID();
|
|
513
|
+
setExitCode(await run((client, me, _credentialKind, members) => client.PUT("/v1/projects/{projectId}/work-items/{workItemId}/assignee", {
|
|
514
|
+
body: {
|
|
515
|
+
assigneeId: options.unassign === true
|
|
516
|
+
? null
|
|
517
|
+
: (me ??
|
|
518
|
+
(options.assignee === undefined
|
|
519
|
+
? null
|
|
520
|
+
: (members?.get(options.assignee) ?? options.assignee))),
|
|
521
|
+
},
|
|
522
|
+
params: {
|
|
523
|
+
header: {
|
|
524
|
+
"idempotency-key": idempotencyKey,
|
|
525
|
+
"if-match": options.expectedVersion,
|
|
526
|
+
},
|
|
527
|
+
path: {
|
|
528
|
+
projectId: options.projectId,
|
|
529
|
+
workItemId: options.workItemId,
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
}), {
|
|
533
|
+
resolveMe: options.assignee === "me",
|
|
534
|
+
...(options.assignee === undefined || options.unassign === true
|
|
535
|
+
? {}
|
|
536
|
+
: {
|
|
537
|
+
memberReferences: { projectId: options.projectId, values: [options.assignee] },
|
|
538
|
+
}),
|
|
539
|
+
project: (data) => itemOutput(data, outputMode(), warnMissingUrl),
|
|
540
|
+
ambiguousOutcomeMessage: "Work Item assignment outcome is unknown; read the Work Item before retrying",
|
|
541
|
+
retryTransportOnce: true,
|
|
542
|
+
}));
|
|
543
|
+
});
|
|
544
|
+
workItem
|
|
545
|
+
.command("assign-agent")
|
|
546
|
+
.description("Assign or clear the executing Workspace Agent for a Work Item")
|
|
547
|
+
.requiredOption("--project-id <projectId>")
|
|
548
|
+
.requiredOption("--work-item-id <workItemId>")
|
|
549
|
+
.requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
|
|
550
|
+
.option("--agent-id <agentId>", "Eligible Workspace Agent ID to assign")
|
|
551
|
+
.option("--clear", "Clear the executing Agent")
|
|
552
|
+
.action(async (options) => {
|
|
553
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
554
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (options.agentId === undefined && options.clear !== true) {
|
|
558
|
+
throw invalidArgument("Work Item assign-agent requires --agent-id or --clear");
|
|
559
|
+
}
|
|
560
|
+
if (options.agentId !== undefined && options.clear === true) {
|
|
561
|
+
throw invalidArgument("Work Item assign-agent cannot combine --agent-id and --clear");
|
|
562
|
+
}
|
|
563
|
+
const idempotencyKey = randomUUID();
|
|
564
|
+
setExitCode(await run((client) => client.PUT("/v1/projects/{projectId}/work-items/{workItemId}/assigned-agent", {
|
|
565
|
+
body: {
|
|
566
|
+
assignedAgentId: options.clear === true ? null : (options.agentId ?? null),
|
|
567
|
+
},
|
|
568
|
+
params: {
|
|
569
|
+
header: {
|
|
570
|
+
"idempotency-key": idempotencyKey,
|
|
571
|
+
"if-match": options.expectedVersion,
|
|
572
|
+
},
|
|
573
|
+
path: {
|
|
574
|
+
projectId: options.projectId,
|
|
575
|
+
workItemId: options.workItemId,
|
|
576
|
+
},
|
|
577
|
+
},
|
|
578
|
+
}), {
|
|
579
|
+
project: (data) => itemOutput(data, outputMode(), warnMissingUrl),
|
|
580
|
+
ambiguousOutcomeMessage: "Work Item Agent assignment outcome is unknown; read the Work Item before retrying",
|
|
581
|
+
retryTransportOnce: true,
|
|
582
|
+
}));
|
|
583
|
+
});
|
|
584
|
+
workItem
|
|
585
|
+
.command("delete")
|
|
586
|
+
.requiredOption("--project-id <projectId>")
|
|
587
|
+
.requiredOption("--work-item-id <workItemId>")
|
|
588
|
+
.requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
|
|
589
|
+
.action(async (options) => {
|
|
590
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
591
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const idempotencyKey = randomUUID();
|
|
595
|
+
setExitCode(await run(async (client) => withSuccessData(await client.DELETE("/v1/projects/{projectId}/work-items/{workItemId}", {
|
|
596
|
+
params: {
|
|
597
|
+
header: {
|
|
598
|
+
"idempotency-key": idempotencyKey,
|
|
599
|
+
"if-match": options.expectedVersion,
|
|
600
|
+
},
|
|
601
|
+
path: {
|
|
602
|
+
projectId: options.projectId,
|
|
603
|
+
workItemId: options.workItemId,
|
|
604
|
+
},
|
|
605
|
+
},
|
|
606
|
+
}), { deleted: { workItemId: options.workItemId } }), {
|
|
607
|
+
ambiguousOutcomeMessage: "Work Item deletion outcome is unknown; list Work Items before retrying",
|
|
608
|
+
retryTransportOnce: true,
|
|
609
|
+
}));
|
|
610
|
+
});
|
|
611
|
+
workItemCompletedFlag(workItemSelectionFlags(workItem.command("board")))
|
|
612
|
+
.requiredOption("--project-id <projectId>")
|
|
613
|
+
.action(async (options) => {
|
|
614
|
+
setExitCode(await run((client, _me, _credentialKind, members) => client.GET("/v1/projects/{projectId}/work-item-board", {
|
|
615
|
+
params: {
|
|
616
|
+
path: { projectId: options.projectId },
|
|
617
|
+
query: {
|
|
618
|
+
...workItemSelectionQuery(withResolvedMembers(options, members)),
|
|
619
|
+
...(options.completed === undefined ? {} : { completed: options.completed }),
|
|
620
|
+
},
|
|
621
|
+
},
|
|
622
|
+
}), { memberReferences: selectionMemberReferences(options) }));
|
|
623
|
+
});
|
|
624
|
+
workItem
|
|
625
|
+
.command("bulk")
|
|
626
|
+
.requiredOption("--project-id <projectId>")
|
|
627
|
+
.requiredOption("--action <action>", `Bulk action: ${workItemBulkActions.join(", ")}`, parseWorkItemBulkAction)
|
|
628
|
+
.requiredOption("--target <[projectId/]id@version>", "Target with its observed version, e.g. PAY-1@3 or project-id/PAY-2@4; repeat within the same Workspace", parseWorkItemBulkTarget, [])
|
|
629
|
+
.option("--status <status>", "Destination Workflow Column slug or virtual status (updateStatus)")
|
|
630
|
+
.option("--priority <priority>", "Priority (updatePriority)", parseWorkItemPriority)
|
|
631
|
+
.option("--assignee <assignee>", "Assignee User ID only (updateAssignee); me is not supported")
|
|
632
|
+
.option("--unassign", "Clear the assignee (updateAssignee)")
|
|
633
|
+
.option("--assigned-agent <agentId>", "Executing Workspace Agent ID (updateAssignedAgent)")
|
|
634
|
+
.option("--clear-assigned-agent", "Clear the executing Agent (updateAssignedAgent)")
|
|
635
|
+
.option("--label-id <labelId>", "Work Item Label ID (addLabel/removeLabel)")
|
|
636
|
+
.option("--due-date <dueDate>", "Due date (updateDueDate)", parseWorkItemDate)
|
|
637
|
+
.option("--clear-due-date", "Clear the due date (updateDueDate)")
|
|
638
|
+
.description("Apply one action to several Work Items, which may span Projects inside the same Workspace")
|
|
639
|
+
.action(async (options) => {
|
|
640
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
641
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (options.unassign === true && options.assignee !== undefined) {
|
|
645
|
+
writeSkillError(dependencies, {
|
|
646
|
+
message: "--assignee and --unassign cannot be combined for updateAssignee",
|
|
647
|
+
reason: "Invalid Operation",
|
|
648
|
+
retryable: false,
|
|
649
|
+
});
|
|
650
|
+
setExitCode(1);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (options.clearAssignedAgent === true && options.assignedAgent !== undefined) {
|
|
654
|
+
writeSkillError(dependencies, {
|
|
655
|
+
message: "--assigned-agent and --clear-assigned-agent cannot be combined for updateAssignedAgent",
|
|
656
|
+
reason: "Invalid Operation",
|
|
657
|
+
retryable: false,
|
|
658
|
+
});
|
|
659
|
+
setExitCode(1);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
if (options.clearDueDate === true && options.dueDate !== undefined) {
|
|
663
|
+
writeSkillError(dependencies, {
|
|
664
|
+
message: "--due-date and --clear-due-date cannot be combined for updateDueDate",
|
|
665
|
+
reason: "Invalid Operation",
|
|
666
|
+
retryable: false,
|
|
667
|
+
});
|
|
668
|
+
setExitCode(1);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
const idempotencyKey = randomUUID();
|
|
672
|
+
setExitCode(await run((client) => client.POST("/v1/projects/{projectId}/work-items/bulk", {
|
|
673
|
+
body: {
|
|
674
|
+
action: options.action,
|
|
675
|
+
...(options.action === "updateAssignee"
|
|
676
|
+
? options.unassign === true
|
|
677
|
+
? { assigneeId: null }
|
|
678
|
+
: options.assignee === undefined
|
|
679
|
+
? {}
|
|
680
|
+
: { assigneeId: options.assignee }
|
|
681
|
+
: {}),
|
|
682
|
+
...(options.action === "updateAssignedAgent"
|
|
683
|
+
? options.clearAssignedAgent === true
|
|
684
|
+
? { assignedAgentId: null }
|
|
685
|
+
: options.assignedAgent === undefined
|
|
686
|
+
? {}
|
|
687
|
+
: { assignedAgentId: options.assignedAgent }
|
|
688
|
+
: {}),
|
|
689
|
+
...(options.action === "updateDueDate"
|
|
690
|
+
? options.clearDueDate === true
|
|
691
|
+
? { dueDate: null }
|
|
692
|
+
: options.dueDate === undefined
|
|
693
|
+
? {}
|
|
694
|
+
: { dueDate: options.dueDate }
|
|
695
|
+
: {}),
|
|
696
|
+
...((options.action === "addLabel" || options.action === "removeLabel") &&
|
|
697
|
+
options.labelId !== undefined
|
|
698
|
+
? { labelId: options.labelId }
|
|
699
|
+
: {}),
|
|
700
|
+
...(options.action === "updatePriority" && options.priority !== undefined
|
|
701
|
+
? { priority: options.priority }
|
|
702
|
+
: {}),
|
|
703
|
+
...(options.action === "updateStatus" && options.status !== undefined
|
|
704
|
+
? { status: options.status }
|
|
705
|
+
: {}),
|
|
706
|
+
workItems: options.target.map((target) => ({
|
|
707
|
+
id: target.id,
|
|
708
|
+
...(target.projectId === undefined ? {} : { projectId: target.projectId }),
|
|
709
|
+
version: target.expectedVersion,
|
|
710
|
+
})),
|
|
711
|
+
},
|
|
712
|
+
params: {
|
|
713
|
+
header: { "idempotency-key": idempotencyKey },
|
|
714
|
+
path: { projectId: options.projectId },
|
|
715
|
+
},
|
|
716
|
+
}), {
|
|
717
|
+
ambiguousOutcomeMessage: "Work Item bulk outcome is unknown; list Work Items before retrying",
|
|
718
|
+
retryTransportOnce: true,
|
|
719
|
+
}));
|
|
720
|
+
});
|
|
721
|
+
workItem
|
|
722
|
+
.command("import")
|
|
723
|
+
.description("Import JSON tasks into the explicit Project; imported labels are reported as skipped")
|
|
724
|
+
.requiredOption("--project-id <projectId>")
|
|
725
|
+
.requiredOption("--file <path>", "JSON task file, at most 1 MiB and 1000 tasks")
|
|
726
|
+
.requiredOption("--idempotency-key <key>", "Reuse this key with the same file when retrying")
|
|
727
|
+
.action(async (options) => {
|
|
728
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
729
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
const key = options.idempotencyKey.trim();
|
|
733
|
+
if (key.length === 0 || key.length > 200) {
|
|
734
|
+
throw invalidArgument("The import idempotency key must contain 1 to 200 characters");
|
|
735
|
+
}
|
|
736
|
+
const body = await readWorkItemImportFile(options.file);
|
|
737
|
+
if (body === null) {
|
|
738
|
+
writeSkillError(dependencies, {
|
|
739
|
+
message: "The import file must be valid task JSON within 1 MiB and 1000 tasks",
|
|
740
|
+
reason: "Invalid Operation",
|
|
741
|
+
retryable: false,
|
|
742
|
+
});
|
|
743
|
+
setExitCode(2);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
let failed = 0;
|
|
747
|
+
const code = await run(async (client) => {
|
|
748
|
+
const result = await client.POST("/v1/projects/{projectId}/work-items/import", {
|
|
749
|
+
body,
|
|
750
|
+
params: {
|
|
751
|
+
header: { "idempotency-key": key },
|
|
752
|
+
path: { projectId: options.projectId },
|
|
753
|
+
},
|
|
754
|
+
});
|
|
755
|
+
if (result.data !== undefined) {
|
|
756
|
+
failed = result.data.results.failed;
|
|
757
|
+
}
|
|
758
|
+
return result;
|
|
759
|
+
}, {
|
|
760
|
+
ambiguousOutcomeMessage: "Import outcome is unknown; retry the same file and idempotency key",
|
|
761
|
+
retryTransportOnce: true,
|
|
762
|
+
});
|
|
763
|
+
setExitCode(code);
|
|
764
|
+
if (code === 0 && failed > 0) {
|
|
765
|
+
writeSkillError(dependencies, {
|
|
766
|
+
message: "Some tasks were refused; inspect the per-row results and import only corrected failed rows with a new key",
|
|
767
|
+
reason: "Invalid Operation",
|
|
768
|
+
retryable: false,
|
|
769
|
+
});
|
|
770
|
+
setExitCode(2);
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
workItemSelectionFlags(workItem.command("export"))
|
|
774
|
+
.description("Export selected readable Project tasks as JSON on stdout")
|
|
775
|
+
.requiredOption("--project-id <projectId>")
|
|
776
|
+
.action(async (options) => {
|
|
777
|
+
setExitCode(await run((client, _me, _credentialKind, members) => client.GET("/v1/projects/{projectId}/work-items/export", {
|
|
778
|
+
params: {
|
|
779
|
+
path: { projectId: options.projectId },
|
|
780
|
+
query: workItemSelectionQuery(withResolvedMembers(options, members)),
|
|
781
|
+
},
|
|
782
|
+
}), { memberReferences: selectionMemberReferences(options) }));
|
|
783
|
+
});
|
|
784
|
+
workItem
|
|
785
|
+
.command("transfer")
|
|
786
|
+
.description("Move a Work Item into another Project in its Workspace")
|
|
787
|
+
.requiredOption("--project-id <projectId>")
|
|
788
|
+
.requiredOption("--work-item-id <workItemId>")
|
|
789
|
+
.requiredOption("--destination-project-id <projectId>")
|
|
790
|
+
.requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
|
|
791
|
+
.option("--destination-status <status>", "Destination Workflow Column slug; defaults to the matching or first column")
|
|
792
|
+
.action(async (options) => {
|
|
793
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
794
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const idempotencyKey = randomUUID();
|
|
798
|
+
setExitCode(await run((client) => client.POST("/v1/projects/{projectId}/work-items/{workItemId}/transfer", {
|
|
799
|
+
body: {
|
|
800
|
+
destinationProjectId: options.destinationProjectId,
|
|
801
|
+
...(options.destinationStatus === undefined
|
|
802
|
+
? {}
|
|
803
|
+
: { destinationStatus: options.destinationStatus }),
|
|
804
|
+
},
|
|
805
|
+
params: {
|
|
806
|
+
header: { "idempotency-key": idempotencyKey, "if-match": options.expectedVersion },
|
|
807
|
+
path: { projectId: options.projectId, workItemId: options.workItemId },
|
|
808
|
+
},
|
|
809
|
+
}), {
|
|
810
|
+
ambiguousOutcomeMessage: "Work Item transfer outcome is unknown; inspect both Projects before retrying",
|
|
811
|
+
retryTransportOnce: true,
|
|
812
|
+
}));
|
|
813
|
+
});
|
|
814
|
+
workItem
|
|
815
|
+
.command("move")
|
|
816
|
+
.requiredOption("--project-id <projectId>")
|
|
817
|
+
.requiredOption("--work-item-id <workItemId>")
|
|
818
|
+
.requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
|
|
819
|
+
.requiredOption("--status <status>", "Destination Workflow Column slug or virtual status")
|
|
820
|
+
.option("--position <position>", "Board index inside the destination column", parseBoardPosition)
|
|
821
|
+
.option("--with-subtasks", "When the destination is completed or canceled, also move every unfinished subtask (any depth) you may update into its own Project's matching status, in one atomic command")
|
|
822
|
+
.action(async (options) => {
|
|
823
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
824
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
if (options.withSubtasks === true && options.position !== undefined) {
|
|
828
|
+
writeSkillError(dependencies, {
|
|
829
|
+
message: "--position cannot be combined with --with-subtasks",
|
|
830
|
+
reason: "Invalid Operation",
|
|
831
|
+
retryable: false,
|
|
832
|
+
});
|
|
833
|
+
setExitCode(1);
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
const idempotencyKey = randomUUID();
|
|
837
|
+
if (options.withSubtasks === true) {
|
|
838
|
+
setExitCode(await run((client) => moveWithSubtasks(client, {
|
|
839
|
+
expectedVersion: options.expectedVersion,
|
|
840
|
+
idempotencyKey,
|
|
841
|
+
projectId: options.projectId,
|
|
842
|
+
status: options.status,
|
|
843
|
+
workItemId: options.workItemId,
|
|
844
|
+
}), {
|
|
845
|
+
ambiguousOutcomeMessage: "Work Item move outcome is unknown; read the Work Item and its subtasks before retrying",
|
|
846
|
+
retryTransportOnce: true,
|
|
847
|
+
}));
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
setExitCode(await run(async (client) => {
|
|
851
|
+
const moved = await client.POST("/v1/projects/{projectId}/work-items/{workItemId}/move", {
|
|
852
|
+
body: {
|
|
853
|
+
...(options.position === undefined ? {} : { position: options.position }),
|
|
854
|
+
status: options.status,
|
|
855
|
+
},
|
|
856
|
+
params: {
|
|
857
|
+
header: {
|
|
858
|
+
"idempotency-key": idempotencyKey,
|
|
859
|
+
"if-match": options.expectedVersion,
|
|
860
|
+
},
|
|
861
|
+
path: {
|
|
862
|
+
projectId: options.projectId,
|
|
863
|
+
workItemId: options.workItemId,
|
|
864
|
+
},
|
|
865
|
+
},
|
|
866
|
+
});
|
|
867
|
+
if (moved.data !== undefined) {
|
|
868
|
+
const hint = await subtaskCascadeHint(client, {
|
|
869
|
+
projectId: options.projectId,
|
|
870
|
+
status: options.status,
|
|
871
|
+
workItemId: options.workItemId,
|
|
872
|
+
});
|
|
873
|
+
if (hint !== null)
|
|
874
|
+
dependencies.stderr(formatResourceDiagnostic(hint));
|
|
875
|
+
}
|
|
876
|
+
return moved;
|
|
877
|
+
}, {
|
|
878
|
+
ambiguousOutcomeMessage: "Work Item move outcome is unknown; read the Work Item board before retrying",
|
|
879
|
+
retryTransportOnce: true,
|
|
880
|
+
}));
|
|
881
|
+
});
|
|
882
|
+
for (const action of ["archive", "unarchive"]) {
|
|
883
|
+
workItem
|
|
884
|
+
.command(action)
|
|
885
|
+
.requiredOption("--project-id <projectId>")
|
|
886
|
+
.requiredOption("--work-item-id <workItemId>")
|
|
887
|
+
.requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
|
|
888
|
+
.action(async (options) => {
|
|
889
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
890
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
const idempotencyKey = randomUUID();
|
|
894
|
+
setExitCode(await run((client) => client.POST(action === "archive"
|
|
895
|
+
? "/v1/projects/{projectId}/work-items/{workItemId}/archive"
|
|
896
|
+
: "/v1/projects/{projectId}/work-items/{workItemId}/unarchive", {
|
|
897
|
+
params: {
|
|
898
|
+
path: { projectId: options.projectId, workItemId: options.workItemId },
|
|
899
|
+
header: {
|
|
900
|
+
"if-match": options.expectedVersion,
|
|
901
|
+
"idempotency-key": idempotencyKey,
|
|
902
|
+
},
|
|
903
|
+
},
|
|
904
|
+
}), {
|
|
905
|
+
retryTransportOnce: true,
|
|
906
|
+
ambiguousOutcomeMessage: "Work Item archive outcome is unknown; read the Work Item before retrying",
|
|
907
|
+
}));
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
workItem
|
|
911
|
+
.command("complete")
|
|
912
|
+
.requiredOption("--project-id <projectId>")
|
|
913
|
+
.requiredOption("--work-item-id <workItemId>")
|
|
914
|
+
.requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
|
|
915
|
+
.description("Move a Work Item into the Project's first final Workflow Column")
|
|
916
|
+
.option("--with-subtasks", "Also complete every unfinished subtask (any depth) you may update, in one atomic command")
|
|
917
|
+
.action(async (options) => {
|
|
918
|
+
if (hasWorkspaceReadToken(dependencies.environment)) {
|
|
919
|
+
setExitCode(rejectTokenWrite(dependencies));
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
const idempotencyKey = randomUUID();
|
|
923
|
+
setExitCode(await run(async (client) => {
|
|
924
|
+
const board = await client.GET("/v1/projects/{projectId}/work-item-board", {
|
|
925
|
+
params: { path: { projectId: options.projectId } },
|
|
926
|
+
});
|
|
927
|
+
if (!board.response.ok) {
|
|
928
|
+
return board;
|
|
929
|
+
}
|
|
930
|
+
const finalColumn = board.data?.workflowColumns.find((column) => column.category === "completed");
|
|
931
|
+
if (finalColumn === undefined) {
|
|
932
|
+
return {
|
|
933
|
+
error: {
|
|
934
|
+
code: "WORKFLOW_COLUMN_NO_FINAL",
|
|
935
|
+
message: "The Project has no final Workflow Column; mark a column final or move the Work Item to its slug directly",
|
|
936
|
+
},
|
|
937
|
+
response: new Response(null, { status: 422 }),
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
if (options.withSubtasks === true)
|
|
941
|
+
return await moveWithSubtasks(client, {
|
|
942
|
+
expectedVersion: options.expectedVersion,
|
|
943
|
+
idempotencyKey,
|
|
944
|
+
projectId: options.projectId,
|
|
945
|
+
status: finalColumn.slug,
|
|
946
|
+
workItemId: options.workItemId,
|
|
947
|
+
});
|
|
948
|
+
const moved = await client.POST("/v1/projects/{projectId}/work-items/{workItemId}/move", {
|
|
949
|
+
body: { status: finalColumn.slug },
|
|
950
|
+
params: {
|
|
951
|
+
header: {
|
|
952
|
+
"idempotency-key": idempotencyKey,
|
|
953
|
+
"if-match": options.expectedVersion,
|
|
954
|
+
},
|
|
955
|
+
path: {
|
|
956
|
+
projectId: options.projectId,
|
|
957
|
+
workItemId: options.workItemId,
|
|
958
|
+
},
|
|
959
|
+
},
|
|
960
|
+
});
|
|
961
|
+
if (moved.data !== undefined) {
|
|
962
|
+
const hint = await subtaskCascadeHint(client, {
|
|
963
|
+
columns: board.data?.workflowColumns,
|
|
964
|
+
projectId: options.projectId,
|
|
965
|
+
status: finalColumn.slug,
|
|
966
|
+
workItemId: options.workItemId,
|
|
967
|
+
});
|
|
968
|
+
if (hint !== null)
|
|
969
|
+
dependencies.stderr(formatResourceDiagnostic(hint));
|
|
970
|
+
}
|
|
971
|
+
return moved;
|
|
972
|
+
}, {
|
|
973
|
+
ambiguousOutcomeMessage: "Work Item completion outcome is unknown; read the Work Item board before retrying",
|
|
974
|
+
retryTransportOnce: true,
|
|
975
|
+
}));
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
//# sourceMappingURL=work-item-commands.js.map
|