@defrex/autobuild 1.0.0-beta.3 → 1.0.0-beta.4

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 (130) hide show
  1. package/SPEC.md +317 -20
  2. package/bin/ab-dispatch-generation.ts +93 -0
  3. package/docs/answering-blocked-builds.md +21 -3
  4. package/docs/architecture.md +166 -7
  5. package/docs/configuration.md +173 -5
  6. package/docs/integration-tree.md +87 -2
  7. package/docs/integration.md +54 -0
  8. package/docs/operator-api.md +58 -5
  9. package/docs/remote-store-protocol.md +4 -1
  10. package/docs/restacking.md +4 -1
  11. package/docs/setup.md +20 -0
  12. package/docs/spec-standard.md +23 -5
  13. package/package.json +3 -3
  14. package/packages/core/src/cli/artifact.ts +5 -4
  15. package/packages/core/src/cli/attention.ts +2 -0
  16. package/packages/core/src/cli/binary-direct.ts +190 -0
  17. package/packages/core/src/cli/binary-lifecycle.ts +46 -0
  18. package/packages/core/src/cli/binary.ts +24 -210
  19. package/packages/core/src/cli/build-control.ts +105 -2
  20. package/packages/core/src/cli/context.ts +41 -1
  21. package/packages/core/src/cli/dashboard/hand-pushed.ts +24 -0
  22. package/packages/core/src/cli/dashboard/handoff.ts +64 -0
  23. package/packages/core/src/cli/dashboard/integration-detail.ts +3 -0
  24. package/packages/core/src/cli/dashboard/model.ts +34 -10
  25. package/packages/core/src/cli/dashboard/render.ts +24 -2
  26. package/packages/core/src/cli/dashboard/rollback.ts +30 -0
  27. package/packages/core/src/cli/dispatch-args.ts +53 -0
  28. package/packages/core/src/cli/dispatch-crash-budget.ts +15 -0
  29. package/packages/core/src/cli/dispatch-frontend.ts +52 -5
  30. package/packages/core/src/cli/dispatch-handoff.ts +276 -0
  31. package/packages/core/src/cli/dispatch-launch-contract.ts +170 -0
  32. package/packages/core/src/cli/dispatch-launcher.ts +580 -0
  33. package/packages/core/src/cli/dispatch-parent-watch.ts +44 -0
  34. package/packages/core/src/cli/dispatch-preflight.ts +272 -0
  35. package/packages/core/src/cli/dispatch-presentation-job.ts +46 -0
  36. package/packages/core/src/cli/dispatch-presentation-ownership.ts +9 -0
  37. package/packages/core/src/cli/dispatch-process.ts +22 -90
  38. package/packages/core/src/cli/dispatch-readiness.ts +47 -0
  39. package/packages/core/src/cli/dispatch-repository-feed.ts +5 -1
  40. package/packages/core/src/cli/dispatch-runtime-cache.ts +522 -0
  41. package/packages/core/src/cli/dispatch-runtime-dependencies.ts +291 -0
  42. package/packages/core/src/cli/dispatch-runtime-use.ts +336 -0
  43. package/packages/core/src/cli/dispatch-upgrade-controller.ts +221 -0
  44. package/packages/core/src/cli/dispatch-upgrade-install.ts +258 -0
  45. package/packages/core/src/cli/dispatch-upgrade-source.ts +309 -0
  46. package/packages/core/src/cli/dispatch-upgrade-target.ts +190 -0
  47. package/packages/core/src/cli/dispatch.ts +604 -60
  48. package/packages/core/src/cli/dispatcher-liveness.ts +1 -1
  49. package/packages/core/src/cli/harvest.ts +28 -11
  50. package/packages/core/src/cli/help.ts +6 -3
  51. package/packages/core/src/cli/installation.ts +5 -3
  52. package/packages/core/src/cli/main-checkout.ts +59 -0
  53. package/packages/core/src/cli/main.ts +15 -45
  54. package/packages/core/src/cli/node-verification-provenance.ts +97 -0
  55. package/packages/core/src/cli/repo-state.ts +3 -58
  56. package/packages/core/src/cli/repository-status.ts +67 -3
  57. package/packages/core/src/cli/runtime-spawn.ts +16 -0
  58. package/packages/core/src/cli/status.ts +57 -3
  59. package/packages/core/src/cli/upgrade-followup.ts +25 -0
  60. package/packages/core/src/cli/wait.ts +3 -0
  61. package/packages/core/src/cli/watch.ts +7 -0
  62. package/packages/core/src/config/live.ts +1 -0
  63. package/packages/core/src/config/schema.ts +8 -4
  64. package/packages/core/src/distribution-packaging.ts +116 -0
  65. package/packages/core/src/events/catalog.ts +6 -0
  66. package/packages/core/src/events/payloads.ts +53 -9
  67. package/packages/core/src/events/policy.ts +25 -0
  68. package/packages/core/src/events/repository.ts +184 -4
  69. package/packages/core/src/events/runtime.ts +16 -0
  70. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +2515 -78
  71. package/packages/core/src/kernel/dispatch-drain-recovery.ts +121 -0
  72. package/packages/core/src/kernel/dispatch-status.ts +4 -2
  73. package/packages/core/src/kernel/dispatch-upgrade.ts +171 -0
  74. package/packages/core/src/kernel/dispatcher-liveness.ts +7 -0
  75. package/packages/core/src/kernel/generators/repository-journals.ts +82 -0
  76. package/packages/core/src/kernel/guarded-forge.ts +1 -1
  77. package/packages/core/src/kernel/harvest.ts +98 -4
  78. package/packages/core/src/kernel/integration-attention.ts +20 -0
  79. package/packages/core/src/kernel/integration-state.ts +80 -11
  80. package/packages/core/src/kernel/landing-readiness.ts +6 -1
  81. package/packages/core/src/kernel/mixed-version.ts +34 -0
  82. package/packages/core/src/kernel/node-polling.ts +160 -0
  83. package/packages/core/src/kernel/read-facts.ts +40 -5
  84. package/packages/core/src/kernel/reducer-registry.ts +3 -0
  85. package/packages/core/src/kernel/reducer.ts +75 -14
  86. package/packages/core/src/kernel/service-facts.ts +11 -4
  87. package/packages/core/src/operator/presentation.ts +7 -0
  88. package/packages/core/src/operator/query.ts +6 -2
  89. package/packages/core/src/operator/registry.ts +1 -1
  90. package/packages/core/src/plugins/load.ts +4 -1
  91. package/packages/core/src/plugins/runtime-snapshot.ts +128 -0
  92. package/packages/core/src/ports/forge/contract.ts +29 -0
  93. package/packages/core/src/ports/forge/github.ts +189 -61
  94. package/packages/core/src/ports/forge-failure.ts +1 -0
  95. package/packages/core/src/ports/forge-telemetry.ts +3 -0
  96. package/packages/core/src/ports/runner/session-env.ts +1 -0
  97. package/packages/core/src/ports/types.ts +10 -0
  98. package/packages/core/src/ports/workspace/distribution-archive.ts +22 -149
  99. package/packages/core/src/ports/workspace/distribution-release.ts +56 -0
  100. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  101. package/packages/core/src/ports/workspace/local-build-execution.ts +37 -17
  102. package/packages/core/src/processes/build-child-exit.ts +5 -26
  103. package/packages/core/src/processes/build-runner.ts +81 -11
  104. package/packages/core/src/processes/dispatcher.ts +254 -23
  105. package/packages/core/src/processes/execution-no-progress.ts +6 -0
  106. package/packages/core/src/processes/execution-relaunch.ts +30 -0
  107. package/packages/core/src/processes/execution-settlement.ts +16 -7
  108. package/packages/core/src/processes/harvest-runner.ts +328 -292
  109. package/packages/core/src/processes/process-group-reaper.ts +17 -10
  110. package/packages/core/src/runtime-identity.ts +22 -3
  111. package/packages/core/src/store/contract.ts +153 -0
  112. package/packages/core/src/store/local/store.ts +197 -72
  113. package/packages/core/src/store/reduced-reads.ts +8 -0
  114. package/packages/core/src/store/reducer-value-shapes.json +5783 -3305
  115. package/packages/core/src/store/remote/client.ts +43 -0
  116. package/packages/core/src/store/repo-state-events.ts +20 -3
  117. package/packages/core/src/store/types.ts +7 -0
  118. package/skills/guide/SKILL.md +231 -23
  119. package/skills/guide/references/integration-tree.md +87 -2
  120. package/skills/guide/references/operator-api.md +53 -4
  121. package/skills/guide/references/plugin-authoring.md +45 -4
  122. package/skills/guide/references/remote-store-protocol.md +4 -1
  123. package/skills/guide/references/restacking.md +4 -1
  124. package/skills/guide/references/setup.md +20 -0
  125. package/skills/guide/references/spec-standard.md +23 -5
  126. package/skills/harvest/SKILL.md +4 -0
  127. package/skills/harvest-review/SKILL.md +4 -0
  128. package/skills/operate/SKILL.md +78 -8
  129. package/skills/spec/SKILL.md +19 -1
  130. package/skills/tickets/SKILL.md +19 -0
@@ -1,3 +1,5 @@
1
+ import { nativeSessionHandleSchema } from './native-session'
2
+ import { runtimeIdentitySchema } from './runtime'
1
3
  import { stampCompatibility, type CompatibilityMetadata, repositoryEventPolicy } from './policy'
2
4
  import { hardReadinessKeys } from '../ports/forge/readiness'
3
5
  /**
@@ -28,7 +30,7 @@ import {
28
30
  type ActorKind,
29
31
  } from './envelope'
30
32
  import { EventValidationError } from './catalog'
31
- import { providerAttemptsSchema, providerSubstitutionSchema } from './payloads'
33
+ import { providerAttemptSchema } from './payloads'
32
34
 
33
35
  const round = z.number().int().positive()
34
36
  const attempt = z.number().int().positive()
@@ -117,6 +119,27 @@ const restartRequiredConfigPathsSchema = z
117
119
  })
118
120
  })
119
121
 
122
+ const upgradeTargetSchema = z.strictObject({
123
+ mode: z.enum(['pinned', 'installed', 'source']),
124
+ key: z.string().min(1),
125
+ source: z.string().min(1),
126
+ version: z.string().optional(),
127
+ base: z.string().optional(),
128
+ sha: z.string().optional(),
129
+ })
130
+ const upgradeIdentitySchema = z.strictObject({
131
+ correlation: z.string().min(1),
132
+ run: dispatchRun,
133
+ lineage: z.string().min(1),
134
+ from: runtimeIdentitySchema,
135
+ target: upgradeTargetSchema,
136
+ })
137
+ const handoffSchema = upgradeIdentitySchema.extend({
138
+ to: runtimeIdentitySchema,
139
+ root: z.string().min(1),
140
+ cacheId: z.string().min(1),
141
+ })
142
+
120
143
  export const harvestEventPayloadSchemas = {
121
144
  // Repository-wide operator control. Requests are human commands; paused /
122
145
  // resumed are kernel acknowledgements made only at workflow boundaries.
@@ -202,7 +225,54 @@ export const harvestEventPayloadSchemas = {
202
225
  artifact: artifactRefSchema.optional(),
203
226
  detail: z.string().optional(),
204
227
  }),
228
+ 'harvest.session.native-handle-recorded': z.strictObject({
229
+ run: z.string().min(1),
230
+ session: z.string().min(1),
231
+ handle: nativeSessionHandleSchema,
232
+ }),
233
+ 'harvest.session.suspended': z.strictObject({
234
+ run: z.string().min(1),
235
+ session: z.string().min(1),
236
+ cause: z.enum(['shutdown', 'cutover']),
237
+ transcript: artifactRefSchema,
238
+ usage: z
239
+ .strictObject({
240
+ inputTokens: z.number().int().nonnegative(),
241
+ outputTokens: z.number().int().nonnegative(),
242
+ turns: z.number().int().nonnegative(),
243
+ })
244
+ .optional(),
245
+ }),
246
+ 'harvest.session.resumed': z.strictObject({
247
+ run: z.string().min(1),
248
+ session: z.string().min(1),
249
+ predecessor: z.string().min(1),
250
+ root: z.string().min(1),
251
+ handle: nativeSessionHandleSchema,
252
+ }),
253
+ 'harvest.session.resume-fallback': z.strictObject({
254
+ run: z.string().min(1),
255
+ session: z.string().min(1),
256
+ reason: z.enum([
257
+ 'missing-handle',
258
+ 'changed-route',
259
+ 'unsupported',
260
+ 'wrong-runner',
261
+ 'wrong-host',
262
+ 'wrong-workspace',
263
+ 'missing-state',
264
+ ]),
265
+ message: z.string().min(1),
266
+ }),
205
267
  'harvest.session.started': z.strictObject({
268
+ continuation: z
269
+ .strictObject({
270
+ predecessor: z.string().min(1),
271
+ root: z.string().min(1),
272
+ handle: nativeSessionHandleSchema.optional(),
273
+ cause: z.enum(['shutdown', 'cutover', 'runner-loss']),
274
+ })
275
+ .optional(),
206
276
  run: z.string().min(1),
207
277
  session: z.string().min(1),
208
278
  role: z.enum(['harvest', 'harvest-review']),
@@ -215,7 +285,16 @@ export const harvestEventPayloadSchemas = {
215
285
  /** Stream id this session's live view writes to (SPEC §9, session
216
286
  * streams). Optional only so historical journals replay unchanged. */
217
287
  stream: z.string().min(1).optional(),
218
- substitution: providerSubstitutionSchema.optional(),
288
+ // Native continuation can try a configured alternate before index zero.
289
+ substitution: z
290
+ .strictObject({
291
+ failed: providerAttemptSchema,
292
+ selectedIndex: z.number().int().nonnegative(),
293
+ })
294
+ .refine((value) => value.selectedIndex !== value.failed.index, {
295
+ message: 'substitution must select a different configured target',
296
+ })
297
+ .optional(),
219
298
  }),
220
299
  'harvest.session.ended': z.strictObject({
221
300
  run: z.string().min(1),
@@ -275,7 +354,14 @@ export const harvestEventPayloadSchemas = {
275
354
  attempt,
276
355
  error: z.string().min(1),
277
356
  willRetry: z.boolean(),
278
- providerAttempts: providerAttemptsSchema.optional(),
357
+ providerAttempts: z
358
+ .array(providerAttemptSchema)
359
+ .min(1)
360
+ .refine(
361
+ (attempts) => new Set(attempts.map((attempt) => attempt.index)).size === attempts.length,
362
+ { message: 'provider attempts must name distinct configured targets' },
363
+ )
364
+ .optional(),
279
365
  }),
280
366
  } as const
281
367
 
@@ -386,8 +472,83 @@ export const dispatcherStatusEventPayloadSchemas = {
386
472
  }),
387
473
  /** A terminal frontend follows exactly one run. The referenced artifact is
388
474
  * the composed Config the kernel is actually using, never an on-disk guess. */
475
+ 'dispatcher.upgrade-target-resolved': z.strictObject({
476
+ run: dispatchRun,
477
+ lineage: z.string().min(1),
478
+ target: upgradeTargetSchema,
479
+ }),
480
+ 'dispatcher.target-prepared': handoffSchema,
481
+ 'dispatcher.yield-requested': handoffSchema.extend({
482
+ successor: dispatchRun,
483
+ mode: z.enum(['drain', 'cutover']),
484
+ evidence: z.string().min(1),
485
+ }),
486
+ 'dispatcher.terminal-released': handoffSchema,
487
+ 'dispatcher.takeover': handoffSchema.extend({ successor: dispatchRun }),
488
+ 'dispatcher.drain-settled': handoffSchema.extend({
489
+ slug: z.string().min(1),
490
+ instance: z.string().min(1),
491
+ outcome: z.enum(['drained', 'suspended', 'unknown']),
492
+ }),
493
+ 'dispatcher.drain-deadline': handoffSchema.extend({ deadline: z.iso.datetime() }),
494
+ 'dispatcher.upgrade-detected': upgradeIdentitySchema,
495
+ 'dispatcher.upgrade-failed': upgradeIdentitySchema.extend({ reason: z.string().min(1) }),
496
+ 'dispatcher.runtime-rolled-back': z.strictObject({
497
+ correlation: dispatchRun,
498
+ run: dispatchRun,
499
+ lineage: dispatchRun,
500
+ predecessor: dispatchRun,
501
+ successor: dispatchRun,
502
+ handoff: dispatchRun,
503
+ takeoverAt: z.iso.datetime(),
504
+ failures: z.literal(3),
505
+ failed: runtimeIdentitySchema,
506
+ restored: runtimeIdentitySchema,
507
+ failedRoot: z.string().min(1),
508
+ restoredRoot: z.string().min(1),
509
+ target: upgradeTargetSchema,
510
+ reason: z.string().min(1),
511
+ }),
512
+ 'dispatcher.rollback-hold-cleared': z.strictObject({
513
+ correlation: dispatchRun,
514
+ run: dispatchRun,
515
+ lineage: dispatchRun,
516
+ target: upgradeTargetSchema,
517
+ }),
518
+ 'dispatcher.handoff-started': handoffSchema.extend({
519
+ remoteBuilds: z
520
+ .array(
521
+ z.strictObject({
522
+ slug: z.string().min(1),
523
+ instance: z.string().min(1),
524
+ runtime: runtimeIdentitySchema.optional(),
525
+ }),
526
+ )
527
+ .optional(),
528
+ successor: dispatchRun.optional(),
529
+ mode: z.enum(['drain', 'cutover']).optional(),
530
+ startedAt: z.iso.datetime().optional(),
531
+ deadline: z.iso.datetime().optional(),
532
+ builds: z
533
+ .array(z.strictObject({ slug: z.string().min(1), instance: z.string().min(1) }))
534
+ .optional(),
535
+ }),
536
+ 'dispatcher.handoff-completed': handoffSchema.extend({
537
+ successor: dispatchRun,
538
+ mode: z.enum(['drain', 'cutover']).optional(),
539
+ startedAt: z.iso.datetime().optional(),
540
+ endedAt: z.iso.datetime().optional(),
541
+ drained: z.number().int().nonnegative().optional(),
542
+ suspended: z.number().int().nonnegative().optional(),
543
+ }),
544
+ 'dispatcher.runtime-recorded': z.strictObject({
545
+ run: dispatchRun,
546
+ startedSeq: z.number().int().positive(),
547
+ runtime: runtimeIdentitySchema,
548
+ }),
389
549
  'dispatcher.run-started': z.strictObject({
390
550
  run: dispatchRun,
551
+ lineage: dispatchRun.optional(),
391
552
  pid: z.number().int().positive(),
392
553
  host: z.string().trim().min(1).optional(),
393
554
  effectiveConfig: artifactRefSchema,
@@ -447,7 +608,7 @@ export const dispatcherStatusEventPayloadSchemas = {
447
608
  'dispatcher.runner-settled': z.strictObject({
448
609
  run: dispatchRun,
449
610
  slug: z.string().min(1),
450
- outcome: z.enum(['parked', 'lease-held', 'launch-failed', 'failed']),
611
+ outcome: z.enum(['parked', 'lease-held', 'launch-failed', 'failed', 'relaunch']),
451
612
  status: z.string().min(1).optional(),
452
613
  error: z.string().min(1).optional(),
453
614
  }),
@@ -650,6 +811,11 @@ const allowedActorKinds: Record<RepositoryEventType, readonly ActorKind[]> = {
650
811
  'harvest.step.completed': ['kernel'],
651
812
  'harvest.session.started': ['kernel'],
652
813
  'harvest.session.ended': ['kernel'],
814
+ 'harvest.session.native-handle-recorded': ['kernel'],
815
+ 'harvest.session.suspended': ['kernel'],
816
+ 'harvest.session.resumed': ['kernel'],
817
+ 'harvest.session.resume-fallback': ['kernel'],
818
+
653
819
  'harvest.proposals.submitted': ['agent'],
654
820
  'harvest.review.verdict': ['agent'],
655
821
  'harvest.proposal.id-reserved': ['kernel'],
@@ -669,6 +835,20 @@ const allowedActorKinds: Record<RepositoryEventType, readonly ActorKind[]> = {
669
835
  'orchestrator.sandbox.reset': ['human'],
670
836
  'orchestrator.sandbox.published': ['human'],
671
837
  'orchestrator.sandbox.publish-failed': ['human'],
838
+ 'dispatcher.upgrade-target-resolved': ['dispatcher'],
839
+ 'dispatcher.target-prepared': ['dispatcher'],
840
+ 'dispatcher.yield-requested': ['dispatcher'],
841
+ 'dispatcher.terminal-released': ['dispatcher'],
842
+ 'dispatcher.takeover': ['dispatcher'],
843
+ 'dispatcher.drain-settled': ['dispatcher'],
844
+ 'dispatcher.drain-deadline': ['dispatcher'],
845
+ 'dispatcher.upgrade-detected': ['dispatcher'],
846
+ 'dispatcher.upgrade-failed': ['dispatcher'],
847
+ 'dispatcher.runtime-rolled-back': ['dispatcher'],
848
+ 'dispatcher.rollback-hold-cleared': ['dispatcher'],
849
+ 'dispatcher.handoff-started': ['dispatcher'],
850
+ 'dispatcher.handoff-completed': ['dispatcher'],
851
+ 'dispatcher.runtime-recorded': ['dispatcher'],
672
852
  'dispatcher.run-started': ['dispatcher'],
673
853
  'dispatcher.stop-requested': ['dispatcher'],
674
854
  'dispatcher.run-stopped': ['dispatcher'],
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod'
2
+
3
+ export const runtimeIdentitySchema = z.strictObject({
4
+ version: z.string().trim().min(1),
5
+ commit: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64}|unknown)$/),
6
+ source: z.strictObject({
7
+ kind: z.enum(['source', 'package']),
8
+ location: z.string().trim().min(1),
9
+ }),
10
+ })
11
+ export type RuntimeIdentity = z.infer<typeof runtimeIdentitySchema>
12
+ export function formatRuntimeIdentity(runtime: RuntimeIdentity | null): string {
13
+ return runtime === null
14
+ ? 'runtime unrecorded'
15
+ : `autobuild ${runtime.version}; commit ${runtime.commit}; ${runtime.source.kind} ${runtime.source.location}`
16
+ }