@defrex/autobuild 1.6.0 → 1.8.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 (165) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +423 -57
  3. package/docs/agent-runtimes.md +1 -1
  4. package/docs/answering-blocked-builds.md +44 -3
  5. package/docs/architecture.md +124 -29
  6. package/docs/cli.md +1 -0
  7. package/docs/configuration-overview.md +11 -1
  8. package/docs/configuration.md +334 -14
  9. package/docs/dispatcher.md +1 -1
  10. package/docs/forges.md +1 -0
  11. package/docs/integration-overview.md +2 -2
  12. package/docs/integration-tree.md +7 -4
  13. package/docs/merge-policy.md +78 -6
  14. package/docs/migration-1.0.md +4 -2
  15. package/docs/operating.md +3 -2
  16. package/docs/operator-api.md +45 -13
  17. package/docs/operator-surfaces.md +16 -3
  18. package/docs/plugin-authoring.md +45 -7
  19. package/docs/remote-store-protocol.md +28 -7
  20. package/docs/restacking.md +35 -11
  21. package/docs/ticket-dependencies.md +9 -4
  22. package/docs/ticket-sources.md +34 -6
  23. package/docs/tickets.md +7 -1
  24. package/docs/troubleshooting.md +1 -1
  25. package/docs/workspaces.md +1 -1
  26. package/package.json +3 -3
  27. package/packages/core/src/cli/attention.ts +2 -0
  28. package/packages/core/src/cli/binary-direct.ts +1 -0
  29. package/packages/core/src/cli/build-control.ts +65 -7
  30. package/packages/core/src/cli/context.ts +55 -14
  31. package/packages/core/src/cli/dashboard/actions.ts +13 -4
  32. package/packages/core/src/cli/dashboard/landing-display.ts +32 -8
  33. package/packages/core/src/cli/dashboard/model.ts +61 -8
  34. package/packages/core/src/cli/dashboard/render.ts +28 -3
  35. package/packages/core/src/cli/dashboard/tree.ts +9 -1
  36. package/packages/core/src/cli/dispatch-frontend.ts +10 -14
  37. package/packages/core/src/cli/dispatch-preflight.ts +1 -0
  38. package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
  39. package/packages/core/src/cli/dispatch.ts +9 -3
  40. package/packages/core/src/cli/help.ts +80 -11
  41. package/packages/core/src/cli/init-validation.ts +14 -1
  42. package/packages/core/src/cli/landings.ts +1 -1
  43. package/packages/core/src/cli/main.ts +60 -9
  44. package/packages/core/src/cli/publication-settlement.ts +10 -0
  45. package/packages/core/src/cli/repository-status.ts +37 -2
  46. package/packages/core/src/cli/status.ts +186 -12
  47. package/packages/core/src/cli/terminals.ts +197 -4
  48. package/packages/core/src/cli/ticket.ts +22 -4
  49. package/packages/core/src/cli/wait.ts +1 -0
  50. package/packages/core/src/cli/watch.ts +73 -0
  51. package/packages/core/src/config/landing.ts +12 -0
  52. package/packages/core/src/config/live.ts +4 -0
  53. package/packages/core/src/config/path-selectors.ts +68 -0
  54. package/packages/core/src/config/profiles.ts +96 -0
  55. package/packages/core/src/config/ready-assignee.ts +43 -11
  56. package/packages/core/src/config/roles.ts +33 -10
  57. package/packages/core/src/config/schema.ts +205 -81
  58. package/packages/core/src/events/catalog.ts +17 -3
  59. package/packages/core/src/events/compatibility.ts +4 -1
  60. package/packages/core/src/events/forge-degradation-policy.ts +16 -2
  61. package/packages/core/src/events/head-paths-limits.ts +25 -0
  62. package/packages/core/src/events/payloads.ts +323 -20
  63. package/packages/core/src/events/policy.ts +22 -0
  64. package/packages/core/src/events/repository.ts +47 -1
  65. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +320 -130
  66. package/packages/core/src/kernel/build-creation.ts +29 -0
  67. package/packages/core/src/kernel/consent-revocation.ts +72 -0
  68. package/packages/core/src/kernel/dispatch-capacity.ts +19 -8
  69. package/packages/core/src/kernel/engine.ts +48 -8
  70. package/packages/core/src/kernel/forge-health.ts +47 -0
  71. package/packages/core/src/kernel/guarded-forge.ts +76 -18
  72. package/packages/core/src/kernel/head-paths-state.ts +63 -0
  73. package/packages/core/src/kernel/head-paths.ts +401 -0
  74. package/packages/core/src/kernel/landing-policy-identity.ts +20 -0
  75. package/packages/core/src/kernel/landing-policy.ts +55 -2
  76. package/packages/core/src/kernel/landing-readiness.ts +104 -9
  77. package/packages/core/src/kernel/landing-state.ts +44 -4
  78. package/packages/core/src/kernel/leaf-restack-state.ts +50 -2
  79. package/packages/core/src/kernel/log-index.ts +27 -1
  80. package/packages/core/src/kernel/node-parent.ts +2 -0
  81. package/packages/core/src/kernel/node-polling.ts +13 -3
  82. package/packages/core/src/kernel/node-restack-state.ts +8 -1
  83. package/packages/core/src/kernel/node-restack-transaction.ts +45 -0
  84. package/packages/core/src/kernel/read-deferrals.ts +3 -1
  85. package/packages/core/src/kernel/read-facts.ts +37 -2
  86. package/packages/core/src/kernel/reducer-registry.ts +22 -1
  87. package/packages/core/src/kernel/reducer.ts +332 -16
  88. package/packages/core/src/kernel/target-observation.ts +2 -5
  89. package/packages/core/src/kernel/terminal-guard.ts +52 -3
  90. package/packages/core/src/kernel/ticket-handbacks.ts +40 -0
  91. package/packages/core/src/kernel/ticket-preparation.ts +15 -1
  92. package/packages/core/src/kernel/ticket-wait.ts +345 -0
  93. package/packages/core/src/kernel/verify-applicability.ts +9 -19
  94. package/packages/core/src/ontology.ts +1 -0
  95. package/packages/core/src/operator/annotations.ts +6 -0
  96. package/packages/core/src/operator/index.ts +3 -0
  97. package/packages/core/src/operator/protocol.ts +25 -2
  98. package/packages/core/src/operator/query.ts +1 -1
  99. package/packages/core/src/operator/registry.ts +122 -10
  100. package/packages/core/src/operator/repository-events.ts +67 -0
  101. package/packages/core/src/operator/sandbox-host.ts +3 -0
  102. package/packages/core/src/operator/tickets.ts +15 -3
  103. package/packages/core/src/plugin-sdk/index.ts +4 -0
  104. package/packages/core/src/ports/forge/create.ts +6 -0
  105. package/packages/core/src/ports/forge/github-transport.ts +40 -3
  106. package/packages/core/src/ports/forge/github.ts +12 -1
  107. package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
  108. package/packages/core/src/ports/forge-failure.ts +31 -2
  109. package/packages/core/src/ports/runner/routing.ts +66 -5
  110. package/packages/core/src/ports/tickets/assignees.ts +54 -0
  111. package/packages/core/src/ports/tickets/contract.ts +164 -4
  112. package/packages/core/src/ports/tickets/create.ts +17 -3
  113. package/packages/core/src/ports/tickets/fake.ts +5 -0
  114. package/packages/core/src/ports/tickets/github-fake.ts +18 -2
  115. package/packages/core/src/ports/tickets/github.ts +247 -29
  116. package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
  117. package/packages/core/src/ports/tickets/operations.ts +6 -1
  118. package/packages/core/src/ports/tickets/tree.ts +12 -2
  119. package/packages/core/src/ports/tickets/update.ts +6 -2
  120. package/packages/core/src/ports/types.ts +36 -5
  121. package/packages/core/src/ports/workspace/vercel-sandbox.ts +9 -0
  122. package/packages/core/src/processes/build-child.ts +28 -7
  123. package/packages/core/src/processes/build-execution-state.ts +34 -2
  124. package/packages/core/src/processes/build-runner.ts +165 -19
  125. package/packages/core/src/processes/dispatcher.ts +837 -115
  126. package/packages/core/src/processes/execution-no-progress.ts +22 -2
  127. package/packages/core/src/processes/harvest-child.ts +4 -0
  128. package/packages/core/src/processes/harvest-runner.ts +5 -0
  129. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  130. package/packages/core/src/processes/publication-state.ts +6 -1
  131. package/packages/core/src/processes/repo-view.ts +2 -0
  132. package/packages/core/src/scenarios/harness.ts +15 -1
  133. package/packages/core/src/store/digest.ts +41 -2
  134. package/packages/core/src/store/reduced-reads.ts +4 -1
  135. package/packages/core/src/store/reducer-value-shapes.json +10310 -8441
  136. package/packages/core/src/store/remote/client.ts +49 -10
  137. package/packages/core/src/store/remote/index.ts +4 -0
  138. package/packages/core/src/store/remote/protocol.ts +18 -1
  139. package/packages/core/src/store/remote/released-clients.json +22 -0
  140. package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
  141. package/packages/core/src/store/remote/released-reducer-values/1.8.0.json +29043 -0
  142. package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
  143. package/packages/core/src/store/repo-state-events.ts +3 -0
  144. package/packages/core/src/store/types.ts +27 -0
  145. package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
  146. package/packages/core/src/testing/index.ts +2 -0
  147. package/packages/core/src/testing/reduced-read-budget.ts +419 -9
  148. package/skills/code-review/SKILL.md +8 -0
  149. package/skills/finalize/SKILL.md +4 -0
  150. package/skills/guide/SKILL.md +241 -47
  151. package/skills/guide/references/integration-tree.md +7 -4
  152. package/skills/guide/references/merge-policy.md +78 -6
  153. package/skills/guide/references/migration-1.0.md +4 -2
  154. package/skills/guide/references/operator-api.md +45 -13
  155. package/skills/guide/references/plugin-authoring.md +45 -7
  156. package/skills/guide/references/remote-store-protocol.md +28 -7
  157. package/skills/guide/references/restacking.md +35 -11
  158. package/skills/guide/references/ticket-dependencies.md +9 -4
  159. package/skills/implement/SKILL.md +15 -1
  160. package/skills/operate/SKILL.md +133 -16
  161. package/skills/plan/SKILL.md +17 -2
  162. package/skills/plan-review/SKILL.md +8 -0
  163. package/skills/reconcile/SKILL.md +21 -5
  164. package/skills/tickets/SKILL.md +23 -6
  165. package/templates/hosted-service/package.json +2 -2
@@ -24,7 +24,16 @@
24
24
  * A `readyAssignee` narrows the ready read itself
25
25
  * (its `assignee` query parameter); `"me"` costs one `GET /user` per
26
26
  * dispatcher start, sent by `prepareReadyAssignee` before the loop and never
27
- * during a tick.
27
+ * during a tick. It also adds one conditional `assignee=none` read per ready
28
+ * scan, plus one per further page, that reports ready issues with no
29
+ * assignee as diagnostics; its failures, rate limits included, never fail
30
+ * the scan or arm the source cooldown.
31
+ * Assignees cost reads nothing: every issue payload already carries them. A
32
+ * write naming assignees sends one `GET /repos/{o}/{r}/assignees/{login}` per
33
+ * distinct login per instance (positive answers are memoized) and resolves
34
+ * `"me"` through the same memoized `GET /user`; a dispatcher prepared it at
35
+ * startup, so a harvest proposal filed under `createAssignee = "me"` adds no
36
+ * `GET /user` and an idle tick adds nothing.
28
37
  */
29
38
  import { z } from 'zod'
30
39
  import {
@@ -85,7 +94,12 @@ import {
85
94
  validCreationKey,
86
95
  writeForState,
87
96
  } from './github-issues'
88
- import { GITHUB_READY_ASSIGNEE } from '../../config/ready-assignee'
97
+ import {
98
+ GITHUB_CREATE_ASSIGNEE,
99
+ GITHUB_READY_ASSIGNEE,
100
+ githubAssigneeForm,
101
+ } from '../../config/ready-assignee'
102
+ import { MAX_TICKET_ASSIGNEES } from './assignees'
89
103
  import { type GitHubValidatorStore, MemoryGitHubValidatorStore } from './github-validators'
90
104
  import { normalizeIssueLinks } from './issue-links'
91
105
  import { holdsState, type TicketLifecycle } from './lifecycle'
@@ -115,6 +129,8 @@ const LINK_LABEL_DESCRIPTION = 'Autobuild issue link'
115
129
  const NODE_LABEL_DESCRIPTION = 'Autobuild integration node'
116
130
  /** GitHub limits a label description to 100 characters. */
117
131
  const LABEL_DESCRIPTION_MAX = 100
132
+ /** Ready issues with no assignee a scan names before counting the rest. */
133
+ const UNASSIGNED_REPORT_LIMIT = 10
118
134
 
119
135
  /** A keyed create reached the source without the key's reservation time. */
120
136
  export class TicketCreationKeyReservationRequired extends Error {
@@ -203,6 +219,12 @@ function etagOf(read: { etag?: string }): { etag?: string } {
203
219
  return read.etag !== undefined ? { etag: read.etag } : {}
204
220
  }
205
221
 
222
+ /** Requested logins the issue does not hold, compared case-insensitively. */
223
+ function missingAssignees(issue: GitHubIssue, requested: readonly string[]): string[] {
224
+ const held = loginSet(assigneeLogins(issue))
225
+ return requested.filter((login) => !held.has(login.toLowerCase()))
226
+ }
227
+
206
228
  function blockerList(ids: string[]): string {
207
229
  return ids.length > 0 ? ids.map((id) => `"${id}"`).join(', ') : 'none'
208
230
  }
@@ -217,14 +239,30 @@ const githubCommentSchema = z
217
239
  /** Who the credential belongs to, as `prepareReadyAssignee` found it. */
218
240
  type Viewer = { login: string } | { noUser: true } | { failed: string }
219
241
 
220
- const NO_USER_ASSIGNEE =
221
- 'github tickets: [tickets].readyAssignee = "me" but the GitHub credential has no user (a GitHub App installation token has none) — set readyAssignee to a GitHub username'
242
+ type AssigneeKey = 'readyAssignee' | 'createAssignee'
243
+
244
+ const NO_USER_ASSIGNEE = (key: AssigneeKey): string =>
245
+ `github tickets: [tickets].${key} = "me" but the GitHub credential has no user (a GitHub App installation token has none) — set ${key} to a GitHub username`
246
+
247
+ /** The key-neutral form, for a write whose assignees name `me`. */
248
+ const NO_USER_WRITE =
249
+ 'the GitHub credential has no user (a GitHub App installation token has none) — name a GitHub username instead of me'
250
+
251
+ /** Logins compared as GitHub does: case-insensitively. */
252
+ function loginSet(logins: readonly string[]): Set<string> {
253
+ return new Set(logins.map((login) => login.toLowerCase()))
254
+ }
255
+
256
+ function assigneeLogins(issue: GitHubIssue): string[] {
257
+ return (issue.assignees ?? []).map((assignee) => assignee.login)
258
+ }
222
259
 
223
260
  export class GitHubTicketSource implements TicketSource {
224
261
  readonly name = 'github'
225
262
  readonly issueLinks = true
226
263
  readonly allocatesIds = true
227
264
  readonly readyAssignee = true
265
+ readonly assignees = true
228
266
  readonly integrationTree = true
229
267
 
230
268
  private readonly transport: GitHubRequest
@@ -236,6 +274,9 @@ export class GitHubTicketSource implements TicketSource {
236
274
  private readonly now: () => number
237
275
  private readonly credentialMiss?: () => Promise<string | undefined>
238
276
  private cooldown?: TicketSourceRateLimitError
277
+ /** A rate limit hit by the unassigned-ready report, kept apart from
278
+ * `cooldown` so it never refuses the listing or claim reads. */
279
+ private unassignedCooldownUntil?: number
239
280
  /** Exact label name (lowercased) → the one registry write in progress. */
240
281
  private readonly pendingLabels = new Map<string, Promise<void>>()
241
282
  /** Labels this instance created or saw created, lowercased. */
@@ -245,6 +286,8 @@ export class GitHubTicketSource implements TicketSource {
245
286
  private creationScan?: { floor: number; newest: number; keys: Map<string, number> }
246
287
  /** The credential's owner, memoized for the instance's lifetime. */
247
288
  private viewer?: Viewer
289
+ /** Logins (lowercased) GitHub confirmed can be assigned issues here. */
290
+ private readonly assignable = new Set<string>()
248
291
 
249
292
  constructor(opts: GitHubTicketSourceOptions) {
250
293
  for (const label of opts.readyLabels) {
@@ -452,6 +495,17 @@ export class GitHubTicketSource implements TicketSource {
452
495
  `github ${operation}: token lacks push access; label changes were dropped on #${number} (${issue.html_url})`,
453
496
  )
454
497
  }
498
+ // Assignees the token may not set are dropped the same way.
499
+ if (Array.isArray(body.assignees)) {
500
+ const wanted = loginSet(body.assignees as string[])
501
+ const held = loginSet(assigneeLogins(issue))
502
+ if (wanted.size !== held.size || [...wanted].some((login) => !held.has(login)))
503
+ throw new Error(
504
+ `github ${operation}: #${number} (${issue.html_url}) was written but its assignees were not applied — GitHub holds ${
505
+ held.size > 0 ? [...held].join(', ') : 'none (it is unassigned)'
506
+ } instead of ${wanted.size > 0 ? [...wanted].join(', ') : 'none'}; the token needs push access to assign`,
507
+ )
508
+ }
455
509
  return issue
456
510
  }
457
511
 
@@ -798,6 +852,8 @@ export class GitHubTicketSource implements TicketSource {
798
852
  labels: ticketLabelsOf(issue),
799
853
  ...(blockedBy.length > 0 ? { blockedBy } : {}),
800
854
  issueLinks,
855
+ // Not part of the revision: ticketRevision picks its fields explicitly.
856
+ assignees: assigneeLogins(issue),
801
857
  }
802
858
  ticket.revision = ticketRevision(ticket)
803
859
  return ticket
@@ -975,7 +1031,7 @@ export class GitHubTicketSource implements TicketSource {
975
1031
  // A label state: the ready listing is the recurring dispatcher read, so
976
1032
  // it alone is remembered, oldest first for a stable order.
977
1033
  const recurring = holdsState(wanted, this.lifecycle.ready)
978
- return this.listing(
1034
+ const listing = await this.listing(
979
1035
  await listIssues(
980
1036
  'listReady',
981
1037
  {
@@ -989,6 +1045,75 @@ export class GitHubTicketSource implements TicketSource {
989
1045
  holds,
990
1046
  recurring,
991
1047
  )
1048
+ if (!recurring || login === undefined) return listing
1049
+ return {
1050
+ tickets: listing.tickets,
1051
+ diagnostics: [...listing.diagnostics, ...(await this.unassignedReady(wanted, labels, login))],
1052
+ }
1053
+ }
1054
+
1055
+ /**
1056
+ * Ready issues no `readyAssignee` read can see because nobody is assigned:
1057
+ * one remembered `assignee=none` listing, never hydrated. It only reports;
1058
+ * a failure becomes a diagnostic and leaves the source cooldown as it was,
1059
+ * so assigned tickets are still listed and claimed.
1060
+ */
1061
+ private async unassignedReady(state: string, labels: string[], login: string): Promise<string[]> {
1062
+ const failed = (reason: string) => [
1063
+ `github tickets: could not check ready issues for a missing assignee (${reason}); assigned ready issues are unaffected`,
1064
+ ]
1065
+ const rateLimited = (resetAt: number) =>
1066
+ failed(`rate limited until ${new Date(resetAt).toISOString()}`)
1067
+ if (this.unassignedCooldownUntil !== undefined) {
1068
+ if (this.now() < this.unassignedCooldownUntil)
1069
+ return rateLimited(this.unassignedCooldownUntil)
1070
+ this.unassignedCooldownUntil = undefined
1071
+ }
1072
+ const prior = this.cooldown
1073
+ let issues: GitHubIssue[]
1074
+ try {
1075
+ issues = await this.listIssues(
1076
+ 'listReadyUnassigned',
1077
+ {
1078
+ state: 'open',
1079
+ sort: 'created',
1080
+ direction: 'asc',
1081
+ labels: [stateLabel(state), ...labels].join(','),
1082
+ assignee: 'none',
1083
+ },
1084
+ true,
1085
+ )
1086
+ } catch (error) {
1087
+ this.cooldown = prior
1088
+ if (error instanceof TicketSourceRateLimitError) {
1089
+ this.unassignedCooldownUntil = error.resetAt
1090
+ return rateLimited(error.resetAt)
1091
+ }
1092
+ return failed(message(error))
1093
+ }
1094
+ const required = labels.map((label) => label.toLowerCase())
1095
+ const numbers = issues
1096
+ .filter((issue) => {
1097
+ if (issue.state !== 'open' || (issue.assignees ?? []).length > 0) return false
1098
+ const current = issueState(issue, this.lifecycle)
1099
+ if ('malformed' in current || !holdsState(current.state, state)) return false
1100
+ const held = ticketLabelsOf(issue).map((label) => label.toLowerCase())
1101
+ return required.every((label) => held.includes(label))
1102
+ })
1103
+ .map((issue) => issue.number)
1104
+ .sort((a, b) => a - b)
1105
+ const diagnostics = numbers
1106
+ .slice(0, UNASSIGNED_REPORT_LIMIT)
1107
+ .map(
1108
+ (number) =>
1109
+ `github #${number}: ready but unassigned — [tickets].readyAssignee claims only issues assigned to ${login}; assign it to make it claimable`,
1110
+ )
1111
+ const more = numbers.length - UNASSIGNED_REPORT_LIMIT
1112
+ if (more > 0)
1113
+ diagnostics.push(
1114
+ `github: ${more} more ready issues are unassigned and unclaimed — assign them to make them claimable`,
1115
+ )
1116
+ return diagnostics
992
1117
  }
993
1118
 
994
1119
  private async listing(
@@ -1231,6 +1356,8 @@ export class GitHubTicketSource implements TicketSource {
1231
1356
  : Date.parse(opts.idempotencyKeyReservedAt)
1232
1357
  if (!Number.isFinite(reservedAt)) throw new TicketCreationKeyReservationRequired()
1233
1358
  }
1359
+ const assignees =
1360
+ draft.assignees === undefined ? [] : await this.resolveAssignees('create', draft.assignees)
1234
1361
  const state = await this.resolveTarget('create', opts.state ?? this.lifecycle.create)
1235
1362
  const target =
1236
1363
  draft.target === undefined || draft.target === null
@@ -1240,7 +1367,7 @@ export class GitHubTicketSource implements TicketSource {
1240
1367
  const write = writeForState(state, this.lifecycle, [...labels, ...links.map(linkLabel)])
1241
1368
  if (key !== undefined && reservedAt !== undefined) {
1242
1369
  const adopted = await this.findByCreationKey(key, reservedAt)
1243
- if (adopted !== undefined) return this.adopt(adopted, blockedBy)
1370
+ if (adopted !== undefined) return this.adopt(adopted, blockedBy, assignees)
1244
1371
  }
1245
1372
  // A closing create state opens the issue without a state label and
1246
1373
  // closes it as a follow-up.
@@ -1257,6 +1384,7 @@ export class GitHubTicketSource implements TicketSource {
1257
1384
  title: draft.title,
1258
1385
  body: key === undefined ? draft.body : encodeCreationMarker(draft.body, key, intent),
1259
1386
  labels: initial,
1387
+ ...(assignees.length > 0 ? { assignees } : {}),
1260
1388
  },
1261
1389
  })
1262
1390
  const issue = this.parseIssue('create', response.json)
@@ -1265,6 +1393,13 @@ export class GitHubTicketSource implements TicketSource {
1265
1393
  throw new Error(
1266
1394
  `github create: token lacks push access; labels were dropped on #${issue.number} (${issue.html_url})`,
1267
1395
  )
1396
+ // GitHub silently drops assignees the token may not set. A keyed create's
1397
+ // marker stays pending, so a retry adopts this issue and reconciles them.
1398
+ const dropped = missingAssignees(issue, assignees)
1399
+ if (dropped.length > 0)
1400
+ throw new Error(
1401
+ `github create: #${issue.number} (${issue.html_url}) was created but is unassigned — GitHub dropped assignee(s) ${dropped.join(', ')}; the token needs push access to assign`,
1402
+ )
1268
1403
  return this.finishCreate(issue, intent, key, false)
1269
1404
  }
1270
1405
 
@@ -1324,10 +1459,22 @@ export class GitHubTicketSource implements TicketSource {
1324
1459
  return read.issue
1325
1460
  }
1326
1461
 
1327
- /** A retry found the issue its key opened. A pending marker finishes the
1328
- * first attempt's recorded intent; a plain one reconciles only missing
1329
- * blockers from this retry, as Linear does. */
1330
- private async adopt(issue: GitHubIssue, retryBlockers: string[]): Promise<Ticket> {
1462
+ /** A retry found the issue its key opened. Missing requested assignees are
1463
+ * added first. A pending marker finishes the first attempt's recorded
1464
+ * intent; a plain one reconciles only missing blockers from this retry, as
1465
+ * Linear does. */
1466
+ private async adopt(
1467
+ found: GitHubIssue,
1468
+ retryBlockers: string[],
1469
+ assignees: string[],
1470
+ ): Promise<Ticket> {
1471
+ let issue = found
1472
+ if (missingAssignees(issue, assignees).length > 0) {
1473
+ const held = assigneeLogins(issue)
1474
+ issue = await this.patchIssue('create', issue.number, {
1475
+ assignees: [...held, ...missingAssignees(issue, assignees)],
1476
+ })
1477
+ }
1331
1478
  const marker = splitCreationMarker(issue.body).marker!
1332
1479
  if (marker.pending !== undefined)
1333
1480
  return this.finishCreate(issue, marker.pending, marker.key, true)
@@ -1636,9 +1783,14 @@ export class GitHubTicketSource implements TicketSource {
1636
1783
  if (local !== canonical) parentWrite = { set: canonical, replace: parentIsNode }
1637
1784
  }
1638
1785
  }
1639
- if (ticketLabels?.includes(NODE_LABEL) && !held.includes(NODE_LABEL))
1640
- await this.ensureNodeLabel('update')
1641
1786
  }
1787
+ const assignees =
1788
+ validated.assignees === undefined
1789
+ ? undefined
1790
+ : await this.resolveAssignees('update', validated.assignees)
1791
+ // The first write: every refusal above, assignees included, writes nothing.
1792
+ if (ticketLabels?.includes(NODE_LABEL) && !held.includes(NODE_LABEL))
1793
+ await this.ensureNodeLabel('update')
1642
1794
  const body: Record<string, unknown> = {}
1643
1795
  if (validated.title !== undefined) body.title = validated.title
1644
1796
  if (validated.body !== undefined) {
@@ -1655,6 +1807,7 @@ export class GitHubTicketSource implements TicketSource {
1655
1807
  await this.ensureLabels('update', labels)
1656
1808
  body.labels = [...new Set(labels)]
1657
1809
  }
1810
+ if (assignees !== undefined) body.assignees = assignees
1658
1811
  const fields = Object.keys(body)
1659
1812
  if (fields.length > 0) await this.patchIssue('update', number, body)
1660
1813
  if (parentWrite === undefined) return
@@ -1920,43 +2073,108 @@ export class GitHubTicketSource implements TicketSource {
1920
2073
  }
1921
2074
  }
1922
2075
 
1923
- readyAssigneeRefusal(value: string): string | undefined {
1924
- if (!GITHUB_READY_ASSIGNEE.accepts(value)) return GITHUB_READY_ASSIGNEE.message
2076
+ private assigneeRefusal(key: AssigneeKey, value: string): string | undefined {
2077
+ const form = key === 'readyAssignee' ? GITHUB_READY_ASSIGNEE : GITHUB_CREATE_ASSIGNEE
2078
+ if (!form.accepts(value)) return form.message
1925
2079
  if (value !== 'me') return undefined
1926
2080
  if (this.viewer === undefined || 'failed' in this.viewer)
1927
- return `github tickets: [tickets].readyAssignee = "me" but the GitHub credential owner could not be resolved at dispatcher startup (${
2081
+ return `github tickets: [tickets].${key} = "me" but the GitHub credential owner could not be resolved at dispatcher startup (${
1928
2082
  this.viewer === undefined ? 'not prepared' : this.viewer.failed
1929
- }); restart dispatch to enable readyAssignee = "me"`
1930
- return 'noUser' in this.viewer ? NO_USER_ASSIGNEE : undefined
2083
+ }); restart dispatch to enable ${key} = "me"`
2084
+ return 'noUser' in this.viewer ? NO_USER_ASSIGNEE(key) : undefined
2085
+ }
2086
+
2087
+ readyAssigneeRefusal(value: string): string | undefined {
2088
+ return this.assigneeRefusal('readyAssignee', value)
1931
2089
  }
1932
2090
 
1933
- /** The login a `readyAssignee` value names. An unprepared one-shot surface
1934
- * (`ab ticket list`, init validation) resolves `"me"` once, lazily. */
1935
- private async assigneeLogin(value: string): Promise<string> {
2091
+ createAssigneeRefusal(value: string): string | undefined {
2092
+ return this.assigneeRefusal('createAssignee', value)
2093
+ }
2094
+
2095
+ /** The login a value names. An unprepared one-shot surface (`ab ticket
2096
+ * list`, `ab ticket create`, init validation) resolves `"me"` once, lazily. */
2097
+ private async assigneeLogin(value: string, noUser = NO_USER_ASSIGNEE('readyAssignee')) {
1936
2098
  if (value !== 'me') return value
1937
2099
  if (this.viewer === undefined || 'failed' in this.viewer) this.viewer = await this.readViewer()
1938
- if ('noUser' in this.viewer) throw new Error(NO_USER_ASSIGNEE)
2100
+ if ('noUser' in this.viewer) throw new Error(noUser)
1939
2101
  return (this.viewer as { login: string }).login
1940
2102
  }
1941
2103
 
1942
- async describeReadyAssignee(value: string): Promise<string> {
1943
- if (value === 'me') await this.prepareReadyAssignee()
1944
- const refusal = this.readyAssigneeRefusal(value)
1945
- if (refusal !== undefined) throw new Error(refusal)
1946
- const login = await this.assigneeLogin(value)
2104
+ /** Whether GitHub lets `login` be assigned issues here: one 204/404 read,
2105
+ * memoized when positive. */
2106
+ private async canAssign(operation: string, login: string): Promise<boolean> {
2107
+ if (this.assignable.has(login.toLowerCase())) return true
1947
2108
  const check = await this.request(
1948
- 'readyAssignee',
2109
+ operation,
1949
2110
  'GET',
1950
2111
  this.path(`/assignees/${encodeURIComponent(login)}`),
1951
2112
  { missing: true },
1952
2113
  )
1953
- if (check === null)
2114
+ if (check === null) return false
2115
+ this.assignable.add(login.toLowerCase())
2116
+ return true
2117
+ }
2118
+
2119
+ private async describeAssignee(key: AssigneeKey, value: string): Promise<string> {
2120
+ if (value === 'me') await this.prepareReadyAssignee()
2121
+ const refusal = this.assigneeRefusal(key, value)
2122
+ if (refusal !== undefined) throw new Error(refusal)
2123
+ const login = await this.assigneeLogin(value, NO_USER_ASSIGNEE(key))
2124
+ if (!(await this.canAssign(key, login)))
1954
2125
  throw new Error(
1955
- `github tickets: [tickets].readyAssignee "${login}" cannot be assigned issues in ${this.fullName} — use a GitHub username with access to the repository, or "me"`,
2126
+ `github tickets: [tickets].${key} "${login}" cannot be assigned issues in ${this.fullName} — use a GitHub username with access to the repository, or "me"`,
1956
2127
  )
1957
2128
  return `${value} → @${login}`
1958
2129
  }
1959
2130
 
2131
+ async describeReadyAssignee(value: string): Promise<string> {
2132
+ return this.describeAssignee('readyAssignee', value)
2133
+ }
2134
+
2135
+ async describeCreateAssignee(value: string): Promise<string> {
2136
+ return this.describeAssignee('createAssignee', value)
2137
+ }
2138
+
2139
+ /**
2140
+ * The exact logins a write names, before anything is written: each entry's
2141
+ * form, at most ten (GitHub's limit), `me` resolved to the credential's
2142
+ * owner, duplicates dropped, and each login confirmed assignable.
2143
+ */
2144
+ private async resolveAssignees(operation: string, entries: readonly string[]): Promise<string[]> {
2145
+ const form = githubAssigneeForm('createAssignee')
2146
+ for (const entry of entries)
2147
+ if (!form.accepts(entry))
2148
+ throw new Error(
2149
+ `github ${operation}: assignee "${entry}" must be "me" or a GitHub username — nothing was written`,
2150
+ )
2151
+ const logins: string[] = []
2152
+ const seen = new Set<string>()
2153
+ for (const entry of entries) {
2154
+ let login: string
2155
+ try {
2156
+ login = await this.assigneeLogin(entry, NO_USER_WRITE)
2157
+ } catch (error) {
2158
+ throw new Error(`github ${operation}: ${message(error)} — nothing was written`, {
2159
+ cause: error,
2160
+ })
2161
+ }
2162
+ if (seen.has(login.toLowerCase())) continue
2163
+ seen.add(login.toLowerCase())
2164
+ logins.push(login)
2165
+ }
2166
+ if (logins.length > MAX_TICKET_ASSIGNEES)
2167
+ throw new Error(
2168
+ `github ${operation}: at most ${MAX_TICKET_ASSIGNEES} assignees per issue — nothing was written`,
2169
+ )
2170
+ for (const login of logins)
2171
+ if (!(await this.canAssign(operation, login)))
2172
+ throw new Error(
2173
+ `github ${operation}: "${login}" cannot be assigned issues in ${this.fullName} — nothing was written`,
2174
+ )
2175
+ return logins
2176
+ }
2177
+
1960
2178
  // ── Init validation ───────────────────────────────────────────────────────
1961
2179
 
1962
2180
  /** One specific message per access problem, for `ab init --validate`. */
@@ -41,6 +41,7 @@ export {
41
41
  urgentFirst,
42
42
  type TicketPriority,
43
43
  } from './priority'
44
+ export { TicketAssigneesUnsupported } from './assignees'
44
45
 
45
46
  export {
46
47
  hostedTicketPolicySchema,
@@ -5,6 +5,7 @@ import {
5
5
  TicketIssueLinksUnsupported,
6
6
  } from './issue-links'
7
7
  import { refuseUnsupportedPriority, TicketPriorityUnsupported } from './priority'
8
+ import { refuseUnsupportedAssignees, TicketAssigneesUnsupported } from './assignees'
8
9
  import {
9
10
  mutateTicketIfRevision,
10
11
  TicketRevisionConflict,
@@ -69,7 +70,8 @@ function passthrough(error: unknown): boolean {
69
70
  error instanceof TicketRevisionConflict ||
70
71
  error instanceof TicketRevisionUnsupported ||
71
72
  error instanceof TicketIssueLinksUnsupported ||
72
- error instanceof TicketPriorityUnsupported
73
+ error instanceof TicketPriorityUnsupported ||
74
+ error instanceof TicketAssigneesUnsupported
73
75
  )
74
76
  }
75
77
 
@@ -99,6 +101,7 @@ export async function createTicket(
99
101
  ): Promise<Ticket> {
100
102
  refuseUnsupportedIssueLinks(source, input)
101
103
  refuseUnsupportedPriority(source, input)
104
+ refuseUnsupportedAssignees(source, input)
102
105
  source = compatibleTicketSource(source)
103
106
  const blockedBy = await knownBlockers(
104
107
  source,
@@ -117,6 +120,7 @@ export async function createTicket(
117
120
  ? { issueLinks: normalizeIssueLinks(input.issueLinks) }
118
121
  : {}),
119
122
  ...(input.priority !== undefined ? { priority: input.priority } : {}),
123
+ ...(input.assignees !== undefined ? { assignees: [...input.assignees] } : {}),
120
124
  }
121
125
  try {
122
126
  return input.state === undefined
@@ -140,6 +144,7 @@ export async function updateTicket(
140
144
  ): Promise<Ticket | null> {
141
145
  refuseUnsupportedIssueLinks(source, patch)
142
146
  refuseUnsupportedPriority(source, patch)
147
+ refuseUnsupportedAssignees(source, patch)
143
148
  source = compatibleTicketSource(source)
144
149
  try {
145
150
  if (expectedRevision !== undefined)
@@ -3,6 +3,7 @@ import { checkTicketRevision } from './revision'
3
3
  import { validateTicketUpdate } from './update'
4
4
  import { refuseUnsupportedIssueLinks } from './issue-links'
5
5
  import { refuseUnsupportedPriority, withoutUnsupportedPriority } from './priority'
6
+ import { refuseUnsupportedAssignees } from './assignees'
6
7
 
7
8
  /** Sources without a capability cannot present that capability's fields. */
8
9
  export function normalizeTicket(
@@ -10,8 +11,9 @@ export function normalizeTicket(
10
11
  supported = true,
11
12
  issueLinks = true,
12
13
  priority = true,
14
+ assignees = true,
13
15
  ): Ticket {
14
- const { target, issueLinks: links, priority: urgency, ...rest } = ticket
16
+ const { target, issueLinks: links, priority: urgency, assignees: assigned, ...rest } = ticket
15
17
  return {
16
18
  ...rest,
17
19
  kind: supported ? (ticket.kind ?? 'work') : 'work',
@@ -19,12 +21,19 @@ export function normalizeTicket(
19
21
  ...(issueLinks && links !== undefined ? { issueLinks: links } : {}),
20
22
  // Normal is the absence of the field, so strict wire schemas never see it.
21
23
  ...(priority && urgency === 'urgent' ? { priority: urgency } : {}),
24
+ ...(assignees && assigned !== undefined ? { assignees: assigned } : {}),
22
25
  }
23
26
  }
24
27
 
25
28
  /** Apply the source's own capabilities to a ticket it returned. */
26
29
  export function normalizeSourceTicket(source: TicketSource, ticket: Ticket): Ticket {
27
- return normalizeTicket(ticket, !!source.integrationTree, !!source.issueLinks, !!source.priority)
30
+ return normalizeTicket(
31
+ ticket,
32
+ !!source.integrationTree,
33
+ !!source.issueLinks,
34
+ !!source.priority,
35
+ !!source.assignees,
36
+ )
28
37
  }
29
38
 
30
39
  export function refuseUnsupportedMetadata(
@@ -37,6 +46,7 @@ export function refuseUnsupportedMetadata(
37
46
  )
38
47
  refuseUnsupportedIssueLinks(source, patch)
39
48
  refuseUnsupportedPriority(source, patch)
49
+ refuseUnsupportedAssignees(source, patch)
40
50
  }
41
51
 
42
52
  /** Validate before any part of a mixed patch is written. Canonical refs close alias cycles. */
@@ -3,6 +3,7 @@ import { expandIssues } from '../../zod-issues'
3
3
  import type { TicketUpdate } from '../types'
4
4
  import { issueLinksInputSchema, normalizeIssueLinks } from './issue-links'
5
5
  import { ticketPrioritySchema } from './priority'
6
+ import { ticketAssigneesSchema } from './assignees'
6
7
 
7
8
  const ticketUpdateSchema = z
8
9
  .strictObject({
@@ -23,6 +24,7 @@ const ticketUpdateSchema = z
23
24
  labels: z.array(z.string()).optional(),
24
25
  issueLinks: issueLinksInputSchema.optional(),
25
26
  priority: ticketPrioritySchema.optional(),
27
+ assignees: ticketAssigneesSchema.optional(),
26
28
  })
27
29
  .refine(
28
30
  (patch) =>
@@ -32,8 +34,9 @@ const ticketUpdateSchema = z
32
34
  patch.kind !== undefined ||
33
35
  patch.target !== undefined ||
34
36
  patch.issueLinks !== undefined ||
35
- patch.priority !== undefined,
36
- 'update must name at least one of title, body, labels, issue links, priority, kind, or target',
37
+ patch.priority !== undefined ||
38
+ patch.assignees !== undefined,
39
+ 'update must name at least one of title, body, labels, issue links, priority, assignees, kind, or target',
37
40
  )
38
41
 
39
42
  /** Render ticket-update issues while retaining nested union branch detail. */
@@ -70,5 +73,6 @@ export function validateTicketUpdate(patch: TicketUpdate): TicketUpdate {
70
73
  ? { issueLinks: normalizeIssueLinks(result.data.issueLinks) }
71
74
  : {}),
72
75
  ...(result.data.priority !== undefined ? { priority: result.data.priority } : {}),
76
+ ...(result.data.assignees !== undefined ? { assignees: [...result.data.assignees] } : {}),
73
77
  }
74
78
  }
@@ -96,6 +96,9 @@ export interface Ticket {
96
96
  /** `urgent` dispatches before normal ready work. Absent means normal, or a
97
97
  * source that cannot store priority. Normalized tickets never carry `normal`. */
98
98
  priority?: TicketPriority
99
+ /** Usernames the ticket is assigned to. Present (possibly empty) only for
100
+ * sources with the `assignees` capability; not part of `revision`. */
101
+ assignees?: string[]
99
102
  }
100
103
 
101
104
  /** Dispatch class: urgent ready work is claimed before normal ready work. */
@@ -123,6 +126,7 @@ export interface TicketCriteria {
123
126
  export interface TicketPage {
124
127
  limit: number
125
128
  offset?: number
129
+ /** Dispatch order or newest filed first; see `TicketSource.listPage`. */
126
130
  order?: 'oldest' | 'newest'
127
131
  }
128
132
 
@@ -156,6 +160,10 @@ export interface TicketDraft {
156
160
  /** Dispatch class. A source without the `priority` capability refuses
157
161
  * `urgent`; `normal` is a no-op. */
158
162
  priority?: TicketPriority
163
+ /** Exact assignees: entries are usernames or `me` (the owner of the source's
164
+ * credential). Callers apply any `[tickets].createAssignee` default. A source
165
+ * without the `assignees` capability refuses, never discards. */
166
+ assignees?: string[]
159
167
  }
160
168
 
161
169
  /** One node of the dependency graph, as this source sees it. */
@@ -216,6 +224,10 @@ export interface TicketUpdate {
216
224
  /** `normal` removes urgency. A source without the `priority` capability
217
225
  * refuses `urgent`; `normal` is a no-op. */
218
226
  priority?: TicketPriority
227
+ /** A complete assignee replacement; entries are usernames or `me`. An
228
+ * explicit empty array clears assignees. A source without the `assignees`
229
+ * capability refuses, never discards. */
230
+ assignees?: string[]
219
231
  }
220
232
 
221
233
  /** One workflow state of a source that can enumerate them. */
@@ -281,6 +293,20 @@ export interface TicketSource {
281
293
  * boundary, including create and guarded writes. Sources without it read
282
294
  * every ticket as normal and refuse any write naming `urgent`. */
283
295
  readonly priority?: boolean
296
+ /** Opt in only when assignees are persisted, returned on every read (an
297
+ * empty array when unassigned) and verified at every write boundary,
298
+ * including create, keyed-create adoption and guarded writes; a write that
299
+ * the provider accepts without the requested assignees must fail. Sources
300
+ * without it refuse any write naming assignees and
301
+ * `[tickets].createAssignee`. */
302
+ readonly assignees?: boolean
303
+ /** Synchronous and request-free: why `[tickets].createAssignee` cannot be
304
+ * honoured given what `prepareReadyAssignee` resolved, or undefined.
305
+ * Checked at dispatcher startup and on every reload. */
306
+ createAssigneeRefusal?(value: string): string | undefined
307
+ /** `ab init --validate`: a one-line summary of who `[tickets].createAssignee`
308
+ * names; throws an actionable error when it names nobody assignable. */
309
+ describeCreateAssignee?(value: string): Promise<string>
284
310
  /** Opt in only when `listReady` (and `listPage`, if implemented) honour
285
311
  * `criteria.assignee` and an unassigned ticket is never ready while it is
286
312
  * set. Sources without it refuse `[tickets].readyAssignee` at startup,
@@ -331,9 +357,13 @@ export interface TicketSource {
331
357
  * actionable diagnostics for individual source records excluded as invalid.
332
358
  * Fatal source failures and invariants still reject the call. */
333
359
  listReady(criteria: TicketCriteria): Promise<TicketListing>
334
- /** Optional native window, equivalent to listReady then reverse/slice.
335
- * Defaults: offset 0, order oldest. Arguments are nonnegative integers;
336
- * zero limit returns no tickets with the full matching total. Diagnostics
360
+ /** Optional native window over the listReady matches. `oldest` (default)
361
+ * is dispatch order: with `priority`, urgent first, then normal, each in
362
+ * listReady order. `newest` is newest filed first: creation time descending,
363
+ * independent of urgency, with a stable tie-break; it is not the reverse of
364
+ * dispatch order. Offset and limit apply after ordering. Default offset 0.
365
+ * Arguments are nonnegative integers; zero limit returns no tickets with the
366
+ * full matching total. Diagnostics
337
367
  * and failures match listReady; a failure must not trigger a full-read fallback.
338
368
  * listReady and listAll remain exhaustive. */
339
369
  listPage?(criteria: TicketCriteria, page: TicketPage): Promise<TicketPageListing>
@@ -359,8 +389,9 @@ export interface TicketSource {
359
389
  /**
360
390
  * Dependency-graph nodes for `ids`. The result covers EVERY requested id, in
361
391
  * request order; a missing id comes back `{exists: false, resolved: false,
362
- * blockedBy: []}`. Read at ticket creation and at dispatch time only — both
363
- * are initiation, so §13's "never consulted mid-build" is untouched.
392
+ * blockedBy: []}`. Read at ticket creation, at dispatch time, and by the
393
+ * dispatcher for open ticket waits — one batched call per tick while any
394
+ * wait is open, the one mid-build consultation §13 allows.
364
395
  */
365
396
  dependencyStates(ids: string[]): Promise<DependencyState[]>
366
397
  /**