@lensmcp/protocol-types 1.26.2 → 1.26.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";var S=Object.defineProperty;var a=(e,s)=>S(e,"name",{value:s,configurable:!0});var w=Object.defineProperty,n=a((e,s)=>w(e,"name",{value:s,configurable:!0}),"i");export const DOCKER_LABELS={run:"com.lensmcp.run",home:"com.lensmcp.home",job:"com.lensmcp.job",probe:"com.lensmcp.probe"},LENS_JOB_KINDS=["compose","testcontainers","playwright"];export function neverShipped(e){const s=(e.split("/").at(-1)??"").toLowerCase();return s===".env"||s===".env.local"||/^\.env\..+\.local$/.test(s)}a(neverShipped,"neverShipped"),n(neverShipped,"neverShipped");export const jobInputFiles=n(e=>[...new Set(e.inputs?.files??[])].sort(),"jobInputFiles"),jobMintedFiles=n(e=>[...new Set(e.inputs?.minted??[])].sort(),"jobMintedFiles"),jobProblemText=n(e=>e.job===void 0?e.problem:`jobs.${e.job}: ${e.problem}`,"jobProblemText");const g=["kind","lane","prepare","command","cleanup","report","artifacts","inputs","timeoutMinutes","retryable","nx","budget"],O={compose:[...g,"compose"],testcontainers:g,playwright:[...g,"stack"]},j={compose:["services","buildMb","hostMb"],testcontainers:["vmMb","hostMb"],playwright:["hostMb","vmMb"]},M=/^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/,k=/^[A-Za-z0-9][A-Za-z0-9._-]*$/,v=1024*1024,_=360,l=100,$=4e3,p=n(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObj"),N=n(e=>typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=v,"isMb"),L=n(e=>e.map(s=>`"${s}"`).join(", "),"quoted");function m(e){return typeof e!="string"||!e||e.length>500||/[\0\\]/.test(e)||e.startsWith("/")||e.startsWith("~")||/^[A-Za-z]:/.test(e)?!1:!e.split("/").includes("..")}a(m,"b"),n(m,"inTree");function f(e){return Array.isArray(e)&&e.length>=1&&e.length<=l&&e.every(s=>typeof s=="string"&&s.length<=$)&&e[0]!==""}a(f,"g"),n(f,"isArgv");function h(e,s,t,o){const r=Object.keys(e).filter(i=>!s.includes(i));r.length&&o.push(`${t?`${t} has`:"has"} ${r.length===1?"an unknown key":"unknown keys"} ${L(r)}`)}a(h,"f"),n(h,"unknownKeys");function A(e,s,t){e!==void 0&&(!Array.isArray(e)||e.length>l||!e.every(m))&&t.push(`${s} is a list of paths inside the checkout`)}a(A,"R"),n(A,"paths");function y(e,s,t){if(e===void 0)return[];if(!Array.isArray(e)||e.length>l||!e.every(m))return t.push(`${s} is a list of paths inside the checkout`),[];for(const o of e){const r=o.split("/");r.some(i=>i===""||i===".")?t.push(`${s} names ${JSON.stringify(o)}: a file is written as git names it \u2014 a/b.json, with no ./, no // and no trailing /`):r.some(i=>i.toLowerCase()===".git")&&t.push(`${s} names ${JSON.stringify(o)}, which is inside git's own folder`)}return e}a(y,"A"),n(y,"inputPaths");function E(e){if(!p(e))return["is not an object"];const s=e.kind;if(!LENS_JOB_KINDS.includes(s))return[`kind is ${LENS_JOB_KINDS.slice(0,-1).join(", ")} or ${LENS_JOB_KINDS.at(-1)}`];const t=[];h(e,O[s],"",t),e.lane!==void 0&&e.lane!=="light"&&e.lane!=="heavy"&&t.push("lane is light or heavy"),f(e.command)||t.push("command is a program and its arguments, as a list of strings \u2014 not a shell line"),e.cleanup!==void 0&&!f(e.cleanup)&&t.push("cleanup is a program and its arguments, as a list of strings"),e.prepare!==void 0&&!(Array.isArray(e.prepare)&&e.prepare.length<=l&&e.prepare.every(f))&&t.push("prepare is a list of steps, each a program and its arguments"),e.report!==void 0&&!["jest","vitest","playwright"].includes(e.report)&&t.push("report is jest, vitest or playwright"),A(e.artifacts,"artifacts",t),e.timeoutMinutes!==void 0&&!(typeof e.timeoutMinutes=="number"&&e.timeoutMinutes>0&&e.timeoutMinutes<=_)&&t.push(`timeoutMinutes is execution minutes, up to ${_}`),e.retryable!==void 0&&typeof e.retryable!="boolean"&&t.push("retryable is true or false"),e.nx!==void 0&&!(typeof e.nx=="string"&&/^\S+:[^\s:]+$/.test(e.nx))&&t.push("nx is <project>:<target>");const o=e.inputs;if(o!==void 0)if(!p(o))t.push("inputs is an object of files, minted and secrets");else{h(o,["files","minted","secrets"],"inputs",t);const i=y(o.files,"inputs.files",t),u=y(o.minted,"inputs.minted",t);for(const d of i)neverShipped(d)&&t.push(`inputs.files names ${d}, which is never shipped to another Mac \u2014 declare it in inputs.minted, and make it in a prepare step`);const c=[...new Set(i.filter(d=>u.includes(d)))];c.length&&t.push(`inputs names ${c.join(", ")} in files and in minted: a file is shipped by hash, or made per run on the host that runs it \u2014 not both`);const b=o.secrets;b!==void 0&&!(Array.isArray(b)&&b.length<=l&&b.every(d=>typeof d=="string"&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(d)))&&t.push("inputs.secrets is a list of variable names, never values")}const r=e.budget;if(!p(r))t.push("has no budget: the memory it declares is what it is admitted by");else{h(r,j[s],"budget",t);for(const i of["buildMb","hostMb","vmMb"])j[s].includes(i)&&r[i]!==void 0&&!N(r[i])&&t.push(`budget.${i} is MiB, a whole number from 1 to ${v}`);if(s==="testcontainers"&&(r.vmMb===void 0||r.hostMb===void 0)&&t.push("budget needs vmMb (its containers, in Docker's VM) and hostMb (the test runner, on the host)"),s==="playwright"&&r.vmMb===void 0&&r.hostMb===void 0&&t.push("budget needs hostMb or vmMb: where its browsers run"),s==="compose"){const i=r.services;if(!p(i)||!Object.keys(i).length)t.push("budget.services is each service's expected peak, MiB, by its name in the compose files");else for(const[u,c]of Object.entries(i))k.test(u)?N(c)||t.push(`budget.services.${u} is MiB, a whole number from 1 to ${v}`):t.push(`budget.services has "${u}", which is no service name`)}}if(s==="compose"){const i=e.compose;if(!p(i))t.push("compose is an object of files and edge");else{h(i,["files","edge"],"compose",t);const u=i.files;(!Array.isArray(u)||!u.length||u.length>l||!u.every(m))&&t.push("compose.files is the compose files, as paths inside the checkout");const c=i.edge;c!==void 0&&(!p(c)||typeof c.service!="string"||!k.test(c.service)||!Number.isInteger(c.port)||c.port<1||c.port>65535?t.push('compose.edge is the service and the container port its URL reaches: { "service": "edge", "port": 8443 }'):(h(c,["service","port"],"compose.edge",t),p(r)&&p(r.services)&&!Object.hasOwn(r.services,c.service)&&t.push(`${c.service} has no budget`)))}}return s==="playwright"&&e.stack!==void 0&&!(typeof e.stack=="string"&&M.test(e.stack))&&t.push("stack is the name of a compose job of this file"),t}a(E,"j"),n(E,"jobProblems");export function readLensJobs(e){const s={jobs:{},problems:[]};if(e===void 0)return s;if(!p(e))return s.problems.push({problem:"jobs is an object of jobs by name"}),s;for(const[t,o]of Object.entries(e)){if(!M.test(t)){s.problems.push({job:t,problem:"a job's name is letters, digits, dots, dashes and underscores \u2014 63 at most, the first a letter or a digit"});continue}const r=E(o);r.length?s.problems.push(...r.map(i=>({job:t,problem:i}))):s.jobs[t]=o}for(const[t,o]of Object.entries(s.jobs))o.kind!=="playwright"||o.stack===void 0||s.jobs[o.stack]?.kind!=="compose"&&(s.problems.push({job:t,problem:`stack names "${o.stack}", which is no compose job of this file that may run`}),delete s.jobs[t]);return s}a(readLensJobs,"readLensJobs"),n(readLensJobs,"readLensJobs");const R=n(e=>Object.values(e).reduce((s,t)=>s+t,0),"sum");export function jobVmNeedMb(e,s={}){if(e.kind==="compose")return Math.max(e.budget.buildMb??0,R(e.budget.services));if(e.kind==="testcontainers")return e.budget.vmMb;const t=e.budget.vmMb??0,o=e.stack===void 0?void 0:s[e.stack];return o?.kind==="compose"?Math.max(o.budget.buildMb??0,R(o.budget.services)+t):t}a(jobVmNeedMb,"jobVmNeedMb"),n(jobVmNeedMb,"jobVmNeedMb");export function jobHostNeedMb(e,s={}){const t=e.budget.hostMb??0,o=e.kind==="playwright"&&e.stack!==void 0?s[e.stack]:void 0;return t+(o?.kind==="compose"?o.budget.hostMb??0:0)}a(jobHostNeedMb,"jobHostNeedMb"),n(jobHostNeedMb,"jobHostNeedMb");export function jobLane(e){return e.lane?e.lane:e.kind==="compose"||e.kind==="playwright"&&e.stack!==void 0?"heavy":"light"}a(jobLane,"jobLane"),n(jobLane,"jobLane");export function unbudgetedServices(e,s){return[...new Set(s)].filter(t=>!Object.hasOwn(e.budget.services,t)).sort()}a(unbudgetedServices,"unbudgetedServices"),n(unbudgetedServices,"unbudgetedServices");export const RUN_ID_PATTERN=/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/;export function runShortId(e){const s=e.toLowerCase().replace(/^[a-z]+_/,"").replace(/[^a-z0-9]/g,"").slice(0,8);return s.length===8?s:void 0}a(runShortId,"runShortId"),n(runShortId,"runShortId");export const composeProjectOf=n(e=>`lensmcp-${e}`,"composeProjectOf"),DOCKER_RUN_ENV={id:"LENSMCP_RUN_ID",origin:"LENSMCP_RUN_ORIGIN",artifacts:"LENSMCP_RUN_ARTIFACTS",labels:"LENSMCP_RUN_LABELS",override:"LENSMCP_COMPOSE_OVERRIDE",project:"COMPOSE_PROJECT_NAME"};export function dockerRunLabels(e){return{[DOCKER_LABELS.run]:e.id,[DOCKER_LABELS.home]:e.home,[DOCKER_LABELS.job]:e.job}}a(dockerRunLabels,"dockerRunLabels"),n(dockerRunLabels,"dockerRunLabels");export const runLabelsEnv=n(e=>JSON.stringify(e),"runLabelsEnv");export function jobRunScope(e){return e.kind==="compose"||e.kind==="playwright"&&e.stack!==void 0?"stack":jobVmNeedMb(e)>0?"containers":"none"}a(jobRunScope,"jobRunScope"),n(jobRunScope,"jobRunScope");export const RYUK_DISABLED_ENV="TESTCONTAINERS_RYUK_DISABLED",RYUK_LABEL="org.testcontainers.ryuk";export function ryukWarning(e,s){const t=s[RYUK_DISABLED_ENV];if(!(e.kind!=="testcontainers"||t===void 0||t.trim().toLowerCase()!=="true"))return`${RYUK_DISABLED_ENV}=${t.trim()} is set in the job's environment: testcontainers' own reaper (Ryuk) is off, so a container the suite leaves is removed only where it carries the run's labels \u2014 hand ${DOCKER_RUN_ENV.labels} to every container it starts. One that does not carry them stays in Docker's VM: LensMCP never removes it, and nothing else does.`}a(ryukWarning,"ryukWarning"),n(ryukWarning,"ryukWarning");export const MAX_RUN_ROUTE_SEC=14400,DOCKER_RUN_ENDS=["passed","failed","cancelled","timeout","errored","lost"],dockerRunEnded=n(e=>DOCKER_RUN_ENDS.includes(e),"dockerRunEnded"),MAX_RUN_STRANGERS=20,MAX_RUN_KILLS=100,CONTAINER_OOM="container-oom",DOCKER_ENGINE_LOST="docker-engine-lost",DOCKER_RUN_FIELD="dockerRun";
@@ -0,0 +1,99 @@
1
+ import { type DockerRunCleanup, type DockerRunEngineLost, type DockerRunKill, type DockerRunRecord, type DockerRunScope, type DockerRunService, type DockerRunState, type DockerRunVm, type DockerRunWatch, type LensJobKind } from './docker-jobs.js';
2
+ /**
3
+ * A RUN'S REPORT (planning/docker/00-plan.md § 4 and § 6, slice D6): what the run was, each service against its
4
+ * budget with its peak, the kills, the VM, how it ended and what its cleanup left — out of the run's record alone
5
+ * (`~/.lensmcp/docker/runs/<id>.json`, docker-jobs.ts `DockerRunRecord`). `lensmcp docker report <run>` prints it; a
6
+ * project's own runner reads it as JSON for its OOM report, before it takes its stack down; the dashboard shows the
7
+ * same figures.
8
+ *
9
+ * Pure: it asks Docker nothing and reads no file — so it says the same while the run runs, after it has ended, and
10
+ * on a Mac whose Docker is not running.
11
+ */
12
+ /** A service as the report shows it: the record's figures, and what they come to against its budget. */
13
+ export interface DockerReportService extends DockerRunService {
14
+ /**
15
+ * By how much its peak was over what the manifest declares for it, MiB — none: within it, or it declares no
16
+ * figure. Said, never acted on: the budget is what the queue admits by, not a limit.
17
+ */
18
+ overMb?: number;
19
+ /** No sample found a container of it holding anything: the manifest names it, and it never ran, or came and went between two samples. */
20
+ unsampled?: true;
21
+ }
22
+ export interface DockerRunReport {
23
+ run: {
24
+ id: string;
25
+ job: string;
26
+ kind: LensJobKind;
27
+ state: DockerRunState;
28
+ /** It has ended: the figures are final. */
29
+ ended: boolean;
30
+ /** How far it reaches into Docker — a record that does not say is a stack's. */
31
+ scope: DockerRunScope;
32
+ /** Its Compose project — empty: it has none. */
33
+ project: string;
34
+ root: string;
35
+ context?: string;
36
+ stage?: string;
37
+ note?: string;
38
+ url?: string;
39
+ origin?: string;
40
+ urlNote?: string;
41
+ createdAt: number;
42
+ startedAt?: number;
43
+ endedAt?: number;
44
+ /** How long its command has run, or ran, ms. */
45
+ ranMs?: number;
46
+ exit?: {
47
+ code: number | null;
48
+ signal: string | null;
49
+ };
50
+ };
51
+ /** Each service against its budget — those over it first, then by peak. */
52
+ services: DockerReportService[];
53
+ /** The run's containers together at the last sample, and what its services declare together. */
54
+ totals: {
55
+ lastMb: number;
56
+ budgetMb?: number;
57
+ };
58
+ /** The containers killed for memory: each kill once. */
59
+ kills: DockerRunKill[];
60
+ killsMore?: number;
61
+ engineLost?: DockerRunEngineLost;
62
+ vm?: DockerRunVm;
63
+ cleanup?: DockerRunCleanup;
64
+ /** What LensMCP said of how the job is set up, as the run started (the Ryuk warning). */
65
+ warnings?: string[];
66
+ /** What the run's labels were not on, a sentence each ({@link runUnlabeledWords}). */
67
+ unlabeled?: string[];
68
+ /** The watcher's own account: how often it sampled, and what it could not do. */
69
+ watch?: DockerRunWatch;
70
+ /** Where the rest is: every sample, every event of the run's containers, the commands' output, what the project kept. */
71
+ files: {
72
+ samples?: string;
73
+ events?: string;
74
+ log: string;
75
+ artifacts: string;
76
+ };
77
+ }
78
+ /**
79
+ * What a run says, at its end, of the containers its labels are NOT on (planning/docker/00-plan.md § 5
80
+ * «testcontainers», DW-Q9; slice D10) — a sentence each, none when there is nothing to say. Only of a run that has
81
+ * no Compose project and whose commands were given the labels (`scope: 'containers'`): a stack's strangers sit in its
82
+ * Compose project and are its cleanup's (`cleanup.unlabeled`).
83
+ *
84
+ * As far as LensMCP can honestly tell, and no further. Two things it knows: that it SAW no container with the run's
85
+ * labels — its command ran, and the look at its end answered — and which containers without a LensMCP label came up
86
+ * meanwhile and were still there ({@link DockerRunRecord.strangers}). Who started those Docker does not say, so
87
+ * neither does this — and no name is read for a hint. `queue run` says these where the run's end is read;
88
+ * `lensmcp docker report` prints them.
89
+ */
90
+ export declare function runUnlabeledWords(record: DockerRunRecord): string[];
91
+ /** The report of a run, from its record as it stands at `now`. */
92
+ export declare function dockerRunReport(record: DockerRunRecord, now?: number): DockerRunReport;
93
+ /** A time as the report writes it: UTC, to the second — the same on every Mac that reads the record. */
94
+ declare const when: (at: number) => string;
95
+ declare const lasted: (ms: number) => string;
96
+ /** The report's own way with a time and a length of time, for what is written beside it (docker-runs.ts): a list of runs says them the same. */
97
+ export { when as dockerTime, lasted as dockerLasted };
98
+ /** The report as `lensmcp docker report <run>` prints it. */
99
+ export declare function dockerRunReportText(report: DockerRunReport): string;
@@ -0,0 +1,2 @@
1
+ "use strict";var M=Object.defineProperty;var h=(e,t)=>M(e,"name",{value:t,configurable:!0});var w=Object.defineProperty,u=h((e,t)=>w(e,"name",{value:t,configurable:!0}),"u");import{DOCKER_RUN_ENV as b,dockerRunEnded as k,RYUK_DISABLED_ENV as x}from"./docker-jobs.js";export function runUnlabeledWords(e){if(e.scope!=="containers")return[];const t=[],o=`hand ${b.labels} to each container it starts \u2014 a JSON object of labels: .withLabels(JSON.parse(process.env.${b.labels} ?? '{}'))`,a=e.startedAt!==void 0&&e.watch?.inspected!==void 0&&!e.engineLost&&!(e.services??[]).length;a&&t.push(`LensMCP saw no container with the run's labels while it ran: it watched none and removed none. If the job starts containers, ${o}.`);const i=e.strangers;if(i?.containers.length){const n=i.containers.length+(i.more??0),c=(e.warnings??[]).some(l=>l.startsWith(x));t.push(`${n} container${n===1?"":"s"} without the run's labels came up while it ran and ${n===1?"is":"are"} still there: ${i.containers.join(", ")}${i.more?` and ${i.more} more`:""}. LensMCP cannot tell whether this run started ${n===1?"it":"them"} \u2014 Docker does not say who starts a container \u2014 and ${n===1?"does not remove it":"removes none of them"}: only what carries the run's labels is the run's. `+(c?"testcontainers' own reaper is off, so nothing else removes what a suite left either.":"Where testcontainers' own reaper is on, it removes what a suite left.")+(a?"":` If the job started ${n===1?"it":"them"}, ${o}.`))}return t}h(runUnlabeledWords,"runUnlabeledWords"),u(runUnlabeledWords,"runUnlabeledWords");export function dockerRunReport(e,t=Date.now()){const o=k(e.state),a=(e.services??[]).map(l=>{const s=l.budgetMb===void 0?0:l.peakMb-l.budgetMb;return{...l,...s>0?{overMb:s}:{},...l.peakMb>0?{}:{unsampled:!0}}}).sort((l,s)=>(s.overMb??0)-(l.overMb??0)||s.peakMb-l.peakMb||l.name.localeCompare(s.name)),i=a.filter(l=>l.budgetMb!==void 0),n=e.startedAt===void 0?void 0:Math.max(0,(e.endedAt??t)-e.startedAt),c=runUnlabeledWords(e);return{run:{id:e.id,job:e.job,kind:e.kind,state:e.state,ended:o,scope:e.scope??"stack",project:e.project,root:e.root,...e.context?{context:e.context}:{},...e.stage?{stage:e.stage}:{},...e.note?{note:e.note}:{},...e.url?{url:e.url}:{},...e.origin?{origin:e.origin}:{},...e.urlNote?{urlNote:e.urlNote}:{},createdAt:e.createdAt,...e.startedAt!==void 0?{startedAt:e.startedAt}:{},...e.endedAt!==void 0?{endedAt:e.endedAt}:{},...n!==void 0?{ranMs:n}:{},...e.exit?{exit:e.exit}:{}},services:a,totals:{lastMb:a.reduce((l,s)=>l+s.lastMb,0),...i.length?{budgetMb:i.reduce((l,s)=>l+(s.budgetMb??0),0)}:{}},kills:e.kills??[],...e.killsMore?{killsMore:e.killsMore}:{},...e.engineLost?{engineLost:e.engineLost}:{},...e.vm?{vm:e.vm}:{},...e.cleanup?{cleanup:e.cleanup}:{},...e.warnings?.length?{warnings:e.warnings}:{},...c.length?{unlabeled:c}:{},...e.watch?{watch:e.watch}:{},files:{...e.files.samples?{samples:e.files.samples}:{},...e.files.events?{events:e.files.events}:{},log:e.files.log,artifacts:e.files.artifacts}}}h(dockerRunReport,"dockerRunReport"),u(dockerRunReport,"dockerRunReport");const d=u(e=>new Date(e).toISOString().replace(/\.\d{3}Z$/,"Z"),"when"),g=u(e=>{const t=Math.round(e/1e3);if(t<60)return`${t} s`;const o=Math.floor(t/60);return o<60?`${o} min${t%60?` ${t%60} s`:""}`:`${Math.floor(o/60)} h${o%60?` ${o%60} min`:""}`},"lasted"),$=u((e,t,o)=>`${e} ${e===1?t:o}`,"plural");export{d as dockerTime,g as dockerLasted};function v(e){const t=e.exit?e.exit.signal?`its command was ended by ${e.exit.signal}`:`its command exited ${e.exit.code}`:void 0,o=[e.ranMs!==void 0?`${e.ended?"ran":"running for"} ${g(e.ranMs)}`:void 0,e.startedAt!==void 0?`started ${d(e.startedAt)}`:`created ${d(e.createdAt)}`,e.endedAt!==void 0?`ended ${d(e.endedAt)}`:void 0].filter(Boolean).join(", ");return`${{starting:"starting: nothing of the job has run yet",preparing:"preparing: its prepare steps run",running:"running",cleaning:`cleaning up${t?`: ${t}`:""}`,passed:`passed${t?`: ${t}`:""}`,failed:`failed${t?`: ${t}`:""}`,cancelled:"cancelled",timeout:"timed out",errored:"errored",lost:`lost: its runner died, so nobody knows how it would have ended${t?` (${t})`:""}`}[e.state]} \xB7 ${o}`}h(v,"w"),u(v,"stateText");function f(e){const t=e[0].map((o,a)=>Math.max(...e.map(i=>(i[a]??"").length)));return e.map(o=>o.map((a,i)=>i===0?a.padEnd(t[i]):i===o.length-1?a:a.padStart(t[i])).join(" ").trimEnd())}h(f,"k"),u(f,"table");export function dockerRunReportText(e){const{run:t,vm:o,watch:a,cleanup:i}=e,n=[`Docker run ${t.id} \u2014 job \xAB${t.job}\xBB (${t.kind}), ${t.project?`Compose project ${t.project}`:t.scope==="none"?"nothing in Docker":"no Compose project: its containers by the run's labels"}`,` ${v(t)}`,` in ${t.root}${t.context?` \xB7 Docker context ${t.context}`:""}`];t.stage&&n.push(` stage: ${t.stage}`),t.note&&n.push(` ${t.note}`);for(const s of e.warnings??[])n.push(` ! ${s}`);t.url?n.push(` URL: ${t.url}`):t.urlNote&&n.push(` no URL: ${t.urlNote}`),n.push("");const c=a?.samples?`${$(a.samples,"sample","samples")}${a.sampledAt!==void 0?`, the last at ${d(a.sampledAt)}`:""}`:"no sample was taken";if(n.push(t.scope==="none"?"Memory: the job declares nothing in Docker's VM \u2014 its commands were given no labels, and Docker was not asked about it.":`Memory by service, MiB \u2014 ${c}`),e.services.length){const s=u(r=>r===void 0?"\u2013":String(r),"figure"),m=u(r=>[r.overMb!==void 0?`OVER its budget by ${r.overMb}`:void 0,r.oomKilled?"killed for memory":void 0,r.exitCode!==void 0?`exit ${r.exitCode}`:void 0,r.unsampled?"never sampled":void 0].filter(Boolean).join(" \xB7 "),"remark");n.push(...f([["service","now","peak","budget","limit",""],...e.services.map(r=>[r.name,r.unsampled?"\u2013":String(r.lastMb),r.unsampled?"\u2013":String(r.peakMb),s(r.budgetMb),s(r.limitMb),m(r)]),["all",String(e.totals.lastMb),"",s(e.totals.budgetMb),"",""]]).map(r=>` ${r}`));const p=e.services.filter(r=>r.overMb!==void 0);p.length&&n.push(` ${$(p.length,"service","services")} over what ${p.length===1?"it declares":"they declare"}: raise \`jobs.${t.job}.budget.services\` in lensmcp.json to what ${p.length===1?"it takes":"they take"} \u2014 the queue lets the job in by these figures.`)}else t.scope!=="none"&&n.push(" No container of the run was seen.");n.push("");const l=e.kills.length+(e.killsMore??0);n.push(l?`Killed for memory: ${l}`:"Killed for memory: none");for(const s of e.kills){const m=[s.limitMb!==void 0?`at its ${s.limitMb} MiB limit`:"no limit of its own: the VM ran out, or it was not read",s.peakMb!==void 0?`peak ${s.peakMb} MiB`:"never sampled",s.budgetMb!==void 0?`budget ${s.budgetMb} MiB`:void 0,s.seen==="event"?"seen live":"found by the inspect: the live stream did not tell it"].filter(Boolean).join(" \xB7 ");n.push(` ${d(s.at)} ${s.service}${s.name?` (${s.name})`:""} ${m}`)}if(e.killsMore&&n.push(` \u2026 and ${e.killsMore} more, not listed`),e.engineLost){const s=e.engineLost;n.push(""),n.push(`Docker stopped answering at ${d(s.at)} \u2014 ${s.why}`),s.backAt!==void 0&&n.push(` it answered again at ${d(s.backAt)}`),s.killed?.length&&n.push(` found killed for memory once it was gone: ${s.killed.join(", ")} \u2014 they went with the engine`)}o&&(n.push(""),n.push(`Docker's VM: ${o.totalMb} MiB \xB7 ${o.read==="estimate"?"about ":""}${o.availableAtAdmissionMb} MiB free when the run was let in (${o.read==="estimate"?"an estimate: its own figure could not be read":"the VM's own figure"})`+(o.minAvailableMb!==void 0?` \xB7 lowest ${o.minAvailableMb} MiB while it ran`:" \xB7 not read while it ran")+(o.lastAvailableMb!==void 0?` \xB7 ${o.lastAvailableMb} MiB at the last read${o.sampledAt!==void 0?` (${d(o.sampledAt)})`:""}`:""))),n.push(""),i?i.done?n.push(`Cleanup: by ${i.by==="project"?"the project's own end (LensMCP looked, and found nothing)":i.by} at ${d(i.at)} \u2014 nothing of the run is left`):n.push(`Cleanup: OWED (${i.by}, ${d(i.at)}) \u2014 ${i.why??"something that carries the run's labels is left"}${i.left?.length?` \u2014 left: ${i.left.join(", ")}`:""}`):n.push(t.ended?"Cleanup: not recorded \u2014 its guard, or the sweep, has it":"Cleanup: not yet \u2014 the run has not ended"),i?.unlabeled?.length&&n.push(` in its Compose project without the run's labels, never removed: ${i.unlabeled.join(", ")}`);for(const s of e.unlabeled??[])n.push(` ${s}`);if(a?.notes?.length||a?.streamRestarts){n.push(""),n.push("What the watcher could not do:"),a.streamRestarts&&n.push(` the live stream ended ${$(a.streamRestarts,"time","times")} while Docker answered, and was started again`);for(const s of a.notes??[])n.push(` ${s}`)}return n.push(""),n.push(`Files: ${[e.files.samples?`samples ${e.files.samples}`:void 0,e.files.events?`events ${e.files.events}`:void 0,`log ${e.files.log}`].filter(Boolean).join(" \xB7 ")}`),n.join(`
2
+ `)}h(dockerRunReportText,"dockerRunReportText"),u(dockerRunReportText,"dockerRunReportText");
@@ -0,0 +1,300 @@
1
+ import type { DockerRunCleanup, DockerRunEngineLost, DockerRunKill, DockerRunRecord, DockerRunState, DockerRunVm, DockerVmMemory, LensJobKind } from './docker-jobs.js';
2
+ import { type DockerReportService, type DockerRunReport } from './docker-report.js';
3
+ import type { RunHost, RunShortened, WorkspaceActionQueue, WorkspaceActionState } from './workspace-actions.js';
4
+ /**
5
+ * THE RUNS OF A HOME, AS EVERY SURFACE SHOWS THEM (planning/docker/00-plan.md §§ 1, 4 and 6, slice D9;
6
+ * issues/open/overseer-74). A run is shown in four places — `lensmcp docker report`, `lensmcp docker ps`, the
7
+ * `docker` block of `workspace_action_status`, and Cluster › Docker — and each of them is made here, out of the ONE
8
+ * reading of a run's record there is ({@link dockerRunReport}). None computes a figure again: a list is reports in
9
+ * an order, the block is a report cut to what an agent's answer holds, the page draws reports. So no two of them can
10
+ * say different things about one run.
11
+ *
12
+ * Pure, like the report: no file, no process, no Docker.
13
+ */
14
+ /**
15
+ * Where a run stands for whoever asks what is in Docker's VM. `up`: it has not ended — what it started is there, or
16
+ * on its way. `owed`: it ended and its cleanup is not done — something of it may still hold memory, and its record
17
+ * is the only thing that says those containers are LensMCP's. `ended`: it ended and nothing of it is left.
18
+ */
19
+ export type DockerRunStanding = 'up' | 'owed' | 'ended';
20
+ export declare function dockerRunStanding(report: Pick<DockerRunReport, 'run' | 'cleanup'>): DockerRunStanding;
21
+ /** A run in a list: its report, and where it stands. */
22
+ export interface DockerListedRun extends DockerRunReport {
23
+ standing: DockerRunStanding;
24
+ /**
25
+ * Its record says it is up, and the process that ran it is certainly gone: nobody runs it any more. Its guard — or,
26
+ * with the guard gone too, the sweep — writes its end (`lost`) and takes its stack down; until then its record
27
+ * still reads as it did when its runner died. Said by whoever read the registry on the Mac the run is on; a record
28
+ * alone cannot say it.
29
+ */
30
+ runnerGone?: true;
31
+ }
32
+ export interface DockerRunsList {
33
+ /** How many runs of each standing the registry holds — whether or not they are listed. */
34
+ counts: Record<DockerRunStanding, number>;
35
+ /** The ended ones were asked for too. */
36
+ all: boolean;
37
+ /** Ended runs past the most a list shows: counted, not listed. */
38
+ endedMore?: number;
39
+ /** The runs that are up (the newest first), then those that owe a cleanup, then — with `all` — the ended ones. */
40
+ runs: DockerListedRun[];
41
+ }
42
+ export interface DockerRunsOptions {
43
+ /** List the ended runs the registry still keeps as well. */
44
+ all?: boolean;
45
+ /** The most ended runs listed — none: every one. A run that is up or owes a cleanup is always listed. */
46
+ endedMax?: number;
47
+ now?: number;
48
+ /**
49
+ * Whether the process that ran a run is certainly gone — asked only of a run whose record says it is up. None: the
50
+ * list says what the records say, and nothing of their processes.
51
+ */
52
+ runnerGone?: (record: DockerRunRecord) => boolean;
53
+ }
54
+ /** The runs of a registry as a list: each one's report, those that still hold something first. */
55
+ export declare function dockerRunsList(records: readonly DockerRunRecord[], options?: DockerRunsOptions): DockerRunsList;
56
+ /** A run's state as a word or two: «cleaning up», «timed out». */
57
+ export declare const dockerStateWord: (state: DockerRunState) => string;
58
+ /** Since when a run is where it is: a run that is up, since its command started (or, before that, since it was made); an ended one, since its end. */
59
+ export declare function dockerRunSince(report: Pick<DockerRunReport, 'run'>): number;
60
+ /** What a run's containers hold now against what its services declare together: «1030 of 1182 MiB» — none: no sample saw a container of it. */
61
+ export declare function dockerRunHolds(report: Pick<DockerRunReport, 'services' | 'totals'>): string | undefined;
62
+ /** What is said of a run whose record reads up and whose runner is gone. */
63
+ export declare const RUNNER_GONE = "its runner is gone: nothing runs it any more \u2014 its guard, or the sweep, writes its end and takes its stack down";
64
+ /**
65
+ * What a reader must not miss about a run, a phrase each: the services over what they declare, the containers killed
66
+ * for memory, an engine that stopped answering, a cleanup that is owed. None: nothing to say.
67
+ */
68
+ export declare function dockerRunRemarks(report: DockerRunReport & {
69
+ runnerGone?: true;
70
+ }): string[];
71
+ /** The list as `lensmcp docker ps` prints it. */
72
+ export declare function dockerRunsText(list: DockerRunsList): string;
73
+ /** The most services and kills the block lists: an agent's answer is bounded, and `lensmcp docker report <run>` has every one. */
74
+ export declare const BLOCK_MAX_SERVICES = 8;
75
+ export declare const BLOCK_MAX_KILLS = 5;
76
+ /**
77
+ * A run as `workspace_action_status` carries it: the report, cut to what an agent's answer holds. Before the machine
78
+ * queue has let the run in there is no record of it, and the block is its id and its job alone — the action's `queue`
79
+ * says where it waits and why.
80
+ *
81
+ * The same figures under the same names as the report, never others: the services are the report's first (those over
82
+ * their budget, then by peak), the kills its first; what was left out is counted (`servicesMore`, `killsMore`).
83
+ */
84
+ export interface DockerRunBlock {
85
+ /** The run's id — in this home's registry and in the machine queue: `lensmcp docker report <run>` prints the whole of it. */
86
+ run: string;
87
+ /** The job's name in `lensmcp.json` → `jobs`. */
88
+ job: string;
89
+ kind?: LensJobKind;
90
+ /** Where the run is — none: the queue has not let it in yet, or never did. */
91
+ state?: DockerRunState;
92
+ standing?: DockerRunStanding;
93
+ /** Its record says it is up and the process that ran it is gone ({@link DockerListedRun.runnerGone}). */
94
+ runnerGone?: true;
95
+ /** Its Compose project. */
96
+ project?: string;
97
+ context?: string;
98
+ /** Where the project's own command says it is: «building images». */
99
+ stage?: string;
100
+ url?: string;
101
+ urlNote?: string;
102
+ note?: string;
103
+ startedAt?: number;
104
+ endedAt?: number;
105
+ ranMs?: number;
106
+ exit?: {
107
+ code: number | null;
108
+ signal: string | null;
109
+ };
110
+ vm?: DockerRunVm;
111
+ services?: DockerReportService[];
112
+ /** Services past the first {@link BLOCK_MAX_SERVICES}: none of them is over its budget unless every one listed is. */
113
+ servicesMore?: number;
114
+ /** The run's containers together at the last sample, and what its services declare together. */
115
+ totals?: {
116
+ lastMb: number;
117
+ budgetMb?: number;
118
+ };
119
+ kills?: DockerRunKill[];
120
+ killsMore?: number;
121
+ engineLost?: DockerRunEngineLost;
122
+ cleanup?: DockerRunCleanup;
123
+ }
124
+ /** The block of a run that is in the registry, from its report — and, where the reader looked, whether its runner is gone. */
125
+ export declare function dockerRunBlock(report: DockerRunReport & {
126
+ runnerGone?: true;
127
+ }): DockerRunBlock;
128
+ /**
129
+ * One service or kill fewer, for an answer that is still over its budget: the last service listed (the first are
130
+ * the ones over what they declare), then the last kill. Answers undefined when there is nothing left to drop.
131
+ */
132
+ export declare function dockerRunBlockLess(block: DockerRunBlock): DockerRunBlock | undefined;
133
+ /** Why Docker did not answer a read — the four failures of the `docker` wrapper (apps/agent, docker.ts `DockerFailure`). */
134
+ export type DockerLiveFailure = 'not-installed' | 'not-running' | 'timeout' | 'failed';
135
+ /** The most containers and things one section of the page lists; the rest are counted. */
136
+ export declare const PAGE_MAX_ROWS = 50;
137
+ /** A container, network or volume a sweep would remove. */
138
+ export interface DockerPageThing {
139
+ kind: 'container' | 'network' | 'volume';
140
+ name: string;
141
+ }
142
+ /**
143
+ * What a sweep would do, were one run now: the look of `lensmcp docker sweep --dry-run` — listings only, nothing
144
+ * written, nothing ended. The page never sweeps.
145
+ */
146
+ export interface DockerPageSweep {
147
+ /** The engines that did not say what carries this home's labels: nothing can be said of the runs in them. */
148
+ unanswered: Array<{
149
+ context?: string;
150
+ why: string;
151
+ }>;
152
+ /** The dead runs a sweep would take — runner and guard both gone — each with what it would remove. */
153
+ take: Array<{
154
+ id: string;
155
+ job: string;
156
+ project: string;
157
+ state: DockerRunState;
158
+ /** Why it is the sweep's. */
159
+ why: string;
160
+ things: DockerPageThing[];
161
+ thingsMore?: number;
162
+ /** It has no end: a sweep would write `lost`. */
163
+ lost?: true;
164
+ /** Its record says clean and the engine still names things with its labels. */
165
+ again?: true;
166
+ /** Docker did not say what it left. */
167
+ unseen?: string;
168
+ /** What sits in its Compose project without its labels: named, never removed. */
169
+ unlabeled?: string[];
170
+ }>;
171
+ /** The runs that are not clean and are somebody's: a live runner's or guard's, another cleaner's. */
172
+ leave: Array<{
173
+ id: string;
174
+ job: string;
175
+ state: DockerRunState;
176
+ why: string;
177
+ things: number;
178
+ }>;
179
+ /** Labelled as this home's, of no run on record: named, never removed. */
180
+ unrecorded: Array<DockerPageThing & {
181
+ run: string;
182
+ why: string;
183
+ }>;
184
+ unrecordedMore?: number;
185
+ }
186
+ /** The containers LensMCP did not start (plan § 5: «not LensMCP's: 2 containers, 410 MB») — listed, never touched. */
187
+ export interface DockerPageOthers {
188
+ /** The running ones first, the largest first. */
189
+ containers: Array<{
190
+ name: string;
191
+ state: string;
192
+ project?: string;
193
+ mb?: number;
194
+ }>;
195
+ /** Past the first {@link PAGE_MAX_ROWS}. */
196
+ more?: number;
197
+ total: number;
198
+ running: number;
199
+ /** What the running ones hold together, MiB. */
200
+ heldMb: number;
201
+ /** Containers of another LENSMCP_HOME's runs: that home's own to sweep. */
202
+ otherHomes: number;
203
+ /** Why no memory is given: `docker stats` did not answer. */
204
+ memoryWhy?: string;
205
+ }
206
+ /** What Docker said the last time the page had it asked. */
207
+ export interface DockerLive {
208
+ /** When the read was through, and how long it took. */
209
+ at: number;
210
+ ms: number;
211
+ /** The engine the dashboard's own `docker` reaches — none: it did not answer. */
212
+ engine?: {
213
+ context: string;
214
+ version: string;
215
+ os: string;
216
+ cpus: number;
217
+ running: number;
218
+ };
219
+ /** The VM's memory now: its own figure, an estimate (`why` says what kept the figure), or why there is none. */
220
+ vm: ({
221
+ ok: true;
222
+ } & DockerVmMemory) | {
223
+ ok: false;
224
+ failure: DockerLiveFailure;
225
+ why: string;
226
+ };
227
+ /** None: Docker does not answer, and was asked nothing more. */
228
+ sweep?: DockerPageSweep;
229
+ /** None: Docker does not answer; `othersWhy`: it answered, and the listing failed. */
230
+ others?: DockerPageOthers;
231
+ othersWhy?: string;
232
+ }
233
+ /**
234
+ * A run of a declared job placed on a worker Mac, as this Mac — the organizer — holds it: the action that keeps its
235
+ * evidence here (peers/results.ts, slice D16) and, once the worker said anything of its Docker work, that work read as
236
+ * a local run's is ({@link DockerListedRun}, from the worker's record its results carried). It is in none of this
237
+ * home's Docker run registry: its containers are in the WORKER's VM, and its cleanup is the worker's.
238
+ *
239
+ * `state` is the action's, as read now: `lost` — no word from its worker for 45 s, or the worker was revoked — is its
240
+ * own end, never «passed» and never «errored» (a local run whose runner went quiet reads errored; a remote one never
241
+ * does). Once lost, nothing its worker sends of it is taken.
242
+ */
243
+ export interface DockerRemoteRun {
244
+ /** The worker it was given to, as the peer hub knew it when the run was placed. */
245
+ host: RunHost;
246
+ /** The action here that keeps its evidence (`wa_…`): what `workspace_action_status` reads. */
247
+ action: string;
248
+ /** Its id on the channel, in the worker's queue and on its containers (`q_…`). */
249
+ run: string;
250
+ job: string;
251
+ state: WorkspaceActionState;
252
+ queuedAt: number;
253
+ startedAt?: number;
254
+ completedAt?: number;
255
+ /** The last word of it from its worker, by this Mac's clock. */
256
+ heardAt?: number;
257
+ /** One sentence beside its state: where it waits on the worker, why it ended, why it is lost. */
258
+ note?: string;
259
+ /** Where it waits in the WORKER's machine queue, and why. */
260
+ queue?: WorkspaceActionQueue;
261
+ /** Where the job's own command says it is. */
262
+ stage?: string;
263
+ /** Its Docker work as the worker last told it, read as a local run's — none: the worker has said nothing of it yet. */
264
+ report?: DockerListedRun;
265
+ /** What of its evidence reached its cap. */
266
+ shortened?: RunShortened;
267
+ }
268
+ /** Whether a remote run still holds its worker: `up` while it is queued or runs there; `lost` and `ended` are ends. */
269
+ export type DockerRemoteStanding = 'up' | 'lost' | 'ended';
270
+ export interface DockerRemoteRuns {
271
+ counts: Record<DockerRemoteStanding, number>;
272
+ /** The runs that are up (the newest first), then the ended and lost ones, the newest first. */
273
+ runs: DockerRemoteRun[];
274
+ /** Ended and lost runs past the most a list shows: counted, not listed. */
275
+ endedMore?: number;
276
+ }
277
+ export declare function dockerRemoteStanding(run: Pick<DockerRemoteRun, 'state'>): DockerRemoteStanding;
278
+ /** The remote runs as a list: those that hold a worker first, then the ends — the most recent first. */
279
+ export declare function dockerRemoteRunsList(runs: readonly DockerRemoteRun[], options?: {
280
+ endedMax?: number;
281
+ }): DockerRemoteRuns;
282
+ /**
283
+ * `GET /api/docker` — Cluster › Docker. The runs are this home's registry, read as the request comes: they need no
284
+ * Docker. `live` is what Docker itself said — the VM's memory, what a sweep would take down, what is not LensMCP's —
285
+ * the last time it was asked; it is asked in the background, never while a request waits, and only while the page
286
+ * is open: `reading` says one is on its way, and the next answer has it.
287
+ */
288
+ export interface DockerPageView {
289
+ at: number;
290
+ /** This home's label (`com.lensmcp.home`): what a container of its runs carries. */
291
+ home: string;
292
+ runs: DockerRunsList;
293
+ /**
294
+ * The runs this Mac placed on worker Macs (slice D19), read with the registry. None: a lens older than D19 — or
295
+ * a dashboard that reads no run of a worker.
296
+ */
297
+ remote?: DockerRemoteRuns;
298
+ live?: DockerLive;
299
+ reading: boolean;
300
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";var R=Object.defineProperty;var u=(t,e)=>R(t,"name",{value:e,configurable:!0});var b=Object.defineProperty,i=u((t,e)=>b(t,"name",{value:e,configurable:!0}),"l");import{dockerLasted as m,dockerRunReport as A,dockerTime as g}from"./docker-report.js";export function dockerRunStanding(t){return t.run.ended?t.cleanup?.done===!0?"ended":"owed":"up"}u(dockerRunStanding,"dockerRunStanding"),i(dockerRunStanding,"dockerRunStanding");export function dockerRunsList(t,e={}){const o=e.now??Date.now(),s=t.map(p=>{const a=A(p,o),h=dockerRunStanding(a);return{...a,standing:h,...h==="up"&&e.runnerGone?.(p)?{runnerGone:!0}:{}}}),d=i(p=>s.filter(a=>a.standing===p).sort((a,h)=>(h.run.endedAt??h.run.startedAt??h.run.createdAt)-(a.run.endedAt??a.run.startedAt??a.run.createdAt)||a.run.id.localeCompare(h.run.id)),"of"),n=d("up"),l=d("owed"),r=d("ended"),c=e.all?r.slice(0,e.endedMax??r.length):[];return{counts:{up:n.length,owed:l.length,ended:r.length},all:e.all===!0,...e.all&&c.length<r.length?{endedMore:r.length-c.length}:{},runs:[...n,...l,...c]}}u(dockerRunsList,"dockerRunsList"),i(dockerRunsList,"dockerRunsList");const M={starting:"starting",preparing:"preparing",running:"running",cleaning:"cleaning up",passed:"passed",failed:"failed",cancelled:"cancelled",timeout:"timed out",errored:"errored",lost:"lost"};export const dockerStateWord=i(t=>M[t],"dockerStateWord");export function dockerRunSince(t){const{run:e}=t;return e.ended?e.endedAt??e.startedAt??e.createdAt:e.startedAt??e.createdAt}u(dockerRunSince,"dockerRunSince"),i(dockerRunSince,"dockerRunSince");export function dockerRunHolds(t){if(t.services.some(e=>!e.unsampled))return t.totals.budgetMb===void 0?`${t.totals.lastMb} MiB`:`${t.totals.lastMb} of ${t.totals.budgetMb} MiB`}u(dockerRunHolds,"dockerRunHolds"),i(dockerRunHolds,"dockerRunHolds");export const RUNNER_GONE="its runner is gone: nothing runs it any more \u2014 its guard, or the sweep, writes its end and takes its stack down";export function dockerRunRemarks(t){const e=[];t.runnerGone&&!t.run.ended&&e.push(RUNNER_GONE);const o=t.services.filter(l=>l.overMb!==void 0);o.length&&e.push(`OVER its budget: ${o.map(l=>`${l.name} by ${l.overMb} MiB`).join(", ")}`);const s=t.kills.length+(t.killsMore??0),d=[...new Set(t.kills.map(l=>l.service))];s&&e.push(`killed for memory: ${s}${d.length?` (${d.join(", ")})`:""}`),t.engineLost&&e.push(`Docker stopped answering at ${g(t.engineLost.at)}${t.engineLost.backAt!==void 0?`, and answered again at ${g(t.engineLost.backAt)}`:""}`);const{cleanup:n}=t;return t.run.ended&&!n?e.push("cleanup OWED: none is recorded \u2014 its guard, or the sweep, has it"):n&&!n.done&&e.push(`cleanup OWED: ${n.why??"something that carries the run's labels is left"}${n.left?.length?` \u2014 left: ${n.left.join(", ")}`:""}`),n?.unlabeled?.length&&e.push(`in its Compose project without the run's labels, never removed: ${n.unlabeled.join(", ")}`),e}u(dockerRunRemarks,"dockerRunRemarks"),i(dockerRunRemarks,"dockerRunRemarks");function $(t){const{run:e}=t,o=dockerRunSince(t),s=e.ended?`ended ${g(o)}${e.ranMs!==void 0?` after ${m(e.ranMs)}`:""}`:e.startedAt!==void 0?`for ${m(e.ranMs??0)}, since ${g(o)}`:`since ${g(o)}`,d=t.standing==="up"?dockerRunHolds(t):void 0,n=[[e.job,`${dockerStateWord(e.state)}${t.standing==="owed"?", cleanup OWED":t.runnerGone?", its runner GONE":""}`,s,...d?[`holds ${d}`]:[],e.id].join(" ")];e.stage&&!e.ended&&n.push(` stage: ${e.stage}`),e.url?n.push(` URL: ${e.url}`):e.urlNote&&!e.ended&&n.push(` no URL: ${e.urlNote}`),e.note&&n.push(` ${e.note}`);for(const l of dockerRunRemarks(t))n.push(` ${l}`);return n}u($,"R"),i($,"runLines");const v=i((t,e,o)=>`${t} ${t===1?e:o}`,"plural");export function dockerRunsText(t){const{counts:e}=t;if(!(e.up+e.owed+e.ended))return["This home's registry holds no Docker run.","A job is declared in the checkout's lensmcp.json \u2192 jobs, and started with `lensmcp docker run <job>`."].join(`
2
+ `);const o=e.ended?` \xB7 ${v(e.ended,"ended one is","ended ones are")} kept${t.all?"":" (--all lists them)"}`:"",s=[`Docker runs of this home \u2014 ${e.up} up, ${e.owed?`${v(e.owed,"owes","owe")} a cleanup`:"none owes a cleanup"}${o}`];t.runs.length||s.push(" Nothing of this home is in Docker now.");for(const d of t.runs)s.push(...$(d).map(n=>` ${n}`));return t.endedMore&&s.push(` \u2026 and ${t.endedMore} more ended, not listed`),e.owed&&s.push("","A cleanup that is owed is taken by the run's guard, then by the sweep: `lensmcp docker sweep --dry-run` says what one would take down."),s.join(`
3
+ `)}u(dockerRunsText,"dockerRunsText"),i(dockerRunsText,"dockerRunsText");export const BLOCK_MAX_SERVICES=8,BLOCK_MAX_KILLS=5;const x=8,w=300,k=i(t=>t.length>w?`${t.slice(0,w-1)}\u2026`:t,"cut"),f=i(t=>t?.length?t.slice(0,x).map(e=>e.slice(0,120)):void 0,"names");export function dockerRunBlock(t){const{run:e,cleanup:o,engineLost:s}=t,d=t.services.slice(0,BLOCK_MAX_SERVICES),n=t.kills.slice(0,BLOCK_MAX_KILLS),l=t.kills.length-n.length+(t.killsMore??0),r=f(o?.left),c=f(o?.unlabeled),p=f(s?.killed);return{run:e.id,job:e.job,kind:e.kind,state:e.state,standing:dockerRunStanding(t),...t.runnerGone&&!e.ended?{runnerGone:!0}:{},project:e.project,...e.context?{context:e.context}:{},...e.stage?{stage:e.stage}:{},...e.url?{url:e.url}:{},...e.urlNote?{urlNote:k(e.urlNote)}:{},...e.note?{note:k(e.note)}:{},...e.startedAt!==void 0?{startedAt:e.startedAt}:{},...e.endedAt!==void 0?{endedAt:e.endedAt}:{},...e.ranMs!==void 0?{ranMs:e.ranMs}:{},...e.exit?{exit:e.exit}:{},...t.vm?{vm:t.vm}:{},services:d,...t.services.length>d.length?{servicesMore:t.services.length-d.length}:{},totals:t.totals,kills:n.map(a=>({...a,container:a.container.slice(0,12)})),...l?{killsMore:l}:{},...s?{engineLost:{at:s.at,why:k(s.why),...s.backAt!==void 0?{backAt:s.backAt}:{},...p?{killed:p}:{}}}:{},...o?{cleanup:{by:o.by,at:o.at,done:o.done,...r?{left:r}:{},...c?{unlabeled:c}:{},...o.why?{why:k(o.why)}:{}}}:{}}}u(dockerRunBlock,"dockerRunBlock"),i(dockerRunBlock,"dockerRunBlock");export function dockerRunBlockLess(t){if(t.services&&t.services.length>1)return{...t,services:t.services.slice(0,-1),servicesMore:(t.servicesMore??0)+1};if(t.kills&&t.kills.length>1)return{...t,kills:t.kills.slice(0,-1),killsMore:(t.killsMore??0)+1}}u(dockerRunBlockLess,"dockerRunBlockLess"),i(dockerRunBlockLess,"dockerRunBlockLess");export const PAGE_MAX_ROWS=50;const L=["queued","running"];export function dockerRemoteStanding(t){return t.state==="lost"?"lost":L.includes(t.state)?"up":"ended"}u(dockerRemoteStanding,"dockerRemoteStanding"),i(dockerRemoteStanding,"dockerRemoteStanding");export function dockerRemoteRunsList(t,e={}){const o=i(r=>r.completedAt??r.startedAt??r.queuedAt,"since"),s=[...t].sort((r,c)=>o(c)-o(r)||r.run.localeCompare(c.run)),d=s.filter(r=>dockerRemoteStanding(r)==="up"),n=s.filter(r=>dockerRemoteStanding(r)!=="up"),l=n.slice(0,e.endedMax??n.length);return{counts:{up:d.length,lost:n.filter(r=>r.state==="lost").length,ended:n.filter(r=>r.state!=="lost").length},runs:[...d,...l],...l.length<n.length?{endedMore:n.length-l.length}:{}}}u(dockerRemoteRunsList,"dockerRemoteRunsList"),i(dockerRemoteRunsList,"dockerRemoteRunsList");
@@ -0,0 +1,139 @@
1
+ /**
2
+ * ACCOUNTS AND LIMITS PER HOST (planning/docker/00-plan.md § 13 «Accounts and goal power», slice D31;
3
+ * issues/open/overseer-74). Each Mac has its own sign-ins: a worker reports its accounts — id, client, label, whether it
4
+ * is standalone, which one is selected per client, its quota stop and its usage — in its capacity advert (`agents`),
5
+ * and the organizer reads that part field by field before it keeps it, per host. NEVER a token, never the path of a
6
+ * sign-in's folder: the advert names an account by its id and label only, and a part that carries anything shaped like
7
+ * a credential is refused whole.
8
+ *
9
+ * Goal power stays team-wide (planning/team/22): capacity counts agents wherever they run. A host adds its own ceiling —
10
+ * `agents` at once, the person's number, else one from its memory — and the clients it has a sign-in for.
11
+ *
12
+ * ~/.lensmcp/peers/host-agents.json 0600 the organizer's: each worker's agents part as last read, by its peer id
13
+ * ~/.lensmcp/peers/host-ceilings.json 0600 the person's ceilings, by host (`local` or a worker's peer id)
14
+ *
15
+ * Pure, as the rest of this package: the dashboard reads these too.
16
+ */
17
+ export type HostAgentClient = 'claude' | 'codex';
18
+ export declare const HOST_AGENT_CLIENTS: readonly HostAgentClient[];
19
+ /** The organizer's files for the hosts' accounts and ceilings, under `~/.lensmcp/peers/`. */
20
+ export declare const HOST_AGENTS_FILES: {
21
+ readonly agents: "host-agents.json";
22
+ readonly ceilings: "host-ceilings.json";
23
+ };
24
+ /** What an agents part may hold: more is refused whole, never cut — a Mac with more sign-ins than this is not one the organizer reads. */
25
+ export declare const HOST_AGENTS_LIMITS: {
26
+ readonly accounts: 32;
27
+ readonly windows: 6;
28
+ readonly label: 60;
29
+ readonly why: 300;
30
+ readonly plan: 40;
31
+ readonly name: 40;
32
+ /** The most agents a host's ceiling may say at once. */
33
+ readonly agents: 64;
34
+ };
35
+ /** An account's id (`lensmcp agent accounts`): the storage's `ACCOUNT_ID`. */
36
+ export declare const HOST_ACCOUNT_ID: RegExp;
37
+ /** A quota stop in force on a sign-in (storage client-quota.ts `ClientQuotaStop`, without the launch and repository). */
38
+ export interface HostQuotaStop {
39
+ /** When it was read, and until when no launch runs on it — by the HOST's clock. */
40
+ at: number;
41
+ until: number;
42
+ reset: 'given' | 'assumed' | 'held';
43
+ /** The client's own words. */
44
+ why: string;
45
+ }
46
+ /** What a sign-in has used of its plan (storage account-usage.ts `AccountUsage`), as its host last read it. */
47
+ export interface HostUsage {
48
+ at: number;
49
+ plan?: string;
50
+ windows: Array<{
51
+ name: string;
52
+ usedPercent: number;
53
+ resetsAt?: number;
54
+ minutes?: number;
55
+ }>;
56
+ /** Codex: the limit it says was reached, and whether credits carry work past a full window. */
57
+ reached?: string;
58
+ carried?: true;
59
+ }
60
+ /** One account on a host — what the person and placement need, and nothing that signs in. */
61
+ export interface HostAccount {
62
+ id: string;
63
+ client: HostAgentClient;
64
+ label: string;
65
+ /** Kept for the person's own sessions: no team agent runs on it, on any host. */
66
+ standalone?: true;
67
+ /** The account new launches of its client use on that host. */
68
+ selected?: true;
69
+ quota?: HostQuotaStop;
70
+ usage?: HostUsage;
71
+ }
72
+ /** A client's own sign-in on a host (`~/.claude`, `~/.codex` there): what a launch runs under when no account of the client is selected. */
73
+ export interface HostOwnSignIn {
74
+ client: HostAgentClient;
75
+ quota?: HostQuotaStop;
76
+ usage?: HostUsage;
77
+ }
78
+ /**
79
+ * The `agents` part of a worker's capacity advert (in `hello` and `capacity`). `at` is the host's clock; `running`: the
80
+ * launched agents running there now (its launch registry, every repository's).
81
+ */
82
+ export interface HostAgentsAdvert {
83
+ at: number;
84
+ running: number;
85
+ accounts: HostAccount[];
86
+ /** The clients whose own sign-in folder exists there — none: no client is set up there outside its accounts. */
87
+ own: HostOwnSignIn[];
88
+ }
89
+ /** A host's ceiling: the person's number, or one from its memory. */
90
+ export interface HostCeiling {
91
+ agents: number;
92
+ from: 'person' | 'memory';
93
+ /** The whole memory the default was worked out from, MiB — none: not known yet. */
94
+ memoryMb?: number;
95
+ /** When the person set it. */
96
+ setAt?: number;
97
+ }
98
+ /** A host's account as the page shows it: `stopped` — its quota stop holds now. */
99
+ export type HostAccountView = HostAccount & {
100
+ stopped?: true;
101
+ };
102
+ export type HostOwnView = HostOwnSignIn & {
103
+ stopped?: true;
104
+ };
105
+ /** One host's agents, accounts and ceiling, as `GET /api/team/hosts` answers it. */
106
+ export interface HostAgentsView {
107
+ /** `local` — this Mac — or the worker's peer id. */
108
+ id: string;
109
+ name: string;
110
+ local: boolean;
111
+ /** When its accounts were said, by THIS Mac's clock — a worker's: its last advert's. */
112
+ at?: number;
113
+ /** The launched agents running there now, as it last said. */
114
+ running?: number;
115
+ ceiling: HostCeiling;
116
+ /** The clients a goal can run on there: a usable sign-in (the selected account, else the client's own) that is not quota-stopped now. */
117
+ clients: HostAgentClient[];
118
+ accounts: HostAccountView[];
119
+ own: HostOwnView[];
120
+ /** Why its accounts are not known: a worker that has not said them, or said them in a form this Mac does not read. */
121
+ unread?: string;
122
+ }
123
+ /** `GET /api/team/hosts` (and the answer of a ceiling's write). */
124
+ export interface HostAccountsAnswer {
125
+ at: number;
126
+ /** This Mac first, then the paired workers by name. */
127
+ hosts: HostAgentsView[];
128
+ /** The ceiling writes are taken from a dashboard bound to loopback only (Settings › Hosts' rule): false — read only here. */
129
+ writable: boolean;
130
+ }
131
+ /** `POST /api/team/hosts/ceiling`: the person's ceiling for a host — `null`: back to the one from its memory. */
132
+ export interface HostCeilingWrite {
133
+ host: string;
134
+ agents: number | null;
135
+ }
136
+ /** Whether `text` carries something shaped like a credential. */
137
+ export declare function tokenShaped(text: string): boolean;
138
+ /** `text` with every credential-shaped piece replaced by `…` — what a worker says of a client's own words before it sends them. */
139
+ export declare function withoutTokens(text: string): string;
@@ -0,0 +1 @@
1
+ "use strict";var A=Object.defineProperty;var s=(t,e)=>A(t,"name",{value:e,configurable:!0});var c=Object.defineProperty,o=s((t,e)=>c(t,"name",{value:e,configurable:!0}),"o");export const HOST_AGENT_CLIENTS=["claude","codex"],HOST_AGENTS_FILES={agents:"host-agents.json",ceilings:"host-ceilings.json"},HOST_AGENTS_LIMITS={accounts:32,windows:6,label:60,why:300,plan:40,name:40,agents:64},HOST_ACCOUNT_ID=/^ac-[a-z0-9]{1,12}-[a-f0-9]{6}$/;const n=[/\bsk-[A-Za-z0-9_-]{16,}/,/\b[rs]k_(?:live|test)_[A-Za-z0-9]{12,}/,/\bgh[pousr]_[A-Za-z0-9]{20,}|\bgithub_pat_[A-Za-z0-9_]{20,}/,/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/,/\bxox[abposr]-[A-Za-z0-9-]{10,}/,/\bAIza[0-9A-Za-z_-]{30,}/,/\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{4,}/,/-----BEGIN [A-Z ]*(?:PRIVATE KEY|CERTIFICATE)-----/,/\bbearer\s+[A-Za-z0-9._~+/=-]{12,}/i],r=/[A-Za-z0-9+/_=-]{32,}/g;export function tokenShaped(t){if(n.some(e=>e.test(t)))return!0;for(const e of t.match(r)??[])if(/\d/.test(e)&&/[A-Za-z]/.test(e))return!0;return!1}s(tokenShaped,"tokenShaped"),o(tokenShaped,"tokenShaped");export function withoutTokens(t){let e=t;for(const a of n)e=e.replace(new RegExp(a.source,a.flags.includes("g")?a.flags:`${a.flags}g`),"\u2026");return e.replace(r,a=>/\d/.test(a)&&/[A-Za-z]/.test(a)?"\u2026":a)}s(withoutTokens,"withoutTokens"),o(withoutTokens,"withoutTokens");