@defrex/autobuild 0.14.0 → 1.0.0-beta.1

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 (173) hide show
  1. package/README.md +13 -6
  2. package/SPEC.md +657 -100
  3. package/docs/architecture.md +230 -5
  4. package/docs/assets/headline-wide.png +0 -0
  5. package/docs/configuration.md +118 -14
  6. package/docs/hosted-service.md +18 -0
  7. package/docs/integration-tree.md +117 -0
  8. package/docs/landing-policy.md +150 -0
  9. package/docs/mcp.md +24 -0
  10. package/docs/migration-1.0.md +68 -0
  11. package/docs/operator-api.md +19 -8
  12. package/docs/remote-store-protocol.md +30 -7
  13. package/docs/remote-ticket-protocol.md +26 -5
  14. package/docs/restacking.md +79 -0
  15. package/docs/setup.md +53 -6
  16. package/docs/ticket-dependencies.md +69 -0
  17. package/docs/ticket-migration.md +8 -0
  18. package/package.json +3 -3
  19. package/packages/core/src/cli/attention.ts +25 -2
  20. package/packages/core/src/cli/build-control.ts +65 -41
  21. package/packages/core/src/cli/context.ts +54 -2
  22. package/packages/core/src/cli/dashboard/actions.ts +6 -3
  23. package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
  24. package/packages/core/src/cli/dashboard/live.ts +5 -0
  25. package/packages/core/src/cli/dashboard/model.ts +142 -18
  26. package/packages/core/src/cli/dashboard/poll.ts +15 -9
  27. package/packages/core/src/cli/dashboard/refresh.ts +183 -0
  28. package/packages/core/src/cli/dashboard/render.ts +78 -28
  29. package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
  30. package/packages/core/src/cli/dashboard/selection.ts +7 -1
  31. package/packages/core/src/cli/dashboard/tree.ts +107 -0
  32. package/packages/core/src/cli/dispatch-frontend.ts +156 -105
  33. package/packages/core/src/cli/dispatch.ts +257 -139
  34. package/packages/core/src/cli/dispatcher-liveness.ts +15 -2
  35. package/packages/core/src/cli/help.ts +52 -33
  36. package/packages/core/src/cli/init-validation.ts +43 -2
  37. package/packages/core/src/cli/keyboard.ts +6 -0
  38. package/packages/core/src/cli/landings.ts +18 -0
  39. package/packages/core/src/cli/main.ts +49 -15
  40. package/packages/core/src/cli/mcp.ts +9 -0
  41. package/packages/core/src/cli/publication-settlement.ts +168 -2
  42. package/packages/core/src/cli/repository-status.ts +11 -0
  43. package/packages/core/src/cli/status.ts +72 -5
  44. package/packages/core/src/cli/terminal-restore.ts +54 -0
  45. package/packages/core/src/cli/terminal.ts +16 -2
  46. package/packages/core/src/cli/terminals.ts +98 -79
  47. package/packages/core/src/cli/ticket-editor.ts +10 -3
  48. package/packages/core/src/cli/ticket.ts +113 -18
  49. package/packages/core/src/cli/upgrade-commit.ts +4 -0
  50. package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
  51. package/packages/core/src/cli/upgrade-landing.ts +69 -0
  52. package/packages/core/src/cli/upgrade.ts +16 -0
  53. package/packages/core/src/cli/wait.ts +115 -19
  54. package/packages/core/src/cli/watch.ts +51 -12
  55. package/packages/core/src/config/landing.ts +22 -0
  56. package/packages/core/src/config/live.ts +1 -0
  57. package/packages/core/src/config/schema.ts +3 -0
  58. package/packages/core/src/events/catalog.ts +48 -3
  59. package/packages/core/src/events/payloads.ts +295 -6
  60. package/packages/core/src/events/repository.ts +31 -0
  61. package/packages/core/src/integration/harness.ts +10 -0
  62. package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +1030 -239
  63. package/packages/core/src/kernel/auto-merge-default.ts +1 -0
  64. package/packages/core/src/kernel/auto-merge.ts +12 -3
  65. package/packages/core/src/kernel/build-identity.ts +94 -0
  66. package/packages/core/src/kernel/change-presence.ts +179 -0
  67. package/packages/core/src/kernel/dispatch-status.ts +17 -1
  68. package/packages/core/src/kernel/engine.ts +89 -2
  69. package/packages/core/src/kernel/generators/build-log.ts +23 -0
  70. package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
  71. package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
  72. package/packages/core/src/kernel/generators/repository-journals.ts +11 -0
  73. package/packages/core/src/kernel/integration-completeness.ts +81 -0
  74. package/packages/core/src/kernel/integration-landing.ts +263 -0
  75. package/packages/core/src/kernel/integration-stack.ts +36 -0
  76. package/packages/core/src/kernel/integration-state.ts +135 -0
  77. package/packages/core/src/kernel/landing-policy.ts +47 -0
  78. package/packages/core/src/kernel/landing-publication.ts +41 -0
  79. package/packages/core/src/kernel/landing-readiness.ts +67 -0
  80. package/packages/core/src/kernel/landing-state.ts +96 -0
  81. package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
  82. package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
  83. package/packages/core/src/kernel/log-index.ts +35 -5
  84. package/packages/core/src/kernel/node-landing.ts +439 -0
  85. package/packages/core/src/kernel/node-parent.ts +184 -0
  86. package/packages/core/src/kernel/node-restack-state.ts +191 -0
  87. package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
  88. package/packages/core/src/kernel/node-restack.ts +274 -0
  89. package/packages/core/src/kernel/read-facts.ts +70 -3
  90. package/packages/core/src/kernel/reconcile-head.ts +51 -0
  91. package/packages/core/src/kernel/reconcile-restack.ts +560 -0
  92. package/packages/core/src/kernel/reducer-registry.ts +16 -0
  93. package/packages/core/src/kernel/reducer.ts +121 -6
  94. package/packages/core/src/kernel/snapshot-parent.ts +33 -0
  95. package/packages/core/src/ontology.ts +9 -1
  96. package/packages/core/src/operator/annotations.ts +12 -0
  97. package/packages/core/src/operator/control.ts +6 -0
  98. package/packages/core/src/operator/index.ts +4 -0
  99. package/packages/core/src/operator/landings.ts +35 -0
  100. package/packages/core/src/operator/presentation.ts +1 -0
  101. package/packages/core/src/operator/protocol.ts +12 -3
  102. package/packages/core/src/operator/query.ts +3 -1
  103. package/packages/core/src/operator/registry.ts +48 -19
  104. package/packages/core/src/operator/requests.ts +1 -8
  105. package/packages/core/src/operator/tickets.ts +55 -9
  106. package/packages/core/src/plugins/load.ts +3 -4
  107. package/packages/core/src/ports/forge/contract.ts +91 -3
  108. package/packages/core/src/ports/forge/fake.ts +142 -4
  109. package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
  110. package/packages/core/src/ports/forge/github-readiness.ts +421 -0
  111. package/packages/core/src/ports/forge/github.ts +631 -35
  112. package/packages/core/src/ports/forge/local-git.ts +119 -5
  113. package/packages/core/src/ports/forge/readiness.ts +99 -0
  114. package/packages/core/src/ports/tickets/contract.ts +41 -0
  115. package/packages/core/src/ports/tickets/create.ts +8 -1
  116. package/packages/core/src/ports/tickets/fake.ts +32 -1
  117. package/packages/core/src/ports/tickets/file-codec.ts +7 -0
  118. package/packages/core/src/ports/tickets/file.ts +18 -1
  119. package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
  120. package/packages/core/src/ports/tickets/linear.ts +124 -4
  121. package/packages/core/src/ports/tickets/migration.ts +25 -1
  122. package/packages/core/src/ports/tickets/operations.ts +7 -2
  123. package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
  124. package/packages/core/src/ports/tickets/remote.ts +10 -1
  125. package/packages/core/src/ports/tickets/revision.ts +3 -1
  126. package/packages/core/src/ports/tickets/tree.ts +148 -0
  127. package/packages/core/src/ports/tickets/update.ts +15 -2
  128. package/packages/core/src/ports/types.ts +135 -5
  129. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  130. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
  131. package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
  132. package/packages/core/src/processes/build-runner.ts +530 -23
  133. package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
  134. package/packages/core/src/processes/dispatcher.ts +2145 -203
  135. package/packages/core/src/processes/execution-no-progress.ts +46 -1
  136. package/packages/core/src/processes/publication-state.ts +30 -5
  137. package/packages/core/src/processes/repo-view.ts +21 -2
  138. package/packages/core/src/store/build-scope.ts +18 -0
  139. package/packages/core/src/store/contract.ts +658 -0
  140. package/packages/core/src/store/digest.ts +52 -4
  141. package/packages/core/src/store/local/schema.ts +25 -13
  142. package/packages/core/src/store/local/store.ts +117 -1
  143. package/packages/core/src/store/memory.ts +62 -1
  144. package/packages/core/src/store/phase-session.ts +17 -0
  145. package/packages/core/src/store/reduced-reads.ts +2 -1
  146. package/packages/core/src/store/reducer-value-shapes.json +10707 -6440
  147. package/packages/core/src/store/remote/client.ts +45 -0
  148. package/packages/core/src/store/remote/compatibility.ts +25 -9
  149. package/packages/core/src/store/remote/protocol.ts +11 -0
  150. package/packages/core/src/store/repo-state-events.ts +2 -0
  151. package/packages/core/src/store/session-handle.ts +15 -0
  152. package/packages/core/src/store/subscribe.ts +1 -1
  153. package/packages/core/src/store/types.ts +34 -4
  154. package/packages/core/src/testing/index.ts +2 -0
  155. package/packages/core/src/testing/reduced-read-budget.ts +48 -8
  156. package/packages/core/src/testing/refresh-scheduler.ts +32 -0
  157. package/skills/guide/SKILL.md +117 -64
  158. package/skills/guide/references/integration-tree.md +117 -0
  159. package/skills/guide/references/landing-policy.md +150 -0
  160. package/skills/guide/references/migration-1.0.md +68 -0
  161. package/skills/guide/references/operator-api.md +12 -5
  162. package/skills/guide/references/plugin-authoring.md +42 -3
  163. package/skills/guide/references/remote-store-protocol.md +30 -7
  164. package/skills/guide/references/remote-ticket-protocol.md +26 -5
  165. package/skills/guide/references/restacking.md +79 -0
  166. package/skills/guide/references/setup.md +53 -6
  167. package/skills/guide/references/ticket-dependencies.md +69 -0
  168. package/skills/guide/references/ticket-migration.md +8 -0
  169. package/skills/operate/SKILL.md +55 -5
  170. package/skills/reconcile/SKILL.md +55 -48
  171. package/skills/spec/SKILL.md +67 -1
  172. package/skills/tickets/SKILL.md +55 -2
  173. package/templates/autobuild.toml +3 -0
@@ -1,3 +1,5 @@
1
+ export type { ForgeReadinessCheck, ForgeReadinessInput } from './forge/readiness'
2
+ import type { ForgeReadinessCheck, ForgeReadinessInput } from './forge/readiness'
1
3
  import type { BuildStore } from '../store/types'
2
4
  /**
3
5
  * Ports (SPEC §3.2): interfaces to the world, each with swappable adapters.
@@ -57,7 +59,13 @@ export interface TicketComment {
57
59
  author?: string
58
60
  }
59
61
 
62
+ export type TicketKind = 'work' | 'node'
63
+
60
64
  export interface Ticket {
65
+ /** Optional only for legacy plugin compatibility; public reads normalize to work. */
66
+ kind?: TicketKind
67
+ /** Canonical source-local node ticket id; absent means the baseBranch root. */
68
+ target?: string
61
69
  /** Opaque source version of title, body, labels, state and blockers. */
62
70
  revision: string
63
71
  /** Complete history oldest first when exposed by this read. Absent means
@@ -91,6 +99,8 @@ export interface TicketListing {
91
99
  }
92
100
 
93
101
  export interface TicketDraft {
102
+ kind?: TicketKind
103
+ target?: string | null
94
104
  title: string
95
105
  body: string
96
106
  /** Labels applied at creation. Names need not already exist in the source;
@@ -132,6 +142,8 @@ export interface TicketCreateOptions {
132
142
  /** Editable ticket fields. Omitted fields are preserved; state is deliberately
133
143
  * absent because `transition()` exclusively owns lifecycle changes. */
134
144
  export interface TicketUpdate {
145
+ kind?: TicketKind
146
+ target?: string | null
135
147
  /** Required when named: an update cannot clear the ticket's title. */
136
148
  title?: string
137
149
  /** Required when named: pre-build, this is the spec (§6.3). */
@@ -181,6 +193,11 @@ export type TicketMutation =
181
193
  | { kind: 'blockers'; operation: 'block' | 'unblock'; ids: string[] }
182
194
 
183
195
  export interface TicketSource {
196
+ /** Opt in only when kind/target persistence, graph validation and complete
197
+ * enumeration are supported at every write boundary, including guarded writes. */
198
+ readonly integrationTree?: boolean
199
+ /** Every lifecycle state, including archived/completed tickets; no ready gate. */
200
+ listAll?(): Promise<TicketListing>
184
201
  /** Import support: the same pure id policy used by create, for mutation-free preflight. */
185
202
  readonly requestedIds?: import('./tickets/requested-id').RequestedIdPolicy
186
203
  readonly assets?: TicketAssetStore
@@ -261,6 +278,15 @@ export interface WorkspaceProvisionResult extends WorkspaceHandle {
261
278
  }
262
279
 
263
280
  export interface WorkspacePublication {
281
+ /** Trusted after-teardown path; never route a restack through plain publish. */
282
+ rewrite?(input: {
283
+ ref: string
284
+ sha: string
285
+ branch: string
286
+ expected: string
287
+ localExpected?: string
288
+ archives: { ref: string; sha: string }[]
289
+ }): Promise<RewriteResult>
264
290
  /** Observe whether the exact requested commit already reached the durable
265
291
  * remote branch after an interrupted acknowledgement. `ref` optionally
266
292
  * names the workspace whose git database the probe runs against — used by
@@ -335,7 +361,7 @@ export interface WorkspaceProvider {
335
361
  //
336
362
  // D7: agents never touch the remote — push, PR creation, and forge API calls
337
363
  // are plumbing triggered by terminal commands. D1: PR→main is squash merge,
338
- // main→feature is a merge commit, rebase is banned.
364
+ // reconcile replays one change onto its frozen base with archived evidence and exact head guards.
339
365
 
340
366
  export interface PrRef {
341
367
  number: number
@@ -345,9 +371,11 @@ export interface PrRef {
345
371
  headSha: string
346
372
  }
347
373
 
374
+ /** Native state is sampled with the ordinary PR read. Omission means the
375
+ * adapter cannot observe it; callers retain conservative cancellation. */
348
376
  export type PrState =
349
- | { state: 'open'; mergeable: boolean | null }
350
- | { state: 'merged'; sha: string }
377
+ | { state: 'open'; mergeable: boolean | null; nativeAutoMerge?: boolean }
378
+ | { state: 'merged'; sha: string; headSha?: string }
351
379
  | { state: 'closed' }
352
380
 
353
381
  /** Abort cleanup may race landing. A merged result is terminal and must never
@@ -360,6 +388,7 @@ export type ClosePrResult = { state: 'closed' } | { state: 'merged'; sha: string
360
388
  export type AutoMergeDeferralCode =
361
389
  | 'github-plan-limitation'
362
390
  | 'repository-auto-merge-disabled'
391
+ | 'gated-node-destination'
363
392
  | 'unproven-gate-state'
364
393
  /** A persistent, definite state — GitHub has computed merge conflicts with
365
394
  * the base branch. Recovery is updating the branch or resolving the
@@ -381,6 +410,7 @@ export type AutoMergeDeferralClass = 'pipeline-resolved' | 'human-actionable'
381
410
  export const autoMergeDeferralClasses = {
382
411
  'github-plan-limitation': 'human-actionable',
383
412
  'repository-auto-merge-disabled': 'human-actionable',
413
+ 'gated-node-destination': 'human-actionable',
384
414
  'unproven-gate-state': 'human-actionable',
385
415
  'merge-conflicts': 'pipeline-resolved',
386
416
  'mergeability-uncomputed': 'pipeline-resolved',
@@ -424,7 +454,90 @@ export interface PrAttachmentHosting {
424
454
  reclaim(request: PrAttachmentReclaimRequest): Promise<void>
425
455
  }
426
456
 
457
+ export interface BuildLandingOptions {
458
+ buildSlug: string
459
+ /** Optional query hint, verified against the current provider PR base. */
460
+ baseBranch?: string
461
+ /** Refresh durable consent and pipeline eligibility before native mutation. */
462
+ canApply?: () => Promise<boolean>
463
+ }
464
+
465
+ export class NoCommitsBetweenBranchesError extends Error {
466
+ constructor(message: string) {
467
+ super(message)
468
+ this.name = 'NoCommitsBetweenBranchesError'
469
+ }
470
+ }
471
+
472
+ /** Reconcile-only branch replacement. All object ids are exact, never ref expressions.
473
+ * A successful CAS overtaken before readback returns lease-mismatch with
474
+ * rewritten: true: record its receipt, then replay actual instead of completing. */
475
+ export type RewriteResult =
476
+ | { kind: 'published' }
477
+ | { kind: 'lease-mismatch'; actual: string | null; rewritten?: true }
478
+ export interface ForgeRewrite {
479
+ /** General destination publication, restricted to proven fast-forward ancestry. */
480
+ fastForward?(input: {
481
+ workspacePath: string
482
+ branch: string
483
+ expected: string
484
+ sha: string
485
+ }): Promise<RewriteResult>
486
+
487
+ snapshot(input: {
488
+ workspacePath: string
489
+ branch: string
490
+ destinationRef: string
491
+ }): Promise<string>
492
+ archive(input: { workspacePath: string; ref: string; sha: string }): Promise<void>
493
+ replace(input: {
494
+ workspacePath: string
495
+ branch: string
496
+ expected: string
497
+ localExpected?: string
498
+ sha: string
499
+ }): Promise<RewriteResult>
500
+ }
501
+
502
+ /** Read-only proof for controlled landing into an exact destination branch.
503
+ * Bypass privileges are never evidence that a branch is ungated. */
504
+ export type LandingGateInspection =
505
+ | { kind: 'proved-ungated' }
506
+ | { kind: 'gated'; reason: string }
507
+ | { kind: 'unproven'; reason: string }
508
+
427
509
  export interface Forge {
510
+ inspectReadiness?(input: ForgeReadinessInput): Promise<ForgeReadinessCheck[]>
511
+ /** Trusted kernel-only Git execution, with forge credentials scoped to its
512
+ * origin. Never pass this capability or its environment to agent sessions. */
513
+ readonly kernelExec?: import('./workspace/git-worktree').Exec
514
+ /** Credentialed rewrite transport for dispatcher-owned node work. Workspace
515
+ * replay retains its existing provider-controlled transport. */
516
+ readonly kernelRewrite?: ForgeRewrite
517
+ mergeLinearStack?(workspacePath: string, number: number, expectedHead: string): Promise<string>
518
+ inspectMergeFreshness?(branch: string): Promise<{ fenced: boolean; evidence: string[] }>
519
+ inspectLandingGate?(branch: string): Promise<LandingGateInspection>
520
+ inspectLandingPr?(
521
+ workspacePath: string,
522
+ number: number,
523
+ ): Promise<{ base: string; head: string; headSha: string; open: boolean }>
524
+
525
+ /** Change only an existing open review's base, preserving its identity.
526
+ * Implementations acknowledge only a matching inspected base/head. */
527
+ retargetPr?(workspacePath: string, number: number, base: string): Promise<void>
528
+ readonly rewrite?: ForgeRewrite
529
+ /** Create once at sha; retries adopt only descendants of that opening commit. */
530
+ createNodeBranch?(branch: string, sha: string): Promise<string>
531
+ /** Observe exact heads and count commits reachable only from head. */
532
+ compareBranches?(
533
+ parent: string,
534
+ head: string,
535
+ ): Promise<{
536
+ parentSha: string
537
+ headSha: string
538
+ ahead: number
539
+ }>
540
+
428
541
  readonly name: string
429
542
  /** Optional because another forge may support PRs but not public image assets. */
430
543
  readonly prAttachments?: PrAttachmentHosting
@@ -461,12 +574,29 @@ export interface Forge {
461
574
  * inspect or apply consent returns a reason-bearing deferral. The operation
462
575
  * is idempotent and safe to retry across the forge-call/event-append crash window.
463
576
  */
464
- setAutoMerge(workspacePath: string, number: number, enabled: boolean): Promise<AutoMergeResult>
577
+ setAutoMerge(
578
+ workspacePath: string,
579
+ number: number,
580
+ enabled: boolean,
581
+ options?: BuildLandingOptions,
582
+ ): Promise<AutoMergeResult>
465
583
  /**
466
584
  * Perform a normal squash merge, guarded by the inspected PR head. This is
467
585
  * never an admin/force operation: forge-side protection still applies.
468
586
  */
469
- squashMerge(workspacePath: string, number: number, expectedHeadSha: string): Promise<void>
587
+ squashMerge(
588
+ workspacePath: string,
589
+ number: number,
590
+ expectedHeadSha: string,
591
+ options?: BuildLandingOptions,
592
+ ): Promise<void>
593
+ /** Actual landed message. Absent capability or read failure means unknown
594
+ * trailer evidence; neither may prevent observing a merged PR. */
595
+ readCommitMessage?(workspacePath: string, sha: string): Promise<string>
596
+ /** Inspect exact trailer values across all reachable history, including
597
+ * merged side branches. Missing refs/read failures throw; false is proven
598
+ * absence. Do not cache by branch name across history rewrites. */
599
+ containsBuild?(workspacePath: string, branch: string, buildSlug: string): Promise<boolean>
470
600
  /** Post the build's summary comment (§7.5). */
471
601
  commentOnPr(workspacePath: string, number: number, body: string): Promise<void>
472
602
  /** Optional checkout-less capability: the current tip of a remote branch.
@@ -35,7 +35,7 @@ export interface ExecResult {
35
35
  /** Injectable exec seam — the default shells out via Bun.spawn. */
36
36
  export type Exec = (
37
37
  cmd: string[],
38
- opts: { cwd?: string; signal?: AbortSignal },
38
+ opts: { cwd?: string; signal?: AbortSignal; env?: Record<string, string | undefined> },
39
39
  ) => Promise<ExecResult>
40
40
 
41
41
  export const spawnExec: Exec = async (cmd, opts) => {
@@ -44,6 +44,7 @@ export const spawnExec: Exec = async (cmd, opts) => {
44
44
  stdin: 'ignore',
45
45
  stdout: 'pipe',
46
46
  stderr: 'pipe',
47
+ ...(opts.env === undefined ? {} : { env: { ...process.env, ...opts.env } }),
47
48
  ...(opts.signal === undefined ? {} : { signal: opts.signal }),
48
49
  })
49
50
  const [stdout, stderr, exitCode] = await Promise.all([
@@ -55,7 +55,7 @@ export function sandboxForbiddenEnvMessage(name: string): string {
55
55
 
56
56
  export interface ReadinessCheck {
57
57
  name: string
58
- status: 'pass' | 'fail' | 'absent'
58
+ status: 'pass' | 'fail' | 'absent' | 'warning' | 'unknown'
59
59
  detail: string
60
60
  }
61
61
 
@@ -1,3 +1,4 @@
1
+ import { gitRewrite } from '../forge/git-rewrite'
1
2
  import { delegateCredential } from '../../store/remote/credentials'
2
3
  import type { ExecutionLaunchAuth } from './build-execution'
3
4
  import { createHash } from 'node:crypto'
@@ -1231,6 +1232,8 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1231
1232
  },
1232
1233
  }
1233
1234
  this.publication = {
1235
+ rewrite: (input: Parameters<NonNullable<WorkspacePublication['rewrite']>>[0]) =>
1236
+ this.publish(input),
1234
1237
  isPublished: (input: { sha: string; branch: string }) => this.isPublished(input),
1235
1238
  publish: (input: { ref: string; sha: string; branch: string }) => this.publish(input),
1236
1239
  }
@@ -2531,7 +2534,18 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2531
2534
  return head === input.sha
2532
2535
  }
2533
2536
 
2534
- private async publish(input: { ref: string; sha: string; branch: string }): Promise<void> {
2537
+ private async publish(
2538
+ input: Parameters<NonNullable<WorkspacePublication['rewrite']>>[0],
2539
+ ): Promise<import('../types').RewriteResult>
2540
+ private async publish(input: { ref: string; sha: string; branch: string }): Promise<void>
2541
+ private async publish(input: {
2542
+ ref: string
2543
+ sha: string
2544
+ branch: string
2545
+ expected?: string
2546
+ localExpected?: string
2547
+ archives?: { ref: string; sha: string }[]
2548
+ }): Promise<void | import('../types').RewriteResult> {
2535
2549
  if (this.active.has(input.ref) || this.uncertain.has(input.ref)) {
2536
2550
  throw new Error('publication is forbidden until sandbox execution teardown is confirmed')
2537
2551
  }
@@ -2554,7 +2568,15 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2554
2568
  match: {
2555
2569
  method: ['GET'],
2556
2570
  path: { exact: `${origin.path}/info/refs` },
2557
- queryString: [{ key: { exact: 'service' }, value: { exact: 'git-receive-pack' } }],
2571
+ queryString: [
2572
+ {
2573
+ key: { exact: 'service' },
2574
+ value:
2575
+ input.expected === undefined
2576
+ ? { exact: 'git-receive-pack' }
2577
+ : { regex: '^git-(receive|upload)-pack$' },
2578
+ },
2579
+ ],
2558
2580
  },
2559
2581
  transform: [
2560
2582
  {
@@ -2565,7 +2587,15 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2565
2587
  ],
2566
2588
  },
2567
2589
  {
2568
- match: { method: ['POST'], path: { exact: `${origin.path}/git-receive-pack` } },
2590
+ match: {
2591
+ method: ['POST'],
2592
+ path:
2593
+ input.expected === undefined
2594
+ ? { exact: `${origin.path}/git-receive-pack` }
2595
+ : {
2596
+ regex: `^${origin.path.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/git-(receive|upload)-pack$`,
2597
+ },
2598
+ },
2569
2599
  transform: [
2570
2600
  {
2571
2601
  headers: {
@@ -2579,6 +2609,33 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2579
2609
  }
2580
2610
  try {
2581
2611
  await sandbox.update({ networkPolicy: publicationPolicy }, { signal: this.operationSignal() })
2612
+ if (input.expected !== undefined) {
2613
+ const capability = gitRewrite(async (cmd) => {
2614
+ const result = await sandbox.runCommand({
2615
+ cmd: cmd[0]!,
2616
+ args: cmd.slice(1),
2617
+ cwd: VERCEL_WORKSPACE_PATH,
2618
+ })
2619
+ if (result.exitCode === null)
2620
+ throw new Error('trusted rewrite command has no exit status')
2621
+ if (!('stdout' in result) || !('stderr' in result))
2622
+ throw new Error('trusted rewrite requires command output capture')
2623
+ return {
2624
+ exitCode: result.exitCode,
2625
+ stdout: await result.stdout!(),
2626
+ stderr: await result.stderr!(),
2627
+ }
2628
+ }, false)
2629
+ for (const archive of input.archives ?? [])
2630
+ await capability.archive({ workspacePath: VERCEL_WORKSPACE_PATH, ...archive })
2631
+ return await capability.replace({
2632
+ workspacePath: VERCEL_WORKSPACE_PATH,
2633
+ branch: input.branch,
2634
+ expected: input.expected,
2635
+ ...(input.localExpected !== undefined ? { localExpected: input.localExpected } : {}),
2636
+ sha: input.sha,
2637
+ })
2638
+ }
2582
2639
  await commandOrThrow(sandbox, {
2583
2640
  cmd: 'git',
2584
2641
  args: ['push', '--no-verify', 'origin', `${input.sha}:refs/heads/${input.branch}`],