@defrex/autobuild 1.17.0 → 1.18.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 (55) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +41 -2
  3. package/docs/architecture.md +27 -2
  4. package/docs/configuration.md +11 -3
  5. package/docs/dispatcher-hosting.md +5 -3
  6. package/docs/operator-api.md +14 -1
  7. package/docs/plugin-authoring.md +29 -1
  8. package/docs/remote-ticket-protocol.md +34 -1
  9. package/docs/restacking.md +5 -0
  10. package/docs/setup.md +9 -3
  11. package/docs/ticket-sources.md +28 -1
  12. package/docs/troubleshooting.md +15 -0
  13. package/docs/workspaces.md +1 -1
  14. package/package.json +4 -4
  15. package/packages/core/src/cli/dashboard/refresh.ts +8 -0
  16. package/packages/core/src/config/schema.ts +2 -1
  17. package/packages/core/src/events/repository.ts +37 -1
  18. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/d41044cb2e54809c.json +194 -0
  19. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e0f89f52e48cbf62.json +197 -0
  20. package/packages/core/src/kernel/reducer-revisions.ts +5 -0
  21. package/packages/core/src/kernel/repository-read-facts.ts +9 -2
  22. package/packages/core/src/kernel/ticket-preparation.ts +10 -0
  23. package/packages/core/src/operator/registry.ts +64 -9
  24. package/packages/core/src/operator/tickets.ts +139 -25
  25. package/packages/core/src/plugin-sdk/index.ts +4 -0
  26. package/packages/core/src/plugins/manifest.ts +1 -1
  27. package/packages/core/src/ports/tickets/completion.ts +71 -0
  28. package/packages/core/src/ports/tickets/contract.ts +73 -0
  29. package/packages/core/src/ports/tickets/github-fake.ts +8 -0
  30. package/packages/core/src/ports/tickets/github-issues.ts +1 -0
  31. package/packages/core/src/ports/tickets/github.ts +18 -6
  32. package/packages/core/src/ports/tickets/hosted-index.ts +8 -0
  33. package/packages/core/src/ports/tickets/linear.ts +18 -2
  34. package/packages/core/src/ports/tickets/remote-protocol.ts +37 -8
  35. package/packages/core/src/ports/tickets/remote.ts +41 -3
  36. package/packages/core/src/ports/tickets/tree.ts +11 -1
  37. package/packages/core/src/ports/types.ts +32 -4
  38. package/packages/core/src/ports/workspace/vercel-sandbox.ts +78 -25
  39. package/packages/core/src/processes/dispatcher.ts +852 -276
  40. package/packages/core/src/processes/pass-stages.ts +32 -6
  41. package/packages/core/src/store/reducer-value-shapes.json +8309 -8240
  42. package/packages/core/src/store/remote/released-clients.json +11 -0
  43. package/packages/core/src/store/remote/released-reducer-values/1.18.0.json +36436 -0
  44. package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
  45. package/packages/core/src/testing/dispatch-read-budget.ts +143 -16
  46. package/packages/core/src/testing/index.ts +2 -0
  47. package/packages/core/src/testing/reduced-read-budget.ts +198 -2
  48. package/skills/guide/SKILL.md +21 -5
  49. package/skills/guide/references/operator-api.md +14 -1
  50. package/skills/guide/references/plugin-authoring.md +29 -1
  51. package/skills/guide/references/remote-ticket-protocol.md +34 -1
  52. package/skills/guide/references/restacking.md +5 -0
  53. package/skills/guide/references/setup.md +9 -3
  54. package/skills/operate/SKILL.md +18 -1
  55. package/templates/hosted-service/package.json +2 -2
@@ -6,15 +6,20 @@ import { TicketIssueLinksUnsupported } from './issue-links'
6
6
  import { TicketPriorityUnsupported } from './priority'
7
7
  import { ticketLifecycle } from './lifecycle'
8
8
  import { TicketSearchCursorInvalid, TicketSearchUnsupported } from './search'
9
+ import {
10
+ TICKET_COMPLETION_SCAN_LIMIT,
11
+ TicketCompletionRangeTooBroad,
12
+ usesCompletionCriteria,
13
+ } from './completion'
9
14
  import type { TicketsConfig } from '../../config/schema'
10
15
  import type {
11
16
  DependencyState,
12
17
  Ticket,
13
18
  TicketCreateOptions,
14
19
  TicketDraft,
15
- TicketCriteria,
16
20
  TicketListing,
17
21
  TicketPage,
22
+ TicketPageCriteria,
18
23
  TicketPageListing,
19
24
  TicketPriority,
20
25
  TicketSearchPage,
@@ -62,6 +67,8 @@ import {
62
67
  TICKET_TARGETING_PROBE_NODE,
63
68
  TICKET_PAGING_HEADER,
64
69
  TICKET_PAGING_CAPABILITY,
70
+ TICKET_COMPLETION_HEADER,
71
+ TICKET_COMPLETION_CAPABILITY,
65
72
  TICKET_SEARCH_HEADER,
66
73
  TICKET_SEARCH_CAPABILITY,
67
74
  dependencyStatesWireSchema,
@@ -174,9 +181,11 @@ export class HostedTicketSource implements TicketSource {
174
181
  private readonly targeted = (nodeId: string) => this.targetedListing(nodeId)
175
182
  /** Unknown until a response settles it; see `noteCapabilities`. */
176
183
  private pagingSupport: boolean | undefined
177
- private readonly paged = (criteria: TicketCriteria, page: TicketPage) =>
184
+ private readonly paged = (criteria: TicketPageCriteria, page: TicketPage) =>
178
185
  this.pagedListing(criteria, page)
179
186
  /** Unknown until a response settles it; see `noteCapabilities`. */
187
+ private completionSupport: boolean | undefined
188
+ /** Unknown until a response settles it; see `noteCapabilities`. */
180
189
  private searchSupport: boolean | undefined
181
190
  private readonly searched = (query: TicketSearchQuery) => this.searchPage(query)
182
191
 
@@ -237,6 +246,12 @@ export class HostedTicketSource implements TicketSource {
237
246
  return this.pagingSupport === true ? this.paged : undefined
238
247
  }
239
248
 
249
+ /** True only once the service has advertised both `list-page` and its
250
+ * completion criteria; until then the operator filters `list-ready`. */
251
+ get completionPaging(): boolean {
252
+ return this.pagingSupport === true && this.completionSupport === true
253
+ }
254
+
240
255
  /** Present only once the service has positively advertised `search`; while
241
256
  * support is unknown or refused, callers refuse with `TicketSearchUnsupported`
242
257
  * before any request. There is never a listing fallback. */
@@ -274,6 +289,9 @@ export class HostedTicketSource implements TicketSource {
274
289
  if (response.headers.get(TICKET_SEARCH_HEADER) === TICKET_SEARCH_CAPABILITY)
275
290
  this.searchSupport = true
276
291
  else if (response.ok) this.searchSupport = false
292
+ if (response.headers.get(TICKET_COMPLETION_HEADER) === TICKET_COMPLETION_CAPABILITY)
293
+ this.completionSupport = true
294
+ else if (response.ok) this.completionSupport = false
277
295
  }
278
296
 
279
297
  private async send(
@@ -308,6 +326,7 @@ export class HostedTicketSource implements TicketSource {
308
326
  [TICKET_PAGING_HEADER]: TICKET_PAGING_CAPABILITY,
309
327
  [TICKET_SEARCH_HEADER]: TICKET_SEARCH_CAPABILITY,
310
328
  ...storeCallerHeaders(),
329
+ [TICKET_COMPLETION_HEADER]: TICKET_COMPLETION_CAPABILITY,
311
330
  [AUTOBUILD_VERSION_HEADER]: AUTOBUILD_VERSION,
312
331
  [REMOTE_STORE_PROTOCOL_VERSION_HEADER]: REMOTE_STORE_PROTOCOL_VERSION,
313
332
  },
@@ -412,6 +431,11 @@ export class HostedTicketSource implements TicketSource {
412
431
  ? body.error
413
432
  : 'ticket service cannot page this ticket source',
414
433
  )
434
+ if (body.code === 'completion-range-too-broad')
435
+ throw new TicketCompletionRangeTooBroad(
436
+ this.name,
437
+ typeof body.limit === 'number' ? body.limit : TICKET_COMPLETION_SCAN_LIMIT,
438
+ )
415
439
  if (body.code === 'search-unsupported') throw new TicketSearchUnsupported(this.name)
416
440
  if (body.code === 'search-cursor-invalid')
417
441
  throw new TicketSearchCursorInvalid(this.name, String(body.cursor ?? ''))
@@ -448,6 +472,7 @@ export class HostedTicketSource implements TicketSource {
448
472
  error instanceof TicketIssueLinksUnsupported ||
449
473
  error instanceof TicketPriorityUnsupported ||
450
474
  error instanceof HostedTicketPagingError ||
475
+ error instanceof TicketCompletionRangeTooBroad ||
451
476
  error instanceof TicketSearchUnsupported ||
452
477
  error instanceof TicketSearchCursorInvalid
453
478
  )
@@ -491,12 +516,19 @@ export class HostedTicketSource implements TicketSource {
491
516
  /** The service's native window: its order and total are canonical, so an
492
517
  * answer that contradicts the request fails rather than being repaired. */
493
518
  private async pagedListing(
494
- criteria: TicketCriteria,
519
+ criteria: TicketPageCriteria,
495
520
  page: TicketPage,
496
521
  ): Promise<TicketPageListing> {
497
522
  if (criteria.assignee !== undefined) {
498
523
  throw new Error('the hosted ticket source does not support an assignee gate')
499
524
  }
525
+ // A strict service predating completion criteria would refuse them, so
526
+ // they are sent only after a response echoed the completion capability.
527
+ if (usesCompletionCriteria(criteria, page) && this.completionSupport !== true)
528
+ throw new HostedTicketPagingError(
529
+ 'service-predates',
530
+ 'ticket service predates completion listing (since, until, excludeLabels, order completed); upgrade the service',
531
+ )
500
532
  const offset = page.offset ?? 0
501
533
  const listing = await this.request(
502
534
  'list-page',
@@ -504,6 +536,12 @@ export class HostedTicketSource implements TicketSource {
504
536
  criteria: {
505
537
  ...(criteria.labels !== undefined ? { labels: criteria.labels } : {}),
506
538
  ...(criteria.state !== undefined ? { state: criteria.state } : {}),
539
+ // Sent only when it excludes something, which the guard above
540
+ // has already negotiated; an empty list would trip an older
541
+ // service's strict request schema for no effect.
542
+ ...(criteria.excludeLabels?.length ? { excludeLabels: criteria.excludeLabels } : {}),
543
+ ...(criteria.since !== undefined ? { since: criteria.since } : {}),
544
+ ...(criteria.until !== undefined ? { until: criteria.until } : {}),
507
545
  },
508
546
  page: {
509
547
  limit: page.limit,
@@ -15,11 +15,21 @@ export function normalizeTicket(
15
15
  priority = true,
16
16
  assignees = true,
17
17
  ): Ticket {
18
- const { target, issueLinks: links, priority: level, assignees: assigned, ...rest } = ticket
18
+ const {
19
+ target,
20
+ targetTitle,
21
+ resolvedAt,
22
+ issueLinks: links,
23
+ priority: level,
24
+ assignees: assigned,
25
+ ...rest
26
+ } = ticket
19
27
  return {
20
28
  ...rest,
21
29
  kind: supported ? (ticket.kind ?? 'work') : 'work',
22
30
  ...(supported && target !== undefined ? { target } : {}),
31
+ ...(supported && target !== undefined && targetTitle !== undefined ? { targetTitle } : {}),
32
+ ...(ticket.resolved && resolvedAt !== undefined ? { resolvedAt } : {}),
23
33
  ...(issueLinks && links !== undefined ? { issueLinks: links } : {}),
24
34
  // Normal is the absence of the field, so strict wire schemas never see it.
25
35
  ...(priority && ticketPriority({ priority: level }) !== 'normal' ? { priority: level } : {}),
@@ -69,6 +69,9 @@ export interface Ticket {
69
69
  kind?: TicketKind
70
70
  /** Canonical source-local node ticket id; absent means the baseBranch root. */
71
71
  target?: string
72
+ /** The target node's title when the source answered it in the same read. A
73
+ * listing-time fact, not part of `revision`; present only alongside `target`. */
74
+ targetTitle?: string
72
75
  /** Opaque source version of title, body, labels, state and blockers. */
73
76
  revision: string
74
77
  /** Complete history oldest first when exposed by this read. Absent means
@@ -85,6 +88,10 @@ export interface Ticket {
85
88
  state?: string
86
89
  /** Native completion fact, identical to DependencyState.resolved. */
87
90
  resolved: boolean
91
+ /** ISO-8601 time the ticket entered its completed state, when the source
92
+ * knows it. A listing-time fact, not part of `revision`; present only when
93
+ * `resolved`. */
94
+ resolvedAt?: string
88
95
  labels: string[]
89
96
  /** Listing-time source fact that all declared blockers are resolved. Only
90
97
  * true permits skipping dependency reads; consumers fall back when absent. */
@@ -129,11 +136,25 @@ export interface TicketCriteria {
129
136
  assignee?: string
130
137
  }
131
138
 
139
+ /** `listPage` criteria: the dispatch criteria plus completion filters, which
140
+ * a source honours only when it declares `completionPaging`. */
141
+ export interface TicketPageCriteria extends TicketCriteria {
142
+ /** Omit every ticket carrying any of these labels. */
143
+ excludeLabels?: string[]
144
+ /** Completion range, half-open: `since <= resolvedAt < until`, both
145
+ * ISO-8601. A ticket without `resolvedAt` never matches. Completion criteria
146
+ * require `state`. A native source may refuse a range too broad for its
147
+ * per-request cap with `TicketCompletionRangeTooBroad`. */
148
+ since?: string
149
+ until?: string
150
+ }
151
+
132
152
  export interface TicketPage {
133
153
  limit: number
134
154
  offset?: number
135
- /** Dispatch order or newest filed first; see `TicketSource.listPage`. */
136
- order?: 'oldest' | 'newest'
155
+ /** Dispatch order, newest filed first, or most recently completed first;
156
+ * see `TicketSource.listPage`. */
157
+ order?: 'oldest' | 'newest' | 'completed'
137
158
  }
138
159
 
139
160
  export interface TicketPageListing extends TicketListing {
@@ -444,8 +465,15 @@ export interface TicketSource {
444
465
  * Arguments are nonnegative integers; zero limit returns no tickets with the
445
466
  * full matching total. Diagnostics
446
467
  * and failures match listReady; a failure must not trigger a full-read fallback.
447
- * listReady and listAll remain exhaustive. */
448
- listPage?(criteria: TicketCriteria, page: TicketPage): Promise<TicketPageListing>
468
+ * listReady and listAll remain exhaustive. `completed` (only sent to
469
+ * sources declaring `completionPaging`) puts tickets with `resolvedAt`
470
+ * first, most recent first, ties newest filed first; the rest follow newest
471
+ * filed first. */
472
+ listPage?(criteria: TicketPageCriteria, page: TicketPage): Promise<TicketPageListing>
473
+ /** Opt in only when `listPage` honours `excludeLabels`, `since`, `until`
474
+ * and order `completed`. Callers send them only to sources declaring it;
475
+ * the rest are filtered over the exhaustive `listReady` listing. */
476
+ readonly completionPaging?: boolean
449
477
  /** Optional text search over every lifecycle state (or `query.state`).
450
478
  * A ticket matches when every whitespace-separated term of `query.text`
451
479
  * occurs, case-insensitively, in its title or body (each term may hit either
@@ -1124,18 +1124,30 @@ function redactRuntimeError(error: unknown, env: Record<string, string>): string
1124
1124
  * callers decide which names a guest may see — the build and harvest paths
1125
1125
  * forward `[workspace.config].environmentVariables`, while the operator
1126
1126
  * sandbox passes its credential-free forwarded set only (build-workspace
1127
- * variables never enter a sandbox). */
1127
+ * variables never enter a sandbox).
1128
+ *
1129
+ * `mode` selects the chain. `'install'` provisions a fresh workspace: every
1130
+ * group installs, then preflights. `'repair'` relaunches into an existing
1131
+ * workspace: every group preflights, and a group whose preflight fails installs
1132
+ * in place and preflights again, so a runtime a role change newly selected (or
1133
+ * a changed pin) reaches the workspace at its next launch. Only a failure after
1134
+ * that install fails a repair; a passing preflight is never reinstalled. */
1128
1135
  async function bootstrapRuntimes(
1129
1136
  sandbox: VercelSandboxHandle,
1130
1137
  config: VercelSandboxConfig,
1131
1138
  env: Record<string, string>,
1132
1139
  references: readonly RuntimeReferenceGroup[],
1133
- install: boolean,
1140
+ mode: 'install' | 'repair',
1134
1141
  signal?: AbortSignal,
1135
1142
  opts: {
1136
1143
  /** Bound for each install and preflight; its stage label is replaced by
1137
- * `runtime bootstrap <runtime> <install|preflight>`. */
1144
+ * `runtime bootstrap <runtime> <install|preflight>`. In `'repair'` mode it
1145
+ * bounds only the first preflight. */
1138
1146
  bound?: CommandBound
1147
+ /** Bound for the install and second preflight a `'repair'` runs after a
1148
+ * failed preflight; its stage label is replaced by
1149
+ * `runtime repair <runtime> <install|preflight>`. */
1150
+ repairBound?: CommandBound
1139
1151
  /** Reports `<runtime> install` / `<runtime> preflight` before each. */
1140
1152
  onStage?: (step: string) => void
1141
1153
  } = {},
@@ -1149,26 +1161,55 @@ async function bootstrapRuntimes(
1149
1161
  `runtime ${displayName(group.runtime)} selected by ${group.references.join(', ')} has no provisioning; add [workspace.config.runtimeProvisioning.${tomlKey(group.runtime)}] with install and preflight commands`,
1150
1162
  )
1151
1163
  }
1152
- for (const stage of install ? (['install', 'preflight'] as const) : (['preflight'] as const)) {
1164
+ const selectedBy = group.references.join(', ')
1165
+ const run = async (
1166
+ stage: 'install' | 'preflight',
1167
+ bound: CommandBound | undefined,
1168
+ label: string,
1169
+ ): Promise<void> => {
1153
1170
  const step = `${group.runtime} ${stage}`
1154
1171
  opts.onStage?.(step)
1155
- try {
1156
- await readableCommand(sandbox, {
1157
- cmd: 'sh',
1158
- args: ['-c', provisioning[stage]],
1159
- cwd: VERCEL_WORKSPACE_PATH,
1160
- env,
1161
- ...(signal === undefined ? {} : { signal }),
1162
- ...(opts.bound === undefined
1163
- ? {}
1164
- : { ...opts.bound, stage: `runtime bootstrap ${step}` }),
1165
- })
1166
- } catch (error) {
1167
- if (signal?.aborted) throw error
1168
- throw new Error(
1169
- `runtime ${displayName(group.runtime)} ${stage} failed (selected by ${group.references.join(', ')}); fix workspace.config.runtimeProvisioning.${group.runtime}.${stage}: ${redactRuntimeError(error, env)}`,
1170
- )
1172
+ await readableCommand(sandbox, {
1173
+ cmd: 'sh',
1174
+ args: ['-c', provisioning[stage]],
1175
+ cwd: VERCEL_WORKSPACE_PATH,
1176
+ env,
1177
+ ...(signal === undefined ? {} : { signal }),
1178
+ ...(bound === undefined ? {} : { ...bound, stage: `${label} ${step}` }),
1179
+ })
1180
+ }
1181
+ const failure = (stage: 'install' | 'preflight', qualifier: string, error: unknown): Error =>
1182
+ new Error(
1183
+ `runtime ${displayName(group.runtime)} ${stage} failed${qualifier} (selected by ${selectedBy}); fix workspace.config.runtimeProvisioning.${group.runtime}.${stage}: ${redactRuntimeError(error, env)}`,
1184
+ )
1185
+ if (mode === 'install') {
1186
+ for (const stage of ['install', 'preflight'] as const) {
1187
+ try {
1188
+ await run(stage, opts.bound, 'runtime bootstrap')
1189
+ } catch (error) {
1190
+ if (signal?.aborted) throw error
1191
+ throw failure(stage, '', error)
1192
+ }
1171
1193
  }
1194
+ continue
1195
+ }
1196
+ try {
1197
+ await run('preflight', opts.bound, 'runtime bootstrap')
1198
+ continue
1199
+ } catch (error) {
1200
+ if (signal?.aborted) throw error
1201
+ }
1202
+ try {
1203
+ await run('install', opts.repairBound, 'runtime repair')
1204
+ } catch (error) {
1205
+ if (signal?.aborted) throw error
1206
+ throw failure('install', ' after its preflight failed in an existing workspace', error)
1207
+ }
1208
+ try {
1209
+ await run('preflight', opts.repairBound, 'runtime repair')
1210
+ } catch (error) {
1211
+ if (signal?.aborted) throw error
1212
+ throw failure('preflight', ' after install', error)
1172
1213
  }
1173
1214
  }
1174
1215
  }
@@ -1575,7 +1616,7 @@ export async function validateVercelSandbox(
1575
1616
  options.env,
1576
1617
  ),
1577
1618
  options.runtimeReferences ?? [],
1578
- true,
1619
+ 'install',
1579
1620
  options.signal,
1580
1621
  )
1581
1622
  const setup = await readableCommand(
@@ -2822,7 +2863,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2822
2863
  this.options.config,
2823
2864
  { ...this.guestEnvironment(), AB_TOKEN: scopedToken },
2824
2865
  references,
2825
- true,
2866
+ 'install',
2826
2867
  invocation,
2827
2868
  {
2828
2869
  bound: commandBound(timeouts, timeouts.runtime),
@@ -3258,12 +3299,19 @@ export class VercelSandboxProvider implements WorkspaceProvider {
3258
3299
  )
3259
3300
  }
3260
3301
  }
3302
+ // Every selected runtime preflights before the runner starts. A runtime
3303
+ // whose preflight fails — one a role change newly selected, or a changed
3304
+ // pin — is installed in place and preflighted again, so the change reaches
3305
+ // this existing workspace now instead of failing every relaunch.
3306
+ const repairTimeouts = resolveProvisioningTimeouts(this.options.provisioningTimeouts)
3261
3307
  await bootstrapRuntimes(
3262
3308
  sandbox,
3263
3309
  this.options.config,
3264
3310
  { ...this.guestEnvironment(), AB_TOKEN: scopedToken },
3265
3311
  currentRuntimeReferences(this.options.runtimeReferences),
3266
- false,
3312
+ 'repair',
3313
+ undefined,
3314
+ { repairBound: commandBound(repairTimeouts, repairTimeouts.runtime) },
3267
3315
  )
3268
3316
  this.sessions.set(ref, sandbox)
3269
3317
  const env: Record<string, string> = {
@@ -3534,7 +3582,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
3534
3582
  this.options.config,
3535
3583
  { ...this.guestEnvironment(), AB_TOKEN: scopedToken },
3536
3584
  currentRuntimeReferences(this.options.runtimeReferences),
3537
- true,
3585
+ 'install',
3538
3586
  )
3539
3587
  await commandOrThrow(sandbox, {
3540
3588
  cmd: 'touch',
@@ -3580,12 +3628,17 @@ export class VercelSandboxProvider implements WorkspaceProvider {
3580
3628
  }
3581
3629
  throw error
3582
3630
  }
3631
+ // A reused harvest sandbox installs a newly selected runtime in place,
3632
+ // exactly as a build relaunch does.
3633
+ const repairTimeouts = resolveProvisioningTimeouts(this.options.provisioningTimeouts)
3583
3634
  await bootstrapRuntimes(
3584
3635
  sandbox,
3585
3636
  this.options.config,
3586
3637
  { ...this.guestEnvironment(), AB_TOKEN: scopedToken },
3587
3638
  currentRuntimeReferences(this.options.runtimeReferences),
3588
- false,
3639
+ 'repair',
3640
+ undefined,
3641
+ { repairBound: commandBound(repairTimeouts, repairTimeouts.runtime) },
3589
3642
  )
3590
3643
  this.sessions.set(name, sandbox)
3591
3644
  const sessionId = sandbox.currentSession?.().sessionId