@defrex/autobuild 0.10.1 → 0.12.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 (120) hide show
  1. package/README.md +3 -1
  2. package/SPEC.md +237 -23
  3. package/bin/ab-dispatch-kernel.ts +1 -1
  4. package/docs/architecture.md +66 -4
  5. package/docs/configuration.md +137 -19
  6. package/docs/hosted-dispatcher.md +17 -2
  7. package/docs/hosted-service.md +214 -0
  8. package/docs/mcp.md +8 -2
  9. package/docs/operator-api.md +107 -7
  10. package/docs/remote-store-protocol.md +189 -144
  11. package/docs/remote-ticket-protocol.md +111 -18
  12. package/docs/setup.md +173 -16
  13. package/docs/ticket-dependencies.md +1 -1
  14. package/package.json +7 -6
  15. package/packages/core/src/cli/attention.ts +209 -0
  16. package/packages/core/src/cli/binary.ts +3 -3
  17. package/packages/core/src/cli/configured-store.ts +17 -0
  18. package/packages/core/src/cli/connect.ts +261 -0
  19. package/packages/core/src/cli/dashboard/model.ts +8 -5
  20. package/packages/core/src/cli/dashboard/render.ts +37 -7
  21. package/packages/core/src/cli/dispatch-frontend.ts +16 -1
  22. package/packages/core/src/cli/dispatch-process.ts +25 -7
  23. package/packages/core/src/cli/dispatch.ts +247 -47
  24. package/packages/core/src/cli/dispatcher-liveness.ts +91 -0
  25. package/packages/core/src/cli/help.ts +45 -13
  26. package/packages/core/src/cli/init-validation.ts +27 -2
  27. package/packages/core/src/cli/main.ts +41 -15
  28. package/packages/core/src/cli/mcp.ts +7 -1
  29. package/packages/core/src/cli/pr-summary-publication.ts +220 -0
  30. package/packages/core/src/cli/pr-summary.ts +2 -0
  31. package/packages/core/src/cli/project-credentials.ts +132 -0
  32. package/packages/core/src/cli/repo-state.ts +15 -2
  33. package/packages/core/src/cli/repository-status.ts +45 -5
  34. package/packages/core/src/cli/self-update.ts +10 -0
  35. package/packages/core/src/cli/store-opening.ts +22 -14
  36. package/packages/core/src/cli/terminals.ts +0 -10
  37. package/packages/core/src/cli/ticket.ts +8 -1
  38. package/packages/core/src/cli/upgrade-compatibility.ts +80 -0
  39. package/packages/core/src/cli/wait.ts +84 -17
  40. package/packages/core/src/cli/watch.ts +350 -68
  41. package/packages/core/src/config/live.ts +4 -0
  42. package/packages/core/src/config/schema.ts +65 -11
  43. package/packages/core/src/connection.ts +86 -0
  44. package/packages/core/src/events/catalog.ts +10 -2
  45. package/packages/core/src/events/globs.ts +8 -3
  46. package/packages/core/src/events/payloads.ts +44 -0
  47. package/packages/core/src/events/repository.ts +64 -2
  48. package/packages/core/src/integration/harness.ts +2 -1
  49. package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +148 -83
  50. package/packages/core/src/kernel/dispatch-status.ts +9 -1
  51. package/packages/core/src/kernel/dispatcher-liveness.ts +70 -0
  52. package/packages/core/src/kernel/engine.ts +24 -0
  53. package/packages/core/src/kernel/generators/build-log.ts +10 -0
  54. package/packages/core/src/kernel/log-index.ts +17 -0
  55. package/packages/core/src/kernel/pr-summary.ts +89 -0
  56. package/packages/core/src/kernel/reducer-registry.ts +12 -0
  57. package/packages/core/src/kernel/reducer.ts +8 -0
  58. package/packages/core/src/kernel/ticket-source-health.ts +30 -0
  59. package/packages/core/src/ontology.ts +1 -0
  60. package/packages/core/src/operator/index.ts +7 -0
  61. package/packages/core/src/operator/query.ts +44 -19
  62. package/packages/core/src/operator/ticket-source-backend.ts +1 -0
  63. package/packages/core/src/operator/tickets.ts +6 -8
  64. package/packages/core/src/plugin-sdk/index.ts +1 -0
  65. package/packages/core/src/plugins/manifest.ts +5 -3
  66. package/packages/core/src/plugins/runtimes.ts +3 -1
  67. package/packages/core/src/ports/forge/fake.ts +13 -1
  68. package/packages/core/src/ports/forge/github-transport.ts +36 -1
  69. package/packages/core/src/ports/forge/github.ts +29 -5
  70. package/packages/core/src/ports/forge/local-git.ts +12 -4
  71. package/packages/core/src/ports/forge/summary-marker.ts +8 -0
  72. package/packages/core/src/ports/runner/session-env.ts +1 -0
  73. package/packages/core/src/ports/tickets/contract.ts +25 -0
  74. package/packages/core/src/ports/tickets/create.ts +11 -3
  75. package/packages/core/src/ports/tickets/fake.ts +10 -8
  76. package/packages/core/src/ports/tickets/file.ts +1 -0
  77. package/packages/core/src/ports/tickets/hosted-index.ts +0 -3
  78. package/packages/core/src/ports/tickets/linear.ts +241 -49
  79. package/packages/core/src/ports/tickets/remote-protocol.ts +3 -0
  80. package/packages/core/src/ports/tickets/remote.ts +1 -0
  81. package/packages/core/src/ports/types.ts +17 -0
  82. package/packages/core/src/ports/workspace/build-execution.ts +5 -1
  83. package/packages/core/src/ports/workspace/create.ts +11 -2
  84. package/packages/core/src/ports/workspace/distribution-archive.ts +3 -5
  85. package/packages/core/src/ports/workspace/harvest-execution.ts +3 -1
  86. package/packages/core/src/ports/workspace/local-build-execution.ts +8 -1
  87. package/packages/core/src/ports/workspace/vercel-sandbox.ts +47 -19
  88. package/packages/core/src/processes/build-execution-state.ts +1 -1
  89. package/packages/core/src/processes/build-runner.ts +87 -26
  90. package/packages/core/src/processes/dispatch-failure-budget.ts +83 -0
  91. package/packages/core/src/processes/dispatcher.ts +336 -83
  92. package/packages/core/src/processes/harvest-child.ts +1 -0
  93. package/packages/core/src/processes/harvest-execution-state.ts +19 -2
  94. package/packages/core/src/processes/harvest-runner.ts +142 -100
  95. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  96. package/packages/core/src/processes/publication-loss.ts +18 -1
  97. package/packages/core/src/processes/repo-view.ts +2 -1
  98. package/packages/core/src/store/adapter.ts +1 -0
  99. package/packages/core/src/store/contract.ts +109 -0
  100. package/packages/core/src/store/digest.ts +14 -2
  101. package/packages/core/src/store/local/store.ts +18 -5
  102. package/packages/core/src/store/remote/client.ts +1 -1
  103. package/packages/core/src/store/remote/compatibility.ts +90 -0
  104. package/packages/core/src/store/remote/credentials.ts +28 -0
  105. package/packages/core/src/store/remote/index.ts +14 -1
  106. package/packages/core/src/store/remote/protocol.ts +26 -0
  107. package/packages/core/src/store/remote/token.ts +74 -13
  108. package/packages/core/src/store/repo-state-events.ts +49 -59
  109. package/packages/core/src/store/types.ts +5 -1
  110. package/packages/core/src/testing/index.ts +7 -0
  111. package/skills/guide/SKILL.md +175 -26
  112. package/skills/guide/references/operator-api.md +135 -13
  113. package/skills/guide/references/plugin-authoring.md +10 -2
  114. package/skills/guide/references/remote-store-protocol.md +189 -144
  115. package/skills/guide/references/remote-ticket-protocol.md +111 -18
  116. package/skills/guide/references/setup.md +173 -16
  117. package/skills/guide/references/ticket-dependencies.md +1 -1
  118. package/skills/operate/SKILL.md +159 -34
  119. package/templates/hosted-service/package.json +13 -0
  120. package/templates/hosted-service/vercel.json +7 -0
@@ -31,6 +31,7 @@
31
31
  * Read-only: it appends no event, claims or renews no lease, and creates no
32
32
  * build or repository record. Output carries no ANSI, ever, in either form.
33
33
  */
34
+ import { buildNeedsAttention, mergeDecision, mergeIdentity } from './attention'
34
35
  import type { AbEvent } from '../events/catalog'
35
36
  import type { EventType } from '../events/payloads'
36
37
  import type { BuildState, PrLifecycle } from '../kernel/reducer'
@@ -54,6 +55,8 @@ import {
54
55
  encodeCursor,
55
56
  parseDurationMs,
56
57
  projectRecord,
58
+ projectAttentionRecord,
59
+ renderAttentionLine,
57
60
  renderWatchLine,
58
61
  watchSelection,
59
62
  } from './watch'
@@ -153,8 +156,8 @@ export function parseConditions(
153
156
  return { conditions, globs }
154
157
  }
155
158
 
156
- /** Does one condition body hold over a reduction? Attention is event-only. */
157
- function stateSatisfies(cond: ConditionBody, state: BuildState): boolean {
159
+ /** Does one condition body hold over a reduction? Attention includes current escalation and merge state. */
160
+ function stateSatisfies(cond: ConditionBody, state: BuildState, events: AbEvent[] = []): boolean {
158
161
  switch (cond.kind) {
159
162
  case 'status':
160
163
  return state.status === cond.status
@@ -165,7 +168,7 @@ function stateSatisfies(cond: ConditionBody, state: BuildState): boolean {
165
168
  case 'phase':
166
169
  return (state.phase ?? null) === cond.phase
167
170
  case 'attention':
168
- return false
171
+ return buildNeedsAttention(events, state)
169
172
  }
170
173
  }
171
174
 
@@ -174,9 +177,13 @@ function stateSatisfies(cond: ConditionBody, state: BuildState): boolean {
174
177
  * the start-of-command and start-of-registration checks — never during a
175
178
  * backlog replay, where only event conditions may fire.
176
179
  */
177
- export function matchState(conditions: readonly WaitCondition[], state: BuildState): string | null {
180
+ export function matchState(
181
+ conditions: readonly WaitCondition[],
182
+ state: BuildState,
183
+ events: AbEvent[] = [],
184
+ ): string | null {
178
185
  for (const { text, cond } of conditions) {
179
- if (stateSatisfies(cond, state)) return text
186
+ if (stateSatisfies(cond, state, events)) return text
180
187
  }
181
188
  return null
182
189
  }
@@ -188,9 +195,15 @@ export function matchEvent(
188
195
  event: Pick<AbEvent, 'type'>,
189
196
  conditions: readonly WaitCondition[],
190
197
  globs: readonly EventGlob[],
198
+ events: AbEvent[] = [],
191
199
  ): string | null {
192
200
  for (const { text, cond } of conditions) {
193
- if (cond.kind === 'attention' && isAttentionEvent(event.type)) return text
201
+ if (
202
+ cond.kind === 'attention' &&
203
+ (isAttentionEvent(event.type) ||
204
+ (events.length > 0 && mergeDecision(events, new Date(0)) !== null))
205
+ )
206
+ return text
194
207
  }
195
208
  for (const { regex, text } of globs) {
196
209
  if (regex.test(event.type)) return text
@@ -209,10 +222,16 @@ function matchFirst(
209
222
  state: BuildState,
210
223
  conditions: readonly WaitCondition[],
211
224
  globs: readonly EventGlob[],
225
+ events: AbEvent[] = [],
212
226
  ): string | null {
213
227
  for (const { text, cond } of conditions) {
214
- if (stateSatisfies(cond, state)) return text
215
- if (cond.kind === 'attention' && isAttentionEvent(event.type)) return text
228
+ if (stateSatisfies(cond, state, events)) return text
229
+ if (
230
+ cond.kind === 'attention' &&
231
+ (isAttentionEvent(event.type) ||
232
+ (events.length > 0 && mergeDecision(events, new Date(0)) !== null))
233
+ )
234
+ return text
216
235
  }
217
236
  for (const { regex, text } of globs) {
218
237
  if (regex.test(event.type)) return text
@@ -305,11 +324,12 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
305
324
  const interval = intervalMs ?? watchSelection(storeRef).intervalMs
306
325
 
307
326
  // Decode --since before any read: a foreign cursor is rejected outright.
308
- const sinceStreams =
327
+ const resumedCursor =
309
328
  opts.since !== undefined
310
329
  ? decodeCursor(opts.since, { store: storeRef, repo }, { verb: 'wait', usage: WAIT_USAGE })
311
- .streams
312
- : {}
330
+ : undefined
331
+ const sinceStreams = resumedCursor?.streams ?? {}
332
+ const deliveredAttention = new Set(resumedCursor?.deliveredAttention ?? [])
313
333
 
314
334
  const identity = normalizeGitRemoteUrl(repo)
315
335
  const mine = (record: BuildRecord): boolean =>
@@ -322,17 +342,40 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
322
342
  const positions: Record<string, number> = { ...sinceStreams }
323
343
 
324
344
  const encodeCurrent = (): string =>
325
- encodeCursor({ v: 1, store: storeRef, repo, streams: { ...positions } })
345
+ encodeCursor({
346
+ v: 1,
347
+ store: storeRef,
348
+ repo,
349
+ streams: { ...positions },
350
+ ...(resumedCursor?.lostRuns ? { lostRuns: resumedCursor.lostRuns } : {}),
351
+ deliveredAttention: [...deliveredAttention],
352
+ })
326
353
 
327
354
  /** The one success/terminal record. Exit 0 is contractually tied to
328
355
  * exactly one condition-satisfying record; the exit-2 record carries
329
356
  * `condition` null so the caller can see how the build ended. */
330
357
  const finish = (condition: string | null, event: AbEvent, state: BuildState): number => {
331
- const record = { ...projectRecord(event, state, encodeCurrent()), condition }
358
+ const observation =
359
+ condition === 'attention' && event.type !== 'escalation.raised'
360
+ ? mergeDecision(
361
+ streams.get(event.build)?.events.filter((e) => e.seq <= event.seq) ?? [],
362
+ now(),
363
+ state,
364
+ )
365
+ : null
366
+ if (observation) deliveredAttention.add(mergeIdentity(event.build, observation.pr.number))
367
+ const record = {
368
+ ...(observation
369
+ ? projectAttentionRecord(observation, state, encodeCurrent(), { build: event.build })
370
+ : projectRecord(event, state, encodeCurrent())),
371
+ condition,
372
+ }
332
373
  if (json) {
333
374
  opts.stdout(JSON.stringify(record))
334
375
  } else {
335
- const line = renderWatchLine(event, state)
376
+ const line = observation
377
+ ? renderAttentionLine(observation, event.build)
378
+ : renderWatchLine(event, state)
336
379
  opts.stdout(condition === null ? line : `${line} (${condition})`)
337
380
  }
338
381
  return condition === null ? 2 : 0
@@ -351,6 +394,15 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
351
394
  if (satisfied === null) satisfied = { event, state, condition }
352
395
  }
353
396
 
397
+ const eventConditions = (event: AbEvent, prefix: AbEvent[]): readonly WaitCondition[] => {
398
+ if (event.type === 'escalation.raised') return conditions
399
+ const observation = mergeDecision(prefix, now())
400
+ return observation &&
401
+ !deliveredAttention.has(mergeIdentity(event.build, observation.pr.number))
402
+ ? conditions
403
+ : conditions.filter(({ cond }) => cond.kind !== 'attention')
404
+ }
405
+
354
406
  const registerStream = (slug: string, events: AbEvent[], named: boolean): WaitStream => {
355
407
  const state = reduceBuild(events)
356
408
  const stream: WaitStream = {
@@ -370,7 +422,7 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
370
422
  * latest event. Not cursor-relative — `--since` does not suppress it. */
371
423
  const checkRegistrationState = (stream: WaitStream): void => {
372
424
  const state = reduceBuild(stream.events)
373
- const condition = matchState(conditions, state)
425
+ const condition = matchState(conditions, state, stream.events)
374
426
  if (condition !== null && stream.events.length > 0) {
375
427
  match(stream.events.at(-1)!, state, condition)
376
428
  }
@@ -401,12 +453,20 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
401
453
  // the reduction of the prefix ENDING at that event, never the
402
454
  // reduction of the full loaded prefix.
403
455
  const replay: AbEvent[] = events.filter((event) => event.seq <= resumeSeq)
456
+ if (resumedCursor?.deliveredAttention === undefined) {
457
+ const historical: AbEvent[] = []
458
+ for (const event of replay) {
459
+ historical.push(event)
460
+ const observation = mergeDecision(historical, now())
461
+ if (observation) deliveredAttention.add(mergeIdentity(slug, observation.pr.number))
462
+ }
463
+ }
404
464
  for (const event of events) {
405
465
  if (event.seq <= resumeSeq) continue
406
466
  replay.push(event)
407
467
  stream.lastSeq = event.seq
408
468
  positions[slug] = event.seq
409
- const condition = matchEvent(event, conditions, globs)
469
+ const condition = matchEvent(event, eventConditions(event, replay), globs, replay)
410
470
  if (condition !== null) {
411
471
  match(event, reduceBuild(replay), condition)
412
472
  break
@@ -470,7 +530,13 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
470
530
  positions[stream.slug] = event.seq
471
531
  const state = reduceBuild(stream.events)
472
532
  stream.status = state.status
473
- const condition = matchFirst(event, state, conditions, globs)
533
+ const condition = matchFirst(
534
+ event,
535
+ state,
536
+ eventConditions(event, stream.events),
537
+ globs,
538
+ stream.events,
539
+ )
474
540
  if (condition !== null) {
475
541
  match(event, state, condition)
476
542
  return
@@ -564,6 +630,7 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
564
630
  // Cursor streams that are no longer named resume anyway: finishing
565
631
  // their backlog is what makes a resumed wait lossless.
566
632
  for (const key of Object.keys(sinceStreams)) {
633
+ if (key === '#repo') continue
567
634
  await trackBuild(key, sinceStreams[key])
568
635
  if (hasMatch()) return finishSatisfied()
569
636
  }