@gonovus-ai/spec-flow-cli 2.5.0 → 2.5.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.
Files changed (78) hide show
  1. package/README.md +14 -7
  2. package/dist/acceptance-commands.js +20 -2
  3. package/dist/acceptance-commands.js.map +1 -1
  4. package/dist/capability-commands.d.ts +3 -0
  5. package/dist/capability-commands.js +92 -0
  6. package/dist/capability-commands.js.map +1 -0
  7. package/dist/cli-command-context.d.ts +31 -0
  8. package/dist/cli-command-context.js +2 -0
  9. package/dist/cli-command-context.js.map +1 -0
  10. package/dist/cli-command-support.d.ts +62 -0
  11. package/dist/cli-command-support.js +118 -0
  12. package/dist/cli-command-support.js.map +1 -0
  13. package/dist/cli.js +66 -3817
  14. package/dist/cli.js.map +1 -1
  15. package/dist/credential-store.d.ts +1 -0
  16. package/dist/credential-store.js +111 -6
  17. package/dist/credential-store.js.map +1 -1
  18. package/dist/global-search-commands.d.ts +4 -0
  19. package/dist/global-search-commands.js +23 -0
  20. package/dist/global-search-commands.js.map +1 -0
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.js +15 -4
  23. package/dist/index.js.map +1 -1
  24. package/dist/notification-commands.d.ts +3 -0
  25. package/dist/notification-commands.js +184 -0
  26. package/dist/notification-commands.js.map +1 -0
  27. package/dist/program.js +1 -1
  28. package/dist/program.js.map +1 -1
  29. package/dist/project-commands.d.ts +4 -0
  30. package/dist/project-commands.js +127 -0
  31. package/dist/project-commands.js.map +1 -0
  32. package/dist/proposal-commands.d.ts +3 -0
  33. package/dist/proposal-commands.js +165 -0
  34. package/dist/proposal-commands.js.map +1 -0
  35. package/dist/runner/workflow.d.ts +2 -2
  36. package/dist/runner/workflow.js +9 -3
  37. package/dist/runner/workflow.js.map +1 -1
  38. package/dist/runtime/session.js +10 -1
  39. package/dist/runtime/session.js.map +1 -1
  40. package/dist/spec-commands.d.ts +4 -0
  41. package/dist/spec-commands.js +347 -0
  42. package/dist/spec-commands.js.map +1 -0
  43. package/dist/token-commands.d.ts +3 -0
  44. package/dist/token-commands.js +79 -0
  45. package/dist/token-commands.js.map +1 -0
  46. package/dist/work-item-commands.d.ts +4 -0
  47. package/dist/work-item-commands.js +974 -0
  48. package/dist/work-item-commands.js.map +1 -0
  49. package/dist/work-item-comment-commands.d.ts +4 -0
  50. package/dist/work-item-comment-commands.js +160 -0
  51. package/dist/work-item-comment-commands.js.map +1 -0
  52. package/dist/work-item-custom-field-commands.d.ts +3 -0
  53. package/dist/work-item-custom-field-commands.js +209 -0
  54. package/dist/work-item-custom-field-commands.js.map +1 -0
  55. package/dist/work-item-label-commands.d.ts +3 -0
  56. package/dist/work-item-label-commands.js +224 -0
  57. package/dist/work-item-label-commands.js.map +1 -0
  58. package/dist/work-item-relation-commands.d.ts +4 -0
  59. package/dist/work-item-relation-commands.js +209 -0
  60. package/dist/work-item-relation-commands.js.map +1 -0
  61. package/dist/workflow-column-commands.d.ts +3 -0
  62. package/dist/workflow-column-commands.js +206 -0
  63. package/dist/workflow-column-commands.js.map +1 -0
  64. package/dist/workspace-commands.d.ts +4 -0
  65. package/dist/workspace-commands.js +299 -0
  66. package/dist/workspace-commands.js.map +1 -0
  67. package/dist/workspace-finding-commands.d.ts +4 -0
  68. package/dist/workspace-finding-commands.js +303 -0
  69. package/dist/workspace-finding-commands.js.map +1 -0
  70. package/dist/workspace-glossary-commands.d.ts +4 -0
  71. package/dist/workspace-glossary-commands.js +121 -0
  72. package/dist/workspace-glossary-commands.js.map +1 -0
  73. package/dist/workspace-review-commands.d.ts +4 -0
  74. package/dist/workspace-review-commands.js +108 -0
  75. package/dist/workspace-review-commands.js.map +1 -0
  76. package/guides/acceptance.md +8 -1
  77. package/guides/workspace-admin.md +5 -1
  78. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,165 +1,54 @@
1
- import { CommanderError, InvalidArgumentError } from "commander";
2
- import { randomUUID } from "node:crypto";
3
- import { z } from "zod";
1
+ import { CommanderError } from "commander";
4
2
  import { registerAcceptanceCommands } from "./acceptance-commands.js";
5
3
  import { registerAgentCommands } from "./agent-commands.js";
6
4
  import { addAuthenticationCommandTopology } from "./authentication-command-topology.js";
7
5
  import { registerBoardCommands } from "./board-commands.js";
6
+ import { registerCapabilityCommands } from "./capability-commands.js";
7
+ import { invalidArgument, parseOpaqueVersion, parseProjectId, parseRoleStatements, parseSearchLimit, parseWorkItemId, rejectTokenWrite, } from "./cli-command-support.js";
8
8
  import { registerClientCompatibilityCommands } from "./commands/client-compatibility.js";
9
- import { itemOutput, itemListOutput, relationListOutput, relationReceiptOutput, } from "./commands/work-item-output.js";
10
9
  import { registerContextDocumentCommands } from "./context-document-commands.js";
11
- import { registerCustomFieldColorCommands, parseOptionColors, } from "./custom-field-color-commands.js";
12
10
  import { registerDiscussCommands } from "./discuss-commands.js";
13
11
  import { registerGitHubAccountCommands } from "./github-account-commands.js";
12
+ import { registerGlobalSearchCommands } from "./global-search-commands.js";
14
13
  import { registerGroupNotificationCommands } from "./group-notification-commands.js";
15
- import { readDescription, singleDescriptionSource } from "./input/text-source.js";
16
- import { formatMemberResolutionDiagnostic, needsMemberResolution, resolveMemberReferences, splitMemberReferences, substituteMemberReferences, } from "./member-references.js";
14
+ import { formatMemberResolutionDiagnostic, needsMemberResolution, resolveMemberReferences, splitMemberReferences, } from "./member-references.js";
15
+ import { registerNotificationCommands } from "./notification-commands.js";
17
16
  import { registerProductMapCommands } from "./product-map-commands.js";
18
17
  import { createProgram } from "./program.js";
19
18
  import { registerProjectAdministrationCommands } from "./project-administration-commands.js";
19
+ import { registerProjectCommands } from "./project-commands.js";
20
+ import { registerProposalCommands } from "./proposal-commands.js";
20
21
  import { observeCompatibility } from "./runtime/client-compatibility.js";
21
- import { mapHttpFailure, writeSkillError, skillErrorExitCode, } from "./runtime/errors.js";
22
- import { execute, } from "./runtime/execute.js";
22
+ import { mapHttpFailure, skillErrorExitCode, writeSkillError } from "./runtime/errors.js";
23
+ import { execute } from "./runtime/execute.js";
23
24
  import { readIdentity } from "./runtime/identity.js";
24
25
  import { writeResult } from "./runtime/output.js";
25
- import { selectSession, hasWorkspaceReadToken, rejectWorkspaceReadTokenOperation, } from "./runtime/session.js";
26
+ import { hasWorkspaceReadToken, rejectWorkspaceReadTokenOperation, selectSession, } from "./runtime/session.js";
27
+ import { registerSpecCommands } from "./spec-commands.js";
26
28
  import { registerSpecDiscussionCommands } from "./spec-discussion-commands.js";
27
29
  import { registerSpecOwnerCommands } from "./spec-owner-commands.js";
30
+ import { registerTokenCommands } from "./token-commands.js";
28
31
  import { registerUserApiKeyCommands } from "./user-api-key-commands.js";
29
- import { registerSpecLabelCommands, registerVersionCommands, resolveProjectVersion, } from "./version-commands.js";
32
+ import { registerSpecLabelCommands, registerVersionCommands } from "./version-commands.js";
30
33
  import { registerWorkItemAssetCommands } from "./work-item-asset-commands.js";
34
+ import { registerWorkItemCommands } from "./work-item-commands.js";
35
+ import { registerWorkItemCommentCommands } from "./work-item-comment-commands.js";
36
+ import { registerWorkItemCustomFieldCommands } from "./work-item-custom-field-commands.js";
31
37
  import { registerWorkItemDeliveryCommands } from "./work-item-delivery-commands.js";
32
- import { readWorkItemImportFile } from "./work-item-exchange-file.js";
38
+ import { registerWorkItemLabelCommands } from "./work-item-label-commands.js";
33
39
  import { registerWorkItemQueryCommands } from "./work-item-query-commands.js";
40
+ import { registerWorkItemRelationCommands } from "./work-item-relation-commands.js";
34
41
  import { registerWorkItemResourceLinkCommands } from "./work-item-resource-link-commands.js";
35
- import { moveWithSubtasks, subtaskCascadeHint } from "./work-item-subtask-cascade.js";
36
42
  import { registerWorkItemThreadCommands } from "./work-item-thread-commands.js";
37
43
  import { registerWorkItemWatcherCommands } from "./work-item-watcher-commands.js";
44
+ import { registerWorkflowColumnCommands } from "./workflow-column-commands.js";
45
+ import { registerWorkspaceCommands } from "./workspace-commands.js";
46
+ import { registerWorkspaceFindingCommands } from "./workspace-finding-commands.js";
47
+ import { registerWorkspaceGlossaryCommands } from "./workspace-glossary-commands.js";
48
+ import { registerWorkspaceReviewCommands } from "./workspace-review-commands.js";
38
49
  export function formatResourceDiagnostic(message) {
39
50
  return `${JSON.stringify({ diagnostic: { level: "warning", message } })}\n`;
40
51
  }
41
- const workItemCompletedFilters = ["all", "pastDay", "pastWeek", "pastMonth", "none"];
42
- const workItemBulkActions = [
43
- "updateStatus",
44
- "updatePriority",
45
- "updateAssignee",
46
- "updateAssignedAgent",
47
- "delete",
48
- "addLabel",
49
- "removeLabel",
50
- "updateDueDate",
51
- ];
52
- const glossaryEntryInputSchema = z
53
- .object({
54
- canonicalTerm: z.string().trim().min(1).max(200),
55
- definition: z.string().trim().min(1).max(4_000),
56
- id: z.string().trim().min(1).max(200),
57
- usageNote: z.string().trim().min(1).max(2_000).nullable(),
58
- })
59
- .strict();
60
- const glossaryEntriesInputSchema = z.array(glossaryEntryInputSchema).max(500);
61
- const sourceReferenceInputSchema = z
62
- .object({
63
- externalRevision: z.string().trim().min(1).max(200).optional(),
64
- section: z.string().trim().min(1).max(500).optional(),
65
- title: z.string().trim().min(1).max(300),
66
- url: z
67
- .url()
68
- .max(2_000)
69
- .refine((value) => {
70
- const url = new URL(value);
71
- return ((url.protocol === "https:" || url.protocol === "http:") &&
72
- url.username.length === 0 &&
73
- url.password.length === 0);
74
- }),
75
- })
76
- .strict();
77
- const sourceReferencesInputSchema = z.array(sourceReferenceInputSchema).max(20);
78
- const roleStatementsInputSchema = z.record(z.string().trim().min(1).max(200), z.array(z.string().trim().min(1).max(200)).min(1).max(50));
79
- const findingReferenceSchema = z
80
- .object({
81
- kind: z.enum(["SharedPrecondition", "ExampleTable", "Title", "Rule", "Scenario", "Line"]),
82
- text: z.string().trim().min(1).max(20_000),
83
- })
84
- .strict();
85
- const findingTargetSchema = z
86
- .object({
87
- references: z.array(findingReferenceSchema).min(1).max(50),
88
- specId: z
89
- .string()
90
- .trim()
91
- .toUpperCase()
92
- .regex(/^[A-Z]{2,10}-S[1-9]\d*$/u),
93
- })
94
- .strict();
95
- const findingEvidenceSchema = z.discriminatedUnion("kind", [
96
- z
97
- .object({
98
- incompatibleClaims: z.tuple([
99
- z.string().trim().min(1).max(4_000),
100
- z.string().trim().min(1).max(4_000),
101
- ]),
102
- kind: z.literal("Contradiction"),
103
- })
104
- .strict(),
105
- z
106
- .object({
107
- incompatibleRequirements: z.tuple([
108
- z.string().trim().min(1).max(4_000),
109
- z.string().trim().min(1).max(4_000),
110
- ]),
111
- kind: z.literal("Conflict"),
112
- })
113
- .strict(),
114
- z
115
- .object({
116
- duplicatedBehavior: z.string().trim().min(1).max(4_000),
117
- kind: z.literal("Duplicate"),
118
- })
119
- .strict(),
120
- z
121
- .object({
122
- interpretations: z.tuple([
123
- z
124
- .object({
125
- behavior: z.string().trim().min(1).max(4_000),
126
- meaning: z.string().trim().min(1).max(4_000),
127
- })
128
- .strict(),
129
- z
130
- .object({
131
- behavior: z.string().trim().min(1).max(4_000),
132
- meaning: z.string().trim().min(1).max(4_000),
133
- })
134
- .strict(),
135
- ]),
136
- kind: z.literal("Ambiguity"),
137
- })
138
- .strict(),
139
- z
140
- .object({
141
- glossaryEntryIds: z.array(z.string().trim().min(1).max(200)).max(20),
142
- issue: z.enum(["MissingDefinition", "GlossaryConflict", "MultipleMeanings"]),
143
- kind: z.literal("Terminology"),
144
- term: z.string().trim().min(1).max(200),
145
- })
146
- .strict(),
147
- z
148
- .object({
149
- kind: z.literal("Unverifiable"),
150
- missingCriterion: z.string().trim().min(1).max(4_000),
151
- })
152
- .strict(),
153
- ]);
154
- const findingCreateInputSchema = z
155
- .object({
156
- affectedScenarios: z.array(z.string().trim().min(1).max(300)).max(50),
157
- conclusion: z.string().trim().min(1).max(4_000),
158
- evidence: findingEvidenceSchema,
159
- explanation: z.string().trim().min(1).max(8_000),
160
- targets: z.array(findingTargetSchema).min(1).max(10),
161
- })
162
- .strict();
163
52
  export async function runCli(arguments_, originalDependencies) {
164
53
  let exitCode = 0;
165
54
  const observe = observeCompatibility(originalDependencies);
@@ -227,21 +116,35 @@ export async function runCli(arguments_, originalDependencies) {
227
116
  }
228
117
  return writeResult(dependencies, () => options.project === undefined ? result.data : options.project(result.data));
229
118
  };
119
+ const setExitCode = (value) => {
120
+ exitCode = value;
121
+ };
122
+ const resourceRuntime = {
123
+ run,
124
+ setExitCode,
125
+ parseOpaqueVersion,
126
+ parseLimit: parseSearchLimit,
127
+ };
128
+ const context = {
129
+ program,
130
+ dependencies,
131
+ run,
132
+ setExitCode,
133
+ outputMode: () => outputMode,
134
+ warnMissingUrl,
135
+ resourceRuntime,
136
+ };
230
137
  registerUserApiKeyCommands(program, {
231
138
  dependencies,
232
139
  run,
233
- setExitCode: (value) => {
234
- exitCode = value;
235
- },
140
+ setExitCode,
236
141
  parseScopes: parseRoleStatements,
237
142
  parseLimit: parseSearchLimit,
238
143
  });
239
144
  registerGitHubAccountCommands(program, {
240
145
  dependencies,
241
146
  run,
242
- setExitCode: (value) => {
243
- exitCode = value;
244
- },
147
+ setExitCode,
245
148
  });
246
149
  const authentication = addAuthenticationCommandTopology(program);
247
150
  program.hook("preAction", (_command, actionCommand) => {
@@ -311,1458 +214,40 @@ export async function runCli(arguments_, originalDependencies) {
311
214
  };
312
215
  }, { rejectWorkspaceReadToken: true });
313
216
  });
314
- const workspace = program.command("workspace");
315
- workspace.command("list").action(async () => {
316
- exitCode = await run((client) => client.GET("/v1/workspaces"), {
317
- rejectWorkspaceReadToken: true,
318
- });
319
- });
320
- workspace
321
- .command("create")
322
- .requiredOption("--name <name>")
323
- .option("--prefix <prefix>", "Immutable Workspace number prefix, 2 to 10 uppercase letters")
324
- .option("--spec-language <language>", "Workspace keyword language: zh-CN or en", (value) => z.enum(["zh-CN", "en"]).parse(value), "zh-CN")
325
- .action(async (options) => {
326
- if (hasWorkspaceReadToken(dependencies.environment)) {
327
- exitCode = rejectTokenWrite(dependencies);
328
- return;
329
- }
330
- const idempotencyKey = randomUUID();
331
- exitCode = await run((client) => client.POST("/v1/workspaces", {
332
- body: {
333
- name: options.name,
334
- prefix: options.prefix,
335
- specLanguage: options.specLanguage,
336
- },
337
- params: { header: { "idempotency-key": idempotencyKey } },
338
- }), {
339
- retryTransportOnce: true,
340
- ambiguousOutcomeMessage: "Workspace creation outcome is unknown; run workspace list before trying a new command identity",
341
- });
342
- });
343
- workspace
344
- .command("rename")
345
- .requiredOption("--workspace-id <workspaceId>")
346
- .requiredOption("--name <name>")
347
- .requiredOption("--expected-version <version>", "Observed Workspace settings version", parseOpaqueVersion)
348
- .requiredOption("--idempotency-key <key>")
349
- .action(async (options) => {
350
- exitCode = await run((client) => client.PATCH("/v1/workspaces/{workspaceId}/settings", {
351
- params: {
352
- path: { workspaceId: options.workspaceId },
353
- header: {
354
- "idempotency-key": options.idempotencyKey,
355
- "if-match": options.expectedVersion,
356
- },
357
- },
358
- body: { name: options.name },
359
- }), { retryTransportOnce: true });
360
- });
361
- const workspaceSettings = workspace.command("settings");
362
- workspaceSettings
363
- .command("read")
364
- .requiredOption("--workspace-id <workspaceId>")
365
- .action(async (options) => {
366
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/settings", { params: { path: options } }));
367
- });
368
- workspaceSettings
369
- .command("update")
370
- .requiredOption("--workspace-id <workspaceId>")
371
- .requiredOption("--spec-language <language>", "Workspace keyword language", (value) => z.enum(["zh-CN", "en"]).parse(value))
372
- .requiredOption("--expected-version <version>", "Observed Workspace settings version", parseOpaqueVersion)
373
- .requiredOption("--idempotency-key <key>")
374
- .action(async (options) => {
375
- if (hasWorkspaceReadToken(dependencies.environment)) {
376
- exitCode = rejectTokenWrite(dependencies);
377
- return;
378
- }
379
- exitCode = await run((client) => client.PATCH("/v1/workspaces/{workspaceId}/settings", {
380
- params: {
381
- path: { workspaceId: options.workspaceId },
382
- header: {
383
- "idempotency-key": options.idempotencyKey,
384
- "if-match": options.expectedVersion,
385
- },
386
- },
387
- body: { specLanguage: options.specLanguage },
388
- }), { retryTransportOnce: true });
389
- });
390
- const workspaceMember = workspace.command("member");
391
- workspaceMember
392
- .command("list")
393
- .requiredOption("--workspace-id <workspaceId>")
394
- .action(async (options) => {
395
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/members", {
396
- params: { path: { workspaceId: options.workspaceId } },
397
- }), { rejectWorkspaceReadToken: true });
398
- });
399
- workspaceMember
400
- .command("search")
401
- .requiredOption("--workspace-id <workspaceId>")
402
- .requiredOption("--query <query>")
403
- .option("--limit <limit>", "Maximum directory candidates", parseSearchLimit, 10)
404
- .action(async (options) => {
405
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/members/directory", {
406
- params: {
407
- path: { workspaceId: options.workspaceId },
408
- query: { limit: options.limit, query: options.query },
409
- },
410
- }), { rejectWorkspaceReadToken: true });
411
- });
412
- workspaceMember
413
- .command("add")
414
- .requiredOption("--workspace-id <workspaceId>")
415
- .requiredOption("--issuer <issuer>", "Authentik issuer URL from `workspace member search`")
416
- .requiredOption("--subject <subject>", "Authentik subject from `workspace member search`")
417
- .requiredOption("--role <role>", "Workspace Role name")
418
- .action(async (options) => {
419
- if (hasWorkspaceReadToken(dependencies.environment)) {
420
- exitCode = rejectTokenWrite(dependencies);
421
- return;
422
- }
423
- const idempotencyKey = randomUUID();
424
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/members", {
425
- body: {
426
- issuer: options.issuer,
427
- role: options.role,
428
- subject: options.subject,
429
- },
430
- params: {
431
- header: { "idempotency-key": idempotencyKey },
432
- path: { workspaceId: options.workspaceId },
433
- },
434
- }), { retryTransportOnce: true });
435
- });
436
- workspaceMember
437
- .command("set-role")
438
- .requiredOption("--workspace-id <workspaceId>")
439
- .requiredOption("--user-id <userId>", "Member User ID from `workspace member list`")
440
- .requiredOption("--role <role>", "Workspace Role name")
441
- .requiredOption("--expected-version <version>", "Opaque Member version from `workspace member list`", parseOpaqueVersion)
442
- .action(async (options) => {
443
- if (hasWorkspaceReadToken(dependencies.environment)) {
444
- exitCode = rejectTokenWrite(dependencies);
445
- return;
446
- }
447
- const idempotencyKey = randomUUID();
448
- exitCode = await run((client) => client.PATCH("/v1/workspaces/{workspaceId}/members/{userId}", {
449
- body: { role: options.role },
450
- params: {
451
- header: {
452
- "idempotency-key": idempotencyKey,
453
- "if-match": options.expectedVersion,
454
- },
455
- path: {
456
- userId: options.userId,
457
- workspaceId: options.workspaceId,
458
- },
459
- },
460
- }), {
461
- ambiguousOutcomeMessage: "Member Role change outcome is unknown; read `workspace member list` before retrying",
462
- retryTransportOnce: true,
463
- });
464
- });
465
- const workspaceMemberAlias = workspaceMember
466
- .command("alias")
467
- .description("Administer Member Aliases: set, change or clear; scripts should keep using User IDs");
468
- workspaceMemberAlias
469
- .command("set")
470
- .description("Set or change a Member Alias; pass --alias '' to clear it")
471
- .requiredOption("--workspace-id <workspaceId>")
472
- .requiredOption("--user-id <userId>", "Member User ID from `workspace member list`")
473
- .requiredOption("--alias <alias>", "2–12 characters without @, unique in the Workspace and different from other Members' names; empty clears")
474
- .option("--idempotency-key <key>", "Reuse the same key and inputs when retrying")
475
- .action(async (options) => {
476
- if (hasWorkspaceReadToken(dependencies.environment)) {
477
- exitCode = rejectTokenWrite(dependencies);
478
- return;
479
- }
480
- const idempotencyKey = options.idempotencyKey ?? randomUUID();
481
- exitCode = await run((client) => client.PUT("/v1/workspaces/{workspaceId}/members/{userId}/alias", {
482
- body: { alias: options.alias },
483
- params: {
484
- header: { "idempotency-key": idempotencyKey },
485
- path: { userId: options.userId, workspaceId: options.workspaceId },
486
- },
487
- }), {
488
- ambiguousOutcomeMessage: "Member Alias outcome is unknown; read `workspace member list` before retrying",
489
- retryTransportOnce: true,
490
- });
491
- });
492
- workspaceMember
493
- .command("remove")
494
- .requiredOption("--workspace-id <workspaceId>")
495
- .requiredOption("--user-id <userId>", "Member User ID from `workspace member list`")
496
- .requiredOption("--expected-version <version>", "Opaque Member version from `workspace member list`", parseOpaqueVersion)
497
- .action(async (options) => {
498
- if (hasWorkspaceReadToken(dependencies.environment)) {
499
- exitCode = rejectTokenWrite(dependencies);
500
- return;
501
- }
502
- const idempotencyKey = randomUUID();
503
- exitCode = await run((client) => client.DELETE("/v1/workspaces/{workspaceId}/members/{userId}", {
504
- params: {
505
- header: {
506
- "idempotency-key": idempotencyKey,
507
- "if-match": options.expectedVersion,
508
- },
509
- path: {
510
- userId: options.userId,
511
- workspaceId: options.workspaceId,
512
- },
513
- },
514
- }), {
515
- ambiguousOutcomeMessage: "Member removal outcome is unknown; read `workspace member list` before retrying",
516
- retryTransportOnce: true,
517
- });
518
- });
519
- const workspaceRole = workspace.command("role");
520
- workspaceRole
521
- .command("list")
522
- .requiredOption("--workspace-id <workspaceId>")
523
- .action(async (options) => {
524
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/roles", {
525
- params: { path: { workspaceId: options.workspaceId } },
526
- }), { rejectWorkspaceReadToken: true });
527
- });
528
- workspaceRole
529
- .command("create")
530
- .requiredOption("--workspace-id <workspaceId>")
531
- .requiredOption("--name <name>", "Custom Workspace Role name")
532
- .requiredOption("--statements <statements>", "JSON object mapping permission resources to granted actions", parseRoleStatements)
533
- .action(async (options) => {
534
- if (hasWorkspaceReadToken(dependencies.environment)) {
535
- exitCode = rejectTokenWrite(dependencies);
536
- return;
537
- }
538
- const idempotencyKey = randomUUID();
539
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/roles", {
540
- body: { name: options.name, statements: options.statements },
541
- params: {
542
- header: { "idempotency-key": idempotencyKey },
543
- path: { workspaceId: options.workspaceId },
544
- },
545
- }), { retryTransportOnce: true });
546
- });
547
- workspaceRole
548
- .command("update")
549
- .requiredOption("--workspace-id <workspaceId>")
550
- .requiredOption("--name <name>", "Workspace Role name from `workspace role list`")
551
- .requiredOption("--statements <statements>", "JSON object mapping permission resources to granted actions", parseRoleStatements)
552
- .requiredOption("--expected-version <version>", "Opaque Role version from `workspace role list`", parseOpaqueVersion)
553
- .action(async (options) => {
554
- if (hasWorkspaceReadToken(dependencies.environment)) {
555
- exitCode = rejectTokenWrite(dependencies);
556
- return;
557
- }
558
- const idempotencyKey = randomUUID();
559
- exitCode = await run((client) => client.PUT("/v1/workspaces/{workspaceId}/roles/{roleName}", {
560
- body: { statements: options.statements },
561
- params: {
562
- header: {
563
- "idempotency-key": idempotencyKey,
564
- "if-match": options.expectedVersion,
565
- },
566
- path: {
567
- roleName: options.name,
568
- workspaceId: options.workspaceId,
569
- },
570
- },
571
- }), {
572
- ambiguousOutcomeMessage: "Role update outcome is unknown; read `workspace role list` before retrying",
573
- retryTransportOnce: true,
574
- });
575
- });
576
- workspaceRole
577
- .command("delete")
578
- .requiredOption("--workspace-id <workspaceId>")
579
- .requiredOption("--name <name>", "Custom Workspace Role name")
580
- .requiredOption("--expected-version <version>", "Opaque Role version from `workspace role list`", parseOpaqueVersion)
581
- .action(async (options) => {
582
- if (hasWorkspaceReadToken(dependencies.environment)) {
583
- exitCode = rejectTokenWrite(dependencies);
584
- return;
585
- }
586
- const idempotencyKey = randomUUID();
587
- exitCode = await run((client) => client.DELETE("/v1/workspaces/{workspaceId}/roles/{roleName}", {
588
- params: {
589
- header: {
590
- "idempotency-key": idempotencyKey,
591
- "if-match": options.expectedVersion,
592
- },
593
- path: {
594
- roleName: options.name,
595
- workspaceId: options.workspaceId,
596
- },
597
- },
598
- }), {
599
- ambiguousOutcomeMessage: "Role deletion outcome is unknown; read `workspace role list` before retrying",
600
- retryTransportOnce: true,
601
- });
602
- });
603
- const project = program.command("project");
604
- project
605
- .command("list")
606
- .option("--status <status>", "Filter by Project lifecycle status", parseProjectStatus)
607
- .option("--workspace-id <workspaceId>", "Filter by owning Workspace ID from `workspace list`")
608
- .action(async (options) => {
609
- exitCode = await run((client) => client.GET("/v1/projects", {
610
- params: {
611
- query: {
612
- ...(options.status === undefined ? {} : { status: options.status }),
613
- ...(options.workspaceId === undefined ? {} : { workspaceId: options.workspaceId }),
614
- },
615
- },
616
- }), { rejectWorkspaceReadToken: true });
617
- });
618
- project
619
- .command("create")
620
- .requiredOption("--name <name>")
621
- .requiredOption("--workspace-id <workspaceId>", "Workspace ID returned by `workspace list` or `workspace create`")
622
- .action(async (options) => {
623
- if (hasWorkspaceReadToken(dependencies.environment)) {
624
- exitCode = rejectTokenWrite(dependencies);
625
- return;
626
- }
627
- const idempotencyKey = randomUUID();
628
- exitCode = await run((client) => client.POST("/v1/projects", {
629
- body: {
630
- name: options.name,
631
- workspaceId: options.workspaceId,
632
- },
633
- params: { header: { "idempotency-key": idempotencyKey } },
634
- }), { retryTransportOnce: true });
635
- });
636
- for (const operation of ["archive", "restore", "trash"]) {
637
- project
638
- .command(operation)
639
- .requiredOption("--project-id <projectId>")
640
- .requiredOption("--expected-version <version>", "Opaque Project version", parseOpaqueVersion)
641
- .action(async (options) => {
642
- const idempotencyKey = randomUUID();
643
- exitCode = await run((client) => client.POST(`/v1/projects/{projectId}/${operation}`, {
644
- params: {
645
- header: {
646
- "idempotency-key": idempotencyKey,
647
- "if-match": options.expectedVersion,
648
- },
649
- path: { projectId: options.projectId },
650
- },
651
- }), {
652
- ambiguousOutcomeMessage: `Project ${operation} outcome is unknown; read Project context before retrying`,
653
- rejectWorkspaceReadToken: true,
654
- retryTransportOnce: true,
655
- });
656
- });
657
- }
658
- project
659
- .command("context")
660
- .requiredOption("--project-id <projectId>")
661
- .action(async (options) => {
662
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/context", {
663
- params: { path: { projectId: options.projectId } },
664
- }));
665
- });
666
- const sharing = project
667
- .command("sharing")
668
- .description("Manage anonymous task-only Project sharing");
669
- sharing
670
- .command("read")
671
- .requiredOption("--project-id <projectId>")
672
- .action(async (options) => {
673
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/sharing", {
674
- params: { path: { projectId: options.projectId } },
675
- }), { rejectWorkspaceReadToken: true });
676
- });
677
- sharing
678
- .command("set")
679
- .requiredOption("--project-id <projectId>")
680
- .requiredOption("--public <boolean>", "true or false", (value) => {
681
- if (value !== "true" && value !== "false")
682
- throw new InvalidArgumentError("--public must be true or false");
683
- return value === "true";
684
- })
685
- .requiredOption("--expected-version <version>", "Opaque sharing version from project sharing read", parseOpaqueVersion)
686
- .requiredOption("--idempotency-key <key>", "UUID; reuse the same key and intent after an uncertain response", (value) => {
687
- if (!z.uuid().safeParse(value).success)
688
- throw new InvalidArgumentError("The sharing command key must be a UUID");
689
- return value;
690
- })
691
- .action(async (options) => {
692
- if (hasWorkspaceReadToken(dependencies.environment)) {
693
- exitCode = rejectTokenWrite(dependencies);
694
- return;
695
- }
696
- exitCode = await run((client) => client.PUT("/v1/projects/{projectId}/sharing", {
697
- body: { isPublic: options.public },
698
- params: {
699
- path: { projectId: options.projectId },
700
- header: {
701
- "if-match": options.expectedVersion,
702
- "idempotency-key": options.idempotencyKey,
703
- },
704
- },
705
- }), {
706
- rejectWorkspaceReadToken: true,
707
- retryTransportOnce: true,
708
- ambiguousOutcomeMessage: "Sharing outcome is unknown; reread project sharing and retry the same command key and intent",
709
- });
710
- });
711
- const spec = program.command("spec");
712
- spec
713
- .command("list")
714
- .requiredOption("--workspace-id <workspaceId>")
715
- .option("--project-id <projectId>")
716
- .option("--query <query>")
717
- .option("--limit <limit>", "Maximum results", parseSearchLimit, 50)
718
- .option("--cursor <cursor>")
719
- .action(async (options) => {
720
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/spec-directory", {
721
- params: {
722
- path: { workspaceId: options.workspaceId },
723
- query: {
724
- ...(options.projectId === undefined ? {} : { projectId: options.projectId }),
725
- ...(options.query === undefined ? {} : { query: options.query }),
726
- limit: options.limit,
727
- ...(options.cursor === undefined ? {} : { cursor: options.cursor }),
728
- },
729
- },
730
- }), { rejectWorkspaceReadToken: true });
731
- });
732
- spec
733
- .command("read")
734
- .requiredOption("--workspace-id <workspaceId>")
735
- .requiredOption("--spec-id <specId>")
736
- .action(async (options) => {
737
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/specs/{specId}", {
738
- params: { path: options },
739
- }), { rejectWorkspaceReadToken: true });
740
- });
741
- spec
742
- .command("changelog")
743
- .requiredOption("--workspace-id <workspaceId>")
744
- .requiredOption("--spec-id <specId>")
745
- .action(async (options) => {
746
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/specs/{specId}/changelog", {
747
- params: { path: options },
748
- }), { rejectWorkspaceReadToken: true });
749
- });
750
- spec
751
- .command("search")
752
- .requiredOption("--workspace-id <workspaceId>")
753
- .requiredOption("--query <query>")
754
- .option("--limit <limit>", "Maximum results", parseSearchLimit, 20)
755
- .option("--cursor <cursor>")
756
- .action(async (options) => {
757
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/spec-search", {
758
- params: {
759
- path: { workspaceId: options.workspaceId },
760
- query: {
761
- ...(options.cursor === undefined ? {} : { cursor: options.cursor }),
762
- limit: options.limit,
763
- query: options.query,
764
- },
765
- },
766
- }));
767
- });
768
- spec
769
- .command("current")
770
- .requiredOption("--workspace-id <workspaceId>")
771
- .requiredOption("--spec-id <specId>")
772
- .action(async (options) => {
773
- exitCode = await run((client) => client.GET(hasWorkspaceReadToken(dependencies.environment)
774
- ? "/v1/workspaces/{workspaceId}/published/specs/{specId}/current-revision"
775
- : "/v1/workspaces/{workspaceId}/specs/{specId}/current-revision", { params: { path: options } }));
776
- });
777
- spec
778
- .command("revision")
779
- .requiredOption("--workspace-id <workspaceId>")
780
- .requiredOption("--spec-id <specId>")
781
- .requiredOption("--revision-id <revisionId>")
782
- .action(async (options) => {
783
- exitCode = await run((client) => client.GET(hasWorkspaceReadToken(dependencies.environment)
784
- ? "/v1/workspaces/{workspaceId}/published/specs/{specId}/revisions/{revisionId}"
785
- : "/v1/workspaces/{workspaceId}/specs/{specId}/revisions/{revisionId}", { params: { path: options } }));
786
- });
787
- spec
788
- .command("edit")
789
- .requiredOption("--workspace-id <workspaceId>")
790
- .requiredOption("--spec-id <specId>")
791
- .requiredOption("--content <content>")
792
- .option("--agent-revision <agentRevision>")
793
- .option("--agent-model <agentModel>")
794
- .option("--source-reference-ids <sourceReferenceIds>")
795
- .action(async (options) => {
796
- if (hasWorkspaceReadToken(dependencies.environment)) {
797
- exitCode = rejectTokenWrite(dependencies);
798
- return;
799
- }
800
- exitCode = await run((client) => client.PUT("/v1/workspaces/{workspaceId}/specs/{specId}/draft", {
801
- body: {
802
- content: options.content,
803
- provenance: toAgentProvenance(options),
804
- },
805
- params: { path: options },
806
- }));
807
- });
808
- spec
809
- .command("assign-scenario-ids")
810
- .requiredOption("--workspace-id <workspaceId>")
811
- .requiredOption("--spec-id <specId>")
812
- .option("--agent-revision <agentRevision>")
813
- .option("--agent-model <agentModel>")
814
- .action(async (options) => {
815
- if (hasWorkspaceReadToken(dependencies.environment)) {
816
- exitCode = rejectTokenWrite(dependencies);
817
- return;
818
- }
819
- const idempotencyKey = randomUUID();
820
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/specs/{specId}/draft/scenario-ids", {
821
- body: { provenance: toAgentProvenance(options) },
822
- params: {
823
- header: { "idempotency-key": idempotencyKey },
824
- path: options,
825
- },
826
- }), {
827
- ambiguousOutcomeMessage: "Scenario ID assignment outcome is unknown; inspect the Working Draft before retrying",
828
- retryTransportOnce: true,
829
- });
830
- });
831
- spec
832
- .command("publish")
833
- .requiredOption("--workspace-id <workspaceId>")
834
- .requiredOption("--spec-id <specId>")
835
- .action(async (options) => {
836
- if (hasWorkspaceReadToken(dependencies.environment)) {
837
- exitCode = rejectTokenWrite(dependencies);
838
- return;
839
- }
840
- const idempotencyKey = randomUUID();
841
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/specs/{specId}/publish", {
842
- params: {
843
- header: { "idempotency-key": idempotencyKey },
844
- path: options,
845
- },
846
- }), {
847
- ambiguousOutcomeMessage: "Spec Publish outcome is unknown; inspect the Spec Changelog before retrying",
848
- retryTransportOnce: true,
849
- });
850
- });
851
- spec
852
- .command("create")
853
- .requiredOption("--workspace-id <workspaceId>")
854
- .option("--capability-id <capabilityId>")
855
- .requiredOption("--feature-name <featureName>")
856
- .option("--source-references <sourceReferences>")
857
- .action(async (options) => {
858
- if (hasWorkspaceReadToken(dependencies.environment)) {
859
- exitCode = rejectTokenWrite(dependencies);
860
- return;
861
- }
862
- const idempotencyKey = randomUUID();
863
- const sourceReferences = parseSourceReferences(options.sourceReferences ?? "[]");
864
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/specs", {
865
- body: {
866
- capabilityId: options.capabilityId ?? null,
867
- featureName: options.featureName,
868
- sourceReferences,
869
- },
870
- params: {
871
- header: { "idempotency-key": idempotencyKey },
872
- path: { workspaceId: options.workspaceId },
873
- },
874
- }), {
875
- ambiguousOutcomeMessage: "Spec Creation outcome is unknown; inspect the Project directory before retrying",
876
- retryTransportOnce: true,
877
- });
878
- });
879
- spec
880
- .command("update")
881
- .requiredOption("--workspace-id <workspaceId>")
882
- .requiredOption("--spec-id <specId>")
883
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
884
- .option("--capability-id <capabilityId>")
885
- .option("--source-references <sourceReferences>")
886
- .action(async (options) => {
887
- if (hasWorkspaceReadToken(dependencies.environment)) {
888
- exitCode = rejectTokenWrite(dependencies);
889
- return;
890
- }
891
- if (options.capabilityId === undefined && options.sourceReferences === undefined) {
892
- throw invalidArgument("Spec update requires Metadata to change");
893
- }
894
- const sourceReferences = options.sourceReferences === undefined
895
- ? undefined
896
- : parseSourceReferences(options.sourceReferences);
897
- exitCode = await run((client) => client.PATCH("/v1/workspaces/{workspaceId}/specs/{specId}", {
898
- body: {
899
- ...(options.capabilityId === undefined
900
- ? {}
901
- : { capabilityId: options.capabilityId === "none" ? null : options.capabilityId }),
902
- ...(sourceReferences === undefined ? {} : { sourceReferences }),
903
- },
904
- params: {
905
- header: { "if-match": options.expectedVersion },
906
- path: options,
907
- },
908
- }));
909
- });
910
- spec
911
- .command("draft")
912
- .requiredOption("--workspace-id <workspaceId>")
913
- .requiredOption("--spec-id <specId>")
914
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
915
- .action(async (options) => {
916
- if (hasWorkspaceReadToken(dependencies.environment)) {
917
- exitCode = rejectTokenWrite(dependencies);
918
- return;
919
- }
920
- const idempotencyKey = randomUUID();
921
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/specs/{specId}/draft-session", {
922
- params: {
923
- header: {
924
- "idempotency-key": idempotencyKey,
925
- "if-match": options.expectedVersion,
926
- },
927
- path: options,
928
- },
929
- }), {
930
- ambiguousOutcomeMessage: "Spec Draft Session outcome is unknown; read the Spec before retrying",
931
- retryTransportOnce: true,
932
- });
933
- });
934
- spec
935
- .command("state")
936
- .requiredOption("--workspace-id <workspaceId>")
937
- .requiredOption("--spec-id <specId>")
938
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
939
- .requiredOption("--state <state>", "Ready or Unavailable", parseSpecState)
940
- .option("--unavailability-reason <unavailabilityReason>")
941
- .action(async (options) => {
942
- if (hasWorkspaceReadToken(dependencies.environment)) {
943
- exitCode = rejectTokenWrite(dependencies);
944
- return;
945
- }
946
- if (options.state === "Unavailable" && options.unavailabilityReason === undefined) {
947
- throw invalidArgument("Unavailable requires --unavailability-reason");
948
- }
949
- if (options.state === "Ready" && options.unavailabilityReason !== undefined) {
950
- throw invalidArgument("Ready does not accept --unavailability-reason");
951
- }
952
- exitCode = await run((client) => client.PATCH("/v1/workspaces/{workspaceId}/specs/{specId}/state", {
953
- body: options.state === "Ready"
954
- ? { state: "Ready" }
955
- : {
956
- state: "Unavailable",
957
- unavailabilityReason: options.unavailabilityReason ?? "",
958
- },
959
- params: {
960
- header: { "if-match": options.expectedVersion },
961
- path: options,
962
- },
963
- }));
964
- });
965
- spec
966
- .command("rollback")
967
- .requiredOption("--workspace-id <workspaceId>")
968
- .requiredOption("--spec-id <specId>")
969
- .requiredOption("--revision-id <revisionId>")
970
- .action(async (options) => {
971
- if (hasWorkspaceReadToken(dependencies.environment)) {
972
- exitCode = rejectTokenWrite(dependencies);
973
- return;
974
- }
975
- const idempotencyKey = randomUUID();
976
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/specs/{specId}/rollback", {
977
- body: { revisionId: options.revisionId },
978
- params: {
979
- header: { "idempotency-key": idempotencyKey },
980
- path: options,
981
- },
982
- }), {
983
- ambiguousOutcomeMessage: "Spec Rollback outcome is unknown; inspect the Spec Changelog before retrying",
984
- retryTransportOnce: true,
985
- });
986
- });
987
- spec
988
- .command("delete")
989
- .requiredOption("--workspace-id <workspaceId>")
990
- .requiredOption("--spec-id <specId>")
991
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
992
- .action(async (options) => {
993
- if (hasWorkspaceReadToken(dependencies.environment)) {
994
- exitCode = rejectTokenWrite(dependencies);
995
- return;
996
- }
997
- exitCode = await run(async (client) => withSuccessData(await client.DELETE("/v1/workspaces/{workspaceId}/specs/{specId}", {
998
- params: {
999
- header: { "if-match": options.expectedVersion },
1000
- path: options,
1001
- },
1002
- }), { deleted: { specId: options.specId } }));
1003
- });
1004
- const workspaceGlossary = workspace.command("glossary");
1005
- workspaceGlossary
1006
- .command("revision")
1007
- .requiredOption("--workspace-id <workspaceId>")
1008
- .requiredOption("--revision-id <revisionId>")
1009
- .action(async (options) => {
1010
- exitCode = await run((client) => client.GET(hasWorkspaceReadToken(dependencies.environment)
1011
- ? "/v1/workspaces/{workspaceId}/published/glossary/revisions/{revisionId}"
1012
- : "/v1/workspaces/{workspaceId}/glossary/revisions/{revisionId}", { params: { path: options } }));
1013
- });
1014
- workspaceGlossary
1015
- .command("read")
1016
- .requiredOption("--workspace-id <workspaceId>")
1017
- .action(async (options) => {
1018
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/glossary", {
1019
- params: { path: { workspaceId: options.workspaceId } },
1020
- }), { rejectWorkspaceReadToken: true });
1021
- });
1022
- workspaceGlossary
1023
- .command("changelog")
1024
- .requiredOption("--workspace-id <workspaceId>")
1025
- .action(async (options) => {
1026
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/glossary/changelog", {
1027
- params: { path: { workspaceId: options.workspaceId } },
1028
- }), { rejectWorkspaceReadToken: true });
1029
- });
1030
- workspaceGlossary
1031
- .command("draft")
1032
- .requiredOption("--workspace-id <workspaceId>")
1033
- .action(async (options) => {
1034
- if (hasWorkspaceReadToken(dependencies.environment)) {
1035
- exitCode = rejectTokenWrite(dependencies);
1036
- return;
1037
- }
1038
- const idempotencyKey = randomUUID();
1039
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/glossary/draft-session", {
1040
- params: {
1041
- header: { "idempotency-key": idempotencyKey },
1042
- path: { workspaceId: options.workspaceId },
1043
- },
1044
- }), {
1045
- ambiguousOutcomeMessage: "Glossary Draft Session outcome is unknown; read the Glossary before retrying",
1046
- retryTransportOnce: true,
1047
- });
1048
- });
1049
- workspaceGlossary
1050
- .command("edit")
1051
- .requiredOption("--workspace-id <workspaceId>")
1052
- .requiredOption("--entries <entries>")
1053
- .option("--agent-revision <agentRevision>")
1054
- .option("--agent-model <agentModel>")
1055
- .option("--source-reference-ids <sourceReferenceIds>")
1056
- .action(async (options) => {
1057
- if (hasWorkspaceReadToken(dependencies.environment)) {
1058
- exitCode = rejectTokenWrite(dependencies);
1059
- return;
1060
- }
1061
- const entries = parseGlossaryEntries(options.entries);
1062
- exitCode = await run((client) => client.PUT("/v1/workspaces/{workspaceId}/glossary/draft", {
1063
- body: { entries, provenance: toAgentProvenance(options) },
1064
- params: { path: { workspaceId: options.workspaceId } },
1065
- }));
1066
- });
1067
- workspaceGlossary
1068
- .command("publish")
1069
- .requiredOption("--workspace-id <workspaceId>")
1070
- .option("--entry-ids <entryIds...>", "Publish only the selected term changes")
1071
- .action(async (options) => {
1072
- if (hasWorkspaceReadToken(dependencies.environment)) {
1073
- exitCode = rejectTokenWrite(dependencies);
1074
- return;
1075
- }
1076
- const idempotencyKey = randomUUID();
1077
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/glossary/publish", {
1078
- body: options.entryIds === undefined ? {} : { entryIds: options.entryIds },
1079
- params: {
1080
- header: { "idempotency-key": idempotencyKey },
1081
- path: { workspaceId: options.workspaceId },
1082
- },
1083
- }), {
1084
- ambiguousOutcomeMessage: "Glossary Publish outcome is unknown; inspect the Glossary Changelog before retrying",
1085
- retryTransportOnce: true,
1086
- });
1087
- });
1088
- workspaceGlossary
1089
- .command("rollback")
1090
- .requiredOption("--workspace-id <workspaceId>")
1091
- .requiredOption("--revision-id <revisionId>")
1092
- .action(async (options) => {
1093
- if (hasWorkspaceReadToken(dependencies.environment)) {
1094
- exitCode = rejectTokenWrite(dependencies);
1095
- return;
1096
- }
1097
- const idempotencyKey = randomUUID();
1098
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/glossary/rollback", {
1099
- body: { revisionId: options.revisionId },
1100
- params: {
1101
- header: { "idempotency-key": idempotencyKey },
1102
- path: { workspaceId: options.workspaceId },
1103
- },
1104
- }), {
1105
- ambiguousOutcomeMessage: "Glossary Rollback outcome is unknown; inspect the Glossary Changelog before retrying",
1106
- retryTransportOnce: true,
1107
- });
1108
- });
1109
- workspace
1110
- .command("context")
1111
- .requiredOption("--workspace-id <workspaceId>")
1112
- .action(async (options) => {
1113
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/knowledge-context", {
1114
- params: { path: { workspaceId: options.workspaceId } },
1115
- }), { rejectWorkspaceReadToken: true });
1116
- });
1117
- const proposal = program.command("proposal");
1118
- proposal
1119
- .command("create-spec")
1120
- .requiredOption("--workspace-id <workspaceId>")
1121
- .requiredOption("--spec-id <specId>")
1122
- .requiredOption("--baseline-content <baselineContent>")
1123
- .requiredOption("--proposed-content <proposedContent>")
1124
- .option("--agent-revision <agentRevision>")
1125
- .option("--agent-model <agentModel>")
1126
- .option("--source-reference-ids <sourceReferenceIds>")
1127
- .action(async (options) => {
1128
- if (hasWorkspaceReadToken(dependencies.environment)) {
1129
- exitCode = rejectTokenWrite(dependencies);
1130
- return;
1131
- }
1132
- const idempotencyKey = randomUUID();
1133
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/draft-proposals", {
1134
- body: {
1135
- baselineContent: options.baselineContent,
1136
- kind: "Spec",
1137
- proposedContent: options.proposedContent,
1138
- provenance: toAgentProvenance(options),
1139
- specId: options.specId,
1140
- },
1141
- params: {
1142
- header: { "idempotency-key": idempotencyKey },
1143
- path: { workspaceId: options.workspaceId },
1144
- },
1145
- }), {
1146
- ambiguousOutcomeMessage: "Draft Proposal Creation outcome is unknown; list open Proposals before retrying",
1147
- retryTransportOnce: true,
1148
- });
1149
- });
1150
- proposal
1151
- .command("create-glossary")
1152
- .requiredOption("--workspace-id <workspaceId>")
1153
- .requiredOption("--baseline-entries <baselineEntries>")
1154
- .requiredOption("--proposed-entries <proposedEntries>")
1155
- .option("--agent-revision <agentRevision>")
1156
- .option("--agent-model <agentModel>")
1157
- .option("--source-reference-ids <sourceReferenceIds>")
1158
- .action(async (options) => {
1159
- if (hasWorkspaceReadToken(dependencies.environment)) {
1160
- exitCode = rejectTokenWrite(dependencies);
1161
- return;
1162
- }
1163
- const idempotencyKey = randomUUID();
1164
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/draft-proposals", {
1165
- body: {
1166
- baselineEntries: parseGlossaryEntries(options.baselineEntries),
1167
- kind: "Glossary",
1168
- proposedEntries: parseGlossaryEntries(options.proposedEntries),
1169
- provenance: toAgentProvenance(options),
1170
- },
1171
- params: {
1172
- header: { "idempotency-key": idempotencyKey },
1173
- path: { workspaceId: options.workspaceId },
1174
- },
1175
- }), {
1176
- ambiguousOutcomeMessage: "Draft Proposal Creation outcome is unknown; list open Proposals before retrying",
1177
- retryTransportOnce: true,
1178
- });
1179
- });
1180
- proposal
1181
- .command("list")
1182
- .requiredOption("--workspace-id <workspaceId>")
1183
- .option("--target-kind <targetKind>", "Spec or Glossary", parseProposalTargetKind)
1184
- .option("--spec-id <specId>")
1185
- .option("--status <status>", "Open, Applied, or Discarded", parseProposalStatus)
1186
- .action(async (options) => {
1187
- if ((options.targetKind === "Spec" && options.specId === undefined) ||
1188
- (options.targetKind !== "Spec" && options.specId !== undefined)) {
1189
- throw invalidArgument("--spec-id requires --target-kind Spec");
1190
- }
1191
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/draft-proposals", {
1192
- params: {
1193
- path: { workspaceId: options.workspaceId },
1194
- query: {
1195
- ...(options.specId === undefined ? {} : { specId: options.specId }),
1196
- ...(options.status === undefined ? {} : { status: options.status }),
1197
- ...(options.targetKind === undefined ? {} : { targetKind: options.targetKind }),
1198
- },
1199
- },
1200
- }));
1201
- });
1202
- proposal
1203
- .command("apply")
1204
- .requiredOption("--workspace-id <workspaceId>")
1205
- .requiredOption("--proposal-id <proposalId>")
1206
- .option("--change-ids <changeIds>")
1207
- .action(async (options) => {
1208
- if (hasWorkspaceReadToken(dependencies.environment)) {
1209
- exitCode = rejectTokenWrite(dependencies);
1210
- return;
1211
- }
1212
- const idempotencyKey = randomUUID();
1213
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/draft-proposals/{proposalId}/apply", {
1214
- body: {
1215
- changeIds: options.changeIds === undefined
1216
- ? null
1217
- : parseStringArray(options.changeIds, "change IDs"),
1218
- },
1219
- params: {
1220
- header: { "idempotency-key": idempotencyKey },
1221
- path: {
1222
- workspaceId: options.workspaceId,
1223
- proposalId: options.proposalId,
1224
- },
1225
- },
1226
- }), {
1227
- ambiguousOutcomeMessage: "Draft Proposal Apply outcome is unknown; reread the Proposal and Working Draft",
1228
- retryTransportOnce: true,
1229
- });
1230
- });
1231
- proposal
1232
- .command("discard")
1233
- .requiredOption("--workspace-id <workspaceId>")
1234
- .requiredOption("--proposal-id <proposalId>")
1235
- .action(async (options) => {
1236
- if (hasWorkspaceReadToken(dependencies.environment)) {
1237
- exitCode = rejectTokenWrite(dependencies);
1238
- return;
1239
- }
1240
- const idempotencyKey = randomUUID();
1241
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/draft-proposals/{proposalId}/discard", {
1242
- params: {
1243
- header: { "idempotency-key": idempotencyKey },
1244
- path: {
1245
- workspaceId: options.workspaceId,
1246
- proposalId: options.proposalId,
1247
- },
1248
- },
1249
- }), {
1250
- ambiguousOutcomeMessage: "Draft Proposal Discard outcome is unknown; reread the Proposal",
1251
- retryTransportOnce: true,
1252
- });
1253
- });
1254
- program
1255
- .command("authoring-history")
1256
- .requiredOption("--workspace-id <workspaceId>")
1257
- .action(async (options) => {
1258
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/authoring-history", { params: { path: options } }));
1259
- });
1260
- const capability = program.command("capability");
1261
- capability
1262
- .command("create")
1263
- .requiredOption("--workspace-id <workspaceId>")
1264
- .requiredOption("--name <name>")
1265
- .option("--parent-id <parentId>")
1266
- .action(async (options) => {
1267
- if (hasWorkspaceReadToken(dependencies.environment)) {
1268
- exitCode = rejectTokenWrite(dependencies);
1269
- return;
1270
- }
1271
- const idempotencyKey = randomUUID();
1272
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/capabilities", {
1273
- body: {
1274
- name: options.name,
1275
- parentId: options.parentId ?? null,
1276
- },
1277
- params: {
1278
- header: { "idempotency-key": idempotencyKey },
1279
- path: { workspaceId: options.workspaceId },
1280
- },
1281
- }), {
1282
- ambiguousOutcomeMessage: "Capability Creation outcome is unknown; inspect the Project directory before retrying",
1283
- retryTransportOnce: true,
1284
- });
1285
- });
1286
- capability
1287
- .command("update")
1288
- .requiredOption("--workspace-id <workspaceId>")
1289
- .requiredOption("--capability-id <capabilityId>")
1290
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
1291
- .option("--name <name>")
1292
- .option("--parent-id <parentId>")
1293
- .option("--move-to-root")
1294
- .action(async (options) => {
1295
- if (hasWorkspaceReadToken(dependencies.environment)) {
1296
- exitCode = rejectTokenWrite(dependencies);
1297
- return;
1298
- }
1299
- if (options.parentId !== undefined && options.moveToRoot === true) {
1300
- throw invalidArgument("Capability update cannot combine --parent-id and --move-to-root");
1301
- }
1302
- if (options.name === undefined &&
1303
- options.parentId === undefined &&
1304
- options.moveToRoot !== true) {
1305
- throw invalidArgument("Capability update requires a change");
1306
- }
1307
- exitCode = await run((client) => client.PATCH("/v1/workspaces/{workspaceId}/capabilities/{capabilityId}", {
1308
- body: {
1309
- ...(options.name === undefined ? {} : { name: options.name }),
1310
- ...(options.moveToRoot === true
1311
- ? { parentId: null }
1312
- : options.parentId === undefined
1313
- ? {}
1314
- : { parentId: options.parentId }),
1315
- },
1316
- params: {
1317
- header: { "if-match": options.expectedVersion },
1318
- path: options,
1319
- },
1320
- }));
1321
- });
1322
- capability
1323
- .command("delete")
1324
- .option("--idempotency-key <key>", "Reuse this key when retrying the same deletion")
1325
- .requiredOption("--workspace-id <workspaceId>")
1326
- .requiredOption("--capability-id <capabilityId>")
1327
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
1328
- .action(async (options) => {
1329
- if (hasWorkspaceReadToken(dependencies.environment)) {
1330
- exitCode = rejectTokenWrite(dependencies);
1331
- return;
1332
- }
1333
- const idempotencyKey = options.idempotencyKey ?? randomUUID();
1334
- exitCode = await run(async (client) => withSuccessData(await client.DELETE("/v1/workspaces/{workspaceId}/capabilities/{capabilityId}", {
1335
- params: {
1336
- header: { "if-match": options.expectedVersion, "idempotency-key": idempotencyKey },
1337
- path: options,
1338
- },
1339
- }), { deleted: { capabilityId: options.capabilityId } }));
1340
- });
1341
- const workspaceFinding = workspace.command("finding");
1342
- workspaceFinding
1343
- .command("list")
1344
- .requiredOption("--workspace-id <workspaceId>")
1345
- .option("--spec-id <specId>")
1346
- .option("--status <status>", "Unresolved (or Proposed), Resolved or Dismissed; Confirmed and Stale are accepted as older names", parseFindingStatus)
1347
- .option("--awaiting-recheck", "Only open Findings whose cited content changed and await a recheck")
1348
- .option("--limit <limit>", "Maximum results", parseSearchLimit, 20)
1349
- .option("--cursor <cursor>")
1350
- .action(async (options) => {
1351
- exitCode = await run((client) => options.specId === undefined
1352
- ? client.GET("/v1/workspaces/{workspaceId}/findings", {
1353
- params: {
1354
- path: { workspaceId: options.workspaceId },
1355
- query: {
1356
- limit: options.limit,
1357
- ...(options.cursor === undefined ? {} : { cursor: options.cursor }),
1358
- ...(options.status === undefined ? {} : { status: options.status }),
1359
- ...(options.awaitingRecheck === true ? { awaitingRecheck: "true" } : {}),
1360
- },
1361
- },
1362
- })
1363
- : client.GET("/v1/workspaces/{workspaceId}/specs/{specId}/findings", {
1364
- params: {
1365
- path: { workspaceId: options.workspaceId, specId: options.specId },
1366
- query: {
1367
- limit: options.limit,
1368
- ...(options.cursor === undefined ? {} : { cursor: options.cursor }),
1369
- ...(options.status === undefined ? {} : { status: options.status }),
1370
- ...(options.awaitingRecheck === true ? { awaitingRecheck: "true" } : {}),
1371
- },
1372
- },
1373
- }), { rejectWorkspaceReadToken: true });
1374
- });
1375
- workspaceFinding
1376
- .command("read")
1377
- .requiredOption("--workspace-id <workspaceId>")
1378
- .requiredOption("--finding-id <findingId>")
1379
- .action(async (options) => {
1380
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/findings/{findingId}", {
1381
- params: { path: options },
1382
- }), { rejectWorkspaceReadToken: true });
1383
- });
1384
- workspaceFinding
1385
- .command("create")
1386
- .requiredOption("--workspace-id <workspaceId>")
1387
- .requiredOption("--input <input>")
1388
- .action(async (options) => {
1389
- if (hasWorkspaceReadToken(dependencies.environment)) {
1390
- exitCode = rejectTokenWrite(dependencies);
1391
- return;
1392
- }
1393
- const idempotencyKey = randomUUID();
1394
- const input = parseFindingInput(options.input);
1395
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/findings", {
1396
- body: input,
1397
- params: {
1398
- header: { "idempotency-key": idempotencyKey },
1399
- path: { workspaceId: options.workspaceId },
1400
- },
1401
- }), {
1402
- ambiguousOutcomeMessage: "Finding Creation outcome is unknown; inspect the Finding list before retrying",
1403
- retryTransportOnce: true,
1404
- });
1405
- });
1406
- for (const [commandName, status, description] of [
1407
- [
1408
- "confirm",
1409
- "Confirmed",
1410
- "Deprecated: an open Finding needs no confirmation; returns it unchanged",
1411
- ],
1412
- ["dismiss", "Dismissed", "Close an open Finding as not worth fixing"],
1413
- ["resolve", "Resolved", "Close an open Finding as fixed"],
1414
- ["reopen", "Proposed", "Reopen a Resolved or Dismissed Finding"],
1415
- ]) {
1416
- const command = workspaceFinding
1417
- .command(commandName)
1418
- .description(description)
1419
- .requiredOption("--workspace-id <workspaceId>")
1420
- .requiredOption("--finding-id <findingId>")
1421
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion);
1422
- if (status === "Proposed")
1423
- command.option("--note <note>", "Why it is reopened; the next recheck reads it");
1424
- command.action(async (options) => {
1425
- if (hasWorkspaceReadToken(dependencies.environment)) {
1426
- exitCode = rejectTokenWrite(dependencies);
1427
- return;
1428
- }
1429
- const idempotencyKey = randomUUID();
1430
- exitCode = await run((client) => client.PATCH("/v1/workspaces/{workspaceId}/findings/{findingId}/status", {
1431
- body: {
1432
- status,
1433
- ...(options.note === undefined ? {} : { note: options.note }),
1434
- },
1435
- params: {
1436
- header: {
1437
- "idempotency-key": idempotencyKey,
1438
- "if-match": options.expectedVersion,
1439
- },
1440
- path: { findingId: options.findingId, workspaceId: options.workspaceId },
1441
- },
1442
- }), {
1443
- ambiguousOutcomeMessage: "Finding disposition outcome is unknown; read the Finding before retrying",
1444
- retryTransportOnce: true,
1445
- });
1446
- });
1447
- }
1448
- workspaceFinding
1449
- .command("persists")
1450
- .description("Say a Finding awaiting a recheck still applies to the current Revision")
1451
- .requiredOption("--workspace-id <workspaceId>")
1452
- .requiredOption("--finding-id <findingId>")
1453
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
1454
- .action(async (options) => {
1455
- if (hasWorkspaceReadToken(dependencies.environment)) {
1456
- exitCode = rejectTokenWrite(dependencies);
1457
- return;
1458
- }
1459
- const idempotencyKey = randomUUID();
1460
- exitCode = await run((client) => client.PATCH("/v1/workspaces/{workspaceId}/findings/{findingId}/recheck", {
1461
- body: { outcome: "Persists" },
1462
- params: {
1463
- header: {
1464
- "idempotency-key": idempotencyKey,
1465
- "if-match": options.expectedVersion,
1466
- },
1467
- path: { findingId: options.findingId, workspaceId: options.workspaceId },
1468
- },
1469
- }), {
1470
- ambiguousOutcomeMessage: "Finding recheck answer outcome is unknown; read the Finding before retrying",
1471
- retryTransportOnce: true,
1472
- });
1473
- });
1474
- workspaceFinding
1475
- .command("handler")
1476
- .description("Retired: Findings no longer have a Handler")
1477
- .allowUnknownOption()
1478
- .allowExcessArguments()
1479
- .action(() => {
1480
- writeSkillError(dependencies, {
1481
- message: "Findings no longer have a Handler. Resolve or dismiss the Finding, or turn it into a Work Item with `finding follow-up`.",
1482
- reason: "Invalid Operation",
1483
- retryable: false,
1484
- });
1485
- exitCode = 2;
1486
- });
1487
- workspaceFinding
1488
- .command("follow-up")
1489
- .requiredOption("--workspace-id <workspaceId>")
1490
- .requiredOption("--finding-id <findingId>")
1491
- .requiredOption("--project-id <projectId>")
1492
- .requiredOption("--idempotency-key <key>")
1493
- .action(async (options) => {
1494
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/findings/{findingId}/work-item", {
1495
- body: { projectId: options.projectId },
1496
- params: {
1497
- path: { workspaceId: options.workspaceId, findingId: options.findingId },
1498
- header: { "idempotency-key": options.idempotencyKey },
1499
- },
1500
- }), { rejectWorkspaceReadToken: true });
1501
- });
1502
- workspaceFinding
1503
- .command("discussion")
1504
- .requiredOption("--workspace-id <workspaceId>")
1505
- .requiredOption("--finding-id <findingId>")
1506
- .action(async (options) => {
1507
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/findings/{findingId}/discussion", {
1508
- params: { path: options },
1509
- }), { rejectWorkspaceReadToken: true });
1510
- });
1511
- workspaceFinding
1512
- .command("comment")
1513
- .requiredOption("--workspace-id <workspaceId>")
1514
- .requiredOption("--finding-id <findingId>")
1515
- .requiredOption("--body <body>")
1516
- .option("--parent-id <parentId>")
1517
- .requiredOption("--idempotency-key <key>")
1518
- .action(async (options) => {
1519
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/findings/{findingId}/discussion", {
1520
- body: { body: options.body, parentId: options.parentId ?? null },
1521
- params: { path: options, header: { "idempotency-key": options.idempotencyKey } },
1522
- }), { rejectWorkspaceReadToken: true });
1523
- });
1524
- const workspaceReview = workspace.command("review");
1525
- workspaceReview
1526
- .command("request")
1527
- .requiredOption("--workspace-id <workspaceId>")
1528
- .requiredOption("--spec-id <specId>")
1529
- .option("--idempotency-key <key>")
1530
- .action(async (options) => {
1531
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/specs/{specId}/reviews", {
1532
- params: {
1533
- path: options,
1534
- header: { "idempotency-key": options.idempotencyKey ?? randomUUID() },
1535
- },
1536
- }), { rejectWorkspaceReadToken: true });
1537
- });
1538
- workspaceReview
1539
- .command("history")
1540
- .requiredOption("--workspace-id <workspaceId>")
1541
- .action(async (options) => {
1542
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/reviews", { params: { path: options } }), { rejectWorkspaceReadToken: true });
1543
- });
1544
- workspaceReview
1545
- .command("read")
1546
- .requiredOption("--workspace-id <workspaceId>")
1547
- .requiredOption("--review-id <reviewId>")
1548
- .action(async (options) => {
1549
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/reviews/{reviewId}", {
1550
- params: { path: options },
1551
- }), { rejectWorkspaceReadToken: true });
1552
- });
1553
- workspaceReview
1554
- .command("plan")
1555
- .requiredOption("--workspace-id <workspaceId>")
1556
- .action(async (options) => {
1557
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/review-schedule", { params: { path: options } }), { rejectWorkspaceReadToken: true });
1558
- });
1559
- workspaceReview
1560
- .command("configure")
1561
- .requiredOption("--workspace-id <workspaceId>")
1562
- .requiredOption("--expected-version <expectedVersion>", "Opaque version", parseOpaqueVersion)
1563
- .requiredOption("--input <input>", "Review plan JSON")
1564
- .action(async (options) => {
1565
- const body = reviewPlanInputSchema.parse(JSON.parse(options.input));
1566
- exitCode = await run((client) => client.PUT("/v1/workspaces/{workspaceId}/review-schedule", {
1567
- body,
1568
- params: { path: options, header: { "if-match": options.expectedVersion } },
1569
- }), { rejectWorkspaceReadToken: true });
1570
- });
1571
- workspaceReview
1572
- .command("finding-types")
1573
- .description("Show which Finding types the Review Agent reports in this Workspace")
1574
- .requiredOption("--workspace-id <workspaceId>")
1575
- .action(async (options) => {
1576
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/review-finding-types", {
1577
- params: { path: options },
1578
- }), { rejectWorkspaceReadToken: true });
1579
- });
1580
- workspaceReview
1581
- .command("configure-finding-types")
1582
- .description("Choose the Finding types the Review Agent reports (comma-separated)")
1583
- .requiredOption("--workspace-id <workspaceId>")
1584
- .requiredOption("--expected-version <expectedVersion>", "Opaque version", parseOpaqueVersion)
1585
- .requiredOption("--types <types>", "Contradiction, Conflict, Duplicate, Terminology, Unverifiable, Ambiguity", parseFindingTypeList)
1586
- .action(async (options) => {
1587
- exitCode = await run((client) => client.PUT("/v1/workspaces/{workspaceId}/review-finding-types", {
1588
- body: { enabledFindingTypes: [...options.types] },
1589
- params: { path: options, header: { "if-match": options.expectedVersion } },
1590
- }), { rejectWorkspaceReadToken: true });
1591
- });
1592
- const notification = program
1593
- .command("notification")
1594
- .description("Read and manage your personal task notifications");
1595
- notification.command("list").action(async () => {
1596
- if (hasWorkspaceReadToken(dependencies.environment)) {
1597
- exitCode = rejectWorkspaceReadTokenOperation(dependencies);
1598
- return;
1599
- }
1600
- exitCode = await run((client) => client.GET("/v1/notifications"));
1601
- });
1602
- notification
1603
- .command("create")
1604
- .option("--title <title>")
1605
- .option("--message <message>")
1606
- .option("--type <type>", "Notification type", "info")
1607
- .option("--event-data <json>", "JSON object for presentation", parseNotificationEventData)
1608
- .option("--related-entity-id <id>", "Public task ID or Workspace ID")
1609
- .option("--related-entity-type <type>", "task or workspace", (value) => {
1610
- if (value !== "task" && value !== "workspace")
1611
- throw invalidArgument("Notification target must be task or workspace");
1612
- return value;
1613
- })
1614
- .requiredOption("--idempotency-key <key>", "Reuse the same command key and inputs when retrying", parseNotificationUuid)
1615
- .action(async (options) => {
1616
- if (hasWorkspaceReadToken(dependencies.environment)) {
1617
- exitCode = rejectWorkspaceReadTokenOperation(dependencies);
1618
- return;
1619
- }
1620
- if ((options.relatedEntityId === undefined) !== (options.relatedEntityType === undefined))
1621
- throw invalidArgument("Notification target identity and type must be provided together");
1622
- exitCode = await run((client) => client.POST("/v1/notifications", {
1623
- body: {
1624
- type: options.type,
1625
- ...(options.title === undefined ? {} : { title: options.title }),
1626
- ...(options.message === undefined ? {} : { message: options.message }),
1627
- ...(options.eventData === undefined ? {} : { eventData: options.eventData }),
1628
- ...(options.relatedEntityId === undefined
1629
- ? {}
1630
- : { relatedEntityId: options.relatedEntityId }),
1631
- ...(options.relatedEntityType === undefined
1632
- ? {}
1633
- : { relatedEntityType: options.relatedEntityType }),
1634
- },
1635
- params: { header: { "idempotency-key": options.idempotencyKey } },
1636
- }), {
1637
- retryTransportOnce: true,
1638
- ambiguousOutcomeMessage: "Notification creation outcome is unknown; retry with the same inputs and command key",
1639
- });
1640
- });
1641
- notification
1642
- .command("read")
1643
- .requiredOption("--notification-id <id>", "Notification UUID returned by the list", parseNotificationUuid)
1644
- .requiredOption("--idempotency-key <key>", "Reuse the same key when retrying", parseNotificationUuid)
1645
- .action(async (options) => {
1646
- if (hasWorkspaceReadToken(dependencies.environment)) {
1647
- exitCode = rejectWorkspaceReadTokenOperation(dependencies);
1648
- return;
1649
- }
1650
- exitCode = await run((client) => client.PATCH("/v1/notifications/{notificationId}/read", {
1651
- params: {
1652
- path: { notificationId: options.notificationId },
1653
- header: { "idempotency-key": options.idempotencyKey },
1654
- },
1655
- }), {
1656
- retryTransportOnce: true,
1657
- ambiguousOutcomeMessage: "Notification read outcome is unknown; retry with the same notification and command key",
1658
- });
1659
- });
1660
- for (const action of ["read-all", "clear"]) {
1661
- notification
1662
- .command(action)
1663
- .requiredOption("--idempotency-key <key>", "Reuse the same key to avoid changing notifications that arrived after the first command", parseNotificationUuid)
1664
- .action(async (options) => {
1665
- if (hasWorkspaceReadToken(dependencies.environment)) {
1666
- exitCode = rejectWorkspaceReadTokenOperation(dependencies);
1667
- return;
1668
- }
1669
- const params = { header: { "idempotency-key": options.idempotencyKey } };
1670
- exitCode = await run((client) => action === "read-all"
1671
- ? client.PATCH("/v1/notifications/read", { params })
1672
- : client.DELETE("/v1/notifications", { params }), {
1673
- retryTransportOnce: true,
1674
- ambiguousOutcomeMessage: "Notification bulk command outcome is unknown; retry with the same command key",
1675
- });
1676
- });
1677
- }
1678
- const notificationPreferences = notification.command("preferences");
1679
- notificationPreferences.command("get").action(async () => {
1680
- if (hasWorkspaceReadToken(dependencies.environment)) {
1681
- exitCode = rejectWorkspaceReadTokenOperation(dependencies);
1682
- return;
1683
- }
1684
- exitCode = await run((client) => client.GET("/v1/notification-preferences"));
1685
- });
1686
- notificationPreferences
1687
- .command("update")
1688
- .requiredOption("--expected-version <version>", "Opaque preference version returned by get")
1689
- .requiredOption("--preferences <json>", "JSON category settings; omitted settings remain unchanged", parseNotificationPreferences)
1690
- .requiredOption("--idempotency-key <key>", "Reuse the same key and settings when retrying", parseNotificationUuid)
1691
- .action(async (options) => {
1692
- if (hasWorkspaceReadToken(dependencies.environment)) {
1693
- exitCode = rejectWorkspaceReadTokenOperation(dependencies);
1694
- return;
1695
- }
1696
- exitCode = await run((client) => client.PATCH("/v1/notification-preferences", {
1697
- body: options.preferences,
1698
- params: {
1699
- header: {
1700
- "idempotency-key": options.idempotencyKey,
1701
- "if-match": options.expectedVersion,
1702
- },
1703
- },
1704
- }), {
1705
- retryTransportOnce: true,
1706
- ambiguousOutcomeMessage: "Notification preference outcome is unknown; retry with the same settings and command key",
1707
- });
1708
- });
217
+ const workspace = registerWorkspaceCommands(context);
218
+ const project = registerProjectCommands(context);
219
+ const spec = registerSpecCommands(context);
220
+ registerWorkspaceGlossaryCommands(context, workspace);
221
+ registerProposalCommands(context);
222
+ registerCapabilityCommands(context);
223
+ registerWorkspaceFindingCommands(context, workspace);
224
+ registerWorkspaceReviewCommands(context, workspace);
225
+ registerNotificationCommands(context);
1709
226
  const workItem = program.command("work-item");
1710
227
  registerWorkItemAssetCommands(workItem, {
1711
228
  dependencies,
1712
229
  run,
1713
- setExitCode: (value) => {
1714
- exitCode = value;
1715
- },
230
+ setExitCode,
1716
231
  rejectWrite: () => rejectTokenWrite(dependencies),
1717
232
  });
1718
- const resourceRuntime = {
1719
- run,
1720
- setExitCode: (value) => {
1721
- exitCode = value;
1722
- },
1723
- parseOpaqueVersion,
1724
- parseLimit: parseSearchLimit,
1725
- };
1726
233
  registerSpecOwnerCommands(spec, resourceRuntime);
1727
234
  registerAcceptanceCommands(program, resourceRuntime, dependencies);
1728
235
  registerSpecDiscussionCommands(spec, resourceRuntime);
1729
236
  registerProjectAdministrationCommands(project, workspace, resourceRuntime);
1730
- program
1731
- .command("search-global")
1732
- .description("Search all currently accessible objects; preserves server totals and cursor")
1733
- .requiredOption("--query <query>")
1734
- .option("--types <types>", "Comma-separated kinds: project,work-item,capability,spec,glossary,screen,journey,user")
1735
- .option("--limit <limit>", "Server page size (1–100)", resourceRuntime.parseLimit, 20)
1736
- .option("--cursor <cursor>")
1737
- .action(async (options) => {
1738
- resourceRuntime.setExitCode(await resourceRuntime.run((client) => client.GET("/v1/search", {
1739
- params: {
1740
- query: {
1741
- query: options.query,
1742
- limit: options.limit,
1743
- ...(options.cursor === undefined ? {} : { cursor: options.cursor }),
1744
- ...(options.types === undefined ? {} : { types: options.types }),
1745
- },
1746
- },
1747
- }), { rejectWorkspaceReadToken: true }));
1748
- });
237
+ registerGlobalSearchCommands(program, resourceRuntime);
1749
238
  registerWorkItemQueryCommands(workItem, workspace, resourceRuntime);
1750
239
  registerWorkItemDeliveryCommands(workItem, project, resourceRuntime);
1751
240
  registerProductMapCommands(program, {
1752
241
  dependencies,
1753
242
  run,
1754
- setExitCode: (value) => {
1755
- exitCode = value;
1756
- },
243
+ setExitCode,
1757
244
  canWrite: () => !hasWorkspaceReadToken(dependencies.environment),
1758
245
  rejectWrite: () => rejectTokenWrite(dependencies),
1759
246
  parseOpaqueVersion,
1760
247
  });
1761
248
  registerWorkItemResourceLinkCommands(workItem, spec, {
1762
249
  run,
1763
- setExitCode: (value) => {
1764
- exitCode = value;
1765
- },
250
+ setExitCode,
1766
251
  canWrite: () => !hasWorkspaceReadToken(dependencies.environment),
1767
252
  rejectWrite: () => rejectTokenWrite(dependencies),
1768
253
  parseOpaqueVersion,
@@ -1770,9 +255,7 @@ export async function runCli(arguments_, originalDependencies) {
1770
255
  });
1771
256
  registerWorkItemWatcherCommands(workItem, {
1772
257
  run,
1773
- setExitCode: (value) => {
1774
- exitCode = value;
1775
- },
258
+ setExitCode,
1776
259
  canWrite: () => !hasWorkspaceReadToken(dependencies.environment),
1777
260
  rejectWrite: () => rejectTokenWrite(dependencies),
1778
261
  });
@@ -1794,9 +277,7 @@ export async function runCli(arguments_, originalDependencies) {
1794
277
  const contextRuntime = {
1795
278
  dependencies,
1796
279
  run,
1797
- setExitCode: (value) => {
1798
- exitCode = value;
1799
- },
280
+ setExitCode,
1800
281
  canWrite: () => !hasWorkspaceReadToken(dependencies.environment),
1801
282
  rejectWrite: () => rejectTokenWrite(dependencies),
1802
283
  isReadToken: () => hasWorkspaceReadToken(dependencies.environment),
@@ -1808,1616 +289,13 @@ export async function runCli(arguments_, originalDependencies) {
1808
289
  .command("group-notification")
1809
290
  .description("Manage Lark group chat notifications for a Workspace, Project or Version"), contextRuntime);
1810
291
  registerSpecLabelCommands(spec, contextRuntime);
1811
- const workItemComment = workItem
1812
- .command("comment")
1813
- .description("Read and manage authored task comments");
1814
- workItemComment
1815
- .command("list")
1816
- .requiredOption("--project-id <projectId>")
1817
- .requiredOption("--work-item-id <workItemId>")
1818
- .option("--limit <limit>", "Maximum results, 1 through 100", parseSearchLimit, 50)
1819
- .option("--cursor <cursor>", "Opaque cursor returned by the previous page")
1820
- .action(async (options) => {
1821
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/work-items/{workItemId}/comments", {
1822
- params: {
1823
- path: { projectId: options.projectId, workItemId: options.workItemId },
1824
- query: {
1825
- limit: options.limit,
1826
- ...(options.cursor === undefined ? {} : { cursor: options.cursor }),
1827
- },
1828
- },
1829
- }));
1830
- });
1831
- workItem
1832
- .command("discussion")
1833
- .description("Read comments and immutable activity newest first")
1834
- .requiredOption("--project-id <projectId>")
1835
- .requiredOption("--work-item-id <workItemId>")
1836
- .option("--limit <limit>", "Maximum results, 1 through 100", parseSearchLimit, 50)
1837
- .option("--cursor <cursor>", "Opaque cursor returned by the previous page")
1838
- .action(async (options) => {
1839
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/work-items/{workItemId}/discussion", {
1840
- params: {
1841
- path: { projectId: options.projectId, workItemId: options.workItemId },
1842
- query: {
1843
- limit: options.limit,
1844
- ...(options.cursor === undefined ? {} : { cursor: options.cursor }),
1845
- },
1846
- },
1847
- }));
1848
- });
1849
- workItemComment
1850
- .command("create")
1851
- .requiredOption("--project-id <projectId>")
1852
- .requiredOption("--work-item-id <workItemId>")
1853
- .requiredOption("--content <markdown>", "Markdown comment body, up to 20000 characters", parseCommentContent)
1854
- .option("--mention <id>", "User ID, Agent ID, or Agent slug to mention; repeat for several", collectOption, [])
1855
- .requiredOption("--idempotency-key <key>", "Reuse the same key and inputs when retrying", parseCommentCommandKey)
1856
- .action(async (options) => {
1857
- if (hasWorkspaceReadToken(dependencies.environment)) {
1858
- exitCode = rejectTokenWrite(dependencies);
1859
- return;
1860
- }
1861
- const mentions = [...new Set(options.mention.map((item) => item.trim()).filter(Boolean))];
1862
- exitCode = await run((client) => client.POST("/v1/projects/{projectId}/work-items/{workItemId}/comments", {
1863
- body: {
1864
- content: options.content,
1865
- ...(mentions.length === 0 ? {} : { mentions }),
1866
- },
1867
- params: {
1868
- path: { projectId: options.projectId, workItemId: options.workItemId },
1869
- header: { "idempotency-key": options.idempotencyKey },
1870
- },
1871
- }), {
1872
- retryTransportOnce: true,
1873
- ambiguousOutcomeMessage: "Comment creation outcome is unknown; retry with the same inputs and command key",
1874
- });
1875
- });
1876
- workItemComment
1877
- .command("update")
1878
- .requiredOption("--project-id <projectId>")
1879
- .requiredOption("--work-item-id <workItemId>")
1880
- .requiredOption("--comment-id <commentId>", "Identifier returned by comments", parseCommentId)
1881
- .requiredOption("--content <markdown>", "Markdown comment body, up to 20000 characters", parseCommentContent)
1882
- .option("--mention <id>", "User ID, Agent ID, or Agent slug to mention; repeat for several", collectOption, [])
1883
- .requiredOption("--expected-version <version>", "Opaque comment version returned by SpecFlow", parseOpaqueVersion)
1884
- .requiredOption("--idempotency-key <key>", "Reuse the same key and inputs when retrying", parseCommentCommandKey)
1885
- .action(async (options) => {
1886
- if (hasWorkspaceReadToken(dependencies.environment)) {
1887
- exitCode = rejectTokenWrite(dependencies);
1888
- return;
1889
- }
1890
- const mentions = [...new Set(options.mention.map((item) => item.trim()).filter(Boolean))];
1891
- exitCode = await run((client) => client.PATCH("/v1/projects/{projectId}/work-items/{workItemId}/comments/{commentId}", {
1892
- body: {
1893
- content: options.content,
1894
- ...(mentions.length === 0 ? {} : { mentions }),
1895
- },
1896
- params: {
1897
- path: {
1898
- projectId: options.projectId,
1899
- workItemId: options.workItemId,
1900
- commentId: options.commentId,
1901
- },
1902
- header: {
1903
- "idempotency-key": options.idempotencyKey,
1904
- "if-match": options.expectedVersion,
1905
- },
1906
- },
1907
- }), {
1908
- retryTransportOnce: true,
1909
- ambiguousOutcomeMessage: "Comment edit outcome is unknown; reread the comment or retry the same inputs and command key",
1910
- });
1911
- });
1912
- workItemComment
1913
- .command("delete")
1914
- .requiredOption("--project-id <projectId>")
1915
- .requiredOption("--work-item-id <workItemId>")
1916
- .requiredOption("--comment-id <commentId>", "Identifier returned by comments", parseCommentId)
1917
- .requiredOption("--expected-version <version>", "Opaque comment version returned by SpecFlow", parseOpaqueVersion)
1918
- .requiredOption("--idempotency-key <key>", "Reuse the same key and inputs when retrying", parseCommentCommandKey)
1919
- .action(async (options) => {
1920
- if (hasWorkspaceReadToken(dependencies.environment)) {
1921
- exitCode = rejectTokenWrite(dependencies);
1922
- return;
1923
- }
1924
- exitCode = await run((client) => client.DELETE("/v1/projects/{projectId}/work-items/{workItemId}/comments/{commentId}", {
1925
- params: {
1926
- path: {
1927
- projectId: options.projectId,
1928
- workItemId: options.workItemId,
1929
- commentId: options.commentId,
1930
- },
1931
- header: {
1932
- "idempotency-key": options.idempotencyKey,
1933
- "if-match": options.expectedVersion,
1934
- },
1935
- },
1936
- }), {
1937
- retryTransportOnce: true,
1938
- ambiguousOutcomeMessage: "Comment deletion outcome is unknown; reread the comment or retry the same inputs and command key",
1939
- });
1940
- });
1941
- const workItemRelation = workItem
1942
- .command("relation")
1943
- .description("Manage subtask, blocking and related task links");
1944
- workItemRelation
1945
- .command("list")
1946
- .requiredOption("--project-id <projectId>")
1947
- .requiredOption("--work-item-id <workItemId>")
1948
- .action(async (options) => {
1949
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/work-items/{workItemId}/relations", {
1950
- params: { path: options },
1951
- }), { project: (data) => relationListOutput(data, outputMode, warnMissingUrl) });
1952
- });
1953
- workItemRelation
1954
- .command("create")
1955
- .addHelpText("after", "\nExample: specflow work-item relation create --project-id PROJECT --work-item-id GON-78 --target-project-id PROJECT --target-work-item-id GON-79 --type subtask --idempotency-key KEY\n")
1956
- .requiredOption("--project-id <projectId>")
1957
- .requiredOption("--work-item-id <workItemId>")
1958
- .requiredOption("--target-project-id <projectId>", "Target task's current Project", parseProjectId)
1959
- .requiredOption("--target-work-item-id <workItemId>", "Target task's public identity", parseWorkItemId)
1960
- .option("--type <type>", "subtask (source=parent, target=child), blocks, related or duplicate", (value) => {
1961
- const result = z.enum(["subtask", "blocks", "related", "duplicate"]).safeParse(value);
1962
- if (!result.success)
1963
- throw invalidArgument("Relation type must be subtask, blocks, related or duplicate");
1964
- return result.data;
1965
- })
1966
- .option("--direction <direction>", "Direction from the current task: related, subtask, parent, blocks or blocked-by", (value) => {
1967
- const result = z
1968
- .enum(["related", "subtask", "parent", "blocks", "blocked-by"])
1969
- .safeParse(value);
1970
- if (!result.success)
1971
- throw invalidArgument("Invalid relation direction");
1972
- return result.data;
1973
- })
1974
- .option("--replace-parent", "Replace the existing parent when linking a subtask")
1975
- .requiredOption("--idempotency-key <key>", "Reuse the same key and inputs when retrying", parseRelationCommandKey)
1976
- .action(async (options) => {
1977
- if (hasWorkspaceReadToken(dependencies.environment)) {
1978
- exitCode = rejectTokenWrite(dependencies);
1979
- return;
1980
- }
1981
- if (options.direction === undefined && options.type === undefined)
1982
- throw invalidArgument("Provide --type or --direction");
1983
- const relationBody = options.direction === undefined
1984
- ? options.type === undefined
1985
- ? (() => {
1986
- throw invalidArgument("Provide --type or --direction");
1987
- })()
1988
- : { relationType: options.type }
1989
- : { direction: options.direction };
1990
- exitCode = await run((client) => client.POST("/v1/projects/{projectId}/work-items/{workItemId}/relations", {
1991
- body: {
1992
- targetProjectId: options.targetProjectId,
1993
- targetWorkItemId: options.targetWorkItemId,
1994
- ...relationBody,
1995
- ...(options.replaceParent === undefined
1996
- ? {}
1997
- : { replaceParent: options.replaceParent }),
1998
- },
1999
- params: {
2000
- path: { projectId: options.projectId, workItemId: options.workItemId },
2001
- header: { "idempotency-key": options.idempotencyKey },
2002
- },
2003
- }), {
2004
- project: (data) => relationReceiptOutput(data, outputMode, warnMissingUrl),
2005
- retryTransportOnce: true,
2006
- ambiguousOutcomeMessage: "Relation creation outcome is unknown; retry with the same inputs and command key",
2007
- });
2008
- });
2009
- workItem
2010
- .command("subtask")
2011
- .command("link")
2012
- .description("Link parent (source) to child (target), including across Projects")
2013
- .requiredOption("--project-id <projectId>", "Parent Project")
2014
- .requiredOption("--parent <workItemId>", "Parent public Work Item ID", parseWorkItemId)
2015
- .requiredOption("--child <workItemId>", "Child public Work Item ID", parseWorkItemId)
2016
- .option("--child-project-id <projectId>", "Child Project, defaults to parent Project", parseProjectId)
2017
- .requiredOption("--idempotency-key <key>", "Reuse the same key and inputs when retrying", parseRelationCommandKey)
2018
- .action(async (options) => {
2019
- if (hasWorkspaceReadToken(dependencies.environment)) {
2020
- exitCode = rejectTokenWrite(dependencies);
2021
- return;
2022
- }
2023
- exitCode = await run((client) => client.POST("/v1/projects/{projectId}/work-items/{workItemId}/relations", {
2024
- body: {
2025
- relationType: "subtask",
2026
- targetProjectId: options.childProjectId ?? options.projectId,
2027
- targetWorkItemId: options.child,
2028
- },
2029
- params: {
2030
- path: { projectId: options.projectId, workItemId: options.parent },
2031
- header: { "idempotency-key": options.idempotencyKey },
2032
- },
2033
- }), {
2034
- retryTransportOnce: true,
2035
- project: (data) => relationReceiptOutput(data, outputMode, warnMissingUrl),
2036
- ambiguousOutcomeMessage: "Relation creation outcome is unknown; retry with the same inputs and command key",
2037
- });
2038
- });
2039
- workItemRelation
2040
- .command("delete")
2041
- .requiredOption("--project-id <projectId>")
2042
- .requiredOption("--work-item-id <workItemId>")
2043
- .requiredOption("--peer-project-id <projectId>", "Other endpoint's current Project", parseProjectId)
2044
- .requiredOption("--relation-id <relationId>", "Relation identifier returned by list", (value) => {
2045
- if (!z.uuid().safeParse(value).success)
2046
- throw invalidArgument("Relation ID must be a UUID returned by SpecFlow");
2047
- return value;
2048
- })
2049
- .requiredOption("--expected-version <expectedVersion>", "Opaque relation version returned by SpecFlow", parseOpaqueVersion)
2050
- .requiredOption("--idempotency-key <key>", "Reuse the same key and inputs when retrying", parseRelationCommandKey)
2051
- .action(async (options) => {
2052
- if (hasWorkspaceReadToken(dependencies.environment)) {
2053
- exitCode = rejectTokenWrite(dependencies);
2054
- return;
2055
- }
2056
- exitCode = await run((client) => client.DELETE("/v1/projects/{projectId}/work-items/{workItemId}/relations/{relationId}", {
2057
- params: {
2058
- path: {
2059
- projectId: options.projectId,
2060
- workItemId: options.workItemId,
2061
- relationId: options.relationId,
2062
- },
2063
- query: { peerProjectId: options.peerProjectId },
2064
- header: {
2065
- "idempotency-key": options.idempotencyKey,
2066
- "if-match": options.expectedVersion,
2067
- },
2068
- },
2069
- }), {
2070
- retryTransportOnce: true,
2071
- ambiguousOutcomeMessage: "Relation removal outcome is unknown; retry with the same inputs and command key",
2072
- });
2073
- });
2074
- workItemRelation
2075
- .command("duplicate")
2076
- .description("Mark or cancel a duplicate Work Item mark")
2077
- .command("mark")
2078
- .requiredOption("--project-id <projectId>")
2079
- .requiredOption("--work-item-id <workItemId>")
2080
- .requiredOption("--target-project-id <projectId>", "Project containing the retained task")
2081
- .requiredOption("--target-work-item-id <workItemId>", "Retained task public identity", parseWorkItemId)
2082
- .requiredOption("--expected-version <expectedVersion>", "Current task version", parseOpaqueVersion)
2083
- .requiredOption("--idempotency-key <key>", "Reuse the same key and inputs when retrying", parseRelationCommandKey)
2084
- .action(async (options) => {
2085
- if (hasWorkspaceReadToken(dependencies.environment)) {
2086
- exitCode = rejectTokenWrite(dependencies);
2087
- return;
2088
- }
2089
- const expectedVersion = Number(options.expectedVersion);
2090
- if (!Number.isInteger(expectedVersion) || expectedVersion < 1)
2091
- throw invalidArgument("Expected version must be a positive integer");
2092
- exitCode = await run((client) => client.POST("/v1/projects/{projectId}/work-items/{workItemId}/relations/duplicate", {
2093
- body: {
2094
- targetProjectId: options.targetProjectId,
2095
- targetWorkItemId: options.targetWorkItemId,
2096
- expectedVersion,
2097
- },
2098
- params: {
2099
- path: { projectId: options.projectId, workItemId: options.workItemId },
2100
- header: { "idempotency-key": options.idempotencyKey },
2101
- },
2102
- }), {
2103
- project: (data) => itemOutput(data, outputMode, warnMissingUrl),
2104
- retryTransportOnce: true,
2105
- ambiguousOutcomeMessage: "Duplicate mark outcome is unknown; retry with the same inputs and command key",
2106
- });
2107
- });
2108
- workItemRelation
2109
- .command("duplicate-cancel")
2110
- .description("Cancel a duplicate Work Item mark")
2111
- .requiredOption("--project-id <projectId>")
2112
- .requiredOption("--work-item-id <workItemId>")
2113
- .requiredOption("--expected-version <expectedVersion>", "Current task version", parseOpaqueVersion)
2114
- .requiredOption("--idempotency-key <key>", "Reuse the same key and inputs when retrying", parseRelationCommandKey)
2115
- .action(async (options) => {
2116
- if (hasWorkspaceReadToken(dependencies.environment)) {
2117
- exitCode = rejectTokenWrite(dependencies);
2118
- return;
2119
- }
2120
- const expectedVersion = Number(options.expectedVersion);
2121
- if (!Number.isInteger(expectedVersion) || expectedVersion < 1)
2122
- throw invalidArgument("Expected version must be a positive integer");
2123
- exitCode = await run((client) => client.DELETE("/v1/projects/{projectId}/work-items/{workItemId}/relations/duplicate", {
2124
- params: {
2125
- path: { projectId: options.projectId, workItemId: options.workItemId },
2126
- query: { expectedVersion },
2127
- header: { "idempotency-key": options.idempotencyKey },
2128
- },
2129
- }), {
2130
- project: (data) => itemOutput(data, outputMode, warnMissingUrl),
2131
- retryTransportOnce: true,
2132
- ambiguousOutcomeMessage: "Duplicate cancellation outcome is unknown; retry with the same inputs and command key",
2133
- });
2134
- });
2135
- workItemCompletedFlag(workItemSelectionFlags(workItem.command("list")))
2136
- .requiredOption("--project-id <projectId>")
2137
- .option("--limit <limit>", "Maximum results", parseSearchLimit, 20)
2138
- .option("--cursor <cursor>")
2139
- .option("--group-by <field>", "Group the page by field (status)", (value) => {
2140
- if (value === "status") {
2141
- return "status";
2142
- }
2143
- throw invalidArgument("Work Items can only be grouped by status");
2144
- })
2145
- .action(async (options) => {
2146
- exitCode = await run((client, _me, _credentialKind, members) => client.GET("/v1/projects/{projectId}/work-items", {
2147
- params: {
2148
- path: { projectId: options.projectId },
2149
- query: {
2150
- ...workItemSelectionQuery(withResolvedMembers(options, members)),
2151
- ...(options.completed === undefined ? {} : { completed: options.completed }),
2152
- ...(options.cursor === undefined ? {} : { cursor: options.cursor }),
2153
- ...(options.groupBy === undefined ? {} : { groupBy: options.groupBy }),
2154
- limit: options.limit,
2155
- },
2156
- },
2157
- }), {
2158
- memberReferences: selectionMemberReferences(options),
2159
- project: (data) => itemListOutput(data, outputMode, warnMissingUrl),
2160
- });
2161
- });
2162
- workItem
2163
- .command("read")
2164
- .requiredOption("--project-id <projectId>")
2165
- .requiredOption("--work-item-id <workItemId>")
2166
- .action(async (options) => {
2167
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/work-items/{workItemId}", {
2168
- params: { path: options },
2169
- }), { project: (data) => itemOutput(data, outputMode, warnMissingUrl) });
2170
- });
2171
- workItem
2172
- .command("assignees")
2173
- .requiredOption("--project-id <projectId>")
2174
- .action(async (options) => {
2175
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/work-item-assignees", {
2176
- params: { path: options },
2177
- }));
2178
- });
2179
- workItem
2180
- .command("agents")
2181
- .description("List active Agents granted to this Project")
2182
- .requiredOption("--project-id <projectId>")
2183
- .action(async (options) => {
2184
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/agents", {
2185
- params: { path: options },
2186
- }), { rejectWorkspaceReadToken: true });
2187
- });
2188
- workItem
2189
- .command("create")
2190
- .requiredOption("--project-id <projectId>")
2191
- .requiredOption("--title <title>")
2192
- .option("--description <description>", "Inline description text", singleDescriptionSource)
2193
- .option("--description-file <path>", "Read description from a UTF-8 regular file, or - for piped stdin", singleDescriptionSource)
2194
- .option("--label <labelId>", "Workspace label definition ID; repeat for several labels", collectOption, [])
2195
- .option("--assignee <assignee>", "Workspace member User ID, me for the selected credential, or an exact Member Alias or name")
2196
- .option("--assigned-agent <agentId>", "Eligible Workspace Agent ID to assign for execution")
2197
- .option("--custom-field <fieldId=value>", "Custom Field value as fieldId=value; repeat for several fields", collectOption, [])
2198
- .option("--priority <priority>", "Work Item priority", parseWorkItemPriority)
2199
- .option("--start-date <startDate>", "ISO 8601 date", parseWorkItemDate)
2200
- .option("--due-date <dueDate>", "ISO 8601 date", parseWorkItemDate)
2201
- .option("--status <status>", "Workflow Column slug or virtual status to create the Work Item in")
2202
- .option("--relation-direction <direction>", "Create one relation atomically: related, subtask, parent, blocks or blocked-by", (value) => {
2203
- const result = z
2204
- .enum(["related", "subtask", "parent", "blocks", "blocked-by"])
2205
- .safeParse(value);
2206
- if (!result.success)
2207
- throw invalidArgument("Invalid relation direction");
2208
- return result.data;
2209
- })
2210
- .option("--relation-target-project-id <projectId>", "Project containing the related task")
2211
- .option("--relation-target-work-item-id <workItemId>", "Public identity of the related task", parseWorkItemId)
2212
- .option("--replace-parent", "Replace an existing parent when creating a subtask relation")
2213
- .option("--initial-watcher-ids <json>", "Initial watcher User IDs as a JSON array; [] explicitly mutes the creator", (value) => parseStringArray(value, "initial-watcher-ids"))
2214
- .option("--version-id <versionId>", "Plan the Work Item in this unsealed Version: its id or name, such as v2.4", parseVersionId)
2215
- .action(async (options) => {
2216
- const description = (await readDescription(options)) ?? undefined;
2217
- if (hasWorkspaceReadToken(dependencies.environment)) {
2218
- exitCode = rejectTokenWrite(dependencies);
2219
- return;
2220
- }
2221
- const relationFlags = [
2222
- options.relationDirection,
2223
- options.relationTargetProjectId,
2224
- options.relationTargetWorkItemId,
2225
- ];
2226
- if (relationFlags.some((value) => value !== undefined) &&
2227
- relationFlags.some((value) => value === undefined))
2228
- throw invalidArgument("Atomic relation creation requires --relation-direction, --relation-target-project-id and --relation-target-work-item-id together");
2229
- const relation = options.relationDirection === undefined
2230
- ? undefined
2231
- : options.relationTargetProjectId === undefined ||
2232
- options.relationTargetWorkItemId === undefined
2233
- ? (() => {
2234
- throw invalidArgument("Atomic relation creation requires a relation target");
2235
- })()
2236
- : {
2237
- direction: options.relationDirection,
2238
- targetProjectId: options.relationTargetProjectId,
2239
- targetWorkItemId: options.relationTargetWorkItemId,
2240
- ...(options.replaceParent === undefined
2241
- ? {}
2242
- : { replaceParent: options.replaceParent }),
2243
- };
2244
- const customFields = options.customField.map(parseCustomFieldAssignment);
2245
- const idempotencyKey = randomUUID();
2246
- exitCode = await run(async (client, me, _credentialKind, members) => {
2247
- const plannedVersion = options.versionId === undefined
2248
- ? undefined
2249
- : await resolveProjectVersion(client, options.projectId, options.versionId);
2250
- if (plannedVersion !== undefined && "failure" in plannedVersion)
2251
- return plannedVersion.failure;
2252
- return await client.POST("/v1/projects/{projectId}/work-items", {
2253
- body: {
2254
- ...(options.assignee === undefined
2255
- ? {}
2256
- : { assigneeId: me ?? members?.get(options.assignee) ?? options.assignee }),
2257
- ...(options.assignedAgent === undefined
2258
- ? {}
2259
- : { assignedAgentId: options.assignedAgent }),
2260
- ...(options.customField.length === 0
2261
- ? {}
2262
- : {
2263
- customFields,
2264
- }),
2265
- ...(description === undefined ? {} : { description }),
2266
- ...(options.label.length === 0 ? {} : { labelIds: [...new Set(options.label)] }),
2267
- ...(options.initialWatcherIds === undefined
2268
- ? {}
2269
- : { initialWatcherIds: options.initialWatcherIds }),
2270
- ...(options.dueDate === undefined ? {} : { dueDate: options.dueDate }),
2271
- ...(options.priority === undefined ? {} : { priority: options.priority }),
2272
- ...(options.startDate === undefined ? {} : { startDate: options.startDate }),
2273
- ...(options.status === undefined ? {} : { status: options.status }),
2274
- ...(relation === undefined ? {} : { relation }),
2275
- title: options.title,
2276
- ...(plannedVersion === undefined ? {} : { versionId: plannedVersion.id }),
2277
- },
2278
- params: {
2279
- header: { "idempotency-key": idempotencyKey },
2280
- path: { projectId: options.projectId },
2281
- },
2282
- });
2283
- }, {
2284
- resolveMe: options.assignee === "me",
2285
- ...(options.assignee === undefined
2286
- ? {}
2287
- : {
2288
- memberReferences: { projectId: options.projectId, values: [options.assignee] },
2289
- }),
2290
- project: (data) => itemOutput(data, outputMode, warnMissingUrl),
2291
- ambiguousOutcomeMessage: "Work Item creation outcome is unknown; list Work Items before retrying",
2292
- retryTransportOnce: true,
2293
- });
2294
- });
2295
- workItem
2296
- .command("update")
2297
- .requiredOption("--project-id <projectId>")
2298
- .requiredOption("--work-item-id <workItemId>")
2299
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2300
- .option("--title <title>")
2301
- .option("--description <description>", "Inline description text", singleDescriptionSource)
2302
- .option("--description-file <path>", "Read description from a UTF-8 regular file, or - for piped stdin", singleDescriptionSource)
2303
- .option("--clear-description", "Remove the Work Item description")
2304
- .option("--priority <priority>", "Work Item priority", parseWorkItemPriority)
2305
- .option("--start-date <startDate>", "ISO 8601 date", parseWorkItemDate)
2306
- .option("--due-date <dueDate>", "ISO 8601 date", parseWorkItemDate)
2307
- .option("--clear-start-date", "Remove the Work Item start date")
2308
- .option("--clear-due-date", "Remove the Work Item due date")
2309
- .option("--version-id <versionId>", "Move the Work Item into this unsealed Version: its id or name, such as v2.4", parseVersionId)
2310
- .option("--clear-version", "Take the Work Item out of its Version")
2311
- .action(async (options) => {
2312
- const description = (await readDescription(options)) ?? undefined;
2313
- if (hasWorkspaceReadToken(dependencies.environment)) {
2314
- exitCode = rejectTokenWrite(dependencies);
2315
- return;
2316
- }
2317
- if (options.title === undefined &&
2318
- description === undefined &&
2319
- options.clearDescription !== true &&
2320
- options.priority === undefined &&
2321
- options.startDate === undefined &&
2322
- options.dueDate === undefined &&
2323
- options.clearStartDate !== true &&
2324
- options.clearDueDate !== true &&
2325
- options.versionId === undefined &&
2326
- options.clearVersion !== true) {
2327
- throw invalidArgument("Work Item update requires a field change");
2328
- }
2329
- if (options.clearVersion === true && options.versionId !== undefined) {
2330
- throw invalidArgument("Work Item update cannot set and clear the Version together");
2331
- }
2332
- if (options.clearStartDate === true && options.startDate !== undefined) {
2333
- throw invalidArgument("Work Item update cannot set and clear the start date together");
2334
- }
2335
- if (options.clearDueDate === true && options.dueDate !== undefined) {
2336
- throw invalidArgument("Work Item update cannot set and clear the due date together");
2337
- }
2338
- const idempotencyKey = randomUUID();
2339
- exitCode = await run(async (client) => {
2340
- const plannedVersion = options.versionId === undefined
2341
- ? undefined
2342
- : await resolveProjectVersion(client, options.projectId, options.versionId);
2343
- if (plannedVersion !== undefined && "failure" in plannedVersion)
2344
- return plannedVersion.failure;
2345
- return await client.PATCH("/v1/projects/{projectId}/work-items/{workItemId}", {
2346
- body: {
2347
- ...(options.clearDescription === true
2348
- ? { description: null }
2349
- : description === undefined
2350
- ? {}
2351
- : { description }),
2352
- ...(options.clearDueDate === true
2353
- ? { dueDate: null }
2354
- : options.dueDate === undefined
2355
- ? {}
2356
- : { dueDate: options.dueDate }),
2357
- ...(options.clearStartDate === true
2358
- ? { startDate: null }
2359
- : options.startDate === undefined
2360
- ? {}
2361
- : { startDate: options.startDate }),
2362
- ...(options.priority === undefined ? {} : { priority: options.priority }),
2363
- ...(options.title === undefined ? {} : { title: options.title }),
2364
- ...(options.clearVersion === true
2365
- ? { versionId: null }
2366
- : plannedVersion === undefined
2367
- ? {}
2368
- : { versionId: plannedVersion.id }),
2369
- },
2370
- params: {
2371
- header: {
2372
- "idempotency-key": idempotencyKey,
2373
- "if-match": options.expectedVersion,
2374
- },
2375
- path: {
2376
- projectId: options.projectId,
2377
- workItemId: options.workItemId,
2378
- },
2379
- },
2380
- });
2381
- }, {
2382
- project: (data) => itemOutput(data, outputMode, warnMissingUrl),
2383
- ambiguousOutcomeMessage: "Work Item update outcome is unknown; read the Work Item before retrying",
2384
- retryTransportOnce: true,
2385
- });
2386
- });
2387
- workItem
2388
- .command("assign")
2389
- .requiredOption("--project-id <projectId>")
2390
- .requiredOption("--work-item-id <workItemId>")
2391
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2392
- .option("--assignee <assignee>", "Workspace member User ID, me for the selected credential, or an exact Member Alias or name")
2393
- .option("--unassign", "Remove the Work Item assignee")
2394
- .action(async (options) => {
2395
- if (hasWorkspaceReadToken(dependencies.environment)) {
2396
- exitCode = rejectTokenWrite(dependencies);
2397
- return;
2398
- }
2399
- if (options.assignee === undefined && options.unassign !== true) {
2400
- throw invalidArgument("Work Item assign requires an assignee or --unassign");
2401
- }
2402
- if (options.assignee !== undefined && options.unassign === true) {
2403
- throw invalidArgument("Work Item assign cannot set and clear the assignee together");
2404
- }
2405
- const idempotencyKey = randomUUID();
2406
- exitCode = await run((client, me, _credentialKind, members) => client.PUT("/v1/projects/{projectId}/work-items/{workItemId}/assignee", {
2407
- body: {
2408
- assigneeId: options.unassign === true
2409
- ? null
2410
- : (me ??
2411
- (options.assignee === undefined
2412
- ? null
2413
- : (members?.get(options.assignee) ?? options.assignee))),
2414
- },
2415
- params: {
2416
- header: {
2417
- "idempotency-key": idempotencyKey,
2418
- "if-match": options.expectedVersion,
2419
- },
2420
- path: {
2421
- projectId: options.projectId,
2422
- workItemId: options.workItemId,
2423
- },
2424
- },
2425
- }), {
2426
- resolveMe: options.assignee === "me",
2427
- ...(options.assignee === undefined || options.unassign === true
2428
- ? {}
2429
- : {
2430
- memberReferences: { projectId: options.projectId, values: [options.assignee] },
2431
- }),
2432
- project: (data) => itemOutput(data, outputMode, warnMissingUrl),
2433
- ambiguousOutcomeMessage: "Work Item assignment outcome is unknown; read the Work Item before retrying",
2434
- retryTransportOnce: true,
2435
- });
2436
- });
2437
- workItem
2438
- .command("assign-agent")
2439
- .description("Assign or clear the executing Workspace Agent for a Work Item")
2440
- .requiredOption("--project-id <projectId>")
2441
- .requiredOption("--work-item-id <workItemId>")
2442
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2443
- .option("--agent-id <agentId>", "Eligible Workspace Agent ID to assign")
2444
- .option("--clear", "Clear the executing Agent")
2445
- .action(async (options) => {
2446
- if (hasWorkspaceReadToken(dependencies.environment)) {
2447
- exitCode = rejectTokenWrite(dependencies);
2448
- return;
2449
- }
2450
- if (options.agentId === undefined && options.clear !== true) {
2451
- throw invalidArgument("Work Item assign-agent requires --agent-id or --clear");
2452
- }
2453
- if (options.agentId !== undefined && options.clear === true) {
2454
- throw invalidArgument("Work Item assign-agent cannot combine --agent-id and --clear");
2455
- }
2456
- const idempotencyKey = randomUUID();
2457
- exitCode = await run((client) => client.PUT("/v1/projects/{projectId}/work-items/{workItemId}/assigned-agent", {
2458
- body: {
2459
- assignedAgentId: options.clear === true ? null : (options.agentId ?? null),
2460
- },
2461
- params: {
2462
- header: {
2463
- "idempotency-key": idempotencyKey,
2464
- "if-match": options.expectedVersion,
2465
- },
2466
- path: {
2467
- projectId: options.projectId,
2468
- workItemId: options.workItemId,
2469
- },
2470
- },
2471
- }), {
2472
- project: (data) => itemOutput(data, outputMode, warnMissingUrl),
2473
- ambiguousOutcomeMessage: "Work Item Agent assignment outcome is unknown; read the Work Item before retrying",
2474
- retryTransportOnce: true,
2475
- });
2476
- });
2477
- workItem
2478
- .command("delete")
2479
- .requiredOption("--project-id <projectId>")
2480
- .requiredOption("--work-item-id <workItemId>")
2481
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2482
- .action(async (options) => {
2483
- if (hasWorkspaceReadToken(dependencies.environment)) {
2484
- exitCode = rejectTokenWrite(dependencies);
2485
- return;
2486
- }
2487
- const idempotencyKey = randomUUID();
2488
- exitCode = await run(async (client) => withSuccessData(await client.DELETE("/v1/projects/{projectId}/work-items/{workItemId}", {
2489
- params: {
2490
- header: {
2491
- "idempotency-key": idempotencyKey,
2492
- "if-match": options.expectedVersion,
2493
- },
2494
- path: {
2495
- projectId: options.projectId,
2496
- workItemId: options.workItemId,
2497
- },
2498
- },
2499
- }), { deleted: { workItemId: options.workItemId } }), {
2500
- ambiguousOutcomeMessage: "Work Item deletion outcome is unknown; list Work Items before retrying",
2501
- retryTransportOnce: true,
2502
- });
2503
- });
2504
- workItemCompletedFlag(workItemSelectionFlags(workItem.command("board")))
2505
- .requiredOption("--project-id <projectId>")
2506
- .action(async (options) => {
2507
- exitCode = await run((client, _me, _credentialKind, members) => client.GET("/v1/projects/{projectId}/work-item-board", {
2508
- params: {
2509
- path: { projectId: options.projectId },
2510
- query: {
2511
- ...workItemSelectionQuery(withResolvedMembers(options, members)),
2512
- ...(options.completed === undefined ? {} : { completed: options.completed }),
2513
- },
2514
- },
2515
- }), { memberReferences: selectionMemberReferences(options) });
2516
- });
2517
- workItem
2518
- .command("bulk")
2519
- .requiredOption("--project-id <projectId>")
2520
- .requiredOption("--action <action>", `Bulk action: ${workItemBulkActions.join(", ")}`, parseWorkItemBulkAction)
2521
- .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, [])
2522
- .option("--status <status>", "Destination Workflow Column slug or virtual status (updateStatus)")
2523
- .option("--priority <priority>", "Priority (updatePriority)", parseWorkItemPriority)
2524
- .option("--assignee <assignee>", "Assignee User ID only (updateAssignee); me is not supported")
2525
- .option("--unassign", "Clear the assignee (updateAssignee)")
2526
- .option("--assigned-agent <agentId>", "Executing Workspace Agent ID (updateAssignedAgent)")
2527
- .option("--clear-assigned-agent", "Clear the executing Agent (updateAssignedAgent)")
2528
- .option("--label-id <labelId>", "Work Item Label ID (addLabel/removeLabel)")
2529
- .option("--due-date <dueDate>", "Due date (updateDueDate)", parseWorkItemDate)
2530
- .option("--clear-due-date", "Clear the due date (updateDueDate)")
2531
- .description("Apply one action to several Work Items, which may span Projects inside the same Workspace")
2532
- .action(async (options) => {
2533
- if (hasWorkspaceReadToken(dependencies.environment)) {
2534
- exitCode = rejectTokenWrite(dependencies);
2535
- return;
2536
- }
2537
- if (options.unassign === true && options.assignee !== undefined) {
2538
- writeSkillError(dependencies, {
2539
- message: "--assignee and --unassign cannot be combined for updateAssignee",
2540
- reason: "Invalid Operation",
2541
- retryable: false,
2542
- });
2543
- exitCode = 1;
2544
- return;
2545
- }
2546
- if (options.clearAssignedAgent === true && options.assignedAgent !== undefined) {
2547
- writeSkillError(dependencies, {
2548
- message: "--assigned-agent and --clear-assigned-agent cannot be combined for updateAssignedAgent",
2549
- reason: "Invalid Operation",
2550
- retryable: false,
2551
- });
2552
- exitCode = 1;
2553
- return;
2554
- }
2555
- if (options.clearDueDate === true && options.dueDate !== undefined) {
2556
- writeSkillError(dependencies, {
2557
- message: "--due-date and --clear-due-date cannot be combined for updateDueDate",
2558
- reason: "Invalid Operation",
2559
- retryable: false,
2560
- });
2561
- exitCode = 1;
2562
- return;
2563
- }
2564
- const idempotencyKey = randomUUID();
2565
- exitCode = await run((client) => client.POST("/v1/projects/{projectId}/work-items/bulk", {
2566
- body: {
2567
- action: options.action,
2568
- ...(options.action === "updateAssignee"
2569
- ? options.unassign === true
2570
- ? { assigneeId: null }
2571
- : options.assignee === undefined
2572
- ? {}
2573
- : { assigneeId: options.assignee }
2574
- : {}),
2575
- ...(options.action === "updateAssignedAgent"
2576
- ? options.clearAssignedAgent === true
2577
- ? { assignedAgentId: null }
2578
- : options.assignedAgent === undefined
2579
- ? {}
2580
- : { assignedAgentId: options.assignedAgent }
2581
- : {}),
2582
- ...(options.action === "updateDueDate"
2583
- ? options.clearDueDate === true
2584
- ? { dueDate: null }
2585
- : options.dueDate === undefined
2586
- ? {}
2587
- : { dueDate: options.dueDate }
2588
- : {}),
2589
- ...((options.action === "addLabel" || options.action === "removeLabel") &&
2590
- options.labelId !== undefined
2591
- ? { labelId: options.labelId }
2592
- : {}),
2593
- ...(options.action === "updatePriority" && options.priority !== undefined
2594
- ? { priority: options.priority }
2595
- : {}),
2596
- ...(options.action === "updateStatus" && options.status !== undefined
2597
- ? { status: options.status }
2598
- : {}),
2599
- workItems: options.target.map((target) => ({
2600
- id: target.id,
2601
- ...(target.projectId === undefined ? {} : { projectId: target.projectId }),
2602
- version: target.expectedVersion,
2603
- })),
2604
- },
2605
- params: {
2606
- header: { "idempotency-key": idempotencyKey },
2607
- path: { projectId: options.projectId },
2608
- },
2609
- }), {
2610
- ambiguousOutcomeMessage: "Work Item bulk outcome is unknown; list Work Items before retrying",
2611
- retryTransportOnce: true,
2612
- });
2613
- });
2614
- workItem
2615
- .command("import")
2616
- .description("Import JSON tasks into the explicit Project; imported labels are reported as skipped")
2617
- .requiredOption("--project-id <projectId>")
2618
- .requiredOption("--file <path>", "JSON task file, at most 1 MiB and 1000 tasks")
2619
- .requiredOption("--idempotency-key <key>", "Reuse this key with the same file when retrying")
2620
- .action(async (options) => {
2621
- if (hasWorkspaceReadToken(dependencies.environment)) {
2622
- exitCode = rejectTokenWrite(dependencies);
2623
- return;
2624
- }
2625
- const key = options.idempotencyKey.trim();
2626
- if (key.length === 0 || key.length > 200) {
2627
- throw invalidArgument("The import idempotency key must contain 1 to 200 characters");
2628
- }
2629
- const body = await readWorkItemImportFile(options.file);
2630
- if (body === null) {
2631
- writeSkillError(dependencies, {
2632
- message: "The import file must be valid task JSON within 1 MiB and 1000 tasks",
2633
- reason: "Invalid Operation",
2634
- retryable: false,
2635
- });
2636
- exitCode = 2;
2637
- return;
2638
- }
2639
- let failed = 0;
2640
- exitCode = await run(async (client) => {
2641
- const result = await client.POST("/v1/projects/{projectId}/work-items/import", {
2642
- body,
2643
- params: {
2644
- header: { "idempotency-key": key },
2645
- path: { projectId: options.projectId },
2646
- },
2647
- });
2648
- if (result.data !== undefined) {
2649
- failed = result.data.results.failed;
2650
- }
2651
- return result;
2652
- }, {
2653
- ambiguousOutcomeMessage: "Import outcome is unknown; retry the same file and idempotency key",
2654
- retryTransportOnce: true,
2655
- });
2656
- if (exitCode === 0 && failed > 0) {
2657
- writeSkillError(dependencies, {
2658
- message: "Some tasks were refused; inspect the per-row results and import only corrected failed rows with a new key",
2659
- reason: "Invalid Operation",
2660
- retryable: false,
2661
- });
2662
- exitCode = 2;
2663
- }
2664
- });
2665
- workItemSelectionFlags(workItem.command("export"))
2666
- .description("Export selected readable Project tasks as JSON on stdout")
2667
- .requiredOption("--project-id <projectId>")
2668
- .action(async (options) => {
2669
- exitCode = await run((client, _me, _credentialKind, members) => client.GET("/v1/projects/{projectId}/work-items/export", {
2670
- params: {
2671
- path: { projectId: options.projectId },
2672
- query: workItemSelectionQuery(withResolvedMembers(options, members)),
2673
- },
2674
- }), { memberReferences: selectionMemberReferences(options) });
2675
- });
2676
- workItem
2677
- .command("transfer")
2678
- .description("Move a Work Item into another Project in its Workspace")
2679
- .requiredOption("--project-id <projectId>")
2680
- .requiredOption("--work-item-id <workItemId>")
2681
- .requiredOption("--destination-project-id <projectId>")
2682
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2683
- .option("--destination-status <status>", "Destination Workflow Column slug; defaults to the matching or first column")
2684
- .action(async (options) => {
2685
- if (hasWorkspaceReadToken(dependencies.environment)) {
2686
- exitCode = rejectTokenWrite(dependencies);
2687
- return;
2688
- }
2689
- const idempotencyKey = randomUUID();
2690
- exitCode = await run((client) => client.POST("/v1/projects/{projectId}/work-items/{workItemId}/transfer", {
2691
- body: {
2692
- destinationProjectId: options.destinationProjectId,
2693
- ...(options.destinationStatus === undefined
2694
- ? {}
2695
- : { destinationStatus: options.destinationStatus }),
2696
- },
2697
- params: {
2698
- header: { "idempotency-key": idempotencyKey, "if-match": options.expectedVersion },
2699
- path: { projectId: options.projectId, workItemId: options.workItemId },
2700
- },
2701
- }), {
2702
- ambiguousOutcomeMessage: "Work Item transfer outcome is unknown; inspect both Projects before retrying",
2703
- retryTransportOnce: true,
2704
- });
2705
- });
2706
- workItem
2707
- .command("move")
2708
- .requiredOption("--project-id <projectId>")
2709
- .requiredOption("--work-item-id <workItemId>")
2710
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2711
- .requiredOption("--status <status>", "Destination Workflow Column slug or virtual status")
2712
- .option("--position <position>", "Board index inside the destination column", parseBoardPosition)
2713
- .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")
2714
- .action(async (options) => {
2715
- if (hasWorkspaceReadToken(dependencies.environment)) {
2716
- exitCode = rejectTokenWrite(dependencies);
2717
- return;
2718
- }
2719
- if (options.withSubtasks === true && options.position !== undefined) {
2720
- writeSkillError(dependencies, {
2721
- message: "--position cannot be combined with --with-subtasks",
2722
- reason: "Invalid Operation",
2723
- retryable: false,
2724
- });
2725
- exitCode = 1;
2726
- return;
2727
- }
2728
- const idempotencyKey = randomUUID();
2729
- if (options.withSubtasks === true) {
2730
- exitCode = await run((client) => moveWithSubtasks(client, {
2731
- expectedVersion: options.expectedVersion,
2732
- idempotencyKey,
2733
- projectId: options.projectId,
2734
- status: options.status,
2735
- workItemId: options.workItemId,
2736
- }), {
2737
- ambiguousOutcomeMessage: "Work Item move outcome is unknown; read the Work Item and its subtasks before retrying",
2738
- retryTransportOnce: true,
2739
- });
2740
- return;
2741
- }
2742
- exitCode = await run(async (client) => {
2743
- const moved = await client.POST("/v1/projects/{projectId}/work-items/{workItemId}/move", {
2744
- body: {
2745
- ...(options.position === undefined ? {} : { position: options.position }),
2746
- status: options.status,
2747
- },
2748
- params: {
2749
- header: {
2750
- "idempotency-key": idempotencyKey,
2751
- "if-match": options.expectedVersion,
2752
- },
2753
- path: {
2754
- projectId: options.projectId,
2755
- workItemId: options.workItemId,
2756
- },
2757
- },
2758
- });
2759
- if (moved.data !== undefined) {
2760
- const hint = await subtaskCascadeHint(client, {
2761
- projectId: options.projectId,
2762
- status: options.status,
2763
- workItemId: options.workItemId,
2764
- });
2765
- if (hint !== null)
2766
- dependencies.stderr(formatResourceDiagnostic(hint));
2767
- }
2768
- return moved;
2769
- }, {
2770
- ambiguousOutcomeMessage: "Work Item move outcome is unknown; read the Work Item board before retrying",
2771
- retryTransportOnce: true,
2772
- });
2773
- });
2774
- for (const action of ["archive", "unarchive"]) {
2775
- workItem
2776
- .command(action)
2777
- .requiredOption("--project-id <projectId>")
2778
- .requiredOption("--work-item-id <workItemId>")
2779
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2780
- .action(async (options) => {
2781
- if (hasWorkspaceReadToken(dependencies.environment)) {
2782
- exitCode = rejectTokenWrite(dependencies);
2783
- return;
2784
- }
2785
- const idempotencyKey = randomUUID();
2786
- exitCode = await run((client) => client.POST(action === "archive"
2787
- ? "/v1/projects/{projectId}/work-items/{workItemId}/archive"
2788
- : "/v1/projects/{projectId}/work-items/{workItemId}/unarchive", {
2789
- params: {
2790
- path: { projectId: options.projectId, workItemId: options.workItemId },
2791
- header: {
2792
- "if-match": options.expectedVersion,
2793
- "idempotency-key": idempotencyKey,
2794
- },
2795
- },
2796
- }), {
2797
- retryTransportOnce: true,
2798
- ambiguousOutcomeMessage: "Work Item archive outcome is unknown; read the Work Item before retrying",
2799
- });
2800
- });
2801
- }
2802
- workItem
2803
- .command("complete")
2804
- .requiredOption("--project-id <projectId>")
2805
- .requiredOption("--work-item-id <workItemId>")
2806
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2807
- .description("Move a Work Item into the Project's first final Workflow Column")
2808
- .option("--with-subtasks", "Also complete every unfinished subtask (any depth) you may update, in one atomic command")
2809
- .action(async (options) => {
2810
- if (hasWorkspaceReadToken(dependencies.environment)) {
2811
- exitCode = rejectTokenWrite(dependencies);
2812
- return;
2813
- }
2814
- const idempotencyKey = randomUUID();
2815
- exitCode = await run(async (client) => {
2816
- const board = await client.GET("/v1/projects/{projectId}/work-item-board", {
2817
- params: { path: { projectId: options.projectId } },
2818
- });
2819
- if (!board.response.ok) {
2820
- return board;
2821
- }
2822
- const finalColumn = board.data?.workflowColumns.find((column) => column.category === "completed");
2823
- if (finalColumn === undefined) {
2824
- return {
2825
- error: {
2826
- code: "WORKFLOW_COLUMN_NO_FINAL",
2827
- message: "The Project has no final Workflow Column; mark a column final or move the Work Item to its slug directly",
2828
- },
2829
- response: new Response(null, { status: 422 }),
2830
- };
2831
- }
2832
- if (options.withSubtasks === true)
2833
- return await moveWithSubtasks(client, {
2834
- expectedVersion: options.expectedVersion,
2835
- idempotencyKey,
2836
- projectId: options.projectId,
2837
- status: finalColumn.slug,
2838
- workItemId: options.workItemId,
2839
- });
2840
- const moved = await client.POST("/v1/projects/{projectId}/work-items/{workItemId}/move", {
2841
- body: { status: finalColumn.slug },
2842
- params: {
2843
- header: {
2844
- "idempotency-key": idempotencyKey,
2845
- "if-match": options.expectedVersion,
2846
- },
2847
- path: {
2848
- projectId: options.projectId,
2849
- workItemId: options.workItemId,
2850
- },
2851
- },
2852
- });
2853
- if (moved.data !== undefined) {
2854
- const hint = await subtaskCascadeHint(client, {
2855
- columns: board.data?.workflowColumns,
2856
- projectId: options.projectId,
2857
- status: finalColumn.slug,
2858
- workItemId: options.workItemId,
2859
- });
2860
- if (hint !== null)
2861
- dependencies.stderr(formatResourceDiagnostic(hint));
2862
- }
2863
- return moved;
2864
- }, {
2865
- ambiguousOutcomeMessage: "Work Item completion outcome is unknown; read the Work Item board before retrying",
2866
- retryTransportOnce: true,
2867
- });
2868
- });
2869
- const workItemLabel = program.command("work-item-label");
2870
- workItemLabel
2871
- .command("list")
2872
- .requiredOption("--project-id <projectId>")
2873
- .option("--work-item-id <workItemId>", "List only the labels attached to one Work Item")
2874
- .action(async (options) => {
2875
- exitCode = await run((client) => options.workItemId === undefined
2876
- ? client.GET("/v1/projects/{projectId}/work-item-labels", {
2877
- params: { path: { projectId: options.projectId } },
2878
- })
2879
- : client.GET("/v1/projects/{projectId}/work-items/{workItemId}/labels", {
2880
- params: {
2881
- path: {
2882
- projectId: options.projectId,
2883
- workItemId: options.workItemId,
2884
- },
2885
- },
2886
- }));
2887
- });
2888
- workItemLabel
2889
- .command("read")
2890
- .requiredOption("--project-id <projectId>")
2891
- .requiredOption("--label-id <labelId>")
2892
- .action(async (options) => {
2893
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/work-item-labels/{labelId}", {
2894
- params: { path: options },
2895
- }));
2896
- });
2897
- workItemLabel
2898
- .command("create")
2899
- .requiredOption("--project-id <projectId>")
2900
- .requiredOption("--name <name>")
2901
- .requiredOption("--color <color>")
2902
- .option("--work-item-id <workItemId>", "Create the label directly on the named Work Item instead of the Workspace definition")
2903
- .action(async (options) => {
2904
- if (hasWorkspaceReadToken(dependencies.environment)) {
2905
- exitCode = rejectTokenWrite(dependencies);
2906
- return;
2907
- }
2908
- const idempotencyKey = randomUUID();
2909
- exitCode = await run((client) => client.POST("/v1/projects/{projectId}/work-item-labels", {
2910
- body: {
2911
- color: options.color,
2912
- name: options.name,
2913
- ...(options.workItemId === undefined ? {} : { workItemId: options.workItemId }),
2914
- },
2915
- params: {
2916
- header: { "idempotency-key": idempotencyKey },
2917
- path: { projectId: options.projectId },
2918
- },
2919
- }), {
2920
- ambiguousOutcomeMessage: "Work Item Label creation outcome is unknown; list Work Item Labels before retrying",
2921
- retryTransportOnce: true,
2922
- });
2923
- });
2924
- workItemLabel
2925
- .command("update")
2926
- .requiredOption("--project-id <projectId>")
2927
- .requiredOption("--label-id <labelId>")
2928
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2929
- .option("--name <name>")
2930
- .option("--color <color>")
2931
- .action(async (options) => {
2932
- if (hasWorkspaceReadToken(dependencies.environment)) {
2933
- exitCode = rejectTokenWrite(dependencies);
2934
- return;
2935
- }
2936
- if (options.name === undefined && options.color === undefined) {
2937
- throw invalidArgument("Work Item Label update requires a field change");
2938
- }
2939
- const idempotencyKey = randomUUID();
2940
- exitCode = await run((client) => client.PATCH("/v1/projects/{projectId}/work-item-labels/{labelId}", {
2941
- body: {
2942
- ...(options.color === undefined ? {} : { color: options.color }),
2943
- ...(options.name === undefined ? {} : { name: options.name }),
2944
- },
2945
- params: {
2946
- header: {
2947
- "idempotency-key": idempotencyKey,
2948
- "if-match": options.expectedVersion,
2949
- },
2950
- path: {
2951
- labelId: options.labelId,
2952
- projectId: options.projectId,
2953
- },
2954
- },
2955
- }), {
2956
- ambiguousOutcomeMessage: "Work Item Label update outcome is unknown; read the Work Item Label before retrying",
2957
- retryTransportOnce: true,
2958
- });
2959
- });
2960
- workItemLabel
2961
- .command("delete")
2962
- .requiredOption("--project-id <projectId>")
2963
- .requiredOption("--label-id <labelId>")
2964
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
2965
- .description("Delete a Work Item Label; a Workspace definition's task-copy cascade resumes automatically across bounded batches")
2966
- .action(async (options) => {
2967
- if (hasWorkspaceReadToken(dependencies.environment)) {
2968
- exitCode = rejectTokenWrite(dependencies);
2969
- return;
2970
- }
2971
- const idempotencyKey = randomUUID();
2972
- exitCode = await run(async (client) => {
2973
- const request = () => client.DELETE("/v1/projects/{projectId}/work-item-labels/{labelId}", {
2974
- params: {
2975
- header: {
2976
- "idempotency-key": idempotencyKey,
2977
- "if-match": options.expectedVersion,
2978
- },
2979
- path: {
2980
- labelId: options.labelId,
2981
- projectId: options.projectId,
2982
- },
2983
- },
2984
- });
2985
- let result = await request();
2986
- // HTTP 202 marks a definition cascade still in flight; the same
2987
- // request resumes it, bounded so a runaway copy count stops.
2988
- for (let attempt = 0; result.response.status === 202 && attempt < 40; attempt += 1) {
2989
- result = await request();
2990
- }
2991
- return withSuccessData(result, {
2992
- deleted: { labelId: options.labelId },
2993
- });
2994
- }, {
2995
- ambiguousOutcomeMessage: "Work Item Label deletion outcome is unknown; list Work Item Labels before retrying",
2996
- retryTransportOnce: true,
2997
- // A bounded 202 stream that never completes is not a success —
2998
- // report the resumable deletion as retryable instead of printing
2999
- // the pending payload as if it were done.
3000
- validateSuccess: (data) => isWorkItemLabelDeletionPending(data)
3001
- ? {
3002
- message: "Work Item Label deletion is still in progress; run the same command again to resume it",
3003
- reason: "Temporary Failure",
3004
- retryable: true,
3005
- }
3006
- : null,
3007
- });
3008
- });
3009
- workItemLabel
3010
- .command("attach")
3011
- .requiredOption("--project-id <projectId>")
3012
- .requiredOption("--work-item-id <workItemId>")
3013
- .requiredOption("--label-id <labelId>")
3014
- .option("--expected-version <expectedVersion>", "Opaque version of the task copy being moved; required when the Label is already attached elsewhere", parseOpaqueVersion)
3015
- .description("Attach a Work Item Label to a Work Item as a task-level copy")
3016
- .action(async (options) => {
3017
- if (hasWorkspaceReadToken(dependencies.environment)) {
3018
- exitCode = rejectTokenWrite(dependencies);
3019
- return;
3020
- }
3021
- const idempotencyKey = randomUUID();
3022
- exitCode = await run((client) => client.PUT("/v1/projects/{projectId}/work-items/{workItemId}/labels/{labelId}", {
3023
- params: {
3024
- header: {
3025
- "idempotency-key": idempotencyKey,
3026
- ...(options.expectedVersion === undefined
3027
- ? {}
3028
- : { "if-match": options.expectedVersion }),
3029
- },
3030
- path: {
3031
- labelId: options.labelId,
3032
- projectId: options.projectId,
3033
- workItemId: options.workItemId,
3034
- },
3035
- },
3036
- }), {
3037
- ambiguousOutcomeMessage: "Work Item Label attachment outcome is unknown; list the Work Item's labels before retrying",
3038
- retryTransportOnce: true,
3039
- });
3040
- });
3041
- workItemLabel
3042
- .command("detach")
3043
- .requiredOption("--project-id <projectId>")
3044
- .requiredOption("--work-item-id <workItemId>")
3045
- .requiredOption("--label-id <labelId>")
3046
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow for the attached copy", parseOpaqueVersion)
3047
- .description("Detach a Work Item Label copy from a Work Item")
3048
- .action(async (options) => {
3049
- if (hasWorkspaceReadToken(dependencies.environment)) {
3050
- exitCode = rejectTokenWrite(dependencies);
3051
- return;
3052
- }
3053
- const idempotencyKey = randomUUID();
3054
- exitCode = await run((client) => client.DELETE("/v1/projects/{projectId}/work-items/{workItemId}/labels/{labelId}", {
3055
- params: {
3056
- header: {
3057
- "idempotency-key": idempotencyKey,
3058
- "if-match": options.expectedVersion,
3059
- },
3060
- path: {
3061
- labelId: options.labelId,
3062
- projectId: options.projectId,
3063
- workItemId: options.workItemId,
3064
- },
3065
- },
3066
- }), {
3067
- ambiguousOutcomeMessage: "Work Item Label detachment outcome is unknown; list the Work Item's labels before retrying",
3068
- retryTransportOnce: true,
3069
- });
3070
- });
3071
- const workItemCustomField = program.command("work-item-custom-field");
3072
- registerCustomFieldColorCommands(workItemCustomField, resourceRuntime);
3073
- workItemCustomField
3074
- .command("list")
3075
- .requiredOption("--project-id <projectId>")
3076
- .action(async (options) => {
3077
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/work-item-custom-fields", {
3078
- params: { path: options },
3079
- }));
3080
- });
3081
- workItemCustomField
3082
- .command("create")
3083
- .requiredOption("--project-id <projectId>")
3084
- .requiredOption("--name <name>")
3085
- .requiredOption("--type <type>", "text, number, date, dropdown, multi-select, or boolean", parseWorkItemCustomFieldType)
3086
- .option("--option <option>", "Dropdown option; repeat for every choice", collectOption, [])
3087
- .option("--default-value <defaultValue>")
3088
- .option("--required", "Reject Work Items that leave the field blank")
3089
- .option("--option-colors <json>", "One color or null per dropdown option", parseOptionColors)
3090
- .action(async (options) => {
3091
- if (hasWorkspaceReadToken(dependencies.environment)) {
3092
- exitCode = rejectTokenWrite(dependencies);
3093
- return;
3094
- }
3095
- const idempotencyKey = randomUUID();
3096
- exitCode = await run((client) => client.POST("/v1/projects/{projectId}/work-item-custom-fields", {
3097
- body: {
3098
- ...(options.defaultValue === undefined ? {} : { defaultValue: options.defaultValue }),
3099
- name: options.name,
3100
- ...(options.optionColors === undefined ? {} : { optionColors: options.optionColors }),
3101
- ...(options.option.length === 0 ? {} : { options: options.option }),
3102
- ...(options.required === undefined ? {} : { required: options.required }),
3103
- type: options.type,
3104
- },
3105
- params: {
3106
- header: { "idempotency-key": idempotencyKey },
3107
- path: { projectId: options.projectId },
3108
- },
3109
- }), {
3110
- ambiguousOutcomeMessage: "Work Item Custom Field creation outcome is unknown; list Work Item Custom Fields before retrying",
3111
- retryTransportOnce: true,
3112
- });
3113
- });
3114
- workItemCustomField
3115
- .command("delete")
3116
- .requiredOption("--project-id <projectId>")
3117
- .requiredOption("--field-id <fieldId>")
3118
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
3119
- .description("Delete a Work Item Custom Field; its stored values cascade with the definition")
3120
- .action(async (options) => {
3121
- if (hasWorkspaceReadToken(dependencies.environment)) {
3122
- exitCode = rejectTokenWrite(dependencies);
3123
- return;
3124
- }
3125
- const idempotencyKey = randomUUID();
3126
- exitCode = await run(async (client) => withSuccessData(await client.DELETE("/v1/projects/{projectId}/work-item-custom-fields/{fieldId}", {
3127
- params: {
3128
- header: {
3129
- "idempotency-key": idempotencyKey,
3130
- "if-match": options.expectedVersion,
3131
- },
3132
- path: {
3133
- fieldId: options.fieldId,
3134
- projectId: options.projectId,
3135
- },
3136
- },
3137
- }), { deleted: { fieldId: options.fieldId } }), {
3138
- ambiguousOutcomeMessage: "Work Item Custom Field deletion outcome is unknown; list Work Item Custom Fields before retrying",
3139
- retryTransportOnce: true,
3140
- });
3141
- });
3142
- workItemCustomField
3143
- .command("reorder")
3144
- .requiredOption("--project-id <projectId>")
3145
- .requiredOption("--order <order>", 'Comma-separated id@version pairs in display order — version is the integer inside the field\'s opaque "N" version')
3146
- .action(async (options) => {
3147
- if (hasWorkspaceReadToken(dependencies.environment)) {
3148
- exitCode = rejectTokenWrite(dependencies);
3149
- return;
3150
- }
3151
- const fields = parseFieldOrder(options.order);
3152
- const idempotencyKey = randomUUID();
3153
- exitCode = await run((client) => client.PUT("/v1/projects/{projectId}/work-item-custom-fields/reorder", {
3154
- body: { fields },
3155
- params: {
3156
- header: { "idempotency-key": idempotencyKey },
3157
- path: { projectId: options.projectId },
3158
- },
3159
- }), {
3160
- ambiguousOutcomeMessage: "Work Item Custom Field reorder outcome is unknown; list Work Item Custom Fields before retrying",
3161
- retryTransportOnce: true,
3162
- });
3163
- });
3164
- workItemCustomField
3165
- .command("values")
3166
- .requiredOption("--project-id <projectId>")
3167
- .option("--work-item-id <workItemId>", "List only the values stored on one Work Item")
3168
- .action(async (options) => {
3169
- exitCode = await run((client) => options.workItemId === undefined
3170
- ? client.GET("/v1/projects/{projectId}/work-item-custom-field-values", {
3171
- params: { path: { projectId: options.projectId } },
3172
- })
3173
- : client.GET("/v1/projects/{projectId}/work-items/{workItemId}/custom-field-values", {
3174
- params: {
3175
- path: {
3176
- projectId: options.projectId,
3177
- workItemId: options.workItemId,
3178
- },
3179
- },
3180
- }));
3181
- });
3182
- workItemCustomField
3183
- .command("filter-values")
3184
- .requiredOption("--project-id <projectId>")
3185
- .action(async (options) => {
3186
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/work-item-custom-field-filter-values", {
3187
- params: { path: options },
3188
- }));
3189
- });
3190
- workItemCustomField
3191
- .command("set")
3192
- .requiredOption("--project-id <projectId>")
3193
- .requiredOption("--work-item-id <workItemId>")
3194
- .requiredOption("--field-id <fieldId>")
3195
- .requiredOption("--expected-version <version>", "The opaque Work Item version returned by SpecFlow")
3196
- .requiredOption("--value <value>", "Stored value; an empty string clears a non-required field")
3197
- .action(async (options) => {
3198
- if (hasWorkspaceReadToken(dependencies.environment)) {
3199
- exitCode = rejectTokenWrite(dependencies);
3200
- return;
3201
- }
3202
- const expectedVersion = parseOpaqueVersion(options.expectedVersion);
3203
- const idempotencyKey = randomUUID();
3204
- exitCode = await run((client) => client.PUT("/v1/projects/{projectId}/work-items/{workItemId}/custom-field-values/{fieldId}", {
3205
- body: { value: options.value },
3206
- params: {
3207
- header: {
3208
- "idempotency-key": idempotencyKey,
3209
- "if-match": expectedVersion,
3210
- },
3211
- path: {
3212
- fieldId: options.fieldId,
3213
- projectId: options.projectId,
3214
- workItemId: options.workItemId,
3215
- },
3216
- },
3217
- }), {
3218
- ambiguousOutcomeMessage: "Work Item Custom Field value outcome is unknown; list the Work Item's Custom Field values before retrying",
3219
- retryTransportOnce: true,
3220
- });
3221
- });
3222
- const workflowColumn = program.command("workflow-column");
3223
- workflowColumn
3224
- .command("list")
3225
- .requiredOption("--project-id <projectId>")
3226
- .action(async (options) => {
3227
- exitCode = await run((client) => client.GET("/v1/projects/{projectId}/workflow-columns", {
3228
- params: { path: options },
3229
- }));
3230
- });
3231
- workflowColumn
3232
- .command("create")
3233
- .requiredOption("--project-id <projectId>")
3234
- .requiredOption("--name <name>")
3235
- .option("--icon <icon>", "Workflow icon", parseWorkflowIcon)
3236
- .option("--color <color>", "Column color")
3237
- .option("--category <category>", "Lifecycle category", parseWorkflowCategory)
3238
- .action(async (options) => {
3239
- if (hasWorkspaceReadToken(dependencies.environment)) {
3240
- exitCode = rejectTokenWrite(dependencies);
3241
- return;
3242
- }
3243
- const idempotencyKey = randomUUID();
3244
- exitCode = await run((client) => client.POST("/v1/projects/{projectId}/workflow-columns", {
3245
- body: {
3246
- ...(options.color === undefined ? {} : { color: options.color }),
3247
- ...(options.category === undefined ? {} : { category: options.category }),
3248
- ...(options.icon === undefined ? {} : { icon: options.icon }),
3249
- name: options.name,
3250
- },
3251
- params: {
3252
- header: { "idempotency-key": idempotencyKey },
3253
- path: { projectId: options.projectId },
3254
- },
3255
- }), {
3256
- ambiguousOutcomeMessage: "Workflow Column creation outcome is unknown; list Workflow Columns before retrying",
3257
- retryTransportOnce: true,
3258
- });
3259
- });
3260
- workflowColumn
3261
- .command("update")
3262
- .requiredOption("--project-id <projectId>")
3263
- .requiredOption("--column-slug <columnSlug>")
3264
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
3265
- .option("--name <name>")
3266
- .option("--icon <icon>", "Workflow icon", parseWorkflowIcon)
3267
- .option("--color <color>", "Column color")
3268
- .option("--clear-icon", "Remove the column icon")
3269
- .option("--clear-color", "Remove the column color")
3270
- .option("--category <category>", "Lifecycle category", parseWorkflowCategory)
3271
- .action(async (options) => {
3272
- if (hasWorkspaceReadToken(dependencies.environment)) {
3273
- exitCode = rejectTokenWrite(dependencies);
3274
- return;
3275
- }
3276
- if (options.name === undefined &&
3277
- options.icon === undefined &&
3278
- options.clearIcon !== true &&
3279
- options.color === undefined &&
3280
- options.clearColor !== true &&
3281
- options.category === undefined) {
3282
- throw invalidArgument("Workflow Column update requires a field change");
3283
- }
3284
- if (options.clearIcon === true && options.icon !== undefined) {
3285
- throw invalidArgument("Workflow Column update cannot set and clear the icon together");
3286
- }
3287
- if (options.clearColor === true && options.color !== undefined) {
3288
- throw invalidArgument("Workflow Column update cannot set and clear the color together");
3289
- }
3290
- const idempotencyKey = randomUUID();
3291
- exitCode = await run((client) => client.PATCH("/v1/projects/{projectId}/workflow-columns/{columnSlug}", {
3292
- body: {
3293
- ...(options.clearColor === true
3294
- ? { color: null }
3295
- : options.color === undefined
3296
- ? {}
3297
- : { color: options.color }),
3298
- ...(options.clearIcon === true
3299
- ? { icon: null }
3300
- : options.icon === undefined
3301
- ? {}
3302
- : { icon: options.icon }),
3303
- ...(options.category === undefined ? {} : { category: options.category }),
3304
- ...(options.name === undefined ? {} : { name: options.name }),
3305
- },
3306
- params: {
3307
- header: {
3308
- "idempotency-key": idempotencyKey,
3309
- "if-match": options.expectedVersion,
3310
- },
3311
- path: {
3312
- columnSlug: options.columnSlug,
3313
- projectId: options.projectId,
3314
- },
3315
- },
3316
- }), {
3317
- ambiguousOutcomeMessage: "Workflow Column update outcome is unknown; list Workflow Columns before retrying",
3318
- retryTransportOnce: true,
3319
- });
3320
- });
3321
- workflowColumn
3322
- .command("delete")
3323
- .requiredOption("--project-id <projectId>")
3324
- .requiredOption("--column-slug <columnSlug>")
3325
- .requiredOption("--expected-version <expectedVersion>", "Opaque version returned by SpecFlow", parseOpaqueVersion)
3326
- .action(async (options) => {
3327
- if (hasWorkspaceReadToken(dependencies.environment)) {
3328
- exitCode = rejectTokenWrite(dependencies);
3329
- return;
3330
- }
3331
- const idempotencyKey = randomUUID();
3332
- exitCode = await run(async (client) => withSuccessData(await client.DELETE("/v1/projects/{projectId}/workflow-columns/{columnSlug}", {
3333
- params: {
3334
- header: {
3335
- "idempotency-key": idempotencyKey,
3336
- "if-match": options.expectedVersion,
3337
- },
3338
- path: {
3339
- columnSlug: options.columnSlug,
3340
- projectId: options.projectId,
3341
- },
3342
- },
3343
- }), { deleted: { columnSlug: options.columnSlug } }), {
3344
- ambiguousOutcomeMessage: "Workflow Column deletion outcome is unknown; list Workflow Columns before retrying",
3345
- retryTransportOnce: true,
3346
- });
3347
- });
3348
- workflowColumn
3349
- .command("reorder")
3350
- .requiredOption("--project-id <projectId>")
3351
- .requiredOption("--order <order>", 'Comma-separated slug@version pairs in board order — version is the integer inside the column\'s opaque "N" version')
3352
- .action(async (options) => {
3353
- if (hasWorkspaceReadToken(dependencies.environment)) {
3354
- exitCode = rejectTokenWrite(dependencies);
3355
- return;
3356
- }
3357
- const columns = parseColumnOrder(options.order);
3358
- const idempotencyKey = randomUUID();
3359
- exitCode = await run((client) => client.PUT("/v1/projects/{projectId}/workflow-column-order", {
3360
- body: { columns },
3361
- params: {
3362
- header: { "idempotency-key": idempotencyKey },
3363
- path: { projectId: options.projectId },
3364
- },
3365
- }), {
3366
- ambiguousOutcomeMessage: "Workflow Column reorder outcome is unknown; list Workflow Columns before retrying",
3367
- retryTransportOnce: true,
3368
- });
3369
- });
3370
- const token = program.command("token");
3371
- token
3372
- .command("issue")
3373
- .requiredOption("--workspace-id <workspaceId>")
3374
- .requiredOption("--name <name>")
3375
- .option("--expires-at <expiresAt>", "ISO 8601 expiry date-time", parseIsoDateTime)
3376
- .action(async (options) => {
3377
- if (hasWorkspaceReadToken(dependencies.environment)) {
3378
- exitCode = rejectTokenWrite(dependencies);
3379
- return;
3380
- }
3381
- const idempotencyKey = randomUUID();
3382
- exitCode = await run((client) => client.POST("/v1/workspaces/{workspaceId}/read-tokens", {
3383
- body: {
3384
- expiresAt: options.expiresAt ?? null,
3385
- name: options.name,
3386
- },
3387
- params: {
3388
- header: { "idempotency-key": idempotencyKey },
3389
- path: { workspaceId: options.workspaceId },
3390
- },
3391
- }), {
3392
- ambiguousOutcomeMessage: "Workspace read-only Token issuance outcome is unknown; list tokens before retrying",
3393
- retryTransportOnce: true,
3394
- validateSuccess: validateIssuedWorkspaceReadToken,
3395
- });
3396
- });
3397
- token
3398
- .command("list")
3399
- .requiredOption("--workspace-id <workspaceId>")
3400
- .action(async (options) => {
3401
- exitCode = await run((client) => client.GET("/v1/workspaces/{workspaceId}/read-tokens", {
3402
- params: { path: { workspaceId: options.workspaceId } },
3403
- }), { rejectWorkspaceReadToken: true });
3404
- });
3405
- token
3406
- .command("revoke")
3407
- .requiredOption("--workspace-id <workspaceId>")
3408
- .requiredOption("--token-id <tokenId>")
3409
- .action(async (options) => {
3410
- if (hasWorkspaceReadToken(dependencies.environment)) {
3411
- exitCode = rejectTokenWrite(dependencies);
3412
- return;
3413
- }
3414
- exitCode = await run(async (client) => withSuccessData(await client.DELETE("/v1/workspaces/{workspaceId}/read-tokens/{tokenId}", {
3415
- params: { path: options },
3416
- }), { revoked: { tokenId: options.tokenId } }), {
3417
- ambiguousOutcomeMessage: "Workspace read-only Token revocation outcome is unknown; list tokens before retrying",
3418
- retryTransportOnce: true,
3419
- });
3420
- });
292
+ registerWorkItemCommentCommands(context, workItem);
293
+ registerWorkItemRelationCommands(context, workItem);
294
+ registerWorkItemCommands(context, workItem);
295
+ registerWorkItemLabelCommands(context);
296
+ registerWorkItemCustomFieldCommands(context);
297
+ registerWorkflowColumnCommands(context);
298
+ registerTokenCommands(context);
3421
299
  try {
3422
300
  await program.parseAsync([...arguments_], { from: "user" });
3423
301
  return exitCode;
@@ -3441,56 +319,6 @@ export async function runCli(arguments_, originalDependencies) {
3441
319
  throw cause;
3442
320
  }
3443
321
  }
3444
- function validateIssuedWorkspaceReadToken(data) {
3445
- if (typeof data === "object" &&
3446
- data !== null &&
3447
- "credential" in data &&
3448
- data.credential === null) {
3449
- return {
3450
- message: "Workspace read-only Token issuance completed, but its credential cannot be recovered; list or revoke the token before deliberately issuing another",
3451
- reason: "Temporary Failure",
3452
- retryable: false,
3453
- };
3454
- }
3455
- return null;
3456
- }
3457
- function parseRelationCommandKey(value) {
3458
- const key = value.trim();
3459
- if (key.length === 0 || key.length > 200)
3460
- throw invalidArgument("Relation command key must contain 1 to 200 characters");
3461
- return key;
3462
- }
3463
- function parseSearchLimit(value) {
3464
- const limit = Number(value);
3465
- if (!Number.isInteger(limit) || limit < 1 || limit > 100) {
3466
- throw new CommanderError(1, "commander.invalidArgument", "Search limit must be an integer from 1 to 100");
3467
- }
3468
- return limit;
3469
- }
3470
- /** Older names stay accepted: the server reads Confirmed as open and Stale as awaiting a recheck. */
3471
- function parseFindingStatus(value) {
3472
- if (value === "Confirmed" ||
3473
- value === "Dismissed" ||
3474
- value === "Proposed" ||
3475
- value === "Resolved" ||
3476
- value === "Stale" ||
3477
- value === "Unresolved") {
3478
- return value;
3479
- }
3480
- throw invalidArgument("Finding status is not supported");
3481
- }
3482
- function parseProjectStatus(value) {
3483
- if (value === "Active" || value === "Archived" || value === "Trashed") {
3484
- return value;
3485
- }
3486
- throw new CommanderError(1, "commander.invalidArgument", "Project status must be Active, Archived, or Trashed");
3487
- }
3488
- function parseProjectId(value) {
3489
- const normalized = value.trim();
3490
- if (/^[A-Za-z0-9_-]{1,200}$/u.test(normalized))
3491
- return normalized;
3492
- throw invalidArgument("Project ID must be the system identity returned by Project discovery");
3493
- }
3494
322
  function parseSpecId(value) {
3495
323
  const normalized = value.trim().toUpperCase();
3496
324
  if (/^[A-Z]{2,10}-S[1-9]\d*$/u.test(normalized)) {
@@ -3498,583 +326,4 @@ function parseSpecId(value) {
3498
326
  }
3499
327
  throw invalidArgument("Spec ID must have the Workspace prefix, S marker and positive number");
3500
328
  }
3501
- function parseVersionId(value) {
3502
- const normalized = value.trim();
3503
- if (normalized.length > 0 && normalized.length <= 200)
3504
- return normalized;
3505
- throw invalidArgument("--version-id takes a Version id or name, such as v2.4");
3506
- }
3507
- function parseWorkItemId(value) {
3508
- const normalized = value.trim().toUpperCase();
3509
- if (/^[A-Z]{2,10}-[1-9]\d*$/u.test(normalized)) {
3510
- return normalized;
3511
- }
3512
- throw invalidArgument("Work Item ID must be a Project ID followed by a positive number");
3513
- }
3514
- const workflowCategories = ["backlog", "unstarted", "started", "completed", "canceled"];
3515
- const workflowIcons = [
3516
- "backlog",
3517
- "todo",
3518
- "in-progress",
3519
- "in-review",
3520
- "done",
3521
- "canceled",
3522
- "duplicate",
3523
- ];
3524
- function parseWorkflowCategory(value) {
3525
- if (workflowCategories.includes(value))
3526
- return value;
3527
- throw invalidArgument("Workflow category must be backlog, unstarted, started, completed or canceled");
3528
- }
3529
- function parseWorkflowIcon(value) {
3530
- if (workflowIcons.includes(value))
3531
- return value;
3532
- throw invalidArgument("Workflow icon must be backlog, todo, in-progress, in-review, done, canceled or duplicate");
3533
- }
3534
- const workItemPriorities = ["no-priority", "low", "medium", "high", "urgent"];
3535
- function parseWorkItemPriority(value) {
3536
- const normalized = value.trim().toLowerCase();
3537
- if (workItemPriorities.includes(normalized)) {
3538
- return normalized;
3539
- }
3540
- throw invalidArgument("Work Item priority must be no-priority, low, medium, high, or urgent");
3541
- }
3542
- function parseWorkItemDate(value) {
3543
- if (z.iso.date().safeParse(value).success || z.iso.datetime().safeParse(value).success) {
3544
- return value;
3545
- }
3546
- throw invalidArgument("Work Item dates must be an ISO 8601 date or date-time");
3547
- }
3548
- const workItemDueDateFilters = ["dueThisWeek", "dueNextWeek", "noDueDate"];
3549
- const workItemQuerySortFields = [
3550
- "status",
3551
- "startDate",
3552
- "updatedAt",
3553
- "assignee",
3554
- "createdAt",
3555
- "dueDate",
3556
- "number",
3557
- "position",
3558
- "priority",
3559
- "title",
3560
- ];
3561
- const workItemSortOrders = ["asc", "desc"];
3562
- function parseWorkItemDueFilter(value) {
3563
- if (workItemDueDateFilters.includes(value)) {
3564
- return value;
3565
- }
3566
- throw invalidArgument("Due filter must be dueThisWeek, dueNextWeek, or noDueDate");
3567
- }
3568
- function parseWorkItemSortField(value) {
3569
- if (workItemQuerySortFields.includes(value)) {
3570
- return value;
3571
- }
3572
- throw invalidArgument("Work Item sort must be createdAt, dueDate, number, position, priority, or title");
3573
- }
3574
- function parseWorkItemSortOrder(value) {
3575
- if (workItemSortOrders.includes(value)) {
3576
- return value;
3577
- }
3578
- throw invalidArgument("Work Item sort order must be asc or desc");
3579
- }
3580
- /** The member-filter values of a selection that may name Members by Alias or name. */
3581
- function selectionMemberReferences(options) {
3582
- return {
3583
- projectId: options.projectId,
3584
- values: [...options.assignee, ...(options.creator ?? []), ...options.watcher],
3585
- };
3586
- }
3587
- function withResolvedMembers(options, members) {
3588
- if (members === undefined || members.size === 0)
3589
- return options;
3590
- return {
3591
- ...options,
3592
- assignee: substituteMemberReferences(options.assignee, members),
3593
- ...(options.creator === undefined
3594
- ? {}
3595
- : { creator: substituteMemberReferences(options.creator, members) }),
3596
- watcher: substituteMemberReferences(options.watcher, members),
3597
- };
3598
- }
3599
- /**
3600
- * Builds the wire selection query shared by `work-item list` and
3601
- * `work-item board`: repeatable flags become the API's CSV fields and
3602
- * repeated `fieldId=value` pairs merge into the `customFields` JSON map.
3603
- */
3604
- function workItemSelectionQuery(options) {
3605
- const customFields = {};
3606
- for (const entry of options.customField) {
3607
- const { fieldId, value } = parseCustomFieldAssignment(entry);
3608
- customFields[fieldId] = [...(customFields[fieldId] ?? []), value];
3609
- }
3610
- return {
3611
- ...(options.creator === undefined || options.creator.length === 0
3612
- ? {}
3613
- : { creator: options.creator.join(",") }),
3614
- ...Object.fromEntries(["operators", "created", "updated", "relations", "specs", "pullRequests"].flatMap((key) => (options[key] === undefined ? [] : [[key, options[key]]]))),
3615
- ...(options.assignee.length === 0 ? {} : { assignee: options.assignee.join(",") }),
3616
- ...(options.assignedAgent.length === 0
3617
- ? {}
3618
- : { assignedAgent: options.assignedAgent.join(",") }),
3619
- ...(options.watcher.length === 0 ? {} : { watcher: options.watcher.join(",") }),
3620
- ...(Object.keys(customFields).length === 0
3621
- ? {}
3622
- : { customFields: JSON.stringify(customFields) }),
3623
- ...(options.due.length === 0 ? {} : { due: options.due.join(",") }),
3624
- ...(options.dueAfter === undefined ? {} : { dueAfter: options.dueAfter }),
3625
- ...(options.dueBefore === undefined ? {} : { dueBefore: options.dueBefore }),
3626
- ...(options.label.length === 0 ? {} : { label: options.label.join(",") }),
3627
- ...(options.priority.length === 0 ? {} : { priority: options.priority.join(",") }),
3628
- ...(options.repositoryConnectionId === undefined
3629
- ? {}
3630
- : { repositoryConnectionId: options.repositoryConnectionId }),
3631
- ...(options.search === undefined ? {} : { search: options.search }),
3632
- ...(options.sort === undefined ? {} : { sortBy: options.sort }),
3633
- ...(options.order === undefined ? {} : { sortOrder: options.order }),
3634
- ...(options.startAfter === undefined ? {} : { startAfter: options.startAfter }),
3635
- ...(options.startBefore === undefined ? {} : { startBefore: options.startBefore }),
3636
- ...(options.status.length === 0 ? {} : { status: options.status.join(",") }),
3637
- };
3638
- }
3639
- /** List and board only: which completed Work Items to keep. */
3640
- function workItemCompletedFlag(command) {
3641
- return command.option("--completed <filter>", "Completed Work Items to keep: all (default), pastDay, pastWeek, pastMonth, or none", (value) => {
3642
- if (workItemCompletedFilters.includes(value))
3643
- return value;
3644
- throw invalidArgument(`Completed filter must be ${workItemCompletedFilters.join(", ")}`);
3645
- });
3646
- }
3647
- /**
3648
- * The selection options `work-item list` and `work-item board` share.
3649
- * Attach with `workItemSelectionFlags(command)`.
3650
- */
3651
- function workItemSelectionFlags(command) {
3652
- return command
3653
- .option("--creator <id>", "Creator User ID, me, or an exact Member Alias or name; repeat for several", collectOption, [])
3654
- .option("--operators <json>", "Category -> include|exclude; custom fields use customField:<id>")
3655
- .option("--created <filter>", "today|pastWeek|past2Weeks|pastMonth|past3Months or YYYY-MM-DD (UTC inclusive)")
3656
- .option("--updated <filter>", "Same time choices as --created")
3657
- .option("--relations <csv>", "blocked,blocking,hasParent,hasChildren,related")
3658
- .option("--specs <csv>", "Linked Spec IDs, or none")
3659
- .option("--pull-requests <csv>", "none,draft,open,merged,closed; synchronized state only")
3660
- .option("--assignee <assignee>", "Filter by assignee User ID, me, unassigned, or an exact Member Alias or name; repeat for several", collectOption, [])
3661
- .option("--assigned-agent <agentId>", "Filter by executing Agent ID or unassigned; repeat for several", collectOption, [])
3662
- .option("--watcher <userId>", "Filter by watcher User ID, me, or an exact Member Alias or name; repeat for several", collectOption, [])
3663
- .option("--custom-field <fieldId=value>", "Filter by Custom Field value; repeat to OR values or combine fields", collectOption, [])
3664
- .option("--due <filter>", "Filter by due bucket: dueThisWeek, dueNextWeek, or noDueDate; repeat for several", (value, previous) => [
3665
- ...previous,
3666
- parseWorkItemDueFilter(value),
3667
- ], [])
3668
- .option("--due-after <date>", "Filter due on/after", parseWorkItemDate)
3669
- .option("--due-before <date>", "Filter due on/before", parseWorkItemDate)
3670
- .option("--label <labelId>", "Filter by Work Item Label ID; repeat for several", collectOption, [])
3671
- .option("--priority <priority>", "Filter by priority; repeat for several", (value, previous) => [...previous, parseWorkItemPriority(value)], [])
3672
- .option("--repository-connection-id <id>", "Filter by an explicit GitHub repository connection")
3673
- .option("--search <search>", "Filter by title search text")
3674
- .option("--sort <field>", "Sort by field", parseWorkItemSortField)
3675
- .option("--order <order>", "Sort order", parseWorkItemSortOrder)
3676
- .option("--start-after <date>", "Filter start on/after", parseWorkItemDate)
3677
- .option("--start-before <date>", "Filter start on/before", parseWorkItemDate)
3678
- .option("--status <status>", "Filter by Workflow Column slug or virtual status; repeat for several", collectOption, []);
3679
- }
3680
- function parseWorkItemBulkAction(value) {
3681
- if (workItemBulkActions.includes(value)) {
3682
- return value;
3683
- }
3684
- throw invalidArgument(`Bulk action must be ${workItemBulkActions.join(", ")}`);
3685
- }
3686
- /**
3687
- * Targets default to the route Project; an explicit `projectId/` selects
3688
- * another owner without inferring Project identity from Workspace numbering.
3689
- */
3690
- function parseWorkItemBulkTarget(value, previous) {
3691
- const [identity, version, extra] = value.split("@");
3692
- const segments = identity?.split("/") ?? [];
3693
- const id = segments.length === 2 ? segments[1] : segments[0];
3694
- const projectId = segments.length === 2 ? parseProjectId(segments[0] ?? "") : undefined;
3695
- if (segments.length > 2 ||
3696
- id === undefined ||
3697
- version === undefined ||
3698
- extra !== undefined ||
3699
- !/^[A-Z]{2,10}-[1-9]\d*$/u.test(id.trim().toUpperCase()) ||
3700
- !/^[1-9]\d*$/u.test(version)) {
3701
- throw invalidArgument(`Bulk target "${value}" must be a WORK-ITEM-ID@version pair`);
3702
- }
3703
- const numericVersion = Number(version);
3704
- if (!Number.isSafeInteger(numericVersion) || numericVersion > 2_147_483_647) {
3705
- throw invalidArgument(`Bulk target "${value}" has a version outside the supported range`);
3706
- }
3707
- return [
3708
- ...previous,
3709
- {
3710
- expectedVersion: `"${version}"`,
3711
- id: id.trim().toUpperCase(),
3712
- ...(projectId === undefined ? {} : { projectId }),
3713
- },
3714
- ];
3715
- }
3716
- function parseBoardPosition(value) {
3717
- const position = Number(value);
3718
- if (!Number.isInteger(position) || position < 0 || position > 2_147_483_646) {
3719
- throw invalidArgument("Board position must be a nonnegative integer within the supported range");
3720
- }
3721
- return position;
3722
- }
3723
- /**
3724
- * Comma-separated `slug@version` pairs become the verbatim board order —
3725
- * position equals list index, matching the reorder contract, and each
3726
- * version is the column's observed version sent as its reorder
3727
- * precondition.
3728
- */
3729
- function parseColumnOrder(value) {
3730
- const entries = value
3731
- .split(",")
3732
- .map((entry) => entry.trim())
3733
- .filter((entry) => entry.length > 0);
3734
- if (entries.length === 0 || entries.length > 200) {
3735
- throw invalidArgument("Workflow Column order must list between 1 and 200 slug@version pairs");
3736
- }
3737
- const parsed = entries.map((entry, position) => {
3738
- const [slug, version, extra] = entry.split("@");
3739
- if (slug === undefined ||
3740
- version === undefined ||
3741
- extra !== undefined ||
3742
- !/^[1-9]\d*$/u.test(version)) {
3743
- throw invalidArgument(`Workflow Column order entry "${entry}" must be a slug@version pair`);
3744
- }
3745
- return { expectedVersion: `"${version}"`, position, slug };
3746
- });
3747
- const slugs = parsed.map((entry) => entry.slug);
3748
- if (new Set(slugs).size !== slugs.length) {
3749
- throw invalidArgument("Workflow Column order cannot repeat a slug");
3750
- }
3751
- return parsed;
3752
- }
3753
- const workItemCustomFieldTypes = [
3754
- "text",
3755
- "number",
3756
- "date",
3757
- "multi-select",
3758
- "dropdown",
3759
- "boolean",
3760
- ];
3761
- function parseWorkItemCustomFieldType(value) {
3762
- const normalized = value.trim().toLowerCase();
3763
- if (workItemCustomFieldTypes.includes(normalized)) {
3764
- return normalized;
3765
- }
3766
- throw invalidArgument("Custom Field type must be text, number, date, dropdown, multi-select, or boolean");
3767
- }
3768
- function collectOption(value, previous) {
3769
- return [...previous, value];
3770
- }
3771
- /**
3772
- * A `fieldId=value` assignment splits on the first `=` so values may carry
3773
- * the separator; the field id itself is an opaque server identity.
3774
- */
3775
- function parseCustomFieldAssignment(value) {
3776
- const separator = value.indexOf("=");
3777
- const fieldId = separator === -1 ? "" : value.slice(0, separator).trim();
3778
- if (fieldId.length === 0 || fieldId.length > 200) {
3779
- throw invalidArgument("Custom Field values must be written as fieldId=value");
3780
- }
3781
- const fieldValue = value.slice(separator + 1);
3782
- if (fieldValue.length > 2_000) {
3783
- throw invalidArgument("Custom Field values must stay within the supported length");
3784
- }
3785
- return { fieldId, value: fieldValue };
3786
- }
3787
- /**
3788
- * Comma-separated `id@version` pairs become the verbatim display order —
3789
- * position equals list index, matching the reorder contract, and each
3790
- * version is the field's observed version sent as its reorder
3791
- * precondition.
3792
- */
3793
- function parseFieldOrder(value) {
3794
- const entries = value
3795
- .split(",")
3796
- .map((entry) => entry.trim())
3797
- .filter((entry) => entry.length > 0);
3798
- if (entries.length === 0 || entries.length > 500) {
3799
- throw invalidArgument("Custom Field order must list between 1 and 500 id@version pairs");
3800
- }
3801
- const parsed = entries.map((entry, position) => {
3802
- const [id, version, extra] = entry.split("@");
3803
- if (id === undefined ||
3804
- version === undefined ||
3805
- extra !== undefined ||
3806
- !/^[1-9]\d*$/u.test(version)) {
3807
- throw invalidArgument(`Custom Field order entry "${entry}" must be an id@version pair`);
3808
- }
3809
- return { expectedVersion: `"${version}"`, id, position };
3810
- });
3811
- const ids = parsed.map((entry) => entry.id);
3812
- if (new Set(ids).size !== ids.length) {
3813
- throw invalidArgument("Custom Field order cannot repeat a field id");
3814
- }
3815
- return parsed;
3816
- }
3817
- function parseOpaqueVersion(value) {
3818
- if (/^"[1-9]\d*"$/u.test(value)) {
3819
- return value;
3820
- }
3821
- throw invalidArgument("Expected version must be the opaque version returned by SpecFlow");
3822
- }
3823
- function parseIsoDateTime(value) {
3824
- if (z.iso.datetime().safeParse(value).success) {
3825
- return value;
3826
- }
3827
- throw invalidArgument("Expiry must be an ISO 8601 date-time");
3828
- }
3829
- function parseSpecState(value) {
3830
- if (value === "Ready" || value === "Unavailable") {
3831
- return value;
3832
- }
3833
- throw invalidArgument("Spec State must be Ready or Unavailable");
3834
- }
3835
- function parseSourceReferences(value) {
3836
- let parsed;
3837
- try {
3838
- parsed = JSON.parse(value);
3839
- }
3840
- catch {
3841
- throw invalidArgument("Source References must be valid JSON");
3842
- }
3843
- const sourceReferences = sourceReferencesInputSchema.safeParse(parsed);
3844
- if (!sourceReferences.success) {
3845
- throw invalidArgument("Source References do not match the supported bounded contract");
3846
- }
3847
- return sourceReferences.data.map((reference) => ({
3848
- ...(reference.externalRevision === undefined
3849
- ? {}
3850
- : { externalRevision: reference.externalRevision }),
3851
- ...(reference.section === undefined ? {} : { section: reference.section }),
3852
- title: reference.title,
3853
- url: reference.url,
3854
- }));
3855
- }
3856
- function invalidArgument(message) {
3857
- return new CommanderError(1, "commander.invalidArgument", message);
3858
- }
3859
- function parseGlossaryEntries(value) {
3860
- let parsed;
3861
- try {
3862
- parsed = JSON.parse(value);
3863
- }
3864
- catch {
3865
- throw new CommanderError(1, "commander.invalidArgument", "Glossary Entries must be valid JSON");
3866
- }
3867
- const entries = glossaryEntriesInputSchema.safeParse(parsed);
3868
- if (!entries.success) {
3869
- throw new CommanderError(1, "commander.invalidArgument", "Glossary Entries do not match the supported contract");
3870
- }
3871
- return entries.data;
3872
- }
3873
- function parseStringArray(value, label) {
3874
- let parsed;
3875
- try {
3876
- parsed = JSON.parse(value);
3877
- }
3878
- catch {
3879
- throw invalidArgument(`${label} must be valid JSON`);
3880
- }
3881
- const result = z.array(z.string().trim().min(1).max(200)).max(500).safeParse(parsed);
3882
- if (!result.success) {
3883
- throw invalidArgument(`${label} must be a bounded JSON string array`);
3884
- }
3885
- return result.data;
3886
- }
3887
- function toAgentProvenance(options) {
3888
- return {
3889
- ...(options.agentRevision === undefined ? {} : { agentRevision: options.agentRevision }),
3890
- ...(options.agentModel === undefined ? {} : { model: options.agentModel }),
3891
- sourceReferenceIds: options.sourceReferenceIds === undefined
3892
- ? []
3893
- : parseStringArray(options.sourceReferenceIds, "source reference IDs"),
3894
- };
3895
- }
3896
- function parseRoleStatements(value) {
3897
- let parsed;
3898
- try {
3899
- parsed = JSON.parse(value);
3900
- }
3901
- catch {
3902
- throw invalidArgument("Role statements must be valid JSON");
3903
- }
3904
- const statements = roleStatementsInputSchema.safeParse(parsed);
3905
- if (!statements.success) {
3906
- throw invalidArgument("Role statements must map permission resources to non-empty action arrays");
3907
- }
3908
- return statements.data;
3909
- }
3910
- function parseProposalTargetKind(value) {
3911
- if (value === "Glossary" || value === "Spec") {
3912
- return value;
3913
- }
3914
- throw invalidArgument("Proposal target kind must be Spec or Glossary");
3915
- }
3916
- function parseProposalStatus(value) {
3917
- if (value === "Applied" || value === "Discarded" || value === "Open") {
3918
- return value;
3919
- }
3920
- throw invalidArgument("Proposal status must be Open, Applied, or Discarded");
3921
- }
3922
- function parseFindingInput(value) {
3923
- let parsed;
3924
- try {
3925
- parsed = JSON.parse(value);
3926
- }
3927
- catch {
3928
- throw invalidArgument("Finding input must be valid JSON");
3929
- }
3930
- const finding = findingCreateInputSchema.safeParse(parsed);
3931
- if (!finding.success) {
3932
- throw invalidArgument("Finding input does not match the supported contract");
3933
- }
3934
- return finding.data;
3935
- }
3936
- function withSuccessData(result, data) {
3937
- return result.response.ok && result.data === undefined ? { ...result, data } : result;
3938
- }
3939
- /**
3940
- * Whether a `work-item-label delete` payload is the still-running cascade —
3941
- * the 202 body carries the definition with its deletion boundary set.
3942
- */
3943
- function isWorkItemLabelDeletionPending(data) {
3944
- if (typeof data !== "object" || data === null || !("workItemLabel" in data)) {
3945
- return false;
3946
- }
3947
- const label = data.workItemLabel;
3948
- return (typeof label === "object" &&
3949
- label !== null &&
3950
- label.deletionStartedAt !== null &&
3951
- label.deletionStartedAt !== undefined);
3952
- }
3953
- function rejectTokenWrite(dependencies) {
3954
- if (hasWorkspaceReadToken(dependencies.environment)) {
3955
- writeSkillError(dependencies, {
3956
- message: "Workspace read-only Token does not permit write operations",
3957
- reason: "Permission Denied",
3958
- retryable: false,
3959
- });
3960
- return 3;
3961
- }
3962
- writeSkillError(dependencies, {
3963
- message: "An authenticated CLI Session is required",
3964
- reason: "Authentication Failed",
3965
- retryable: false,
3966
- });
3967
- return 2;
3968
- }
3969
- function parseCommentContent(value) {
3970
- const result = z
3971
- .string()
3972
- .trim()
3973
- .min(1)
3974
- .max(20_000)
3975
- .refine((content) => !content.includes("\0"))
3976
- .safeParse(value);
3977
- if (!result.success)
3978
- throw invalidArgument("Comment content must contain 1 through 20000 characters without null characters");
3979
- return result.data;
3980
- }
3981
- function parseCommentId(value) {
3982
- if (!z.uuid().safeParse(value).success)
3983
- throw invalidArgument("Comment ID must be a UUID returned by SpecFlow");
3984
- return value;
3985
- }
3986
- function parseCommentCommandKey(value) {
3987
- if (!z.uuid().safeParse(value).success)
3988
- throw invalidArgument("Comment command key must be a UUID; reuse the same key and inputs when retrying");
3989
- return value;
3990
- }
3991
- function parseNotificationUuid(value) {
3992
- if (!z.uuid().safeParse(value).success)
3993
- throw invalidArgument("Notification identity and command keys must be UUIDs");
3994
- return value;
3995
- }
3996
- function parseNotificationEventData(value) {
3997
- let parsed;
3998
- try {
3999
- parsed = JSON.parse(value);
4000
- }
4001
- catch {
4002
- throw invalidArgument("Notification event data must be a JSON object");
4003
- }
4004
- const result = z.record(z.string(), z.json()).safeParse(parsed);
4005
- if (!result.success)
4006
- throw invalidArgument("Notification event data must be a JSON object");
4007
- return result.data;
4008
- }
4009
- function parseNotificationPreferences(value) {
4010
- let parsed;
4011
- try {
4012
- parsed = JSON.parse(value);
4013
- }
4014
- catch {
4015
- throw invalidArgument("Notification preferences must be a JSON object");
4016
- }
4017
- const result = z
4018
- .object({
4019
- taskAssignmentEnabled: z.boolean().optional(),
4020
- taskCommentEnabled: z.boolean().optional(),
4021
- taskStatusChangeEnabled: z.boolean().optional(),
4022
- dueDateReminderEnabled: z.boolean().optional(),
4023
- dueDateReminderMinutes: z.number().int().min(5).max(43200).optional(),
4024
- codeReviewEnabled: z.boolean().optional(),
4025
- })
4026
- .strict()
4027
- .safeParse(parsed);
4028
- if (!result.success)
4029
- throw invalidArgument("Notification preferences contain unsupported settings or invalid values");
4030
- const data = result.data;
4031
- return {
4032
- ...(data.taskAssignmentEnabled === undefined
4033
- ? {}
4034
- : { taskAssignmentEnabled: data.taskAssignmentEnabled }),
4035
- ...(data.taskCommentEnabled === undefined
4036
- ? {}
4037
- : { taskCommentEnabled: data.taskCommentEnabled }),
4038
- ...(data.taskStatusChangeEnabled === undefined
4039
- ? {}
4040
- : { taskStatusChangeEnabled: data.taskStatusChangeEnabled }),
4041
- ...(data.dueDateReminderEnabled === undefined
4042
- ? {}
4043
- : { dueDateReminderEnabled: data.dueDateReminderEnabled }),
4044
- ...(data.dueDateReminderMinutes === undefined
4045
- ? {}
4046
- : { dueDateReminderMinutes: data.dueDateReminderMinutes }),
4047
- ...(data.codeReviewEnabled === undefined ? {} : { codeReviewEnabled: data.codeReviewEnabled }),
4048
- };
4049
- }
4050
- const reviewPlanInputSchema = z.discriminatedUnion("cadence", [
4051
- z.object({ cadence: z.literal("Disabled") }).strict(),
4052
- z.object({ cadence: z.literal("Daily"), timeOfDay: z.string(), timeZone: z.string() }).strict(),
4053
- z
4054
- .object({
4055
- cadence: z.literal("Weekly"),
4056
- dayOfWeek: z.number().int().min(1).max(7),
4057
- timeOfDay: z.string(),
4058
- timeZone: z.string(),
4059
- })
4060
- .strict(),
4061
- ]);
4062
- const reviewFindingTypes = [
4063
- "Contradiction",
4064
- "Conflict",
4065
- "Duplicate",
4066
- "Terminology",
4067
- "Unverifiable",
4068
- "Ambiguity",
4069
- ];
4070
- function parseFindingTypeList(value) {
4071
- const names = value
4072
- .split(",")
4073
- .map((name) => name.trim())
4074
- .filter((name) => name.length > 0);
4075
- const types = reviewFindingTypes.filter((type) => names.includes(type));
4076
- if (names.length === 0 || types.length !== new Set(names).size)
4077
- throw invalidArgument(`Finding types must be among ${reviewFindingTypes.join(", ")}`);
4078
- return types;
4079
- }
4080
329
  //# sourceMappingURL=cli.js.map