@lensmcp/core 1.25.47 → 1.25.49
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/lib/capture-off.d.ts +50 -0
- package/lib/capture-off.js +1 -0
- package/lib/lens-dir.d.ts +10 -0
- package/lib/lens-dir.js +9 -1
- package/lib/settings.d.ts +117 -0
- package/lib/settings.js +2 -0
- package/package.json +12 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the project records no longer (planning/modules/01-split.md S3), as every writer to the bus reads it:
|
|
3
|
+
* `.lensmcp/capture.json` → `off`, beside the bus file, written by the lens from `lensmcp.json` and the feature cards
|
|
4
|
+
* (servers/lensmcp-mcp project/capture-sync.ts). Each entry is an event `source` (`db`) or `source:kind`
|
|
5
|
+
* (`lens:db-dropped`): an event that matches one is not written, and the lens's own ingest drops it too.
|
|
6
|
+
*
|
|
7
|
+
* Read at most every two seconds — a stat, and the file only when it changed — so turning a feature off reaches every
|
|
8
|
+
* running service within seconds, with no restart. No file, or one it cannot read: nothing is off, as before.
|
|
9
|
+
*
|
|
10
|
+
* `parts` (the Map, 02-settings ST3): each part's capabilities its exceptions turn off, by the part's name — the Nx
|
|
11
|
+
* project a service or a dev server runs as (`LENSMCP_PROJECT`). A process asks of its own: `off.part(PROJECT, 'observe')`.
|
|
12
|
+
*
|
|
13
|
+
* Node-only and dependency-free: the caller injects the fs primitives, so the fs-tap-safe pristine references in
|
|
14
|
+
* `node-instrumentation/emit.ts` keep working. The same arrangement as `./bus-rotation`.
|
|
15
|
+
*/
|
|
16
|
+
export interface CaptureFs {
|
|
17
|
+
statSync(path: string): {
|
|
18
|
+
mtimeMs: number;
|
|
19
|
+
};
|
|
20
|
+
readFileSync(path: string, encoding: 'utf8'): string;
|
|
21
|
+
}
|
|
22
|
+
/** The file beside the bus: `<dir of events.jsonl>/capture.json`. */
|
|
23
|
+
export declare const CAPTURE_FILE_NAME = "capture.json";
|
|
24
|
+
/** How long a read holds. */
|
|
25
|
+
export declare const CAPTURE_OFF_EVERY_MS = 2000;
|
|
26
|
+
/** The `off` list of a capture file's text: the strings in it, nothing when it says none. */
|
|
27
|
+
export declare function readCaptureOff(text: string): Set<string>;
|
|
28
|
+
/** The `off` list and the `parts` of a capture file's text — nothing of either it cannot read. */
|
|
29
|
+
export declare function readCapture(text: string): {
|
|
30
|
+
off: Set<string>;
|
|
31
|
+
parts: Map<string, Set<string>>;
|
|
32
|
+
};
|
|
33
|
+
/** Whether an event is one of `off`'s: its source, or its source and `raw.kind`. */
|
|
34
|
+
export declare function isRecordOff(off: ReadonlySet<string>, source: unknown, kind: unknown): boolean;
|
|
35
|
+
export interface CaptureOff {
|
|
36
|
+
/** Whether an event of this source and kind is off now (as of at most two seconds ago). */
|
|
37
|
+
(source: unknown, kind?: unknown): boolean;
|
|
38
|
+
/** Whether a capability is off on one part (`observe` on the project this process runs as). */
|
|
39
|
+
part(name: string | undefined, capability: string): boolean;
|
|
40
|
+
/** Forget the last read: the next ask reads the file. */
|
|
41
|
+
reset(): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A reader of one capture file. `file` is asked on each read, so a writer whose bus file is resolved late (from the
|
|
45
|
+
* environment) still finds it.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createCaptureOff(file: () => string | undefined, fs: CaptureFs, opts?: {
|
|
48
|
+
everyMs?: number;
|
|
49
|
+
now?: () => number;
|
|
50
|
+
}): CaptureOff;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var d=Object.defineProperty;var s=(r,t)=>d(r,"name",{value:t,configurable:!0});var S=Object.defineProperty,a=s((r,t)=>S(r,"name",{value:t,configurable:!0}),"s");export const CAPTURE_FILE_NAME="capture.json",CAPTURE_OFF_EVERY_MS=2e3;export function readCaptureOff(r){return readCapture(r).off}s(readCaptureOff,"readCaptureOff"),a(readCaptureOff,"readCaptureOff");export function readCapture(r){const t=new Map;try{const e=JSON.parse(r);if(e.parts&&typeof e.parts=="object"&&!Array.isArray(e.parts))for(const[o,p]of Object.entries(e.parts))Array.isArray(p)&&t.set(o,new Set(p.filter(c=>typeof c=="string")));return{off:new Set(Array.isArray(e.off)?e.off.filter(o=>typeof o=="string"&&o.length>0):[]),parts:t}}catch{return{off:new Set,parts:t}}}s(readCapture,"readCapture"),a(readCapture,"readCapture");export function isRecordOff(r,t,e){return!r.size||typeof t!="string"?!1:r.has(t)||typeof e=="string"&&r.has(`${t}:${e}`)}s(isRecordOff,"isRecordOff"),a(isRecordOff,"isRecordOff");export function createCaptureOff(r,t,e={}){const o=e.everyMs??2e3,p=e.now??(()=>Date.now());let c=-1/0,u,y=new Set,h=new Map;const i=a(()=>{u=void 0,y=new Set,h=new Map},"none"),O=a(n=>{c=n;const f=r();if(!f)return i();let l;try{l=t.statSync(f).mtimeMs}catch{return i()}if(l!==u)try{({off:y,parts:h}=readCapture(t.readFileSync(f,"utf8"))),u=l}catch{i()}},"refresh"),A=a(()=>{const n=p();n-c>=o&&O(n)},"look"),w=a(((n,f)=>{try{return A(),isRecordOff(y,n,f)}catch{return!1}}),"ask");return w.part=(n,f)=>{try{return A(),!!n&&h.get(n)?.has(f)===!0}catch{return!1}},w.reset=()=>{c=-1/0,i()},w}s(createCaptureOff,"createCaptureOff"),a(createCaptureOff,"createCaptureOff");
|
package/lib/lens-dir.d.ts
CHANGED
|
@@ -26,3 +26,13 @@
|
|
|
26
26
|
export declare const LENS_SHARED_DIRS: readonly string[];
|
|
27
27
|
/** The .gitignore lines for `.lensmcp/`: at any depth (prefix `**\/`), or at the root only (`/`). */
|
|
28
28
|
export declare function lensGitignoreLines(prefix?: '**/' | '/'): string[];
|
|
29
|
+
/**
|
|
30
|
+
* A .gitignore with its `.lensmcp` lines made right: the runtime ignored and each shared folder let back in under it.
|
|
31
|
+
* A `.lensmcp/` line becomes `**\/.lensmcp/*`; `/.lensmcp/` (the root's) becomes `/.lensmcp/*`. Lines it does not own
|
|
32
|
+
* are left as they are. Lock-step with `@lensmcp/nx-plugin` init `fixLensGitignore` (that package depends on no other):
|
|
33
|
+
* what `lensmcp install` writes and what Settings › Project › Setup's Run writes are the same lines.
|
|
34
|
+
*/
|
|
35
|
+
export declare function fixLensGitignore(text: string): {
|
|
36
|
+
text: string;
|
|
37
|
+
changed: boolean;
|
|
38
|
+
};
|
package/lib/lens-dir.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var r=(t,e)=>u(t,"name",{value:e,configurable:!0});var p=Object.defineProperty,l=r((t,e)=>p(t,"name",{value:e,configurable:!0}),"c");export const LENS_SHARED_DIRS=["sql-review","route-review","flow-review","ui-review","cache-review","queue-review","ai-review","ai-names","team","team-design"];export function lensGitignoreLines(t="**/"){return[`${t}.lensmcp/*`,...LENS_SHARED_DIRS.map(e=>`!${t}.lensmcp/${e}/`)]}r(lensGitignoreLines,"lensGitignoreLines"),l(lensGitignoreLines,"lensGitignoreLines");const $="# LensMCP: this machine's runtime state is ignored; the team's analyzer instructions are kept";export function fixLensGitignore(t){const e=t.split(`
|
|
2
|
+
`),m=/^(\/|\*\*\/)?\.lensmcp\/?(\*)?$/;let n=e.findIndex(i=>m.test(i.trim())),s=!1;if(n<0){const i=t.length&&!t.endsWith(`
|
|
3
|
+
`)?`${t}
|
|
4
|
+
`:t;return{text:`${i}${i.trim()?`
|
|
5
|
+
`:""}${$}
|
|
6
|
+
${lensGitignoreLines().join(`
|
|
7
|
+
`)}
|
|
8
|
+
`,changed:!0}}const c=m.exec(e[n].trim())[1]==="/"?"/":"**/";e[n].trim()!==`${c}.lensmcp/*`&&(e[n]=`${c}.lensmcp/*`,s=!0);for(const i of LENS_SHARED_DIRS){const o=`!${c}.lensmcp/${i}/`;e.some(a=>a.trim()===o||a.trim()===o.slice(0,-1))||(e.splice(++n,0,o),s=!0)}return{text:e.join(`
|
|
9
|
+
`),changed:s}}r(fixLensGitignore,"fixLensGitignore"),l(fixLensGitignore,"fixLensGitignore");
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variables kept as settings (planning/modules/03-settings-pages.md SP3-2): the `LENSMCP_*` variables worth setting
|
|
3
|
+
* from the dashboard, each with what it does, the values it takes, where it is kept and when a change takes effect.
|
|
4
|
+
*
|
|
5
|
+
* A setting is kept in one place, by its variable's name:
|
|
6
|
+
* - `repository`: `lensmcp.json` → `settings`, beside the code. Whoever clones the repository gets the same.
|
|
7
|
+
* - `machine`: `~/.lensmcp/settings.json` → `settings`. This computer's capacity: cold starts, memory floors, idle times.
|
|
8
|
+
*
|
|
9
|
+
* The value is the variable's own text, exactly what the process that reads it parses. A kept value reaches a process
|
|
10
|
+
* through its environment (`keptEnv`, `applyKeptSettings`), and never over one that is set: a variable in the
|
|
11
|
+
* environment, from the shell or a dotenv file, wins.
|
|
12
|
+
*
|
|
13
|
+
* Each entry mirrors how its reader parses it (file:line in `parse`'s comments). A reader changed is a setting to change.
|
|
14
|
+
*/
|
|
15
|
+
export type SettingKept = 'repository' | 'machine';
|
|
16
|
+
/** When a change reaches what reads it: when a service starts again, when the lens starts again, when the gateway does. */
|
|
17
|
+
export type SettingApplies = 'service' | 'lens' | 'gateway';
|
|
18
|
+
export interface VariableSetting {
|
|
19
|
+
env: string;
|
|
20
|
+
/** The Settings page it is on, and its section there. */
|
|
21
|
+
page: string;
|
|
22
|
+
section: string;
|
|
23
|
+
title: string;
|
|
24
|
+
desc: string;
|
|
25
|
+
kept: SettingKept;
|
|
26
|
+
applies: SettingApplies;
|
|
27
|
+
kind: 'toggle' | 'choice' | 'number';
|
|
28
|
+
/** A choice's values, each with its word. A toggle's are `on` / `off`. */
|
|
29
|
+
options?: ReadonlyArray<{
|
|
30
|
+
value: string;
|
|
31
|
+
label: string;
|
|
32
|
+
}>;
|
|
33
|
+
/** A number: the unit it is edited in, how many stored units one of it is, its bounds (stored units), what 0 means. */
|
|
34
|
+
number?: {
|
|
35
|
+
unit: string;
|
|
36
|
+
scale?: number;
|
|
37
|
+
min?: number;
|
|
38
|
+
max?: number;
|
|
39
|
+
zero?: string;
|
|
40
|
+
};
|
|
41
|
+
/** The default, as the screen shows it: a word, or a number in stored units. */
|
|
42
|
+
default: string | number | (() => number);
|
|
43
|
+
/** A toggle's variable text for on and off — what is written. */
|
|
44
|
+
write?: {
|
|
45
|
+
on: string;
|
|
46
|
+
off: string;
|
|
47
|
+
};
|
|
48
|
+
/** The value a variable's text means, as its reader parses it: a word, or a number. Unreadable: the default. */
|
|
49
|
+
parse?: (raw: string) => string | number | undefined;
|
|
50
|
+
}
|
|
51
|
+
export declare const SETTINGS: readonly VariableSetting[];
|
|
52
|
+
export declare const settingOf: (env: string) => VariableSetting | undefined;
|
|
53
|
+
export declare const defaultOf: (s: VariableSetting) => string | number;
|
|
54
|
+
/** The value a variable's text means, as the screen shows it; unreadable text reads as the default. */
|
|
55
|
+
export declare function valueOf(s: VariableSetting, raw: string): string | number;
|
|
56
|
+
/**
|
|
57
|
+
* The variable's text for a value from the screen, or why it is refused. A toggle's word becomes its `1` / `0`, a
|
|
58
|
+
* choice must be one of its values, a number must be within its bounds (stored units).
|
|
59
|
+
*/
|
|
60
|
+
export declare function textFor(s: VariableSetting, value: unknown): {
|
|
61
|
+
text: string;
|
|
62
|
+
} | {
|
|
63
|
+
refused: string;
|
|
64
|
+
};
|
|
65
|
+
/** `lensmcp.json` — the repository's project file (feature-cards `PROJECT_FILE`; a lock-step copy). */
|
|
66
|
+
export declare const PROJECT_FILE_NAME = "lensmcp.json";
|
|
67
|
+
/** The machine's file: `~/.lensmcp/settings.json` (`LENSMCP_HOME` moves the home, as for the rest of `~/.lensmcp`). */
|
|
68
|
+
export declare function machineSettingsFile(env?: NodeJS.ProcessEnv): string;
|
|
69
|
+
export interface KeptSettings {
|
|
70
|
+
repository: Record<string, string>;
|
|
71
|
+
machine: Record<string, string>;
|
|
72
|
+
}
|
|
73
|
+
/** What the repository (`<root>/lensmcp.json`) and this machine keep, by variable — each from the file its catalog entry names. */
|
|
74
|
+
export declare function readKeptSettings(root: string, env?: NodeJS.ProcessEnv): KeptSettings;
|
|
75
|
+
/** Every kept value of a checkout, by variable: what a process it starts should have unless its environment says otherwise. */
|
|
76
|
+
export declare function keptEnv(root: string, env?: NodeJS.ProcessEnv): Record<string, string>;
|
|
77
|
+
/**
|
|
78
|
+
* The names a lens process put in the environment from what is kept, comma-separated — so a process it starts, which
|
|
79
|
+
* inherits them, can tell them from a variable the shell or a dotenv file set: those win, these give way to what that
|
|
80
|
+
* process's own checkout keeps.
|
|
81
|
+
*/
|
|
82
|
+
export declare const KEPT_MARK = "LENSMCP_KEPT_SETTINGS";
|
|
83
|
+
/** Whether a variable in the environment is there because it is kept as a setting, not because the shell or a dotenv file set it. */
|
|
84
|
+
export declare const fromSettings: (name: string, env?: NodeJS.ProcessEnv) => boolean;
|
|
85
|
+
/** The root-level dotenv files nx and Vite load, the first one winning — what sets a variable before a setting can. */
|
|
86
|
+
export declare const DOTENV_FILES: readonly [".env.local", ".local.env", ".env"];
|
|
87
|
+
/** Each variable a checkout's root dotenv files declare (`KEY=…`, optional `export `), with the file that declares it. */
|
|
88
|
+
export declare function dotenvKeys(root: string): Map<string, string>;
|
|
89
|
+
/** Which dotenv file at a checkout's root declares a variable, if one does. */
|
|
90
|
+
export declare const dotenvDeclaring: (root: string, name: string) => string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* The environment a process of `root` starts with: `base` with what `root` keeps (its repository's and this machine's
|
|
93
|
+
* settings) in it. A variable the shell or a dotenv file set is left as it is. One a parent put there from ITS
|
|
94
|
+
* checkout's settings gives way to this checkout's — or goes, when this one keeps none, or when this checkout's own
|
|
95
|
+
* dotenv file declares it (nx loads that file next, and it never overrides a variable already set).
|
|
96
|
+
*/
|
|
97
|
+
export declare function withKeptSettings(root: string, base: NodeJS.ProcessEnv, env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
98
|
+
/**
|
|
99
|
+
* Give this process what its checkout keeps — at its start, before anything reads the variables — so everything it
|
|
100
|
+
* starts inherits it (`withKeptSettings` on its own environment). Returns the names it set.
|
|
101
|
+
*/
|
|
102
|
+
export declare function applyKeptSettings(root: string, env?: NodeJS.ProcessEnv): string[];
|
|
103
|
+
export interface ResolvedSetting {
|
|
104
|
+
value: string | number;
|
|
105
|
+
source: 'default' | SettingKept | 'env';
|
|
106
|
+
/** With `env`: `shell`, or the dotenv file that declares it. */
|
|
107
|
+
envFrom?: string;
|
|
108
|
+
/** What the file keeps, when it keeps one (shown under an environment that wins over it). */
|
|
109
|
+
kept?: string;
|
|
110
|
+
}
|
|
111
|
+
/** A setting's value here, and where it comes from: the environment first, then what is kept, then the default. */
|
|
112
|
+
export declare function resolveSetting(s: VariableSetting, root: string, env?: NodeJS.ProcessEnv, kept?: KeptSettings): ResolvedSetting;
|
|
113
|
+
/**
|
|
114
|
+
* Keep a setting, or forget it (`text` null: back to its default). Written to a copy and renamed, so a reader never
|
|
115
|
+
* sees half a file; every other key of the file is kept as it was. Returns the text it had.
|
|
116
|
+
*/
|
|
117
|
+
export declare function writeKeptSetting(root: string, name: string, text: string | null, env?: NodeJS.ProcessEnv): string | null;
|
package/lib/settings.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var M=Object.defineProperty;var l=(t,e)=>M(t,"name",{value:e,configurable:!0});var N=Object.defineProperty,s=l((t,e)=>N(t,"name",{value:e,configurable:!0}),"n");import{readFileSync as k,renameSync as L,statSync as C,unlinkSync as O,writeFileSync as P,mkdirSync as A}from"node:fs";import{availableParallelism as T,homedir as x}from"node:os";import{dirname as R,join as g}from"node:path";const I=[{value:"on",label:"On"},{value:"off",label:"Off"}],m=s(t=>t==="0"?"off":"on","zeroIsOff"),S=s(t=>/^(0|off|false|no)$/i.test(t.trim())?"off":"on","wordIsOff"),a=s(t=>{if(t.trim()==="")return;const e=Number(t);return Number.isFinite(e)?e:void 0},"num"),f={kind:"toggle",options:I,write:{on:"1",off:"0"}};export const SETTINGS=[{env:"LENSMCP_HTTP_CAPTURE",page:"capture",section:"Requests",title:"What each request keeps",desc:"For every request a service serves or makes: its headers, the query and the first 64 KB of each body; its headers only; or nothing.",kept:"repository",applies:"service",kind:"choice",options:[{value:"bodies",label:"Headers and bodies"},{value:"headers",label:"Headers"},{value:"off",label:"Nothing"}],default:"bodies",parse:s(t=>/^(off|0|false|none)$/i.test(t.trim())?"off":t.trim().toLowerCase()==="headers"?"headers":"bodies","parse")},{env:"LENSMCP_HTTP_MAX_FILES",page:"capture",section:"Requests",title:"Exchanges kept in each place",desc:"How many exchanges are kept for third-party calls, for requests served, and for calls between services. The oldest go first; AI calls are kept.",kept:"machine",applies:"service",kind:"number",number:{unit:"exchanges",min:10},default:1e4,parse:s(t=>{const e=a(t);return e!==void 0&&e>=10?Math.floor(e):void 0},"parse")},{env:"LENSMCP_LOGS",page:"capture",section:"Logs",...f,title:"Mirror the services\u2019 logs",desc:"What each service prints, and what its handlers give the Nest Logger, goes on the lens as logs. Off: Logs shows nothing of the services.",kept:"repository",applies:"service",default:"on",parse:m},{env:"LENSMCP_EVENT_LOOP",page:"capture",section:"Event loops",...f,title:"Measure the services\u2019 event loops",desc:"Samples each service\u2019s event-loop delay, measures slow callbacks and watches for a loop that stops answering. Off: Cluster \u203A Event loops has nothing.",kept:"repository",applies:"service",default:"on",parse:m},{env:"LENSMCP_TRACE_FLOWLESS_MIN_MS",page:"capture",section:"Traces",title:"Shortest traced call outside a request",desc:"A traced method that runs outside any request, flow or job and returns faster than this leaves no span \u2014 a timer that runs every second would otherwise fill the history.",kept:"repository",applies:"service",kind:"number",number:{unit:"ms",min:0,zero:"keep every one"},default:10,parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_EVENT_HISTORY_DAYS",page:"history",section:"Event history",title:"Keep the history for",desc:"Rows older than this go. Whichever comes first, this or the size below, decides.",kept:"machine",applies:"lens",kind:"number",number:{unit:"days",min:0,zero:"keep by size only"},default:30,parse:s(t=>{const e=a(t);return e===void 0?void 0:e>0?e:0},"parse")},{env:"LENSMCP_EVENT_HISTORY_MAX_GB",page:"history",section:"Event history",title:"Most history kept",desc:"Past this size the oldest rows go, whatever their age. A busy workspace reaches it in days.",kept:"machine",applies:"lens",kind:"number",number:{unit:"GB",min:0,zero:"no limit"},default:16,parse:s(t=>{const e=a(t);return e===void 0?void 0:e>0?e:0},"parse")},{env:"LENSMCP_EVENT_LOOP_DAYS",page:"history",section:"Event history",title:"Keep event-loop stalls for",desc:"How long a stall and its evidence stay in the history.",kept:"machine",applies:"lens",kind:"number",number:{unit:"days",min:1},default:30,parse:s(t=>{const e=a(t);return e!==void 0&&e>0?e:void 0},"parse")},{env:"LENSMCP_EVENT_MAX_BYTES",page:"history",section:"The event bus",title:"Size of one bus file",desc:"The events every process writes go to .lensmcp/events.jsonl; past this size it is rotated.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"MB",scale:1048576,min:1048576},default:52428800,parse:s(t=>{const e=a(t);return e!==void 0&&e>0?e:void 0},"parse")},{env:"LENSMCP_EVENT_MAX_FILES",page:"history",section:"The event bus",title:"Bus files kept",desc:"How many rotated bus files are kept beside the one being written.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"files",min:1,max:20},default:5,parse:s(t=>{const e=a(t);return e!==void 0&&e>=1&&e<=20?Math.floor(e):void 0},"parse")},{env:"LENSMCP_TYPECHECK",page:"typecheck",section:"The checker",title:"Type checker",desc:"tsgo checks a service after each build with the native compiler and keeps nothing in memory between saves. fork-ts-checker keeps a whole TypeScript program in memory for each service, 1\u20133 GB on a large one. Off: no type errors on the lens.",kept:"repository",applies:"service",kind:"choice",options:[{value:"tsgo",label:"tsgo"},{value:"tsc",label:"fork-ts-checker"},{value:"off",label:"Off"}],default:"tsgo",parse:s(t=>t==="off"?"off":t==="tsgo"||t===""?"tsgo":"tsc","parse")},{env:"LENSMCP_TYPECHECK_MIN_FREE_MB",page:"typecheck",section:"tsgo",title:"Wait for free memory",desc:"A check waits while the machine has less than this free, and the lens says it is held. Each check of a large service takes 1.5\u20133.5 GB while it runs.",kept:"machine",applies:"service",kind:"number",number:{unit:"MB",min:0,zero:"never wait"},default:2048,parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?Math.round(e):void 0},"parse")},{env:"LENSMCP_TYPECHECK_CONCURRENCY",page:"typecheck",section:"tsgo",title:"Checks at once on this machine",desc:"How many services are checked at the same time, every workspace\u2019s together. The rest wait their turn.",kept:"machine",applies:"service",kind:"number",number:{unit:"checks",min:1,max:8},default:1,parse:s(t=>{const e=a(t);return e!==void 0&&Number.isInteger(e)&&e>=1?Math.min(e,8):void 0},"parse")},{env:"LENSMCP_TSGO_INCREMENTAL",page:"typecheck",section:"tsgo",...f,title:"Check only what a change affects",desc:"Each service keeps what its last check learnt on disk (tmp/lensmcp-tsgo) and checks again only the files a change can affect. Off: every check is a full one.",kept:"repository",applies:"service",default:"on",parse:S},{env:"LENSMCP_PERF_RULES",page:"performance",section:"Rules",...f,title:"Performance rules",desc:"The rules that flag a barrel import that compiles a whole library, and a pod over its memory budget. Off: Performance shows none of their findings.",kept:"repository",applies:"service",default:"on",parse:S},{env:"LENSMCP_POD_HEAP_BUDGET_MB",page:"performance",section:"Rules",title:"A pod\u2019s memory budget",desc:"The live heap after a full collection above which a pod is flagged as over its budget. A service\u2019s own perfRules in .lensmcp/config.json wins.",kept:"repository",applies:"lens",kind:"number",number:{unit:"MB",min:16,max:1e6},default:512,parse:s(t=>{const e=a(t);return e!==void 0&&e>=16&&e<=1e6?e:void 0},"parse")},{env:"LENSMCP_MAX_COLD_STARTS",page:"services",section:"Starting",title:"Services starting at once",desc:"How many services may cold start together, every workspace\u2019s and worktree\u2019s counted. The rest wait their turn. Fewer start slower but keep a loaded machine answering.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"services",min:0,zero:"no limit"},default:s(()=>Math.max(2,Math.floor(T()/2)),"default"),parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_POD_RESPONSE_TIMEOUT_MS",page:"services",section:"Answering",title:"Wait for a first byte",desc:"How long the gateway waits for a pod\u2019s first byte before it checks the pod is alive. A service\u2019s own cluster.firstByteMs wins.",kept:"repository",applies:"gateway",kind:"number",number:{unit:"s",scale:1e3,min:1e3},default:3e4,parse:s(t=>{const e=a(t);return e!==void 0&&e>0?e:void 0},"parse")},{env:"LENSMCP_POD_RECYCLE",page:"services",section:"Recycling",...f,title:"Recycle a pod that missed a change",desc:"A pod whose watcher missed a file added or removed is replaced by a fresh one. Off: a pod keeps serving its old code until you restart it.",kept:"repository",applies:"gateway",default:"on",parse:m},{env:"LENSMCP_POD_MAX_AGE_MS",page:"services",section:"Recycling",title:"Recycle a pod older than",desc:"A pod this old is replaced even with no change seen \u2014 the one whose watcher went quiet.",kept:"repository",applies:"gateway",kind:"number",number:{unit:"h",scale:36e5,min:0,zero:"never"},default:144e5,parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_SWAP_MODE",page:"services",section:"A new build",title:"How a pod takes a new build",desc:"A fresh pod takes each new build and the old one finishes its work. In the same pod: the app is swapped inside the running process \u2014 faster, but a module that holds state can leak.",kept:"repository",applies:"service",kind:"choice",options:[{value:"process",label:"A fresh pod"},{value:"in-process",label:"In the same pod"}],default:"process",parse:s(t=>/^(in-process|inprocess|hot)$/i.test(t.trim())?"in-process":"process","parse")},{env:"LENSMCP_SWAP_DRAIN_MS",page:"services",section:"A new build",title:"Let the old app finish for",desc:"How long the previous app may finish its requests and background jobs before it is closed anyway.",kept:"repository",applies:"service",kind:"number",number:{unit:"min",scale:6e4,min:0,zero:"close at once"},default:9e5,parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_SHARED_COMPILER",page:"builds",section:"Compiling",...f,title:"One compilation for every service",desc:"The services of a checkout share one webpack compilation: a shared library is compiled once, not once per service. Off: each service has its own watcher again.",kept:"repository",applies:"service",default:"on",parse:s(t=>/^(0|off|false|no)$/i.test(t.trim())?"off":"on","parse")},{env:"LENSMCP_BUILD_HOST_IDLE_SEC",page:"builds",section:"Compiling",title:"Stop an idle build host after",desc:"How long a checkout\u2019s build host keeps running once none of its services runs.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"min",scale:60,min:0,zero:"never"},default:300,parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_DEV_DEVTOOL",page:"builds",section:"Source maps",title:"Source maps in development",desc:"eval is the fastest to build. A full source map gives exact lines in stack traces and costs build time and memory. A serve target\u2019s own devtool wins.",kept:"repository",applies:"service",kind:"choice",options:[{value:"eval",label:"eval"},{value:"eval-cheap-module-source-map",label:"eval-cheap-module-source-map"},{value:"cheap-module-source-map",label:"cheap-module-source-map"},{value:"source-map",label:"source-map"},{value:"off",label:"None"}],default:"eval",parse:s(t=>{const e=t.trim();return e?/^(false|off|none|0)$/i.test(e)?"off":/^(?:eval|(?:inline-|hidden-|eval-)?(?:nosources-)?(?:cheap-(?:module-)?)?source-map(?:-debugids)?)$/.test(e)?e:"eval":"eval"},"parse")},{env:"LENSMCP_WARM_MIN_FREE_MB",page:"worktrees",section:"Starting",title:"Start a worktree\u2019s services only with free memory",desc:"When a worktree registers, its always-warm services start one at a time, each only while the machine has this much free. The rest start on their first request.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"MB",min:0,zero:"no floor"},default:4096,parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_WORKTREE_IDLE_SEC",page:"worktrees",section:"Sleeping",title:"Stop an unused worktree service after",desc:"A worktree\u2019s service with no request for this long stops, and starts again on the next one.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"min",scale:60,min:0,zero:"never"},default:1800,parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_DASHBOARD_IDLE_SEC",page:"worktrees",section:"Sleeping",title:"Stop an unused worktree dashboard after",desc:"A worktree\u2019s dashboard starts on its first request and stops after this long with none.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"min",scale:60,min:0,zero:"always up"},default:600,parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_GUEST_REPLAY",page:"worktrees",section:"After a restart",...f,title:"Host the worktrees again after a restart",desc:"A restarted gateway hosts again every worktree and workspace registered with it before. Off: each registers again when its lens starts.",kept:"machine",applies:"gateway",default:"on",parse:m},{env:"LENSMCP_GUEST_MIDDLEWARE",page:"worktrees",section:"Requests",title:"Whose middleware runs on a worktree\u2019s routes",desc:"Its own \u2014 the middleware its gateway target declares; the main checkout\u2019s, on every route; or none.",kept:"machine",applies:"gateway",kind:"choice",options:[{value:"own",label:"Its own"},{value:"owner",label:"The main checkout\u2019s"},{value:"none",label:"None"}],default:"own",parse:s(t=>t==="owner"||t==="none"?t:"own","parse")},{env:"LENSMCP_GW_ACT",page:"gateway",section:"Acting as a user",...f,title:"Let agents act as a signed-in user",desc:"An agent may call the services as a user who signed in on this machine, through a ticket the gateway checks. Off: every ticket is refused.",kept:"machine",applies:"gateway",default:"on",parse:m},{env:"LENSMCP_MAX_CONNECTIONS",page:"gateway",section:"Limits",title:"Most connections at once",desc:"The front door\u2019s ceiling on open connections. Past it, new ones wait.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"connections",min:0,zero:"no limit"},default:512,parse:s(t=>{const e=a(t);return e!==void 0&&e>=0?Math.floor(e):void 0},"parse")},{env:"LENSMCP_ANSWER_BUDGET_BYTES",page:"answers",section:"Size",title:"Largest answer to an agent",desc:"Every answer, and every page result_query reads, fits this. A bigger one is folded, or cut when folding is off.",kept:"repository",applies:"lens",kind:"number",number:{unit:"KB",scale:1024,min:2048,zero:"no limit (folding off)"},default:24576,parse:s(t=>{const e=a(t);return e===void 0||e<0?void 0:e===0?0:Math.max(2048,Math.floor(e))},"parse")},{env:"LENSMCP_RESULT_HANDLES_THRESHOLD_BYTES",page:"answers",section:"Size",title:"Fold answers larger than",desc:"An answer at or under this goes to the agent as it is; a larger one goes as a preview and a handle.",kept:"repository",applies:"lens",kind:"number",number:{unit:"KB",scale:1024,min:1024},default:8192,parse:s(t=>{const e=a(t);return e!==void 0&&e>=1024?Math.floor(e):void 0},"parse")}];const y=new Map(SETTINGS.map(t=>[t.env,t]));export const settingOf=s(t=>y.get(t),"settingOf"),defaultOf=s(t=>typeof t.default=="function"?t.default():t.default,"defaultOf");export function valueOf(t,e){const r=t.parse?t.parse(e):e;return r===void 0?defaultOf(t):r}l(valueOf,"valueOf"),s(valueOf,"valueOf");export function textFor(t,e){if(t.kind==="toggle")return e!=="on"&&e!=="off"?{refused:`${t.env} is on or off`}:{text:e==="on"?t.write.on:t.write.off};if(t.kind==="choice"){const o=t.options?.find(i=>i.value===e);return o?{text:o.value}:{refused:`${t.env} is one of ${t.options.map(i=>i.value).join(", ")}`}}const r=typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):NaN,n=t.number;return Number.isFinite(r)?r===0&&n.zero?{text:"0"}:n.min!==void 0&&r<n.min?{refused:`${t.env} is at least ${n.min}${n.zero?`, or 0 (${n.zero})`:""}`}:n.max!==void 0&&r>n.max?{refused:`${t.env} is at most ${n.max}`}:{text:String(r)}:{refused:`${t.env} is a number`}}l(textFor,"textFor"),s(textFor,"textFor");export const PROJECT_FILE_NAME="lensmcp.json";export function machineSettingsFile(t=process.env){return g(t.LENSMCP_HOME||x(),".lensmcp","settings.json")}l(machineSettingsFile,"machineSettingsFile"),s(machineSettingsFile,"machineSettingsFile");const w=new Map;function b(t){let e;try{const o=C(t);e=`${o.size}:${o.mtimeMs}`}catch{return w.delete(t),{}}const r=w.get(t);if(r?.stamp===e)return r.settings;const n={};try{const o=JSON.parse(k(t,"utf8"));if(o.settings&&typeof o.settings=="object"&&!Array.isArray(o.settings))for(const[i,c]of Object.entries(o.settings))y.has(i)&&(typeof c=="string"||typeof c=="number")&&(n[i]=String(c))}catch{}return w.set(t,{stamp:e,settings:n}),n}l(b,"E"),s(b,"fileSettings");export function readKeptSettings(t,e=process.env){const r=b(g(t,PROJECT_FILE_NAME)),n=b(machineSettingsFile(e)),o=s((i,c)=>Object.fromEntries(Object.entries(i).filter(([d])=>y.get(d)?.kept===c)),"pick");return{repository:o(r,"repository"),machine:o(n,"machine")}}l(readKeptSettings,"readKeptSettings"),s(readKeptSettings,"readKeptSettings");export function keptEnv(t,e=process.env){const r=readKeptSettings(t,e);return{...r.machine,...r.repository}}l(keptEnv,"keptEnv"),s(keptEnv,"keptEnv");export const KEPT_MARK="LENSMCP_KEPT_SETTINGS";const E=s(t=>new Set((t[KEPT_MARK]??"").split(",").filter(Boolean)),"markedNames");export const fromSettings=s((t,e=process.env)=>e[t]!==void 0&&E(e).has(t),"fromSettings"),DOTENV_FILES=[".env.local",".local.env",".env"];export function dotenvKeys(t){const e=new Map;for(const r of DOTENV_FILES){let n;try{n=k(g(t,r),"utf8")}catch{continue}for(const o of n.matchAll(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/gm))e.has(o[1])||e.set(o[1],r)}return e}l(dotenvKeys,"dotenvKeys"),s(dotenvKeys,"dotenvKeys");export const dotenvDeclaring=s((t,e)=>dotenvKeys(t).get(e),"dotenvDeclaring");export function withKeptSettings(t,e,r=process.env){const n={...e},o=keptEnv(t,r),i=E(e),c=dotenvKeys(t),d=[];for(const h of SETTINGS){const u=h.env;if(n[u]!==void 0&&!i.has(u))continue;const v=o[u];v===void 0||c.has(u)?delete n[u]:(n[u]=v,d.push(u))}return d.length?n[KEPT_MARK]=d.join(","):delete n[KEPT_MARK],n}l(withKeptSettings,"withKeptSettings"),s(withKeptSettings,"withKeptSettings");export function applyKeptSettings(t,e=process.env){const r=withKeptSettings(t,e,e);for(const n of[...SETTINGS.map(o=>o.env),KEPT_MARK])r[n]===void 0?delete e[n]:e[n]=r[n];return[...E(e)]}l(applyKeptSettings,"applyKeptSettings"),s(applyKeptSettings,"applyKeptSettings");export function resolveSetting(t,e,r=process.env,n=readKeptSettings(e,r)){const o=n[t.kept][t.env],i=r[t.env];return i!==void 0&&!fromSettings(t.env,r)?{value:valueOf(t,i),source:"env",envFrom:dotenvDeclaring(e,t.env)??"shell",...o!==void 0?{kept:o}:{}}:o!==void 0?{value:valueOf(t,o),source:t.kept}:{value:defaultOf(t),source:"default"}}l(resolveSetting,"resolveSetting"),s(resolveSetting,"resolveSetting");export function writeKeptSetting(t,e,r,n=process.env){const o=y.get(e);if(!o)throw new Error(`${e} is not a setting`);const i=o.kept==="repository"?g(t,PROJECT_FILE_NAME):machineSettingsFile(n);let c={},d=!0;try{const p=JSON.parse(k(i,"utf8"));if(!p||typeof p!="object"||Array.isArray(p))throw new Error(`${i} is not a JSON object \u2014 fix it by hand first`);c=p}catch(p){if(p.code!=="ENOENT")throw p instanceof SyntaxError?new Error(`${i} is not valid JSON (${p.message}) \u2014 fix it by hand first`):p;d=!1}const h=c.settings&&typeof c.settings=="object"&&!Array.isArray(c.settings)?{...c.settings}:{},u=typeof h[e]=="string"||typeof h[e]=="number"?String(h[e]):null;if(r===null?delete h[e]:h[e]=r,Object.keys(h).length?c.settings=Object.fromEntries(Object.entries(h).sort(([p],[_])=>p.localeCompare(_))):delete c.settings,!d&&!c.settings)return u;d||(c={schemaVersion:1,...c}),A(R(i),{recursive:!0});const v=`${i}.${process.pid}.tmp`;try{P(v,`${JSON.stringify(c,null,2)}
|
|
2
|
+
`),L(v,i)}catch(p){try{O(v)}catch{}throw p}return w.delete(i),u}l(writeKeptSetting,"writeKeptSetting"),s(writeKeptSetting,"writeKeptSetting");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/core",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.49",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -42,11 +42,21 @@
|
|
|
42
42
|
"import": "./lib/lens-dir.js",
|
|
43
43
|
"default": "./lib/lens-dir.js"
|
|
44
44
|
},
|
|
45
|
+
"./settings": {
|
|
46
|
+
"types": "./lib/settings.d.ts",
|
|
47
|
+
"import": "./lib/settings.js",
|
|
48
|
+
"default": "./lib/settings.js"
|
|
49
|
+
},
|
|
45
50
|
"./bus-rotation": {
|
|
46
51
|
"types": "./lib/bus-rotation.d.ts",
|
|
47
52
|
"import": "./lib/bus-rotation.js",
|
|
48
53
|
"default": "./lib/bus-rotation.js"
|
|
49
54
|
},
|
|
55
|
+
"./capture-off": {
|
|
56
|
+
"types": "./lib/capture-off.d.ts",
|
|
57
|
+
"import": "./lib/capture-off.js",
|
|
58
|
+
"default": "./lib/capture-off.js"
|
|
59
|
+
},
|
|
50
60
|
"./lens-events": {
|
|
51
61
|
"types": "./lib/lens-events.d.ts",
|
|
52
62
|
"import": "./lib/lens-events.js",
|
|
@@ -84,7 +94,7 @@
|
|
|
84
94
|
}
|
|
85
95
|
},
|
|
86
96
|
"dependencies": {
|
|
87
|
-
"@lensmcp/protocol-types": "1.25.
|
|
97
|
+
"@lensmcp/protocol-types": "1.25.49",
|
|
88
98
|
"tslib": "^2.3.0"
|
|
89
99
|
},
|
|
90
100
|
"license": "Apache-2.0",
|