@lensmcp/cluster 1.26.2 → 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.
- package/build-host.js +1 -1
- package/devserver-host.d.ts +5 -0
- package/devserver-host.js +1 -1
- package/executors/gateway/runtime/auth.js +1 -1
- package/executors/gateway/runtime/control.d.ts +25 -0
- package/executors/gateway/runtime/control.js +2 -2
- package/executors/gateway/runtime/discovery.js +1 -1
- package/executors/gateway/runtime/docker-sweep.d.ts +51 -0
- package/executors/gateway/runtime/docker-sweep.js +1 -0
- package/executors/gateway/runtime/edge.d.ts +2 -0
- package/executors/gateway/runtime/edge.js +1 -1
- package/executors/gateway/runtime/frontend-updates.d.ts +24 -0
- package/executors/gateway/runtime/frontend-updates.js +1 -0
- package/executors/gateway/runtime/handler.js +1 -1
- package/executors/gateway/runtime/legacy-dashboard-link.d.ts +10 -0
- package/executors/gateway/runtime/legacy-dashboard-link.js +1 -0
- package/executors/gateway/runtime/lens-children.d.ts +9 -0
- package/executors/gateway/runtime/lens-children.js +1 -1
- package/executors/gateway/runtime/lifecycle.d.ts +2 -0
- package/executors/gateway/runtime/lifecycle.js +4 -4
- package/executors/gateway/runtime/peer-hub.d.ts +54 -0
- package/executors/gateway/runtime/peer-hub.js +1 -0
- package/executors/gateway/runtime/proxy.js +1 -1
- package/executors/gateway/runtime/remote-instances.d.ts +167 -0
- package/executors/gateway/runtime/remote-instances.js +1 -0
- package/executors/gateway/runtime/run-routes.d.ts +186 -0
- package/executors/gateway/runtime/run-routes.js +1 -0
- package/executors/gateway/runtime/server.js +2 -2
- package/executors/gateway/runtime/service-updates.d.ts +44 -0
- package/executors/gateway/runtime/service-updates.js +1 -0
- package/executors/gateway/runtime/shared-build.d.ts +8 -1
- package/executors/gateway/runtime/shared-build.js +4 -4
- package/executors/gateway/runtime/types.d.ts +54 -0
- package/executors/gateway/runtime/update-wiring.d.ts +57 -0
- package/executors/gateway/runtime/update-wiring.js +2 -0
- package/executors/gateway/runtime/updates.d.ts +148 -0
- package/executors/gateway/runtime/updates.js +1 -0
- package/executors/gateway/runtime/upgrade.js +1 -1
- package/executors/serve/serve.impl.js +1 -1
- package/executors/serve/updates-gate.d.ts +147 -0
- package/executors/serve/updates-gate.js +2 -0
- package/main.devserver.js +10 -10
- package/package.json +5 -5
- package/program-id.d.ts +4 -0
- package/program-id.js +1 -0
- package/shared-build/host.d.ts +102 -2
- package/shared-build/host.js +3 -3
- package/shared-build/protocol.d.ts +59 -3
- package/shared-build/protocol.js +1 -1
- package/shared-build/shared-compilation.d.ts +21 -0
- package/shared-build/shared-compilation.js +3 -3
- package/static-checks-record.d.ts +391 -0
- package/static-checks-record.js +5 -0
- package/tsgo-check-plugin.d.ts +107 -43
- package/tsgo-check-plugin.js +4 -5
- package/tsgo-shim.d.ts +112 -0
- package/tsgo-shim.js +2 -0
- package/typecheck-bus.d.ts +36 -5
- package/typecheck-bus.js +4 -4
- package/typecheck-memory.d.ts +187 -0
- package/typecheck-memory.js +1 -0
- package/typecheck-queue.d.ts +41 -3
- package/typecheck-queue.js +1 -1
package/typecheck-bus.d.ts
CHANGED
|
@@ -13,18 +13,40 @@ export declare function parseTscDiagnosticLine(raw: string): TscDiagnostic | nul
|
|
|
13
13
|
/** MIRROR of session's `parseTscOutput`. */
|
|
14
14
|
export declare function parseTscOutput(output: string): TscDiagnostic[];
|
|
15
15
|
/**
|
|
16
|
-
* A compiler error
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* A compiler error that says the program was not checked as configured, so the run has no verdict
|
|
17
|
+
* (planning/checks/00-plan.md, finding 1). MIRROR of session's `TscProgramError`. Two shapes, both from tsgo
|
|
18
|
+
* 7.0.0-dev.20260707.2:
|
|
19
|
+
*
|
|
20
|
+
* • no file position — `error TS18003: No inputs were found in config file …`, TS5083 (an extended file it cannot
|
|
21
|
+
* read), TS6053, TS2688 (a type library named in `types` it cannot find);
|
|
22
|
+
* • a position inside a config file — `apps/svc/tsconfig.app.json(4,5): error TS5102: Option 'baseUrl' has been
|
|
23
|
+
* removed`, and TS5108 / TS5090 / TS5023 the same way. tsgo places an option it refuses at the JSON that declares
|
|
24
|
+
* it, so it parses as a diagnostic — and read as one, a refused configuration was «1 type error» in a tsconfig,
|
|
25
|
+
* with every real error of the program unreported (the TS5090 story the checker's shim was written for).
|
|
19
26
|
*/
|
|
20
27
|
export interface TscProgramError {
|
|
21
28
|
code: string;
|
|
22
29
|
message: string;
|
|
23
|
-
/**
|
|
30
|
+
/** What the line named before `error`: the config file of a placed error, or a name printed without a position. */
|
|
24
31
|
source?: string;
|
|
32
|
+
/** Set for an error placed in a config file. */
|
|
33
|
+
line?: number;
|
|
34
|
+
column?: number;
|
|
25
35
|
}
|
|
26
|
-
/**
|
|
36
|
+
/** MIRROR of session's `parseTscProgramErrors`: every error line about the program, not about a place in its code. */
|
|
27
37
|
export declare function parseTscProgramErrors(output: string): TscProgramError[];
|
|
38
|
+
/**
|
|
39
|
+
* Why a run gave no verdict — MIRROR of `ToolErrorKind` in `@lensmcp/protocol-types` (static-checks.ts), which
|
|
40
|
+
* cluster does not depend on. On the END event as `raw.errorKind`.
|
|
41
|
+
*/
|
|
42
|
+
export type ToolErrorKind = 'config-refused' | 'program-error' | 'timeout' | 'signal' | 'exit-without-diagnostics' | 'spawn-failed' | 'unparseable-output';
|
|
43
|
+
/**
|
|
44
|
+
* MIRROR of session's `programErrorKind`: `config-refused` when the compiler refused the configuration — an error
|
|
45
|
+
* placed in a config file, or one of TypeScript's option and config-file codes (TS5xxx: TS5102 / TS5108 / TS5090,
|
|
46
|
+
* TS5083) — else `program-error`: the configuration was taken and the program could not be built from it (TS18003,
|
|
47
|
+
* TS6053, TS2688).
|
|
48
|
+
*/
|
|
49
|
+
export declare function programErrorKind(errors: readonly TscProgramError[]): 'config-refused' | 'program-error';
|
|
28
50
|
/** The no-verdict reason for a run whose program could not be checked: the first program error, and how many more. */
|
|
29
51
|
export declare function programErrorDetail(tool: string, errors: readonly TscProgramError[], exitCode?: number | null): string;
|
|
30
52
|
/** MIRROR of session's cap — a broken tsconfig can cascade into thousands. */
|
|
@@ -64,6 +86,8 @@ export declare function buildTypecheckRunEvents(args: {
|
|
|
64
86
|
diagnostics: readonly TscDiagnostic[];
|
|
65
87
|
durationMs: number;
|
|
66
88
|
toolError?: string;
|
|
89
|
+
/** Which tool error it is, on the END event as `raw.errorKind`. */
|
|
90
|
+
toolErrorKind?: ToolErrorKind;
|
|
67
91
|
/** Kept on the END event of a no-verdict run, so the reason is there with its codes. */
|
|
68
92
|
programErrors?: readonly TscProgramError[];
|
|
69
93
|
now?: () => number;
|
|
@@ -111,6 +135,8 @@ export declare function publishTypecheckRun(args: {
|
|
|
111
135
|
output: string;
|
|
112
136
|
durationMs: number;
|
|
113
137
|
toolError?: string;
|
|
138
|
+
/** Which tool error `toolError` is. A program error found in the output names its own kind. */
|
|
139
|
+
toolErrorKind?: ToolErrorKind;
|
|
114
140
|
eventFile?: string;
|
|
115
141
|
}): TypecheckBusEvent[];
|
|
116
142
|
/**
|
|
@@ -118,6 +144,8 @@ export declare function publishTypecheckRun(args: {
|
|
|
118
144
|
* the line while the machine has less free than a check waits for. Said once per held check, so a check that has not
|
|
119
145
|
* run reads «held», not «slow». No verdict: `phase: 'held'` is neither a run's START (its title does NOT start with
|
|
120
146
|
* `tsc clear`, which an older reducer resets on) nor its END. Producer-only — session's mirror has no checker to hold.
|
|
147
|
+
* `minFreeMb` is what THIS check waits for: the line's least amount, or — with a `reason` — what its own program's last
|
|
148
|
+
* check held and a quarter more (typecheck-memory.ts, slice C6 of planning/checks).
|
|
121
149
|
*/
|
|
122
150
|
export declare function buildTypecheckHeldEvent(args: {
|
|
123
151
|
project: string;
|
|
@@ -125,6 +153,8 @@ export declare function buildTypecheckHeldEvent(args: {
|
|
|
125
153
|
tsConfig?: string;
|
|
126
154
|
availableMb: number;
|
|
127
155
|
minFreeMb: number;
|
|
156
|
+
/** Why it waits for more than the line's least amount: «its last cold check held 6000 MB (sampled), and a quarter more». */
|
|
157
|
+
reason?: string;
|
|
128
158
|
now?: () => number;
|
|
129
159
|
idImpl?: () => string;
|
|
130
160
|
}): TypecheckBusEvent;
|
|
@@ -135,5 +165,6 @@ export declare function publishTypecheckHeld(args: {
|
|
|
135
165
|
tsConfig?: string;
|
|
136
166
|
availableMb: number;
|
|
137
167
|
minFreeMb: number;
|
|
168
|
+
reason?: string;
|
|
138
169
|
eventFile?: string;
|
|
139
170
|
}): TypecheckBusEvent;
|
package/typecheck-bus.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)){const
|
|
3
|
-
`)){const
|
|
1
|
+
"use strict";var g=Object.defineProperty;var s=(r,e)=>g(r,"name",{value:e,configurable:!0});var f=Object.defineProperty,i=s((r,e)=>f(r,"name",{value:e,configurable:!0}),"i");Object.defineProperty(exports,"__esModule",{value:!0}),exports.MAX_DIAGNOSTICS_PER_RUN=void 0,exports.stripAnsi=stripAnsi,exports.parseTscDiagnosticLine=parseTscDiagnosticLine,exports.parseTscOutput=parseTscOutput,exports.parseTscProgramErrors=parseTscProgramErrors,exports.programErrorKind=programErrorKind,exports.programErrorDetail=programErrorDetail,exports.buildTypecheckRunEvents=buildTypecheckRunEvents,exports.resolveEventFile=resolveEventFile,exports.appendTypecheckEvents=appendTypecheckEvents,exports.publishTypecheckDiagnostics=publishTypecheckDiagnostics,exports.publishTypecheckRun=publishTypecheckRun,exports.buildTypecheckHeldEvent=buildTypecheckHeldEvent,exports.publishTypecheckHeld=publishTypecheckHeld;const tslib_1=require("tslib"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path")),busHygiene=(()=>{try{return require("@lensmcp/node-instrumentation")}catch{return}})(),DIAG_LINE_REGEX=/^(.+?)\((\d+),(\d+)\):\s+(error|warning)\s+(TS\d+):\s+(.+)$/,ANSI_CSI=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function stripAnsi(r){return r.replace(ANSI_CSI,"")}s(stripAnsi,"stripAnsi"),i(stripAnsi,"stripAnsi");function parseTscDiagnosticLine(r){const e=stripAnsi(r).trim();if(!e)return null;const o=DIAG_LINE_REGEX.exec(e);if(!o)return null;const[,t,n,p,l,u,a]=o;return!t||!n||!p||!l||!u||!a?null:{file:t,line:Number(n),column:Number(p),severity:l==="warning"?"warning":"error",code:u,message:a}}s(parseTscDiagnosticLine,"parseTscDiagnosticLine"),i(parseTscDiagnosticLine,"parseTscDiagnosticLine");function parseTscOutput(r){const e=[];for(const o of r.split(`
|
|
2
|
+
`)){const t=parseTscDiagnosticLine(o);t&&e.push(t)}return e}s(parseTscOutput,"parseTscOutput"),i(parseTscOutput,"parseTscOutput");const PROGRAM_ERROR_REGEX=/\berror\s+(TS\d+):?\s*(.*)$/,CONFIG_FILE_REGEX=/\.json$/i;function parseTscProgramErrors(r){const e=[];for(const o of r.split(`
|
|
3
|
+
`)){const t=stripAnsi(o).trim();if(!t)continue;const n=parseTscDiagnosticLine(t);if(n){n.severity==="error"&&CONFIG_FILE_REGEX.test(n.file)&&e.push({code:n.code,message:n.message,source:n.file,line:n.line,column:n.column});continue}const p=PROGRAM_ERROR_REGEX.exec(t);if(!p)continue;const[,l="",u=""]=p,a=t.slice(0,p.index).replace(/[\s:]+$/,"");e.push({code:l,message:u,...a?{source:a}:{}})}return e}s(parseTscProgramErrors,"parseTscProgramErrors"),i(parseTscProgramErrors,"parseTscProgramErrors");function programErrorKind(r){return r.some(e=>e.line!==void 0||/^TS5\d{3}$/.test(e.code))?"config-refused":"program-error"}s(programErrorKind,"programErrorKind"),i(programErrorKind,"programErrorKind");function programErrorDetail(r,e,o){const t=e[0],n=e.length>1?` (+${e.length-1} more)`:"",p=o==null?"":` (exit ${o})`;return`${r} could not check the program${p}: ${t?`${t.code}: ${t.message}`.slice(0,300):"no message"}${n}`}s(programErrorDetail,"programErrorDetail"),i(programErrorDetail,"programErrorDetail"),exports.MAX_DIAGNOSTICS_PER_RUN=200;let idCounter=0;function makeId(){return idCounter=(idCounter+1)%65535,`${Date.now().toString(36)}${idCounter.toString(36)}${Math.random().toString(36).slice(2,8)}`}s(makeId,"makeId"),i(makeId,"makeId");function buildTypecheckRunEvents(r){const e=(r.now??Date.now)(),o=r.idImpl??makeId,t="pending",n={sessionId:t,source:"typescript",category:"typecheck",context:{sessionId:t,projectName:r.project}},p={project:r.project,tool:r.tool,...r.tsConfig?{tsConfig:r.tsConfig}:{}},l=r.diagnostics.filter(c=>c.severity==="error"),u=r.diagnostics.slice(0,exports.MAX_DIAGNOSTICS_PER_RUN),a=[];if(!r.toolError){a.push({...n,id:o(),timestamp:e,severity:"info",title:`tsc clear: ${r.project}`,message:`typecheck run starting for ${r.project}`,fingerprint:`tsc:${r.project}:run-start`,raw:{...p,kind:"typecheck-run",phase:"start"}});for(const c of u)a.push({...n,id:o(),timestamp:e,severity:c.severity,title:`${c.code}: ${c.message}`,message:c.message,location:{file:c.file,line:c.line,column:c.column},fingerprint:`tsc:${r.project}:${c.file}:${c.line}:${c.column}:${c.code}`,raw:{...p,kind:"typecheck-diagnostic",code:c.code}})}const d=r.toolError?"error":l.length>0?"failing":"clean";return a.push({...n,id:o(),timestamp:e,severity:"info",title:`typecheck run: ${r.project} \u2014 ${r.toolError?"tool error":`${l.length} error${l.length===1?"":"s"}`} (${r.durationMs}ms)`,...r.toolError?{message:r.toolError}:{},fingerprint:`tsc:${r.project}:run-end`,raw:{...p,kind:"typecheck-run",phase:"end",status:d,durationMs:r.durationMs,errorCount:l.length,warningCount:r.diagnostics.length-l.length,...r.diagnostics.length>u.length?{truncatedDiagnostics:r.diagnostics.length-u.length}:{},...r.toolError?{error:r.toolError}:{},...r.toolError&&r.toolErrorKind?{errorKind:r.toolErrorKind}:{},...r.programErrors?.length?{programErrors:r.programErrors.slice(0,exports.MAX_DIAGNOSTICS_PER_RUN)}:{}}}),a}s(buildTypecheckRunEvents,"buildTypecheckRunEvents"),i(buildTypecheckRunEvents,"buildTypecheckRunEvents");function resolveEventFile(r){return process.env.LENSMCP_EVENT_FILE||path.join(r,".lensmcp","events.jsonl")}s(resolveEventFile,"resolveEventFile"),i(resolveEventFile,"resolveEventFile");let ensuredDir=null;function ensureDir(r){const e=path.dirname(r);ensuredDir!==e&&(fs.mkdirSync(e,{recursive:!0}),ensuredDir=e)}s(ensureDir,"ensureDir"),i(ensureDir,"ensureDir");function appendTypecheckEvents(r,e){if(e.length===0)return;const o=e.map(t=>JSON.stringify(t)).join(`
|
|
4
4
|
`)+`
|
|
5
|
-
`;try{ensureDir(
|
|
5
|
+
`;try{ensureDir(r),busHygiene?.maybeRotateEventFile(r,o.length),fs.appendFileSync(r,o)}catch(t){if(t?.code==="ENOENT"){try{ensuredDir=null,ensureDir(r),fs.appendFileSync(r,o)}catch{}return}}}s(appendTypecheckEvents,"appendTypecheckEvents"),i(appendTypecheckEvents,"appendTypecheckEvents");function publishTypecheckDiagnostics(r){const e=buildTypecheckRunEvents({project:r.project,tool:r.tool,...r.tsConfig?{tsConfig:r.tsConfig}:{},diagnostics:r.diagnostics,durationMs:r.durationMs});return appendTypecheckEvents(r.eventFile??resolveEventFile(r.workspaceRoot),e),e}s(publishTypecheckDiagnostics,"publishTypecheckDiagnostics"),i(publishTypecheckDiagnostics,"publishTypecheckDiagnostics");function publishTypecheckRun(r){const e=parseTscProgramErrors(r.output),o=r.toolError??(e.length?programErrorDetail(r.tool,e):void 0),t=r.toolErrorKind??(e.length?programErrorKind(e):void 0),n=buildTypecheckRunEvents({project:r.project,tool:r.tool,...r.tsConfig?{tsConfig:r.tsConfig}:{},diagnostics:o?[]:parseTscOutput(r.output),durationMs:r.durationMs,...o?{toolError:o}:{},...o&&t?{toolErrorKind:t}:{},...e.length?{programErrors:e}:{}});return appendTypecheckEvents(r.eventFile??resolveEventFile(r.workspaceRoot),n),n}s(publishTypecheckRun,"publishTypecheckRun"),i(publishTypecheckRun,"publishTypecheckRun");function buildTypecheckHeldEvent(r){const e="pending";return{id:(r.idImpl??makeId)(),sessionId:e,timestamp:(r.now??Date.now)(),source:"typescript",category:"typecheck",severity:"info",context:{sessionId:e,projectName:r.project},title:`typecheck held: ${r.project} \u2014 ${r.availableMb} MB free, a check waits for ${r.minFreeMb} MB`,message:`the type check of ${r.project} waits until ${r.minFreeMb} MB is free ${r.reason?`\u2014 ${r.reason}`:"(LENSMCP_TYPECHECK_MIN_FREE_MB)"}`,fingerprint:`tsc:${r.project}:run-held`,raw:{project:r.project,tool:r.tool,...r.tsConfig?{tsConfig:r.tsConfig}:{},kind:"typecheck-run",phase:"held",availableMb:r.availableMb,minFreeMb:r.minFreeMb,...r.reason?{reason:r.reason}:{}}}}s(buildTypecheckHeldEvent,"buildTypecheckHeldEvent"),i(buildTypecheckHeldEvent,"buildTypecheckHeldEvent");function publishTypecheckHeld(r){const e=buildTypecheckHeldEvent(r);return appendTypecheckEvents(r.eventFile??resolveEventFile(r.workspaceRoot),[e]),e}s(publishTypecheckHeld,"publishTypecheckHeld"),i(publishTypecheckHeld,"publishTypecheckHeld");
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { type ProgramFiles } from './static-checks-record';
|
|
2
|
+
/** Moves when what a peaks file holds changes: one kept by another version is never read as this one's. */
|
|
3
|
+
export declare const PEAKS_SCHEMA = 1;
|
|
4
|
+
/** What a turn waits for, over what the check last held. */
|
|
5
|
+
export declare const PEAK_MARGIN = 1.25;
|
|
6
|
+
/** What a program is taken for when nothing in the workspace was ever measured (MB) — the plan's figure, and what a worktree's services wait for before they start (`LENSMCP_WARM_MIN_FREE_MB`). */
|
|
7
|
+
export declare const DEFAULT_UNMEASURED_MB = 4096;
|
|
8
|
+
/**
|
|
9
|
+
* Above this, a check runs on fewer checkers (MB). Read from the issue's measurements (overseer-75, «Phase 4 — memory
|
|
10
|
+
* bounds»): the three programs measured there hold 5.7–8.0 GB with the compiler's four checkers — engine app,
|
|
11
|
+
* dashboard app, engine spec, the «tsgo default» column — and a service's cold check otherwise holds 1.4–3.4 GB
|
|
12
|
+
* (foodguard-34). 4,096 is between the two: every program the issue names for its memory runs on two, and no ordinary
|
|
13
|
+
* service does. What two checkers cost in time and save in memory is not measured yet — the issue has only the
|
|
14
|
+
* single-threaded column — so this default is to be set again from that measurement (the plan's [FG] of slice C6).
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_CHECKERS_ABOVE_MB = 4096;
|
|
17
|
+
/** The checkers a program over the threshold is checked with. */
|
|
18
|
+
export declare const REDUCED_CHECKERS = 2;
|
|
19
|
+
/** How a peak was read: macOS «peak memory footprint», a maximum resident size, or resident sizes looked at while it ran — a lower bound. */
|
|
20
|
+
export type PeakHow = 'footprint' | 'maxrss' | 'sampled';
|
|
21
|
+
export interface MeasuredPeak {
|
|
22
|
+
mb: number;
|
|
23
|
+
how: PeakHow;
|
|
24
|
+
/** The checkers the check ran with; absent: the compiler's own number. */
|
|
25
|
+
checkers?: number;
|
|
26
|
+
at: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ProgramPeaks {
|
|
29
|
+
schema: number;
|
|
30
|
+
/** program-id.ts. */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Workspace-relative: for whoever reads the file. */
|
|
33
|
+
tsconfig: string;
|
|
34
|
+
/** The last check that started with no build info to read. */
|
|
35
|
+
cold?: MeasuredPeak;
|
|
36
|
+
/** The last check that started from one. */
|
|
37
|
+
warm?: MeasuredPeak;
|
|
38
|
+
/** The most a check with the compiler's own number of checkers held: what puts the program on fewer, and keeps it there. */
|
|
39
|
+
full?: {
|
|
40
|
+
mb: number;
|
|
41
|
+
at: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** `LENSMCP_TYPECHECK_CHECKERS_ABOVE_MB`, default 4096; `0` never runs a check on fewer checkers. Anything unreadable is the default. */
|
|
45
|
+
export declare function typecheckCheckersAboveMb(env?: NodeJS.ProcessEnv): number;
|
|
46
|
+
/** `LENSMCP_TYPECHECK_SINGLE_THREADED` — off unless it is `1`/`true`/`on`/`yes`. */
|
|
47
|
+
export declare function typecheckSingleThreaded(env?: NodeJS.ProcessEnv): boolean;
|
|
48
|
+
/** `<root>/.lensmcp/static-checks/typecheck/<id>.peaks.json` — beside the program's verdict record. */
|
|
49
|
+
export declare function peaksFile(root: string, id: string): string;
|
|
50
|
+
/** What this checkout measured of a program; null when it measured nothing, or the file is another schema's. */
|
|
51
|
+
export declare function readPeaks(root: string, id: string): ProgramPeaks | null;
|
|
52
|
+
/**
|
|
53
|
+
* The main checkout of the repository a worktree belongs to, read from the files git keeps — in a worktree `.git` is a
|
|
54
|
+
* file naming the worktree's own git folder, whose `commondir` names the repository's. No git is started: a service
|
|
55
|
+
* asks this in its own process. Null in the main checkout itself, outside a repository, in a submodule, and for a
|
|
56
|
+
* workspace that is not at its repository's root.
|
|
57
|
+
*/
|
|
58
|
+
export declare function mainCheckout(root: string): string | null;
|
|
59
|
+
export interface KnownPeaks {
|
|
60
|
+
peaks: ProgramPeaks;
|
|
61
|
+
/** Whose measurement it is: this checkout's, or the main checkout's of the same program. */
|
|
62
|
+
from: 'checkout' | 'main';
|
|
63
|
+
}
|
|
64
|
+
/** What is known of a program's memory: this checkout's measurements, else the main checkout's. */
|
|
65
|
+
export declare function knownPeaks(root: string, id: string): KnownPeaks | null;
|
|
66
|
+
/** The most any check of the workspace was measured to hold, in MB — this checkout's, else the main checkout's; undefined when nothing was ever measured. */
|
|
67
|
+
export declare function largestKnownPeakMb(root: string): number | undefined;
|
|
68
|
+
export interface NotedRun {
|
|
69
|
+
id: string;
|
|
70
|
+
/** Workspace-relative. */
|
|
71
|
+
tsconfig: string;
|
|
72
|
+
/** It started from a build info. */
|
|
73
|
+
warm: boolean;
|
|
74
|
+
/** The checkers it ran with; absent: the compiler's own number. */
|
|
75
|
+
checkers?: number;
|
|
76
|
+
peakMb: number;
|
|
77
|
+
peakHow: PeakHow;
|
|
78
|
+
at?: number;
|
|
79
|
+
env?: NodeJS.ProcessEnv;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Keep what a check that gave a verdict held. It starts from what is known — the main checkout's figures in a worktree
|
|
83
|
+
* that has none of its own — so the figure that put a program on fewer checkers comes along with the first measurement
|
|
84
|
+
* taken on fewer. Never throws: a checkout that cannot be written to still gets its check; null when nothing was kept.
|
|
85
|
+
*/
|
|
86
|
+
export declare function notePeak(root: string, run: NotedRun): ProgramPeaks | null;
|
|
87
|
+
export interface MemoryNeed {
|
|
88
|
+
/** What the turn waits for, in MB. The line takes the larger of this and its least amount. */
|
|
89
|
+
mb: number;
|
|
90
|
+
/** What it is made from: the program's last cold or warm check, the workspace's largest check, or nothing measured at all. */
|
|
91
|
+
basis: 'cold' | 'warm' | 'largest' | 'default';
|
|
92
|
+
/** The peak it is made from. */
|
|
93
|
+
peakMb?: number;
|
|
94
|
+
how?: PeakHow;
|
|
95
|
+
/** The figure is the main checkout's: this one has none of the program. */
|
|
96
|
+
fromMain?: true;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* What a check waits for before it starts (see the header). `warm`: it will start from a build info
|
|
100
|
+
* ({@link startsWarm}). `unmeasured`: what a program with no figure waits for — `largest`, the workspace's largest
|
|
101
|
+
* check or 4,096 MB (a check someone waits for); `floor`, nothing beyond the line's least amount (a service's own).
|
|
102
|
+
* Undefined: nothing says more than the line's least amount.
|
|
103
|
+
*/
|
|
104
|
+
export declare function memoryNeed(args: {
|
|
105
|
+
known: KnownPeaks | null;
|
|
106
|
+
warm: boolean;
|
|
107
|
+
unmeasured: 'largest' | 'floor';
|
|
108
|
+
largest?: () => number | undefined;
|
|
109
|
+
}): MemoryNeed | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* What a cold run over these programs asks the machine's queue for, in MB (plan § 8 and § Memory bounds, rule 2): it
|
|
112
|
+
* checks them one at a time, each on its own turn in the line, so the most it holds is the largest of them — each
|
|
113
|
+
* program's last cold check as it stands, one never measured cold taken as {@link memoryNeed} takes it. No margin: the
|
|
114
|
+
* queue adds its own reserve. 0 for no program.
|
|
115
|
+
*/
|
|
116
|
+
export declare function coldRunNeedMb(root: string, ids: readonly string[]): number;
|
|
117
|
+
/** Why a turn waits for what it does, for the line that says it is held: «its last cold check held 6000 MB (footprint), and a quarter more». */
|
|
118
|
+
export declare function needReason(need: MemoryNeed): string;
|
|
119
|
+
/**
|
|
120
|
+
* Will the next check of this program start from a build info? What `beginRun` decides (static-checks-record.ts
|
|
121
|
+
* `trustBuildInfo`), read here without touching anything: the trust record names this program under these inputs, and
|
|
122
|
+
* the build info is there.
|
|
123
|
+
*/
|
|
124
|
+
export declare function startsWarm(files: Pick<ProgramFiles, 'trust' | 'buildInfo'>, id: string, configKey: string): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Does this compiler take the flag? `tsgo <flag…> --version` prints its version and exits 0 with a flag it knows, and
|
|
127
|
+
* «error TS5023: Unknown compiler option» with one it does not (7.0.0-dev.20260707.2, about 50 ms). Asked of the binary
|
|
128
|
+
* once while the file is the one it was, as its version is.
|
|
129
|
+
*/
|
|
130
|
+
export declare function compilerTakes(bin: string, flag: readonly string[]): boolean;
|
|
131
|
+
/** What is already known of a compiler and a flag — undefined: it was never asked. Asks nothing. */
|
|
132
|
+
export declare function compilerTakesKnown(bin: string, flag: readonly string[]): boolean | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* {@link compilerTakes} for a caller whose thread must not be held: the dev checker runs INSIDE a service, and a
|
|
135
|
+
* `tsgo --version` that takes seconds on a starved machine would hold that service's event loop for as long. The
|
|
136
|
+
* same question, the same memory of the answer; undefined when the compiler did not answer (it is asked again).
|
|
137
|
+
*/
|
|
138
|
+
export declare function askCompilerTakes(bin: string, flag: readonly string[]): Promise<boolean | undefined>;
|
|
139
|
+
export interface CheckerChoice {
|
|
140
|
+
/** What the compiler is given to bound its memory: `--checkers 2`, `--singleThreaded`, or nothing. */
|
|
141
|
+
args: string[];
|
|
142
|
+
/** The checkers the check runs with; absent: the compiler's own number. */
|
|
143
|
+
checkers?: number;
|
|
144
|
+
/** The flag that was called for and that this compiler does not take: the check runs without it, and whoever runs it says so. */
|
|
145
|
+
untaken?: string;
|
|
146
|
+
}
|
|
147
|
+
/** How many checkers the next check of a program runs with (see the header). `takes`: asks the compiler; default {@link compilerTakes}. */
|
|
148
|
+
export declare function chooseCheckers(args: {
|
|
149
|
+
peaks: ProgramPeaks | null;
|
|
150
|
+
bin: string;
|
|
151
|
+
env?: NodeJS.ProcessEnv;
|
|
152
|
+
takes?: (flag: readonly string[]) => boolean;
|
|
153
|
+
}): CheckerChoice;
|
|
154
|
+
/** The flag the next check of a program is to be given, before the compiler is asked whether it takes it — none: its own number of checkers. */
|
|
155
|
+
export declare function wantedFlag(args: {
|
|
156
|
+
peaks: ProgramPeaks | null;
|
|
157
|
+
env?: NodeJS.ProcessEnv;
|
|
158
|
+
}): string[] | undefined;
|
|
159
|
+
/** What is said, once, when the compiler does not take a flag its check was to be given. */
|
|
160
|
+
export declare function untakenText(flag: string, compiler: string): string;
|
|
161
|
+
/** One process's resident size, in MB — `ps -o rss=`; undefined when it is gone, or ps does not answer. */
|
|
162
|
+
export declare function psRssMb(pid: number): Promise<number | undefined>;
|
|
163
|
+
export interface RssSampler {
|
|
164
|
+
/** Stop looking. The most that was seen, in MB — a lower bound of the peak; undefined when nothing was. */
|
|
165
|
+
stop(): number | undefined;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Look at a running check's resident size now and every `periodMs` (500), and keep the most seen: the peak of a check
|
|
169
|
+
* that cannot be wrapped in `time` (the dev checker — see tsgo-check-plugin.ts). One `ps` per look, and nothing left
|
|
170
|
+
* behind: the timer never keeps a process alive, and a look still out when it stops is not counted.
|
|
171
|
+
*/
|
|
172
|
+
export declare function sampleRss(pid: number, opts?: {
|
|
173
|
+
periodMs?: number;
|
|
174
|
+
read?: (pid: number) => Promise<number | undefined>;
|
|
175
|
+
}): RssSampler;
|
|
176
|
+
/**
|
|
177
|
+
* What a held turn is told, the same wherever it is said: «812 MB free, it waits for 2048 MB
|
|
178
|
+
* (LENSMCP_TYPECHECK_MIN_FREE_MB)» for the line's least amount — and, when it waits for its own check's need, why.
|
|
179
|
+
* `hold` is the line's (typecheck-queue.ts `MemoryHold`): what it waits for is the line's word, which never asks for
|
|
180
|
+
* more than the machine has.
|
|
181
|
+
*/
|
|
182
|
+
export declare function holdText(hold: {
|
|
183
|
+
availableMb: number;
|
|
184
|
+
minFreeMb: number;
|
|
185
|
+
own?: true;
|
|
186
|
+
promisedMb?: number;
|
|
187
|
+
}, need: MemoryNeed | undefined): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var m=Object.defineProperty;var i=(e,r)=>m(e,"name",{value:r,configurable:!0});var f=Object.defineProperty,o=i((e,r)=>f(e,"name",{value:r,configurable:!0}),"o");Object.defineProperty(exports,"__esModule",{value:!0}),exports.REDUCED_CHECKERS=exports.DEFAULT_CHECKERS_ABOVE_MB=exports.DEFAULT_UNMEASURED_MB=exports.PEAK_MARGIN=exports.PEAKS_SCHEMA=void 0,exports.typecheckCheckersAboveMb=typecheckCheckersAboveMb,exports.typecheckSingleThreaded=typecheckSingleThreaded,exports.peaksFile=peaksFile,exports.readPeaks=readPeaks,exports.mainCheckout=mainCheckout,exports.knownPeaks=knownPeaks,exports.largestKnownPeakMb=largestKnownPeakMb,exports.notePeak=notePeak,exports.memoryNeed=memoryNeed,exports.coldRunNeedMb=coldRunNeedMb,exports.needReason=needReason,exports.startsWarm=startsWarm,exports.compilerTakes=compilerTakes,exports.compilerTakesKnown=compilerTakesKnown,exports.askCompilerTakes=askCompilerTakes,exports.chooseCheckers=chooseCheckers,exports.wantedFlag=wantedFlag,exports.untakenText=untakenText,exports.psRssMb=psRssMb,exports.sampleRss=sampleRss,exports.holdText=holdText;const tslib_1=require("tslib"),node_child_process_1=require("node:child_process"),node_crypto_1=require("node:crypto"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path")),static_checks_record_1=require("./static-checks-record");exports.PEAKS_SCHEMA=1,exports.PEAK_MARGIN=1.25,exports.DEFAULT_UNMEASURED_MB=4096,exports.DEFAULT_CHECKERS_ABOVE_MB=4096,exports.REDUCED_CHECKERS=2;function typecheckCheckersAboveMb(e=process.env){const r=e.LENSMCP_TYPECHECK_CHECKERS_ABOVE_MB,t=Number(r);return r!==void 0&&r.trim()!==""&&Number.isFinite(t)&&t>=0?Math.round(t):exports.DEFAULT_CHECKERS_ABOVE_MB}i(typecheckCheckersAboveMb,"typecheckCheckersAboveMb"),o(typecheckCheckersAboveMb,"typecheckCheckersAboveMb");function typecheckSingleThreaded(e=process.env){return/^(1|true|on|yes)$/i.test((e.LENSMCP_TYPECHECK_SINGLE_THREADED??"").trim())}i(typecheckSingleThreaded,"typecheckSingleThreaded"),o(typecheckSingleThreaded,"typecheckSingleThreaded");const isObj=o(e=>!!e&&typeof e=="object"&&!Array.isArray(e),"isObj");function readJson(e){try{return JSON.parse(fs.readFileSync(e,"utf8"))}catch{return}}i(readJson,"readJson"),o(readJson,"readJson");function writeAtomic(e,r){fs.mkdirSync(path.dirname(e),{recursive:!0});const t=`${e}.${process.pid}.${(0,node_crypto_1.randomBytes)(4).toString("hex")}.tmp`;try{fs.writeFileSync(t,r),fs.renameSync(t,e)}catch(n){throw fs.rmSync(t,{force:!0}),n}}i(writeAtomic,"writeAtomic"),o(writeAtomic,"writeAtomic");const PEAKS_SUFFIX=".peaks.json";function peaksFile(e,r){return path.join((0,static_checks_record_1.typecheckRecordsDir)(e),`${r}${PEAKS_SUFFIX}`)}i(peaksFile,"peaksFile"),o(peaksFile,"peaksFile");function peakOf(e){if(!isObj(e)||typeof e.mb!="number"||!(e.mb>0)||typeof e.at!="number")return;const r=e.how==="footprint"||e.how==="maxrss"||e.how==="sampled"?e.how:void 0;if(r)return{mb:e.mb,how:r,...typeof e.checkers=="number"&&e.checkers>=1?{checkers:e.checkers}:{},at:e.at}}i(peakOf,"peakOf"),o(peakOf,"peakOf");function peaksOf(e,r){if(!isObj(e)||e.schema!==exports.PEAKS_SCHEMA||typeof e.id!="string"||r!==void 0&&e.id!==r)return null;const t=peakOf(e.cold),n=peakOf(e.warm),s=isObj(e.full)&&typeof e.full.mb=="number"&&e.full.mb>0?{mb:e.full.mb,at:typeof e.full.at=="number"?e.full.at:0}:void 0;return{schema:exports.PEAKS_SCHEMA,id:e.id,tsconfig:typeof e.tsconfig=="string"?e.tsconfig:"",...t?{cold:t}:{},...n?{warm:n}:{},...s?{full:s}:{}}}i(peaksOf,"peaksOf"),o(peaksOf,"peaksOf");function readPeaks(e,r){return peaksOf(readJson(peaksFile(e,r)),r)}i(readPeaks,"readPeaks"),o(readPeaks,"readPeaks");const mains=new Map;function mainCheckout(e){const r=path.resolve(e),t=mains.get(r);if(t!==void 0)return t;let n=null;try{const s=path.join(r,".git"),c=fs.statSync(s).isFile()?/^gitdir:\s*(.+)$/m.exec(fs.readFileSync(s,"utf8"))?.[1]?.trim():void 0;if(c){const a=path.resolve(r,c),u=path.resolve(a,fs.readFileSync(path.join(a,"commondir"),"utf8").trim()),l=path.basename(u)===".git"?path.dirname(u):null;l&&l!==r&&fs.statSync(l).isDirectory()&&(n=l)}}catch{n=null}return mains.size>64&&mains.clear(),mains.set(r,n),n}i(mainCheckout,"mainCheckout"),o(mainCheckout,"mainCheckout");function knownPeaks(e,r){const t=readPeaks(e,r);if(t)return{peaks:t,from:"checkout"};const n=mainCheckout(e),s=n?readPeaks(n,r):null;return s?{peaks:s,from:"main"}:null}i(knownPeaks,"knownPeaks"),o(knownPeaks,"knownPeaks");function largestIn(e){const r=(0,static_checks_record_1.typecheckRecordsDir)(e);let t;try{t=fs.readdirSync(r).filter(s=>s.endsWith(PEAKS_SUFFIX))}catch{return}let n;for(const s of t){const c=peaksOf(readJson(path.join(r,s))),a=Math.max(c?.cold?.mb??0,c?.warm?.mb??0);a>0&&(n===void 0||a>n)&&(n=a)}return n}i(largestIn,"largestIn"),o(largestIn,"largestIn");function largestKnownPeakMb(e){const r=largestIn(e);if(r!==void 0)return r;const t=mainCheckout(e);return t?largestIn(t):void 0}i(largestKnownPeakMb,"largestKnownPeakMb"),o(largestKnownPeakMb,"largestKnownPeakMb");function notePeak(e,r){if(!Number.isFinite(r.peakMb)||r.peakMb<=0)return null;try{const t=r.at??Date.now(),n=knownPeaks(e,r.id)?.peaks,s={mb:Math.max(1,Math.round(r.peakMb)),how:r.peakHow,...r.checkers!==void 0?{checkers:r.checkers}:{},at:t},c={schema:exports.PEAKS_SCHEMA,id:r.id,tsconfig:r.tsconfig,...n?.cold?{cold:n.cold}:{},...n?.warm?{warm:n.warm}:{},...n?.full?{full:n.full}:{}};return r.warm?c.warm=s:c.cold=s,r.checkers===void 0?(!r.warm||!c.full||s.mb>c.full.mb)&&(c.full={mb:s.mb,at:t}):!r.warm&&s.mb<typecheckCheckersAboveMb(r.env)/2&&delete c.full,writeAtomic(peaksFile(e,r.id),JSON.stringify(c)),c}catch{return null}}i(notePeak,"notePeak"),o(notePeak,"notePeak");function memoryNeed(e){const r=e.known?.peaks,t=o((a,u)=>({mb:Math.ceil(a.mb*exports.PEAK_MARGIN),basis:u,peakMb:a.mb,how:a.how,...e.known?.from==="main"?{fromMain:!0}:{}}),"fromPeak");if(e.warm&&r?.warm)return t(r.warm,"warm");if(r?.cold)return t(r.cold,"cold");const n=r?.warm?t(r.warm,"warm"):void 0;if(e.unmeasured==="floor")return n;const s=e.largest?.(),c=s!==void 0?{mb:s,basis:"largest",peakMb:s}:{mb:exports.DEFAULT_UNMEASURED_MB,basis:"default"};return n&&n.mb>=c.mb?n:c}i(memoryNeed,"memoryNeed"),o(memoryNeed,"memoryNeed");function coldRunNeedMb(e,r){let t=null,n=0;for(const s of r){const c=knownPeaks(e,s)?.peaks;let a=c?.cold?.mb;a===void 0&&(t===null&&(t=largestKnownPeakMb(e)),a=Math.max(c?.warm?.mb??0,t??exports.DEFAULT_UNMEASURED_MB)),a>n&&(n=a)}return n}i(coldRunNeedMb,"coldRunNeedMb"),o(coldRunNeedMb,"coldRunNeedMb");function needReason(e){const r=e.fromMain?" in the main checkout":"";switch(e.basis){case"cold":return`its last cold check held ${e.peakMb} MB (${e.how})${r}, and a quarter more`;case"warm":return`its last check held ${e.peakMb} MB (${e.how})${r}, and a quarter more`;case"largest":return`it was never measured, and the largest check this workspace knows held ${e.peakMb} MB`;case"default":return`it was never measured, and no check of this workspace was: ${exports.DEFAULT_UNMEASURED_MB} MB`}}i(needReason,"needReason"),o(needReason,"needReason");function startsWarm(e,r,t){const n=readJson(e.trust);return isObj(n)&&n.schema===static_checks_record_1.RECORD_SCHEMA&&n.id===r&&n.configKey===t&&fs.existsSync(e.buildInfo)}i(startsWarm,"startsWarm"),o(startsWarm,"startsWarm");const taken=new Map;function compilerTakes(e,r){const t=takenKey(e,r),n=taken.get(t);if(n!==void 0)return n;let s;try{(0,node_child_process_1.execFileSync)(e,[...r,"--version"],{encoding:"utf8",timeout:ASK_TIMEOUT_MS,stdio:["ignore","pipe","ignore"]}),s=!0}catch(c){if(!REFUSED.test(String(c.stdout??"")))return!1;s=!1}return remember(t,s),s}i(compilerTakes,"compilerTakes"),o(compilerTakes,"compilerTakes");const ASK_TIMEOUT_MS=15e3,REFUSED=/TS5023|Unknown compiler option/;function takenKey(e,r){let t;try{const n=fs.statSync(e);t=`${n.mtimeMs}:${n.size}:${n.ino}`}catch{t=""}return`${e}\0${t}\0${r.join(" ")}`}i(takenKey,"takenKey"),o(takenKey,"takenKey");function remember(e,r){taken.size>64&&taken.clear(),taken.set(e,r)}i(remember,"remember"),o(remember,"remember");function compilerTakesKnown(e,r){return taken.get(takenKey(e,r))}i(compilerTakesKnown,"compilerTakesKnown"),o(compilerTakesKnown,"compilerTakesKnown");const asking=new Map;function askCompilerTakes(e,r){const t=takenKey(e,r),n=taken.get(t);if(n!==void 0)return Promise.resolve(n);const s=asking.get(t);if(s)return s;const c=new Promise(a=>{(0,node_child_process_1.execFile)(e,[...r,"--version"],{encoding:"utf8",timeout:ASK_TIMEOUT_MS},(u,l)=>{asking.delete(t),u?REFUSED.test(String(l??""))&&remember(t,!1):remember(t,!0),a(taken.get(t))})});return asking.set(t,c),c}i(askCompilerTakes,"askCompilerTakes"),o(askCompilerTakes,"askCompilerTakes");function chooseCheckers(e){const r=wantedFlag(e);return r?(e.takes??(t=>compilerTakes(e.bin,t)))(r)?{args:[...r],checkers:r[0]==="--singleThreaded"?1:exports.REDUCED_CHECKERS}:{args:[],untaken:r[0]}:{args:[]}}i(chooseCheckers,"chooseCheckers"),o(chooseCheckers,"chooseCheckers");function wantedFlag(e){const r=e.env??process.env;if(typecheckSingleThreaded(r))return["--singleThreaded"];const t=typecheckCheckersAboveMb(r);if(!(t<=0||!e.peaks?.full||e.peaks.full.mb<=t))return["--checkers",String(exports.REDUCED_CHECKERS)]}i(wantedFlag,"wantedFlag"),o(wantedFlag,"wantedFlag");function untakenText(e,r){return`${r} does not take ${e}: the check runs with the compiler's own checkers, and waits for what that holds`}i(untakenText,"untakenText"),o(untakenText,"untakenText");function psRssMb(e){return new Promise(r=>{(0,node_child_process_1.execFile)("ps",["-o","rss=","-p",String(e)],{encoding:"utf8",timeout:5e3},(t,n)=>{const s=Number(String(n??"").trim());r(!t&&Number.isFinite(s)&&s>0?s/1024:void 0)})})}i(psRssMb,"psRssMb"),o(psRssMb,"psRssMb");function sampleRss(e,r={}){const t=r.read??psRssMb;let n,s=!1;const c=o(()=>{t(e).then(u=>{!s&&u!==void 0&&(n===void 0||u>n)&&(n=u)},()=>{})},"look");c();const a=setInterval(c,r.periodMs??500);return a.unref?.(),{stop(){return s=!0,clearInterval(a),n===void 0?void 0:Math.max(1,Math.round(n))}}}i(sampleRss,"sampleRss"),o(sampleRss,"sampleRss");function holdText(e,r){const t=`${e.availableMb} MB free${e.promisedMb?`, ${e.promisedMb} MB of it for the checks ahead of it`:""}`;return!e.own||!r?`${t}, it waits for ${e.minFreeMb} MB (LENSMCP_TYPECHECK_MIN_FREE_MB)`:`${t}, it waits for ${e.minFreeMb} MB \u2014 ${needReason(r)}${e.minFreeMb<r.mb?", as far as this machine has it":""}`}i(holdText,"holdText"),o(holdText,"holdText");
|
package/typecheck-queue.d.ts
CHANGED
|
@@ -1,15 +1,40 @@
|
|
|
1
1
|
export interface QueueTicket {
|
|
2
2
|
/** Give the slot back, or leave the line. Idempotent. */
|
|
3
3
|
release(): void;
|
|
4
|
+
/**
|
|
5
|
+
* After its turn: may its holder start one more check on this slot without asking again? Only while nobody else is
|
|
6
|
+
* in the line, memory is not short for THAT check (`needMb`, as {@link QueueHooks.needMb}), and the ticket is young
|
|
7
|
+
* — else the holder gives the slot back and asks again, so whoever waits gets a turn and the hold is looked at
|
|
8
|
+
* before every check. A check that needs more than this ticket said it does asks again too: the ticket's name is
|
|
9
|
+
* what the line reads. Absent: ask again for every check.
|
|
10
|
+
*/
|
|
11
|
+
mayContinue?(needMb?: number): boolean;
|
|
4
12
|
}
|
|
5
|
-
/** What a caller in line is told besides its turn. */
|
|
13
|
+
/** What a caller in line is told besides its turn — and what it tells the line. */
|
|
6
14
|
export interface QueueHooks {
|
|
7
|
-
/** Its turn came, and is held: the machine has less memory free than
|
|
15
|
+
/** Its turn came, and is held: the machine has less memory free than this check waits for. Called once per ticket. */
|
|
8
16
|
onHold?(hold: MemoryHold): void;
|
|
17
|
+
/** Someone is waiting for this check's answer: a ticket nobody waits for lets it pass (see the header). */
|
|
18
|
+
waited?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The memory this check needs free before it starts, in MB — what its program's last check held, and a margin
|
|
21
|
+
* (typecheck-memory.ts). Its turn waits for this when it is more than the line's least amount. Absent: the least.
|
|
22
|
+
*/
|
|
23
|
+
needMb?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Nobody asked for this check: the lens server started it by itself (see the header). It lets every other check
|
|
26
|
+
* pass, and no held turn lets it pass. Never together with `waited`.
|
|
27
|
+
*/
|
|
28
|
+
background?: boolean;
|
|
9
29
|
}
|
|
10
30
|
export interface MemoryHold {
|
|
11
31
|
availableMb: number;
|
|
32
|
+
/** What this turn waits for: the line's least amount, or its own check's need when that is more. */
|
|
12
33
|
minFreeMb: number;
|
|
34
|
+
/** It waits for its own check's need — more than the line's least amount. */
|
|
35
|
+
own?: true;
|
|
36
|
+
/** Of what is free, what the tickets ahead of it in the slots said they need (more than one slot). */
|
|
37
|
+
promisedMb?: number;
|
|
13
38
|
}
|
|
14
39
|
/** Join the line; `onTurn` is called once, when this caller may run. */
|
|
15
40
|
export type TypecheckQueue = (label: string, onTurn: () => void, hooks?: QueueHooks) => QueueTicket;
|
|
@@ -29,10 +54,12 @@ export interface MachineQueueOptions {
|
|
|
29
54
|
pid?: number;
|
|
30
55
|
isAlive?: (pid: number) => boolean;
|
|
31
56
|
now?: () => number;
|
|
32
|
-
/**
|
|
57
|
+
/** The least a turn waits for: it is held while less than this is free (MB); 0 holds nothing. Default {@link typecheckMinFreeMb}. */
|
|
33
58
|
minFreeMb?: number;
|
|
34
59
|
/** The memory the OS can still hand out, in MB; undefined when it cannot tell. Default {@link availableMemoryMb}. */
|
|
35
60
|
availableMb?: () => number | undefined;
|
|
61
|
+
/** All the memory this machine — or its container — has, in MB; undefined when it cannot tell. Default {@link machineMemoryMb}. */
|
|
62
|
+
totalMb?: () => number | undefined;
|
|
36
63
|
/** How often a held turn looks at the memory again. */
|
|
37
64
|
holdPollMs?: number;
|
|
38
65
|
}
|
|
@@ -48,6 +75,17 @@ export declare function typecheckMinFreeMb(env?: NodeJS.ProcessEnv): number;
|
|
|
48
75
|
* few hundred MB on a busy machine that has gigabytes to give. A Node without it cannot tell: undefined, nothing held.
|
|
49
76
|
*/
|
|
50
77
|
export declare function availableMemoryMb(): number | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* All the memory there is, in MB: a container's limit under cgroups (`process.constrainedMemory()`, where it names
|
|
80
|
+
* one), else the machine's. What no turn can ever wait for more than.
|
|
81
|
+
*/
|
|
82
|
+
export declare function machineMemoryMb(): number | undefined;
|
|
83
|
+
/** Is someone waiting for this ticket's check? Said in its name. */
|
|
84
|
+
export declare const isWaitedTicket: (name: string) => boolean;
|
|
85
|
+
/** Did nobody ask for this ticket's check — a re-check the lens server started by itself? Said in its name. */
|
|
86
|
+
export declare const isBackgroundTicket: (name: string) => boolean;
|
|
87
|
+
/** What a ticket's check needs free beyond the line's least amount, in MB — said in its name; undefined when it says none. */
|
|
88
|
+
export declare function ticketNeedMb(name: string): number | undefined;
|
|
51
89
|
/**
|
|
52
90
|
* The line, oldest first. A ticket whose owner is dead — or that has sat past `maxAgeMs` — is
|
|
53
91
|
* deleted on the way, so a crashed service never holds a slot.
|
package/typecheck-queue.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var U=Object.defineProperty;var u=(t,e)=>U(t,"name",{value:e,configurable:!0});var I=Object.defineProperty,n=u((t,e)=>I(t,"name",{value:e,configurable:!0}),"n");Object.defineProperty(exports,"__esModule",{value:!0}),exports.immediateQueue=exports.isBackgroundTicket=exports.isWaitedTicket=void 0,exports.typecheckQueueDir=typecheckQueueDir,exports.typecheckSlots=typecheckSlots,exports.typecheckMinFreeMb=typecheckMinFreeMb,exports.availableMemoryMb=availableMemoryMb,exports.machineMemoryMb=machineMemoryMb,exports.ticketNeedMb=ticketNeedMb,exports.liveTickets=liveTickets,exports.machineTypecheckQueue=machineTypecheckQueue;const tslib_1=require("tslib"),fs=tslib_1.__importStar(require("node:fs")),os=tslib_1.__importStar(require("node:os")),path=tslib_1.__importStar(require("node:path")),TICKET_SUFFIX=".ticket",WAITED_MARK="-w",NEED_MARK=/-M(\d+)(?:-w)?\.ticket$/,BACKGROUND_MARK=/-B(?:-M\d+)?\.ticket$/,MAX_STEP_BACK_MS=5*6e4,MAX_KEEP_MS=6e4,DEFAULT_POLL_MS=250,DEFAULT_SETTLE_MS=120,DEFAULT_MAX_AGE_MS=15*6e4,MAX_SLOTS=8,DEFAULT_HOLD_POLL_MS=2e3,DEFAULT_MIN_FREE_MB=2048;function typecheckQueueDir(t=process.env){return path.join(t.LENSMCP_HOME||os.homedir(),".lensmcp","typecheck-queue")}u(typecheckQueueDir,"typecheckQueueDir"),n(typecheckQueueDir,"typecheckQueueDir");function typecheckSlots(t=process.env){const e=Number(t.LENSMCP_TYPECHECK_CONCURRENCY);return Number.isInteger(e)&&e>=1?Math.min(e,MAX_SLOTS):1}u(typecheckSlots,"typecheckSlots"),n(typecheckSlots,"typecheckSlots");function typecheckMinFreeMb(t=process.env){const e=t.LENSMCP_TYPECHECK_MIN_FREE_MB,c=Number(e);return e!==void 0&&e.trim()!==""&&Number.isFinite(c)&&c>=0?Math.round(c):DEFAULT_MIN_FREE_MB}u(typecheckMinFreeMb,"typecheckMinFreeMb"),n(typecheckMinFreeMb,"typecheckMinFreeMb");function availableMemoryMb(){const t=process.availableMemory;if(typeof t=="function")try{const e=t.call(process);return Number.isFinite(e)&&e>0?Math.round(e/(1024*1024)):void 0}catch{return}}u(availableMemoryMb,"availableMemoryMb"),n(availableMemoryMb,"availableMemoryMb");function machineMemoryMb(){const t=os.totalmem();let e;try{e=process.constrainedMemory?.()??0}catch{e=0}const c=e>0&&e<t?e:t;return Number.isFinite(c)&&c>0?Math.round(c/(1024*1024)):void 0}u(machineMemoryMb,"machineMemoryMb"),n(machineMemoryMb,"machineMemoryMb");function pidAlive(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}u(pidAlive,"pidAlive"),n(pidAlive,"pidAlive");const ticketPid=n(t=>{const e=Number(t.split("-")[0]);return Number.isInteger(e)&&e>0?e:void 0},"ticketPid"),isWaitedTicket=n(t=>t.endsWith(`${WAITED_MARK}${TICKET_SUFFIX}`),"isWaitedTicket");exports.isWaitedTicket=isWaitedTicket;const isBackgroundTicket=n(t=>BACKGROUND_MARK.test(t),"isBackgroundTicket");exports.isBackgroundTicket=isBackgroundTicket;function ticketNeedMb(t){const e=Number(NEED_MARK.exec(t)?.[1]);return Number.isInteger(e)&&e>0?e:void 0}u(ticketNeedMb,"ticketNeedMb"),n(ticketNeedMb,"ticketNeedMb");function liveTickets(t,e={}){const c=e.isAlive??pidAlive,y=(e.now??Date.now)(),v=e.maxAgeMs??DEFAULT_MAX_AGE_MS;let f;try{f=fs.readdirSync(t).filter(s=>s.endsWith(TICKET_SUFFIX))}catch{return[]}const a=[];for(const s of f){const M=path.join(t,s);let _;try{_=fs.statSync(M,{bigint:!0})}catch{continue}const T=ticketPid(s);if(T===void 0||!c(T)||y-Number(_.mtimeMs)>v){try{fs.unlinkSync(M)}catch{}continue}a.push({name:s,at:_.mtimeNs})}return a.sort((s,M)=>s.at<M.at?-1:s.at>M.at?1:s.name<M.name?-1:s.name>M.name?1:0),a.map(s=>s.name)}u(liveTickets,"liveTickets"),n(liveTickets,"liveTickets");let ticketSeq=0;function machineTypecheckQueue(t={}){const e=t.dir??typecheckQueueDir(),c=Math.max(1,t.slots??typecheckSlots()),y=t.pollMs??DEFAULT_POLL_MS,v=t.settleMs??DEFAULT_SETTLE_MS,f=t.pid??process.pid,a=t.minFreeMb??typecheckMinFreeMb(),s=t.availableMb??availableMemoryMb,M=t.totalMb??machineMemoryMb,_=t.holdPollMs??DEFAULT_HOLD_POLL_MS,T=n(()=>liveTickets(e,t),"scan"),C=n(i=>{if(a<=0)return 0;if(i===void 0||!Number.isFinite(i)||i<=a)return a;const r=M();return Math.round(r===void 0?i:Math.max(a,Math.min(i,r-a)))},"wantedMb"),L=n(i=>{if(a<=0)return;const r=s();if(r!==void 0)return{free:r,promised:i.reduce((p,S)=>p+(ticketNeedMb(S)??0),0)}},"roomFor"),P=n((i,r)=>{if(!(!r||i<=0||r.free-r.promised>=i))return{availableMb:r.free,minFreeMb:i,...i>a?{own:!0}:{},...r.promised>0?{promisedMb:r.promised}:{}}},"holdOf"),B=n((i,r)=>!r||r.free-r.promised>=Math.max(a,ticketNeedMb(i)??0),"fits");return(i,r,p)=>{const S=p?.waited===!0,F=p?.background===!0&&!S,E=C(p?.needMb),R=E>a?`-M${E}`:"",N=`${f}-${(ticketSeq++).toString(36)}-${Math.random().toString(36).slice(2,8)}${F?"-B":""}${R}${S?WAITED_MARK:""}${TICKET_SUFFIX}`,D=path.join(e,N),O=Date.now();let h=!1,x=!1,$=!1,A;const g=n(()=>{h||x||(x=!0,r())},"turn"),K=n(()=>{try{return fs.mkdirSync(e,{recursive:!0}),fs.writeFileSync(D,JSON.stringify({pid:f,label:i,at:(t.now??Date.now)()})),!0}catch{return!1}},"write"),k=n(o=>{A=setTimeout(Q,o),A.unref?.()},"later"),w=n(o=>{try{const m=o[o.length-1],d=m&&m!==N?fs.statSync(path.join(e,m)).mtimeMs:0,b=new Date(Math.floor(Math.max(d,Date.now()))+2);return fs.utimesSync(D,b,b),!0}catch{return!1}},"stepBack");function Q(){if(h||x)return;const o=T(),m=o.indexOf(N);if(m===-1)return K()?k(v):g();if(m<c){const d=L(o.slice(0,m)),b=P(E,d);if(F&&o.slice(c).some(l=>!(0,exports.isBackgroundTicket)(l))&&w(o)||!S&&Date.now()-O<MAX_STEP_BACK_MS&&o.slice(c).some(l=>(0,exports.isWaitedTicket)(l)&&(b!==void 0||B(l,d)))&&w(o))return k(y);if(!b)return g();if(!$){$=!0;try{p?.onHold?.(b)}catch{}}return o.slice(m+1).some(l=>(F||!(0,exports.isBackgroundTicket)(l))&&B(l,d))&&w(o)?k(y):k(_)}k(y)}return u(Q,"R"),n(Q,"look"),K()?(k(v),{release(){if(!h){h=!0,A&&clearTimeout(A);try{fs.unlinkSync(D)}catch{}}},mayContinue(o){if(h||!x||Date.now()-O>=MAX_KEEP_MS)return!1;const m=C(o);if(c>1&&m>E)return!1;const d=T();return d.length===1&&d[0]===N&&!P(m,L([]))}}):(g(),{release(){h=!0}})}}u(machineTypecheckQueue,"machineTypecheckQueue"),n(machineTypecheckQueue,"machineTypecheckQueue");const immediateQueue=n((t,e)=>(e(),{release(){},mayContinue:n(()=>!0,"mayContinue")}),"immediateQueue");exports.immediateQueue=immediateQueue;
|