@lensmcp/core 1.23.2 → 1.23.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bus-rotation.d.ts +37 -0
- package/lib/bus-rotation.js +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-process rotation for the shared `events.jsonl` bus (issues/foodguard/13).
|
|
3
|
+
*
|
|
4
|
+
* Many processes append to one bus file — the gateway, every pod, each session's MCP server, the
|
|
5
|
+
* capture sidecar — and each used to run its OWN rename cascade (`unlink .N`, `.N-1→.N` … `file→.1`)
|
|
6
|
+
* off its OWN size check. Two writers that both saw the file over the cap before either renamed it
|
|
7
|
+
* both cascaded: the second shifted the first's just-rotated generation down a slot, overwrote the
|
|
8
|
+
* history behind it, and rotated a near-empty live file into `.1`. That is the missing-generation
|
|
9
|
+
* signature. Serialising the cascade behind an `O_EXCL` lock file, and RE-CHECKING the size once the
|
|
10
|
+
* lock is held, makes the second writer see a fresh file and stand down.
|
|
11
|
+
*
|
|
12
|
+
* Node-only and dependency-free: the caller injects the fs primitives so the fs-tap-safe pristine
|
|
13
|
+
* references in `node-instrumentation/emit.ts` keep working. Same arrangement as `./redact`.
|
|
14
|
+
*/
|
|
15
|
+
export interface BusFs {
|
|
16
|
+
statSync(path: string): {
|
|
17
|
+
size: number;
|
|
18
|
+
mtimeMs: number;
|
|
19
|
+
};
|
|
20
|
+
renameSync(from: string, to: string): void;
|
|
21
|
+
unlinkSync(path: string): void;
|
|
22
|
+
openSync(path: string, flags: string): number;
|
|
23
|
+
closeSync(fd: number): void;
|
|
24
|
+
}
|
|
25
|
+
export interface BusRotationOptions {
|
|
26
|
+
maxBytes: number;
|
|
27
|
+
maxFiles: number;
|
|
28
|
+
fs: BusFs;
|
|
29
|
+
/** A lock older than this belongs to a writer that died mid-cascade. Default 30 s. */
|
|
30
|
+
staleLockMs?: number;
|
|
31
|
+
}
|
|
32
|
+
export type BusRotationResult = 'rotated' | 'not-needed' | 'busy';
|
|
33
|
+
/**
|
|
34
|
+
* Rotate `file` if it is over `maxBytes`. `busy` means another writer holds the cascade — it will do
|
|
35
|
+
* the work, so the caller just carries on. Never throws.
|
|
36
|
+
*/
|
|
37
|
+
export declare function rotateBusFile(file: string, opts: BusRotationOptions): BusRotationResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var y=(t,c)=>u(t,"name",{value:c,configurable:!0});var l=Object.defineProperty,f=y((t,c)=>l(t,"name",{value:c,configurable:!0}),"o");export function rotateBusFile(t,c){const{fs:e,maxBytes:i,maxFiles:o}=c,r=`${t}.rotate.lock`,s=c.staleLockMs??3e4;let a;for(let n=0;n<2&&a===void 0;n++)try{a=e.openSync(r,"wx")}catch{try{if(Date.now()-e.statSync(r).mtimeMs<=s)return"busy";e.unlinkSync(r)}catch{}}if(a===void 0)return"busy";try{try{if(e.statSync(t).size<=i)return"not-needed"}catch{return"not-needed"}try{e.unlinkSync(`${t}.${o}`)}catch{}for(let n=o-1;n>=1;n--)try{e.renameSync(`${t}.${n}`,`${t}.${n+1}`)}catch{}try{e.renameSync(t,`${t}.1`)}catch{}return"rotated"}finally{try{e.closeSync(a)}catch{}try{e.unlinkSync(r)}catch{}}}y(rotateBusFile,"rotateBusFile"),f(rotateBusFile,"rotateBusFile");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/core",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -16,10 +16,15 @@
|
|
|
16
16
|
"types": "./lib/redact.d.ts",
|
|
17
17
|
"import": "./lib/redact.js",
|
|
18
18
|
"default": "./lib/redact.js"
|
|
19
|
+
},
|
|
20
|
+
"./bus-rotation": {
|
|
21
|
+
"types": "./lib/bus-rotation.d.ts",
|
|
22
|
+
"import": "./lib/bus-rotation.js",
|
|
23
|
+
"default": "./lib/bus-rotation.js"
|
|
19
24
|
}
|
|
20
25
|
},
|
|
21
26
|
"dependencies": {
|
|
22
|
-
"@lensmcp/protocol-types": "1.23.
|
|
27
|
+
"@lensmcp/protocol-types": "1.23.4",
|
|
23
28
|
"tslib": "^2.3.0"
|
|
24
29
|
},
|
|
25
30
|
"license": "Apache-2.0",
|