@defrex/autobuild 1.11.1 → 1.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 (102) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +177 -54
  3. package/docs/answering-blocked-builds.md +10 -2
  4. package/docs/architecture.md +66 -6
  5. package/docs/assets/headline-wide.png +0 -0
  6. package/docs/configuration.md +13 -11
  7. package/docs/dispatcher.md +1 -1
  8. package/docs/integration-tree.md +28 -16
  9. package/docs/operator-api.md +4 -4
  10. package/docs/operator-surfaces.md +35 -0
  11. package/docs/optimization-nodes.md +3 -2
  12. package/docs/tickets.md +1 -1
  13. package/docs/troubleshooting.md +1 -1
  14. package/package.json +3 -3
  15. package/packages/core/src/cli/ambient-errors.ts +17 -0
  16. package/packages/core/src/cli/bounded-io.ts +174 -0
  17. package/packages/core/src/cli/dashboard/model.ts +81 -23
  18. package/packages/core/src/cli/dashboard/poll.ts +20 -31
  19. package/packages/core/src/cli/dashboard/render.ts +14 -37
  20. package/packages/core/src/cli/dashboard/row-text.ts +24 -7
  21. package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
  22. package/packages/core/src/cli/dashboard/vocabulary.ts +161 -20
  23. package/packages/core/src/cli/dispatch-handoff.ts +41 -10
  24. package/packages/core/src/cli/dispatch-launch-contract.ts +5 -0
  25. package/packages/core/src/cli/dispatch-launcher-cadence.ts +80 -0
  26. package/packages/core/src/cli/dispatch-launcher.ts +9 -10
  27. package/packages/core/src/cli/dispatch-preflight.ts +12 -3
  28. package/packages/core/src/cli/dispatch-release-observer.ts +53 -0
  29. package/packages/core/src/cli/dispatch-runtime-cache.ts +204 -82
  30. package/packages/core/src/cli/dispatch-runtime-dependencies.ts +250 -43
  31. package/packages/core/src/cli/dispatch-upgrade-install.ts +36 -16
  32. package/packages/core/src/cli/dispatch-upgrade-source.ts +8 -2
  33. package/packages/core/src/cli/dispatch-yield-observer.ts +82 -0
  34. package/packages/core/src/cli/dispatch.ts +68 -5
  35. package/packages/core/src/cli/env.ts +2 -15
  36. package/packages/core/src/cli/help.ts +5 -4
  37. package/packages/core/src/cli/main.ts +4 -2
  38. package/packages/core/src/cli/production-store.ts +102 -0
  39. package/packages/core/src/cli/repo-state.ts +2 -3
  40. package/packages/core/src/cli/repository-status.ts +28 -22
  41. package/packages/core/src/cli/sessionless-store.ts +26 -0
  42. package/packages/core/src/cli/status.ts +169 -40
  43. package/packages/core/src/cli/store-opening.ts +15 -58
  44. package/packages/core/src/cli/store-ref.ts +6 -1
  45. package/packages/core/src/config/schema.ts +1 -1
  46. package/packages/core/src/distribution-packaging.ts +156 -18
  47. package/packages/core/src/events/catalog-identity.ts +28 -0
  48. package/packages/core/src/events/catalog.ts +3 -9
  49. package/packages/core/src/events/compatibility.ts +2 -30
  50. package/packages/core/src/events/payloads.ts +11 -0
  51. package/packages/core/src/events/policy.ts +3 -0
  52. package/packages/core/src/events/repository.ts +1 -1
  53. package/packages/core/src/events/sessions.ts +1 -1
  54. package/packages/core/src/events/validation-error.ts +12 -0
  55. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +9 -0
  56. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
  57. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -0
  58. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/da3bc91c49211eab.json +310 -0
  59. package/packages/core/src/kernel/auto-merge-default.ts +2 -1
  60. package/packages/core/src/kernel/capacity-build.ts +21 -0
  61. package/packages/core/src/kernel/discard-in-flight.ts +13 -0
  62. package/packages/core/src/kernel/dispatch-capacity.ts +354 -147
  63. package/packages/core/src/kernel/engine.ts +2 -8
  64. package/packages/core/src/kernel/measurement.ts +24 -0
  65. package/packages/core/src/kernel/read-facts.ts +8 -370
  66. package/packages/core/src/kernel/reducer-registry.ts +40 -125
  67. package/packages/core/src/kernel/reducer-revisions.ts +3 -0
  68. package/packages/core/src/kernel/reducer-value-entry.ts +98 -0
  69. package/packages/core/src/kernel/reducer-value-index.ts +75 -0
  70. package/packages/core/src/kernel/reducer.ts +57 -9
  71. package/packages/core/src/kernel/reopen-state.ts +10 -0
  72. package/packages/core/src/kernel/repository-read-facts.ts +375 -0
  73. package/packages/core/src/kernel/verify-stage-state.ts +145 -3
  74. package/packages/core/src/operator/presentation.ts +13 -0
  75. package/packages/core/src/operator/query.ts +40 -39
  76. package/packages/core/src/operator/registry.ts +3 -3
  77. package/packages/core/src/ports/workspace/fake.ts +15 -3
  78. package/packages/core/src/processes/dispatcher.ts +232 -75
  79. package/packages/core/src/processes/execution-no-progress.ts +1 -0
  80. package/packages/core/src/store/local/capabilities.ts +115 -0
  81. package/packages/core/src/store/local/store.ts +86 -56
  82. package/packages/core/src/store/reduced-reads.ts +9 -1
  83. package/packages/core/src/store/reducer-value-read.ts +235 -0
  84. package/packages/core/src/store/reducer-value-shapes.json +1437 -1349
  85. package/packages/core/src/store/reducer-values.ts +36 -204
  86. package/packages/core/src/store/remote/released-clients.json +11 -0
  87. package/packages/core/src/store/remote/released-reducer-values/1.12.0.json +35806 -0
  88. package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
  89. package/packages/core/src/store/rollup-lease.ts +41 -0
  90. package/packages/core/src/store/rollups.ts +7 -38
  91. package/packages/core/src/store/snapshots.ts +1 -1
  92. package/packages/core/src/testing/dispatch-read-budget.ts +265 -4
  93. package/packages/core/src/testing/import-graph.ts +78 -0
  94. package/packages/core/src/testing/reduced-read-budget.ts +221 -22
  95. package/packages/core/src/testing/slot-agreement.ts +52 -0
  96. package/packages/core/src/web/assets/app.js +5 -5
  97. package/skills/guide/SKILL.md +115 -44
  98. package/skills/guide/references/integration-tree.md +28 -16
  99. package/skills/guide/references/operator-api.md +4 -4
  100. package/skills/guide/references/optimization-nodes.md +3 -2
  101. package/skills/operate/SKILL.md +38 -20
  102. package/templates/hosted-service/package.json +2 -2
@@ -55,21 +55,8 @@ export interface JudgeCliEnv {
55
55
  export type AmbientReadSession = CliEnv | HarvestCliEnv
56
56
 
57
57
  const PHASE_FORMAT = "'<phase>[@<round>]' (e.g. 'implement@2', 'verify:acceptance@1')"
58
- const BUILD_AMBIENT_TUPLE = 'AB_STORE/AB_BUILD/AB_PHASE/AB_SESSION'
59
- const HARVEST_AMBIENT_TUPLE = 'AB_STORE/AB_REPO/AB_HARVEST/AB_PHASE/AB_SESSION'
60
-
61
- /** Optional ambient identity is present but cannot safely select one scope. */
62
- export class InvalidAmbientContextError extends Error {
63
- override readonly name = 'InvalidAmbientContextError'
64
-
65
- constructor(detail: string) {
66
- super(
67
- `invalid ambient context: ${detail}. Expected no agent identity markers, ` +
68
- `a complete build tuple (${BUILD_AMBIENT_TUPLE}), or a complete Harvest tuple ` +
69
- `(${HARVEST_AMBIENT_TUPLE})`,
70
- )
71
- }
72
- }
58
+ export { InvalidAmbientContextError } from './ambient-errors'
59
+ import { InvalidAmbientContextError } from './ambient-errors'
73
60
 
74
61
  /** A required runner-provided session value is absent or empty. Callers that
75
62
  * resolve ambient auth directly still receive the variable-specific message;
@@ -707,10 +707,11 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
707
707
  'dashboard’s global-row r: it durably releases the queued-build hold, then',
708
708
  'turns ticket intake back on, then requests a resume on every cleanly paused',
709
709
  'build that does not already have one. A released queued build becomes',
710
- 'launchable on the next ordinary tick with no further action. Running, resuming,',
711
- 'blocked, and finished builds are skipped without error, and a build still',
712
- 'holding an open escalation is left to ab answer. Output names every build that',
713
- 'received a request, the hold, and the intake value written; --json emits that',
710
+ 'launchable on the next ordinary tick with no further action. Running builds,',
711
+ 'builds with a resume already pending, and blocked and finished builds are',
712
+ 'skipped without error, and a build still holding an open escalation is',
713
+ 'left to ab answer. Output names every build that received a request, the',
714
+ 'hold, and the intake value written; --json emits that',
714
715
  'summary as JSON. Re-running it changes nothing further. A phase session may not',
715
716
  'use --all. A failure exits nonzero and reports which of the two repository',
716
717
  'facts landed and which builds were requested.',
@@ -1000,7 +1000,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1000
1000
  }
1001
1001
 
1002
1002
  case 'builds': {
1003
- const { abBuilds } = await import('./status')
1003
+ const { abBuilds, statusColor } = await import('./status')
1004
1004
  const usage = 'usage: ab builds [--queued] [--all] [--json] [--store <ref>] (§8.2)'
1005
1005
  const parsed = parseArgs(
1006
1006
  rest,
@@ -1020,6 +1020,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1020
1020
  queued: parsed.flags.has('queued'),
1021
1021
  all: parsed.flags.has('all'),
1022
1022
  json: parsed.flags.has('json'),
1023
+ color: statusColor(deps.terminal, parsed.flags.has('json')),
1023
1024
  ...(storeRef !== undefined ? { storeRef } : {}),
1024
1025
  ...(deps.openStore !== undefined ? { openStore: deps.openStore } : {}),
1025
1026
  ...(deps.clock !== undefined ? { now: deps.clock } : {}),
@@ -1050,7 +1051,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1050
1051
  }
1051
1052
 
1052
1053
  case 'build': {
1053
- const { abBuildAssetGet, abBuildStatus } = await import('./status')
1054
+ const { abBuildAssetGet, abBuildStatus, statusColor } = await import('./status')
1054
1055
  const usage =
1055
1056
  'usage: ab build status <slug> [--events <n>] [--json] [--store <ref>] (§8.2)\n' +
1056
1057
  ' ab build asset get <slug> <kind> <name> <dest> [--rev <n>] [--json] [--store <ref>] (§8.8)'
@@ -1117,6 +1118,7 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1117
1118
  stdout,
1118
1119
  slug,
1119
1120
  json: parsed.flags.has('json'),
1121
+ color: statusColor(deps.terminal, parsed.flags.has('json')),
1120
1122
  ...(events !== undefined ? { events } : {}),
1121
1123
  ...(storeRef !== undefined ? { storeRef } : {}),
1122
1124
  ...(deps.openStore !== undefined ? { openStore: deps.openStore } : {}),
@@ -0,0 +1,102 @@
1
+ /**
2
+ * The adapter-free half of production store composition. A local reference
3
+ * never evaluates the remote HTTP adapter or repository configuration: the
4
+ * remote client loads only when `openProductionStoreAsync` opens an http(s)
5
+ * reference, and repository-state resolution lives in `store-opening.ts` and
6
+ * `sessionless-store.ts`. `store-opening.ts` re-exposes all of this with its
7
+ * eager remote factory, so its exports and behavior are unchanged.
8
+ */
9
+ import { AccountRedactor, redactAccountStore } from '../store/account-redaction'
10
+ import type { BuildStore } from '../store/types'
11
+ import { InvalidAmbientContextError } from './ambient-errors'
12
+ import { projectToken } from './project-credentials'
13
+ import type { RepoStatePaths } from './repo-state'
14
+ import { isRemoteStoreRef, resolveStore, type ResolveStoreOpts } from './store-ref'
15
+
16
+ /** Shared injection seam used by every command that opens a BuildStore. */
17
+ export type StoreOpener = (ref: string, token?: string) => BuildStore
18
+
19
+ export function optionalToken(value: string | undefined): string | undefined {
20
+ // Bearer credentials are opaque. Only absence and the exact empty value mean
21
+ // "no token"; nonempty values are forwarded byte-for-byte.
22
+ return value !== undefined && value !== '' ? value : undefined
23
+ }
24
+
25
+ /** Production local/remote composition over a supplied remote factory. */
26
+ export function composeProductionStore(
27
+ ref: string,
28
+ token: string | undefined,
29
+ remoteFactory?: ResolveStoreOpts['remoteFactory'],
30
+ ): BuildStore {
31
+ const forwardedToken = optionalToken(token)
32
+ const store = resolveStore(ref, {
33
+ ...(remoteFactory ? { remoteFactory } : {}),
34
+ ...(forwardedToken !== undefined ? { token: forwardedToken } : {}),
35
+ })
36
+ const raw = process.env.AB_ACCOUNT_CREDENTIAL_ENVS
37
+ if (!raw) return store
38
+ const names: unknown = JSON.parse(raw)
39
+ if (!Array.isArray(names) || !names.every((name) => typeof name === 'string'))
40
+ throw new Error('Invalid account credential variable inventory')
41
+ return redactAccountStore(
42
+ store,
43
+ new AccountRedactor(() => names.map((name) => process.env[name])),
44
+ )
45
+ }
46
+
47
+ /** The production remote factory, loaded with the remote adapter. */
48
+ export async function loadRemoteFactory(): Promise<NonNullable<ResolveStoreOpts['remoteFactory']>> {
49
+ const { RemoteBuildStore } = await import('../store/remote/client')
50
+ return (url, remoteToken) => new RemoteBuildStore({ url, token: remoteToken })
51
+ }
52
+
53
+ /** The production opener for `ref`: the remote adapter loads only for an
54
+ * http(s) reference. */
55
+ export async function productionOpenerFor(ref: string): Promise<StoreOpener> {
56
+ const remoteFactory = isRemoteStoreRef(ref) ? await loadRemoteFactory() : undefined
57
+ return (selected, token) => composeProductionStore(selected, token, remoteFactory)
58
+ }
59
+
60
+ /** `openProductionStore` without loading the remote adapter for a local ref. */
61
+ export async function openProductionStoreAsync(ref: string, token?: string): Promise<BuildStore> {
62
+ return (await productionOpenerFor(ref))(ref, token)
63
+ }
64
+
65
+ export interface OpenStoreForRepoStateOpts {
66
+ env: Record<string, string | undefined>
67
+ openStore?: StoreOpener
68
+ useProjectCredential?: boolean
69
+ }
70
+
71
+ export interface OpenedStoreContext extends RepoStatePaths {
72
+ store: BuildStore
73
+ token?: string
74
+ /** The validated ambient phase/Harvest identity this invocation carries, if
75
+ * any — the same value that scoped `store`. Exposed for commands whose
76
+ * repository selection also depends on ambient own-build authority. */
77
+ ambient?: import('./env').AmbientReadSession
78
+ }
79
+
80
+ /** Open from an already canonicalized state selection with `opener`. */
81
+ export function openStoreForRepoStateWith(
82
+ state: RepoStatePaths,
83
+ opts: OpenStoreForRepoStateOpts,
84
+ opener: StoreOpener,
85
+ ): OpenedStoreContext {
86
+ // A judge session's only store authority is its one preference.
87
+ if (opts.env.AB_JUDGE !== undefined)
88
+ throw new InvalidAmbientContextError('a judge session has no read authority')
89
+ const token =
90
+ opts.useProjectCredential !== false && isRemoteStoreRef(state.storeRef)
91
+ ? projectToken(state.storeRef, state.repo, opts.env)
92
+ : optionalToken(opts.env.AB_TOKEN)
93
+ if (!token && isRemoteStoreRef(state.storeRef) && state.configStore === state.storeRef) {
94
+ throw new Error('No project credential for this service; run ab connect')
95
+ }
96
+ const store = opener(state.storeRef, token)
97
+ return {
98
+ ...state,
99
+ store,
100
+ ...(token !== undefined ? { token } : {}),
101
+ }
102
+ }
@@ -32,9 +32,8 @@ export { normalizeGitRemoteUrl } from '../kernel/origin'
32
32
 
33
33
  export const LOCAL_STATE_DIR = '.autobuild'
34
34
 
35
- export function isRemoteStoreRef(ref: string): boolean {
36
- return /^https?:\/\//i.test(ref)
37
- }
35
+ export { isRemoteStoreRef } from './store-ref'
36
+ import { isRemoteStoreRef } from './store-ref'
38
37
 
39
38
  export { resolveMainRepo } from './main-checkout'
40
39
  import { resolveMainRepo } from './main-checkout'
@@ -7,7 +7,6 @@ import {
7
7
  } from '../kernel/ticket-starts'
8
8
  import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
9
9
  import { OPERATOR_PRESENCE_TTL_MS, type OperatorPresence } from '../store/operator-presence'
10
- import { migrationIdentity } from '../kernel/ticket-migrations'
11
10
  import {
12
11
  dispatchUpgradeReducer,
13
12
  upgradeRunRecency,
@@ -15,7 +14,7 @@ import {
15
14
  type UpgradeRun,
16
15
  } from '../kernel/dispatch-upgrade'
17
16
  import { formatRuntimeIdentity } from '../events/runtime'
18
- import { landingRestackDue } from '../kernel/engine'
17
+ import { capacityBuildFromFacts } from '../kernel/capacity-build'
19
18
  import {
20
19
  dispatchCapacity,
21
20
  startClaimDemand,
@@ -23,6 +22,7 @@ import {
23
22
  waitingExplanation,
24
23
  type DispatchCapacity,
25
24
  type CapacityBuild,
25
+ type SlotState,
26
26
  } from '../kernel/dispatch-capacity'
27
27
  import { backpressureStatusLine } from '../kernel/open-pr-backpressure'
28
28
  import {
@@ -574,9 +574,10 @@ export function renderRepositoryStatus(status: RepositoryStatus): string[] {
574
574
  `repository: ${status.repo}`,
575
575
  ...(status.capacity
576
576
  ? [
577
- `capacity: ${status.capacity.occupied}/${status.capacity.effective} effective; ${status.capacity.configured} configured; ${status.capacity.borrowingNodes.length} node${status.capacity.borrowingNodes.length === 1 ? '' : 's'} using descendant-held slots${status.capacity.borrowingNodes.length ? `: ${status.capacity.borrowingNodes.join(', ')}` : ''}${status.capacity.waitingNodes?.length || status.capacity.waitingBuilds?.length || status.capacity.urgentClaims || status.capacity.startRequests ? `; ${waitingExplanation(status.capacity, { requests: true })}` : ''}`,
577
+ `capacity: ${status.capacity.occupied}/${status.capacity.configured}${status.capacity.waitingNodes?.length || status.capacity.waitingBuilds?.length || status.capacity.urgentClaims || status.capacity.startRequests ? `; ${waitingExplanation(status.capacity, { requests: true })}` : ''}`,
578
578
  ]
579
579
  : []),
580
+ ...(status.capacity?.slots ? [slotsStatusLine(status.capacity.slots)] : []),
580
581
  ...(status.capacity?.backpressure
581
582
  ? [backpressureStatusLine(status.capacity.backpressure)]
582
583
  : []),
@@ -723,6 +724,24 @@ export function localOverridesFromArtifact(
723
724
 
724
725
  /** Capacity is optional when no held dispatcher has a retrievable configuration
725
726
  * (`artifact` comes from `readHeldEffectiveConfig`). */
727
+ /** Every reported build's slot state, grouped held, requested and none,
728
+ * each group sorted by slug; `none` when no build is reported. Builds whose
729
+ * state is unknown are not listed. */
730
+ function slotsStatusLine(slots: Record<string, SlotState>): string {
731
+ const entries = Object.entries(slots).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
732
+ const label = (slug: string, slot: SlotState) =>
733
+ slot.state === 'requested'
734
+ ? `${slug} (${slot.request}${slot.priority === 'urgent' ? ', urgent' : ''})`
735
+ : slug
736
+ const clauses = (['held', 'requested', 'none'] as const).flatMap((state) => {
737
+ const members = entries.filter(([, slot]) => slot.state === state)
738
+ return members.length
739
+ ? [`${state} ${members.map(([slug, slot]) => label(slug, slot)).join(', ')}`]
740
+ : []
741
+ })
742
+ return `slots: ${clauses.length ? clauses.join('; ') : 'none'}`
743
+ }
744
+
726
745
  export async function readRepositoryCapacity(
727
746
  store: BuildStore,
728
747
  repo: string,
@@ -739,26 +758,13 @@ export async function readRepositoryCapacity(
739
758
  // settled build, so this read stays flat as history accumulates.
740
759
  for (const { record, digest } of await store.listOpenBuilds(repo)) {
741
760
  if (digest.terminal) continue
742
- const build = (await readBuildFacts(store, record.slug)).value
743
- builds.push({
744
- record,
745
- state: build.state,
746
- workspace: build.workspace !== null,
747
- provisioning: build.provisionMarker !== undefined,
748
- restackDue: landingRestackDue(build.state, build.log),
749
- })
761
+ builds.push(capacityBuildFromFacts(record, (await readBuildFacts(store, record.slug)).value))
750
762
  }
751
- return dispatchCapacity(
752
- builds,
753
- config.capacity,
754
- now,
755
- migrationIdentity(facts.ticketMigrations, config.tickets.source),
756
- {
757
- urgentClaims: urgentClaimDemand(facts),
758
- startRequests: startClaimDemand(facts),
759
- openPrs: { policy: config.policy, engaged: facts.openPrBackpressure !== undefined },
760
- },
761
- )
763
+ return dispatchCapacity(builds, config.capacity, now, {
764
+ urgentClaims: urgentClaimDemand(facts),
765
+ startRequests: startClaimDemand(facts),
766
+ openPrs: { policy: config.policy, engaged: facts.openPrBackpressure !== undefined },
767
+ })
762
768
  }
763
769
 
764
770
  /**
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `openSessionlessStore` for callers that must not evaluate the remote adapter
3
+ * for a local reference. This is the only light-path module that resolves
4
+ * repository state (and with it configuration), so readers that already know
5
+ * their journal never load it.
6
+ */
7
+ import { resolveRepoState } from './repo-state'
8
+ import {
9
+ openStoreForRepoStateWith,
10
+ productionOpenerFor,
11
+ type OpenedStoreContext,
12
+ } from './production-store'
13
+ import type { SessionlessStoreOpts } from './store-opening'
14
+
15
+ export async function openSessionlessStoreLazily(
16
+ opts: SessionlessStoreOpts,
17
+ ): Promise<OpenedStoreContext> {
18
+ const state = await resolveRepoState({
19
+ targetRepo: opts.targetRepo,
20
+ exec: opts.exec,
21
+ ...(opts.storeRef !== undefined ? { storeRef: opts.storeRef } : {}),
22
+ ...(opts.env.AB_STORE !== undefined ? { envStore: opts.env.AB_STORE } : {}),
23
+ })
24
+ const opener = opts.openStore ?? (await productionOpenerFor(state.storeRef))
25
+ return openStoreForRepoStateWith(state, opts, opener)
26
+ }