@lensmcp/core 1.25.58 → 1.25.60
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 +10 -3
- package/lib/lens-events.js +2 -2
- package/lib/resource-store.d.ts +24 -2
- package/lib/resource-store.js +1 -1
- package/package.json +2 -2
package/lib/lens-events.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type BaseEvent, type ErrorDismissalDraft } from '@lensmcp/protocol-types';
|
|
1
|
+
import { type BaseEvent, type ErrorDismissalDraft, type MetricsChange } from '@lensmcp/protocol-types';
|
|
2
2
|
/**
|
|
3
|
-
* Events the lens writes about itself —
|
|
4
|
-
* they reach the bus.
|
|
3
|
+
* Events the lens writes about itself — a dismissed error and its undo, a reset of a catalog's
|
|
4
|
+
* numbers and its undo — and the one way they reach the bus.
|
|
5
5
|
*
|
|
6
6
|
* Three processes can dismiss: the dashboard (a click), the MCP server (an agent's tool call, or
|
|
7
7
|
* the CLI through it). None of them changes its own memory. Each appends to the bus FILE and hears
|
|
@@ -13,6 +13,13 @@ export declare function lensEventFile(env?: Record<string, string | undefined>,
|
|
|
13
13
|
/** Stamped AT `until`: the reader clamps a dismissal to its own timestamp, so the two must agree. */
|
|
14
14
|
export declare function dismissalEvent(draft: ErrorDismissalDraft, sessionId: string): BaseEvent;
|
|
15
15
|
export declare function restoralEvent(groupId: string, sessionId: string, at: number): BaseEvent;
|
|
16
|
+
/**
|
|
17
|
+
* A reset of a catalog's numbers, or its undo (`@lensmcp/protocol-types` metrics-reset.ts), as the events that carry
|
|
18
|
+
* it: one for everything in the scope, else one per batch of ids the bus keeps whole — each stamped AT the reset, which
|
|
19
|
+
* the reader clamps to. The fingerprint is the kind and the scope only: it is the flood guard's bucket, and what was
|
|
20
|
+
* reset is in `raw`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function metricsChangeEvents(change: MetricsChange, sessionId: string, at: number): BaseEvent[];
|
|
16
23
|
/**
|
|
17
24
|
* Append events to the bus file. Throws when the write fails: the caller is answering a person or
|
|
18
25
|
* 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("")))}
|
|
1
|
+
"use strict";var u=Object.defineProperty;var r=(n,e)=>u(n,"name",{value:e,configurable:!0});var E=Object.defineProperty,i=r((n,e)=>E(n,"name",{value:e,configurable:!0}),"o");import{appendFileSync as l,closeSync as m,mkdirSync as S,openSync as v,renameSync as y,statSync as f,unlinkSync as I}from"node:fs";import{dirname as g,join as _}from"node:path";import{ERROR_DISMISSED as c,ERROR_RESTORED as p,LENS_EVENT_SOURCE as N,METRICS_RESET as R,metricsIdBatches as $}from"@lensmcp/protocol-types";import{rotateBusFile as b}from"./bus-rotation.js";import{ulid as x}from"./ulid.js";export function lensEventFile(n=process.env,e=process.cwd()){return n.LENSMCP_EVENT_FILE??_(e,".lensmcp","events.jsonl")}r(lensEventFile,"lensEventFile"),i(lensEventFile,"lensEventFile");const a=i((n,e,s,t,o)=>({id:x(),sessionId:n,timestamp:e,source:N,category:"runtime",severity:"info",context:{sessionId:n},fingerprint:s,title:t,raw:o}),"lensEvent");export function dismissalEvent(n,e){return a(e,n.until,`${c}:${n.groupId}`,`error dismissed: ${n.title??n.groupId}`,{kind:c,groupId:n.groupId,until:n.until,eventIds:n.eventIds,...n.by?{by:n.by}:{},...n.reason?{reason:n.reason}:{},...n.title?{title:n.title}:{}})}r(dismissalEvent,"dismissalEvent"),i(dismissalEvent,"dismissalEvent");export function restoralEvent(n,e,s){return a(e,s,`${p}:${n}`,"error restored",{kind:p,groupId:n})}r(restoralEvent,"restoralEvent"),i(restoralEvent,"restoralEvent");export function metricsChangeEvents(n,e,s){const t=n.kind===R;return(n.ids?$(n.ids):[void 0]).map(o=>a(e,s,`${n.kind}:${n.scope}`,`${t?"numbers reset":"numbers counted whole again"}: ${n.scope}${o?` \xB7 ${o.length}`:" \xB7 all"}`,{kind:n.kind,scope:n.scope,...t?{at:s}:{},...o?{ids:o}:{}}))}r(metricsChangeEvents,"metricsChangeEvents"),i(metricsChangeEvents,"metricsChangeEvents");const d=i((n,e,s)=>{const t=Number(process.env[n]);return Number.isFinite(t)&&s(t)?t:e},"envNumber");export function appendBusEvents(n,e){e.length!==0&&(S(g(n),{recursive:!0}),b(n,{maxBytes:d("LENSMCP_EVENT_MAX_BYTES",50*1024*1024,s=>s>0),maxFiles:d("LENSMCP_EVENT_MAX_FILES",5,s=>s>=1&&s<=20),fs:{statSync:f,renameSync:y,unlinkSync:I,openSync:v,closeSync:m}}),l(n,e.map(s=>JSON.stringify(s)+`
|
|
2
|
+
`).join("")))}r(appendBusEvents,"appendBusEvents"),i(appendBusEvents,"appendBusEvents");
|
package/lib/resource-store.d.ts
CHANGED
|
@@ -34,6 +34,16 @@ export interface ResourceStoreOptions {
|
|
|
34
34
|
* says which resource it was rebuilding (issues/closed/overseer-12). Begin a span; call what it returns at the end.
|
|
35
35
|
*/
|
|
36
36
|
work?: (what: string) => () => void;
|
|
37
|
+
/**
|
|
38
|
+
* Recompute a resource on its marks only while someone subscribes to it (false, the default: on every mark). A mark
|
|
39
|
+
* of one no one subscribes to only marks it stale; the next read that produces it recomputes it — revision bump and
|
|
40
|
+
* notification included, as a mark would have — and a first subscriber to a stale one gets its recompute at once.
|
|
41
|
+
* FoodGuard's dashboard, 2026-11-03: it subscribes to 25 resources, yet every mark of the others was produced and
|
|
42
|
+
* serialised for no one — catalog://sql, routes://lint, db://lint, the event-loop stalls, and kv://lint and
|
|
43
|
+
* queues://lint with a Redis census each — ~20 s of event-loop holds that day, ~35 s the day before (catalog://sql
|
|
44
|
+
* alone 22.7 s).
|
|
45
|
+
*/
|
|
46
|
+
lazy?: boolean;
|
|
37
47
|
}
|
|
38
48
|
/**
|
|
39
49
|
* The resource store. URIs are registered once; reading is cheap; the
|
|
@@ -52,6 +62,7 @@ export declare class ResourceStore {
|
|
|
52
62
|
/** What the last recompute of each URI took (produce + serialise), in ms. */
|
|
53
63
|
private readonly lastCost;
|
|
54
64
|
private readonly work;
|
|
65
|
+
private readonly lazy;
|
|
55
66
|
constructor(opts?: ResourceStoreOptions);
|
|
56
67
|
register(uri: string, produce: ResourceProducer): Unsubscribe;
|
|
57
68
|
read(uri: string): Promise<ResourceValue>;
|
|
@@ -59,20 +70,31 @@ export declare class ResourceStore {
|
|
|
59
70
|
* The resource as produced at most `maxAgeMs` ago — by its own recompute or a read — else produced now. For a reader
|
|
60
71
|
* that can take it that old and reads it as part of its own recompute: `agent://current-status` reads ~13 signal
|
|
61
72
|
* resources each time, and `read` produced each whole again (routes lint, the SQL lint…) — 2.6 GB of allocation a
|
|
62
|
-
* minute on FoodGuard's traffic (foodguard-72). The value is shared: never changed in place.
|
|
73
|
+
* minute on FoodGuard's traffic (foodguard-72). The value is shared: never changed in place. A stale resource (`lazy`)
|
|
74
|
+
* too is handed as produced within `maxAgeMs`, and recomputed past it.
|
|
63
75
|
*/
|
|
64
76
|
readRecent(uri: string, maxAgeMs: number): Promise<ResourceValue>;
|
|
77
|
+
/**
|
|
78
|
+
* What the resource produced last — by a recompute or a read — whatever its age; undefined before the first. Never
|
|
79
|
+
* produces it: for a reader that must not start the producer's work, and takes the last value it settled on —
|
|
80
|
+
* `agent://current-status` reading `kv://lint`, whose producer runs a Redis census. Shared: never changed in place.
|
|
81
|
+
*/
|
|
82
|
+
latest(uri: string): ResourceValue | undefined;
|
|
83
|
+
/** Marked since its last recompute, with no one subscribed (`lazy`): its revision waits for the next read. */
|
|
84
|
+
isStale(uri: string): boolean;
|
|
65
85
|
list(): string[];
|
|
66
86
|
/**
|
|
67
87
|
* Recompute the JSON, bump the revision counter if it differs, and
|
|
68
88
|
* notify subscribers. No-op if the URI is unknown or the JSON didn't
|
|
69
|
-
* change.
|
|
89
|
+
* change. In a `lazy` store, a resource no one subscribes to is only
|
|
90
|
+
* marked stale: its next read recomputes it.
|
|
70
91
|
*/
|
|
71
92
|
markDirty(uri: string): Promise<void>;
|
|
72
93
|
/** How long after its last recompute a URI may be recomputed again. */
|
|
73
94
|
private gapFor;
|
|
74
95
|
/** What the last recompute of a URI took, in ms (produce + serialise) — undefined before the first. */
|
|
75
96
|
cost(uri: string): number | undefined;
|
|
97
|
+
/** Produce it, and — when its JSON changed — bump its revision and notify its subscribers. Resolves to what it produced. */
|
|
76
98
|
private recompute;
|
|
77
99
|
revision(uri: string): number | undefined;
|
|
78
100
|
subscribe(uri: string, handler: ResourceUpdatedHandler): Unsubscribe;
|
package/lib/resource-store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var u=(o,t)=>d(o,"name",{value:t,configurable:!0});var w=Object.defineProperty,l=u((o,t)=>w(o,"name",{value:t,configurable:!0}),"c");export class ResourceStore{static{u(this,"ResourceStore")}static{l(this,"ResourceStore")}constructor(t={}){this.entries=new Map,this.subs=new Map,this.queued=new Map,this.lastRun=new Map,this.lastCost=new Map,this.coalesceMs=Math.max(0,t.coalesceMs??0),this.costFactor=Math.max(0,t.costFactor??0),this.maxGapMs=Math.max(0,t.maxGapMs??3e4),this.work=t.work,this.lazy=t.lazy===!0}register(t,e){if(this.entries.has(t))throw new Error(`Resource already registered: ${t}`);return this.entries.set(t,{uri:t,produce:e,revision:0}),()=>{this.entries.delete(t),this.subs.delete(t),this.lastRun.delete(t),this.lastCost.delete(t)}}async read(t){const e=this.entries.get(t);if(!e)throw new Error(`Unknown resource: ${t}`);if(e.stale)return this.recompute(t);const s=await e.produce();return e.produced={at:Date.now(),value:s},s}async readRecent(t,e){const s=this.entries.get(t);if(!s)throw new Error(`Unknown resource: ${t}`);return s.produced&&Date.now()-s.produced.at<=e?s.produced.value:this.read(t)}latest(t){const e=this.entries.get(t);if(!e)throw new Error(`Unknown resource: ${t}`);return e.produced?.value}isStale(t){return this.entries.get(t)?.stale===!0}list(){return[...this.entries.keys()]}markDirty(t){const e=this.entries.get(t);if(e&&this.lazy&&!this.subs.get(t)?.size)return e.stale=!0,Promise.resolve();if(this.coalesceMs===0&&this.costFactor===0)return this.recompute(t).then(()=>{});if(!e)return Promise.resolve();const s=this.queued.get(t);if(s)return s;const n=Math.max(0,(this.lastRun.get(t)??Number.NEGATIVE_INFINITY)+this.gapFor(t)-Date.now()),a=new Promise(r=>{const i=l(()=>{this.queued.delete(t),this.lastRun.set(t,Date.now()),this.recompute(t).then(()=>r(),()=>r())},"go");n===0?setImmediate(i):setTimeout(i,n).unref?.()});return this.queued.set(t,a),a}gapFor(t){const e=this.lastCost.get(t)??0;return Math.max(this.coalesceMs,Math.min(this.maxGapMs,this.costFactor*e))}cost(t){return this.lastCost.get(t)}async recompute(t){const e=this.entries.get(t);if(!e)return;const s=performance.now(),n=this.work?.(`recompute ${t}`),a=e.stale===!0;e.stale=!1;let r,i;try{r=await e.produce(),e.produced={at:Date.now(),value:r},i=JSON.stringify(r)}catch(c){throw a&&(e.stale=!0),c}finally{n?.()}if(this.lastCost.set(t,performance.now()-s),i===e.lastJson)return r;e.lastJson=i,e.revision+=1;const h=this.subs.get(t);if(h)for(const c of h)try{c(t,e.revision)}catch{}return r}revision(t){return this.entries.get(t)?.revision}subscribe(t,e){let s=this.subs.get(t);return s||(s=new Set,this.subs.set(t,s)),s.add(e),this.entries.get(t)?.stale&&this.markDirty(t).catch(()=>{}),()=>{s?.delete(e)}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/core",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.60",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@lensmcp/protocol-types": "1.25.
|
|
97
|
+
"@lensmcp/protocol-types": "1.25.60",
|
|
98
98
|
"tslib": "^2.3.0"
|
|
99
99
|
},
|
|
100
100
|
"license": "Apache-2.0",
|