@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
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/** The variables through which the shared test runner (`tools/test-temp-leaks.ts`)
|
|
2
2
|
* isolates every suite child from the developer's global, XDG and system git
|
|
3
|
-
* config. */
|
|
3
|
+
* config and from their per-user state home (where build worktrees default). */
|
|
4
4
|
export const GIT_CONFIG_ISOLATION_KEYS = [
|
|
5
5
|
'GIT_CONFIG_GLOBAL',
|
|
6
6
|
'GIT_CONFIG_NOSYSTEM',
|
|
7
7
|
'GIT_CONFIG_SYSTEM',
|
|
8
|
+
'XDG_STATE_HOME',
|
|
8
9
|
] as const
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
* The defined git config isolation variables in `env`. A
|
|
12
|
-
* subprocess with a hand-picked environment forwarding the
|
|
13
|
-
* spread this next to it, or the child rediscovers the
|
|
14
|
-
* `~/.gitconfig` and `~/.config/git/config` (rerere, signing, …)
|
|
12
|
+
* The defined git config and per-user state isolation variables in `env`. A
|
|
13
|
+
* test that spawns a subprocess with a hand-picked environment forwarding the
|
|
14
|
+
* real `HOME` must spread this next to it, or the child rediscovers the
|
|
15
|
+
* developer's `~/.gitconfig` and `~/.config/git/config` (rerere, signing, …)
|
|
16
|
+
* and provisions build worktrees under their `~/.local/state`.
|
|
15
17
|
*/
|
|
16
18
|
export function inheritedGitConfigIsolation(
|
|
17
19
|
env: Record<string, string | undefined> = process.env,
|
|
@@ -74,12 +74,24 @@ export {
|
|
|
74
74
|
targetedCompletenessParity,
|
|
75
75
|
ticketListReadBudget,
|
|
76
76
|
ticketPageReadBudget,
|
|
77
|
+
ticketSearchReadBudget,
|
|
78
|
+
ticketSearchRequestBudget,
|
|
79
|
+
ticketSearchRows,
|
|
77
80
|
ticketTargetingReadBudget,
|
|
78
81
|
type TicketPageFixture,
|
|
82
|
+
type TicketSearchFixture,
|
|
83
|
+
type TicketSearchRequestFixture,
|
|
84
|
+
type TicketSearchRow,
|
|
79
85
|
type TicketTargetingFixture,
|
|
80
86
|
} from './dispatch-read-budget'
|
|
81
87
|
|
|
82
88
|
export {
|
|
89
|
+
buildFeedReadBudget,
|
|
90
|
+
filteredBuildPageReadBudget,
|
|
91
|
+
buildRosterReadBudget,
|
|
92
|
+
rollupReadBudget,
|
|
93
|
+
rollupRemoteReadBudget,
|
|
94
|
+
type RollupReadCost,
|
|
83
95
|
catalogSkewReadBudget,
|
|
84
96
|
reducedReadBudget,
|
|
85
97
|
countHistoricalRows,
|
|
@@ -117,6 +129,16 @@ export { REDUCER_REVISIONS } from '../kernel/reducer-revisions'
|
|
|
117
129
|
export { projectReducerValue } from '../store/reducer-value-validation'
|
|
118
130
|
|
|
119
131
|
export { placementReadBudget } from './reduced-read-budget'
|
|
132
|
+
export {
|
|
133
|
+
operatorSandboxCallReadBudget,
|
|
134
|
+
operatorSandboxListingReadBudget,
|
|
135
|
+
} from './reduced-read-budget'
|
|
136
|
+
export {
|
|
137
|
+
memoryOperatorSandbox,
|
|
138
|
+
MEMORY_SANDBOX_BASE_SHA,
|
|
139
|
+
MEMORY_SANDBOX_HEAD_SHA,
|
|
140
|
+
type MemoryOperatorSandbox,
|
|
141
|
+
} from './memory-operator-sandbox'
|
|
120
142
|
export { ticketRoleTickBudget } from './reduced-read-budget'
|
|
121
143
|
export { urgentIntakeReadBudget } from './reduced-read-budget'
|
|
122
144
|
export { openPrBackpressureReadBudget } from './reduced-read-budget'
|
|
@@ -130,3 +152,8 @@ export { kernelGitUnavailableDetail } from '../kernel/kernel-git'
|
|
|
130
152
|
// The judge's self-contained launcher, for seam tests that run it against a
|
|
131
153
|
// hosted store.
|
|
132
154
|
export { bundleJudgeLauncher } from '../processes/judge-launcher'
|
|
155
|
+
export {
|
|
156
|
+
AGENT_CONTEXT_ARTIFACT,
|
|
157
|
+
encodeAgentContext,
|
|
158
|
+
type AgentContextRecord,
|
|
159
|
+
} from '../store/agent-context'
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An IO-free operator-sandbox provider double for unit tests: it implements
|
|
3
|
+
* only what `createOperatorSandboxService` touches (`name`,
|
|
4
|
+
* `orchestratorSandbox`, `sandboxPublication`) and records every command,
|
|
5
|
+
* file and push in memory. `FakeWorkspaceProvider` spawns processes and
|
|
6
|
+
* touches the filesystem, so tests under the unit IO guard use this instead.
|
|
7
|
+
*
|
|
8
|
+
* Lifecycle: `immediate` provisioning (the default) makes `open` return
|
|
9
|
+
* `ready` at once; `deferred` returns `provisioning`/`resuming` plus a
|
|
10
|
+
* `settled` promise the test resolves through `complete`. Environment state
|
|
11
|
+
* (existence, recorded base head, failure) lives in the double itself, the
|
|
12
|
+
* analogue of the local providers' on-disk marker, so a second service over
|
|
13
|
+
* the same double sees it without the first service's promise. No timers.
|
|
14
|
+
*/
|
|
15
|
+
import type { WorkspaceProvider, WorkspacePublication } from '../ports/types'
|
|
16
|
+
import type {
|
|
17
|
+
OperatorSandboxExecution,
|
|
18
|
+
SandboxCommandResult,
|
|
19
|
+
SandboxEnvironmentIdentity,
|
|
20
|
+
SandboxProviderStatus,
|
|
21
|
+
SandboxProvisionStage,
|
|
22
|
+
SandboxRefreshResult,
|
|
23
|
+
} from '../ports/workspace/operator-sandbox'
|
|
24
|
+
|
|
25
|
+
/** The base head every fresh provision reports by default. */
|
|
26
|
+
export const MEMORY_SANDBOX_BASE_SHA = '0'.repeat(40)
|
|
27
|
+
/** The checkout head `git rev-parse` reports, a descendant of the base. */
|
|
28
|
+
export const MEMORY_SANDBOX_HEAD_SHA = '1'.repeat(40)
|
|
29
|
+
|
|
30
|
+
export interface MemoryOperatorSandboxOptions {
|
|
31
|
+
provisioning?: 'immediate' | 'deferred'
|
|
32
|
+
/** `close`/`release` of a deferred in-flight attempt resolve it `ready`
|
|
33
|
+
* instead of cancelling it: setup finished just before the abort. */
|
|
34
|
+
completeBeforeClose?: boolean
|
|
35
|
+
/** `false` models a provider without the lifecycle: `lifecycleSupported`
|
|
36
|
+
* is false and `ensure` plus every lifecycle method throws if called. */
|
|
37
|
+
lifecycle?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface MemoryOperatorSandbox {
|
|
41
|
+
provider: WorkspaceProvider
|
|
42
|
+
/** Every exec/start, in order, with the environment it ran in. */
|
|
43
|
+
readonly commands: { environmentId: string; command: string }[]
|
|
44
|
+
/** Every published commit, in order. */
|
|
45
|
+
readonly pushes: { ref: string; sha: string; branch: string }[]
|
|
46
|
+
/** Every release, in order. */
|
|
47
|
+
readonly releases: { operator: string; environmentId: string }[]
|
|
48
|
+
/** Checkout files, keyed by `<environmentId>\0<path>`. */
|
|
49
|
+
readonly files: Map<string, Uint8Array>
|
|
50
|
+
/** Every `open` call, in order. */
|
|
51
|
+
readonly opened: { environmentId: string }[]
|
|
52
|
+
/** Every `close` call, in order. */
|
|
53
|
+
readonly closed: { environmentId: string }[]
|
|
54
|
+
/** Every `refresh` call, in order. */
|
|
55
|
+
readonly refreshes: { environmentId: string }[]
|
|
56
|
+
/** Environments whose in-flight attempt `close`/`release` cancelled. */
|
|
57
|
+
readonly cancelled: string[]
|
|
58
|
+
/** Calls to `ensure` (the service must make none). */
|
|
59
|
+
readonly ensureCalls: string[]
|
|
60
|
+
/** Settle the latest non-cancelled in-flight attempt. A no-op when none
|
|
61
|
+
* is in flight (a late completion of a cancelled attempt). */
|
|
62
|
+
complete(
|
|
63
|
+
result: 'ready' | { stage: SandboxProvisionStage; message: string },
|
|
64
|
+
baseSha?: string,
|
|
65
|
+
): void
|
|
66
|
+
/** The next `refresh` result; defaults to a fast-forward. */
|
|
67
|
+
refreshResult: SandboxRefreshResult
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface Attempt {
|
|
71
|
+
environmentId: string
|
|
72
|
+
kind: 'provision' | 'resume'
|
|
73
|
+
resolve: (status: SandboxProviderStatus) => void
|
|
74
|
+
promise: Promise<SandboxProviderStatus>
|
|
75
|
+
done: boolean
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function scripted(command: string): SandboxCommandResult {
|
|
79
|
+
if (command.startsWith('git rev-parse'))
|
|
80
|
+
return { exitCode: 0, stdout: `${MEMORY_SANDBOX_HEAD_SHA}\n`, stderr: '' }
|
|
81
|
+
if (command.startsWith('git status --porcelain')) return { exitCode: 0, stdout: '', stderr: '' }
|
|
82
|
+
if (command.startsWith('git merge-base --is-ancestor'))
|
|
83
|
+
return { exitCode: 0, stdout: '', stderr: '' }
|
|
84
|
+
return { exitCode: 0, stdout: command, stderr: '' }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function memoryOperatorSandbox(
|
|
88
|
+
name = 'memory-sandbox',
|
|
89
|
+
opts: MemoryOperatorSandboxOptions = {},
|
|
90
|
+
): MemoryOperatorSandbox {
|
|
91
|
+
const deferred = opts.provisioning === 'deferred'
|
|
92
|
+
const lifecycle = opts.lifecycle !== false
|
|
93
|
+
const commands: MemoryOperatorSandbox['commands'] = []
|
|
94
|
+
const pushes: MemoryOperatorSandbox['pushes'] = []
|
|
95
|
+
const releases: MemoryOperatorSandbox['releases'] = []
|
|
96
|
+
const opened: MemoryOperatorSandbox['opened'] = []
|
|
97
|
+
const closed: MemoryOperatorSandbox['closed'] = []
|
|
98
|
+
const refreshes: MemoryOperatorSandbox['refreshes'] = []
|
|
99
|
+
const cancelled: string[] = []
|
|
100
|
+
const ensureCalls: string[] = []
|
|
101
|
+
const files = new Map<string, Uint8Array>()
|
|
102
|
+
const started = new Map<string, SandboxCommandResult>()
|
|
103
|
+
/** Provisioned environments: their recorded base head and whether closed. */
|
|
104
|
+
const environments = new Map<string, { baseSha: string; stopped: boolean }>()
|
|
105
|
+
const failures = new Map<string, { stage: SandboxProvisionStage; message: string }>()
|
|
106
|
+
const inflight = new Map<string, Attempt>()
|
|
107
|
+
const attempts: Attempt[] = []
|
|
108
|
+
|
|
109
|
+
const identity = (input: { repo: string; operator: string }): SandboxEnvironmentIdentity => ({
|
|
110
|
+
provider: name,
|
|
111
|
+
environmentId: `${name}:${input.repo}:${input.operator}`,
|
|
112
|
+
workspacePath: '/checkout',
|
|
113
|
+
})
|
|
114
|
+
const ready = (
|
|
115
|
+
handle: SandboxEnvironmentIdentity,
|
|
116
|
+
kind?: 'provision' | 'resume',
|
|
117
|
+
): SandboxProviderStatus => {
|
|
118
|
+
const env = environments.get(handle.environmentId)
|
|
119
|
+
return {
|
|
120
|
+
state: 'ready',
|
|
121
|
+
handle: { ...handle, ...(env !== undefined ? { baseSha: env.baseSha } : {}) },
|
|
122
|
+
headSha: MEMORY_SANDBOX_HEAD_SHA,
|
|
123
|
+
...(kind !== undefined ? { kind } : {}),
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const settle = (attempt: Attempt, status: SandboxProviderStatus): void => {
|
|
127
|
+
if (attempt.done) return
|
|
128
|
+
attempt.done = true
|
|
129
|
+
if (inflight.get(attempt.environmentId) === attempt) inflight.delete(attempt.environmentId)
|
|
130
|
+
attempt.resolve(status)
|
|
131
|
+
}
|
|
132
|
+
const finish = (
|
|
133
|
+
attempt: Attempt,
|
|
134
|
+
handle: SandboxEnvironmentIdentity,
|
|
135
|
+
result: 'ready' | { stage: SandboxProvisionStage; message: string },
|
|
136
|
+
baseSha = MEMORY_SANDBOX_BASE_SHA,
|
|
137
|
+
): void => {
|
|
138
|
+
if (result === 'ready') {
|
|
139
|
+
const existing = environments.get(attempt.environmentId)
|
|
140
|
+
environments.set(attempt.environmentId, {
|
|
141
|
+
baseSha: attempt.kind === 'resume' && existing !== undefined ? existing.baseSha : baseSha,
|
|
142
|
+
stopped: false,
|
|
143
|
+
})
|
|
144
|
+
settle(attempt, ready(handle, attempt.kind))
|
|
145
|
+
} else {
|
|
146
|
+
failures.set(attempt.environmentId, result)
|
|
147
|
+
settle(attempt, { state: 'failed', failure: result })
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Cancel (or, with `completeBeforeClose`, complete) an in-flight attempt. */
|
|
151
|
+
const stopAttempt = (handle: SandboxEnvironmentIdentity): SandboxProviderStatus | undefined => {
|
|
152
|
+
const attempt = inflight.get(handle.environmentId)
|
|
153
|
+
if (attempt === undefined) return undefined
|
|
154
|
+
if (opts.completeBeforeClose === true) {
|
|
155
|
+
finish(attempt, handle, 'ready')
|
|
156
|
+
return ready(handle, attempt.kind)
|
|
157
|
+
}
|
|
158
|
+
cancelled.push(handle.environmentId)
|
|
159
|
+
const status: SandboxProviderStatus = { state: 'absent', cancelled: true }
|
|
160
|
+
settle(attempt, status)
|
|
161
|
+
return status
|
|
162
|
+
}
|
|
163
|
+
const disabled = (operation: string): never => {
|
|
164
|
+
throw new Error(`memory operator sandbox has no lifecycle; ${operation} must not be called`)
|
|
165
|
+
}
|
|
166
|
+
const byEnvironment = (environmentId: string): SandboxEnvironmentIdentity => ({
|
|
167
|
+
provider: name,
|
|
168
|
+
environmentId,
|
|
169
|
+
workspacePath: '/checkout',
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
const orchestratorSandbox: OperatorSandboxExecution = {
|
|
173
|
+
lifecycleSupported: lifecycle,
|
|
174
|
+
async describe(input) {
|
|
175
|
+
return identity(input)
|
|
176
|
+
},
|
|
177
|
+
async ensure(input) {
|
|
178
|
+
ensureCalls.push(identity(input).environmentId)
|
|
179
|
+
if (!lifecycle) disabled('ensure')
|
|
180
|
+
return { ...identity(input), baseSha: MEMORY_SANDBOX_BASE_SHA }
|
|
181
|
+
},
|
|
182
|
+
async open(input) {
|
|
183
|
+
if (!lifecycle) disabled('open')
|
|
184
|
+
const handle = identity(input)
|
|
185
|
+
opened.push({ environmentId: handle.environmentId })
|
|
186
|
+
const current = inflight.get(handle.environmentId)
|
|
187
|
+
if (current !== undefined) {
|
|
188
|
+
return {
|
|
189
|
+
status: {
|
|
190
|
+
state: current.kind === 'resume' ? 'resuming' : 'provisioning',
|
|
191
|
+
kind: current.kind,
|
|
192
|
+
},
|
|
193
|
+
settled: current.promise,
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const env = environments.get(handle.environmentId)
|
|
197
|
+
const kind = env !== undefined ? 'resume' : 'provision'
|
|
198
|
+
failures.delete(handle.environmentId)
|
|
199
|
+
if (!deferred) {
|
|
200
|
+
if (env === undefined) {
|
|
201
|
+
environments.set(handle.environmentId, {
|
|
202
|
+
baseSha: MEMORY_SANDBOX_BASE_SHA,
|
|
203
|
+
stopped: false,
|
|
204
|
+
})
|
|
205
|
+
} else {
|
|
206
|
+
env.stopped = false
|
|
207
|
+
}
|
|
208
|
+
return { status: ready(handle, kind) }
|
|
209
|
+
}
|
|
210
|
+
if (env !== undefined && !env.stopped) return { status: ready(handle, 'resume') }
|
|
211
|
+
let resolve!: (status: SandboxProviderStatus) => void
|
|
212
|
+
const promise = new Promise<SandboxProviderStatus>((r) => {
|
|
213
|
+
resolve = r
|
|
214
|
+
})
|
|
215
|
+
const attempt: Attempt = {
|
|
216
|
+
environmentId: handle.environmentId,
|
|
217
|
+
kind,
|
|
218
|
+
resolve,
|
|
219
|
+
promise,
|
|
220
|
+
done: false,
|
|
221
|
+
}
|
|
222
|
+
inflight.set(handle.environmentId, attempt)
|
|
223
|
+
attempts.push(attempt)
|
|
224
|
+
return {
|
|
225
|
+
status: { state: kind === 'resume' ? 'resuming' : 'provisioning', kind },
|
|
226
|
+
settled: promise,
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
async status(input) {
|
|
230
|
+
if (!lifecycle) disabled('status')
|
|
231
|
+
const handle = identity(input)
|
|
232
|
+
const current = inflight.get(handle.environmentId)
|
|
233
|
+
if (current !== undefined)
|
|
234
|
+
return { state: current.kind === 'resume' ? 'resuming' : 'provisioning' }
|
|
235
|
+
const failure = failures.get(handle.environmentId)
|
|
236
|
+
if (failure !== undefined) return { state: 'failed', failure }
|
|
237
|
+
const env = environments.get(handle.environmentId)
|
|
238
|
+
if (env === undefined) return { state: 'absent' }
|
|
239
|
+
if (env.stopped) return { state: 'stopped' }
|
|
240
|
+
return ready(handle)
|
|
241
|
+
},
|
|
242
|
+
async close(input) {
|
|
243
|
+
if (!lifecycle) disabled('close')
|
|
244
|
+
closed.push({ environmentId: input.environmentId })
|
|
245
|
+
const handle = byEnvironment(input.environmentId)
|
|
246
|
+
const attempt = stopAttempt(handle)
|
|
247
|
+
const env = environments.get(input.environmentId)
|
|
248
|
+
if (env !== undefined) env.stopped = true
|
|
249
|
+
return {
|
|
250
|
+
outcome: env !== undefined ? 'closed' : 'absent',
|
|
251
|
+
...(attempt !== undefined ? { attempt } : {}),
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
async refresh(handle) {
|
|
255
|
+
if (!lifecycle) disabled('refresh')
|
|
256
|
+
refreshes.push({ environmentId: handle.environmentId })
|
|
257
|
+
return sandbox.refreshResult
|
|
258
|
+
},
|
|
259
|
+
async exec(handle, request) {
|
|
260
|
+
commands.push({ environmentId: handle.environmentId, command: request.command })
|
|
261
|
+
return scripted(request.command)
|
|
262
|
+
},
|
|
263
|
+
async start(handle, request) {
|
|
264
|
+
commands.push({ environmentId: handle.environmentId, command: request.command })
|
|
265
|
+
const commandId = `cmd-${commands.length}`
|
|
266
|
+
started.set(commandId, scripted(request.command))
|
|
267
|
+
return { commandId }
|
|
268
|
+
},
|
|
269
|
+
async wait(_handle, input) {
|
|
270
|
+
const result = started.get(input.commandId)
|
|
271
|
+
return result === undefined
|
|
272
|
+
? { state: 'exited', exitCode: 127, stdout: '', stderr: 'unknown command id' }
|
|
273
|
+
: { state: 'exited', ...result }
|
|
274
|
+
},
|
|
275
|
+
async readFile(handle, path) {
|
|
276
|
+
const content = files.get(`${handle.environmentId}\0${path}`)
|
|
277
|
+
if (content === undefined) throw new Error(`no such file: ${path}`)
|
|
278
|
+
return content
|
|
279
|
+
},
|
|
280
|
+
async writeFile(handle, path, content) {
|
|
281
|
+
files.set(`${handle.environmentId}\0${path}`, content)
|
|
282
|
+
},
|
|
283
|
+
async stop() {
|
|
284
|
+
return { outcome: 'unsupported' }
|
|
285
|
+
},
|
|
286
|
+
async release(input) {
|
|
287
|
+
releases.push({ operator: input.operator, environmentId: input.environmentId })
|
|
288
|
+
const attempt = inflight.get(input.environmentId)
|
|
289
|
+
if (attempt !== undefined) {
|
|
290
|
+
cancelled.push(input.environmentId)
|
|
291
|
+
settle(attempt, { state: 'absent', cancelled: true })
|
|
292
|
+
}
|
|
293
|
+
environments.delete(input.environmentId)
|
|
294
|
+
failures.delete(input.environmentId)
|
|
295
|
+
for (const key of [...files.keys()])
|
|
296
|
+
if (key.startsWith(`${input.environmentId}\0`)) files.delete(key)
|
|
297
|
+
return { snapshots: { outcome: 'confirmed', deleted: 0 } }
|
|
298
|
+
},
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const sandboxPublication: WorkspacePublication = {
|
|
302
|
+
async isPublished(input) {
|
|
303
|
+
return pushes.some((push) => push.sha === input.sha && push.branch === input.branch)
|
|
304
|
+
},
|
|
305
|
+
async publish(input) {
|
|
306
|
+
pushes.push({ ...input })
|
|
307
|
+
},
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const provider: WorkspaceProvider = {
|
|
311
|
+
name,
|
|
312
|
+
orchestratorSandbox,
|
|
313
|
+
sandboxPublication,
|
|
314
|
+
async provision() {
|
|
315
|
+
throw new Error('memory operator sandbox provider does not provision build workspaces')
|
|
316
|
+
},
|
|
317
|
+
async release() {
|
|
318
|
+
throw new Error('memory operator sandbox provider does not release build workspaces')
|
|
319
|
+
},
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const sandbox: MemoryOperatorSandbox = {
|
|
323
|
+
provider,
|
|
324
|
+
commands,
|
|
325
|
+
pushes,
|
|
326
|
+
releases,
|
|
327
|
+
files,
|
|
328
|
+
opened,
|
|
329
|
+
closed,
|
|
330
|
+
refreshes,
|
|
331
|
+
cancelled,
|
|
332
|
+
ensureCalls,
|
|
333
|
+
refreshResult: {
|
|
334
|
+
outcome: 'refreshed',
|
|
335
|
+
headSha: '2'.repeat(40),
|
|
336
|
+
baseSha: '2'.repeat(40),
|
|
337
|
+
previousHeadSha: MEMORY_SANDBOX_HEAD_SHA,
|
|
338
|
+
},
|
|
339
|
+
complete(result, baseSha) {
|
|
340
|
+
const attempt = attempts.filter((candidate) => !candidate.done).at(-1)
|
|
341
|
+
if (attempt === undefined) return
|
|
342
|
+
finish(attempt, byEnvironment(attempt.environmentId), result, baseSha)
|
|
343
|
+
},
|
|
344
|
+
}
|
|
345
|
+
return sandbox
|
|
346
|
+
}
|