@defrex/autobuild 1.0.0-beta.2 → 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.
- package/SPEC.md +342 -23
- package/bin/ab-dispatch-generation.ts +93 -0
- package/docs/answering-blocked-builds.md +21 -3
- package/docs/architecture.md +170 -7
- package/docs/configuration.md +173 -5
- package/docs/integration-tree.md +91 -4
- package/docs/integration.md +54 -0
- package/docs/operator-api.md +58 -5
- package/docs/remote-store-protocol.md +9 -1
- package/docs/remote-ticket-protocol.md +5 -0
- package/docs/restacking.md +4 -1
- package/docs/setup.md +24 -0
- package/docs/spec-standard.md +94 -5
- package/docs/ticket-migration.md +50 -4
- package/package.json +3 -3
- package/packages/core/src/cli/artifact.ts +5 -4
- package/packages/core/src/cli/attention.ts +2 -0
- package/packages/core/src/cli/binary-direct.ts +190 -0
- package/packages/core/src/cli/binary-lifecycle.ts +46 -0
- package/packages/core/src/cli/binary.ts +24 -210
- package/packages/core/src/cli/build-control.ts +108 -5
- package/packages/core/src/cli/context.ts +41 -1
- package/packages/core/src/cli/dashboard/hand-pushed.ts +24 -0
- package/packages/core/src/cli/dashboard/handoff.ts +64 -0
- package/packages/core/src/cli/dashboard/integration-detail.ts +11 -6
- package/packages/core/src/cli/dashboard/integration-row.ts +15 -8
- package/packages/core/src/cli/dashboard/model.ts +41 -10
- package/packages/core/src/cli/dashboard/render.ts +24 -2
- package/packages/core/src/cli/dashboard/rollback.ts +30 -0
- package/packages/core/src/cli/dispatch-args.ts +53 -0
- package/packages/core/src/cli/dispatch-crash-budget.ts +15 -0
- package/packages/core/src/cli/dispatch-frontend.ts +57 -5
- package/packages/core/src/cli/dispatch-handoff.ts +276 -0
- package/packages/core/src/cli/dispatch-launch-contract.ts +170 -0
- package/packages/core/src/cli/dispatch-launcher.ts +580 -0
- package/packages/core/src/cli/dispatch-parent-watch.ts +44 -0
- package/packages/core/src/cli/dispatch-preflight.ts +272 -0
- package/packages/core/src/cli/dispatch-presentation-job.ts +46 -0
- package/packages/core/src/cli/dispatch-presentation-ownership.ts +9 -0
- package/packages/core/src/cli/dispatch-process.ts +22 -90
- package/packages/core/src/cli/dispatch-readiness.ts +47 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +6 -1
- package/packages/core/src/cli/dispatch-runtime-cache.ts +522 -0
- package/packages/core/src/cli/dispatch-runtime-dependencies.ts +291 -0
- package/packages/core/src/cli/dispatch-runtime-use.ts +336 -0
- package/packages/core/src/cli/dispatch-upgrade-controller.ts +221 -0
- package/packages/core/src/cli/dispatch-upgrade-install.ts +258 -0
- package/packages/core/src/cli/dispatch-upgrade-source.ts +309 -0
- package/packages/core/src/cli/dispatch-upgrade-target.ts +190 -0
- package/packages/core/src/cli/dispatch.ts +609 -60
- package/packages/core/src/cli/dispatcher-liveness.ts +1 -1
- package/packages/core/src/cli/harvest.ts +28 -11
- package/packages/core/src/cli/help.ts +7 -3
- package/packages/core/src/cli/installation.ts +5 -3
- package/packages/core/src/cli/main-checkout.ts +59 -0
- package/packages/core/src/cli/main.ts +26 -53
- package/packages/core/src/cli/node-verification-provenance.ts +97 -0
- package/packages/core/src/cli/repo-state.ts +3 -58
- package/packages/core/src/cli/repository-status.ts +74 -4
- package/packages/core/src/cli/runtime-spawn.ts +16 -0
- package/packages/core/src/cli/status.ts +57 -3
- package/packages/core/src/cli/ticket.ts +35 -11
- package/packages/core/src/cli/upgrade-followup.ts +25 -0
- package/packages/core/src/cli/wait.ts +3 -0
- package/packages/core/src/cli/watch.ts +7 -0
- package/packages/core/src/config/live.ts +1 -0
- package/packages/core/src/config/schema.ts +8 -4
- package/packages/core/src/distribution-packaging.ts +116 -0
- package/packages/core/src/events/catalog.ts +6 -0
- package/packages/core/src/events/payloads.ts +55 -9
- package/packages/core/src/events/policy.ts +26 -0
- package/packages/core/src/events/repository.ts +205 -4
- package/packages/core/src/events/runtime.ts +16 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +6537 -4053
- package/packages/core/src/kernel/change-presence.ts +7 -1
- package/packages/core/src/kernel/dispatch-capacity.ts +12 -4
- package/packages/core/src/kernel/dispatch-drain-recovery.ts +121 -0
- package/packages/core/src/kernel/dispatch-status.ts +4 -2
- package/packages/core/src/kernel/dispatch-upgrade.ts +171 -0
- package/packages/core/src/kernel/dispatcher-liveness.ts +7 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +82 -0
- package/packages/core/src/kernel/guarded-forge.ts +1 -1
- package/packages/core/src/kernel/harvest.ts +98 -4
- package/packages/core/src/kernel/integration-attention.ts +20 -0
- package/packages/core/src/kernel/integration-completeness.ts +54 -16
- package/packages/core/src/kernel/integration-state.ts +80 -11
- package/packages/core/src/kernel/landing-readiness.ts +6 -1
- package/packages/core/src/kernel/mixed-version.ts +34 -0
- package/packages/core/src/kernel/node-parent.ts +35 -10
- package/packages/core/src/kernel/node-polling.ts +160 -0
- package/packages/core/src/kernel/read-facts.ts +47 -5
- package/packages/core/src/kernel/reducer-registry.ts +6 -0
- package/packages/core/src/kernel/reducer.ts +75 -14
- package/packages/core/src/kernel/service-facts.ts +11 -4
- package/packages/core/src/kernel/ticket-migrations.ts +139 -0
- package/packages/core/src/operator/presentation.ts +7 -0
- package/packages/core/src/operator/query.ts +13 -3
- package/packages/core/src/operator/registry.ts +1 -1
- package/packages/core/src/operator/tickets.ts +30 -26
- package/packages/core/src/plugins/load.ts +4 -1
- package/packages/core/src/plugins/runtime-snapshot.ts +128 -0
- package/packages/core/src/ports/forge/contract.ts +29 -0
- package/packages/core/src/ports/forge/github.ts +189 -61
- package/packages/core/src/ports/forge-failure.ts +1 -0
- package/packages/core/src/ports/forge-telemetry.ts +3 -0
- package/packages/core/src/ports/runner/session-env.ts +1 -0
- package/packages/core/src/ports/tickets/linear.ts +180 -12
- package/packages/core/src/ports/tickets/migration.ts +92 -9
- package/packages/core/src/ports/types.ts +17 -0
- package/packages/core/src/ports/workspace/distribution-archive.ts +22 -149
- package/packages/core/src/ports/workspace/distribution-release.ts +56 -0
- package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
- package/packages/core/src/ports/workspace/local-build-execution.ts +37 -17
- package/packages/core/src/processes/build-child-exit.ts +5 -26
- package/packages/core/src/processes/build-runner.ts +81 -11
- package/packages/core/src/processes/dispatcher.ts +418 -59
- package/packages/core/src/processes/execution-no-progress.ts +6 -0
- package/packages/core/src/processes/execution-relaunch.ts +30 -0
- package/packages/core/src/processes/execution-settlement.ts +16 -7
- package/packages/core/src/processes/harvest-runner.ts +328 -292
- package/packages/core/src/processes/process-group-reaper.ts +17 -10
- package/packages/core/src/runtime-identity.ts +22 -3
- package/packages/core/src/store/contract.ts +183 -0
- package/packages/core/src/store/local/store.ts +197 -72
- package/packages/core/src/store/reduced-reads.ts +8 -0
- package/packages/core/src/store/reducer-value-shapes.json +8915 -6344
- package/packages/core/src/store/remote/client.ts +43 -0
- package/packages/core/src/store/repo-state-events.ts +21 -3
- package/packages/core/src/store/types.ts +7 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +3 -2
- package/skills/guide/SKILL.md +234 -24
- package/skills/guide/references/integration-tree.md +91 -4
- package/skills/guide/references/operator-api.md +53 -4
- package/skills/guide/references/plugin-authoring.md +45 -4
- package/skills/guide/references/remote-store-protocol.md +9 -1
- package/skills/guide/references/remote-ticket-protocol.md +5 -0
- package/skills/guide/references/restacking.md +4 -1
- package/skills/guide/references/setup.md +24 -0
- package/skills/guide/references/spec-standard.md +94 -5
- package/skills/guide/references/ticket-migration.md +50 -4
- package/skills/harvest/SKILL.md +4 -0
- package/skills/harvest-review/SKILL.md +4 -0
- package/skills/operate/SKILL.md +78 -8
- package/skills/spec/SKILL.md +35 -5
- package/skills/tickets/SKILL.md +19 -0
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { cachedRuntime, resolveCachedGuestArchive } from '../../cli/dispatch-runtime-cache'
|
|
1
2
|
/**
|
|
2
3
|
* The Autobuild distribution archive installed into guests.
|
|
3
4
|
*
|
|
5
|
+
* Source and registry caches retain distinct guest archive provenance. Registry
|
|
6
|
+
* caches lazily install the version-validated GitHub release asset; source caches use
|
|
7
|
+
* their exact packed code. Outside the cache, the sources below apply.
|
|
8
|
+
*
|
|
4
9
|
* Two sources, one archive layout (`autobuild-<version>.tgz`, the same bytes
|
|
5
10
|
* `bun pm pack` produces and the guest bootstrap extracts):
|
|
6
11
|
*
|
|
@@ -35,25 +40,21 @@
|
|
|
35
40
|
* bytes installed and resolution never adds a second pack per tick.
|
|
36
41
|
*/
|
|
37
42
|
import { createHash } from 'node:crypto'
|
|
38
|
-
import { access,
|
|
39
|
-
import {
|
|
40
|
-
import { dirname, join, resolve } from 'node:path'
|
|
43
|
+
import { access, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
|
|
44
|
+
import { join, resolve } from 'node:path'
|
|
41
45
|
import { distributionRoot, distributionPath } from '../../distribution'
|
|
42
46
|
import { REMOTE_STORE_PROTOCOL_VERSION } from '../../store/remote/version'
|
|
43
47
|
import { registryBaseUrl, registryVersionUrl } from '../../registry'
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} from '
|
|
48
|
+
import type { GitHubRequest } from '../forge/github-transport'
|
|
49
|
+
import { fetchDistributionReleaseAsset, distributionAssetName } from './distribution-release'
|
|
50
|
+
export {
|
|
51
|
+
fetchDistributionReleaseAsset,
|
|
52
|
+
distributionAssetName,
|
|
53
|
+
CANONICAL_REPOSITORY_URL,
|
|
54
|
+
} from './distribution-release'
|
|
55
|
+
import { packageDistribution } from '../../distribution-packaging'
|
|
51
56
|
import { spawnExec } from './git-worktree'
|
|
52
57
|
|
|
53
|
-
/** The canonical repository the release assets are published to. Shared with
|
|
54
|
-
* `tools/release.ts`, which uploads them. */
|
|
55
|
-
export const CANONICAL_REPOSITORY_URL = 'https://github.com/defrex/autobuild'
|
|
56
|
-
|
|
57
58
|
/** The shipped manifest `readDistributionPackage()` reads. A bundled
|
|
58
59
|
* deployment must carry this exact file into its function bundle; the hosted
|
|
59
60
|
* service's post-build trace step appends it to the dispatch route's trace. */
|
|
@@ -157,11 +158,6 @@ export async function readDistributionIdentityStamp(): Promise<string> {
|
|
|
157
158
|
return distributionStampFor(archive)
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
/** The release asset a version's distribution ships under. */
|
|
161
|
-
export function distributionAssetName(version: string): string {
|
|
162
|
-
return `autobuild-${version}.tgz`
|
|
163
|
-
}
|
|
164
|
-
|
|
165
161
|
/** Minimal fetch seam for registry reads: the global `fetch` in production. */
|
|
166
162
|
export type RegistryFetch = (
|
|
167
163
|
url: string,
|
|
@@ -234,54 +230,6 @@ async function fetchPublishedDistribution(
|
|
|
234
230
|
}
|
|
235
231
|
}
|
|
236
232
|
|
|
237
|
-
/** Fetch the published `autobuild-<version>.tgz` release asset for the
|
|
238
|
-
* running version. Uses the dispatcher's GitHub credentials when present
|
|
239
|
-
* (required for a private canonical repository). */
|
|
240
|
-
export async function fetchDistributionReleaseAsset(
|
|
241
|
-
version: string,
|
|
242
|
-
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
243
|
-
transport: GitHubRequest = createGitHubFetchTransport({
|
|
244
|
-
token: githubTokenFromEnv(env),
|
|
245
|
-
}),
|
|
246
|
-
): Promise<Uint8Array> {
|
|
247
|
-
const coordinates = parseRepoCoordinates(CANONICAL_REPOSITORY_URL)
|
|
248
|
-
if (coordinates === null) {
|
|
249
|
-
throw new Error(`the canonical repository URL is not parseable: ${CANONICAL_REPOSITORY_URL}`)
|
|
250
|
-
}
|
|
251
|
-
const repo = `repos/${encodeURIComponent(coordinates.owner)}/${encodeURIComponent(coordinates.name)}`
|
|
252
|
-
const tag = `v${version}`
|
|
253
|
-
const release = await transport('GET', `${repo}/releases/tags/${tag}`).catch((error: unknown) => {
|
|
254
|
-
if (error instanceof GitHubApiError && error.status === 404) {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`Autobuild release ${tag} has no published GitHub release; origin-mode dispatch ` +
|
|
257
|
-
'installs the guest distribution from the release asset autobuild-' +
|
|
258
|
-
`${version}.tgz — cut a release with tools/release.ts first`,
|
|
259
|
-
{ cause: error },
|
|
260
|
-
)
|
|
261
|
-
}
|
|
262
|
-
throw error
|
|
263
|
-
})
|
|
264
|
-
const assets = (
|
|
265
|
-
release.json as { assets?: { name?: unknown; browser_download_url?: unknown }[] } | undefined
|
|
266
|
-
)?.assets
|
|
267
|
-
const assetName = distributionAssetName(version)
|
|
268
|
-
const asset = (assets ?? []).find((candidate) => candidate.name === assetName)
|
|
269
|
-
if (asset === undefined || typeof asset.browser_download_url !== 'string') {
|
|
270
|
-
throw new Error(
|
|
271
|
-
`Autobuild release ${tag} does not carry the ${assetName} distribution asset; ` +
|
|
272
|
-
'origin-mode dispatch cannot install a guest distribution without it — ' +
|
|
273
|
-
'cut a release with tools/release.ts first',
|
|
274
|
-
)
|
|
275
|
-
}
|
|
276
|
-
const download = await transport('GET', asset.browser_download_url, {
|
|
277
|
-
headers: { Accept: 'application/octet-stream' },
|
|
278
|
-
})
|
|
279
|
-
if (download.bytes === undefined) {
|
|
280
|
-
throw new Error(`the ${assetName} release asset downloaded no bytes`)
|
|
281
|
-
}
|
|
282
|
-
return download.bytes
|
|
283
|
-
}
|
|
284
|
-
|
|
285
233
|
/** Directory, relative to a distribution root, where a deployment ships the
|
|
286
234
|
* archive it packed at build time (`ab-hosted-dispatcher pack-distribution`). A
|
|
287
235
|
* bundled deployment — the hosted service on Vercel — has neither `bun` nor a
|
|
@@ -293,89 +241,8 @@ export const PREBUILT_DISTRIBUTION_DIR = '.autobuild-dist'
|
|
|
293
241
|
* that place it somewhere other than `PREBUILT_DISTRIBUTION_DIR`. */
|
|
294
242
|
export const DISTRIBUTION_ARCHIVE_ENV = 'AB_DISTRIBUTION_ARCHIVE'
|
|
295
243
|
|
|
296
|
-
async function execOrThrow(cmd: string[], cwd: string): Promise<string> {
|
|
297
|
-
const result = await spawnExec(cmd, { cwd })
|
|
298
|
-
if (result.exitCode !== 0) {
|
|
299
|
-
throw new Error(
|
|
300
|
-
`${cmd.join(' ')} exited ${result.exitCode}: ${result.stderr.trim() || result.stdout.trim()}`,
|
|
301
|
-
)
|
|
302
|
-
}
|
|
303
|
-
return result.stdout.trim()
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/** Manifest fields that name repo-local packaging state and must never reach
|
|
307
|
-
* the packed distribution manifest. `patchedDependencies` entries are resolved
|
|
308
|
-
* by bun against the consuming project's root, and bun 1.4.0 panics
|
|
309
|
-
* (`Option::unwrap`, exit 134) when a consumed manifest declares a patch for a
|
|
310
|
-
* package the consumer tree contains — so a packed manifest carrying the
|
|
311
|
-
* repo's better-auth patch declaration breaks any consumer that installs
|
|
312
|
-
* autobuild next to better-auth. The packed artifact ships no patched
|
|
313
|
-
* package, so the declaration is stripped from the packed manifest while the
|
|
314
|
-
* repo manifest keeps it for workspace installs. The strip is an enforced
|
|
315
|
-
* invariant, not a local detail: the `patchedDependencies` rule in
|
|
316
|
-
* `tools/workspace-manifest-check.ts` rejects a root manifest whose packed
|
|
317
|
-
* dependency set contains a patched package, and the negative control in
|
|
318
|
-
* `packages/core/src/plugin-sdk/package.test.ts` (the packed-distribution
|
|
319
|
-
* better-auth canary) pins the consumed-manifest failure shape this strip
|
|
320
|
-
* guards, so removing the field from this list fails the suite loudly.
|
|
321
|
-
*
|
|
322
|
-
* `devDependencies` is stripped for two reasons. First, the workspace link
|
|
323
|
-
* specifiers it may carry (for example the root's
|
|
324
|
-
* `@defrex/autobuild-postgres-store: workspace:*`) cannot be resolved in the
|
|
325
|
-
* staging tree — it stages only the manifest's `files` set, with no
|
|
326
|
-
* `bun.lock`, no `node_modules`, and no workspace packages — so `bun pm pack`
|
|
327
|
-
* fails there with "Failed to resolve workspace version". Second, the guest
|
|
328
|
-
* installs the distribution with `bun install --production --ignore-scripts`,
|
|
329
|
-
* which ignores devDependencies entirely; the packed artifact ships no
|
|
330
|
-
* dev-only tooling, so the declaration is dead weight in the packed manifest
|
|
331
|
-
* while the repo manifest keeps it for workspace installs. */
|
|
332
|
-
const packedManifestOmittedFields = ['patchedDependencies', 'devDependencies'] as const
|
|
333
|
-
|
|
334
244
|
export async function packageAutobuildDistribution(): Promise<Uint8Array> {
|
|
335
|
-
|
|
336
|
-
const destination = await mkdtemp(join(tmpdir(), 'autobuild-pack-'))
|
|
337
|
-
try {
|
|
338
|
-
// Pack from a staging copy of the repo's `files` set rather than the repo
|
|
339
|
-
// root: the packed manifest must differ from the repo manifest (above), and
|
|
340
|
-
// rewriting the repo manifest in place would leave a window where tracked
|
|
341
|
-
// files are dirty.
|
|
342
|
-
const manifestPath = join(distributionRoot(), 'package.json')
|
|
343
|
-
const manifest = JSON.parse(await readFile(manifestPath, 'utf8')) as Record<string, unknown>
|
|
344
|
-
const files = manifest.files
|
|
345
|
-
if (!Array.isArray(files) || files.some((entry) => typeof entry !== 'string')) {
|
|
346
|
-
throw new Error(
|
|
347
|
-
'Autobuild packaging requires the root package.json to list its files as an array of paths',
|
|
348
|
-
)
|
|
349
|
-
}
|
|
350
|
-
for (const entry of files as string[]) {
|
|
351
|
-
// npm `files` entries may be negated globs (for example
|
|
352
|
-
// `!packages/core/src/**/*.test.ts`, which keeps test files out of the
|
|
353
|
-
// published package). Only positive entries name a path to stage: the
|
|
354
|
-
// negations stay in the staged manifest and `bun pm pack` applies them,
|
|
355
|
-
// so the packed set still excludes those paths.
|
|
356
|
-
if (entry.startsWith('!')) continue
|
|
357
|
-
const target = join(staging, entry)
|
|
358
|
-
await mkdir(dirname(target), { recursive: true })
|
|
359
|
-
await cp(join(distributionRoot(), entry), target, {
|
|
360
|
-
recursive: true,
|
|
361
|
-
errorOnExist: true,
|
|
362
|
-
force: false,
|
|
363
|
-
})
|
|
364
|
-
}
|
|
365
|
-
for (const field of packedManifestOmittedFields) delete manifest[field]
|
|
366
|
-
await writeFile(join(staging, 'package.json'), `${JSON.stringify(manifest, null, 2)}\n`)
|
|
367
|
-
await execOrThrow(
|
|
368
|
-
['bun', 'pm', 'pack', '--ignore-scripts', '--destination', destination],
|
|
369
|
-
staging,
|
|
370
|
-
)
|
|
371
|
-
const archives = (await readdir(destination)).filter((name) => name.endsWith('.tgz'))
|
|
372
|
-
if (archives.length !== 1)
|
|
373
|
-
throw new Error('Autobuild packaging did not produce exactly one archive')
|
|
374
|
-
return new Uint8Array(await readFile(join(destination, archives[0]!)))
|
|
375
|
-
} finally {
|
|
376
|
-
await rm(staging, { recursive: true, force: true })
|
|
377
|
-
await rm(destination, { recursive: true, force: true })
|
|
378
|
-
}
|
|
245
|
+
return packageDistribution(distributionRoot(), (cmd, options) => spawnExec(cmd, options))
|
|
379
246
|
}
|
|
380
247
|
|
|
381
248
|
/** Pack the running distribution into `<root>/.autobuild-dist/autobuild-<version>.tgz`
|
|
@@ -452,6 +319,12 @@ export async function defaultDistributionArchive(
|
|
|
452
319
|
hasBun: () => boolean = hasBunExecutable,
|
|
453
320
|
fetchImpl: RegistryFetch = registryFetch,
|
|
454
321
|
): Promise<Uint8Array> {
|
|
322
|
+
const runtime = await cachedRuntime(distributionRoot())
|
|
323
|
+
if (runtime) {
|
|
324
|
+
return resolveCachedGuestArchive(runtime, (version) =>
|
|
325
|
+
fetchDistributionReleaseAsset(version, env, transport),
|
|
326
|
+
)
|
|
327
|
+
}
|
|
455
328
|
const prebuilt = await findPrebuiltDistributionArchive(env)
|
|
456
329
|
if (prebuilt !== null) return new Uint8Array(await readFile(prebuilt))
|
|
457
330
|
if (await fileExists(join(distributionRoot(), '.git'))) {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { parseRepoCoordinates } from '../forge/github'
|
|
2
|
+
import {
|
|
3
|
+
createGitHubFetchTransport,
|
|
4
|
+
GitHubApiError,
|
|
5
|
+
githubTokenFromEnv,
|
|
6
|
+
type GitHubRequest,
|
|
7
|
+
} from '../forge/github-transport'
|
|
8
|
+
export const CANONICAL_REPOSITORY_URL = 'https://github.com/defrex/autobuild'
|
|
9
|
+
export function distributionAssetName(version: string): string {
|
|
10
|
+
return `autobuild-${version}.tgz`
|
|
11
|
+
}
|
|
12
|
+
/** Fetch the exact version’s published asset through the authenticated transport. */
|
|
13
|
+
export async function fetchDistributionReleaseAsset(
|
|
14
|
+
version: string,
|
|
15
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
16
|
+
transport: GitHubRequest = createGitHubFetchTransport({
|
|
17
|
+
token: githubTokenFromEnv(env),
|
|
18
|
+
}),
|
|
19
|
+
): Promise<Uint8Array> {
|
|
20
|
+
const coordinates = parseRepoCoordinates(CANONICAL_REPOSITORY_URL)
|
|
21
|
+
if (coordinates === null) {
|
|
22
|
+
throw new Error(`the canonical repository URL is not parseable: ${CANONICAL_REPOSITORY_URL}`)
|
|
23
|
+
}
|
|
24
|
+
const repo = `repos/${encodeURIComponent(coordinates.owner)}/${encodeURIComponent(coordinates.name)}`
|
|
25
|
+
const tag = `v${version}`
|
|
26
|
+
const release = await transport('GET', `${repo}/releases/tags/${tag}`).catch((error: unknown) => {
|
|
27
|
+
if (error instanceof GitHubApiError && error.status === 404) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Autobuild release ${tag} has no published GitHub release; origin-mode dispatch ` +
|
|
30
|
+
'installs the guest distribution from the release asset autobuild-' +
|
|
31
|
+
`${version}.tgz — cut a release with tools/release.ts first`,
|
|
32
|
+
{ cause: error },
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
throw error
|
|
36
|
+
})
|
|
37
|
+
const assets = (
|
|
38
|
+
release.json as { assets?: { name?: unknown; browser_download_url?: unknown }[] } | undefined
|
|
39
|
+
)?.assets
|
|
40
|
+
const assetName = distributionAssetName(version)
|
|
41
|
+
const asset = (assets ?? []).find((candidate) => candidate.name === assetName)
|
|
42
|
+
if (asset === undefined || typeof asset.browser_download_url !== 'string') {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Autobuild release ${tag} does not carry the ${assetName} distribution asset; ` +
|
|
45
|
+
'origin-mode dispatch cannot install a guest distribution without it — ' +
|
|
46
|
+
'cut a release with tools/release.ts first',
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
const download = await transport('GET', asset.browser_download_url, {
|
|
50
|
+
headers: { Accept: 'application/octet-stream' },
|
|
51
|
+
})
|
|
52
|
+
if (download.bytes === undefined || download.bytes.byteLength === 0) {
|
|
53
|
+
throw new Error(`the ${assetName} release asset downloaded no bytes`)
|
|
54
|
+
}
|
|
55
|
+
return download.bytes
|
|
56
|
+
}
|
|
@@ -45,7 +45,7 @@ export const spawnExec: Exec = async (cmd, opts) => {
|
|
|
45
45
|
stdin: 'ignore',
|
|
46
46
|
stdout: 'pipe',
|
|
47
47
|
stderr: 'pipe',
|
|
48
|
-
|
|
48
|
+
env: { ...process.env, ...opts.env, AB_DISPATCH_GENERATION: undefined },
|
|
49
49
|
...(opts.signal === undefined ? {} : { signal: opts.signal }),
|
|
50
50
|
})
|
|
51
51
|
const [stdout, stderr, exitCode] = await Promise.all([
|
|
@@ -555,6 +555,7 @@ export class GitWorktreeProvider implements WorkspaceProvider {
|
|
|
555
555
|
}
|
|
556
556
|
env[name] = value
|
|
557
557
|
}
|
|
558
|
+
delete env.AB_DISPATCH_GENERATION
|
|
558
559
|
return env
|
|
559
560
|
}
|
|
560
561
|
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { bunRuntimeArguments } from '../../cli/runtime-spawn'
|
|
2
|
+
import { spawnUsingRuntime } from '../../cli/dispatch-runtime-use'
|
|
3
|
+
import { distributionRoot } from '../../distribution'
|
|
1
4
|
import { distributionPath } from '../../distribution'
|
|
2
5
|
import {
|
|
3
6
|
DEFAULT_PROCESS_GROUP_STOP_TIMEOUT_MS,
|
|
@@ -41,22 +44,28 @@ export class LocalBuildExecution implements BuildExecution {
|
|
|
41
44
|
): Promise<BuildExecutionHandle> {
|
|
42
45
|
if (/^https?:/i.test(input.storeRef) && !auth)
|
|
43
46
|
throw new Error('remote build launch requires delegated authority')
|
|
44
|
-
const child =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
const { child, release } = spawnUsingRuntime(
|
|
48
|
+
distributionRoot(),
|
|
49
|
+
() =>
|
|
50
|
+
this.spawn(bunRuntimeArguments(this.entrypoint), {
|
|
51
|
+
env: {
|
|
52
|
+
...this.env,
|
|
53
|
+
AB_DISPATCH_GENERATION: undefined,
|
|
54
|
+
AB_TOKEN: auth?.token,
|
|
55
|
+
[BUILD_RUNNER_OPTIONS_ENV]: JSON.stringify({
|
|
56
|
+
...input,
|
|
57
|
+
supervision: { kind: 'local-parent', parentPid: process.pid },
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
stdin: 'ignore',
|
|
61
|
+
stdout: 'ignore',
|
|
62
|
+
stderr: 'ignore',
|
|
63
|
+
// On POSIX this makes the build child a new session and process-group
|
|
64
|
+
// leader. Every agent tool descendant inherits that group by default.
|
|
65
|
+
detached: true,
|
|
51
66
|
}),
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
stdout: 'ignore',
|
|
55
|
-
stderr: 'ignore',
|
|
56
|
-
// On POSIX this makes the build child a new session and process-group
|
|
57
|
-
// leader. Every agent tool descendant inherits that group by default.
|
|
58
|
-
detached: true,
|
|
59
|
-
})
|
|
67
|
+
true,
|
|
68
|
+
)
|
|
60
69
|
let reaping: Promise<void> | undefined
|
|
61
70
|
const reap = (): Promise<void> =>
|
|
62
71
|
(reaping ??= terminateProcessGroup(child.pid, this.stopTimeoutMs))
|
|
@@ -69,9 +78,20 @@ export class LocalBuildExecution implements BuildExecution {
|
|
|
69
78
|
const completion = leaderExit.then(async (exit) => {
|
|
70
79
|
// A naturally exited leader may leave inherited descendants behind.
|
|
71
80
|
await reap()
|
|
81
|
+
release()
|
|
72
82
|
return exit
|
|
73
83
|
})
|
|
74
84
|
|
|
85
|
+
let stopping: Promise<void> | undefined
|
|
86
|
+
const stop = (): Promise<void> =>
|
|
87
|
+
(stopping ??= (async () => {
|
|
88
|
+
// Signal only the leader: provider descendants must survive until the
|
|
89
|
+
// runner has closed streams and recorded native-session suspension.
|
|
90
|
+
if (child.exitCode === null) child.kill('SIGTERM')
|
|
91
|
+
await leaderExit
|
|
92
|
+
await reap()
|
|
93
|
+
})())
|
|
94
|
+
|
|
75
95
|
return {
|
|
76
96
|
pid: child.pid,
|
|
77
97
|
supervision: 'local-parent',
|
|
@@ -82,13 +102,13 @@ export class LocalBuildExecution implements BuildExecution {
|
|
|
82
102
|
},
|
|
83
103
|
completion,
|
|
84
104
|
stop: async () => {
|
|
85
|
-
await
|
|
105
|
+
await stop()
|
|
86
106
|
return { outcome: 'confirmed' }
|
|
87
107
|
},
|
|
88
108
|
// A local execution cannot outlive its parent's teardown: detach is the
|
|
89
109
|
// same full reap as stop (the kernel reaps local children on teardown).
|
|
90
110
|
detach: async () => {
|
|
91
|
-
await
|
|
111
|
+
await stop()
|
|
92
112
|
},
|
|
93
113
|
}
|
|
94
114
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DEFAULT_PROCESS_GROUP_STOP_TIMEOUT_MS } from './process-group'
|
|
2
1
|
import type { ProcessGroupReaperOptions } from './process-group-reaper'
|
|
3
2
|
import { launchProcessGroupReaper, processGroupReaperOptions } from './process-group-reaper'
|
|
4
3
|
|
|
@@ -85,42 +84,22 @@ export class BuildChildExitCoordinator {
|
|
|
85
84
|
}
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
/**
|
|
89
|
-
*
|
|
87
|
+
/** Graceful shutdown waits for the runner's durable suspension boundary.
|
|
88
|
+
* Repeated signals preserve the first intent; only the runner calls finish
|
|
89
|
+
* after persistence. Abnormal parent loss still uses finish directly. */
|
|
90
90
|
export class BuildChildShutdown {
|
|
91
91
|
private readonly controller = new AbortController()
|
|
92
|
-
private deadline: number | undefined
|
|
93
92
|
private exitCode: number | undefined
|
|
94
|
-
private
|
|
95
|
-
constructor(
|
|
96
|
-
private readonly terminal: BuildChildExitCoordinator,
|
|
97
|
-
private readonly now: () => number = Date.now,
|
|
98
|
-
private readonly schedule: (callback: () => void, delay: number) => () => void = (
|
|
99
|
-
callback,
|
|
100
|
-
delay,
|
|
101
|
-
) => {
|
|
102
|
-
const timer = setTimeout(callback, delay)
|
|
103
|
-
return () => clearTimeout(timer)
|
|
104
|
-
},
|
|
105
|
-
) {}
|
|
93
|
+
constructor(private readonly terminal: BuildChildExitCoordinator) {}
|
|
106
94
|
get signal(): AbortSignal {
|
|
107
95
|
return this.controller.signal
|
|
108
96
|
}
|
|
109
97
|
request(exitCode: number): void {
|
|
110
98
|
if (this.controller.signal.aborted) return
|
|
111
99
|
this.exitCode = exitCode
|
|
112
|
-
this.deadline = this.now() + DEFAULT_PROCESS_GROUP_STOP_TIMEOUT_MS
|
|
113
|
-
this.cancel = this.schedule(
|
|
114
|
-
() => this.finish(exitCode),
|
|
115
|
-
DEFAULT_PROCESS_GROUP_STOP_TIMEOUT_MS - 1_000,
|
|
116
|
-
)
|
|
117
100
|
this.controller.abort(new Error('dispatcher shutdown'))
|
|
118
101
|
}
|
|
119
102
|
finish(exitCode: number): void {
|
|
120
|
-
this.
|
|
121
|
-
this.terminal.terminate(
|
|
122
|
-
this.exitCode ?? exitCode,
|
|
123
|
-
this.deadline === undefined ? undefined : Math.max(0, this.deadline - this.now()),
|
|
124
|
-
)
|
|
103
|
+
this.terminal.terminate(this.exitCode ?? exitCode)
|
|
125
104
|
}
|
|
126
105
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { reportIntegrationFailures } from '../kernel/integration-attention'
|
|
2
|
+
import type { RuntimeIdentity } from '../events/runtime'
|
|
3
|
+
import { relaunchTarget } from './execution-relaunch'
|
|
4
|
+
import { RUNTIME_IDENTITY } from '../runtime-identity'
|
|
1
5
|
import { publishExact } from '../kernel/publication'
|
|
2
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
deferMixedVersion,
|
|
8
|
+
MixedVersionDeferral,
|
|
9
|
+
withDrainingExecution,
|
|
10
|
+
} from '../kernel/mixed-version'
|
|
3
11
|
import { hostname } from 'node:os'
|
|
4
12
|
import { resumeAgent } from '../ports/runner/native-session'
|
|
5
13
|
import type { AgentStartOpts } from '../ports/types'
|
|
@@ -185,6 +193,8 @@ export interface BuildRunnerDeps {
|
|
|
185
193
|
/** Runtime registry: name → adapter + compatibility data (§9). The resolver
|
|
186
194
|
* applies `config.roles`, including its reserved `default` entry, to it. */
|
|
187
195
|
runtimes: RuntimeRegistry
|
|
196
|
+
/** Immutable identity of this execution distribution; defaults to the loaded runtime. */
|
|
197
|
+
runtimeIdentity?: RuntimeIdentity
|
|
188
198
|
workspacePath: string
|
|
189
199
|
/** Explicit provider eligibility; never inferred from a matching path. */
|
|
190
200
|
workspaceProvider?: string
|
|
@@ -828,6 +838,14 @@ export class BuildRunner {
|
|
|
828
838
|
private boundaryResolver: RuntimeResolver
|
|
829
839
|
|
|
830
840
|
constructor(private readonly deps: BuildRunnerDeps) {
|
|
841
|
+
this.deps = {
|
|
842
|
+
...deps,
|
|
843
|
+
store: withDrainingExecution(
|
|
844
|
+
deps.store,
|
|
845
|
+
deps.instance,
|
|
846
|
+
deps.runtimeIdentity ?? RUNTIME_IDENTITY,
|
|
847
|
+
),
|
|
848
|
+
}
|
|
831
849
|
this.maxPhaseAttempts = deps.opts?.maxPhaseAttempts ?? 2
|
|
832
850
|
this.heartbeatMs = deps.opts?.heartbeatMs ?? 15_000
|
|
833
851
|
this.leaseTtlMs = deps.opts?.leaseTtlMs ?? BUILD_EXECUTION_LEASE_TTL_MS
|
|
@@ -935,7 +953,7 @@ export class BuildRunner {
|
|
|
935
953
|
},
|
|
936
954
|
} satisfies EventWrite<'session.ended'>)
|
|
937
955
|
}
|
|
938
|
-
await store.append(slug, {
|
|
956
|
+
const attached = await store.append(slug, {
|
|
939
957
|
actor: KERNEL,
|
|
940
958
|
type: 'runner.attached',
|
|
941
959
|
payload: {
|
|
@@ -944,6 +962,15 @@ export class BuildRunner {
|
|
|
944
962
|
...(resumedFromSeq > 0 ? { resumedFromSeq } : {}),
|
|
945
963
|
},
|
|
946
964
|
} satisfies EventWrite<'runner.attached'>)
|
|
965
|
+
await store.append(slug, {
|
|
966
|
+
actor: KERNEL,
|
|
967
|
+
type: 'runner.runtime-recorded',
|
|
968
|
+
payload: {
|
|
969
|
+
instance,
|
|
970
|
+
attachedSeq: attached.seq,
|
|
971
|
+
runtime: this.deps.runtimeIdentity ?? RUNTIME_IDENTITY,
|
|
972
|
+
},
|
|
973
|
+
})
|
|
947
974
|
}
|
|
948
975
|
|
|
949
976
|
/**
|
|
@@ -1165,9 +1192,11 @@ export class BuildRunner {
|
|
|
1165
1192
|
return decision
|
|
1166
1193
|
case 'run-check':
|
|
1167
1194
|
await this.runCheck(decision)
|
|
1195
|
+
await reportIntegrationFailures(this.deps.store, this.deps.slug)
|
|
1168
1196
|
return decision
|
|
1169
1197
|
case 'run-agent-verify':
|
|
1170
1198
|
await this.runAgentVerify(decision)
|
|
1199
|
+
await reportIntegrationFailures(this.deps.store, this.deps.slug)
|
|
1171
1200
|
return decision
|
|
1172
1201
|
case 'evaluate-verify':
|
|
1173
1202
|
await this.evaluateVerify(decision)
|
|
@@ -1190,6 +1219,31 @@ export class BuildRunner {
|
|
|
1190
1219
|
}
|
|
1191
1220
|
}
|
|
1192
1221
|
|
|
1222
|
+
private async requestRelaunch(
|
|
1223
|
+
facts: Awaited<ReturnType<typeof readBuildFacts>>['value'],
|
|
1224
|
+
): Promise<boolean> {
|
|
1225
|
+
const request = relaunchTarget(
|
|
1226
|
+
facts.state,
|
|
1227
|
+
this.deps.instance,
|
|
1228
|
+
this.deps.runtimeIdentity ?? RUNTIME_IDENTITY,
|
|
1229
|
+
)
|
|
1230
|
+
if (!request) return false
|
|
1231
|
+
if (
|
|
1232
|
+
facts.state.drainingExecutions?.[this.deps.instance]?.relaunch?.correlation ===
|
|
1233
|
+
request.correlation
|
|
1234
|
+
)
|
|
1235
|
+
return true
|
|
1236
|
+
const written = await this.deps.store.appendIfCurrent(this.deps.slug, facts.state.lastSeq, {
|
|
1237
|
+
actor: KERNEL,
|
|
1238
|
+
type: 'execution.relaunch-requested',
|
|
1239
|
+
payload: request,
|
|
1240
|
+
})
|
|
1241
|
+
// A concurrent control or authorization must be re-read before deciding.
|
|
1242
|
+
if (!written)
|
|
1243
|
+
return this.requestRelaunch((await readBuildFacts(this.deps.store, this.deps.slug)).value)
|
|
1244
|
+
return true
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1193
1247
|
/**
|
|
1194
1248
|
* The pipeline loop (§8): attach if needed, step until the build parks
|
|
1195
1249
|
* (`wait/*` — §11), return the final reduced state. Releases nothing on
|
|
@@ -1198,9 +1252,14 @@ export class BuildRunner {
|
|
|
1198
1252
|
* already deposited — see module doc).
|
|
1199
1253
|
*/
|
|
1200
1254
|
async run(): Promise<BuildState> {
|
|
1255
|
+
const initialFacts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
|
|
1256
|
+
if (await this.requestRelaunch(initialFacts)) {
|
|
1257
|
+
this.stopHeartbeat()
|
|
1258
|
+
await this.closeProducerSessions()
|
|
1259
|
+
return (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
|
|
1260
|
+
}
|
|
1201
1261
|
if (await deferMixedVersion(this.deps.store, this.deps.slug, KERNEL))
|
|
1202
1262
|
return (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
|
|
1203
|
-
const initialFacts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
|
|
1204
1263
|
const initial = initialFacts.state
|
|
1205
1264
|
if (
|
|
1206
1265
|
initial.kind === 'node' &&
|
|
@@ -1220,14 +1279,14 @@ export class BuildRunner {
|
|
|
1220
1279
|
}
|
|
1221
1280
|
try {
|
|
1222
1281
|
await this.settleLocalReconcile()
|
|
1223
|
-
if (await this.refreshSummary())
|
|
1224
|
-
return (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
|
|
1225
1282
|
for (;;) {
|
|
1226
1283
|
if (this.deps.shutdownSignal?.aborted) break
|
|
1227
|
-
if (await deferMixedVersion(this.deps.store, this.deps.slug, KERNEL)) break
|
|
1228
1284
|
await this.ensureLease()
|
|
1229
1285
|
await this.settleLocalReconcile()
|
|
1230
1286
|
const facts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
|
|
1287
|
+
if (await this.requestRelaunch(facts)) break
|
|
1288
|
+
if (await deferMixedVersion(this.deps.store, this.deps.slug, KERNEL)) break
|
|
1289
|
+
if (await this.refreshSummary()) break
|
|
1231
1290
|
if (facts.publication.pending()) {
|
|
1232
1291
|
const next = decideNextFromFacts(facts.state, facts.log, await this.captureConfig())
|
|
1233
1292
|
// Inert controls cannot start more work under unsettled publication.
|
|
@@ -1251,14 +1310,21 @@ export class BuildRunner {
|
|
|
1251
1310
|
if (await this.settlePauseInterruption()) continue
|
|
1252
1311
|
break
|
|
1253
1312
|
}
|
|
1254
|
-
if (
|
|
1255
|
-
|
|
1313
|
+
if (decision.kind === 'wait') {
|
|
1314
|
+
if (decision.reason === 'mixed-version')
|
|
1315
|
+
await this.requestRelaunch(
|
|
1316
|
+
(await readBuildFacts(this.deps.store, this.deps.slug)).value,
|
|
1317
|
+
)
|
|
1318
|
+
break
|
|
1319
|
+
}
|
|
1256
1320
|
}
|
|
1257
1321
|
return (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
|
|
1258
1322
|
} catch (error) {
|
|
1259
1323
|
if (!(error instanceof SessionShutdown) && !(error instanceof MixedVersionDeferral))
|
|
1260
1324
|
throw error
|
|
1261
|
-
|
|
1325
|
+
const facts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
|
|
1326
|
+
if (error instanceof MixedVersionDeferral) await this.requestRelaunch(facts)
|
|
1327
|
+
return facts.state
|
|
1262
1328
|
} finally {
|
|
1263
1329
|
this.stopHeartbeat()
|
|
1264
1330
|
await this.closeProducerSessions()
|
|
@@ -1987,8 +2053,10 @@ export class BuildRunner {
|
|
|
1987
2053
|
|
|
1988
2054
|
if (decision.action.kind === 'run-check') {
|
|
1989
2055
|
await this.runCheck(decision.action)
|
|
2056
|
+
await reportIntegrationFailures(this.deps.store, this.deps.slug)
|
|
1990
2057
|
} else {
|
|
1991
2058
|
await this.runAgentVerify(decision.action)
|
|
2059
|
+
await reportIntegrationFailures(this.deps.store, this.deps.slug)
|
|
1992
2060
|
}
|
|
1993
2061
|
}
|
|
1994
2062
|
|
|
@@ -2840,7 +2908,6 @@ export class BuildRunner {
|
|
|
2840
2908
|
const session = started.payload.session
|
|
2841
2909
|
const state = (await readBuildFacts(store, slug)).value.state
|
|
2842
2910
|
const native = state.sessions.open.find((s) => s.session === session)?.nativeHandle
|
|
2843
|
-
if (!native && cause === 'shutdown') return
|
|
2844
2911
|
const producer = [...this.producerSessions.entries()].find(
|
|
2845
2912
|
([phase]) => phase === started.payload.phase,
|
|
2846
2913
|
)
|
|
@@ -2855,7 +2922,10 @@ export class BuildRunner {
|
|
|
2855
2922
|
if (handle) {
|
|
2856
2923
|
try {
|
|
2857
2924
|
const owner = producer?.[1].runner ?? this.deps.runtimes[started.payload.runner]!.runner
|
|
2858
|
-
const transcript =
|
|
2925
|
+
const transcript =
|
|
2926
|
+
cause === 'shutdown'
|
|
2927
|
+
? await owner.end(handle)
|
|
2928
|
+
: await this.boundedCleanup(owner.end(handle))
|
|
2859
2929
|
content = transcript?.content
|
|
2860
2930
|
usage = value?.result?.usage ?? (producer ? undefined : transcript?.metadata.usage)
|
|
2861
2931
|
} catch {
|