@defrex/autobuild 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +440 -95
  3. package/bin/ab-dispatch-kernel.ts +1 -0
  4. package/docs/accounts.md +9 -0
  5. package/docs/agent-runtimes.md +1 -0
  6. package/docs/answering-blocked-builds.md +2 -1
  7. package/docs/architecture.md +290 -130
  8. package/docs/assets/headline-wide.png +0 -0
  9. package/docs/build-store.md +33 -3
  10. package/docs/cli.md +2 -1
  11. package/docs/configuration-overview.md +9 -0
  12. package/docs/configuration.md +166 -101
  13. package/docs/dispatcher-hosting.md +19 -3
  14. package/docs/dispatcher.md +9 -4
  15. package/docs/integration-overview.md +2 -2
  16. package/docs/integration-tree.md +91 -28
  17. package/docs/merge-policy.md +28 -9
  18. package/docs/operator-api.md +43 -18
  19. package/docs/operator-surfaces.md +1 -1
  20. package/docs/plugin-authoring.md +85 -8
  21. package/docs/remote-store-protocol.md +25 -7
  22. package/docs/remote-ticket-protocol.md +126 -12
  23. package/docs/restacking.md +20 -6
  24. package/docs/seams.md +2 -2
  25. package/docs/setup.md +19 -13
  26. package/docs/spec-standard.md +2 -1
  27. package/docs/ticket-dependencies.md +26 -8
  28. package/docs/ticket-migration.md +70 -7
  29. package/docs/ticket-sources.md +82 -5
  30. package/docs/tickets.md +34 -2
  31. package/docs/troubleshooting.md +2 -2
  32. package/docs/verification.md +5 -5
  33. package/docs/website.md +8 -0
  34. package/docs/workspaces.md +1 -1
  35. package/package.json +5 -4
  36. package/packages/core/src/accounts/hosted-readiness.ts +21 -0
  37. package/packages/core/src/cli/attention.ts +1 -0
  38. package/packages/core/src/cli/build-control.ts +36 -12
  39. package/packages/core/src/cli/connect.ts +9 -18
  40. package/packages/core/src/cli/context.ts +44 -0
  41. package/packages/core/src/cli/dashboard/configuration.ts +11 -0
  42. package/packages/core/src/cli/dashboard/model.ts +40 -10
  43. package/packages/core/src/cli/dashboard/queue.ts +21 -0
  44. package/packages/core/src/cli/dashboard/render.ts +40 -22
  45. package/packages/core/src/cli/dispatch-frontend.ts +63 -30
  46. package/packages/core/src/cli/dispatch-mode.ts +35 -16
  47. package/packages/core/src/cli/dispatch-repository-feed.ts +40 -11
  48. package/packages/core/src/cli/dispatch.ts +154 -47
  49. package/packages/core/src/cli/help.ts +59 -22
  50. package/packages/core/src/cli/init-hosted-accounts.ts +54 -0
  51. package/packages/core/src/cli/init-readiness-remote.ts +16 -3
  52. package/packages/core/src/cli/init-validation.ts +144 -42
  53. package/packages/core/src/cli/issue-links.ts +67 -0
  54. package/packages/core/src/cli/main.ts +32 -15
  55. package/packages/core/src/cli/pr-summary-publication.ts +38 -7
  56. package/packages/core/src/cli/publication-settlement.ts +36 -24
  57. package/packages/core/src/cli/repository-status.ts +201 -49
  58. package/packages/core/src/cli/status.ts +41 -3
  59. package/packages/core/src/cli/terminals.ts +37 -2
  60. package/packages/core/src/cli/ticket-editor.ts +20 -6
  61. package/packages/core/src/cli/ticket.ts +264 -46
  62. package/packages/core/src/cli/triage-count-sampler.ts +59 -0
  63. package/packages/core/src/cli/watch.ts +4 -0
  64. package/packages/core/src/config/live.ts +45 -4
  65. package/packages/core/src/config/load.ts +9 -0
  66. package/packages/core/src/config/pipeline-source.ts +6 -2
  67. package/packages/core/src/config/ready-assignee.ts +86 -0
  68. package/packages/core/src/config/schema.ts +164 -36
  69. package/packages/core/src/distribution-packaging.ts +1 -1
  70. package/packages/core/src/events/catalog.ts +5 -0
  71. package/packages/core/src/events/compatibility.ts +2 -1
  72. package/packages/core/src/events/payloads.ts +70 -0
  73. package/packages/core/src/events/policy.ts +8 -0
  74. package/packages/core/src/events/repository.ts +91 -28
  75. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +41 -0
  76. package/packages/core/src/kernel/build-identity.ts +12 -0
  77. package/packages/core/src/kernel/change-presence.ts +139 -6
  78. package/packages/core/src/kernel/dispatch-capacity.ts +80 -14
  79. package/packages/core/src/kernel/dispatch-status.ts +10 -1
  80. package/packages/core/src/kernel/dispatch-upgrade.ts +104 -5
  81. package/packages/core/src/kernel/engine.ts +4 -2
  82. package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -0
  83. package/packages/core/src/kernel/generators/repository-journals.ts +15 -1
  84. package/packages/core/src/kernel/harvest.ts +4 -1
  85. package/packages/core/src/kernel/integration-completeness.ts +104 -17
  86. package/packages/core/src/kernel/integration-landing.ts +17 -0
  87. package/packages/core/src/kernel/integration-state.ts +17 -0
  88. package/packages/core/src/kernel/issue-keywords.ts +202 -0
  89. package/packages/core/src/kernel/janitor-failure.ts +11 -0
  90. package/packages/core/src/kernel/kernel-git.ts +87 -0
  91. package/packages/core/src/kernel/landing-readiness.ts +25 -17
  92. package/packages/core/src/kernel/log-index.ts +1 -1
  93. package/packages/core/src/kernel/node-issue-links.ts +142 -0
  94. package/packages/core/src/kernel/node-parent.ts +6 -0
  95. package/packages/core/src/kernel/node-restack-transaction.ts +2 -0
  96. package/packages/core/src/kernel/pr-summary.ts +24 -0
  97. package/packages/core/src/kernel/read-deferrals.ts +75 -12
  98. package/packages/core/src/kernel/read-facts.ts +32 -1
  99. package/packages/core/src/kernel/reconcile-restack.ts +1 -1
  100. package/packages/core/src/kernel/reducer-registry.ts +31 -1
  101. package/packages/core/src/kernel/reducer.ts +90 -2
  102. package/packages/core/src/kernel/ticket-preparation.ts +12 -0
  103. package/packages/core/src/kernel/verify-budget.ts +43 -0
  104. package/packages/core/src/operator/index.ts +3 -1
  105. package/packages/core/src/operator/presentation.ts +3 -0
  106. package/packages/core/src/operator/protocol.ts +38 -2
  107. package/packages/core/src/operator/query.ts +66 -29
  108. package/packages/core/src/operator/registry.ts +47 -26
  109. package/packages/core/src/operator/tickets.ts +77 -10
  110. package/packages/core/src/plugin-sdk/index.ts +13 -0
  111. package/packages/core/src/plugins/manifest.ts +1 -1
  112. package/packages/core/src/plugins/registry.ts +1 -0
  113. package/packages/core/src/ports/forge/contract.ts +69 -0
  114. package/packages/core/src/ports/forge/create.ts +5 -0
  115. package/packages/core/src/ports/forge/fake.ts +184 -3
  116. package/packages/core/src/ports/forge/git-rewrite.ts +4 -2
  117. package/packages/core/src/ports/forge/github.ts +175 -38
  118. package/packages/core/src/ports/forge/local-git.ts +14 -0
  119. package/packages/core/src/ports/forge/readiness.ts +10 -0
  120. package/packages/core/src/ports/forge-failure.ts +43 -0
  121. package/packages/core/src/ports/runner/claude.ts +7 -1
  122. package/packages/core/src/ports/runner/codex.ts +7 -2
  123. package/packages/core/src/ports/runner/native-cli-fixture.ts +2 -1
  124. package/packages/core/src/ports/runner/pi.ts +7 -1
  125. package/packages/core/src/ports/runner/runtime.ts +3 -0
  126. package/packages/core/src/ports/runner/start-prompt.ts +37 -0
  127. package/packages/core/src/ports/tickets/contract.ts +320 -7
  128. package/packages/core/src/ports/tickets/create.ts +72 -17
  129. package/packages/core/src/ports/tickets/fake.ts +18 -0
  130. package/packages/core/src/ports/tickets/file-codec.ts +20 -0
  131. package/packages/core/src/ports/tickets/file.ts +43 -1
  132. package/packages/core/src/ports/tickets/github-fake.ts +1123 -0
  133. package/packages/core/src/ports/tickets/github-issues.ts +431 -0
  134. package/packages/core/src/ports/tickets/github-validators.ts +194 -0
  135. package/packages/core/src/ports/tickets/github.ts +2029 -0
  136. package/packages/core/src/ports/tickets/hosted-index.ts +34 -3
  137. package/packages/core/src/ports/tickets/issue-links.ts +86 -0
  138. package/packages/core/src/ports/tickets/lifecycle.ts +60 -4
  139. package/packages/core/src/ports/tickets/linear.ts +66 -6
  140. package/packages/core/src/ports/tickets/migration.ts +290 -68
  141. package/packages/core/src/ports/tickets/operations.ts +98 -12
  142. package/packages/core/src/ports/tickets/priority.ts +55 -0
  143. package/packages/core/src/ports/tickets/remote-protocol.ts +195 -29
  144. package/packages/core/src/ports/tickets/remote.ts +188 -13
  145. package/packages/core/src/ports/tickets/revision.ts +22 -1
  146. package/packages/core/src/ports/tickets/states.ts +43 -0
  147. package/packages/core/src/ports/tickets/tree.ts +58 -12
  148. package/packages/core/src/ports/tickets/update.ts +12 -2
  149. package/packages/core/src/ports/types.ts +194 -11
  150. package/packages/core/src/ports/workspace/commit-preservation.ts +135 -13
  151. package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
  152. package/packages/core/src/ports/workspace/vercel-sandbox.ts +132 -27
  153. package/packages/core/src/processes/build-runner.ts +99 -21
  154. package/packages/core/src/processes/dispatcher.ts +1080 -533
  155. package/packages/core/src/processes/execution-no-progress.ts +5 -0
  156. package/packages/core/src/processes/harvest-runner.ts +17 -8
  157. package/packages/core/src/processes/harvest.ts +5 -8
  158. package/packages/core/src/processes/tick-publication.ts +12 -2
  159. package/packages/core/src/processes/ticket-scan-schedule.ts +78 -0
  160. package/packages/core/src/processes/workspace-preservation.ts +37 -2
  161. package/packages/core/src/runtime-identity.ts +10 -2
  162. package/packages/core/src/scenarios/harness.ts +4 -0
  163. package/packages/core/src/store/adapter.ts +7 -1
  164. package/packages/core/src/store/contract.ts +83 -2
  165. package/packages/core/src/store/digest.ts +32 -1
  166. package/packages/core/src/store/reducer-value-shapes.json +4187 -3391
  167. package/packages/core/src/store/remote/protocol.ts +2 -0
  168. package/packages/core/src/store/remote/released-clients.json +22 -0
  169. package/packages/core/src/store/remote/released-reducer-values/1.5.0.json +26924 -0
  170. package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
  171. package/packages/core/src/store/repo-state-events.ts +2 -0
  172. package/packages/core/src/store/types.ts +5 -0
  173. package/packages/core/src/testing/dispatch-read-budget.ts +729 -123
  174. package/packages/core/src/testing/index.ts +18 -1
  175. package/packages/core/src/testing/presence-history.ts +79 -0
  176. package/packages/core/src/testing/reduced-read-budget.ts +1197 -31
  177. package/packages/core/src/testing/upgrade-generations.ts +77 -0
  178. package/skills/code-review/SKILL.md +4 -3
  179. package/skills/finalize/SKILL.md +18 -2
  180. package/skills/guide/SKILL.md +382 -139
  181. package/skills/guide/references/accounts.md +9 -0
  182. package/skills/guide/references/integration-tree.md +91 -28
  183. package/skills/guide/references/merge-policy.md +28 -9
  184. package/skills/guide/references/operator-api.md +43 -18
  185. package/skills/guide/references/plugin-authoring.md +85 -8
  186. package/skills/guide/references/remote-store-protocol.md +25 -7
  187. package/skills/guide/references/remote-ticket-protocol.md +126 -12
  188. package/skills/guide/references/restacking.md +20 -6
  189. package/skills/guide/references/setup.md +19 -13
  190. package/skills/guide/references/spec-standard.md +2 -1
  191. package/skills/guide/references/ticket-dependencies.md +26 -8
  192. package/skills/guide/references/ticket-migration.md +70 -7
  193. package/skills/harvest-review/SKILL.md +4 -3
  194. package/skills/implement/SKILL.md +20 -1
  195. package/skills/operate/SKILL.md +103 -28
  196. package/skills/plan/SKILL.md +1 -1
  197. package/skills/reconcile/SKILL.md +5 -4
  198. package/skills/spec/SKILL.md +15 -2
  199. package/skills/tickets/SKILL.md +114 -37
  200. package/templates/autobuild.toml +5 -0
  201. package/templates/hosted-service/package.json +2 -2
@@ -3,7 +3,7 @@ import { tmpdir } from 'node:os'
3
3
  import { join } from 'node:path'
4
4
  import type { TicketSource, TicketUpdate } from '../ports/types'
5
5
  import { parseTicketFile, serializeTicketFile } from '../ports/tickets/file-codec'
6
- import { TicketRevisionUnsupported } from '../ports/tickets/revision'
6
+ import { TicketRevisionConflict } from '../ports/tickets/revision'
7
7
  import { requireTicket, updateTicket } from '../ports/tickets/operations'
8
8
 
9
9
  export type TicketEditorRunner = (command: string, path: string) => Promise<number>
@@ -25,7 +25,6 @@ export async function editTicket(
25
25
  stdout: (line: string) => void,
26
26
  runner: TicketEditorRunner = runTicketEditor,
27
27
  ): Promise<void> {
28
- if (!source.mutateIfRevision) throw new TicketRevisionUnsupported(source.name)
29
28
  const command = env.VISUAL?.trim() || env.EDITOR?.trim()
30
29
  if (!command) throw new Error('set VISUAL or EDITOR to edit a ticket')
31
30
  const ticket = await requireTicket(source, id)
@@ -36,6 +35,8 @@ export async function editTicket(
36
35
  title: ticket.title,
37
36
  labels: [...ticket.labels],
38
37
  blockedBy: [...(ticket.blockedBy ?? [])],
38
+ ...(ticket.issueLinks?.length ? { issueLinks: ticket.issueLinks } : {}),
39
+ ...(ticket.priority === 'urgent' ? { priority: ticket.priority } : {}),
39
40
  ...(ticket.creationKey !== undefined ? { idempotencyKey: ticket.creationKey } : {}),
40
41
  }
41
42
  // Reference comments remain part of the frontmatter, outside the editable keys.
@@ -67,16 +68,29 @@ export async function editTicket(
67
68
  parsed.front.target !== front.target ||
68
69
  parsed.front.id !== id ||
69
70
  parsed.front.idempotencyKey !== front.idempotencyKey ||
70
- JSON.stringify(parsed.front.blockedBy ?? []) !== JSON.stringify(front.blockedBy)
71
+ JSON.stringify(parsed.front.blockedBy ?? []) !== JSON.stringify(front.blockedBy) ||
72
+ JSON.stringify(parsed.front.issueLinks ?? []) !== JSON.stringify(front.issueLinks ?? []) ||
73
+ (parsed.front.priority === 'urgent') !== (front.priority === 'urgent')
71
74
  )
72
- throw new Error('kind, target, id, idempotencyKey and blockedBy are read-only')
75
+ throw new Error(
76
+ 'kind, target, id, idempotencyKey, blockedBy, issueLinks and priority are read-only',
77
+ )
73
78
  const patch: TicketUpdate = {}
74
79
  if (parsed.front.title !== ticket.title) patch.title = parsed.front.title
75
80
  if (parsed.body !== ticket.body) patch.body = parsed.body
76
81
  if (JSON.stringify(parsed.front.labels) !== JSON.stringify(ticket.labels))
77
82
  patch.labels = parsed.front.labels
78
- if (Object.keys(patch).length > 0)
79
- await updateTicket(source, id, patch, false, ticket.revision)
83
+ if (Object.keys(patch).length > 0) {
84
+ if (source.mutateIfRevision) await updateTicket(source, id, patch, false, ticket.revision)
85
+ else {
86
+ // Without guarded writes, re-read just before the unguarded write,
87
+ // with the same race window as file revision checks.
88
+ const current = await requireTicket(source, id)
89
+ if (current.revision !== ticket.revision)
90
+ throw new TicketRevisionConflict(id, ticket.revision, current.revision)
91
+ await updateTicket(source, id, patch, false)
92
+ }
93
+ }
80
94
  }
81
95
  await rm(directory, { recursive: true })
82
96
  stdout(`ticket edit complete: ${source.name}:${id}`)
@@ -3,7 +3,11 @@ import { readTicketTree } from '../operator/tickets'
3
3
  import { updateTicketTarget } from '../kernel/node-parent'
4
4
  import { createForge } from '../ports/forge/create'
5
5
  import { compatibleTicketSource, type TicketTreeEntry } from '../ports/tickets/tree'
6
- import { readBuildFacts } from '../store/reduced-reads'
6
+ import { formatIssueLinks, parseIssueLinkList } from '../ports/tickets/issue-links'
7
+ import { parsePriorityFlag, ticketPriority } from '../ports/tickets/priority'
8
+ import { parseIssueId, rejectedStateOf } from '../ports/tickets/github-issues'
9
+ import { readBuildDigests, readBuildFacts } from '../store/reduced-reads'
10
+ import type { TicketRef } from '../ontology'
7
11
  import { exportTickets, importTickets, directMigration } from '../ports/tickets/migration'
8
12
  import { composeTicketAssets } from '../store/ticket-assets'
9
13
  import { editTicket, type TicketEditorRunner } from './ticket-editor'
@@ -20,10 +24,19 @@ import type { Config, TicketsConfig } from '../config/schema'
20
24
  import { loadPlugins } from '../plugins/load'
21
25
  import type { PluginRegistry } from '../plugins/registry'
22
26
  import { createTicketSource } from '../ports/tickets/create'
27
+ import {
28
+ holdsState,
29
+ type LifecycleRole,
30
+ TICKET_MOVE_ROLES,
31
+ ticketLifecycle,
32
+ type TicketLifecycle,
33
+ type TicketMoveRole,
34
+ } from '../ports/tickets/lifecycle'
23
35
  import {
24
36
  changeBlockers,
25
37
  createTicket,
26
38
  moveTicket,
39
+ moveTicketToRole,
27
40
  requireTicket,
28
41
  ticketListCriteria,
29
42
  updateTicket,
@@ -89,6 +102,10 @@ export interface TicketCreateOpts extends TicketCommandOpts {
89
102
  /** Source-local ids of tickets that must complete before this one is
90
103
  * dispatched (§13). Validated against the configured source before create. */
91
104
  blockedBy?: string[]
105
+ /** Forge issues the ticket addresses; sources without support refuse. */
106
+ issueLinks?: import('../ports/types').IssueLink[]
107
+ /** Dispatch class; a source without priority support refuses `urgent`. */
108
+ priority?: import('../ports/types').TicketPriority
92
109
  }
93
110
 
94
111
  export interface TicketUpdateOpts extends TicketCommandOpts {
@@ -101,6 +118,10 @@ export interface TicketUpdateOpts extends TicketCommandOpts {
101
118
  bodyFile?: string
102
119
  /** Complete label replacement. An explicit [] clears labels. */
103
120
  labels?: string[]
121
+ /** Complete issue-link replacement. An explicit [] clears links. */
122
+ issueLinks?: import('../ports/types').IssueLink[]
123
+ /** `normal` removes urgency; a source without priority support refuses `urgent`. */
124
+ priority?: import('../ports/types').TicketPriority
104
125
  }
105
126
 
106
127
  export interface TicketBlockerOpts extends TicketCommandOpts {
@@ -153,12 +174,21 @@ export interface TicketAssetRmOpts extends TicketCommandOpts {
153
174
  stderr?: (line: string) => void
154
175
  }
155
176
 
156
- export interface TicketMoveOpts extends TicketCommandOpts {
177
+ export type TicketMoveOpts = TicketCommandOpts & {
157
178
  id: string
158
- /** Source-local workflow state; validation belongs to the adapter. */
159
- state: string
160
179
  json?: boolean
161
- }
180
+ } & (
181
+ | {
182
+ /** Source-local workflow state; validation belongs to the adapter. */
183
+ state: string
184
+ role?: undefined
185
+ }
186
+ | {
187
+ /** Lifecycle role, resolved through the configured [tickets] names. */
188
+ role: TicketMoveRole
189
+ state?: undefined
190
+ }
191
+ )
162
192
 
163
193
  export interface TicketStatesOpts extends TicketCommandOpts {
164
194
  json?: boolean
@@ -229,6 +259,28 @@ export async function openTicketSource(
229
259
  return createTicketCommandSource(opts, await resolveTicketConfig(opts, label))
230
260
  }
231
261
 
262
+ /** The ticket source and configured rejected role one build control reads
263
+ * for node completeness. */
264
+ export interface ControlTickets {
265
+ ticketSource: () => Promise<TicketSource>
266
+ rejectedState?: () => Promise<string | undefined>
267
+ }
268
+
269
+ /** One lazily opened ticket command shared by a single control's source and
270
+ * the configured rejected role it reads for node completeness. Create one per
271
+ * control request so a hot-reloaded role is never served from an older one. */
272
+ export function lazyTicketSource(open: () => Promise<ResolvedTicketCommand>): {
273
+ ticketSource: () => Promise<TicketSource>
274
+ rejectedState: () => Promise<string | undefined>
275
+ } {
276
+ let opened: Promise<ResolvedTicketCommand> | undefined
277
+ const tickets = () => (opened ??= open())
278
+ return {
279
+ ticketSource: async () => (await tickets()).source,
280
+ rejectedState: async () => ticketLifecycle((await tickets()).config.tickets).rejected,
281
+ }
282
+ }
283
+
232
284
  async function createTicketCommandSource(
233
285
  opts: TicketCommandOpts,
234
286
  { targetRepo, config }: { targetRepo: string; config: Config },
@@ -281,12 +333,14 @@ function ticketSummary(ticket: Ticket): string {
281
333
  const fields = [
282
334
  `${ticket.ref.source}:${ticket.ref.id}`,
283
335
  `(${ticket.state ?? 'state unknown'})`,
336
+ ...(ticket.priority === 'urgent' ? ['— urgent'] : []),
284
337
  `— ${ticket.title}`,
285
338
  ]
286
339
  if (ticket.labels.length > 0) fields.push(`— labels: ${ticket.labels.join(', ')}`)
287
340
  if (ticket.blockedBy !== undefined && ticket.blockedBy.length > 0) {
288
341
  fields.push(`— blocked by: ${ticket.blockedBy.join(', ')}`)
289
342
  }
343
+ if (ticket.issueLinks?.length) fields.push(`— issues: ${formatIssueLinks(ticket.issueLinks)}`)
290
344
  if (ticket.ref.url !== undefined) fields.push(`— ${ticket.ref.url}`)
291
345
  return fields.join(' ')
292
346
  }
@@ -295,26 +349,38 @@ function assetLine(asset: TicketAssetSummary): string {
295
349
  return ` ${asset.kind}/${asset.name} rev ${asset.revision} ${formatAssetSize(asset.size)}`
296
350
  }
297
351
 
298
- function ticketDetail(ticket: Ticket, assets: TicketAssetSummary[] = []): string[] {
352
+ function ticketDetail(
353
+ ticket: Ticket,
354
+ assets: TicketAssetSummary[] = [],
355
+ rejected: ReadonlySet<string> = new Set(),
356
+ ): string[] {
299
357
  const lines = [
300
358
  `ticket ${ticket.ref.source}:${ticket.ref.id}`,
301
359
  ` title: ${ticket.title}`,
302
360
  ` kind: ${ticket.kind ?? 'work'}`,
303
361
  ` target: ${ticket.target ?? '(root)'}`,
304
362
  ` state: ${ticket.state ?? '(unknown)'}`,
363
+ ` priority: ${ticketPriority(ticket)}`,
305
364
  ` labels: ${ticket.labels.join(', ') || '(none)'}`,
306
365
  ]
307
366
  if (ticket.blockedBy !== undefined && ticket.blockedBy.length > 0) {
308
- lines.push(` blocked by: ${ticket.blockedBy.join(', ')}`)
367
+ const blockers = ticket.blockedBy.map((id) => (rejected.has(id) ? `${id} (rejected)` : id))
368
+ lines.push(` blocked by: ${blockers.join(', ')}`)
309
369
  }
370
+ if (ticket.issueLinks?.length) lines.push(` issues: ${formatIssueLinks(ticket.issueLinks)}`)
310
371
  if (ticket.ref.url !== undefined) lines.push(` url: ${ticket.ref.url}`)
311
372
  if (assets.length > 0) lines.push(' assets:', ...assets.map(assetLine))
312
373
  lines.push(' body:')
313
374
  return lines
314
375
  }
315
376
 
377
+ /** CLI JSON always names priority; normalized tickets omit the normal default. */
378
+ function ticketJson(ticket: Ticket): Ticket & { priority: 'urgent' | 'normal' } {
379
+ return { ...ticket, priority: ticketPriority(ticket) }
380
+ }
381
+
316
382
  function emitTicketJson(opts: TicketCommandOpts, ticket: Ticket): void {
317
- opts.stdout(JSON.stringify(ticket, null, 2))
383
+ opts.stdout(JSON.stringify(ticketJson(ticket), null, 2))
318
384
  }
319
385
 
320
386
  export async function abTicketCreate(opts: TicketCreateOpts): Promise<void> {
@@ -331,6 +397,8 @@ export async function abTicketCreate(opts: TicketCreateOpts): Promise<void> {
331
397
  body,
332
398
  ...(opts.labels !== undefined ? { labels: opts.labels } : {}),
333
399
  ...(opts.blockedBy !== undefined ? { blockedBy: opts.blockedBy } : {}),
400
+ ...(opts.issueLinks !== undefined ? { issueLinks: opts.issueLinks } : {}),
401
+ ...(opts.priority !== undefined ? { priority: opts.priority } : {}),
334
402
  ...(opts.state !== undefined ? { state: opts.state } : {}),
335
403
  },
336
404
  {
@@ -348,7 +416,11 @@ export async function abTicketCreate(opts: TicketCreateOpts): Promise<void> {
348
416
  ticket.blockedBy !== undefined && ticket.blockedBy.length > 0
349
417
  ? ` — blocked by ${ticket.blockedBy.join(', ')}`
350
418
  : ''
351
- opts.stdout(`ticket created: ${ticket.ref.source}:${ticket.ref.id} (${state})${blockers}${url}`)
419
+ const issues = ticket.issueLinks?.length ? ` — ${formatIssueLinks(ticket.issueLinks)}` : ''
420
+ const urgent = ticket.priority === 'urgent' ? ' — urgent' : ''
421
+ opts.stdout(
422
+ `ticket created: ${ticket.ref.source}:${ticket.ref.id} (${state})${urgent}${blockers}${issues}${url}`,
423
+ )
352
424
  }
353
425
 
354
426
  export async function abTicketUpdate(opts: TicketUpdateOpts): Promise<void> {
@@ -360,6 +432,8 @@ export async function abTicketUpdate(opts: TicketUpdateOpts): Promise<void> {
360
432
  ...(opts.title !== undefined ? { title: opts.title } : {}),
361
433
  ...(body !== undefined ? { body } : {}),
362
434
  ...(opts.labels !== undefined ? { labels: [...opts.labels] } : {}),
435
+ ...(opts.issueLinks !== undefined ? { issueLinks: [...opts.issueLinks] } : {}),
436
+ ...(opts.priority !== undefined ? { priority: opts.priority } : {}),
363
437
  }
364
438
  const updated =
365
439
  patch.target === undefined
@@ -434,7 +508,7 @@ export async function abTicketList(opts: TicketListOpts): Promise<void> {
434
508
  const listing = await source.listReady(criteria)
435
509
  for (const diagnostic of listing.diagnostics) opts.stderr(diagnostic)
436
510
  if (opts.json === true) {
437
- opts.stdout(JSON.stringify(listing.tickets, null, 2))
511
+ opts.stdout(JSON.stringify(listing.tickets.map(ticketJson), null, 2))
438
512
  return
439
513
  }
440
514
  if (listing.tickets.length === 0) {
@@ -446,17 +520,29 @@ export async function abTicketList(opts: TicketListOpts): Promise<void> {
446
520
 
447
521
  /** `ab ticket show <id>` — complete metadata plus the body/spec. */
448
522
  export async function abTicketShow(opts: TicketShowOpts): Promise<void> {
449
- const { source } = await resolveTicketCommand(opts, 'show')
523
+ const { config, source } = await resolveTicketCommand(opts, 'show')
450
524
  const ticket = await requireTicket(source, opts.id)
451
525
  // An asset-listing failure fails the command rather than hiding the assets.
452
526
  const assets = await withTicketAssets(opts, source, ({ store, repo }) =>
453
- store.listTicketAssets(repo, opts.id),
527
+ store.listTicketAssets(repo, assetTicketId(source.name, opts.id)),
454
528
  )
529
+ // One batched read, only when the ticket declares blockers.
530
+ const rejectedName = ticketLifecycle(config.tickets).rejected
531
+ const blockers = ticket.blockedBy?.length
532
+ ? (await source.dependencyStates(ticket.blockedBy)).map(({ id, exists, resolved, state }) => ({
533
+ id,
534
+ exists,
535
+ resolved,
536
+ ...(state !== undefined ? { state } : {}),
537
+ rejected: holdsState(state, rejectedName),
538
+ }))
539
+ : []
455
540
  if (opts.json === true) {
456
541
  opts.stdout(
457
542
  JSON.stringify(
458
543
  {
459
- ...ticket,
544
+ ...ticketJson(ticket),
545
+ ...(blockers.length > 0 ? { blockers } : {}),
460
546
  assets: assets.map(({ kind, name, revision, size, layout, fileCount }) => ({
461
547
  kind,
462
548
  name,
@@ -472,7 +558,8 @@ export async function abTicketShow(opts: TicketShowOpts): Promise<void> {
472
558
  )
473
559
  return
474
560
  }
475
- for (const line of ticketDetail(ticket, assets)) opts.stdout(line)
561
+ const rejected = new Set(blockers.filter((blocker) => blocker.rejected).map(({ id }) => id))
562
+ for (const line of ticketDetail(ticket, assets, rejected)) opts.stdout(line)
476
563
  // Keep the adapter-provided body untouched. It may itself be multiline and
477
564
  // may intentionally end (or not end) with a newline.
478
565
  opts.stdout(ticket.body)
@@ -500,6 +587,15 @@ function withTicketStore<T>(
500
587
  )
501
588
  }
502
589
 
590
+ /** The id ticket assets are keyed by. GitHub accepts `123` and `#123` for one
591
+ * issue, and the dispatcher reads assets by `ref.id`, so both spellings key by
592
+ * the issue number. Other sources key by the id as given. */
593
+ export function assetTicketId(source: string, id: string): string {
594
+ if (source !== 'github') return id
595
+ const number = parseIssueId(id)
596
+ return number === null ? id : String(number)
597
+ }
598
+
503
599
  function withTicketAssets<T>(
504
600
  opts: TicketCommandOpts,
505
601
  source: TicketSource,
@@ -513,6 +609,38 @@ function withTicketAssets<T>(
513
609
  )
514
610
  }
515
611
 
612
+ /** The lifecycle export records as roles and import lands them in. The file
613
+ * adapter always claims into `doing/` (see `stateRoles`). GitHub issues closed
614
+ * as not planned are rejected work even without a configured rejected state;
615
+ * the github source itself refuses to import into that unmovable state. */
616
+ export function migrationLifecycle(tickets: TicketsConfig): TicketLifecycle {
617
+ const lifecycle = ticketLifecycle(tickets)
618
+ if (tickets.source === 'file') return { ...lifecycle, doing: 'doing' }
619
+ if (tickets.source === 'github') return { ...lifecycle, rejected: rejectedStateOf(lifecycle) }
620
+ return lifecycle
621
+ }
622
+
623
+ /**
624
+ * The ticket and target refs of this repo's unfinished builds, so an import
625
+ * selection cannot leave in-flight work behind. Runs once per explicit
626
+ * `ab ticket import --states`: one build listing, one digest batch and one
627
+ * saved reduced read per unfinished build; never a log read.
628
+ */
629
+ export async function unfinishedBuildTickets(
630
+ store: BuildStore,
631
+ repo: string,
632
+ ): Promise<{ build: string; ticket: TicketRef }[]> {
633
+ const digests = await readBuildDigests(store, repo)
634
+ const refs: { build: string; ticket: TicketRef }[] = []
635
+ for (const record of await store.listBuildsForRepo(repo)) {
636
+ if (digests.get(record.slug)?.terminal !== undefined) continue
637
+ if (record.ticket) refs.push({ build: record.slug, ticket: record.ticket })
638
+ const target = (await readBuildFacts(store, record.slug)).value.state.target?.ticket
639
+ if (target) refs.push({ build: record.slug, ticket: target })
640
+ }
641
+ return refs
642
+ }
643
+
516
644
  /** Slugs of this repo's non-terminal builds for the ticket. A build freezes its
517
645
  * ticket assets at the claim (SPEC §6.3), so a change to them does not reach
518
646
  * it. The notice is advisory: a failed lookup yields none and never blocks. */
@@ -546,8 +674,9 @@ function warnActiveBuilds(
546
674
  * asset, then leave a note on the ticket in its source. Order matters: the
547
675
  * source is asked first, so an unknown id stores nothing; the note follows the
548
676
  * store write, so it never points at nothing. */
549
- export async function abTicketAttach(opts: TicketAttachOpts): Promise<void> {
550
- const { source } = await resolveTicketCommand(opts, 'attach')
677
+ export async function abTicketAttach(given: TicketAttachOpts): Promise<void> {
678
+ const { source } = await resolveTicketCommand(given, 'attach')
679
+ const opts = { ...given, id: assetTicketId(source.name, given.id) }
551
680
  await requireTicket(source, opts.id)
552
681
  const walk = await walkAssetPath(opts.path)
553
682
  const name = opts.name ?? walk.basename
@@ -590,8 +719,9 @@ export async function abTicketAttach(opts: TicketAttachOpts): Promise<void> {
590
719
 
591
720
  /** `ab ticket asset get <id> <kind> <name> <dest>` — exact bytes at the
592
721
  * latest or a named revision. */
593
- export async function abTicketAssetGet(opts: TicketAssetGetOpts): Promise<void> {
594
- const resolved = await resolveTicketConfig(opts, 'ab ticket asset get')
722
+ export async function abTicketAssetGet(given: TicketAssetGetOpts): Promise<void> {
723
+ const resolved = await resolveTicketConfig(given, 'ab ticket asset get')
724
+ const opts = { ...given, id: assetTicketId(resolved.config.tickets.source, given.id) }
595
725
  const readAsset = ({ store, repo }: { store: TicketAssetStore; repo: string }) =>
596
726
  store.getTicketAsset(repo, opts.id, opts.kind, opts.name, opts.rev)
597
727
  const asset =
@@ -621,8 +751,9 @@ export async function abTicketAssetGet(opts: TicketAssetGetOpts): Promise<void>
621
751
 
622
752
  /** `ab ticket asset rm <id> <kind> <name>` — remove from the current assets
623
753
  * (earlier revisions stay retrievable) and note the removal on the ticket. */
624
- export async function abTicketAssetRm(opts: TicketAssetRmOpts): Promise<void> {
625
- const { source } = await resolveTicketCommand(opts, 'asset rm')
754
+ export async function abTicketAssetRm(given: TicketAssetRmOpts): Promise<void> {
755
+ const { source } = await resolveTicketCommand(given, 'asset rm')
756
+ const opts = { ...given, id: assetTicketId(source.name, given.id) }
626
757
  const { removed, active } = await withTicketAssets(
627
758
  opts,
628
759
  source,
@@ -653,18 +784,34 @@ export async function abTicketAssetRm(opts: TicketAssetRmOpts): Promise<void> {
653
784
  opts.stdout(`ticket asset removed: ${source.name}:${opts.id} ${opts.kind}/${opts.name}`)
654
785
  }
655
786
 
656
- /** `ab ticket move <id> <state>` — adapter-owned state validation and move. */
787
+ /** `ab ticket move <id> (<state> | --role <role>)` — adapter-owned state
788
+ * validation; a role resolves through the configured [tickets] names. */
657
789
  export async function abTicketMove(opts: TicketMoveOpts): Promise<void> {
658
- const { source } = await resolveTicketCommand(opts, 'move')
659
- const moved = await moveTicket(source, opts.id, opts.state, opts.expectedRevision)
790
+ const { config, source } = await resolveTicketCommand(opts, 'move')
791
+ const moved =
792
+ opts.role !== undefined
793
+ ? await moveTicketToRole(source, config.tickets, opts.id, opts.role, opts.expectedRevision)
794
+ : await moveTicket(source, opts.id, opts.state, opts.expectedRevision)
660
795
  if (opts.json === true) {
661
- opts.stdout(JSON.stringify(moved, null, 2))
796
+ opts.stdout(JSON.stringify(ticketJson(moved), null, 2))
662
797
  return
663
798
  }
664
799
  opts.stdout(`ticket moved: ${ticketSummary(moved)}`)
665
800
  }
666
801
 
667
- export type TicketStateRole = 'create' | 'ready' | 'claimed' | 'triage' | 'proposal' | 'done'
802
+ export type TicketStateRole = LifecycleRole
803
+
804
+ /** Workflow order: placements sit beside triage, the role they default to. */
805
+ const STATE_ROLE_ORDER: readonly TicketStateRole[] = [
806
+ 'triage',
807
+ 'create',
808
+ 'proposal',
809
+ 'backlog',
810
+ 'ready',
811
+ 'claimed',
812
+ 'done',
813
+ 'rejected',
814
+ ]
668
815
 
669
816
  export interface TicketStateRow extends TicketStateInfo {
670
817
  roles: TicketStateRole[]
@@ -685,11 +832,24 @@ export function stateRoles(
685
832
  const named: Array<[TicketStateRole, string]> = [
686
833
  ['create', tickets.createState ?? 'triage'],
687
834
  ['ready', tickets.readyState],
688
- ['claimed', tickets.source === 'hosted' ? (tickets.claimedState ?? 'doing') : 'doing'],
835
+ [
836
+ 'claimed',
837
+ tickets.source === 'hosted' || tickets.source === 'github'
838
+ ? (tickets.claimedState ?? 'doing')
839
+ : 'doing',
840
+ ],
689
841
  ['triage', triage],
690
842
  ['proposal', tickets.proposalState ?? triage],
691
- ['done', tickets.source === 'hosted' ? (tickets.doneState ?? 'done') : 'done'],
843
+ [
844
+ 'done',
845
+ tickets.source === 'hosted' || tickets.source === 'github'
846
+ ? (tickets.doneState ?? 'done')
847
+ : 'done',
848
+ ],
692
849
  ]
850
+ if (tickets.backlogState !== undefined) named.push(['backlog', tickets.backlogState])
851
+ if (tickets.rejectedState !== undefined) named.push(['rejected', tickets.rejectedState])
852
+ named.sort(([a], [b]) => STATE_ROLE_ORDER.indexOf(a) - STATE_ROLE_ORDER.indexOf(b))
693
853
  const roles = new Map<string, TicketStateRole[]>(names.map((name) => [name, []]))
694
854
  for (const [role, target] of named) {
695
855
  const match =
@@ -724,7 +884,11 @@ export async function abTicketStates(opts: TicketStatesOpts): Promise<void> {
724
884
  config.tickets,
725
885
  infos.map((info) => info.name),
726
886
  )
727
- const rows = infos.map((info) => stateRow(info, roles))
887
+ // Role-holding states in workflow order by their first role; the rest after
888
+ // them in source order. The sort is stable.
889
+ const rank = (row: TicketStateRow) =>
890
+ row.roles.length > 0 ? STATE_ROLE_ORDER.indexOf(row.roles[0]!) : STATE_ROLE_ORDER.length
891
+ const rows = infos.map((info) => stateRow(info, roles)).sort((a, b) => rank(a) - rank(b))
728
892
  if (opts.json === true) {
729
893
  opts.stdout(JSON.stringify(rows, null, 2))
730
894
  return
@@ -767,9 +931,9 @@ export async function abTicketStateCreate(opts: TicketStateCreateOpts): Promise<
767
931
  }
768
932
 
769
933
  const CREATE_USAGE =
770
- 'usage: ab ticket create <title> --body <file> [--state <state>] [--labels a,b] [--blocked-by id,id] [--kind work|node] [--target <id> | --no-target] [--json] (§8.8)'
934
+ 'usage: ab ticket create <title> --body <file> [--state <state>] [--labels a,b] [--blocked-by id,id] [--issues N[:refs],...] [--priority urgent|normal] [--kind work|node] [--target <id> | --no-target] [--json] (§8.8)'
771
935
  const UPDATE_USAGE =
772
- 'usage: ab ticket update <id> [--kind work|node] [--target <id> | --no-target] [--title <title>] [--body <file>] [--labels a,b] [--expected-revision <opaque>] [--json] (§8.8)'
936
+ 'usage: ab ticket update <id> [--kind work|node] [--target <id> | --no-target] [--title <title>] [--body <file>] [--labels a,b] [--issues N[:refs],...] [--priority urgent|normal] [--expected-revision <opaque>] [--json] (§8.8)'
773
937
  const BLOCK_USAGE =
774
938
  'usage: ab ticket block <id> <blocker-id[,blocker-id...]> [--expected-revision <opaque>] [--json] (§8.8)'
775
939
  const UNBLOCK_USAGE =
@@ -783,12 +947,12 @@ const ASSET_GET_USAGE =
783
947
  const ASSET_RM_USAGE =
784
948
  'usage: ab ticket asset rm <id> <kind> <name> [--store <ref>] [--json] (§8.8)'
785
949
  const MOVE_USAGE =
786
- 'usage: ab ticket move <id> <state> [--expected-revision <opaque>] [--json] (§8.8)'
950
+ 'usage: ab ticket move <id> (<state> | --role triage|ready|backlog|rejected) [--expected-revision <opaque>] [--json] (§8.8)'
787
951
  const STATES_USAGE = 'usage: ab ticket states [--json] (§8.8)'
788
952
  const STATE_CREATE_USAGE = 'usage: ab ticket state create <name> [--about <text>] [--json] (§8.8)'
789
953
  export const TICKET_USAGE = [
790
954
  'usage: ab ticket export <dir> [--store <ref>]',
791
- 'usage: ab ticket import <dir> [--store <ref>]',
955
+ 'usage: ab ticket import <dir> [--states <state,...>] [--store <ref>]',
792
956
  'usage: ab ticket migration record <dir> [--store <ref>]',
793
957
  'usage: ab ticket tree [--json]',
794
958
  CREATE_USAGE,
@@ -829,18 +993,43 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
829
993
  case 'import': {
830
994
  const tail = command === 'migration' ? args.slice(1) : args
831
995
  if (command === 'migration' && args[0] !== 'record') throw new Error(TICKET_USAGE)
832
- const parsed = parseArgs(tail, { store: 'value' }, TICKET_USAGE)
996
+ const parsed = parseArgs(tail, { store: 'value', states: 'value' }, TICKET_USAGE)
833
997
  const [dir, ...extra] = parsed.positionals
834
998
  if (!dir?.trim() || extra.length) throw new Error(TICKET_USAGE)
999
+ const selected = stringFlag(parsed, 'states')
1000
+ if (selected !== undefined && command !== 'import')
1001
+ throw new Error(`--states selects what to import; ${TICKET_USAGE}`)
1002
+ const states = selected === undefined ? undefined : commaList(selected)
1003
+ if (states?.length === 0)
1004
+ throw new Error(`--states needs at least one state; ${TICKET_USAGE}`)
835
1005
  const migrationOpts = { ...opts, storeRef: stringFlag(parsed, 'store') ?? opts.storeRef }
836
- const { source } = await resolveTicketCommand(migrationOpts, command)
1006
+ const { config, source } = await resolveTicketCommand(migrationOpts, command)
837
1007
  await withTicketAssets(migrationOpts, source, async ({ store, buildStore, repo }) => {
838
- const input = { source, assets: store, repo, dir, print: opts.stdout, signal: opts.signal }
1008
+ const input = {
1009
+ source,
1010
+ assets: store,
1011
+ repo,
1012
+ dir,
1013
+ print: opts.stdout,
1014
+ signal: opts.signal,
1015
+ lifecycle: migrationLifecycle(config.tickets),
1016
+ }
839
1017
  if (command === 'export') return exportTickets(input)
840
1018
  await buildStore.ensureRepo(repo)
841
- await readTicketMigrations(buildStore, repo)
1019
+ const migrations = await readTicketMigrations(buildStore, repo)
842
1020
  const result =
843
- command === 'import' ? await importTickets(input) : await directMigration(input)
1021
+ command === 'import'
1022
+ ? await importTickets({
1023
+ ...input,
1024
+ ...(states === undefined
1025
+ ? {}
1026
+ : {
1027
+ states,
1028
+ inFlight: await unfinishedBuildTickets(buildStore, repo),
1029
+ migrations,
1030
+ }),
1031
+ })
1032
+ : await directMigration(input)
844
1033
  try {
845
1034
  await recordTicketMigration(
846
1035
  buildStore,
@@ -874,6 +1063,8 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
874
1063
  state: 'value',
875
1064
  labels: 'value',
876
1065
  'blocked-by': 'value',
1066
+ issues: 'value',
1067
+ priority: 'value',
877
1068
  json: 'boolean',
878
1069
  },
879
1070
  TICKET_USAGE,
@@ -887,6 +1078,8 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
887
1078
  if (state !== undefined && state.trim() === '') throw new Error(TICKET_USAGE)
888
1079
  const labels = stringFlag(parsed, 'labels')
889
1080
  const blockedBy = stringFlag(parsed, 'blocked-by')
1081
+ const issues = stringFlag(parsed, 'issues')
1082
+ const priority = stringFlag(parsed, 'priority')
890
1083
  await abTicketCreate({
891
1084
  ...opts,
892
1085
  ...metadataFlags(parsed),
@@ -895,6 +1088,8 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
895
1088
  ...(state !== undefined ? { state } : {}),
896
1089
  ...(labels !== undefined ? { labels: commaList(labels) } : {}),
897
1090
  ...(blockedBy !== undefined ? { blockedBy: commaList(blockedBy) } : {}),
1091
+ ...(issues !== undefined ? { issueLinks: parseIssueLinkList(issues) } : {}),
1092
+ ...(priority !== undefined ? { priority: parsePriorityFlag(priority) } : {}),
898
1093
  json: parsed.flags.has('json'),
899
1094
  })
900
1095
  return
@@ -917,21 +1112,32 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
917
1112
  title: 'value',
918
1113
  body: 'value',
919
1114
  labels: 'value',
1115
+ issues: 'value',
1116
+ priority: 'value',
920
1117
  'expected-revision': 'value',
921
1118
  json: 'boolean',
922
1119
  },
923
1120
  TICKET_USAGE,
924
1121
  )
925
1122
  const [id, ...extra] = parsed.positionals
926
- const hasUpdate = ['title', 'body', 'labels', 'kind', 'target', 'no-target'].some((flag) =>
927
- parsed.flags.has(flag),
928
- )
1123
+ const hasUpdate = [
1124
+ 'title',
1125
+ 'body',
1126
+ 'labels',
1127
+ 'issues',
1128
+ 'priority',
1129
+ 'kind',
1130
+ 'target',
1131
+ 'no-target',
1132
+ ].some((flag) => parsed.flags.has(flag))
929
1133
  if (id === undefined || id.trim() === '' || extra.length > 0 || !hasUpdate) {
930
1134
  throw new Error(TICKET_USAGE)
931
1135
  }
932
1136
  const title = stringFlag(parsed, 'title')
933
1137
  const bodyFile = stringFlag(parsed, 'body')
934
1138
  const labels = stringFlag(parsed, 'labels')
1139
+ const issues = stringFlag(parsed, 'issues')
1140
+ const priority = stringFlag(parsed, 'priority')
935
1141
  if (bodyFile !== undefined && bodyFile.trim() === '') {
936
1142
  throw new Error(TICKET_USAGE)
937
1143
  }
@@ -943,6 +1149,8 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
943
1149
  ...(title !== undefined ? { title } : {}),
944
1150
  ...(bodyFile !== undefined ? { bodyFile } : {}),
945
1151
  ...(labels !== undefined ? { labels: commaList(labels) } : {}),
1152
+ ...(issues !== undefined ? { issueLinks: parseIssueLinkList(issues) } : {}),
1153
+ ...(priority !== undefined ? { priority: parsePriorityFlag(priority) } : {}),
946
1154
  json: parsed.flags.has('json'),
947
1155
  })
948
1156
  return
@@ -1141,26 +1349,36 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
1141
1349
  case 'move': {
1142
1350
  const parsed = parseArgs(
1143
1351
  args,
1144
- { json: 'boolean', 'expected-revision': 'value' },
1352
+ { json: 'boolean', 'expected-revision': 'value', role: 'value' },
1145
1353
  TICKET_USAGE,
1146
1354
  )
1147
1355
  const [id, state, ...extra] = parsed.positionals
1356
+ const role = stringFlag(parsed, 'role')
1148
1357
  if (
1149
1358
  id === undefined ||
1150
1359
  id.trim() === '' ||
1151
- state === undefined ||
1152
- state.trim() === '' ||
1360
+ (state === undefined) === (role === undefined) ||
1361
+ state?.trim() === '' ||
1153
1362
  extra.length > 0
1154
1363
  ) {
1155
1364
  throw new Error(TICKET_USAGE)
1156
1365
  }
1157
- await abTicketMove({
1366
+ if (role !== undefined && !(TICKET_MOVE_ROLES as readonly string[]).includes(role)) {
1367
+ throw new Error(
1368
+ `ab ticket move: unknown --role "${role}"; expected one of ${TICKET_MOVE_ROLES.join(', ')}\n${MOVE_USAGE}`,
1369
+ )
1370
+ }
1371
+ const common = {
1158
1372
  ...opts,
1159
1373
  id,
1160
- state,
1161
1374
  expectedRevision: stringFlag(parsed, 'expected-revision'),
1162
1375
  json: parsed.flags.has('json'),
1163
- })
1376
+ }
1377
+ await abTicketMove(
1378
+ role !== undefined
1379
+ ? { ...common, role: role as TicketMoveRole }
1380
+ : { ...common, state: state! },
1381
+ )
1164
1382
  return
1165
1383
  }
1166
1384