@defrex/autobuild 1.10.0 → 1.11.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.
- package/README.md +1 -1
- package/SPEC.md +738 -68
- package/bin/ab-dispatch-generation.ts +3 -1
- package/docs/accounts.md +2 -1
- package/docs/answering-blocked-builds.md +20 -0
- package/docs/architecture.md +155 -25
- package/docs/build-store.md +10 -7
- package/docs/cli.md +33 -1
- package/docs/configuration-overview.md +4 -1
- package/docs/configuration.md +381 -29
- package/docs/dispatcher.md +63 -4
- package/docs/forges.md +7 -0
- package/docs/integration-tree.md +2 -2
- package/docs/operating.md +4 -2
- package/docs/operator-api.md +134 -6
- package/docs/operator-surfaces.md +85 -0
- package/docs/optimization-nodes.md +69 -11
- package/docs/plugin-authoring.md +37 -1
- package/docs/remote-store-protocol.md +94 -13
- package/docs/remote-ticket-protocol.md +40 -0
- package/docs/restacking.md +20 -4
- package/docs/setup.md +14 -2
- package/docs/ticket-dependencies.md +10 -3
- package/docs/ticket-sources.md +24 -2
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +8 -0
- package/docs/verification.md +4 -3
- package/docs/workspaces.md +3 -0
- package/package.json +9 -5
- package/packages/core/src/cli/accounts.ts +7 -2
- package/packages/core/src/cli/attention.ts +3 -1
- package/packages/core/src/cli/binary-direct.ts +2 -0
- package/packages/core/src/cli/binary-lifecycle.ts +2 -1
- package/packages/core/src/cli/build-control.ts +79 -1
- package/packages/core/src/cli/context.ts +4 -0
- package/packages/core/src/cli/dashboard/facts.ts +49 -53
- package/packages/core/src/cli/dashboard/header.ts +101 -0
- package/packages/core/src/cli/dashboard/model.ts +31 -39
- package/packages/core/src/cli/dashboard/objective-row.ts +46 -14
- package/packages/core/src/cli/dashboard/poll.ts +178 -76
- package/packages/core/src/cli/dashboard/render.ts +129 -230
- package/packages/core/src/cli/dashboard/row-text.ts +538 -0
- package/packages/core/src/cli/dashboard/timeline.ts +288 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +188 -0
- package/packages/core/src/cli/dispatch-args.ts +44 -1
- package/packages/core/src/cli/dispatch-frontend.ts +29 -38
- package/packages/core/src/cli/dispatch-launch-stop.ts +18 -0
- package/packages/core/src/cli/dispatch-launcher.ts +20 -7
- package/packages/core/src/cli/dispatch-web.ts +155 -0
- package/packages/core/src/cli/dispatch.ts +200 -34
- package/packages/core/src/cli/help.ts +87 -3
- package/packages/core/src/cli/init-validation.ts +3 -3
- package/packages/core/src/cli/main.ts +70 -6
- package/packages/core/src/cli/mcp.ts +35 -3
- package/packages/core/src/cli/objective.ts +1 -1
- package/packages/core/src/cli/operator-preference.ts +57 -0
- package/packages/core/src/cli/repo-lease.ts +2 -0
- package/packages/core/src/cli/repo-state.ts +56 -6
- package/packages/core/src/cli/repository-status.ts +97 -43
- package/packages/core/src/cli/status.ts +82 -1
- package/packages/core/src/cli/terminal-restore.ts +32 -7
- package/packages/core/src/cli/ticket.ts +98 -36
- package/packages/core/src/cli/wait.ts +14 -6
- package/packages/core/src/cli/watch.ts +20 -4
- package/packages/core/src/cli/web.ts +139 -0
- package/packages/core/src/config/live.ts +99 -14
- package/packages/core/src/config/load.ts +61 -20
- package/packages/core/src/config/local.ts +212 -0
- package/packages/core/src/config/pipeline-source.ts +2 -0
- package/packages/core/src/config/reference.ts +18 -0
- package/packages/core/src/config/schema.ts +45 -10
- package/packages/core/src/events/catalog.ts +4 -0
- package/packages/core/src/events/payloads.ts +97 -0
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +46 -3
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +316 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/017d8dd5bb6dd80b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/178e12f1759b7552.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4932c70a2af97faf.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/536085773daf6b58.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6bd6275061aaffa5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/89625654b02e9ac1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a98af134be2da8a9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d5d5ccca80a893d8.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f8155387eb5f375c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3c27f918b194e3b3.json +465 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/79f0e0f4ccd43ba2.json +455 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/859c09edac738823.json +1086 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a283c1f3462b1cc1.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6e570fb126991ff.json +36 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a8acf22c968b6e3d.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ba7b85895bf6698e.json +1153 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc66408cde0b6b04.json +637 -0
- package/packages/core/src/kernel/build-roster.ts +230 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +4 -2
- package/packages/core/src/kernel/engine.ts +43 -5
- package/packages/core/src/kernel/execution-intervals.ts +61 -0
- package/packages/core/src/kernel/generators/optimization-log.ts +101 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +13 -0
- package/packages/core/src/kernel/leaf-restack-base.ts +33 -7
- package/packages/core/src/kernel/leaf-restack-state.ts +82 -3
- package/packages/core/src/kernel/log-index.ts +19 -0
- package/packages/core/src/kernel/optimization-admission.ts +244 -3
- package/packages/core/src/kernel/optimization.ts +183 -4
- package/packages/core/src/kernel/phase-failures.ts +121 -0
- package/packages/core/src/kernel/published-branch-head.ts +60 -0
- package/packages/core/src/kernel/reducer-registry.ts +27 -8
- package/packages/core/src/kernel/reducer-revisions.ts +25 -0
- package/packages/core/src/kernel/reducer.ts +63 -4
- package/packages/core/src/kernel/rollup.ts +61 -0
- package/packages/core/src/kernel/setup-streak.ts +38 -0
- package/packages/core/src/kernel/step-durations.ts +257 -0
- package/packages/core/src/kernel/target-observation.ts +6 -1
- package/packages/core/src/kernel/target-rewrite-recovery.ts +116 -0
- package/packages/core/src/kernel/verify-diff-base.ts +5 -0
- package/packages/core/src/kernel/verify-stages.ts +13 -3
- package/packages/core/src/ontology.ts +5 -0
- package/packages/core/src/operator/agent-context-serve.ts +631 -0
- package/packages/core/src/operator/annotations.ts +75 -5
- package/packages/core/src/operator/attention.ts +470 -0
- package/packages/core/src/operator/canonical-skills.ts +35 -0
- package/packages/core/src/operator/cli-equivalents.ts +270 -0
- package/packages/core/src/operator/context-prompts.ts +61 -0
- package/packages/core/src/operator/index.ts +49 -1
- package/packages/core/src/operator/landings.ts +28 -19
- package/packages/core/src/operator/optimization.ts +7 -0
- package/packages/core/src/operator/protocol.ts +3 -0
- package/packages/core/src/operator/query.ts +122 -72
- package/packages/core/src/operator/read-view.ts +5 -2
- package/packages/core/src/operator/registry.ts +406 -46
- package/packages/core/src/operator/requests.ts +20 -18
- package/packages/core/src/operator/sandbox-host.ts +107 -11
- package/packages/core/src/operator/sandbox-resolver.ts +253 -0
- package/packages/core/src/operator/sandbox.ts +778 -82
- package/packages/core/src/operator/ticket-asset-list.ts +77 -0
- package/packages/core/src/operator/ticket-assets.ts +167 -0
- package/packages/core/src/operator/tickets.ts +33 -2
- package/packages/core/src/plugin-sdk/index.ts +22 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/fake.ts +92 -1
- package/packages/core/src/ports/forge/git-blob.ts +15 -0
- package/packages/core/src/ports/forge/github.ts +82 -0
- package/packages/core/src/ports/forge/local-git.ts +61 -1
- package/packages/core/src/ports/forge-failure.ts +24 -0
- package/packages/core/src/ports/runner/antigravity-test.fixture.ts +149 -0
- package/packages/core/src/ports/runner/claude-test.fixture.ts +71 -0
- package/packages/core/src/ports/runner/codex-test.fixture.ts +63 -0
- package/packages/core/src/ports/tickets/contract.ts +71 -0
- package/packages/core/src/ports/tickets/fake.ts +11 -0
- package/packages/core/src/ports/tickets/file.ts +18 -0
- package/packages/core/src/ports/tickets/github-fake.ts +136 -4
- package/packages/core/src/ports/tickets/github.ts +387 -30
- package/packages/core/src/ports/tickets/hosted-index.ts +10 -0
- package/packages/core/src/ports/tickets/linear.ts +130 -0
- package/packages/core/src/ports/tickets/priority.ts +9 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +34 -0
- package/packages/core/src/ports/tickets/remote.ts +70 -6
- package/packages/core/src/ports/tickets/search.ts +139 -0
- package/packages/core/src/ports/types.ts +104 -2
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +9 -0
- package/packages/core/src/ports/workspace/create.ts +15 -1
- package/packages/core/src/ports/workspace/fake.ts +340 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +833 -42
- package/packages/core/src/ports/workspace/operator-sandbox.ts +129 -12
- package/packages/core/src/ports/workspace/process-group.ts +48 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +1260 -123
- package/packages/core/src/processes/agent-context-assemble.ts +576 -0
- package/packages/core/src/processes/agent-context.ts +469 -0
- package/packages/core/src/processes/build-runner.ts +387 -236
- package/packages/core/src/processes/dispatcher.ts +211 -55
- package/packages/core/src/processes/execution-no-progress.ts +4 -0
- package/packages/core/src/processes/optimization-activity.ts +120 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/repo-view.ts +78 -2
- package/packages/core/src/processes/sandbox-state.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +2 -0
- package/packages/core/src/processes/workspace-preparation.ts +76 -0
- package/packages/core/src/scenarios/harness.ts +0 -5
- package/packages/core/src/store/account-redaction.ts +1 -0
- package/packages/core/src/store/adapter.ts +52 -1
- package/packages/core/src/store/agent-context.ts +432 -0
- package/packages/core/src/store/build-feed.ts +291 -0
- package/packages/core/src/store/build-scope.ts +19 -1
- package/packages/core/src/store/contract.ts +911 -14
- package/packages/core/src/store/digest.ts +19 -6
- package/packages/core/src/store/histogram.ts +113 -0
- package/packages/core/src/store/local/schema.ts +62 -0
- package/packages/core/src/store/local/store.ts +628 -22
- package/packages/core/src/store/local/ticket-asset-heads.ts +23 -0
- package/packages/core/src/store/memory.ts +461 -69
- package/packages/core/src/store/open-builds.ts +19 -0
- package/packages/core/src/store/phase-session.ts +32 -4
- package/packages/core/src/store/reduced-reads.ts +14 -4
- package/packages/core/src/store/reducer-value-shapes.json +6987 -5749
- package/packages/core/src/store/reducer-values.ts +6 -1
- package/packages/core/src/store/remote/client.ts +208 -2
- package/packages/core/src/store/remote/compatibility.ts +1 -1
- package/packages/core/src/store/remote/index.ts +33 -0
- package/packages/core/src/store/remote/protocol.ts +69 -0
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.0.json +35680 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
- package/packages/core/src/store/retention.ts +23 -1
- package/packages/core/src/store/rollups.ts +337 -0
- package/packages/core/src/store/session-handle.ts +20 -2
- package/packages/core/src/store/snapshots.ts +10 -0
- package/packages/core/src/store/types.ts +108 -9
- package/packages/core/src/testing/dispatch-read-budget.ts +1092 -2
- package/packages/core/src/testing/git-config-isolation.ts +7 -5
- package/packages/core/src/testing/index.ts +27 -0
- package/packages/core/src/testing/memory-operator-sandbox.ts +346 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1873 -98
- package/packages/core/src/web/analytics-source.ts +303 -0
- package/packages/core/src/web/assets/Atkinson-OFL.txt +93 -0
- package/packages/core/src/web/assets/AtkinsonHyperlegibleNext.latin.woff2 +0 -0
- package/packages/core/src/web/assets/JetBrains-OFL.txt +93 -0
- package/packages/core/src/web/assets/JetBrainsMono.latin.woff2 +0 -0
- package/packages/core/src/web/assets/app.css +1 -0
- package/packages/core/src/web/assets/app.js +9 -0
- package/packages/core/src/web/assets/manifest.json +31 -0
- package/packages/core/src/web/assets/theme.js +1 -0
- package/packages/core/src/web/bounded.ts +31 -0
- package/packages/core/src/web/http.ts +315 -0
- package/packages/core/src/web/hub.ts +160 -0
- package/packages/core/src/web/options.ts +38 -0
- package/packages/core/src/web/overview-source.ts +322 -0
- package/packages/core/src/web/page.ts +56 -0
- package/packages/core/src/web/protocol.ts +151 -0
- package/packages/core/src/web/read-only.ts +23 -0
- package/packages/core/src/web/repository-source.ts +35 -0
- package/packages/core/src/web/server.ts +97 -0
- package/skills/code-review/SKILL.md +10 -2
- package/skills/guide/SKILL.md +366 -52
- package/skills/guide/references/accounts.md +2 -1
- package/skills/guide/references/integration-tree.md +2 -2
- package/skills/guide/references/operator-api.md +134 -6
- package/skills/guide/references/optimization-nodes.md +69 -11
- package/skills/guide/references/plugin-authoring.md +37 -1
- package/skills/guide/references/remote-store-protocol.md +94 -13
- package/skills/guide/references/remote-ticket-protocol.md +40 -0
- package/skills/guide/references/restacking.md +20 -4
- package/skills/guide/references/setup.md +14 -2
- package/skills/guide/references/ticket-dependencies.md +10 -3
- package/skills/implement/SKILL.md +23 -4
- package/skills/operate/SKILL.md +134 -32
- package/skills/plan/SKILL.md +10 -4
- package/skills/plan-review/SKILL.md +9 -2
- package/skills/spec/SKILL.md +34 -8
- package/skills/tickets/SKILL.md +51 -5
- package/templates/hosted-service/package.json +2 -2
|
@@ -20,7 +20,7 @@ import { defineReducer, type IncrementalReducer } from '../kernel/incremental'
|
|
|
20
20
|
import type { AttemptOutcome } from '../events/payloads'
|
|
21
21
|
import {
|
|
22
22
|
advanceOptimization,
|
|
23
|
-
|
|
23
|
+
foldsIntoOptimization,
|
|
24
24
|
isProposerWakeEvent,
|
|
25
25
|
optimizationSignal,
|
|
26
26
|
PROPOSER_WAKE_EVENT_TYPES,
|
|
@@ -58,6 +58,8 @@ export const DIGEST_EVENT_TYPES = [
|
|
|
58
58
|
'escalation.answered',
|
|
59
59
|
'attempt.settled',
|
|
60
60
|
'attempt.ticket-rejected',
|
|
61
|
+
// The node's active-hours clock: attempt execution batches.
|
|
62
|
+
'optimization.activity-recorded',
|
|
61
63
|
// The optimization signal: the node's optimization facts, its proposer
|
|
62
64
|
// deferrals, and every fact that can clear a deferral.
|
|
63
65
|
'optimization.proposal-deferred',
|
|
@@ -121,6 +123,9 @@ export interface DigestAcc {
|
|
|
121
123
|
reclaimed: number[]
|
|
122
124
|
/** `openExecution`: the latest start's instance, cleared only by an instance-matched end. */
|
|
123
125
|
openInstance: string | null
|
|
126
|
+
/** Every `execution.started` and `execution.ended`: the count an
|
|
127
|
+
* optimization node compares with what its clock has accounted. */
|
|
128
|
+
executionFacts: number
|
|
124
129
|
/** Sorted unique node slugs any target or parent move has named. */
|
|
125
130
|
nodeTargets: string[]
|
|
126
131
|
/** The latest ticket-wait fact is a request without its outcome. */
|
|
@@ -144,12 +149,14 @@ export interface DigestAcc {
|
|
|
144
149
|
export class BuildDigestCapabilityError extends Error {
|
|
145
150
|
constructor(
|
|
146
151
|
readonly slug: string,
|
|
147
|
-
readonly capability: 'nodeTargets' | 'optimization' = 'nodeTargets',
|
|
152
|
+
readonly capability: 'nodeTargets' | 'optimization' | 'execution' = 'nodeTargets',
|
|
148
153
|
) {
|
|
149
154
|
super(
|
|
150
155
|
capability === 'nodeTargets'
|
|
151
156
|
? `build digest for ${slug} has no nodeTargets: the store's digest answer predates node targets`
|
|
152
|
-
:
|
|
157
|
+
: capability === 'optimization'
|
|
158
|
+
? `build digest for node ${slug} has no optimization signal: the store's digest answer predates optimization proposing`
|
|
159
|
+
: `build digest for ${slug} has no executionFacts: the store's digest answer predates active-hours budgets`,
|
|
153
160
|
)
|
|
154
161
|
this.name = 'BuildDigestCapabilityError'
|
|
155
162
|
}
|
|
@@ -186,12 +193,13 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
186
193
|
hosted: [],
|
|
187
194
|
reclaimed: [],
|
|
188
195
|
openInstance: null,
|
|
196
|
+
executionFacts: 0,
|
|
189
197
|
nodeTargets: [],
|
|
190
198
|
}),
|
|
191
199
|
fold(acc, events) {
|
|
192
200
|
for (const event of events) {
|
|
193
201
|
if (event.rawUnknown) advanceCompatibility(acc.compatibility, [event.rawUnknown])
|
|
194
|
-
if (event.optimizationEvent !== undefined &&
|
|
202
|
+
if (event.optimizationEvent !== undefined && foldsIntoOptimization(event.optimizationEvent))
|
|
195
203
|
acc.optimization = advanceOptimization(acc.optimization, [event.optimizationEvent])
|
|
196
204
|
if (event.type === 'optimization.proposal-deferred') acc.proposerDeferredSeq = event.seq
|
|
197
205
|
else if (isProposerWakeEvent(event)) acc.proposerWakeSeq = event.seq
|
|
@@ -258,8 +266,11 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
258
266
|
const remaining = acc.pendingRejections.filter((p) => p !== event.attemptProposal)
|
|
259
267
|
acc.pendingRejections = remaining.length > 0 ? remaining : undefined
|
|
260
268
|
}
|
|
261
|
-
} else if (event.type === 'execution.started')
|
|
262
|
-
|
|
269
|
+
} else if (event.type === 'execution.started') {
|
|
270
|
+
acc.executionFacts += 1
|
|
271
|
+
acc.openInstance = event.instance ?? null
|
|
272
|
+
} else if (event.type === 'execution.ended') {
|
|
273
|
+
acc.executionFacts += 1
|
|
263
274
|
if (acc.openInstance !== null && event.instance === acc.openInstance)
|
|
264
275
|
acc.openInstance = null
|
|
265
276
|
}
|
|
@@ -280,6 +291,7 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
280
291
|
hosted,
|
|
281
292
|
reclaimed,
|
|
282
293
|
openInstance,
|
|
294
|
+
executionFacts,
|
|
283
295
|
nodeTargets,
|
|
284
296
|
waitPending,
|
|
285
297
|
ticketWait,
|
|
@@ -306,6 +318,7 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
306
318
|
...(terminal !== undefined ? { terminal } : {}),
|
|
307
319
|
...(reclaimPending ? { reclaimPending: true as const } : {}),
|
|
308
320
|
...(openInstance !== null ? { executionOpen: true as const } : {}),
|
|
321
|
+
executionFacts,
|
|
309
322
|
...(waitPending ? { waitPending } : {}),
|
|
310
323
|
...(ticketWait !== undefined ? { ticketWait: structuredClone(ticketWait) } : {}),
|
|
311
324
|
...(pendingRejections?.length ? { rejectionsPending: true as const } : {}),
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log-scale duration histograms for rollups (RFC 0007 §8.6, SPEC §7.7).
|
|
3
|
+
*
|
|
4
|
+
* Bucket `i` covers `[1000·1.1^i, 1000·1.1^(i+1))` milliseconds: 10% wide,
|
|
5
|
+
* from 1 second to about 7.2 days in 140 buckets. Shorter durations clamp
|
|
6
|
+
* into bucket 0 and longer ones into bucket 139. A histogram is sparse, and
|
|
7
|
+
* each bucket keeps a count and an exact sum, so a mean or total is exact
|
|
8
|
+
* and a percentile is within 5% of the exact nearest-rank value.
|
|
9
|
+
*
|
|
10
|
+
* Pure and browser-safe: plain JSON in and out, no Bun or `node:` APIs.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from 'zod'
|
|
13
|
+
|
|
14
|
+
export const HISTOGRAM_MIN_MS = 1_000
|
|
15
|
+
export const HISTOGRAM_GROWTH = 1.1
|
|
16
|
+
export const HISTOGRAM_BUCKETS = 140
|
|
17
|
+
|
|
18
|
+
/** Bucket index → `[count, sumMs]`. Empty buckets are absent. */
|
|
19
|
+
export type Histogram = Record<string, [number, number]>
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Cast because non-`strict` consumers (plugins typechecking this source) infer
|
|
23
|
+
* zod tuple elements as optional; the runtime schema is the two-element tuple.
|
|
24
|
+
*/
|
|
25
|
+
export const histogramSchema = z.record(
|
|
26
|
+
z.string().regex(/^(0|[1-9][0-9]?|1[0-3][0-9])$/),
|
|
27
|
+
z.tuple([z.number().int().positive(), z.number().nonnegative()]),
|
|
28
|
+
) as unknown as z.ZodType<Histogram>
|
|
29
|
+
|
|
30
|
+
const LOG_GROWTH = Math.log(HISTOGRAM_GROWTH)
|
|
31
|
+
|
|
32
|
+
/** The bucket a duration falls in, clamped to the histogram's range. */
|
|
33
|
+
export function bucketOf(ms: number): number {
|
|
34
|
+
if (!(ms > HISTOGRAM_MIN_MS)) return 0
|
|
35
|
+
const index = Math.floor(Math.log(ms / HISTOGRAM_MIN_MS) / LOG_GROWTH)
|
|
36
|
+
return Math.min(HISTOGRAM_BUCKETS - 1, Math.max(0, index))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The lower bound of bucket `index`, in milliseconds. */
|
|
40
|
+
export function bucketLow(index: number): number {
|
|
41
|
+
return HISTOGRAM_MIN_MS * HISTOGRAM_GROWTH ** index
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Add `count` observations whose durations sum to `sumMs` to one bucket. */
|
|
45
|
+
export function addCell(hist: Histogram, bucket: number, count: number, sumMs: number): void {
|
|
46
|
+
const key = String(bucket)
|
|
47
|
+
const cell = hist[key]
|
|
48
|
+
if (cell === undefined) hist[key] = [count, sumMs]
|
|
49
|
+
else hist[key] = [cell[0] + count, cell[1] + sumMs]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The inverse of `addCell`. A bucket whose count reaches zero is removed. */
|
|
53
|
+
export function subtractCell(hist: Histogram, bucket: number, count: number, sumMs: number): void {
|
|
54
|
+
const key = String(bucket)
|
|
55
|
+
const cell = hist[key]
|
|
56
|
+
if (cell === undefined) return
|
|
57
|
+
const next: [number, number] = [cell[0] - count, cell[1] - sumMs]
|
|
58
|
+
if (next[0] <= 0) delete hist[key]
|
|
59
|
+
else hist[key] = [next[0], Math.max(0, next[1])]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Add every bucket of `from` into `into`. */
|
|
63
|
+
export function mergeInto(into: Histogram, from: Histogram): void {
|
|
64
|
+
for (const [bucket, [count, sum]] of Object.entries(from))
|
|
65
|
+
addCell(into, Number(bucket), count, sum)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Subtract every bucket of `from` out of `into`. */
|
|
69
|
+
export function subtractFrom(into: Histogram, from: Histogram): void {
|
|
70
|
+
for (const [bucket, [count, sum]] of Object.entries(from))
|
|
71
|
+
subtractCell(into, Number(bucket), count, sum)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface HistogramTotals {
|
|
75
|
+
count: number
|
|
76
|
+
totalMs: number
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function totals(hist: Histogram): HistogramTotals {
|
|
80
|
+
let count = 0
|
|
81
|
+
let totalMs = 0
|
|
82
|
+
for (const [c, s] of Object.values(hist)) {
|
|
83
|
+
count += c
|
|
84
|
+
totalMs += s
|
|
85
|
+
}
|
|
86
|
+
return { count, totalMs }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The nearest-rank `q` quantile (0 < q ≤ 1). Within its bucket the estimate is
|
|
91
|
+
* the geometric midpoint `lo·√1.1`, at most 4.9% from any value in the bucket.
|
|
92
|
+
* The clamping buckets 0 and 139 answer their mean instead, because they hold
|
|
93
|
+
* values outside their nominal bounds. An empty histogram answers 0.
|
|
94
|
+
*/
|
|
95
|
+
export function percentile(hist: Histogram, q: number): number {
|
|
96
|
+
const { count } = totals(hist)
|
|
97
|
+
if (count === 0) return 0
|
|
98
|
+
const rank = Math.max(1, Math.ceil(q * count))
|
|
99
|
+
const buckets = Object.keys(hist)
|
|
100
|
+
.map(Number)
|
|
101
|
+
.sort((a, b) => a - b)
|
|
102
|
+
let seen = 0
|
|
103
|
+
for (const bucket of buckets) {
|
|
104
|
+
const [c, sum] = hist[String(bucket)]!
|
|
105
|
+
seen += c
|
|
106
|
+
if (seen >= rank) {
|
|
107
|
+
if (bucket === 0 || bucket === HISTOGRAM_BUCKETS - 1) return sum / c
|
|
108
|
+
return bucketLow(bucket) * Math.sqrt(HISTOGRAM_GROWTH)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Unreachable: the ranks sum to `count`.
|
|
112
|
+
return 0
|
|
113
|
+
}
|
|
@@ -44,6 +44,21 @@ export const builds = sqliteTable(
|
|
|
44
44
|
(t) => [index('builds_repo_created_slug').on(t.repo, t.createdAt, t.slug)],
|
|
45
45
|
)
|
|
46
46
|
|
|
47
|
+
/** The open-build set (`BuildStore.listOpenBuilds`): one row per build whose
|
|
48
|
+
* latest terminal fact is not `build.completed`. Maintained by the
|
|
49
|
+
* `OPEN_BUILDS_DDL` triggers inside every appending statement's transaction,
|
|
50
|
+
* and backfilled once when the table is first created. */
|
|
51
|
+
export const openBuilds = sqliteTable(
|
|
52
|
+
'open_builds',
|
|
53
|
+
{
|
|
54
|
+
slug: text('slug')
|
|
55
|
+
.primaryKey()
|
|
56
|
+
.references(() => builds.slug, { onDelete: 'cascade' }),
|
|
57
|
+
repo: text('repo').notNull(),
|
|
58
|
+
},
|
|
59
|
+
(t) => [index('open_builds_repo_slug').on(t.repo, t.slug)],
|
|
60
|
+
)
|
|
61
|
+
|
|
47
62
|
export const events = sqliteTable(
|
|
48
63
|
'events',
|
|
49
64
|
{
|
|
@@ -253,6 +268,53 @@ export const repoChangePositions = sqliteTable('repo_change_positions', {
|
|
|
253
268
|
position: integer('position').notNull(),
|
|
254
269
|
})
|
|
255
270
|
|
|
271
|
+
/** Each build's latest repository change position, written by the same
|
|
272
|
+
* trigger statement that advances `repo_change_positions`. One row per build,
|
|
273
|
+
* upserted in place; the changed-builds feed range-scans `(repo, position)`. */
|
|
274
|
+
export const buildChangePositions = sqliteTable(
|
|
275
|
+
'build_change_positions',
|
|
276
|
+
{
|
|
277
|
+
slug: text('slug').primaryKey(),
|
|
278
|
+
repo: text('repo').notNull(),
|
|
279
|
+
position: integer('position').notNull(),
|
|
280
|
+
},
|
|
281
|
+
(t) => [index('build_change_positions_repo_position').on(t.repo, t.position)],
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
/** Per-build listing facts behind the paged listing's filters, maintained by
|
|
285
|
+
* triggers in the writing transaction (`BUILD_LISTING_DDL`): kind from
|
|
286
|
+
* `build.created`, merged from the latest `build.completed` (cleared by
|
|
287
|
+
* `build.reopened`), and a mirror of `builds.updated_at`. One index per filter
|
|
288
|
+
* class and order makes every filtered page one bounded range scan. */
|
|
289
|
+
export const buildListingFacts = sqliteTable(
|
|
290
|
+
'build_listing_facts',
|
|
291
|
+
{
|
|
292
|
+
slug: text('slug').primaryKey(),
|
|
293
|
+
repo: text('repo').notNull(),
|
|
294
|
+
createdAt: text('created_at').notNull(),
|
|
295
|
+
updatedAt: text('updated_at').notNull(),
|
|
296
|
+
node: integer('node').notNull().default(0),
|
|
297
|
+
merged: integer('merged').notNull().default(0),
|
|
298
|
+
},
|
|
299
|
+
(t) => [
|
|
300
|
+
index('build_listing_kind_created').on(t.repo, t.node, t.createdAt, t.slug),
|
|
301
|
+
index('build_listing_merged_created')
|
|
302
|
+
.on(t.repo, t.createdAt, t.slug)
|
|
303
|
+
.where(sql`${t.merged} = 1`),
|
|
304
|
+
index('build_listing_merged_kind_created')
|
|
305
|
+
.on(t.repo, t.node, t.createdAt, t.slug)
|
|
306
|
+
.where(sql`${t.merged} = 1`),
|
|
307
|
+
index('build_listing_updated').on(t.repo, t.updatedAt, t.slug),
|
|
308
|
+
index('build_listing_kind_updated').on(t.repo, t.node, t.updatedAt, t.slug),
|
|
309
|
+
index('build_listing_merged_updated')
|
|
310
|
+
.on(t.repo, t.updatedAt, t.slug)
|
|
311
|
+
.where(sql`${t.merged} = 1`),
|
|
312
|
+
index('build_listing_merged_kind_updated')
|
|
313
|
+
.on(t.repo, t.node, t.updatedAt, t.slug)
|
|
314
|
+
.where(sql`${t.merged} = 1`),
|
|
315
|
+
],
|
|
316
|
+
)
|
|
317
|
+
|
|
256
318
|
export const operatorPresence = sqliteTable(
|
|
257
319
|
'operator_presence',
|
|
258
320
|
{
|