@lensmcp/core 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/lib/lens-events.d.ts +20 -2
- package/lib/lens-events.js +2 -2
- package/lib/settings.d.ts +5 -2
- package/lib/settings.js +2 -2
- package/package.json +2 -2
package/lib/lens-events.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { type BaseEvent, type ErrorDismissalDraft, type ExpectedFailureRule, type ExpectedRuleAuthor, type MetricsChange } from '@lensmcp/protocol-types';
|
|
1
|
+
import { type BaseEvent, type ContainerOomEvent, type DockerEngineLostEvent, type ErrorDismissalDraft, type ExpectedFailureRule, type ExpectedRuleAuthor, type MetricsChange } from '@lensmcp/protocol-types';
|
|
2
2
|
/**
|
|
3
3
|
* Events the lens writes about itself — a dismissed error and its undo, a standing rule that expects a failure and its
|
|
4
|
-
* removal, a reset of a catalog's numbers and its undo — and the
|
|
4
|
+
* removal, a reset of a catalog's numbers and its undo — and about the Docker work it runs (a container killed for
|
|
5
|
+
* memory, an engine lost), and the one way they reach the bus.
|
|
5
6
|
*
|
|
6
7
|
* Three processes can dismiss: the dashboard (a click), the MCP server (an agent's tool call, or
|
|
7
8
|
* the CLI through it). None of them changes its own memory. Each appends to the bus FILE and hears
|
|
@@ -26,6 +27,23 @@ export declare function expectedRuleRemovedEvent(id: string, by: Exclude<Expecte
|
|
|
26
27
|
* reset is in `raw`.
|
|
27
28
|
*/
|
|
28
29
|
export declare function metricsChangeEvents(change: MetricsChange, sessionId: string, at: number): BaseEvent[];
|
|
30
|
+
/**
|
|
31
|
+
* A container of a run killed for running out of memory, stamped when it was killed. Both of a kill's witnesses call
|
|
32
|
+
* this — the live events stream (`seen: 'event'`) and the inspect at the run's end (`seen: 'inspect'`), for every
|
|
33
|
+
* container it finds killed: the readers make the two accounts one by the container's id. `sessionId` is whose process
|
|
34
|
+
* tells it; a runner has no lens session and passes its run.
|
|
35
|
+
*
|
|
36
|
+
* The fingerprint — the flood guard's bucket — is the job and the service: what the cause is.
|
|
37
|
+
*/
|
|
38
|
+
export declare function containerOomEvent(kill: Omit<ContainerOomEvent, 'kind'>, sessionId: string, at: number): BaseEvent;
|
|
39
|
+
/**
|
|
40
|
+
* Docker stopped answering while runs were in it, stamped when it stopped. One event per watcher that saw it, each
|
|
41
|
+
* naming the runs it knows were in that engine: the readers fold the accounts of one loss, and never list the
|
|
42
|
+
* containers that went with it as errors of their own.
|
|
43
|
+
*
|
|
44
|
+
* The fingerprint is the VM: the context — and, for a worker's engine told on this Mac's bus (slice D16), the worker.
|
|
45
|
+
*/
|
|
46
|
+
export declare function dockerEngineLostEvent(lost: Omit<DockerEngineLostEvent, 'kind'>, sessionId: string, at: number): BaseEvent;
|
|
29
47
|
/**
|
|
30
48
|
* Append events to the bus file. Throws when the write fails: the caller is answering a person or
|
|
31
49
|
* an agent, and "dismissed" must not be a guess.
|
package/lib/lens-events.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`).join("")))}s(appendBusEvents,"appendBusEvents"),
|
|
1
|
+
"use strict";var f=Object.defineProperty;var s=(e,t)=>f(e,"name",{value:t,configurable:!0});var y=Object.defineProperty,o=s((e,t)=>y(e,"name",{value:t,configurable:!0}),"r");import{appendFileSync as $,closeSync as R,mkdirSync as _,openSync as g,renameSync as I,statSync as k,unlinkSync as N}from"node:fs";import{dirname as b,join as h}from"node:path";import{CONTAINER_OOM as d,DOCKER_ENGINE_LOST as E,ERROR_DISMISSED as u,ERROR_RESTORED as p,EXPECTED_RULE_REMOVED as l,EXPECTED_RULE_SET as m,LENS_EVENT_SOURCE as v,METRICS_RESET as O,describeExpectedMatch as T,dockerErrorWords as M,metricsIdBatches as C,readDockerError as L}from"@lensmcp/protocol-types";import{rotateBusFile as A}from"./bus-rotation.js";import{ulid as S}from"./ulid.js";export function lensEventFile(e=process.env,t=process.cwd()){return e.LENSMCP_EVENT_FILE??h(t,".lensmcp","events.jsonl")}s(lensEventFile,"lensEventFile"),o(lensEventFile,"lensEventFile");const a=o((e,t,n,r,i)=>({id:S(),sessionId:e,timestamp:t,source:v,category:"runtime",severity:"info",context:{sessionId:e},fingerprint:n,title:r,raw:i}),"lensEvent");export function dismissalEvent(e,t){return a(t,e.until,`${u}:${e.groupId}`,`error dismissed: ${e.title??e.groupId}`,{kind:u,groupId:e.groupId,until:e.until,eventIds:e.eventIds,...e.by?{by:e.by}:{},...e.reason?{reason:e.reason}:{},...e.title?{title:e.title}:{}})}s(dismissalEvent,"dismissalEvent"),o(dismissalEvent,"dismissalEvent");export function restoralEvent(e,t,n){return a(t,n,`${p}:${e}`,"error restored",{kind:p,groupId:e})}s(restoralEvent,"restoralEvent"),o(restoralEvent,"restoralEvent");export function expectedRuleEvent(e,t){return a(t,e.createdAt,`${m}:${e.id}`,`failure expected: ${e.title??T(e.match)}`,{kind:m,id:e.id,match:e.match,reason:e.reason,by:e.by,createdAt:e.createdAt,...e.expiresAt!==void 0?{expiresAt:e.expiresAt}:{},...e.title?{title:e.title}:{}})}s(expectedRuleEvent,"expectedRuleEvent"),o(expectedRuleEvent,"expectedRuleEvent");export function expectedRuleRemovedEvent(e,t,n,r){return a(n,r,`${l}:${e}`,"failure no longer expected",{kind:l,id:e,by:t})}s(expectedRuleRemovedEvent,"expectedRuleRemovedEvent"),o(expectedRuleRemovedEvent,"expectedRuleRemovedEvent");export function metricsChangeEvents(e,t,n){const r=e.kind===O;return(e.ids?C(e.ids):[void 0]).map(i=>a(t,n,`${e.kind}:${e.scope}`,`${r?"numbers reset":"numbers counted whole again"}: ${e.scope}${i?` \xB7 ${i.length}`:" \xB7 all"}`,{kind:e.kind,scope:e.scope,...r?{at:n}:{},...i?{ids:i}:{}}))}s(metricsChangeEvents,"metricsChangeEvents"),o(metricsChangeEvents,"metricsChangeEvents");function c(e,t,n,r){const i=M(L(e));return{id:S(),sessionId:n,timestamp:Math.max(0,Math.floor(r)),source:v,category:"cluster",severity:"error",context:{sessionId:n},fingerprint:t,title:i.title,message:i.facts,raw:e}}s(c,"$"),o(c,"dockerErrorEvent");export function containerOomEvent(e,t,n){return c({kind:d,...e},`${d}:${e.job}:${e.service}`,t,n)}s(containerOomEvent,"containerOomEvent"),o(containerOomEvent,"containerOomEvent");export function dockerEngineLostEvent(e,t,n){return c({kind:E,...e},`${E}:${e.context??""}${e.host?`@${e.host.peer}`:""}`,t,n)}s(dockerEngineLostEvent,"dockerEngineLostEvent"),o(dockerEngineLostEvent,"dockerEngineLostEvent");const x=o((e,t,n)=>{const r=Number(process.env[e]);return Number.isFinite(r)&&n(r)?r:t},"envNumber");export function appendBusEvents(e,t){t.length!==0&&(_(b(e),{recursive:!0}),A(e,{maxBytes:x("LENSMCP_EVENT_MAX_BYTES",50*1024*1024,n=>n>0),maxFiles:x("LENSMCP_EVENT_MAX_FILES",5,n=>n>=1&&n<=20),fs:{statSync:k,renameSync:I,unlinkSync:N,openSync:g,closeSync:R}}),$(e,t.map(n=>JSON.stringify(n)+`
|
|
2
|
+
`).join("")))}s(appendBusEvents,"appendBusEvents"),o(appendBusEvents,"appendBusEvents");
|
package/lib/settings.d.ts
CHANGED
|
@@ -13,8 +13,11 @@
|
|
|
13
13
|
* Each entry mirrors how its reader parses it (file:line in `parse`'s comments). A reader changed is a setting to change.
|
|
14
14
|
*/
|
|
15
15
|
export type SettingKept = 'repository' | 'machine';
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* When a change reaches what reads it: at once (the lens reads the kept value as it goes, with no restart), when a
|
|
18
|
+
* service starts again, when the lens starts again, when the gateway does.
|
|
19
|
+
*/
|
|
20
|
+
export type SettingApplies = 'now' | 'service' | 'lens' | 'gateway';
|
|
18
21
|
export interface VariableSetting {
|
|
19
22
|
env: string;
|
|
20
23
|
/** The Settings page it is on, and its section there. */
|
package/lib/settings.js
CHANGED
|
@@ -1,2 +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 y,renameSync as L,statSync as C,unlinkSync as A,writeFileSync as O,mkdirSync as P}from"node:fs";import{availableParallelism as T,homedir as R}from"node:os";import{dirname as x,join as g}from"node:path";const I=[{value:"on",label:"On"},{value:"off",label:"Off"}],m=s(t=>t==="0"?"off":"on","zeroIsOff"),b=s(t=>/^(0|off|false|no)$/i.test(t.trim())?"off":"on","wordIsOff"),o=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=o(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=o(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=o(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=o(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=o(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=o(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=o(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=o(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=o(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:b},{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:b},{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=o(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=o(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=o(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=o(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=o(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=o(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=o(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_WORKTREE_RUN_MAX",page:"worktrees",section:"Starting",title:"On-demand worktrees running at once",desc:"At most this many on-demand worktrees run at the same time. One more is refused, naming those that run and when each parks. The main checkout does not count.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"worktrees",min:0,zero:"no cap"},default:2,parse:s(t=>{const e=o(t);return e!==void 0&&e>=0?Math.floor(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=o(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_WORKTREE_RUN_IDLE_SEC",page:"worktrees",section:"Sleeping",title:"Park an unused on-demand worktree after",desc:"An on-demand worktree that runs is parked after this long with no request and no hold: its services, frontends and dashboard stop, and its data is kept. It runs again when asked.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"min",scale:60,min:60},default:900,parse:s(t=>{const e=o(t);return e!==void 0&&e>=60?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=o(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_MAIN_ALWAYS_UP",page:"worktrees",section:"Main checkout",...f,title:"Keep the main checkout always up",desc:"Every main service starts when the gateway does \u2014 the always-warm ones first, then the rest one at a time while memory holds \u2014 and none stops for idleness. Off: the rest start on their first request.",kept:"machine",applies:"gateway",default:"on",parse:b},{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=o(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=o(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=o(t);return e!==void 0&&e>=1024?Math.floor(e):void 0},"parse")}];const w=new Map(SETTINGS.map(t=>[t.env,t]));export const settingOf=s(t=>w.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 a=t.options?.find(i=>i.value===e);return a?{text:a.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||R(),".lensmcp","settings.json")}l(machineSettingsFile,"machineSettingsFile"),s(machineSettingsFile,"machineSettingsFile");const k=new Map;function E(t){let e;try{const a=C(t);e=`${a.size}:${a.mtimeMs}`}catch{return k.delete(t),{}}const r=k.get(t);if(r?.stamp===e)return r.settings;const n={};try{const a=JSON.parse(y(t,"utf8"));if(a.settings&&typeof a.settings=="object"&&!Array.isArray(a.settings))for(const[i,c]of Object.entries(a.settings))w.has(i)&&(typeof c=="string"||typeof c=="number")&&(n[i]=String(c))}catch{}return k.set(t,{stamp:e,settings:n}),n}l(E,"b"),s(E,"fileSettings");export function readKeptSettings(t,e=process.env){const r=E(g(t,PROJECT_FILE_NAME)),n=E(machineSettingsFile(e)),a=s((i,c)=>Object.fromEntries(Object.entries(i).filter(([d])=>w.get(d)?.kept===c)),"pick");return{repository:a(r,"repository"),machine:a(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 S=s(t=>new Set((t[KEPT_MARK]??"").split(",").filter(Boolean)),"markedNames");export const fromSettings=s((t,e=process.env)=>e[t]!==void 0&&S(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=y(g(t,r),"utf8")}catch{continue}for(const a of n.matchAll(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/gm))e.has(a[1])||e.set(a[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},a=keptEnv(t,r),i=S(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=a[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(a=>a.env),KEPT_MARK])r[n]===void 0?delete e[n]:e[n]=r[n];return[...S(e)]}l(applyKeptSettings,"applyKeptSettings"),s(applyKeptSettings,"applyKeptSettings");export function resolveSetting(t,e,r=process.env,n=readKeptSettings(e,r)){const a=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",...a!==void 0?{kept:a}:{}}:a!==void 0?{value:valueOf(t,a),source:t.kept}:{value:defaultOf(t),source:"default"}}l(resolveSetting,"resolveSetting"),s(resolveSetting,"resolveSetting");export function writeKeptSetting(t,e,r,n=process.env){const a=w.get(e);if(!a)throw new Error(`${e} is not a setting`);const i=a.kept==="repository"?g(t,PROJECT_FILE_NAME):machineSettingsFile(n);let c={},d=!0;try{const p=JSON.parse(y(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}),P(x(i),{recursive:!0});const v=`${i}.${process.pid}.tmp`;try{O(v,`${JSON.stringify(c,null,2)}
|
|
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 y,renameSync as C,statSync as A,unlinkSync as L,writeFileSync as P,mkdirSync as T}from"node:fs";import{availableParallelism as O,homedir as R}from"node:os";import{dirname as x,join as g}from"node:path";const I=[{value:"on",label:"On"},{value:"off",label:"Off"}],v=s(t=>t==="0"?"off":"on","zeroIsOff"),E=s(t=>/^(0|off|false|no)$/i.test(t.trim())?"off":"on","wordIsOff"),o=s(t=>{if(t.trim()==="")return;const e=Number(t);return Number.isFinite(e)?e:void 0},"num"),d={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=o(t);return e!==void 0&&e>=10?Math.floor(e):void 0},"parse")},{env:"LENSMCP_LOGS",page:"capture",section:"Logs",...d,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:v},{env:"LENSMCP_EVENT_LOOP",page:"capture",section:"Event loops",...d,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:v},{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=o(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_TRACE_LEAF_MIN_MS",page:"capture",section:"Traces",title:"Shortest traced call inside a request that calls nothing",desc:"Inside a request, flow or job, a traced method that returns faster than this and calls nothing \u2014 no other traced method, no query, cache command or outbound call \u2014 leaves no span. 1 leaves out the calls that read 0 ms, which around a route read many times a second can fill the history. The request, its controller, an error and every call that calls something keep theirs.",kept:"repository",applies:"service",kind:"number",number:{unit:"ms",min:0,zero:"keep every one"},default:0,parse:s(t=>{const e=o(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=o(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=o(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=o(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=o(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=o(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_REACH",page:"typecheck",section:"The checker",title:"Checked again in the background",desc:"Running services: a service is checked after each of its builds, and any other program when lensmcp typecheck asks; nothing is watched. Every checked program: the lens also watches the checkout and checks again each program that was checked once and whose files changed \u2014 one at a time, after every check someone asked for. One edit to a shared file is a check of every program that holds it: minutes of checking on a large workspace.",kept:"repository",applies:"now",kind:"choice",options:[{value:"services",label:"Running services"},{value:"all",label:"Every checked program"}],default:"services",parse:s(t=>t.trim().toLowerCase()==="all"?"all":"services","parse")},{env:"LENSMCP_TYPECHECK_MIN_FREE_MB",page:"typecheck",section:"tsgo",title:"Wait for free memory",desc:"The least a check waits for: it starts only while the machine has this much free, and the lens says it is held. A program whose last check held more waits for that and a quarter more.",kept:"machine",applies:"service",kind:"number",number:{unit:"MB",min:0,zero:"never wait"},default:2048,parse:s(t=>{const e=o(t);return e!==void 0&&e>=0?Math.round(e):void 0},"parse")},{env:"LENSMCP_TYPECHECK_CHECKERS_ABOVE_MB",page:"typecheck",section:"tsgo",title:"Check with two checkers above",desc:"A program whose check held more than this is checked with two checkers in place of the compiler\u2019s four, which hold less memory and take longer. Its limit on cores does not bound memory.",kept:"machine",applies:"service",kind:"number",number:{unit:"MB",min:0,zero:"never"},default:4096,parse:s(t=>{const e=o(t);return e!==void 0&&e>=0?Math.round(e):void 0},"parse")},{env:"LENSMCP_TYPECHECK_SINGLE_THREADED",page:"typecheck",section:"tsgo",...d,title:"Check on one thread",desc:"Every check runs on one thread: about two thirds of the memory, and up to three times the time. For a machine that cannot hold a check otherwise.",kept:"machine",applies:"service",default:"off",parse:s(t=>/^(1|true|on|yes)$/i.test(t.trim())?"on":"off","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=o(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",...d,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:E},{env:"LENSMCP_PARITY_MAX_AGE_DAYS",page:"typecheck",section:"Parity with tsc",title:"A parity proof stands for",desc:"How long a program counts as proven after lensmcp typecheck --parity showed that its check reports what the workspace\u2019s own tsc reports. A new tsgo, a new tsc or a changed configuration ends a proof at once; this limit catches what new code brings. Past it the program reads unproven until the sweep is run again.",kept:"repository",applies:"now",kind:"number",number:{unit:"days",min:1,max:365},default:14,parse:s(t=>{const e=o(t);return e!==void 0&&Number.isInteger(e)&&e>=1&&e<=365?e:void 0},"parse")},{env:"LENSMCP_PERF_RULES",page:"performance",section:"Rules",...d,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:E},{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=o(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(O()/2)),"default"),parse:s(t=>{const e=o(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=o(t);return e!==void 0&&e>0?e:void 0},"parse")},{env:"LENSMCP_POD_RECYCLE",page:"services",section:"Recycling",...d,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:v},{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=o(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=o(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_SHARED_COMPILER",page:"builds",section:"Compiling",...d,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=o(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_UPDATES_AGENT_HOLDS",page:"builds",section:"Updates",...d,title:"Agents\u2019 edits wait for their turn to end",desc:"On: an agent\u2019s edit holds its checkout\u2019s services and frontends \u2014 what it saves is collected, not built, and the last build keeps serving until its turn ends, then what was collected is built once. Off (the default): every save is built at once, an agent\u2019s as yours; an agent holds only when it asks (service_hold).",kept:"repository",applies:"now",default:"off",parse:s(t=>/^(1|true|on|yes)$/i.test(t.trim())?"on":"off","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=o(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_WORKTREE_RUN_MAX",page:"worktrees",section:"Starting",title:"On-demand worktrees running at once",desc:"At most this many on-demand worktrees run at the same time. One more is refused, naming those that run and when each parks. The main checkout does not count.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"worktrees",min:0,zero:"no cap"},default:2,parse:s(t=>{const e=o(t);return e!==void 0&&e>=0?Math.floor(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=o(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_WORKTREE_RUN_IDLE_SEC",page:"worktrees",section:"Sleeping",title:"Park an unused on-demand worktree after",desc:"An on-demand worktree that runs is parked after this long with no request and no hold: its services, frontends and dashboard stop, and its data is kept. It runs again when asked.",kept:"machine",applies:"gateway",kind:"number",number:{unit:"min",scale:60,min:60},default:900,parse:s(t=>{const e=o(t);return e!==void 0&&e>=60?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=o(t);return e!==void 0&&e>=0?e:void 0},"parse")},{env:"LENSMCP_GUEST_REPLAY",page:"worktrees",section:"After a restart",...d,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:v},{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_MAIN_ALWAYS_UP",page:"worktrees",section:"Main checkout",...d,title:"Keep the main checkout always up",desc:"Every main service starts when the gateway does \u2014 the always-warm ones first, then the rest one at a time while memory holds \u2014 and none stops for idleness. Off: the rest start on their first request.",kept:"machine",applies:"gateway",default:"on",parse:E},{env:"LENSMCP_GW_ACT",page:"gateway",section:"Acting as a user",...d,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:v},{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=o(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=o(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=o(t);return e!==void 0&&e>=1024?Math.floor(e):void 0},"parse")}];const k=new Map(SETTINGS.map(t=>[t.env,t]));export const settingOf=s(t=>k.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 a=t.options?.find(i=>i.value===e);return a?{text:a.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||R(),".lensmcp","settings.json")}l(machineSettingsFile,"machineSettingsFile"),s(machineSettingsFile,"machineSettingsFile");const w=new Map;function b(t){let e;try{const a=A(t);e=`${a.size}:${a.mtimeMs}`}catch{return w.delete(t),{}}const r=w.get(t);if(r?.stamp===e)return r.settings;const n={};try{const a=JSON.parse(y(t,"utf8"));if(a.settings&&typeof a.settings=="object"&&!Array.isArray(a.settings))for(const[i,c]of Object.entries(a.settings))k.has(i)&&(typeof c=="string"||typeof c=="number")&&(n[i]=String(c))}catch{}return w.set(t,{stamp:e,settings:n}),n}l(b,"b"),s(b,"fileSettings");export function readKeptSettings(t,e=process.env){const r=b(g(t,PROJECT_FILE_NAME)),n=b(machineSettingsFile(e)),a=s((i,c)=>Object.fromEntries(Object.entries(i).filter(([h])=>k.get(h)?.kept===c)),"pick");return{repository:a(r,"repository"),machine:a(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 S=s(t=>new Set((t[KEPT_MARK]??"").split(",").filter(Boolean)),"markedNames");export const fromSettings=s((t,e=process.env)=>e[t]!==void 0&&S(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=y(g(t,r),"utf8")}catch{continue}for(const a of n.matchAll(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/gm))e.has(a[1])||e.set(a[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},a=keptEnv(t,r),i=S(e),c=dotenvKeys(t),h=[];for(const f of SETTINGS){const u=f.env;if(n[u]!==void 0&&!i.has(u))continue;const m=a[u];m===void 0||c.has(u)?delete n[u]:(n[u]=m,h.push(u))}return h.length?n[KEPT_MARK]=h.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(a=>a.env),KEPT_MARK])r[n]===void 0?delete e[n]:e[n]=r[n];return[...S(e)]}l(applyKeptSettings,"applyKeptSettings"),s(applyKeptSettings,"applyKeptSettings");export function resolveSetting(t,e,r=process.env,n=readKeptSettings(e,r)){const a=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",...a!==void 0?{kept:a}:{}}:a!==void 0?{value:valueOf(t,a),source:t.kept}:{value:defaultOf(t),source:"default"}}l(resolveSetting,"resolveSetting"),s(resolveSetting,"resolveSetting");export function writeKeptSetting(t,e,r,n=process.env){const a=k.get(e);if(!a)throw new Error(`${e} is not a setting`);const i=a.kept==="repository"?g(t,PROJECT_FILE_NAME):machineSettingsFile(n);let c={},h=!0;try{const p=JSON.parse(y(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;h=!1}const f=c.settings&&typeof c.settings=="object"&&!Array.isArray(c.settings)?{...c.settings}:{},u=typeof f[e]=="string"||typeof f[e]=="number"?String(f[e]):null;if(r===null?delete f[e]:f[e]=r,Object.keys(f).length?c.settings=Object.fromEntries(Object.entries(f).sort(([p],[_])=>p.localeCompare(_))):delete c.settings,!h&&!c.settings)return u;h||(c={schemaVersion:1,...c}),T(x(i),{recursive:!0});const m=`${i}.${process.pid}.tmp`;try{P(m,`${JSON.stringify(c,null,2)}
|
|
2
|
+
`),C(m,i)}catch(p){try{L(m)}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.26.
|
|
3
|
+
"version": "1.26.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
}
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"@lensmcp/protocol-types": "1.26.
|
|
112
|
+
"@lensmcp/protocol-types": "1.26.3",
|
|
113
113
|
"tslib": "^2.3.0"
|
|
114
114
|
},
|
|
115
115
|
"license": "Apache-2.0",
|