@lensmcp/protocol-types 1.26.1 → 1.26.3

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.
@@ -0,0 +1,673 @@
1
+ import type { WorkspaceActionLane } from './workspace-actions.js';
2
+ /**
3
+ * The Docker work LensMCP runs (planning/docker/00-plan.md, issues/open/overseer-74): what its slices share. A gate
4
+ * stack's containers live in Docker's VM, whose memory the Mac gave away when the VM started — so the machine queue,
5
+ * which admits by the host's free memory, was blind to them, and a stack started into an OOM that killed the engine.
6
+ *
7
+ * Pure: the dashboard reads these too, so nothing here touches the filesystem or a process.
8
+ */
9
+ /**
10
+ * The labels on what LensMCP starts in Docker. A container, network or volume is LensMCP's only by these — one it did
11
+ * not start carries none and is never touched.
12
+ */
13
+ export declare const DOCKER_LABELS: {
14
+ /** The run that started it. */
15
+ readonly run: "com.lensmcp.run";
16
+ /** A hash of the LENSMCP_HOME that started it: a spec's scratch home never sweeps the real home's stacks. */
17
+ readonly home: "com.lensmcp.home";
18
+ /** The job's name in `lensmcp.json` → `jobs`. */
19
+ readonly job: "com.lensmcp.job";
20
+ /** The one-shot container that reads the VM's memory. */
21
+ readonly probe: "com.lensmcp.probe";
22
+ };
23
+ /**
24
+ * How the VM's free memory was read: `meminfo` is the VM kernel's own `/proc/meminfo`, read from a probe container;
25
+ * `estimate` is the total less what the running containers use and 1 GiB for the VM itself, taken when the probe
26
+ * could not run — admission then asks for twice its reserve.
27
+ */
28
+ export type DockerVmRead = 'meminfo' | 'estimate';
29
+ /** The memory of Docker's VM as one read found it, MiB. */
30
+ export interface DockerVmMemory {
31
+ totalMb: number;
32
+ /** What a new container can still take: `MemAvailable`, or the estimate. */
33
+ availableMb: number;
34
+ read: DockerVmRead;
35
+ /** With `estimate`: why the VM's own figure could not be read. */
36
+ why?: string;
37
+ }
38
+ /**
39
+ * The VM as a run met it: the `vm` of a run's `docker` block (plan § 4). Admission writes what it was admitted on
40
+ * (slice D3); the lowest free figure while it ran is the sampler's (slice D6).
41
+ */
42
+ export interface DockerRunVm {
43
+ totalMb: number;
44
+ /** What a new container could still take when the queue let the run in. */
45
+ availableAtAdmissionMb: number;
46
+ /** The lowest the run's sampler read while it ran — none: no sample read the VM (the probe did not run). */
47
+ minAvailableMb?: number;
48
+ /** What the sampler last read, and when: the VM's own figure (`meminfo`), whatever admission went by. */
49
+ lastAvailableMb?: number;
50
+ sampledAt?: number;
51
+ /** `estimate`: let in on the weaker read, with twice the reserve. */
52
+ read: DockerVmRead;
53
+ }
54
+ /**
55
+ * A job is declared once, as data, in the committed root `lensmcp.json` → `jobs` (plan § 1). Only LensMCP reads it; a
56
+ * plain run of the project never loads it. A worker runs only jobs the candidate's own committed manifest declares,
57
+ * and the channel carries a job's **name**, never a command — so everything a job may run or read is here, and
58
+ * everything here is checked: a key this version does not know refuses the job rather than being dropped unread.
59
+ *
60
+ * - `compose`: a Compose project and the project's own command that drives it (build, up, tests, its own report).
61
+ * - `testcontainers`: a host test command whose containers come and go.
62
+ * - `playwright`: stories against a URL — a `compose` job's stack (`stack`), or the dev cluster.
63
+ */
64
+ export type LensJobKind = 'compose' | 'testcontainers' | 'playwright';
65
+ export declare const LENS_JOB_KINDS: readonly LensJobKind[];
66
+ /**
67
+ * What a job reads outside the committed tree (plan § 1, § 12; slices D2, D24). Paths are written as git names them
68
+ * (`fixtures/seed.json`: no `./`, no `//`, no trailing `/`, nothing inside `.git`), so a declared file is the one a
69
+ * checkout lists.
70
+ */
71
+ export interface LensJobInputs {
72
+ /**
73
+ * Files shipped with the candidate to a worker, by content and hash, whatever git thinks of them — and what a proof
74
+ * of the job fingerprints, on the organizer as on a worker. Never a file {@link neverShipped} names.
75
+ */
76
+ files?: string[];
77
+ /** Files made per run, on the host that runs it (a 0600 `compose.env`): never shipped, never fingerprinted. */
78
+ minted?: string[];
79
+ /** Provider keys, by **name**: a value travels only for a run the person authorizes. */
80
+ secrets?: string[];
81
+ }
82
+ /**
83
+ * The files that never leave the Mac they are on (plan § 12, slice D24): `.env`, `.env.local`, and the machine-local
84
+ * overrides every dotenv convention keeps beside them (`.env.<mode>.local`) — in any folder, whatever their case
85
+ * (a Mac's disk does not tell `.ENV` from `.env`). Not in a candidate's diff, not as a declared input: a job that needs
86
+ * one declares it `minted` and makes it per run on the host that runs it.
87
+ */
88
+ export declare function neverShipped(path: string): boolean;
89
+ /** A job's declared input files, each once, sorted: what is shipped by hash, and what its proof fingerprints. */
90
+ export declare const jobInputFiles: (job: LensJob) => string[];
91
+ /** A job's minted files, each once, sorted: made per run where it runs, never shipped. */
92
+ export declare const jobMintedFiles: (job: LensJob) => string[];
93
+ interface LensJobCommon {
94
+ /** The machine queue's lane — none: by the kind ({@link jobLane}). */
95
+ lane?: WorkspaceActionLane;
96
+ /** Steps before the command, each a program and its arguments (`yarn install --frozen-lockfile`). */
97
+ prepare?: string[][];
98
+ /** The project's own command: a program and its arguments, never a shell line. */
99
+ command: string[];
100
+ /** Run when the command did not end on its own; LensMCP's `down -v` follows whatever it leaves. */
101
+ cleanup?: string[];
102
+ /** The structured report the command writes. */
103
+ report?: 'jest' | 'vitest' | 'playwright';
104
+ /** Folders kept as the run's evidence. */
105
+ artifacts?: string[];
106
+ inputs?: LensJobInputs;
107
+ timeoutMinutes?: number;
108
+ /** A run lost with its worker may be placed again elsewhere, once. */
109
+ retryable?: boolean;
110
+ /** `<project>:<target>`: `workspace_action_run` runs the job as that target's e2e. */
111
+ nx?: string;
112
+ }
113
+ export interface ComposeJob extends LensJobCommon {
114
+ kind: 'compose';
115
+ compose: {
116
+ /** The compose files, in the checkout. */
117
+ files: string[];
118
+ /** The service and container port the run's URL reaches. */
119
+ edge?: {
120
+ service: string;
121
+ port: number;
122
+ };
123
+ };
124
+ /**
125
+ * The memory it declares, MiB. `services`: each service's expected peak in the VM — every service the compose files
126
+ * name has one, so a new service cannot slip in uncounted. `buildMb`: the image build's peak in the VM. `hostMb`:
127
+ * its processes on the host.
128
+ */
129
+ budget: {
130
+ services: Record<string, number>;
131
+ buildMb?: number;
132
+ hostMb?: number;
133
+ };
134
+ }
135
+ export interface TestcontainersJob extends LensJobCommon {
136
+ kind: 'testcontainers';
137
+ /** `vmMb`: its containers together, in the VM (small). `hostMb`: the test runner on the host (large). */
138
+ budget: {
139
+ vmMb: number;
140
+ hostMb: number;
141
+ };
142
+ }
143
+ export interface PlaywrightJob extends LensJobCommon {
144
+ kind: 'playwright';
145
+ /** The `compose` job whose stack it runs against — none: the dev cluster. */
146
+ stack?: string;
147
+ /** The browsers: on the host (`hostMb`), in a container (`vmMb`), or both. The stack's own budget is added to it. */
148
+ budget: {
149
+ hostMb?: number;
150
+ vmMb?: number;
151
+ };
152
+ }
153
+ export type LensJob = ComposeJob | TestcontainersJob | PlaywrightJob;
154
+ /** What keeps a job from running — of one job, or of the `jobs` block itself. */
155
+ export interface LensJobProblem {
156
+ job?: string;
157
+ problem: string;
158
+ }
159
+ export interface LensJobsRead {
160
+ /** The jobs that may run, by name. A job with a problem is not among them. */
161
+ jobs: Record<string, LensJob>;
162
+ problems: LensJobProblem[];
163
+ }
164
+ /** A problem as one line: «jobs.system-e2e: api-worker has no budget». */
165
+ export declare const jobProblemText: (p: LensJobProblem) => string;
166
+ /**
167
+ * `lensmcp.json` → `jobs`, as written: the jobs that may run, and what is wrong with the others. A job with a problem
168
+ * is left out whole — a manifest half-read would run a stack on a budget nobody declared.
169
+ */
170
+ export declare function readLensJobs(raw: unknown): LensJobsRead;
171
+ /**
172
+ * The memory a job needs in Docker's VM, MiB. A stack: `max(buildMb, Σ services)` — the build and the boot run one
173
+ * after the other, so the larger of the two. Stories on a stack add their browsers' container to what runs.
174
+ * `jobs`: the file's jobs, for a `stack`.
175
+ */
176
+ export declare function jobVmNeedMb(job: LensJob, jobs?: Readonly<Record<string, LensJob>>): number;
177
+ /** The memory a job's processes need on the host, MiB — a stack's own driver beside its stories'. */
178
+ export declare function jobHostNeedMb(job: LensJob, jobs?: Readonly<Record<string, LensJob>>): number;
179
+ /** The lane a job waits in: its own, else heavy for a stack (and stories on one), light for the rest. */
180
+ export declare function jobLane(job: LensJob): WorkspaceActionLane;
181
+ /**
182
+ * The services the compose files name that the budget does not, sorted — each refuses the job («api-worker has no
183
+ * budget»). A budget entry no file names is left alone: it only counts more than runs.
184
+ */
185
+ export declare function unbudgetedServices(job: ComposeJob, composeServices: readonly string[]): string[];
186
+ /**
187
+ * A run's id: letters, digits, `_` and `-`, eight to eighty characters (`q_<uuid>`, `wa_<uuid>`) — a label's value, a
188
+ * file's name in the run registry and, by its first eight, a host and a Compose project.
189
+ *
190
+ * The dev gateway holds the same rule for a run's route (`@lensmcp/cluster`, `runtime/run-routes.ts`). That package
191
+ * does not depend on this one — it mirrors the shapes it shares, each with a parity spec — so the rule, the short id,
192
+ * the longest lease and the request and answer shapes below are written twice, and
193
+ * `run-routes.contract.spec.ts` there fails when the two differ.
194
+ */
195
+ export declare const RUN_ID_PATTERN: RegExp;
196
+ /**
197
+ * The eight characters of a run's id that name it where a whole id does not fit: its letters and digits, lowercased,
198
+ * after a `wa_`-like prefix — `wa_f986b59f-1c2d-…` → `f986b59f`, the short form the logs already use. `undefined`
199
+ * when it has fewer: such an id names no run.
200
+ */
201
+ export declare function runShortId(runId: string): string | undefined;
202
+ /** A run's Compose project, `lensmcp-<short>`: two stacks never share containers, networks or volumes. */
203
+ export declare const composeProjectOf: (short: string) => string;
204
+ /**
205
+ * The variables a run's commands are given (plan § 3). Each read is optional in the project: without LensMCP none is
206
+ * set, and it runs as it always did.
207
+ */
208
+ export declare const DOCKER_RUN_ENV: {
209
+ /** The run. Its presence is how a project's runner knows LensMCP admitted it, watches it and will clean after it. */
210
+ readonly id: "LENSMCP_RUN_ID";
211
+ /** The run's URL, told before the stack boots: an app may need its public origin for cookies and redirects. */
212
+ readonly origin: "LENSMCP_RUN_ORIGIN";
213
+ /** A folder of the run's evidence: what the project drops there is kept. */
214
+ readonly artifacts: "LENSMCP_RUN_ARTIFACTS";
215
+ /**
216
+ * The run's labels, as one JSON object ({@link runLabelsEnv}) — for containers the project starts outside Compose (a
217
+ * testcontainers `.withLabels()`): what carries them is the run's, watched and removed at its end. Not set for a
218
+ * run whose job declares nothing in Docker's VM ({@link DockerRunScope} `none`).
219
+ */
220
+ readonly labels: "LENSMCP_RUN_LABELS";
221
+ /** The compose file LensMCP wrote for the run: the project adds `-f "$LENSMCP_COMPOSE_OVERRIDE"` to its compose calls. Set for a run that has a stack. */
222
+ readonly override: "LENSMCP_COMPOSE_OVERRIDE";
223
+ /** Compose's own variable: the project every compose call of the run lands in. Set for a run that has a stack. */
224
+ readonly project: "COMPOSE_PROJECT_NAME";
225
+ };
226
+ /** The labels of everything a run starts: the run, the LENSMCP_HOME it belongs to (its hash) and the job's name. */
227
+ export declare function dockerRunLabels(run: {
228
+ id: string;
229
+ home: string;
230
+ job: string;
231
+ }): Record<string, string>;
232
+ /**
233
+ * `LENSMCP_RUN_LABELS` as a run's commands get it: ONE JSON object of label → value, on one line —
234
+ * `{"com.lensmcp.run":"q_…","com.lensmcp.home":"…","com.lensmcp.job":"integration"}`. JSON, because every container
235
+ * library takes labels as a map and every language reads JSON without a format of ours to learn; so the read in a
236
+ * project is one line — a testcontainers suite's `.withLabels(JSON.parse(process.env.LENSMCP_RUN_LABELS ?? '{}'))` —
237
+ * and without LensMCP the variable is not set, the object is empty and the suite runs as it always did (plan DW-Q9).
238
+ */
239
+ export declare const runLabelsEnv: (labels: Readonly<Record<string, string>>) => string;
240
+ /**
241
+ * How far a run reaches into Docker: what its commands are given, and so what can carry its labels (slice D10).
242
+ * - `stack`: a Compose project of its own (`lensmcp-<short>`), labelled through the override file — a `compose` job,
243
+ * and stories on one (`stack: <job>`). Its commands get the project, the override file and the labels.
244
+ * - `containers`: no Compose project and no override file. Its commands get the labels (`LENSMCP_RUN_LABELS`), and
245
+ * what they start with them is the run's: a testcontainers suite, stories whose browsers run in a container.
246
+ * - `none`: the job declares nothing in Docker's VM — stories against the dev cluster, their browsers on the host.
247
+ * Its commands get no labels, so nothing can carry them: the run is not watched, and neither its cleanup nor the
248
+ * sweep asks Docker anything on its account. Its record is there for its guard, which ends what its runner left.
249
+ */
250
+ export type DockerRunScope = 'stack' | 'containers' | 'none';
251
+ /** What a job declares decides it: a stack of its own or of the compose job it names, else containers when it declares memory in Docker's VM, else nothing. */
252
+ export declare function jobRunScope(job: LensJob): DockerRunScope;
253
+ /**
254
+ * testcontainers' own switch for its reaper (Ryuk): `true` turns it off. The reaper removes what a suite left when
255
+ * its process ended; LensMCP leaves it on (plan § 5, DW-Q9) and says so when a job's environment turns it off.
256
+ */
257
+ export declare const RYUK_DISABLED_ENV = "TESTCONTAINERS_RYUK_DISABLED";
258
+ /** The label of testcontainers' reaper, on its own container (the image carries it): it is the suite's library's, never a container the suite forgot to label. */
259
+ export declare const RYUK_LABEL = "org.testcontainers.ryuk";
260
+ /**
261
+ * The Ryuk warning (plan § 5 «testcontainers»): a testcontainers job whose environment turns the reaper off leaves
262
+ * containers nothing reaps but LensMCP's labels — said as the run starts, and kept in its record
263
+ * ({@link DockerRunRecord.warnings}). Undefined for another kind of job, and where the variable does not say `true`.
264
+ */
265
+ export declare function ryukWarning(job: LensJob, env: Readonly<Record<string, string | undefined>>): string | undefined;
266
+ /** The longest lease a run's route may ask for (s): a forgotten route lives no longer. Asking again renews it. */
267
+ export declare const MAX_RUN_ROUTE_SEC: number;
268
+ /**
269
+ * `POST /run-route` on the gateway's control socket. A body that names a host or an upstream is refused: the gateway
270
+ * derives both. A remote run (slice D17) names `socket` — its tunnel's `<home>/.lensmcp/peers/runs/<runId>.sock`, and
271
+ * no other path — and its requests go there, never to `127.0.0.1:<port>` of the gateway's Mac; `port` is then the
272
+ * edge's on the worker, named only in the Host header the edge is given. A gateway older than D17 refuses the field.
273
+ */
274
+ export interface RunRouteRequest {
275
+ runId: string;
276
+ /** A workspace registered with the gateway: the run's host goes under its apex. */
277
+ wsKey: string;
278
+ /** The loopback port the stack's edge is published on — on the worker, for a remote run. */
279
+ port: number;
280
+ /** How long the route lives unless asked again (s): more than 0, at most {@link MAX_RUN_ROUTE_SEC}. */
281
+ forSec: number;
282
+ /** A remote run's tunnel socket (D17). */
283
+ socket?: string;
284
+ }
285
+ /** A run's route as `/run-route` answers it. */
286
+ export interface RunRouteView {
287
+ runId: string;
288
+ wsKey: string;
289
+ /** `run-<short>.<apex>`. */
290
+ host: string;
291
+ /** Where a browser opens it. */
292
+ origin: string;
293
+ port: number;
294
+ registeredAt: number;
295
+ /** When it goes unless renewed (ms). */
296
+ expiresAt: number;
297
+ /** A remote run's: the socket its requests go to. */
298
+ socket?: string;
299
+ }
300
+ /** `no-socket` (D17): the socket a remote run names is not one this user's tunnel serves — none there, not a socket, a link, another user's, open to others. */
301
+ export type RunRouteRefusalCode = 'bad-request' | 'no-workspace' | 'run-in-use' | 'no-apex' | 'apex-not-loopback' | 'host-conflict' | 'upstream-is-gateway' | 'upstream-in-use' | 'too-many-runs' | 'no-run-route' | 'no-socket';
302
+ /** Why the gateway refused: a code, and one sentence a person or a run's record can show as it is. */
303
+ export interface RunRouteRefusal {
304
+ error: RunRouteRefusalCode;
305
+ message: string;
306
+ field?: string;
307
+ host?: string;
308
+ heldBy?: string;
309
+ workspaces?: string[];
310
+ max?: number;
311
+ }
312
+ /** `GET /run-route?runId=&wsKey=`: where a run would be routed, asked before its edge is up. */
313
+ export interface RunRoutePreview {
314
+ ok: true;
315
+ routed: boolean;
316
+ runId: string;
317
+ wsKey: string;
318
+ host: string;
319
+ origin: string;
320
+ port?: number;
321
+ registeredAt?: number;
322
+ expiresAt?: number;
323
+ }
324
+ /**
325
+ * Where a run is. `starting`: its record and its guard are there, nothing of the job ran. `preparing`: its `prepare`
326
+ * steps. `running`: its command. `cleaning`: the command is over — its `cleanup`, then whatever still carries the
327
+ * run's labels. Then how it ended: by its command's exit (`passed`, `failed`), by LensMCP (`cancelled`, `timeout`),
328
+ * before or around the command (`errored`), or `lost` — its runner died before it wrote an end, so nobody knows how
329
+ * the command would have ended: never «passed».
330
+ */
331
+ export type DockerRunState = 'starting' | 'preparing' | 'running' | 'cleaning' | 'passed' | 'failed' | 'cancelled' | 'timeout' | 'errored' | 'lost';
332
+ export declare const DOCKER_RUN_ENDS: readonly DockerRunState[];
333
+ export declare const dockerRunEnded: (state: DockerRunState) => boolean;
334
+ /**
335
+ * A process, by its pid and when it started (ms, to the second, as `ps` says it). A pid alone is handed to another
336
+ * process once its owner is gone; the two together are one process. No `startedAt`: `ps` could not say.
337
+ */
338
+ export interface DockerRunProcess {
339
+ pid: number;
340
+ startedAt?: number;
341
+ }
342
+ /** Who cleaned after a run: the project's own end (LensMCP looked and found nothing), LensMCP's runner, the guard, the sweep. */
343
+ export type DockerRunCleaner = 'project' | 'lensmcp' | 'guard' | 'sweep';
344
+ export interface DockerRunCleanup {
345
+ by: DockerRunCleaner;
346
+ at: number;
347
+ /**
348
+ * Nothing in Docker carries the run's labels any more. `false`: cleanup is OWED — `why` says what kept it (Docker
349
+ * did not answer, something would not go) and `left` what is still there; the sweep takes the run from here.
350
+ */
351
+ done: boolean;
352
+ /** What still carries the run's labels, by name. */
353
+ left?: string[];
354
+ /**
355
+ * What sits in the run's Compose project WITHOUT its labels — a compose call that did not take the override file.
356
+ * LensMCP removes only what carries its labels, so these are named and left.
357
+ */
358
+ unlabeled?: string[];
359
+ why?: string;
360
+ }
361
+ /**
362
+ * Containers that carry no LensMCP label, were not in the engine when the run's first command started and were there
363
+ * when it was cleaned (slice D10) — looked for in a run that has no Compose project ({@link DockerRunScope}
364
+ * `containers`), where nothing else says what a suite started without the run's labels. Docker does not say who
365
+ * started a container, so LensMCP cannot tell whether the run did: they are NAMED — never counted as the run's, and
366
+ * never removed (plan DW-Q9). testcontainers' own reaper is not among them (told by its label, {@link RYUK_LABEL}).
367
+ *
368
+ * Written once, with the cleanup's verdict, by whoever cleans while the run's end is fresh — its runner, or its guard
369
+ * the moment the runner died. A cleaner that comes long after (the sweep after a restart) does not look: what came up
370
+ * since would be the machine's history, not the run's.
371
+ */
372
+ export interface DockerRunStrangers {
373
+ /** When the second look was taken: what carried the run's labels was gone, or owed. */
374
+ at: number;
375
+ /** Their names, sorted — the first {@link MAX_RUN_STRANGERS}. */
376
+ containers: string[];
377
+ /** How many more there were. */
378
+ more?: number;
379
+ }
380
+ /** The most strangers one run names: a Mac where another project's stack came up meanwhile has twenty of them. */
381
+ export declare const MAX_RUN_STRANGERS = 20;
382
+ /**
383
+ * One run in the registry — what the guard and the sweep act on, and what `lensmcp docker ps` and the dashboard show.
384
+ *
385
+ * Who writes what (every write is read → change → write, under the record's lock; `run-registry.ts`):
386
+ * - the runner creates it and writes `state` up to its end, `child` (as each step starts and ends), `origin`, `url`,
387
+ * `edgePort`, `startedAt`, `endedAt`, `exit`, `note`, `urlNote`;
388
+ * - the guard writes `guard` — its own name, as it starts: the runner starts nothing of the job before it reads it;
389
+ * - whoever cleans — the runner, the guard, the sweep — writes `cleaning` while it does and `cleanup` when it is
390
+ * through, takes `url` and `edgePort` away with the route, and `child` once it has ended that process group; the
391
+ * guard and the sweep also end a run whose runner died (`lost`);
392
+ * - the project's command writes `stage` (`lensmcp docker stage`);
393
+ * - the runner's watcher (slice D6) writes `services`, `kills`, `killsMore`, `engineLost` and `watch`, and the
394
+ * sampled part of `vm` (`minAvailableMb`, `lastAvailableMb`, `sampledAt`) — the rest of `vm` is what the queue was
395
+ * admitted on, handed to the runner and written as the record is created; a cleaner that is not the runner takes
396
+ * `watch.stream` away once it has ended that process.
397
+ * An end is written once: `lost` never replaces `failed`, and a late runner never replaces `lost`. A `cleanup` that
398
+ * is `done` is never replaced; one that is owed is, by the next attempt. (One exception, the sweep's: a run recorded
399
+ * clean of which the engine still names things with its labels is put back to owed, and cleaned again.)
400
+ *
401
+ * With `project`, `url`, `stage` and `cleanup`, the watcher's fields are the `docker` block of the plan (§ 4): one
402
+ * place `lensmcp docker report` and the dashboard read, whoever ran the job.
403
+ *
404
+ * Every kind of job is one of these (slice D10): what differs is `scope` — and with it `project`, `files.override`
405
+ * and what the watcher and the cleanup ask Docker. `warnings` is the runner's, written as the record is created;
406
+ * `strangers` is written once, with the cleanup's verdict, by whoever cleans while the run's end is fresh.
407
+ */
408
+ export interface DockerRunRecord {
409
+ /** The record's version. A reader that does not know it leaves the run alone. */
410
+ v: 1;
411
+ id: string;
412
+ kind: LensJobKind;
413
+ /** The job's name in `lensmcp.json` → `jobs`. */
414
+ job: string;
415
+ /** The checkout it runs in. */
416
+ root: string;
417
+ /** That checkout's lens workspace, when it is one: the run's URL goes under its apex. */
418
+ wsKey?: string;
419
+ /** The Docker context its calls name — none: the CLI's own. */
420
+ context?: string;
421
+ /**
422
+ * How far it reaches into Docker ({@link DockerRunScope}) — none: a record written before there were kinds, a
423
+ * stack's. Whoever cleans reads it here, not off the job: `none` is the only run Docker is not asked about.
424
+ */
425
+ scope?: DockerRunScope;
426
+ /** `COMPOSE_PROJECT_NAME`: `lensmcp-<short>` — empty for a run that has no Compose project (`scope` is not `stack`). */
427
+ project: string;
428
+ /** Its labels ({@link dockerRunLabels}): what is the run's in Docker carries all three. */
429
+ labels: Record<string, string>;
430
+ state: DockerRunState;
431
+ /** Where the project says it is: «building images». */
432
+ stage?: string;
433
+ stageAt?: number;
434
+ /** One sentence beside the state: why it errored, what its guard did. */
435
+ note?: string;
436
+ /**
437
+ * What LensMCP has to say of how the job is set up, a sentence each — written with the record, before anything of
438
+ * the job runs, and said where the run is followed: the Ryuk warning ({@link ryukWarning}).
439
+ */
440
+ warnings?: string[];
441
+ createdAt: number;
442
+ /** When its command started, and when the run ended. */
443
+ startedAt?: number;
444
+ endedAt?: number;
445
+ /** How its command ended, when it ran to an end. */
446
+ exit?: {
447
+ code: number | null;
448
+ signal: string | null;
449
+ };
450
+ /** The process that runs it. Dead before an end is written: the guard, or the sweep, cleans. */
451
+ runner: DockerRunProcess;
452
+ /** The process that cleans when the runner dies. */
453
+ guard?: DockerRunProcess;
454
+ /**
455
+ * The process group the runner started that runs now — a `prepare` step, the command, the `cleanup`. A cleaner that
456
+ * is not the runner ends it first: left alive, it would start again what was just removed.
457
+ */
458
+ child?: DockerRunProcess & {
459
+ step: 'prepare' | 'command' | 'cleanup';
460
+ };
461
+ /** The origin its commands were told (`LENSMCP_RUN_ORIGIN`), before the stack booted. */
462
+ origin?: string;
463
+ /** Its URL, while the gateway routes it; `edgePort` is the loopback port it reaches. */
464
+ url?: string;
465
+ edgePort?: number;
466
+ /** Why it has no URL: no gateway, a refusal, an edge that never answered. */
467
+ urlNote?: string;
468
+ /** Who is cleaning now. Held by a live process, another cleaner waits for it. */
469
+ cleaning?: DockerRunProcess & {
470
+ by: DockerRunCleaner;
471
+ at: number;
472
+ };
473
+ cleanup?: DockerRunCleanup;
474
+ /** Containers without a LensMCP label that came up while it ran and were still there when it was cleaned ({@link DockerRunStrangers}) — none: there were none, or it was not looked for. */
475
+ strangers?: DockerRunStrangers;
476
+ /**
477
+ * Its files: the run's folder, the override file (a run that has a stack), the artifacts folder, the command's
478
+ * log, the guard's log — and the watcher's two (slice D6): every sample (`docker-samples.jsonl`) and every event of
479
+ * the run's containers the live stream told (`docker-events.jsonl`), a line each. `beside` (a run that has no
480
+ * Compose project): the containers no LensMCP label was on before its first command, which the look at its cleanup
481
+ * is set against ({@link DockerRunStrangers}).
482
+ */
483
+ files: {
484
+ dir: string;
485
+ override?: string;
486
+ artifacts: string;
487
+ log: string;
488
+ guardLog: string;
489
+ samples?: string;
490
+ events?: string;
491
+ beside?: string;
492
+ };
493
+ /** Docker's VM as the run met it, and as its sampler found it since ({@link DockerRunVm}) — none: nothing admitted the run by it. */
494
+ vm?: DockerRunVm;
495
+ /** Each service against its budget: what its containers hold now and the most a sample saw ({@link DockerRunService}). */
496
+ services?: DockerRunService[];
497
+ /** The containers killed for memory — each kill once, whichever witness told it ({@link DockerRunKill}). */
498
+ kills?: DockerRunKill[];
499
+ /** Kills past the first {@link MAX_RUN_KILLS}: counted here, neither listed nor told to the bus. */
500
+ killsMore?: number;
501
+ /** Docker stopped answering while the run was up ({@link DockerRunEngineLost}). */
502
+ engineLost?: DockerRunEngineLost;
503
+ /** The watcher itself: what it did, and what it could not ({@link DockerRunWatch}). */
504
+ watch?: DockerRunWatch;
505
+ }
506
+ /**
507
+ * A service of a run against its budget. A sample (`docker stats`, every ten seconds) says what each of the run's
508
+ * containers holds; they are summed by service, because the service is what the manifest gives a figure
509
+ * (`budget.services.<name>`). A service over its budget is SAID — here, by its numbers — never killed: the budget is
510
+ * what the queue admits by, not a limit.
511
+ */
512
+ export interface DockerRunService {
513
+ /** Its name in the compose files (`com.docker.compose.service`); a container Compose did not make goes by its own name. */
514
+ name: string;
515
+ /** What the manifest declares for it, MiB — none: the job declares no figure for it. */
516
+ budgetMb?: number;
517
+ /** What its containers hold together now, MiB: the last sample. 0 once none runs. */
518
+ lastMb: number;
519
+ /** The most a sample saw them hold together, MiB, and when. */
520
+ peakMb: number;
521
+ peakAt?: number;
522
+ /** A container of it's own memory limit, MiB — none: it has no limit, and can take what the VM has. */
523
+ limitMb?: number;
524
+ /** The containers of it the last look found, running or ended. */
525
+ containers: number;
526
+ /** A container of it was killed for memory, as either witness told it. */
527
+ oomKilled: boolean;
528
+ /** How a container of it last ended, when one did (137: SIGKILL — for memory only when `oomKilled`). */
529
+ exitCode?: number;
530
+ }
531
+ /**
532
+ * A container of a run killed for running out of memory: one entry per kill. Two witnesses see a kill — the live
533
+ * events stream and the inspect — and which accounts are one kill is `DockerErrorLedger`'s rule (docker-errors.ts),
534
+ * the same the Errors page and `observe_errors` count by: so a run's record, its report and the two lists agree.
535
+ */
536
+ export interface DockerRunKill {
537
+ /** When it was killed, by the engine's clock: the `oom` event's time; for a kill only the inspect found, when the container ended. */
538
+ at: number;
539
+ service: string;
540
+ /** The container's id, whole. */
541
+ container: string;
542
+ /** The container's name, for a person. */
543
+ name?: string;
544
+ /** Who told it first — `event` once the live stream has told it at all. */
545
+ seen: DockerKillSeen;
546
+ /** Its memory limit, the most a sample saw it hold, and what the manifest declares for its service, MiB — each when known. */
547
+ limitMb?: number;
548
+ peakMb?: number;
549
+ budgetMb?: number;
550
+ }
551
+ /** The most kills one run lists and tells the bus: a container that restarts into its limit is killed every few seconds for as long as the run lasts. */
552
+ export declare const MAX_RUN_KILLS = 100;
553
+ /** Docker stopped answering while the run was up (plan § 4: «Docker stopped answering at <time>»). ONE per loss, never a kill per container. */
554
+ export interface DockerRunEngineLost {
555
+ /** When it was first seen not to answer. */
556
+ at: number;
557
+ /** How it showed, in the watcher's words: «the events stream ended; Docker is not running». */
558
+ why: string;
559
+ /** When it answered again, if it did while the run was still watched. */
560
+ backAt?: number;
561
+ /** Services of the run found killed for memory once it was gone: they went with the engine — part of this loss, no kills of their own. */
562
+ killed?: string[];
563
+ }
564
+ /**
565
+ * A run's watcher, as it tells of itself: a watcher that fails costs the run nothing but its figures, so what is
566
+ * missing from the record is said here rather than guessed at.
567
+ */
568
+ export interface DockerRunWatch {
569
+ /** When it began — before anything of the job's ran. */
570
+ startedAt: number;
571
+ /** When it was through: the last inspect done, or given up, and its stream ended. */
572
+ endedAt?: number;
573
+ /** Its `docker events` process, while one runs. A cleaner that is not the runner ends it: nobody reads it any more. */
574
+ stream?: DockerRunProcess;
575
+ /** Times the live stream ended while Docker still answered, and was started again. */
576
+ streamRestarts?: number;
577
+ /** Samples that answered, when the last one did, and samples Docker did not answer. */
578
+ samples: number;
579
+ sampledAt?: number;
580
+ missed?: number;
581
+ /** The inspect at the run's end: when it looked, and how many of the run's containers it read. */
582
+ inspected?: {
583
+ at: number;
584
+ containers: number;
585
+ };
586
+ /** What it could not do, a sentence each — the figures that are missing are missing for this. */
587
+ notes?: string[];
588
+ }
589
+ /**
590
+ * The two failures of Docker work that are errors of the workspace (plan § 4 «Errors»): a container killed for running
591
+ * out of memory, and an engine that stopped answering while runs were in it. Each is the `raw` of one bus event, built
592
+ * by `containerOomEvent` / `dockerEngineLostEvent` (`@lensmcp/core/lens-events`) and read by `readDockerError`
593
+ * (docker-errors.ts) — the Errors page and `observe_errors` both read them there, so a row and an entry name one cause
594
+ * with the same words.
595
+ *
596
+ * Every field but `kind` is read as optional: an event from an older or a newer producer is still shown.
597
+ */
598
+ export declare const CONTAINER_OOM = "container-oom";
599
+ export declare const DOCKER_ENGINE_LOST = "docker-engine-lost";
600
+ /**
601
+ * Where a kill was seen. `event`: the live `docker events` stream, as it happened. `inspect`: `.State.OOMKilled` at the
602
+ * run's end — the only account of a kill the stream lost, and a second account of every kill it did not.
603
+ */
604
+ export type DockerKillSeen = 'event' | 'inspect';
605
+ /**
606
+ * The worker Mac a failure happened on (slice D16): the organizer tells a worker's failures again on its OWN bus, naming
607
+ * the worker — none: this Mac. `peer` is the worker's id on the channel, `name` the one the person paired it by.
608
+ */
609
+ export interface DockerEventHost {
610
+ peer: string;
611
+ name: string;
612
+ }
613
+ /** A container of a run was killed for running out of memory. */
614
+ export interface ContainerOomEvent {
615
+ kind: typeof CONTAINER_OOM;
616
+ /** The run it was a container of (`com.lensmcp.run`). */
617
+ run: string;
618
+ /** The job's name in `lensmcp.json` → `jobs` (`com.lensmcp.job`). */
619
+ job: string;
620
+ /**
621
+ * The service: for a stack, its name in the compose files — and in `budget.services`, which is the figure to
622
+ * change. The cause is the service and the job: every kill of one service in one job is one row, each an occurrence.
623
+ */
624
+ service: string;
625
+ /**
626
+ * The container's id. The stream and the end inspect both see one kill, and this is what makes their two accounts
627
+ * one: an `inspect` of a container whose kill was told adds what only the end knows, never a second kill.
628
+ */
629
+ container: string;
630
+ seen: DockerKillSeen;
631
+ /** Its memory limit, MiB — none: it had no limit of its own (the VM ran out), or the limit was not read yet. */
632
+ limitMb?: number;
633
+ /** The most the sampler saw it hold, MiB — none: it was killed before its first sample. */
634
+ peakMb?: number;
635
+ /** What the manifest declares for the service (`budget.services.<service>`), MiB — none: the job declares no figure per service. */
636
+ budgetMb?: number;
637
+ /** The Docker context the run was in (its VM) — none: the CLI's own. */
638
+ context?: string;
639
+ /**
640
+ * The worker it was killed on — none: this Mac. A kill there is the SAME cause as one here: the same service of the
641
+ * same job, and the same budget in `lensmcp.json` to raise. The worker is named on the occurrence.
642
+ */
643
+ host?: DockerEventHost;
644
+ }
645
+ /** A run that was in an engine when it stopped answering. */
646
+ export interface DockerLostRun {
647
+ run: string;
648
+ job: string;
649
+ }
650
+ /**
651
+ * Docker stopped answering while runs were in it (the events stream ended, and `docker info` no longer answers). ONE
652
+ * event for the engine, whatever it held: the containers that went with it are not errors of their own.
653
+ */
654
+ export interface DockerEngineLostEvent {
655
+ kind: typeof DOCKER_ENGINE_LOST;
656
+ /** The Docker context whose engine was lost — the cause is the VM. None: the CLI's own. */
657
+ context?: string;
658
+ /** The runs that were in it. Each watcher may name only its own: accounts of one loss are folded by the reader. */
659
+ runs: DockerLostRun[];
660
+ /** How it showed, in the watcher's words: «the events stream ended». */
661
+ why?: string;
662
+ /** The VM's memory as it was last read, MiB: a VM with none left most likely took the engine with it. */
663
+ vmTotalMb?: number;
664
+ vmAvailableMb?: number;
665
+ /** The worker whose engine it was — none: this Mac's. Its VM is not this Mac's, so its loss is a cause of its own. */
666
+ host?: DockerEventHost;
667
+ }
668
+ /**
669
+ * An error event of another kind that happened BECAUSE of a run — the job it failed — names the run in `raw` under this
670
+ * key. The Errors page then lists it under the kill, or the lost engine, that explains it, instead of as a second error.
671
+ */
672
+ export declare const DOCKER_RUN_FIELD = "dockerRun";
673
+ export {};