@defrex/autobuild 1.12.0 → 1.13.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 (159) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +435 -160
  3. package/bin/ab-build-runner.ts +8 -0
  4. package/docs/answering-blocked-builds.md +25 -3
  5. package/docs/architecture.md +124 -53
  6. package/docs/cli.md +1 -1
  7. package/docs/configuration.md +110 -15
  8. package/docs/dispatcher.md +19 -8
  9. package/docs/integration-overview.md +1 -1
  10. package/docs/integration-tree.md +12 -9
  11. package/docs/merge-policy.md +7 -2
  12. package/docs/operating.md +5 -3
  13. package/docs/operator-api.md +46 -23
  14. package/docs/operator-surfaces.md +7 -6
  15. package/docs/optimization-nodes.md +7 -6
  16. package/docs/plugin-authoring.md +46 -18
  17. package/docs/remote-store-protocol.md +51 -12
  18. package/docs/remote-ticket-protocol.md +85 -38
  19. package/docs/restacking.md +48 -3
  20. package/docs/setup.md +2 -1
  21. package/docs/ticket-migration.md +2 -2
  22. package/docs/ticket-sources.md +23 -8
  23. package/docs/tickets.md +4 -4
  24. package/docs/troubleshooting.md +17 -2
  25. package/docs/verification.md +3 -1
  26. package/package.json +3 -3
  27. package/packages/core/src/cli/build-control.ts +72 -6
  28. package/packages/core/src/cli/dashboard/actions.ts +4 -0
  29. package/packages/core/src/cli/dashboard/integration-row.ts +43 -19
  30. package/packages/core/src/cli/dashboard/model.ts +14 -8
  31. package/packages/core/src/cli/dashboard/poll.ts +218 -10
  32. package/packages/core/src/cli/dashboard/queue.ts +21 -10
  33. package/packages/core/src/cli/dashboard/row-text.ts +2 -1
  34. package/packages/core/src/cli/dashboard/vocabulary.ts +5 -1
  35. package/packages/core/src/cli/dispatch-frontend.ts +2 -1
  36. package/packages/core/src/cli/dispatch-tickets.ts +33 -12
  37. package/packages/core/src/cli/dispatch.ts +527 -144
  38. package/packages/core/src/cli/help.ts +38 -24
  39. package/packages/core/src/cli/main.ts +7 -5
  40. package/packages/core/src/cli/publication-settlement.ts +4 -0
  41. package/packages/core/src/cli/remote-poll.ts +22 -5
  42. package/packages/core/src/cli/repository-status.ts +19 -9
  43. package/packages/core/src/cli/status.ts +23 -11
  44. package/packages/core/src/cli/store-opening.ts +12 -0
  45. package/packages/core/src/cli/ticket-start.ts +3 -3
  46. package/packages/core/src/cli/ticket.ts +12 -11
  47. package/packages/core/src/cli/wait.ts +8 -28
  48. package/packages/core/src/cli/watch.ts +113 -50
  49. package/packages/core/src/config/reference-metadata.ts +7 -1
  50. package/packages/core/src/config/reference.ts +5 -2
  51. package/packages/core/src/config/schema.ts +51 -16
  52. package/packages/core/src/events/payloads.ts +74 -14
  53. package/packages/core/src/events/repository.ts +14 -3
  54. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +27 -0
  55. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/0a10010ee5cf2e47.json +577 -0
  56. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/227701361be6d1e0.json +490 -0
  57. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/76e5043bae7a80ab.json +86 -0
  58. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/87a917802870bbed.json +87 -0
  59. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9d85616e5b9e24c1.json +500 -0
  60. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c7c94fbe7f63cf07.json +84 -0
  61. package/packages/core/src/kernel/clean-restack-policy.ts +40 -0
  62. package/packages/core/src/kernel/dispatch-capacity.ts +243 -107
  63. package/packages/core/src/kernel/done-escalations.ts +269 -0
  64. package/packages/core/src/kernel/engine.ts +28 -9
  65. package/packages/core/src/kernel/integration-landing.ts +24 -4
  66. package/packages/core/src/kernel/integration-stack.ts +39 -0
  67. package/packages/core/src/kernel/janitor-failure.ts +20 -1
  68. package/packages/core/src/kernel/log-index-value.ts +3 -0
  69. package/packages/core/src/kernel/log-index.ts +41 -2
  70. package/packages/core/src/kernel/open-pr-backpressure.ts +3 -3
  71. package/packages/core/src/kernel/reducer-registry.ts +3 -0
  72. package/packages/core/src/kernel/reducer-revisions.ts +15 -0
  73. package/packages/core/src/kernel/reducer.ts +27 -7
  74. package/packages/core/src/kernel/repository-attention.ts +14 -5
  75. package/packages/core/src/kernel/ticket-starts.ts +15 -4
  76. package/packages/core/src/kernel/verify-stages.ts +46 -7
  77. package/packages/core/src/operator/attention.ts +28 -3
  78. package/packages/core/src/operator/done-escalations.ts +38 -0
  79. package/packages/core/src/operator/presentation.ts +1 -1
  80. package/packages/core/src/operator/protocol.ts +8 -5
  81. package/packages/core/src/operator/query.ts +33 -19
  82. package/packages/core/src/operator/registry.ts +17 -13
  83. package/packages/core/src/operator/ticket-start.ts +8 -7
  84. package/packages/core/src/operator/tickets.ts +28 -9
  85. package/packages/core/src/plugin-sdk/index.ts +10 -0
  86. package/packages/core/src/plugins/manifest.ts +14 -1
  87. package/packages/core/src/ports/forge/create.ts +8 -0
  88. package/packages/core/src/ports/forge/github-transport.ts +5 -1
  89. package/packages/core/src/ports/forge/github.ts +3 -0
  90. package/packages/core/src/ports/tickets/contract.ts +147 -76
  91. package/packages/core/src/ports/tickets/create.ts +47 -7
  92. package/packages/core/src/ports/tickets/fake.ts +8 -4
  93. package/packages/core/src/ports/tickets/file-codec.ts +4 -3
  94. package/packages/core/src/ports/tickets/file.ts +7 -3
  95. package/packages/core/src/ports/tickets/github.ts +1 -0
  96. package/packages/core/src/ports/tickets/grants.ts +11 -3
  97. package/packages/core/src/ports/tickets/hosted-index.ts +5 -0
  98. package/packages/core/src/ports/tickets/linear.ts +28 -9
  99. package/packages/core/src/ports/tickets/migration.ts +4 -4
  100. package/packages/core/src/ports/tickets/operations.ts +4 -2
  101. package/packages/core/src/ports/tickets/priority-labels.ts +213 -0
  102. package/packages/core/src/ports/tickets/priority.ts +127 -21
  103. package/packages/core/src/ports/tickets/remote-protocol.ts +10 -0
  104. package/packages/core/src/ports/tickets/remote.ts +104 -11
  105. package/packages/core/src/ports/tickets/revision.ts +5 -3
  106. package/packages/core/src/ports/tickets/search.ts +9 -0
  107. package/packages/core/src/ports/tickets/tree.ts +8 -6
  108. package/packages/core/src/ports/types.ts +30 -15
  109. package/packages/core/src/ports/workspace/build-execution.ts +4 -0
  110. package/packages/core/src/ports/workspace/builtin-capabilities.ts +4 -0
  111. package/packages/core/src/ports/workspace/create.ts +16 -3
  112. package/packages/core/src/ports/workspace/execution-exit-marker.ts +41 -0
  113. package/packages/core/src/ports/workspace/recovery-step.ts +101 -0
  114. package/packages/core/src/ports/workspace/vercel-sandbox.ts +510 -145
  115. package/packages/core/src/processes/build-execution-state.ts +4 -0
  116. package/packages/core/src/processes/build-runner.ts +14 -1
  117. package/packages/core/src/processes/dispatcher.ts +544 -212
  118. package/packages/core/src/processes/execution-settlement.ts +1 -0
  119. package/packages/core/src/processes/harvest-runner.ts +12 -7
  120. package/packages/core/src/processes/infrastructure-failure-budget.ts +7 -2
  121. package/packages/core/src/processes/invocation-budget.ts +176 -0
  122. package/packages/core/src/processes/publication-loss.ts +38 -3
  123. package/packages/core/src/processes/workspace-preservation.ts +86 -15
  124. package/packages/core/src/store/contract.ts +81 -3
  125. package/packages/core/src/store/event-reads.ts +30 -1
  126. package/packages/core/src/store/reduced-reads.ts +23 -0
  127. package/packages/core/src/store/reducer-value-shapes.json +6628 -6469
  128. package/packages/core/src/store/reducer-value-validation.ts +181 -33
  129. package/packages/core/src/store/remote/client.ts +169 -29
  130. package/packages/core/src/store/remote/compatibility.ts +113 -56
  131. package/packages/core/src/store/remote/credentials.ts +4 -1
  132. package/packages/core/src/store/remote/protocol.ts +3 -0
  133. package/packages/core/src/store/remote/released-clients.json +11 -0
  134. package/packages/core/src/store/remote/released-reducer-values/1.13.0.json +35966 -0
  135. package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
  136. package/packages/core/src/store/remote/released-value-policy.ts +144 -0
  137. package/packages/core/src/store/remote/retry.ts +406 -0
  138. package/packages/core/src/testing/dispatch-read-budget.ts +144 -10
  139. package/packages/core/src/testing/index.ts +2 -0
  140. package/packages/core/src/testing/invocation-budget.ts +42 -0
  141. package/packages/core/src/testing/reduced-read-budget.ts +381 -18
  142. package/packages/core/src/testing/released-value-coverage.ts +423 -0
  143. package/packages/core/src/web/overview-source.ts +19 -6
  144. package/skills/guide/SKILL.md +138 -67
  145. package/skills/guide/references/integration-tree.md +12 -9
  146. package/skills/guide/references/merge-policy.md +7 -2
  147. package/skills/guide/references/operator-api.md +46 -23
  148. package/skills/guide/references/optimization-nodes.md +7 -6
  149. package/skills/guide/references/plugin-authoring.md +46 -18
  150. package/skills/guide/references/remote-store-protocol.md +51 -12
  151. package/skills/guide/references/remote-ticket-protocol.md +85 -38
  152. package/skills/guide/references/restacking.md +48 -3
  153. package/skills/guide/references/setup.md +2 -1
  154. package/skills/guide/references/ticket-migration.md +2 -2
  155. package/skills/operate/SKILL.md +82 -51
  156. package/skills/plan/SKILL.md +4 -3
  157. package/skills/spec/SKILL.md +9 -5
  158. package/skills/tickets/SKILL.md +25 -17
  159. package/templates/hosted-service/package.json +2 -2
@@ -10,7 +10,11 @@ import { getOperatorTicketTree } from './tickets'
10
10
  import { openOperatorTickets, operatorControlTickets } from './tickets'
11
11
  import { TicketRevisionConflict, TicketRevisionUnsupported } from '../ports/tickets/revision'
12
12
  import { TicketIssueLinksUnsupported } from '../ports/tickets/issue-links'
13
- import { TicketPriorityUnsupported, ticketPrioritySchema } from '../ports/tickets/priority'
13
+ import {
14
+ buildPrioritySchema,
15
+ START_TIERS,
16
+ TicketPriorityUnsupported,
17
+ } from '../ports/tickets/priority'
14
18
  import { TicketAssigneesUnsupported } from '../ports/tickets/assignees'
15
19
  /**
16
20
  * The agent tool registry — one typed table that is the single source of
@@ -504,10 +508,10 @@ const buildControlInput = z.strictObject({
504
508
  .describe(
505
509
  'Control to request: "pause" (or "cancel-pause" to revoke a pending pause), "resume" a paused build, "merge" (deprecated alias "land") for merge consent or "hold" to withdraw consent, "priority" to set the build\'s slot-admission priority — or the destructive "abort" (cancels the build, cleans up its PR and workspace, hands the ticket back to triage, or to ready with `to`) and "discard" (dequeue a queued build).',
506
510
  ),
507
- priority: ticketPrioritySchema
511
+ priority: buildPrioritySchema
508
512
  .optional()
509
513
  .describe(
510
- 'Required with, and only valid with, "priority": "urgent" admits the build to free slots ahead of normal parked work and normal ticket claims; "normal" returns it to normal order. Running work is never preempted and the ticket is unchanged.',
514
+ 'Required with, and only valid with, "priority": the build\'s level, "urgent", "high", "normal" or "low". Free slots go to each level\'s parked work and then its ticket claims, urgent first and low last. Running work is never preempted and the ticket is unchanged.',
511
515
  ),
512
516
  to: abortDestinationSchema
513
517
  .optional()
@@ -616,7 +620,7 @@ const ticketsListInput = z.strictObject({
616
620
  .enum(['oldest', 'newest'])
617
621
  .optional()
618
622
  .describe(
619
- 'Dispatch order, urgent tickets first and then the source order (the default), or newest filed first regardless of urgency.',
623
+ 'Priority order, urgent then high then normal then low tickets, each in the source order (the default), or newest filed first regardless of priority.',
620
624
  ),
621
625
  })
622
626
 
@@ -679,10 +683,10 @@ const ticketsStartInput = z.strictObject({
679
683
  repo: repoField,
680
684
  id: ticketIdField,
681
685
  priority: z
682
- .enum(['manual', 'urgent', 'normal'])
686
+ .enum(START_TIERS)
683
687
  .optional()
684
688
  .describe(
685
- 'Slot-admission tier for the request (default "manual"): manual goes ahead of all waiting work; urgent waits for urgent parked work; normal waits for normal parked work and urgent claims. Not allowed with cancel.',
689
+ 'Slot-admission tier for the request (default "manual"): manual goes ahead of all waiting work; urgent, high, normal or low waits for parked work at that level or above and for the start requests and ticket claims of every higher level, and goes ahead of that level\'s ready tickets. Not allowed with cancel.',
686
690
  ),
687
691
  cancel: z
688
692
  .boolean()
@@ -867,7 +871,7 @@ export const TOOLS: readonly ToolEntry[] = [
867
871
  'builds.list',
868
872
  'List one repository’s builds, newest first, with effective status derived from the build log.',
869
873
  buildListInput,
870
- 'JSON array of build summaries: slug, ticket ref, effective status, phase/round/attempt, PR number/url/state, updatedAt, lease health, durable-event progress, any ticket wait (`wait` with its state and tickets; `waitOnly` when the wait is the only open escalation), an optimization node’s objective progress (`objective`), and each nonterminal build’s slot state (`slot`: `{state: "held"}`, `{state: "requested", request, priority?: "urgent"}` or `{state: "none"}`; absent means unknown, never none).',
874
+ 'JSON array of build summaries: slug, ticket ref, effective status, phase/round/attempt, PR number/url/state, updatedAt, lease health, durable-event progress, any ticket wait (`wait` with its state and tickets; `waitOnly` when the wait is the only open escalation), an optimization node’s objective progress (`objective`), and each nonterminal build’s slot state (`slot`: `{state: "held"}`, `{state: "requested", request, priority?: "urgent" | "high" | "low"}` or `{state: "none"}`; absent means unknown, never none).',
871
875
  async (raw, ctx) => {
872
876
  const input = raw as z.infer<typeof buildListInput>
873
877
  return listOperatorBuilds({
@@ -996,7 +1000,7 @@ export const TOOLS: readonly ToolEntry[] = [
996
1000
  ),
997
1001
  defineTool(
998
1002
  'builds.control',
999
- "Pause immediately suspends a live agent session. Resume continues where stopped when supported; remote and unsupported sessions rerun fresh. Request a durable control for one active build: pause/cancel-pause, resume, hold or merge — or the destructive abort and discard. Merge requires a ready candidate, and an optional head binds consent to the reviewed head; hold withdraws merge consent, with an optional reason. Priority sets the build's slot-admission priority (urgent or normal) to expedite waiting work without aborting it.",
1003
+ "Pause immediately suspends a live agent session. Resume continues where stopped when supported; remote and unsupported sessions rerun fresh. Request a durable control for one active build: pause/cancel-pause, resume, hold or merge — or the destructive abort and discard. Merge requires a ready candidate, and an optional head binds consent to the reviewed head; hold withdraws merge consent, with an optional reason. Priority sets the build's slot-admission level (urgent, high, normal or low) to expedite or defer waiting work without aborting it.",
1000
1004
  buildControlInput,
1001
1005
  'Either {kind: "command", slug, command, event} for an accepted control, or {kind: "answer-required", slug, escalationIds} when a resume needs its open escalations answered first.',
1002
1006
  async (raw, ctx) => {
@@ -1073,9 +1077,9 @@ export const TOOLS: readonly ToolEntry[] = [
1073
1077
  ),
1074
1078
  defineTool(
1075
1079
  'builds.answer',
1076
- 'Answer a blocked build’s open escalations: guidance text, a bare retry, a dismissal of the cited findings, a review-round ceiling, accept-target (answers only a leaf’s target-rewritten escalation: restack its own commits onto the rewritten target), or a spec revision (destructive — replaces the spec). Leaves require an escalation and restart from plan; idle collecting or verification-failed nodes may revise without an escalation and recollect for verification.',
1080
+ 'Answer a blocked build’s open escalations: guidance text, a bare retry, a dismissal of the cited findings, a review-round ceiling, accept-target (answers only a leaf’s target-rewritten escalation: restack its own commits onto the rewritten target), or a spec revision (destructive — replaces the spec). Leaves require an escalation and restart from plan; idle collecting or verification-failed nodes may revise without an escalation and recollect for verification. On a done build it only acknowledges open escalations (guidance or retry), leaving it done; other resolutions are refused.',
1077
1081
  buildsAnswerInput,
1078
- 'The controlBuild answer result: {kind: "answered", slug, count, resolution, resumed, …} describing how many escalations were answered and with what.',
1082
+ 'The controlBuild answer result: {kind: "answered", slug, count, resolution, resumed, …} describing how many escalations were answered and with what; acknowledged: true when a done build’s escalations were only closed.',
1079
1083
  async (raw, ctx) => {
1080
1084
  const input = raw as OperatorAnswerRequest & { repo: string; slug: string }
1081
1085
  await requireRouteBuild(ctx.store, input.repo, input.slug)
@@ -1351,7 +1355,7 @@ export const TOOLS: readonly ToolEntry[] = [
1351
1355
  ),
1352
1356
  defineTool(
1353
1357
  'tickets.create',
1354
- 'Create a ticket in the configured source, optionally labelled (explicit labels are unioned with the [tickets].createLabels default), pre-blocked, linked to the forge issues it addresses, urgent so it dispatches before normal ready work, assigned (explicit assignees replace the [tickets].createAssignee default), or filed in a nondefault state.',
1358
+ 'Create a ticket in the configured source, optionally labelled (explicit labels are unioned with the [tickets].createLabels default), pre-blocked, linked to the forge issues it addresses, at a priority level (ready work dispatches by level: urgent, high, normal, then low), assigned (explicit assignees replace the [tickets].createAssignee default), or filed in a nondefault state.',
1355
1359
  ticketsCreateInput,
1356
1360
  '{ticket, blockers, build}: the created ticket and its (usually empty) dependency states.',
1357
1361
  async (raw, ctx) => {
@@ -1391,7 +1395,7 @@ export const TOOLS: readonly ToolEntry[] = [
1391
1395
  ),
1392
1396
  defineTool(
1393
1397
  'tickets.update',
1394
- 'Partially replace a ticket’s editable fields (title, body, labels, issue links, priority, assignees, kind, target); urgent priority dispatches before normal ready work, and assignees replace the whole set ([] clears). State is never changed here.',
1398
+ 'Partially replace a ticket’s editable fields (title, body, labels, issue links, priority, assignees, kind, target); ready work dispatches by level (urgent, high, normal, then low), "normal" clears the level, and assignees replace the whole set ([] clears). State is never changed here.',
1395
1399
  ticketsUpdateInput,
1396
1400
  '{ticket, blockers, build}: the updated ticket.',
1397
1401
  async (raw, ctx) => {
@@ -1467,7 +1471,7 @@ export const TOOLS: readonly ToolEntry[] = [
1467
1471
  ),
1468
1472
  defineTool(
1469
1473
  'tickets.start',
1470
- "Ask the running dispatcher to start one ticket by id, even while intake is off. Records a durable, attributed request that the dispatcher (local or hosted) honours on its next tick with a free slot in the request's priority tier (manual by default, ahead of all waiting work; or urgent, or normal), claiming no other ticket. The claimed build is urgent when priority is urgent, otherwise it keeps its ticket's priority. Every gate still applies: ready state, spec standard, resolved blockers, no active build, capacity and repository pause. Repeating the request with another priority updates the pending request. With cancel, cancels the pending request instead.",
1474
+ "Ask the running dispatcher to start one ticket by id, even while intake is off. Records a durable, attributed request that the dispatcher (local or hosted) honours on its next tick with a free slot in the request's priority tier (manual by default, ahead of all waiting work; or urgent, high, normal or low, each after that level's parked work and ahead of its ready tickets), claiming no other ticket. The claimed build takes the request's level, or its ticket's level for a manual request. Every gate still applies: ready state, spec standard, resolved blockers, no active build, capacity and repository pause. Repeating the request with another priority updates the pending request. With cancel, cancels the pending request instead.",
1471
1475
  ticketsStartInput,
1472
1476
  'For a request: {status: "pending", existing, updated, request, priority, requestedAt, ticket, event?} — existing is true when a request for the ticket was already pending; updated is true when its priority was changed to this one (event is the update), and false with no event when nothing was written. For cancel: {cancelled: true, request, ticket, event} or {cancelled: false, id} when nothing was pending. The settlement arrives later as a ticket.start-settled repository event (repository.events) and in repository.status ticketStarts.',
1473
1477
  async (raw, ctx) => {
@@ -1,15 +1,16 @@
1
1
  /** Operator single-ticket start requests (AUT-1293): a durable, attributed
2
2
  * request that the running dispatcher claims one named ticket through the
3
3
  * ordinary admission gates on its next tick with a free slot in the request's
4
- * tier (`manual`, `urgent` or `normal`, SPEC §12), independent of intake. The
4
+ * tier (`manual`, `urgent`, `high`, `normal` or `low`, SPEC §12), independent of intake. The
5
5
  * request only canonicalizes the id; the dispatcher decides and settles
6
6
  * eligibility. One invocation costs one source `get`, one reduced-value
7
7
  * read and at most one append, whatever the number of builds. */
8
8
  import { humanActor, type Via } from '../events/envelope'
9
- import type { RepositoryEventEnvelope, TicketStartPriority } from '../events/repository'
9
+ import type { RepositoryEventEnvelope } from '../events/repository'
10
10
  import { ticketStartKey } from '../kernel/ticket-starts'
11
11
  import type { TicketRef } from '../ontology'
12
12
  import { requireTicket } from '../ports/tickets/operations'
13
+ import { startTierFields, startTierOf, type StartTier } from '../ports/tickets/priority'
13
14
  import type { TicketSource } from '../ports/types'
14
15
  import { readRepositoryFacts } from '../store/reduced-reads'
15
16
  import { OperatorControlError } from './control'
@@ -24,7 +25,7 @@ interface TicketStartOptions {
24
25
  user: string
25
26
  via?: Via
26
27
  /** The request's admission tier; `manual` when omitted. */
27
- priority?: TicketStartPriority
28
+ priority?: StartTier
28
29
  }
29
30
 
30
31
  export interface TicketStartRequested {
@@ -36,7 +37,7 @@ export interface TicketStartRequested {
36
37
  updated: boolean
37
38
  /** The pending request's first seq, unchanged by a priority update. */
38
39
  request: number
39
- priority: TicketStartPriority
40
+ priority: StartTier
40
41
  requestedAt: string
41
42
  ticket: TicketRef
42
43
  event?: RepositoryEventEnvelope
@@ -60,7 +61,7 @@ export async function requestTicketStart(opts: TicketStartOptions): Promise<Tick
60
61
  await opts.store.ensureRepo(opts.repo)
61
62
  const facts = (await readRepositoryFacts(opts.store, opts.repo, true)).value
62
63
  const pending = facts.ticketStarts.pending[ticketStartKey(ticket)]
63
- if (pending?.priority === priority)
64
+ if (pending !== undefined && startTierOf(pending) === priority)
64
65
  return {
65
66
  status: 'pending',
66
67
  existing: true,
@@ -73,7 +74,7 @@ export async function requestTicketStart(opts: TicketStartOptions): Promise<Tick
73
74
  const event = await opts.store.appendRepo(opts.repo, {
74
75
  actor: humanActor(opts.user, opts.via),
75
76
  type: 'ticket.start-requested',
76
- payload: { ticket: pending?.ticket ?? ticket, priority },
77
+ payload: { ticket: pending?.ticket ?? ticket, ...startTierFields(priority) },
77
78
  })
78
79
  if (pending !== undefined)
79
80
  return {
@@ -131,7 +132,7 @@ export async function controlTicketStart(opts: {
131
132
  user: string
132
133
  via?: Via
133
134
  cancel?: boolean
134
- priority?: TicketStartPriority
135
+ priority?: StartTier
135
136
  }): Promise<TicketStartRequested | TicketStartCancelled> {
136
137
  if (opts.cancel && opts.priority !== undefined)
137
138
  throw new OperatorControlError(
@@ -5,12 +5,16 @@ import {
5
5
  } from '../kernel/ticket-migrations'
6
6
  import { updateTicketTarget } from '../kernel/node-parent'
7
7
  import { normalizeIssueLinks, type IssueLinkInput } from '../ports/tickets/issue-links'
8
- import { urgentFirst } from '../ports/tickets/priority'
8
+ import { byPriority, namedPriority } from '../ports/tickets/priority'
9
9
  import { creationAssignees } from '../ports/tickets/assignees'
10
10
  import { creationLabels } from '../ports/tickets/labels'
11
11
  import type { IssueLink, TicketSearchPage } from '../ports/types'
12
12
  import { searchTickets } from '../ports/tickets/search'
13
- import { projectTicketTree, compatibleTicketSource } from '../ports/tickets/tree'
13
+ import {
14
+ projectTicketTree,
15
+ compatibleTicketSource,
16
+ type TicketTreeEntry,
17
+ } from '../ports/tickets/tree'
14
18
  import { readBuildFacts } from '../store/reduced-reads'
15
19
  import { samplePinnedAssets, preparePinnedAssets } from '../store/ticket-assets'
16
20
  import type { TicketRef } from '../ontology'
@@ -149,13 +153,15 @@ export async function searchOperatorTickets(opts: {
149
153
  cursor?: string
150
154
  }): Promise<TicketSearchPage> {
151
155
  const { source } = await openOperatorTickets(opts)
152
- return searchTickets(source, {
156
+ const page = await searchTickets(source, {
153
157
  text: opts.query,
154
158
  ...(opts.state !== undefined ? { state: opts.state } : {}),
155
159
  ...(opts.labels !== undefined ? { labels: opts.labels } : {}),
156
160
  ...(opts.limit !== undefined ? { limit: opts.limit } : {}),
157
161
  ...(opts.cursor !== undefined ? { cursor: opts.cursor } : {}),
158
162
  })
163
+ // Operator outputs name every hit's priority, `normal` included.
164
+ return { ...page, tickets: page.tickets.map(namedPriority) }
159
165
  }
160
166
 
161
167
  export async function listOperatorTickets(opts: {
@@ -181,18 +187,21 @@ export async function listOperatorTickets(opts: {
181
187
  nativePage ? source.listPage!(criteria, opts.page!) : source.listReady(criteria),
182
188
  opts.backend.statesFor(context, source),
183
189
  ])
184
- // Native pages arrive ordered; the fallback mirrors the dispatcher's claim
190
+ // Native pages arrive ordered; the fallback matches a native page's priority
185
191
  // order. listReady is in the source's filing order, so reversing it is newest
186
192
  // filed first.
187
193
  const ordered = nativePage
188
194
  ? listing.tickets
189
195
  : opts.page?.order === 'newest'
190
196
  ? [...listing.tickets].reverse()
191
- : urgentFirst(listing.tickets)
197
+ : byPriority(listing.tickets)
192
198
  const offset = opts.page?.offset ?? 0
193
199
  return {
194
200
  states,
195
- tickets: opts.page && !nativePage ? ordered.slice(offset, offset + opts.page.limit) : ordered,
201
+ tickets: (opts.page && !nativePage
202
+ ? ordered.slice(offset, offset + opts.page.limit)
203
+ : ordered
204
+ ).map(namedPriority),
196
205
  diagnostics: listing.diagnostics,
197
206
  criteria,
198
207
  triageState,
@@ -275,7 +284,7 @@ export async function getOperatorTicket(opts: {
275
284
  const ticket = await requireTicket(source, opts.id)
276
285
  const blockers = await source.dependencyStates(ticket.blockedBy ?? [])
277
286
  return {
278
- ticket,
287
+ ticket: namedPriority(ticket),
279
288
  blockers,
280
289
  build: await matchingBuild(
281
290
  opts.store,
@@ -393,7 +402,7 @@ export async function mutateOperatorTicket(opts: {
393
402
  )
394
403
  const blockers = await source.dependencyStates(ticket.blockedBy ?? [])
395
404
  return {
396
- ticket,
405
+ ticket: namedPriority(ticket),
397
406
  blockers,
398
407
  build: await matchingBuild(
399
408
  opts.store,
@@ -459,7 +468,17 @@ export async function readTicketTree(source: TicketSource, root: string) {
459
468
  `${source.name} cannot enumerate all tickets; use a source with listAll support`,
460
469
  )
461
470
  const listing = await source.listAll()
462
- return { ...projectTicketTree(listing.tickets, root), diagnostics: listing.diagnostics }
471
+ const tree = projectTicketTree(listing.tickets, root)
472
+ // Tree outputs name every ticket's priority, `normal` included.
473
+ return { ...tree, children: namedTree(tree.children), diagnostics: listing.diagnostics }
474
+ }
475
+
476
+ function namedTree(entries: TicketTreeEntry[]): TicketTreeEntry[] {
477
+ return entries.map((entry) => ({
478
+ ...entry,
479
+ ticket: namedPriority(entry.ticket),
480
+ children: namedTree(entry.children),
481
+ }))
463
482
  }
464
483
 
465
484
  export async function getOperatorTicketTree(opts: {
@@ -167,7 +167,17 @@ export {
167
167
  refuseUnsupportedPriority,
168
168
  withoutUnsupportedPriority,
169
169
  urgentFirst,
170
+ byPriority,
171
+ dispatchPriority,
172
+ ticketPriority,
173
+ TICKET_PRIORITIES,
170
174
  } from '../ports/tickets/priority'
175
+ export {
176
+ priorityLabelSource,
177
+ priorityLabel,
178
+ PRIORITY_LABEL_PREFIX,
179
+ PRIORITY_LABELS,
180
+ } from '../ports/tickets/priority-labels'
171
181
  export { TicketSearchCursorInvalid, TicketSearchUnsupported } from '../ports/tickets/search'
172
182
  export {
173
183
  TicketAssigneesUnsupported,
@@ -15,7 +15,7 @@ import type {
15
15
  } from '../ports/workspace/provider-capabilities'
16
16
 
17
17
  /** Version of the in-process plugin contract exposed by `@defrex/autobuild/plugin-sdk`. */
18
- export const PLUGIN_API_VERSION = '1.11.0' as const
18
+ export const PLUGIN_API_VERSION = '1.12.0' as const
19
19
 
20
20
  /** Context supplied when a registered adapter or contract fixture is selected. */
21
21
  export interface PluginFactoryContext<Config = Record<string, unknown>> {
@@ -25,6 +25,19 @@ export interface PluginFactoryContext<Config = Record<string, unknown>> {
25
25
  env: Readonly<Record<string, string | undefined>>
26
26
  /** Absolute root of the repository that enabled the plugin. */
27
27
  repoRoot: string
28
+ /** Present when the host provides plugin API ≥ 1.12: the host's fetch. In
29
+ * a bounded dispatcher invocation every request made through it is
30
+ * cancelled at the current phase's deadline, together with any
31
+ * `init.signal` the plugin passes; otherwise it behaves exactly like global
32
+ * `fetch`. Use it for provider HTTP. */
33
+ fetch?: typeof fetch
34
+ /** Present when the host provides plugin API ≥ 1.12: the current phase's
35
+ * cancellation signal, for non-fetch work such as SQL clients,
36
+ * subprocesses, or SDKs with their own transport. Read it at call time,
37
+ * not at construction. `undefined` outside a bounded invocation. An
38
+ * adapter that ignores both fields still works, but its requests are
39
+ * abandoned rather than cancelled at the deadline. */
40
+ invocationSignal?: () => AbortSignal | undefined
28
41
  }
29
42
 
30
43
  export type PluginFactory<
@@ -44,6 +44,11 @@ export async function createForge(opts: {
44
44
  /** Process label for the builtin GitHub forge: refuse requests that would
45
45
  * go out without a credential. Plugins and `local-git` ignore it. */
46
46
  requireCredential?: string
47
+ /** Host fetch for the builtin GitHub forge and the plugin factory
48
+ * context; absent ⇒ global `fetch`. */
49
+ fetchFn?: typeof fetch
50
+ /** Plugin factory context `invocationSignal`; absent ⇒ `() => undefined`. */
51
+ invocationSignal?: () => AbortSignal | undefined
47
52
  }): Promise<Forge> {
48
53
  const registration = resolveForgeRegistration(opts.name, opts.registry)
49
54
  if (registration.owner.kind === 'builtin') {
@@ -56,6 +61,7 @@ export async function createForge(opts: {
56
61
  ...(opts.requireCredential !== undefined
57
62
  ? { requireCredential: opts.requireCredential }
58
63
  : {}),
64
+ ...(opts.fetchFn !== undefined ? { fetchFn: opts.fetchFn } : {}),
59
65
  })
60
66
  }
61
67
  if (opts.name === 'local-git') return new LocalGitForge({ repoRoot: opts.repoRoot })
@@ -74,6 +80,8 @@ export async function createForge(opts: {
74
80
  config: EMPTY_CONFIG,
75
81
  env: opts.env,
76
82
  repoRoot: resolve(opts.repoRoot),
83
+ fetch: opts.fetchFn ?? globalThis.fetch,
84
+ invocationSignal: opts.invocationSignal ?? (() => undefined),
77
85
  })
78
86
  } catch (error) {
79
87
  throw new Error(
@@ -137,8 +137,12 @@ export function createGitHubFetchTransport(opts: {
137
137
  apiBase?: string
138
138
  now?: () => number
139
139
  requireCredential?: string
140
+ /** Request seam; absent ⇒ global `fetch`. A bounded dispatcher invocation
141
+ * passes a fetch that cancels requests at its deadline. */
142
+ fetchFn?: typeof fetch
140
143
  }): GitHubRequest {
141
144
  const source = opts.token
145
+ const fetchFn = opts.fetchFn ?? fetch
142
146
  const now = opts.now ?? Date.now
143
147
  let resolved: Promise<GitHubCredential> | undefined
144
148
  /** When the current answer arrived; `undefined` while one is in flight. */
@@ -211,7 +215,7 @@ export function createGitHubFetchTransport(opts: {
211
215
  headers['Content-Type'] = 'application/json'
212
216
  body = JSON.stringify(request.body)
213
217
  }
214
- const response = await fetch(url, {
218
+ const response = await fetchFn(url, {
215
219
  method,
216
220
  headers,
217
221
  ...(body !== undefined ? { body } : {}),
@@ -1005,6 +1005,8 @@ export class GitHubForge implements Forge {
1005
1005
  * without a credential. Absent, the environment's
1006
1006
  * `AB_GITHUB_REQUIRE_CREDENTIAL` marker decides. */
1007
1007
  requireCredential?: string
1008
+ /** Request seam for the default transport; absent ⇒ global `fetch`. */
1009
+ fetchFn?: typeof fetch
1008
1010
  } = {},
1009
1011
  ) {
1010
1012
  this.now = opts.now ?? Date.now
@@ -1021,6 +1023,7 @@ export class GitHubForge implements Forge {
1021
1023
  createGitHubFetchTransport({
1022
1024
  token: this.token,
1023
1025
  ...(requireCredential !== undefined ? { requireCredential } : {}),
1026
+ ...(opts.fetchFn !== undefined ? { fetchFn: opts.fetchFn } : {}),
1024
1027
  })
1025
1028
  this.transport = async (...args) =>
1026
1029
  guardedForgeRequest(async () => {