@defrex/autobuild 1.5.0 → 1.7.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 (126) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +192 -24
  3. package/docs/agent-runtimes.md +1 -1
  4. package/docs/answering-blocked-builds.md +7 -4
  5. package/docs/architecture.md +100 -32
  6. package/docs/configuration-overview.md +10 -0
  7. package/docs/configuration.md +340 -10
  8. package/docs/dispatcher.md +2 -2
  9. package/docs/forges.md +1 -0
  10. package/docs/glossary.md +1 -1
  11. package/docs/operating.md +1 -1
  12. package/docs/operator-api.md +33 -10
  13. package/docs/operator-surfaces.md +6 -3
  14. package/docs/plugin-authoring.md +48 -6
  15. package/docs/remote-store-protocol.md +33 -10
  16. package/docs/restacking.md +16 -7
  17. package/docs/ticket-sources.md +34 -6
  18. package/docs/tickets.md +7 -1
  19. package/docs/troubleshooting.md +1 -1
  20. package/docs/workspaces.md +1 -1
  21. package/package.json +3 -3
  22. package/packages/core/src/cli/attention.ts +3 -0
  23. package/packages/core/src/cli/binary-direct.ts +1 -0
  24. package/packages/core/src/cli/dashboard/model.ts +14 -4
  25. package/packages/core/src/cli/dashboard/poll.ts +14 -0
  26. package/packages/core/src/cli/dashboard/render.ts +3 -0
  27. package/packages/core/src/cli/dispatch-frontend.ts +10 -14
  28. package/packages/core/src/cli/dispatch-preflight.ts +5 -1
  29. package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
  30. package/packages/core/src/cli/dispatch-tickets.ts +47 -0
  31. package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
  32. package/packages/core/src/cli/dispatch.ts +377 -101
  33. package/packages/core/src/cli/help.ts +15 -6
  34. package/packages/core/src/cli/init-validation.ts +14 -1
  35. package/packages/core/src/cli/repo-lease.ts +225 -0
  36. package/packages/core/src/cli/repository-status.ts +40 -3
  37. package/packages/core/src/cli/status.ts +21 -13
  38. package/packages/core/src/cli/ticket.ts +22 -4
  39. package/packages/core/src/cli/wait.ts +4 -1
  40. package/packages/core/src/cli/watch.ts +17 -4
  41. package/packages/core/src/config/live.ts +4 -0
  42. package/packages/core/src/config/profiles.ts +96 -0
  43. package/packages/core/src/config/ready-assignee.ts +43 -11
  44. package/packages/core/src/config/roles.ts +33 -10
  45. package/packages/core/src/config/schema.ts +204 -26
  46. package/packages/core/src/events/catalog.ts +2 -0
  47. package/packages/core/src/events/compatibility.ts +3 -1
  48. package/packages/core/src/events/forge-degradation-policy.ts +16 -2
  49. package/packages/core/src/events/payloads.ts +23 -0
  50. package/packages/core/src/events/policy.ts +3 -0
  51. package/packages/core/src/events/repository.ts +19 -0
  52. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +267 -352
  53. package/packages/core/src/kernel/build-creation.ts +29 -0
  54. package/packages/core/src/kernel/dispatch-capacity.ts +134 -30
  55. package/packages/core/src/kernel/engine.ts +13 -6
  56. package/packages/core/src/kernel/forge-health.ts +47 -0
  57. package/packages/core/src/kernel/generators/build-log.ts +9 -0
  58. package/packages/core/src/kernel/guarded-forge.ts +76 -18
  59. package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
  60. package/packages/core/src/kernel/janitor-failure.ts +85 -5
  61. package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
  62. package/packages/core/src/kernel/log-index.ts +1 -1
  63. package/packages/core/src/kernel/node-landing.ts +2 -1
  64. package/packages/core/src/kernel/node-parent.ts +2 -0
  65. package/packages/core/src/kernel/read-facts.ts +9 -1
  66. package/packages/core/src/kernel/reducer-registry.ts +6 -1
  67. package/packages/core/src/kernel/reducer.ts +75 -4
  68. package/packages/core/src/kernel/ticket-preparation.ts +15 -8
  69. package/packages/core/src/operator/protocol.ts +10 -0
  70. package/packages/core/src/operator/query.ts +16 -13
  71. package/packages/core/src/operator/registry.ts +25 -5
  72. package/packages/core/src/operator/sandbox-host.ts +3 -0
  73. package/packages/core/src/operator/tickets.ts +15 -3
  74. package/packages/core/src/plugin-sdk/index.ts +4 -0
  75. package/packages/core/src/ports/forge/create.ts +6 -0
  76. package/packages/core/src/ports/forge/github-transport.ts +40 -3
  77. package/packages/core/src/ports/forge/github.ts +12 -1
  78. package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
  79. package/packages/core/src/ports/forge-failure.ts +31 -2
  80. package/packages/core/src/ports/runner/routing.ts +66 -5
  81. package/packages/core/src/ports/tickets/assignees.ts +54 -0
  82. package/packages/core/src/ports/tickets/contract.ts +164 -4
  83. package/packages/core/src/ports/tickets/create.ts +35 -7
  84. package/packages/core/src/ports/tickets/github-fake.ts +18 -2
  85. package/packages/core/src/ports/tickets/github.ts +247 -29
  86. package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
  87. package/packages/core/src/ports/tickets/operations.ts +6 -1
  88. package/packages/core/src/ports/tickets/tree.ts +12 -2
  89. package/packages/core/src/ports/tickets/update.ts +6 -2
  90. package/packages/core/src/ports/types.ts +37 -3
  91. package/packages/core/src/ports/workspace/commit-preservation.ts +28 -12
  92. package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
  93. package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
  94. package/packages/core/src/ports/workspace/vercel-sandbox.ts +12 -0
  95. package/packages/core/src/processes/build-child.ts +28 -7
  96. package/packages/core/src/processes/build-execution-state.ts +4 -1
  97. package/packages/core/src/processes/build-runner.ts +17 -2
  98. package/packages/core/src/processes/dispatcher.ts +329 -59
  99. package/packages/core/src/processes/execution-no-progress.ts +2 -0
  100. package/packages/core/src/processes/harvest-child.ts +8 -2
  101. package/packages/core/src/processes/harvest-execution-state.ts +104 -0
  102. package/packages/core/src/processes/harvest-runner.ts +251 -17
  103. package/packages/core/src/processes/repo-view.ts +2 -0
  104. package/packages/core/src/scenarios/harness.ts +160 -36
  105. package/packages/core/src/store/reduced-reads.ts +10 -0
  106. package/packages/core/src/store/reducer-value-shapes.json +3339 -2898
  107. package/packages/core/src/store/remote/client.ts +21 -8
  108. package/packages/core/src/store/remote/index.ts +4 -0
  109. package/packages/core/src/store/remote/protocol.ts +7 -0
  110. package/packages/core/src/store/remote/released-clients.json +22 -0
  111. package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
  112. package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
  113. package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
  114. package/packages/core/src/store/repo-state-events.ts +1 -0
  115. package/packages/core/src/store/types.ts +11 -0
  116. package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
  117. package/packages/core/src/testing/index.ts +2 -0
  118. package/packages/core/src/testing/reduced-read-budget.ts +411 -11
  119. package/skills/guide/SKILL.md +166 -35
  120. package/skills/guide/references/operator-api.md +33 -10
  121. package/skills/guide/references/plugin-authoring.md +48 -6
  122. package/skills/guide/references/remote-store-protocol.md +33 -10
  123. package/skills/guide/references/restacking.md +16 -7
  124. package/skills/operate/SKILL.md +79 -14
  125. package/skills/tickets/SKILL.md +22 -4
  126. package/templates/hosted-service/package.json +2 -2
@@ -12,6 +12,7 @@ import {
12
12
  import { validateTicketTree } from '../ports/tickets/tree'
13
13
  import { refuseUnsupportedIssueLinks } from '../ports/tickets/issue-links'
14
14
  import { refuseUnsupportedPriority } from '../ports/tickets/priority'
15
+ import { refuseUnsupportedAssignees } from '../ports/tickets/assignees'
15
16
  import { readBuildFacts } from '../store/reduced-reads'
16
17
  import type { BuildRecord, BuildStore } from '../store/types'
17
18
  import type { BuildState } from './reducer'
@@ -131,6 +132,7 @@ export async function updateTicketTarget(
131
132
  // cancels that request on revision errors.
132
133
  refuseUnsupportedIssueLinks(ctx.source, patch)
133
134
  refuseUnsupportedPriority(ctx.source, patch)
135
+ refuseUnsupportedAssignees(ctx.source, patch)
134
136
  if (patch.target === undefined) return updateTicket(ctx.source, id, patch, true, expectedRevision)
135
137
  const ticket = await requireTicket(ctx.source, id)
136
138
  if (expectedRevision !== undefined) {
@@ -577,7 +577,7 @@ import type { RepositoryEvent } from '../events/repository'
577
577
  import { repositoryAttentionReducer } from './repository-attention'
578
578
  import { dispatchSettingsReducer } from './dispatch-settings'
579
579
  import { harvestReducer } from './harvest'
580
- import { forgeHealthReducer } from './forge-health'
580
+ import { forgeCredentialLimitsReducer, forgeHealthReducer } from './forge-health'
581
581
  import { kernelGitHealthReducer } from './kernel-git'
582
582
  import { ticketSourceHealthReducer } from './ticket-source-health'
583
583
  import { autoMergeDefaultReducer } from './auto-merge-default'
@@ -630,6 +630,7 @@ export interface RepositoryReadAcc {
630
630
  settings: ReturnType<typeof dispatchSettingsReducer.initial>
631
631
  harvest: ReturnType<typeof harvestReducer.initial>
632
632
  forgeHealth: ReturnType<typeof forgeHealthReducer.initial>
633
+ forgeCredentialLimits: ReturnType<typeof forgeCredentialLimitsReducer.initial>
633
634
  kernelGit: ReturnType<typeof kernelGitHealthReducer.initial>
634
635
  ticketMigrations: ReturnType<typeof ticketMigrationsReducer.initial>
635
636
  health: ReturnType<typeof ticketSourceHealthReducer.initial>
@@ -655,6 +656,7 @@ export const repositoryReadFactsReducer = defineReducer({
655
656
  dispatcherRunFactsReducer('version').version +
656
657
  openHarvestExecutionsReducer.version +
657
658
  forgeHealthReducer.version +
659
+ forgeCredentialLimitsReducer.version +
658
660
  kernelGitHealthReducer.version +
659
661
  repositoryAttentionReducer.version +
660
662
  dispatchSettingsReducer.version +
@@ -686,6 +688,7 @@ export const repositoryReadFactsReducer = defineReducer({
686
688
  settings: dispatchSettingsReducer.initial(),
687
689
  harvest: harvestReducer.initial(),
688
690
  forgeHealth: forgeHealthReducer.initial(),
691
+ forgeCredentialLimits: forgeCredentialLimitsReducer.initial(),
689
692
  kernelGit: kernelGitHealthReducer.initial(),
690
693
  ticketMigrations: ticketMigrationsReducer.initial(),
691
694
  health: ticketSourceHealthReducer.initial(),
@@ -704,6 +707,10 @@ export const repositoryReadFactsReducer = defineReducer({
704
707
  acc.settings = dispatchSettingsReducer.advance(acc.settings, events)
705
708
  acc.harvest = harvestReducer.advance(acc.harvest, events)
706
709
  acc.forgeHealth = forgeHealthReducer.advance(acc.forgeHealth, events)
710
+ acc.forgeCredentialLimits = forgeCredentialLimitsReducer.advance(
711
+ acc.forgeCredentialLimits,
712
+ events,
713
+ )
707
714
  acc.kernelGit = kernelGitHealthReducer.advance(acc.kernelGit, events)
708
715
  acc.ticketMigrations = ticketMigrationsReducer.advance(acc.ticketMigrations, events)
709
716
  acc.health = ticketSourceHealthReducer.advance(acc.health, events)
@@ -838,6 +845,7 @@ export const repositoryReadFactsReducer = defineReducer({
838
845
  settings: dispatchSettingsReducer.finish(acc.settings),
839
846
  harvest: harvestReducer.finish(acc.harvest),
840
847
  forgeHealth: forgeHealthReducer.finish(acc.forgeHealth),
848
+ forgeCredentialLimits: forgeCredentialLimitsReducer.finish(acc.forgeCredentialLimits),
841
849
  kernelGit: kernelGitHealthReducer.finish(acc.kernelGit),
842
850
  ticketMigrations: ticketMigrationsReducer.finish(acc.ticketMigrations),
843
851
  health: ticketSourceHealthReducer.finish(acc.health),
@@ -53,7 +53,10 @@ import {
53
53
  lastExecutionOutcomeReducer,
54
54
  openExecutionReducer,
55
55
  } from '../processes/execution-settlement'
56
- import { openHarvestExecutionsReducer } from '../processes/harvest-execution-state'
56
+ import {
57
+ hostedHarvestAuthorityReducer,
58
+ openHarvestExecutionsReducer,
59
+ } from '../processes/harvest-execution-state'
57
60
  import { infrastructureFailureResetReducer } from '../processes/infrastructure-failure-budget'
58
61
  import { publicationStateReducer } from '../processes/publication-state'
59
62
  import { sandboxStatesReducer } from '../processes/sandbox-state'
@@ -152,6 +155,7 @@ const REGISTERED: Record<string, Omit<RegisteredReducer, 'valueRead'>> = {
152
155
  reducer: openHarvestExecutionsReducer,
153
156
  covers: ['openHarvestExecutions'],
154
157
  },
158
+ hostedHarvestAuthority: { reducer: hostedHarvestAuthorityReducer, covers: [] },
155
159
  openTick: { reducer: openTickReducer('run-a'), covers: ['hasOpenTick'] },
156
160
  dispatchFailureBudget: {
157
161
  reducer: dispatchFailureBudgetReducer(false),
@@ -234,6 +238,7 @@ const repositoryValues = new Set([
234
238
  'dispatchStatus',
235
239
  'sandboxStates',
236
240
  'openHarvestExecutions',
241
+ 'hostedHarvestAuthority',
237
242
  'openTick',
238
243
  'autoMergeDefault',
239
244
  ])
@@ -65,6 +65,12 @@ export interface NodeIssueLinksState {
65
65
  published?: { pr: number; issueLinks: IssueLink[]; seq: number }
66
66
  }
67
67
 
68
+ /** A build's frozen role profile (SPEC §9). */
69
+ export interface BuildProfile {
70
+ name: string
71
+ configured: boolean
72
+ }
73
+
68
74
  export interface OpenEscalation {
69
75
  id: string
70
76
  phase: EscalationTarget
@@ -75,6 +81,9 @@ export interface OpenEscalation {
75
81
  /** Policy guard identity. Absent only on historical policy raises. */
76
82
  policyCause?: PolicyEscalationCause
77
83
  deferral?: 'own-build-read'
84
+ /** Raised by `build.janitor-escalated`. Its routing is inert (`setup`
85
+ * target, no cause); the janitor's recovery closes it unanswered. */
86
+ janitor?: true
78
87
  question: string
79
88
  refs?: string[]
80
89
  /** seq of the `escalation.raised` event — what `spec.revised` cites (§15.3). */
@@ -253,6 +262,10 @@ export interface BuildState {
253
262
  * a still-blocked build reports 'blocked' again. No information is lost.
254
263
  */
255
264
  status: BuildStatus
265
+ /** The status this build would have without its janitor escalation; present
266
+ * only while one is open. The janitor reads it so its own escalation never
267
+ * gates the work that would recover it. */
268
+ statusWithoutJanitorEscalation?: BuildStatus
256
269
  /** From `build.completed` — present only once status is 'done'. */
257
270
  outcome?: BuildOutcome
258
271
  /** currentPhase if one is started-but-not-completed, else the latest
@@ -286,6 +299,10 @@ export interface BuildState {
286
299
  message: string
287
300
  nextAttemptAt: string
288
301
  attention?: true
302
+ /** Id of this episode's escalation, once raised. */
303
+ escalation?: string
304
+ /** The escalation was answered: attempt again without waiting out backoff. */
305
+ retryRequested?: true
289
306
  }
290
307
  landing?: LandingState
291
308
  /** Historical auto-merge controls retained for replay compatibility. */
@@ -297,6 +314,10 @@ export interface BuildState {
297
314
  * read it. Compare this against `restartSince`, exactly as engine.ts:707-708
298
315
  * post-filters its own `finalizeCompleted`. */
299
316
  finalizeCompletedSeq: number
317
+ /** Largest settlement key the dispatcher observed at the engine's leaf
318
+ * `wait awaiting-pr` decision (`pipeline.settled`); capacity evidence only,
319
+ * never a pipeline decision input. */
320
+ pipelineSettled?: number
300
321
  /** Full-log `finalize.step-completed` facts, in event order (§5).
301
322
  * Post-steps are failure-tolerant, so a completion counts whether `ok` is
302
323
  * true or false. Current-spec membership is determined by
@@ -316,6 +337,11 @@ export interface BuildState {
316
337
  /** seq of the fact that closed the downgrade window: `issue-links.sealed`,
317
338
  * `publication.requested {operation: 'finalize'}` or `finalize.completed`. */
318
339
  issueLinksSealedSeq?: number
340
+ /** The role profile `build.created` froze at claim. `configured` is the
341
+ * latest `session.started` observation of whether the session's config
342
+ * still defined it; true until a session says otherwise. Absent for builds
343
+ * without a profile and historical logs. */
344
+ profile?: BuildProfile
319
345
  /** Latest spec artifact rev — `spec.imported`/`spec.authored` set it,
320
346
  * `spec.revised` bumps it (§6.3: rev N+1 restarts leaves from plan and nodes from collection). */
321
347
  specRev?: number
@@ -392,6 +418,8 @@ export interface BuildState {
392
418
  dispatchFailures: Array<EventPayload<'dispatch.failed'> & { seq: number }>
393
419
  /** Provider identities and failures are durable even after recovery clears the current error. */
394
420
  executions: Array<EventPayload<'execution.started'> & { seq: number }>
421
+ /** The latest execution, while no instance-matched `execution.ended` follows it. */
422
+ openExecution?: EventPayload<'execution.started'> & { seq: number }
395
423
  infrastructureFailures: Array<EventPayload<'infrastructure.failed'> & { seq: number }>
396
424
  infrastructureFailure?: EventPayload<'infrastructure.failed'> & { seq: number }
397
425
  cleanupAttempts: Array<EventPayload<'infrastructure.cleanup-attempted'> & { seq: number }>
@@ -467,6 +495,10 @@ export interface BuildAcc {
467
495
  message: string
468
496
  nextAttemptAt: string
469
497
  attention?: true
498
+ /** Id of this episode's escalation, once raised. */
499
+ escalation?: string
500
+ /** The escalation was answered: attempt again without waiting out backoff. */
501
+ retryRequested?: true
470
502
  }
471
503
  landing?: LandingState
472
504
  autoMerge: AutoMergeProjection
@@ -475,7 +507,9 @@ export interface BuildAcc {
475
507
  pinnedAssets: PinnedAsset[]
476
508
  issueLinks: BuildIssueLink[]
477
509
  issueLinksSealedSeq?: number
510
+ profile?: BuildProfile
478
511
  finalizeCompletedSeq: number
512
+ pipelineSettled?: number
479
513
  finalizeSteps: BuildState['finalizeSteps']
480
514
  plan: BuildState['plan']
481
515
  implement: BuildState['implement']
@@ -505,7 +539,7 @@ export interface BuildAcc {
505
539
  }
506
540
 
507
541
  /** Bump when `BuildAcc`'s shape or the fold's semantics change. */
508
- export const BUILD_REDUCER_VERSION = 30
542
+ export const BUILD_REDUCER_VERSION = 33
509
543
 
510
544
  function initialBuildAcc(): BuildAcc {
511
545
  return {
@@ -667,9 +701,16 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
667
701
  acc.janitor = {
668
702
  ...event.payload,
669
703
  ...(acc.janitor?.attention ? { attention: true as const } : {}),
704
+ ...(acc.janitor?.escalation ? { escalation: acc.janitor.escalation } : {}),
670
705
  }
671
706
  if (event.type === 'build.janitor-failing' && acc.janitor) acc.janitor.attention = true
672
- if (event.type === 'build.janitor-recovered') delete acc.janitor
707
+ if (event.type === 'build.janitor-escalated' && acc.janitor)
708
+ acc.janitor.escalation = event.payload.id
709
+ if (event.type === 'build.janitor-recovered') {
710
+ delete acc.janitor
711
+ for (const escalation of [...openEscalations.values()])
712
+ if (escalation.janitor) openEscalations.delete(escalation.id)
713
+ }
673
714
  if (event.type === 'target.rewritten') acc.targetRewrite = event
674
715
  if (
675
716
  event.type === 'target.moved' ||
@@ -773,6 +814,8 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
773
814
  acc.baseBranch = event.payload.baseBranch
774
815
  pinnedAssets = event.payload.assets ?? []
775
816
  acc.issueLinks = (event.payload.issueLinks ?? []).map((link) => ({ ...link }))
817
+ if (event.payload.profile !== undefined)
818
+ acc.profile = { name: event.payload.profile, configured: true }
776
819
  break
777
820
  case 'issue-link.downgraded': {
778
821
  // One-way and only before the seal: a later, a repeated or an
@@ -951,6 +994,8 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
951
994
  break
952
995
 
953
996
  case 'session.started': {
997
+ if (event.payload.profile !== undefined && event.payload.profile.name === acc.profile?.name)
998
+ acc.profile = { ...acc.profile, configured: event.payload.profile.configured }
954
999
  const root = event.payload.continuation?.root ?? event.payload.session
955
1000
  acc.sessionTotals[root] ??= { activeMs: 0, transcripts: [] }
956
1001
  const totals = acc.sessionTotals[root]
@@ -1177,6 +1222,9 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
1177
1222
  finalizeCompletedSeq = event.seq
1178
1223
  complete('finalize', event.seq)
1179
1224
  break
1225
+ case 'pipeline.settled':
1226
+ acc.pipelineSettled = Math.max(acc.pipelineSettled ?? 0, event.payload.cycle)
1227
+ break
1180
1228
  case 'finalize.step-completed':
1181
1229
  // §5: post-steps are independent and failure-tolerant — a completion
1182
1230
  // counts whether `ok` is true or false. Retain full-log history with
@@ -1260,6 +1308,17 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
1260
1308
  seq: event.seq,
1261
1309
  })
1262
1310
  break
1311
+ case 'build.janitor-escalated':
1312
+ if (!openEscalations.has(event.payload.id))
1313
+ openEscalations.set(event.payload.id, {
1314
+ id: event.payload.id,
1315
+ phase: 'setup',
1316
+ source: 'policy',
1317
+ janitor: true,
1318
+ question: event.payload.question,
1319
+ seq: event.seq,
1320
+ })
1321
+ break
1263
1322
  case 'escalation.raised': {
1264
1323
  const escalation: OpenEscalation = {
1265
1324
  id: event.payload.id,
@@ -1298,6 +1357,7 @@ function foldBuild(acc: BuildAcc, events: readonly AbEvent[]): void {
1298
1357
  : {}),
1299
1358
  answeredSeq: event.seq,
1300
1359
  })
1360
+ if (open.janitor && acc.janitor?.escalation === open.id) acc.janitor.retryRequested = true
1301
1361
  if (
1302
1362
  event.payload.reviewRoundCeiling !== undefined &&
1303
1363
  open.source === 'policy' &&
@@ -1380,21 +1440,26 @@ function finishBuild(acc: BuildAcc): BuildState {
1380
1440
  discardRequest,
1381
1441
  pending,
1382
1442
  } = acc
1443
+ const latestExecution = acc.executions.at(-1)
1383
1444
 
1384
1445
  // §15.5 precedence: aborted/done (terminal, latest wins) > paused >
1385
1446
  // blocked > running > queued. See BuildState.status for the paused+blocked
1386
1447
  // overlap rule.
1387
- const status: BuildStatus =
1448
+ const statusOf = (escalations: readonly OpenEscalation[]): BuildStatus =>
1388
1449
  terminal ??
1389
1450
  (pausedFlag
1390
1451
  ? 'paused'
1391
- : acc.openEscalations.length > 0 || integrationFailed(acc)
1452
+ : escalations.length > 0 || integrationFailed(acc)
1392
1453
  ? 'blocked'
1393
1454
  : acc.kind === 'node' && acc.nodeOpened !== undefined
1394
1455
  ? 'collecting'
1395
1456
  : attached
1396
1457
  ? 'running'
1397
1458
  : 'queued')
1459
+ const status = statusOf(acc.openEscalations)
1460
+ const statusWithoutJanitorEscalation = acc.openEscalations.some((e) => e.janitor)
1461
+ ? statusOf(acc.openEscalations.filter((e) => !e.janitor))
1462
+ : undefined
1398
1463
 
1399
1464
  const active = currentPhase ?? lastCompletedPhase
1400
1465
 
@@ -1412,6 +1477,7 @@ function finishBuild(acc: BuildAcc): BuildState {
1412
1477
  ...(acc.nodeIssueLinks !== undefined ? { nodeIssueLinks: acc.nodeIssueLinks } : {}),
1413
1478
  nodeRestack: acc.nodeRestack,
1414
1479
  status,
1480
+ ...(statusWithoutJanitorEscalation !== undefined ? { statusWithoutJanitorEscalation } : {}),
1415
1481
  outcome: acc.outcome,
1416
1482
  phase: active?.phase,
1417
1483
  round: acc.round,
@@ -1427,6 +1493,7 @@ function finishBuild(acc: BuildAcc): BuildState {
1427
1493
  landing: acc.landing,
1428
1494
  autoMerge: acc.autoMerge,
1429
1495
  finalizeCompletedSeq: acc.finalizeCompletedSeq,
1496
+ ...(acc.pipelineSettled !== undefined ? { pipelineSettled: acc.pipelineSettled } : {}),
1430
1497
  finalizeSteps: acc.finalizeSteps,
1431
1498
  lastEvent,
1432
1499
  lastSeq: Math.max(lastEvent?.seq ?? 0, acc.compatibility.lastSeq),
@@ -1440,6 +1507,7 @@ function finishBuild(acc: BuildAcc): BuildState {
1440
1507
  ...(acc.issueLinksSealedSeq !== undefined
1441
1508
  ? { issueLinksSealedSeq: acc.issueLinksSealedSeq }
1442
1509
  : {}),
1510
+ ...(acc.profile !== undefined ? { profile: { ...acc.profile } } : {}),
1443
1511
  specRev: acc.specRev,
1444
1512
  restartSince: acc.restartSince,
1445
1513
  plan: acc.plan,
@@ -1455,6 +1523,9 @@ function finishBuild(acc: BuildAcc): BuildState {
1455
1523
  setupFailure: acc.setupFailure,
1456
1524
  dispatchFailures: acc.dispatchFailures,
1457
1525
  executions: acc.executions,
1526
+ ...(latestExecution && !acc.endedExecutionInstances[latestExecution.instance]
1527
+ ? { openExecution: latestExecution }
1528
+ : {}),
1458
1529
  infrastructureFailures: acc.infrastructureFailures,
1459
1530
  infrastructureFailure: acc.infrastructureFailure,
1460
1531
  cleanupAttempts: acc.cleanupAttempts,
@@ -9,6 +9,8 @@ export interface TicketPreparation {
9
9
  claimedState: string
10
10
  claimed: boolean
11
11
  slug?: string
12
+ /** Present when the store attested keyed creation for this attempt. */
13
+ creationKey?: string
12
14
  handback?: string
13
15
  stage?: string
14
16
  error?: string
@@ -21,7 +23,7 @@ export const ticketPreparationReducer = defineReducer<
21
23
  RepositoryEvent,
22
24
  Record<string, TicketPreparation>
23
25
  >({
24
- version: 1,
26
+ version: 2,
25
27
  initial: () => ({}),
26
28
  fold(acc, events) {
27
29
  for (const event of events) {
@@ -39,6 +41,7 @@ export const ticketPreparationReducer = defineReducer<
39
41
  break
40
42
  case 'ticket-preparation.creation-selected':
41
43
  held.slug = event.payload.slug
44
+ if (event.payload.creationKey) held.creationKey = event.payload.creationKey
42
45
  break
43
46
  case 'ticket-preparation.handback-selected':
44
47
  held.handback = event.payload.state
@@ -66,13 +69,17 @@ export const ticketPreparationReducer = defineReducer<
66
69
  })
67
70
 
68
71
  /** The one operator line for a durably abandoned attempt. An unconfirmed
69
- * claim is never reported as applied: its provider outcome is unknown. */
72
+ * claim is never reported as applied: its provider outcome is unknown. An
73
+ * event written before claim certainty was recorded says so. */
70
74
  export function abandonedPreparationDiagnostic(
71
- attempt: Pick<TicketPreparation, 'attempt' | 'ticket' | 'claimed'>,
72
- reason: string,
75
+ attempt: { attempt: string; ticket: TicketRef; claimed?: boolean },
76
+ reason?: string,
73
77
  ): string {
74
- const claim = attempt.claimed
75
- ? 'claim confirmed'
76
- : 'claim unconfirmed (provider outcome unknown; it may have applied the claim)'
77
- return `ticket ${attempt.ticket.id} (${attempt.ticket.source}): preparation ${attempt.attempt} abandoned; ${claim}; ticket unchanged — ${reason}`
78
+ const claim =
79
+ attempt.claimed === true
80
+ ? 'claim confirmed'
81
+ : attempt.claimed === false
82
+ ? 'claim unconfirmed (provider outcome unknown; it may have applied the claim)'
83
+ : 'claim certainty not recorded (provider outcome unknown)'
84
+ return `ticket ${attempt.ticket.id} (${attempt.ticket.source}): preparation ${attempt.attempt} abandoned; ${claim}; ticket unchanged — ${reason ?? 'no reason recorded'}`
78
85
  }
@@ -2,6 +2,7 @@ import { z } from 'zod'
2
2
  import { issueLinksInputSchema } from '../ports/tickets/issue-links'
3
3
  import { TICKET_MOVE_ROLES } from '../ports/tickets/lifecycle'
4
4
  import { ticketPrioritySchema } from '../ports/tickets/priority'
5
+ import { ticketAssigneesSchema } from '../ports/tickets/assignees'
5
6
 
6
7
  const issueLinksField = issueLinksInputSchema
7
8
  .optional()
@@ -15,6 +16,12 @@ const priorityField = ticketPrioritySchema
15
16
  '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
17
  )
17
18
 
19
+ const assigneesField = ticketAssigneesSchema
20
+ .optional()
21
+ .describe(
22
+ 'Usernames to assign, or "me" for the owner of the ticket-source credential. On create, replaces the [tickets].createAssignee default ([] creates an unassigned ticket); on update, a complete replacement ([] clears). Sources that cannot store assignees refuse it.',
23
+ )
24
+
18
25
  export const buildListScopeSchema = z.enum(['active', 'queued', 'all'])
19
26
 
20
27
  export const buildControlRequestSchema = z.discriminatedUnion('action', [
@@ -73,6 +80,7 @@ export const ticketCreateRequestSchema = z.strictObject({
73
80
  blockedBy: z.array(z.string().min(1)).optional(),
74
81
  issueLinks: issueLinksField,
75
82
  priority: priorityField,
83
+ assignees: assigneesField,
76
84
  })
77
85
  const expectedRevisionSchema = z
78
86
  .string()
@@ -88,6 +96,7 @@ export const ticketUpdateRequestSchema = z
88
96
  labels: z.array(z.string()).optional(),
89
97
  issueLinks: issueLinksField,
90
98
  priority: priorityField,
99
+ assignees: assigneesField,
91
100
  })
92
101
  .refine(
93
102
  (value) =>
@@ -96,6 +105,7 @@ export const ticketUpdateRequestSchema = z
96
105
  value.labels !== undefined ||
97
106
  value.issueLinks !== undefined ||
98
107
  value.priority !== undefined ||
108
+ value.assignees !== undefined ||
99
109
  value.kind !== undefined ||
100
110
  value.target !== undefined,
101
111
  'update must name at least one field',
@@ -3,6 +3,7 @@ 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
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 {
@@ -117,18 +118,19 @@ async function listFromView(
117
118
  record,
118
119
  facts.state,
119
120
  opts.now,
120
- facts.state.kind === 'node'
121
- ? slotRequest(
122
- {
123
- record,
124
- state: facts.state,
125
- workspace: facts.workspace !== null,
126
- provisioning:
127
- (await readBuildFacts(view, record.slug)).value.provisionMarker !== undefined,
128
- },
129
- opts.now,
130
- )
131
- : undefined,
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
+ ),
132
134
  )
133
135
  if (statuses.has(projected.status)) output.push(projected)
134
136
  }
@@ -356,7 +358,7 @@ export async function getRepositoryStatus(
356
358
  return withOperatorView(store, repo, 'journal', async (view) => {
357
359
  const { dispatcher } = await readDispatcherLiveness(store, repo, now)
358
360
  const facts = (await readRepositoryFacts(view, repo)).value
359
- const status = repositoryStatusFromFacts(repo, facts, dispatcher)
361
+ const status = repositoryStatusFromFacts(repo, facts, dispatcher, now)
360
362
  const capacity = await readRepositoryCapacity(store, repo, facts, dispatcher, now)
361
363
  return { ...status, ...(capacity ? { capacity } : {}) }
362
364
  })
@@ -439,6 +441,7 @@ async function dashboardFromView(
439
441
  provisioning:
440
442
  facts.state.kind === 'node' &&
441
443
  (await readBuildFacts(view, record.slug)).value.provisionMarker !== undefined,
444
+ restackDue: landingRestackDue(facts.state, facts.log),
442
445
  })
443
446
  if (projectsNoDashboardRow(facts.state)) continue
444
447
  const pinned = await readPinnedConfig(view, record.slug, config, facts.state.verify.configPin)
@@ -6,6 +6,7 @@ import { openOperatorTickets, operatorControlTickets } from './tickets'
6
6
  import { TicketRevisionConflict, TicketRevisionUnsupported } from '../ports/tickets/revision'
7
7
  import { TicketIssueLinksUnsupported } from '../ports/tickets/issue-links'
8
8
  import { TicketPriorityUnsupported } from '../ports/tickets/priority'
9
+ import { TicketAssigneesUnsupported } from '../ports/tickets/assignees'
9
10
  /**
10
11
  * The agent tool registry — one typed table that is the single source of
11
12
  * truth for the agent-facing operator surface (AUT-338).
@@ -330,7 +331,7 @@ const ticketsListInput = z.strictObject({
330
331
  .enum(['oldest', 'newest'])
331
332
  .optional()
332
333
  .describe(
333
- 'Dispatch order, urgent tickets first and then the source order (the default), or newest filed first.',
334
+ 'Dispatch order, urgent tickets first and then the source order (the default), or newest filed first regardless of urgency.',
334
335
  ),
335
336
  })
336
337
 
@@ -345,6 +346,7 @@ const ticketsUpdateInput = ticketUpdateRequestSchema
345
346
  value.labels !== undefined ||
346
347
  value.issueLinks !== undefined ||
347
348
  value.priority !== undefined ||
349
+ value.assignees !== undefined ||
348
350
  value.kind !== undefined ||
349
351
  value.target !== undefined,
350
352
  'update must name at least one field',
@@ -851,13 +853,24 @@ export const TOOLS: readonly ToolEntry[] = [
851
853
  ),
852
854
  defineTool(
853
855
  'tickets.create',
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.',
856
+ '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, assigned (explicit assignees replace the [tickets].createAssignee default), or filed in a nondefault state.',
855
857
  ticketsCreateInput,
856
858
  '{ticket, blockers, build}: the created ticket and its (usually empty) dependency states.',
857
859
  async (raw, ctx) => {
858
860
  const input = raw as z.infer<typeof ticketsCreateInput>
859
- const { repo, title, body, labels, state, blockedBy, issueLinks, priority, kind, target } =
860
- input
861
+ const {
862
+ repo,
863
+ title,
864
+ body,
865
+ labels,
866
+ state,
867
+ blockedBy,
868
+ issueLinks,
869
+ priority,
870
+ assignees,
871
+ kind,
872
+ target,
873
+ } = input
861
874
  return mutateOperatorTicket({
862
875
  store: ctx.store,
863
876
  repo,
@@ -873,13 +886,14 @@ export const TOOLS: readonly ToolEntry[] = [
873
886
  ...(blockedBy !== undefined ? { blockedBy } : {}),
874
887
  ...(issueLinks !== undefined ? { issueLinks } : {}),
875
888
  ...(priority !== undefined ? { priority } : {}),
889
+ ...(assignees !== undefined ? { assignees } : {}),
876
890
  },
877
891
  })
878
892
  },
879
893
  ),
880
894
  defineTool(
881
895
  'tickets.update',
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.',
896
+ '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.',
883
897
  ticketsUpdateInput,
884
898
  '{ticket, blockers, build}: the updated ticket.',
885
899
  async (raw, ctx) => {
@@ -1127,6 +1141,12 @@ function mapDomainError(error: unknown): RegistryError {
1127
1141
  error: error.message,
1128
1142
  code: 'priority-unsupported',
1129
1143
  })
1144
+ if (error instanceof TicketAssigneesUnsupported)
1145
+ return new RegistryError('domain', error.message, {
1146
+ kind: 'refusal',
1147
+ error: error.message,
1148
+ code: 'assignees-unsupported',
1149
+ })
1130
1150
  if (error instanceof TicketOperationError) {
1131
1151
  return new RegistryError('domain', error.message, {
1132
1152
  kind: error.code === 'not-found' ? 'not-found' : 'refusal',
@@ -117,6 +117,9 @@ export async function createHostedOperatorSandboxService(
117
117
  env: options.env,
118
118
  repoRoot: scratch,
119
119
  repository: options.repo,
120
+ // A deployment without a token must fail typed, never spend the
121
+ // hosting platform's shared anonymous GitHub quota.
122
+ requireCredential: 'hosted operator sandbox backend',
120
123
  }))
121
124
  if (forge.remoteBranchSha === undefined) {
122
125
  throw new Error(
@@ -6,6 +6,7 @@ import {
6
6
  import { updateTicketTarget } from '../kernel/node-parent'
7
7
  import { normalizeIssueLinks, type IssueLinkInput } from '../ports/tickets/issue-links'
8
8
  import { urgentFirst } from '../ports/tickets/priority'
9
+ import { creationAssignees } from '../ports/tickets/assignees'
9
10
  import type { IssueLink } from '../ports/types'
10
11
  import { projectTicketTree, compatibleTicketSource } from '../ports/tickets/tree'
11
12
  import { readBuildFacts } from '../store/reduced-reads'
@@ -64,7 +65,7 @@ export interface OperatorTicketQueue {
64
65
  }
65
66
 
66
67
  /** 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. */
68
+ * then the source's order; `newest` is newest filed first, regardless of urgency. */
68
69
  export type OperatorTicketPage = TicketPage
69
70
 
70
71
  export interface OperatorTicketBuild {
@@ -150,7 +151,10 @@ export async function listOperatorTickets(opts: {
150
151
  nativePage ? source.listPage!(criteria, opts.page!) : source.listReady(criteria),
151
152
  opts.backend.statesFor(context, source),
152
153
  ])
153
- // Native pages arrive ordered; the fallback mirrors the dispatcher's claim order.
154
+ // Native pages arrive ordered; the fallback mirrors the dispatcher's claim
155
+ // order. listReady is in the source's filing order, so reversing it is newest
156
+ // filed first. The remote hosted client is the exception: its listing arrives
157
+ // urgent-first with no filing time, so there newest is reversed dispatch order.
154
158
  const ordered = nativePage
155
159
  ? listing.tickets
156
160
  : opts.page?.order === 'newest'
@@ -280,6 +284,7 @@ export async function mutateOperatorTicket(opts: {
280
284
  blockedBy?: string[]
281
285
  issueLinks?: IssueLinkInput[]
282
286
  priority?: import('../ports/types').TicketPriority
287
+ assignees?: string[]
283
288
  }
284
289
  | {
285
290
  kind: 'update'
@@ -298,7 +303,14 @@ export async function mutateOperatorTicket(opts: {
298
303
  if (operation.kind === 'update') await requireTicket(source, operation.id)
299
304
  const ticket =
300
305
  operation.kind === 'create'
301
- ? await createTicket(source, issueLinkDefaults({ ...operation, kind: operation.ticketKind }))
306
+ ? await createTicket(
307
+ source,
308
+ issueLinkDefaults({
309
+ ...operation,
310
+ kind: operation.ticketKind,
311
+ assignees: creationAssignees(context.tickets, operation.assignees),
312
+ }),
313
+ )
302
314
  : operation.kind === 'update'
303
315
  ? (await (operation.patch.target === undefined
304
316
  ? updateTicket(
@@ -168,6 +168,10 @@ export {
168
168
  withoutUnsupportedPriority,
169
169
  urgentFirst,
170
170
  } from '../ports/tickets/priority'
171
+ export {
172
+ TicketAssigneesUnsupported,
173
+ refuseUnsupportedAssignees,
174
+ } from '../ports/tickets/assignees'
171
175
  export {
172
176
  issueKeywordLines,
173
177
  landingMessage,
@@ -41,6 +41,9 @@ export async function createForge(opts: {
41
41
  /** Subprocess seam for the builtin GitHub forge's Git commands, including
42
42
  * `kernelExec`. Absent, the adapter spawns from the host `PATH`. */
43
43
  exec?: Exec
44
+ /** Process label for the builtin GitHub forge: refuse requests that would
45
+ * go out without a credential. Plugins and `local-git` ignore it. */
46
+ requireCredential?: string
44
47
  }): Promise<Forge> {
45
48
  const registration = resolveForgeRegistration(opts.name, opts.registry)
46
49
  if (registration.owner.kind === 'builtin') {
@@ -50,6 +53,9 @@ export async function createForge(opts: {
50
53
  repoRoot: opts.repoRoot,
51
54
  ...(opts.repository !== undefined ? { repository: opts.repository } : {}),
52
55
  ...(opts.exec !== undefined ? { exec: opts.exec } : {}),
56
+ ...(opts.requireCredential !== undefined
57
+ ? { requireCredential: opts.requireCredential }
58
+ : {}),
53
59
  })
54
60
  }
55
61
  if (opts.name === 'local-git') return new LocalGitForge({ repoRoot: opts.repoRoot })