@defrex/autobuild 1.4.2 → 1.6.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 (218) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +512 -101
  3. package/bin/ab-dispatch-kernel.ts +1 -0
  4. package/docs/accounts.md +9 -0
  5. package/docs/agent-runtimes.md +1 -0
  6. package/docs/answering-blocked-builds.md +7 -3
  7. package/docs/architecture.md +313 -130
  8. package/docs/assets/headline-wide.png +0 -0
  9. package/docs/build-store.md +33 -3
  10. package/docs/cli.md +2 -1
  11. package/docs/configuration-overview.md +9 -0
  12. package/docs/configuration.md +217 -106
  13. package/docs/dispatcher-hosting.md +19 -3
  14. package/docs/dispatcher.md +11 -6
  15. package/docs/glossary.md +1 -1
  16. package/docs/integration-overview.md +2 -2
  17. package/docs/integration-tree.md +91 -28
  18. package/docs/merge-policy.md +28 -9
  19. package/docs/operating.md +1 -1
  20. package/docs/operator-api.md +57 -20
  21. package/docs/operator-surfaces.md +1 -1
  22. package/docs/plugin-authoring.md +89 -8
  23. package/docs/remote-store-protocol.md +39 -11
  24. package/docs/remote-ticket-protocol.md +126 -12
  25. package/docs/restacking.md +24 -6
  26. package/docs/seams.md +2 -2
  27. package/docs/setup.md +19 -13
  28. package/docs/spec-standard.md +2 -1
  29. package/docs/ticket-dependencies.md +26 -8
  30. package/docs/ticket-migration.md +70 -7
  31. package/docs/ticket-sources.md +82 -5
  32. package/docs/tickets.md +34 -2
  33. package/docs/troubleshooting.md +3 -3
  34. package/docs/verification.md +5 -5
  35. package/docs/website.md +8 -0
  36. package/docs/workspaces.md +1 -1
  37. package/package.json +4 -3
  38. package/packages/core/src/accounts/hosted-readiness.ts +21 -0
  39. package/packages/core/src/cli/attention.ts +3 -0
  40. package/packages/core/src/cli/build-control.ts +36 -12
  41. package/packages/core/src/cli/connect.ts +9 -18
  42. package/packages/core/src/cli/context.ts +44 -0
  43. package/packages/core/src/cli/dashboard/configuration.ts +11 -0
  44. package/packages/core/src/cli/dashboard/model.ts +51 -11
  45. package/packages/core/src/cli/dashboard/poll.ts +14 -0
  46. package/packages/core/src/cli/dashboard/queue.ts +21 -0
  47. package/packages/core/src/cli/dashboard/render.ts +43 -22
  48. package/packages/core/src/cli/dispatch-frontend.ts +63 -30
  49. package/packages/core/src/cli/dispatch-mode.ts +35 -16
  50. package/packages/core/src/cli/dispatch-preflight.ts +4 -1
  51. package/packages/core/src/cli/dispatch-repository-feed.ts +40 -11
  52. package/packages/core/src/cli/dispatch-tickets.ts +47 -0
  53. package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
  54. package/packages/core/src/cli/dispatch.ts +522 -145
  55. package/packages/core/src/cli/help.ts +63 -24
  56. package/packages/core/src/cli/init-hosted-accounts.ts +54 -0
  57. package/packages/core/src/cli/init-readiness-remote.ts +16 -3
  58. package/packages/core/src/cli/init-validation.ts +144 -42
  59. package/packages/core/src/cli/issue-links.ts +67 -0
  60. package/packages/core/src/cli/main.ts +32 -15
  61. package/packages/core/src/cli/pr-summary-publication.ts +38 -7
  62. package/packages/core/src/cli/publication-settlement.ts +36 -24
  63. package/packages/core/src/cli/repo-lease.ts +225 -0
  64. package/packages/core/src/cli/repository-status.ts +203 -49
  65. package/packages/core/src/cli/status.ts +42 -4
  66. package/packages/core/src/cli/terminals.ts +37 -2
  67. package/packages/core/src/cli/ticket-editor.ts +20 -6
  68. package/packages/core/src/cli/ticket.ts +264 -46
  69. package/packages/core/src/cli/triage-count-sampler.ts +59 -0
  70. package/packages/core/src/cli/wait.ts +4 -1
  71. package/packages/core/src/cli/watch.ts +19 -4
  72. package/packages/core/src/config/live.ts +45 -4
  73. package/packages/core/src/config/load.ts +9 -0
  74. package/packages/core/src/config/pipeline-source.ts +6 -2
  75. package/packages/core/src/config/ready-assignee.ts +86 -0
  76. package/packages/core/src/config/schema.ts +202 -38
  77. package/packages/core/src/distribution-packaging.ts +1 -1
  78. package/packages/core/src/events/catalog.ts +7 -0
  79. package/packages/core/src/events/compatibility.ts +2 -1
  80. package/packages/core/src/events/payloads.ts +85 -0
  81. package/packages/core/src/events/policy.ts +10 -0
  82. package/packages/core/src/events/repository.ts +93 -28
  83. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +237 -230
  84. package/packages/core/src/kernel/build-identity.ts +12 -0
  85. package/packages/core/src/kernel/change-presence.ts +139 -6
  86. package/packages/core/src/kernel/dispatch-capacity.ts +189 -19
  87. package/packages/core/src/kernel/dispatch-status.ts +10 -1
  88. package/packages/core/src/kernel/dispatch-upgrade.ts +104 -5
  89. package/packages/core/src/kernel/engine.ts +17 -8
  90. package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -0
  91. package/packages/core/src/kernel/generators/build-log.ts +9 -0
  92. package/packages/core/src/kernel/generators/repository-journals.ts +15 -1
  93. package/packages/core/src/kernel/harvest.ts +4 -1
  94. package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
  95. package/packages/core/src/kernel/integration-completeness.ts +104 -17
  96. package/packages/core/src/kernel/integration-landing.ts +17 -0
  97. package/packages/core/src/kernel/integration-state.ts +17 -0
  98. package/packages/core/src/kernel/issue-keywords.ts +202 -0
  99. package/packages/core/src/kernel/janitor-failure.ts +96 -5
  100. package/packages/core/src/kernel/kernel-git.ts +87 -0
  101. package/packages/core/src/kernel/landing-readiness.ts +25 -17
  102. package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
  103. package/packages/core/src/kernel/log-index.ts +1 -1
  104. package/packages/core/src/kernel/node-issue-links.ts +142 -0
  105. package/packages/core/src/kernel/node-landing.ts +2 -1
  106. package/packages/core/src/kernel/node-parent.ts +6 -0
  107. package/packages/core/src/kernel/node-restack-transaction.ts +2 -0
  108. package/packages/core/src/kernel/pr-summary.ts +24 -0
  109. package/packages/core/src/kernel/read-deferrals.ts +75 -12
  110. package/packages/core/src/kernel/read-facts.ts +32 -1
  111. package/packages/core/src/kernel/reconcile-restack.ts +1 -1
  112. package/packages/core/src/kernel/reducer-registry.ts +37 -2
  113. package/packages/core/src/kernel/reducer.ts +147 -5
  114. package/packages/core/src/kernel/ticket-preparation.ts +16 -0
  115. package/packages/core/src/kernel/verify-budget.ts +43 -0
  116. package/packages/core/src/operator/index.ts +3 -1
  117. package/packages/core/src/operator/presentation.ts +3 -0
  118. package/packages/core/src/operator/protocol.ts +38 -2
  119. package/packages/core/src/operator/query.ts +69 -29
  120. package/packages/core/src/operator/registry.ts +47 -26
  121. package/packages/core/src/operator/tickets.ts +77 -10
  122. package/packages/core/src/plugin-sdk/index.ts +13 -0
  123. package/packages/core/src/plugins/manifest.ts +1 -1
  124. package/packages/core/src/plugins/registry.ts +1 -0
  125. package/packages/core/src/ports/forge/contract.ts +69 -0
  126. package/packages/core/src/ports/forge/create.ts +5 -0
  127. package/packages/core/src/ports/forge/fake.ts +184 -3
  128. package/packages/core/src/ports/forge/git-rewrite.ts +4 -2
  129. package/packages/core/src/ports/forge/github.ts +175 -38
  130. package/packages/core/src/ports/forge/local-git.ts +14 -0
  131. package/packages/core/src/ports/forge/readiness.ts +10 -0
  132. package/packages/core/src/ports/forge-failure.ts +43 -0
  133. package/packages/core/src/ports/runner/claude.ts +7 -1
  134. package/packages/core/src/ports/runner/codex.ts +7 -2
  135. package/packages/core/src/ports/runner/native-cli-fixture.ts +2 -1
  136. package/packages/core/src/ports/runner/pi.ts +7 -1
  137. package/packages/core/src/ports/runner/runtime.ts +3 -0
  138. package/packages/core/src/ports/runner/start-prompt.ts +37 -0
  139. package/packages/core/src/ports/tickets/contract.ts +320 -7
  140. package/packages/core/src/ports/tickets/create.ts +89 -20
  141. package/packages/core/src/ports/tickets/fake.ts +18 -0
  142. package/packages/core/src/ports/tickets/file-codec.ts +20 -0
  143. package/packages/core/src/ports/tickets/file.ts +43 -1
  144. package/packages/core/src/ports/tickets/github-fake.ts +1123 -0
  145. package/packages/core/src/ports/tickets/github-issues.ts +431 -0
  146. package/packages/core/src/ports/tickets/github-validators.ts +194 -0
  147. package/packages/core/src/ports/tickets/github.ts +2029 -0
  148. package/packages/core/src/ports/tickets/hosted-index.ts +34 -3
  149. package/packages/core/src/ports/tickets/issue-links.ts +86 -0
  150. package/packages/core/src/ports/tickets/lifecycle.ts +60 -4
  151. package/packages/core/src/ports/tickets/linear.ts +66 -6
  152. package/packages/core/src/ports/tickets/migration.ts +290 -68
  153. package/packages/core/src/ports/tickets/operations.ts +98 -12
  154. package/packages/core/src/ports/tickets/priority.ts +55 -0
  155. package/packages/core/src/ports/tickets/remote-protocol.ts +195 -29
  156. package/packages/core/src/ports/tickets/remote.ts +188 -13
  157. package/packages/core/src/ports/tickets/revision.ts +22 -1
  158. package/packages/core/src/ports/tickets/states.ts +43 -0
  159. package/packages/core/src/ports/tickets/tree.ts +58 -12
  160. package/packages/core/src/ports/tickets/update.ts +12 -2
  161. package/packages/core/src/ports/types.ts +194 -9
  162. package/packages/core/src/ports/workspace/commit-preservation.ts +163 -25
  163. package/packages/core/src/ports/workspace/git-worktree.ts +6 -2
  164. package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
  165. package/packages/core/src/ports/workspace/vercel-sandbox.ts +121 -27
  166. package/packages/core/src/processes/build-runner.ts +101 -22
  167. package/packages/core/src/processes/dispatcher.ts +1046 -372
  168. package/packages/core/src/processes/execution-no-progress.ts +7 -0
  169. package/packages/core/src/processes/harvest-child.ts +4 -2
  170. package/packages/core/src/processes/harvest-execution-state.ts +104 -0
  171. package/packages/core/src/processes/harvest-runner.ts +263 -25
  172. package/packages/core/src/processes/harvest.ts +5 -8
  173. package/packages/core/src/processes/tick-publication.ts +12 -2
  174. package/packages/core/src/processes/ticket-scan-schedule.ts +78 -0
  175. package/packages/core/src/processes/workspace-preservation.ts +36 -1
  176. package/packages/core/src/runtime-identity.ts +10 -2
  177. package/packages/core/src/scenarios/harness.ts +149 -35
  178. package/packages/core/src/store/adapter.ts +7 -1
  179. package/packages/core/src/store/contract.ts +83 -2
  180. package/packages/core/src/store/digest.ts +32 -1
  181. package/packages/core/src/store/reduced-reads.ts +10 -0
  182. package/packages/core/src/store/reducer-value-shapes.json +4471 -3427
  183. package/packages/core/src/store/remote/protocol.ts +2 -0
  184. package/packages/core/src/store/remote/released-clients.json +22 -0
  185. package/packages/core/src/store/remote/released-reducer-values/1.5.0.json +26924 -0
  186. package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
  187. package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
  188. package/packages/core/src/store/repo-state-events.ts +2 -0
  189. package/packages/core/src/store/types.ts +5 -0
  190. package/packages/core/src/testing/dispatch-read-budget.ts +729 -123
  191. package/packages/core/src/testing/index.ts +18 -1
  192. package/packages/core/src/testing/presence-history.ts +79 -0
  193. package/packages/core/src/testing/reduced-read-budget.ts +1424 -33
  194. package/packages/core/src/testing/upgrade-generations.ts +77 -0
  195. package/skills/code-review/SKILL.md +4 -3
  196. package/skills/finalize/SKILL.md +18 -2
  197. package/skills/guide/SKILL.md +417 -143
  198. package/skills/guide/references/accounts.md +9 -0
  199. package/skills/guide/references/integration-tree.md +91 -28
  200. package/skills/guide/references/merge-policy.md +28 -9
  201. package/skills/guide/references/operator-api.md +57 -20
  202. package/skills/guide/references/plugin-authoring.md +89 -8
  203. package/skills/guide/references/remote-store-protocol.md +39 -11
  204. package/skills/guide/references/remote-ticket-protocol.md +126 -12
  205. package/skills/guide/references/restacking.md +24 -6
  206. package/skills/guide/references/setup.md +19 -13
  207. package/skills/guide/references/spec-standard.md +2 -1
  208. package/skills/guide/references/ticket-dependencies.md +26 -8
  209. package/skills/guide/references/ticket-migration.md +70 -7
  210. package/skills/harvest-review/SKILL.md +4 -3
  211. package/skills/implement/SKILL.md +20 -1
  212. package/skills/operate/SKILL.md +149 -35
  213. package/skills/plan/SKILL.md +1 -1
  214. package/skills/reconcile/SKILL.md +5 -4
  215. package/skills/spec/SKILL.md +15 -2
  216. package/skills/tickets/SKILL.md +116 -37
  217. package/templates/autobuild.toml +5 -0
  218. package/templates/hosted-service/package.json +2 -2
@@ -1,4 +1,19 @@
1
1
  import { z } from 'zod'
2
+ import { issueLinksInputSchema } from '../ports/tickets/issue-links'
3
+ import { TICKET_MOVE_ROLES } from '../ports/tickets/lifecycle'
4
+ import { ticketPrioritySchema } from '../ports/tickets/priority'
5
+
6
+ const issueLinksField = issueLinksInputSchema
7
+ .optional()
8
+ .describe(
9
+ 'Forge issues this ticket addresses: {issue, intent?}; intent "closes" (default) or "refs" for partial work. On update, a complete replacement; [] clears.',
10
+ )
11
+
12
+ const priorityField = ticketPrioritySchema
13
+ .optional()
14
+ .describe(
15
+ 'Dispatch class: "urgent" is claimed before normal ready work (never preempting a running build); "normal" (the default) removes urgency. Sources that cannot store priority refuse urgent.',
16
+ )
2
17
 
3
18
  export const buildListScopeSchema = z.enum(['active', 'queued', 'all'])
4
19
 
@@ -56,6 +71,8 @@ export const ticketCreateRequestSchema = z.strictObject({
56
71
  labels: z.array(z.string()).optional(),
57
72
  state: z.string().min(1).optional(),
58
73
  blockedBy: z.array(z.string().min(1)).optional(),
74
+ issueLinks: issueLinksField,
75
+ priority: priorityField,
59
76
  })
60
77
  const expectedRevisionSchema = z
61
78
  .string()
@@ -69,12 +86,16 @@ export const ticketUpdateRequestSchema = z
69
86
  title: z.string().optional(),
70
87
  body: z.string().optional(),
71
88
  labels: z.array(z.string()).optional(),
89
+ issueLinks: issueLinksField,
90
+ priority: priorityField,
72
91
  })
73
92
  .refine(
74
93
  (value) =>
75
94
  value.title !== undefined ||
76
95
  value.body !== undefined ||
77
96
  value.labels !== undefined ||
97
+ value.issueLinks !== undefined ||
98
+ value.priority !== undefined ||
78
99
  value.kind !== undefined ||
79
100
  value.target !== undefined,
80
101
  'update must name at least one field',
@@ -85,10 +106,25 @@ export const ticketPageSchema = z.strictObject({
85
106
  offset: z.number().int().min(0).optional(),
86
107
  order: z.enum(['oldest', 'newest']).optional(),
87
108
  })
88
- export const ticketMoveRequestSchema = z.strictObject({
109
+ /** The unrefined move shape, so tool inputs can extend it; validate requests
110
+ * with `ticketMoveRequestSchema`, which requires exactly one target. */
111
+ export const ticketMoveRequestShape = z.strictObject({
89
112
  expectedRevision: expectedRevisionSchema,
90
- state: z.string().min(1),
113
+ state: z.string().min(1).optional(),
114
+ role: z
115
+ .enum(TICKET_MOVE_ROLES)
116
+ .optional()
117
+ .describe(
118
+ "Lifecycle role to move the ticket into, resolved through this repository's [tickets] configuration. Destructive for `ready`.",
119
+ ),
91
120
  })
121
+ export const exactlyOneMoveTarget = (value: { state?: string; role?: string }): boolean =>
122
+ (value.state === undefined) !== (value.role === undefined)
123
+ export const MOVE_TARGET_MESSAGE = 'move must name exactly one of state or role'
124
+ export const ticketMoveRequestSchema = ticketMoveRequestShape.refine(
125
+ exactlyOneMoveTarget,
126
+ MOVE_TARGET_MESSAGE,
127
+ )
92
128
  export const ticketBlockerRequestSchema = z.strictObject({
93
129
  expectedRevision: expectedRevisionSchema,
94
130
  blockerIds: z.array(z.string().min(1)).min(1),
@@ -2,7 +2,8 @@ import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
2
2
  import { migrationIdentity } from '../kernel/ticket-migrations'
3
3
  import { enrichDrainingRow, projectHandoffs } from '../cli/dashboard/handoff'
4
4
  import { enrichIntegrationRows } from '../cli/dashboard/integration-row'
5
- import { dispatchCapacity, type CapacityBuild } from '../kernel/dispatch-capacity'
5
+ import { dispatchCapacity, slotRequest, type CapacityBuild } from '../kernel/dispatch-capacity'
6
+ import { landingRestackDue } from '../kernel/engine'
6
7
  import { forgeReadinessWarnings } from '../kernel/dispatch-status'
7
8
  import { readBuildDigests } from '../store/reduced-reads'
8
9
  import {
@@ -43,7 +44,6 @@ import {
43
44
  import type { BuildState } from '../kernel/reducer'
44
45
  import { DISPATCHER_EFFECTIVE_CONFIG_ARTIFACT } from '../store/retention'
45
46
  import { reduceDispatchStatus } from '../kernel/dispatch-status'
46
- import { unclaimedObservationCount } from '../processes/harvest'
47
47
  import type { RepoViewStore } from '../processes/repo-view'
48
48
  import { withOperatorView } from './read-view'
49
49
  import type { RepositoryEvent } from '../events/repository'
@@ -53,7 +53,11 @@ export type BuildListScope = 'active' | 'queued' | 'all'
53
53
 
54
54
  export class OperatorQueryError extends Error {
55
55
  constructor(
56
- readonly code: 'not-found' | 'effective-config-unavailable' | 'external-ticket-source',
56
+ readonly code:
57
+ | 'not-found'
58
+ | 'effective-config-unavailable'
59
+ | 'no-dispatcher-run'
60
+ | 'external-ticket-source',
57
61
  message: string,
58
62
  ) {
59
63
  super(message)
@@ -109,7 +113,25 @@ async function listFromView(
109
113
  // build therefore cannot change the emitted summaries.
110
114
  if (digest.terminal !== undefined) continue
111
115
  }
112
- const projected = summarizeFrom(record, (await view.buildFacts(record.slug)).state, opts.now)
116
+ const facts = await view.buildFacts(record.slug)
117
+ const projected = summarizeFrom(
118
+ record,
119
+ facts.state,
120
+ opts.now,
121
+ slotRequest(
122
+ {
123
+ record,
124
+ state: facts.state,
125
+ workspace: facts.workspace !== null,
126
+ // Leaves rely on the continuation's lease; only nodes read the marker.
127
+ provisioning:
128
+ facts.state.kind === 'node' &&
129
+ (await readBuildFacts(view, record.slug)).value.provisionMarker !== undefined,
130
+ restackDue: landingRestackDue(facts.state, facts.log),
131
+ },
132
+ opts.now,
133
+ ),
134
+ )
113
135
  if (statuses.has(projected.status)) output.push(projected)
114
136
  }
115
137
  return output.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))
@@ -137,11 +159,13 @@ export async function effectiveConfig(
137
159
  }> {
138
160
  const repositoryEvents = journal ?? (await readRepositoryFacts(store, repo)).value
139
161
  const status = repositoryEvents.status
140
- if (status?.effectiveConfig === undefined)
162
+ if (status?.effectiveConfig === undefined) {
163
+ if (repositoryEvents.config.run === undefined) throw noDispatcherRunError(repo)
141
164
  throw new OperatorQueryError(
142
165
  'effective-config-unavailable',
143
- `effective config unavailable for repository "${repo}"${repositoryEvents.config.run === undefined ? ': no dispatcher run is recorded' : ''}`,
166
+ `effective config unavailable for repository "${repo}"`,
144
167
  )
168
+ }
145
169
  const ref = status.effectiveConfig!
146
170
  const artifact = await store.getRepoArtifact(repo, ref.kind, ref.rev)
147
171
  if (artifact === null) {
@@ -157,6 +181,15 @@ export async function effectiveConfig(
157
181
  }
158
182
  }
159
183
 
184
+ /** No `dispatcher.run-started` is recorded: pipeline configuration is not
185
+ * merely unreadable, it has never existed. */
186
+ export function noDispatcherRunError(repo: string): OperatorQueryError {
187
+ return new OperatorQueryError(
188
+ 'no-dispatcher-run',
189
+ `effective config unavailable for repository "${repo}": no dispatcher run is recorded`,
190
+ )
191
+ }
192
+
160
193
  function latestDispatchConfigStatus(repositoryEvents: RepositoryEvent[]) {
161
194
  let latestRun: string | undefined
162
195
  for (const event of repositoryEvents) {
@@ -172,12 +205,7 @@ export function findEffectiveConfigRef(repositoryEvents: RepositoryEvent[]) {
172
205
 
173
206
  export function selectEffectiveConfig(repositoryEvents: RepositoryEvent[], repo: string) {
174
207
  const status = latestDispatchConfigStatus(repositoryEvents)
175
- if (status === undefined) {
176
- throw new OperatorQueryError(
177
- 'effective-config-unavailable',
178
- `effective config unavailable for repository "${repo}": no dispatcher run is recorded`,
179
- )
180
- }
208
+ if (status === undefined) throw noDispatcherRunError(repo)
181
209
  if (status.effectiveConfig === undefined) {
182
210
  throw new OperatorQueryError(
183
211
  'effective-config-unavailable',
@@ -368,16 +396,16 @@ async function dashboardFromView(
368
396
  view: RepoViewStore,
369
397
  opts: { repo: string; clock: Clock },
370
398
  ): Promise<OperatorDashboardSnapshot> {
371
- const { config, repositoryEvents, status } = await effectiveConfig(
372
- view,
373
- opts.repo,
374
- view.repositoryFacts(),
375
- )
399
+ const facts = view.repositoryFacts()
400
+ // Only the absence of any run is an empty state; a run whose configuration
401
+ // is missing or unreadable still fails below. This branch reads nothing
402
+ // more: no build can exist before a dispatcher claims one.
403
+ if (facts.config.run === undefined) return noDispatcherRunSnapshot(opts.repo, facts, opts.clock)
404
+ const { config, repositoryEvents, status } = await effectiveConfig(view, opts.repo, facts)
376
405
  const records = await view.listBuilds()
377
406
  // One digest read covers every build of the repository (AUT-487): the
378
- // row gate (a `done` digest means no row) and the observation count need no
379
- // per-build histories, so the snapshot's traffic stays flat as finished
380
- // builds accumulate. Row-rendering builds derive from the repository view's
407
+ // row gate (a `done` digest means no row) needs no per-build histories, so
408
+ // the snapshot's traffic stays flat as finished builds accumulate. Row-rendering builds derive from the repository view's
381
409
  // reducer snapshots plus a delta read (AUT-650); every snapshot is a cache
382
410
  // the event log regenerates, so the response equals a full replay's.
383
411
  const digests = await readBuildDigests(view, opts.repo)
@@ -413,6 +441,7 @@ async function dashboardFromView(
413
441
  provisioning:
414
442
  facts.state.kind === 'node' &&
415
443
  (await readBuildFacts(view, record.slug)).value.provisionMarker !== undefined,
444
+ restackDue: landingRestackDue(facts.state, facts.log),
416
445
  })
417
446
  if (projectsNoDashboardRow(facts.state)) continue
418
447
  const pinned = await readPinnedConfig(view, record.slug, config, facts.state.verify.configPin)
@@ -426,14 +455,8 @@ async function dashboardFromView(
426
455
  )
427
456
  if (row !== null) projected.push(decorateWithPinnedMeta(row, pinned))
428
457
  }
429
- // The unclaimed-observation count comes from the digests and the journal
430
- // `effectiveConfig` already returned — no per-build history reads (AUT-487).
431
458
  // The pure core writes nothing — a snapshot performs no store writes and
432
459
  // never creates or locks the repository record.
433
- const observationCount = unclaimedObservationCount({
434
- digests,
435
- harvestEvents: repositoryEvents.harvest,
436
- })
437
460
  const warningLines = [
438
461
  ...status.roleWarnings,
439
462
  ...forgeReadinessWarnings(status),
@@ -453,8 +476,7 @@ async function dashboardFromView(
453
476
  activeCount: capacityProjection.occupied,
454
477
  capacityProjection,
455
478
  capacity: config.capacity,
456
- observationCount,
457
- observationLimit: config.policy.harvestThreshold,
479
+ ...(status.triage !== undefined ? { triage: status.triage } : {}),
458
480
  ...(status.availableUpgrade !== undefined
459
481
  ? { availableUpgrade: status.availableUpgrade }
460
482
  : {}),
@@ -462,8 +484,26 @@ async function dashboardFromView(
462
484
  },
463
485
  repositoryEvents,
464
486
  )
487
+ return dashboardSnapshot(model, opts.clock)
488
+ }
489
+
490
+ /** The dashboard of a repository with no recorded dispatcher run: repository
491
+ * controls reduce from the journal, pipeline configuration is unknown. */
492
+ function noDispatcherRunSnapshot(
493
+ repo: string,
494
+ facts: RepositoryReadFacts,
495
+ clock: Clock,
496
+ ): OperatorDashboardSnapshot {
497
+ const model: DashboardModel = {
498
+ ...buildDashboardFromProjected([], { repo, queued: 0, activeCount: 0, capacity: 0 }, facts),
499
+ configuration: 'no-dispatcher-run',
500
+ }
501
+ return dashboardSnapshot(model, clock)
502
+ }
503
+
504
+ function dashboardSnapshot(model: DashboardModel, clock: Clock): OperatorDashboardSnapshot {
465
505
  return {
466
- generatedAt: opts.clock().toISOString(),
506
+ generatedAt: clock().toISOString(),
467
507
  model,
468
508
  settingsHeader: {
469
509
  intake: !model.drained,
@@ -2,8 +2,10 @@ import { readBuildPage } from '../store/event-reads'
2
2
  import { requestNodeRestack } from './restack'
3
3
  import { listOperatorLandings } from './landings'
4
4
  import { getOperatorTicketTree } from './tickets'
5
- import { openOperatorTickets } from './tickets'
5
+ import { openOperatorTickets, operatorControlTickets } from './tickets'
6
6
  import { TicketRevisionConflict, TicketRevisionUnsupported } from '../ports/tickets/revision'
7
+ import { TicketIssueLinksUnsupported } from '../ports/tickets/issue-links'
8
+ import { TicketPriorityUnsupported } from '../ports/tickets/priority'
7
9
  /**
8
10
  * The agent tool registry — one typed table that is the single source of
9
11
  * truth for the agent-facing operator surface (AUT-338).
@@ -21,7 +23,7 @@ import { TicketRevisionConflict, TicketRevisionUnsupported } from '../ports/tick
21
23
  * carried as base64 strings at the entry level (`builds.artifact`'s
22
24
  * `contentBase64` is the base64 of the exact artifact bytes), so a binding's
23
25
  * `JSON.stringify` can never silently corrupt bytes. The contract suite
24
- * (packages/hosted-store-service/src/registry.contract.test.ts) asserts the
26
+ * (packages/hosted-store-service/src/registry.contract.integration.test.ts) asserts the
25
27
  * round-trip for every tool.
26
28
  *
27
29
  * Risk classes live in `operator/annotations.ts` (checked in, enforced by the
@@ -56,7 +58,9 @@ import {
56
58
  harvestControlRequestSchema,
57
59
  ticketBlockerRequestSchema,
58
60
  ticketCreateRequestSchema,
59
- ticketMoveRequestSchema,
61
+ exactlyOneMoveTarget,
62
+ MOVE_TARGET_MESSAGE,
63
+ ticketMoveRequestShape,
60
64
  ticketUpdateRequestSchema,
61
65
  type OperatorAnswerRequest,
62
66
  } from './protocol'
@@ -325,7 +329,9 @@ const ticketsListInput = z.strictObject({
325
329
  order: z
326
330
  .enum(['oldest', 'newest'])
327
331
  .optional()
328
- .describe('Oldest first (the source order, the default) or newest first.'),
332
+ .describe(
333
+ 'Dispatch order, urgent tickets first and then the source order (the default), or newest filed first.',
334
+ ),
329
335
  })
330
336
 
331
337
  const ticketsCreateInput = ticketCreateRequestSchema.extend({ repo: repoField })
@@ -337,6 +343,8 @@ const ticketsUpdateInput = ticketUpdateRequestSchema
337
343
  value.title !== undefined ||
338
344
  value.body !== undefined ||
339
345
  value.labels !== undefined ||
346
+ value.issueLinks !== undefined ||
347
+ value.priority !== undefined ||
340
348
  value.kind !== undefined ||
341
349
  value.target !== undefined,
342
350
  'update must name at least one field',
@@ -353,16 +361,19 @@ const ticketsBlockersInput = ticketBlockerRequestSchema.extend({
353
361
  ),
354
362
  })
355
363
 
356
- const ticketsMoveInput = ticketMoveRequestSchema.extend({
357
- repo: repoField,
358
- id: ticketIdField,
359
- state: z
360
- .string()
361
- .min(1)
362
- .describe(
363
- 'Provider state to move the ticket into. Destructive: moving a ticket into the repository’s configured ready state queues it for dispatch.',
364
- ),
365
- })
364
+ const ticketsMoveInput = ticketMoveRequestShape
365
+ .extend({
366
+ repo: repoField,
367
+ id: ticketIdField,
368
+ state: z
369
+ .string()
370
+ .min(1)
371
+ .optional()
372
+ .describe(
373
+ 'Provider state to move the ticket into; give this or `role`, not both. Destructive: moving a ticket into the repository’s configured ready state queues it for dispatch.',
374
+ ),
375
+ })
376
+ .refine(exactlyOneMoveTarget, MOVE_TARGET_MESSAGE)
366
377
 
367
378
  const notesReadInput = z.strictObject({ repo: repoField })
368
379
 
@@ -625,12 +636,7 @@ export const TOOLS: readonly ToolEntry[] = [
625
636
  : { kind: input.action }
626
637
  return controlBuild({
627
638
  store: ctx.store,
628
- ticketSource: async () => {
629
- if (!ctx.tickets) throw new Error('ticket source unavailable')
630
- return (
631
- await openOperatorTickets({ store: ctx.store, repo: input.repo, backend: ctx.tickets })
632
- ).source
633
- },
639
+ ...operatorControlTickets({ store: ctx.store, repo: input.repo, backend: ctx.tickets }),
634
640
  repo: input.repo,
635
641
  slug: input.slug,
636
642
  user: attributed(ctx),
@@ -694,7 +700,7 @@ export const TOOLS: readonly ToolEntry[] = [
694
700
  'repository.status',
695
701
  'Report one repository’s durable dispatcher settings and journal state.',
696
702
  repositoryStatusInput,
697
- 'The repository status projection: ticket intake, repository-wide pause, claim-time auto-merge default, and the harvest/dispatch journal state the sessionless CLI and dashboard read.',
703
+ 'The repository status projection: ticket intake, repository-wide pause, claim-time auto-merge default, and the harvest/dispatch journal state the sessionless CLI and dashboard read. operator.presence is "unavailable" here because this tool does not load presence registrations; that is not evidence that no operator is present.',
698
704
  async (raw, ctx) => {
699
705
  const input = raw as z.infer<typeof repositoryStatusInput>
700
706
  return getRepositoryStatus(ctx.store, input.repo)
@@ -730,7 +736,7 @@ export const TOOLS: readonly ToolEntry[] = [
730
736
  'repository.bulk_control',
731
737
  'Pause or resume the whole repository: hold queued builds, set intake, and request per-build pause/resume in one walk.',
732
738
  bulkControlInput,
733
- '{direction, slugs, paused, intake}: the direction, the slugs that received a durable request, and the repository-wide hold/intake values written. A partial walk surfaces as a refusal with code "bulk-partial" and a progress object naming what merged.',
739
+ '{direction, slugs, paused, intake}: the direction, the slugs that received a durable request, and the repository-wide hold/intake values written. A partial walk surfaces as a refusal with code "bulk-partial" and a progress object naming which writes were recorded before the walk stopped.',
734
740
  async (raw, ctx) => {
735
741
  const input = raw as z.infer<typeof bulkControlInput>
736
742
  return bulkControlRepository({
@@ -845,12 +851,13 @@ export const TOOLS: readonly ToolEntry[] = [
845
851
  ),
846
852
  defineTool(
847
853
  'tickets.create',
848
- 'Create a ticket in the configured source, optionally labelled, pre-blocked, or filed in a nondefault state.',
854
+ 'Create a ticket in the configured source, optionally labelled, pre-blocked, linked to the forge issues it addresses, urgent so it dispatches before normal ready work, or filed in a nondefault state.',
849
855
  ticketsCreateInput,
850
856
  '{ticket, blockers, build}: the created ticket and its (usually empty) dependency states.',
851
857
  async (raw, ctx) => {
852
858
  const input = raw as z.infer<typeof ticketsCreateInput>
853
- const { repo, title, body, labels, state, blockedBy, kind, target } = input
859
+ const { repo, title, body, labels, state, blockedBy, issueLinks, priority, kind, target } =
860
+ input
854
861
  return mutateOperatorTicket({
855
862
  store: ctx.store,
856
863
  repo,
@@ -864,13 +871,15 @@ export const TOOLS: readonly ToolEntry[] = [
864
871
  ...(labels !== undefined ? { labels } : {}),
865
872
  ...(state !== undefined ? { state } : {}),
866
873
  ...(blockedBy !== undefined ? { blockedBy } : {}),
874
+ ...(issueLinks !== undefined ? { issueLinks } : {}),
875
+ ...(priority !== undefined ? { priority } : {}),
867
876
  },
868
877
  })
869
878
  },
870
879
  ),
871
880
  defineTool(
872
881
  'tickets.update',
873
- 'Partially replace a ticket’s editable fields (title, body, labels, kind, target); state is never changed here.',
882
+ 'Partially replace a ticket’s editable fields (title, body, labels, issue links, priority, kind, target); urgent priority dispatches before normal ready work. State is never changed here.',
874
883
  ticketsUpdateInput,
875
884
  '{ticket, blockers, build}: the updated ticket.',
876
885
  async (raw, ctx) => {
@@ -938,7 +947,7 @@ export const TOOLS: readonly ToolEntry[] = [
938
947
  operation: {
939
948
  kind: 'move',
940
949
  id: input.id,
941
- state: input.state,
950
+ ...(input.role !== undefined ? { role: input.role } : { state: input.state! }),
942
951
  expectedRevision: input.expectedRevision,
943
952
  },
944
953
  })
@@ -1106,6 +1115,18 @@ function mapDomainError(error: unknown): RegistryError {
1106
1115
  return new RegistryError('domain', error.message, { kind: 'conflict', error: error.message })
1107
1116
  if (error instanceof TicketRevisionUnsupported)
1108
1117
  return new RegistryError('domain', error.message, { kind: 'refusal', error: error.message })
1118
+ if (error instanceof TicketIssueLinksUnsupported)
1119
+ return new RegistryError('domain', error.message, {
1120
+ kind: 'refusal',
1121
+ error: error.message,
1122
+ code: 'issue-links-unsupported',
1123
+ })
1124
+ if (error instanceof TicketPriorityUnsupported)
1125
+ return new RegistryError('domain', error.message, {
1126
+ kind: 'refusal',
1127
+ error: error.message,
1128
+ code: 'priority-unsupported',
1129
+ })
1109
1130
  if (error instanceof TicketOperationError) {
1110
1131
  return new RegistryError('domain', error.message, {
1111
1132
  kind: error.code === 'not-found' ? 'not-found' : 'refusal',
@@ -4,6 +4,9 @@ import {
4
4
  resolveTicketRef,
5
5
  } from '../kernel/ticket-migrations'
6
6
  import { updateTicketTarget } from '../kernel/node-parent'
7
+ import { normalizeIssueLinks, type IssueLinkInput } from '../ports/tickets/issue-links'
8
+ import { urgentFirst } from '../ports/tickets/priority'
9
+ import type { IssueLink } from '../ports/types'
7
10
  import { projectTicketTree, compatibleTicketSource } from '../ports/tickets/tree'
8
11
  import { readBuildFacts } from '../store/reduced-reads'
9
12
  import { samplePinnedAssets, preparePinnedAssets } from '../store/ticket-assets'
@@ -14,6 +17,7 @@ import {
14
17
  changeBlockers,
15
18
  createTicket,
16
19
  moveTicket,
20
+ moveTicketToRole,
17
21
  requireTicket,
18
22
  updateTicket,
19
23
  } from '../ports/tickets/operations'
@@ -26,7 +30,7 @@ import type {
26
30
  TicketPageListing,
27
31
  } from '../ports/types'
28
32
  import type { BuildStore } from '../store/types'
29
- import { ticketLifecycle } from '../ports/tickets/lifecycle'
33
+ import { ticketLifecycle, type TicketMoveRole } from '../ports/tickets/lifecycle'
30
34
  import { effectiveConfig } from './query'
31
35
 
32
36
  export interface OperatorTicketContext {
@@ -59,7 +63,8 @@ export interface OperatorTicketQueue {
59
63
  total: number
60
64
  }
61
65
 
62
- /** A window over a listing. `newest` reverses the source's oldest-first order. */
66
+ /** A window over a listing. `oldest` (default) is dispatch order: urgent first,
67
+ * then the source's order; `newest` reverses the source's filing order. */
63
68
  export type OperatorTicketPage = TicketPage
64
69
 
65
70
  export interface OperatorTicketBuild {
@@ -98,6 +103,30 @@ export async function openOperatorTickets(opts: {
98
103
  return { context, source: compatibleTicketSource(await opts.backend.sourceFor(context)) }
99
104
  }
100
105
 
106
+ /** Lazily open a repository's operator tickets once for a build control:
107
+ * node merge completeness needs the source and the configured rejected role,
108
+ * and only the land path reaches either. */
109
+ export function operatorControlTickets(opts: {
110
+ store: BuildStore
111
+ repo: string
112
+ backend: OperatorTicketBackend | undefined
113
+ }): {
114
+ ticketSource: () => Promise<TicketSource>
115
+ rejectedState: () => Promise<string | undefined>
116
+ } {
117
+ let opened: ReturnType<typeof openOperatorTickets> | undefined
118
+ const tickets = () => {
119
+ const backend = opts.backend
120
+ if (!backend) throw new Error('ticket source unavailable')
121
+ opened ??= openOperatorTickets({ store: opts.store, repo: opts.repo, backend })
122
+ return opened
123
+ }
124
+ return {
125
+ ticketSource: async () => (await tickets()).source,
126
+ rejectedState: async () => ticketLifecycle((await tickets()).context.tickets).rejected,
127
+ }
128
+ }
129
+
101
130
  export async function listOperatorTickets(opts: {
102
131
  store: BuildStore
103
132
  repo: string
@@ -121,8 +150,12 @@ export async function listOperatorTickets(opts: {
121
150
  nativePage ? source.listPage!(criteria, opts.page!) : source.listReady(criteria),
122
151
  opts.backend.statesFor(context, source),
123
152
  ])
124
- const ordered =
125
- !nativePage && opts.page?.order === 'newest' ? [...listing.tickets].reverse() : listing.tickets
153
+ // Native pages arrive ordered; the fallback mirrors the dispatcher's claim order.
154
+ const ordered = nativePage
155
+ ? listing.tickets
156
+ : opts.page?.order === 'newest'
157
+ ? [...listing.tickets].reverse()
158
+ : urgentFirst(listing.tickets)
126
159
  const offset = opts.page?.offset ?? 0
127
160
  return {
128
161
  states,
@@ -221,6 +254,16 @@ export async function getOperatorTicket(opts: {
221
254
  }
222
255
  }
223
256
 
257
+ type OperatorTicketPatch = Omit<TicketUpdate, 'issueLinks'> & { issueLinks?: IssueLinkInput[] }
258
+
259
+ /** Operator inputs may omit intent; the port carries an explicit `closes` default. */
260
+ function issueLinkDefaults<T extends { issueLinks?: IssueLinkInput[] }>(
261
+ input: T,
262
+ ): Omit<T, 'issueLinks'> & { issueLinks?: IssueLink[] } {
263
+ const { issueLinks, ...rest } = input
264
+ return issueLinks === undefined ? rest : { ...rest, issueLinks: normalizeIssueLinks(issueLinks) }
265
+ }
266
+
224
267
  export async function mutateOperatorTicket(opts: {
225
268
  store: BuildStore
226
269
  repo: string
@@ -235,9 +278,19 @@ export async function mutateOperatorTicket(opts: {
235
278
  labels?: string[]
236
279
  state?: string
237
280
  blockedBy?: string[]
281
+ issueLinks?: IssueLinkInput[]
282
+ priority?: import('../ports/types').TicketPriority
283
+ }
284
+ | {
285
+ kind: 'update'
286
+ id: string
287
+ patch: OperatorTicketPatch
288
+ expectedRevision?: string
238
289
  }
239
- | { kind: 'update'; id: string; patch: TicketUpdate; expectedRevision?: string }
240
- | { kind: 'move'; id: string; state: string; expectedRevision?: string }
290
+ | ({ kind: 'move'; id: string; expectedRevision?: string } & (
291
+ | { state: string; role?: undefined }
292
+ | { role: TicketMoveRole; state?: undefined }
293
+ ))
241
294
  | { kind: 'block' | 'unblock'; id: string; blockerIds: string[]; expectedRevision?: string }
242
295
  }): Promise<OperatorTicketDetail> {
243
296
  const { source, context } = await openOperatorTickets(opts)
@@ -245,10 +298,16 @@ export async function mutateOperatorTicket(opts: {
245
298
  if (operation.kind === 'update') await requireTicket(source, operation.id)
246
299
  const ticket =
247
300
  operation.kind === 'create'
248
- ? await createTicket(source, { ...operation, kind: operation.ticketKind })
301
+ ? await createTicket(source, issueLinkDefaults({ ...operation, kind: operation.ticketKind }))
249
302
  : operation.kind === 'update'
250
303
  ? (await (operation.patch.target === undefined
251
- ? updateTicket(source, operation.id, operation.patch, true, operation.expectedRevision)
304
+ ? updateTicket(
305
+ source,
306
+ operation.id,
307
+ issueLinkDefaults(operation.patch),
308
+ true,
309
+ operation.expectedRevision,
310
+ )
252
311
  : updateTicketTarget(
253
312
  {
254
313
  store: opts.store,
@@ -268,11 +327,19 @@ export async function mutateOperatorTicket(opts: {
268
327
  },
269
328
  },
270
329
  operation.id,
271
- operation.patch,
330
+ issueLinkDefaults(operation.patch),
272
331
  operation.expectedRevision,
273
332
  )))!
274
333
  : operation.kind === 'move'
275
- ? await moveTicket(source, operation.id, operation.state, operation.expectedRevision)
334
+ ? operation.role !== undefined
335
+ ? await moveTicketToRole(
336
+ source,
337
+ context.tickets,
338
+ operation.id,
339
+ operation.role,
340
+ operation.expectedRevision,
341
+ )
342
+ : await moveTicket(source, operation.id, operation.state, operation.expectedRevision)
276
343
  : await changeBlockers(
277
344
  source,
278
345
  operation.id,
@@ -161,6 +161,19 @@ export {
161
161
  ticketRevision,
162
162
  checkTicketRevision,
163
163
  } from '../ports/tickets/revision'
164
+ export { TicketIssueLinksUnsupported, normalizeIssueLinks } from '../ports/tickets/issue-links'
165
+ export {
166
+ TicketPriorityUnsupported,
167
+ refuseUnsupportedPriority,
168
+ withoutUnsupportedPriority,
169
+ urgentFirst,
170
+ } from '../ports/tickets/priority'
171
+ export {
172
+ issueKeywordLines,
173
+ landingMessage,
174
+ neutralizeClosingReferences,
175
+ withIssueKeywords,
176
+ } from '../kernel/issue-keywords'
164
177
  export { FakeWorkspaceProvider } from '../ports/workspace/fake'
165
178
  export { ForgeFailure, isForgeFailure } from '../ports/forge-failure'
166
179
  export type {
@@ -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.9.0' as const
18
+ export const PLUGIN_API_VERSION = '1.10.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>> {
@@ -160,6 +160,7 @@ function normalize<AdapterFactory, ContractFactory>(
160
160
  export class PluginRegistry {
161
161
  readonly ticketSources = reserved<TicketSourcePluginFactory, TicketSourceContractFactory>([
162
162
  'file',
163
+ 'github',
163
164
  'hosted',
164
165
  'linear',
165
166
  ])