wavescope-mcp 1.0.2

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.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Ricker (Mexican hat) wavelet: ψ(t) = (1 - t²) · exp(-t²/2)
3
+ */
4
+ export declare function rickerWavelet(t: number): number;
5
+ export interface WaveletCoefficients {
6
+ scales: number[];
7
+ coefficients: number[][];
8
+ }
9
+ export interface Peak {
10
+ position: number;
11
+ coefficient: number;
12
+ scale: number;
13
+ }
14
+ export type Boundary = "reflect" | "zero";
15
+ export interface CWTOptions {
16
+ boundary?: Boundary;
17
+ }
18
+ /**
19
+ * Compute the Continuous Wavelet Transform (Ricker) over the signal.
20
+ *
21
+ * For each scale a, the wavelet ψ_a(t) = (1/√a)·ψ(t/a) is convolved
22
+ * with the signal. The result for scale a at position b is:
23
+ * W(a, b) = Σ_t ψ_a(t-b) · signal[t]
24
+ *
25
+ * Boundary handling defaults to symmetric reflection; pass
26
+ * `{ boundary: "zero" }` for the older zero-pad behavior.
27
+ */
28
+ export declare function computeCWT(signal: number[], scales?: number[], options?: CWTOptions): WaveletCoefficients;
29
+ /**
30
+ * Detect local maxima in wavelet coefficient magnitudes across all scales.
31
+ *
32
+ * Returns peaks sorted by |coefficient| descending. Each peak is a
33
+ * local maximum in its scale band — meaning it's larger than its
34
+ * immediate neighbors at the same scale.
35
+ *
36
+ * Plateau handling: >= left, > right — selects the rightmost element
37
+ * of a flat plateau region.
38
+ *
39
+ * Cross-scale ridge collapse: a single structural feature produces local
40
+ * maxima at the same position across multiple scales. After magnitude
41
+ * sorting, peaks whose position is within `ridgeWindow` of an already-kept
42
+ * stronger peak are dropped, so a single spike yields one peak (the
43
+ * dominant scale) rather than one per scale.
44
+ */
45
+ export declare function detectPeaks(cwt: WaveletCoefficients, threshold: number, maxPeaks?: number, ridgeWindow?: number): Peak[];
46
+ //# sourceMappingURL=wavelet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wavelet.d.ts","sourceRoot":"","sources":["../src/wavelet.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG/C;AAqBD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,GAAE,MAAM,EAAmB,EACjC,OAAO,GAAE,UAAe,GACvB,mBAAmB,CAmCrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,mBAAmB,EACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE,MAAY,EACtB,WAAW,GAAE,MAAU,GACtB,IAAI,EAAE,CA2CR"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Ricker (Mexican hat) wavelet: ψ(t) = (1 - t²) · exp(-t²/2)
3
+ */
4
+ export function rickerWavelet(t) {
5
+ const t2 = t * t;
6
+ return (1 - t2) * Math.exp(-t2 / 2);
7
+ }
8
+ /**
9
+ * Generate wavelet kernel values for scale a, centered at 0.
10
+ * Truncated to ±5a (covers ~99.99% of the Ricker energy) but bounded
11
+ * by half the signal length to keep the kernel finite on short inputs.
12
+ * Includes 1/√a normalization to keep coefficient magnitudes comparable
13
+ * across scales.
14
+ */
15
+ function makeKernel(a, numPoints) {
16
+ if (!Number.isFinite(a) || a <= 0)
17
+ throw new Error(`Invalid scale: ${a}`);
18
+ const halfWidth = Math.ceil(5 * a);
19
+ const half = Math.min(halfWidth, Math.ceil(numPoints / 2));
20
+ const invSqrtA = 1 / Math.sqrt(a);
21
+ const kernel = [];
22
+ for (let t = -half; t <= half; t++) {
23
+ kernel.push(invSqrtA * rickerWavelet(t / a));
24
+ }
25
+ return kernel;
26
+ }
27
+ const DEFAULT_SCALES = [1, 2, 4, 8, 16, 32, 64, 128];
28
+ /**
29
+ * Reflect-index: mirror out-of-range indices back into [0, N-1].
30
+ * Used to suppress boundary artifacts where the wavelet's negative
31
+ * lobes would otherwise be clipped by zero-padding.
32
+ */
33
+ function reflectIndex(idx, N) {
34
+ if (N === 1)
35
+ return 0;
36
+ const period = 2 * (N - 1);
37
+ let i = idx % period;
38
+ if (i < 0)
39
+ i += period;
40
+ return i >= N ? period - i : i;
41
+ }
42
+ /**
43
+ * Compute the Continuous Wavelet Transform (Ricker) over the signal.
44
+ *
45
+ * For each scale a, the wavelet ψ_a(t) = (1/√a)·ψ(t/a) is convolved
46
+ * with the signal. The result for scale a at position b is:
47
+ * W(a, b) = Σ_t ψ_a(t-b) · signal[t]
48
+ *
49
+ * Boundary handling defaults to symmetric reflection; pass
50
+ * `{ boundary: "zero" }` for the older zero-pad behavior.
51
+ */
52
+ export function computeCWT(signal, scales = DEFAULT_SCALES, options = {}) {
53
+ const boundary = options.boundary ?? "reflect";
54
+ const N = signal.length;
55
+ const usedScales = [];
56
+ for (const a of scales) {
57
+ if (!usedScales.includes(a))
58
+ usedScales.push(a);
59
+ }
60
+ const coefficients = [];
61
+ if (N === 0) {
62
+ return { scales: usedScales, coefficients: usedScales.map(() => []) };
63
+ }
64
+ for (const a of usedScales) {
65
+ const kernel = makeKernel(a, N);
66
+ const halfKernel = Math.floor(kernel.length / 2);
67
+ const coeffs = new Array(N);
68
+ for (let pos = 0; pos < N; pos++) {
69
+ let sum = 0;
70
+ for (let k = 0; k < kernel.length; k++) {
71
+ const signalIdx = pos + k - halfKernel;
72
+ if (signalIdx >= 0 && signalIdx < N) {
73
+ sum += kernel[k] * signal[signalIdx];
74
+ }
75
+ else if (boundary === "reflect") {
76
+ sum += kernel[k] * signal[reflectIndex(signalIdx, N)];
77
+ }
78
+ }
79
+ coeffs[pos] = sum;
80
+ }
81
+ coefficients.push(coeffs);
82
+ }
83
+ return { scales: usedScales, coefficients };
84
+ }
85
+ /**
86
+ * Detect local maxima in wavelet coefficient magnitudes across all scales.
87
+ *
88
+ * Returns peaks sorted by |coefficient| descending. Each peak is a
89
+ * local maximum in its scale band — meaning it's larger than its
90
+ * immediate neighbors at the same scale.
91
+ *
92
+ * Plateau handling: >= left, > right — selects the rightmost element
93
+ * of a flat plateau region.
94
+ *
95
+ * Cross-scale ridge collapse: a single structural feature produces local
96
+ * maxima at the same position across multiple scales. After magnitude
97
+ * sorting, peaks whose position is within `ridgeWindow` of an already-kept
98
+ * stronger peak are dropped, so a single spike yields one peak (the
99
+ * dominant scale) rather than one per scale.
100
+ */
101
+ export function detectPeaks(cwt, threshold, maxPeaks = 250, ridgeWindow = 2) {
102
+ if (cwt.coefficients.length === 0)
103
+ return [];
104
+ const peaks = [];
105
+ for (let si = 0; si < cwt.scales.length; si++) {
106
+ const scale = cwt.scales[si];
107
+ const coeffs = cwt.coefficients[si];
108
+ const N = coeffs.length;
109
+ for (let pos = 0; pos < N; pos++) {
110
+ const mag = Math.abs(coeffs[pos]);
111
+ if (mag < threshold)
112
+ continue;
113
+ const leftOk = pos === 0 || mag >= Math.abs(coeffs[pos - 1]);
114
+ const rightOk = pos === N - 1 || mag > Math.abs(coeffs[pos + 1]);
115
+ if (leftOk && rightOk) {
116
+ peaks.push({
117
+ position: pos,
118
+ coefficient: coeffs[pos],
119
+ scale,
120
+ });
121
+ }
122
+ }
123
+ }
124
+ peaks.sort((a, b) => Math.abs(b.coefficient) - Math.abs(a.coefficient));
125
+ const kept = [];
126
+ for (const peak of peaks) {
127
+ let overlap = false;
128
+ for (const k of kept) {
129
+ if (Math.abs(k.position - peak.position) <= ridgeWindow) {
130
+ overlap = true;
131
+ break;
132
+ }
133
+ }
134
+ if (!overlap)
135
+ kept.push(peak);
136
+ if (kept.length >= maxPeaks)
137
+ break;
138
+ }
139
+ return kept;
140
+ }
141
+ //# sourceMappingURL=wavelet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wavelet.js","sourceRoot":"","sources":["../src/wavelet.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,CAAS;IACrC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,CAAS,EAAE,SAAiB;IAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IAC1E,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,MAAM,CAAC,IAAI,CAAC,QAAQ,GAAG,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,MAAM,CAAC;A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CAAC;IACxB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACrB,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC;gBACxD,OAAO,GAAG,IAAI,CAAC;gBACf,MAAM;YACR,CAAC;QACH,CAAC;QACD,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ;YAAE,MAAM;IACrC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "wavescope-mcp",
3
+ "version": "1.0.2",
4
+ "description": "Wavelet-based multi-resolution context management for MCP",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "bin": {
8
+ "wavescope-mcp": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "keywords": [
16
+ "mcp",
17
+ "wavelet",
18
+ "context",
19
+ "llm"
20
+ ],
21
+ "author": "",
22
+ "license": "ISC",
23
+ "devDependencies": {
24
+ "@types/node": "^25.9.1",
25
+ "@vitest/coverage-v8": "^4.1.7",
26
+ "tsx": "^4.22.3",
27
+ "typescript": "^6.0.3",
28
+ "vitest": "^4.1.7"
29
+ },
30
+ "dependencies": {
31
+ "@modelcontextprotocol/sdk": "^1.29.0",
32
+ "zod": "^4.4.3"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc",
36
+ "dev": "tsx src/index.ts",
37
+ "start": "node dist/index.js",
38
+ "test": "vitest",
39
+ "test:run": "vitest run",
40
+ "test:coverage": "vitest run --coverage",
41
+ "typecheck": "tsc --noEmit"
42
+ }
43
+ }