rudow-local-mcp 0.1.1 → 0.1.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.
Files changed (2) hide show
  1. package/dist/incidents.js +44 -12
  2. package/package.json +1 -1
package/dist/incidents.js CHANGED
@@ -11,6 +11,12 @@
11
11
  // A bucket fires an incident when it has enough errors and its error
12
12
  // rate clearly exceeds baseline. Neighbouring firing buckets merge
13
13
  // into one incident. Nothing here calls a model or the network.
14
+ //
15
+ // Baselines are computed from clean buckets only: firing buckets are
16
+ // excluded from the baseline median. A sustained spike would otherwise
17
+ // inflate its own baseline and mask its early buckets, so the firing
18
+ // set is computed iteratively until it stops growing (see
19
+ // detectForSource).
14
20
  import { errorRate, isError, latencyStats, normalizeMessage, round, topErrors, } from "./metrics.js";
15
21
  function median(values) {
16
22
  if (values.length === 0)
@@ -49,41 +55,44 @@ function makeBuckets(entries) {
49
55
  }
50
56
  return buckets;
51
57
  }
52
- function baselineRates(buckets, index) {
58
+ function baselineRates(buckets, index, firing) {
53
59
  const rates = [];
54
60
  for (let i = 0; i < buckets.length; i += 1) {
55
61
  if (i === index)
56
62
  continue;
63
+ if (firing && firing[i])
64
+ continue;
57
65
  if (buckets[i].entries.length >= 3)
58
66
  rates.push(errorRate(buckets[i].entries));
59
67
  }
60
68
  return rates;
61
69
  }
62
- function baselineVolumes(buckets, index) {
70
+ function baselineVolumes(buckets, index, firing) {
63
71
  const volumes = [];
64
72
  for (let i = 0; i < buckets.length; i += 1) {
65
73
  if (i === index)
66
74
  continue;
75
+ if (firing && firing[i])
76
+ continue;
67
77
  volumes.push(buckets[i].entries.length);
68
78
  }
69
79
  return volumes;
70
80
  }
71
- function baselineP95(buckets, index) {
81
+ function baselineP95(buckets, index, firing) {
72
82
  const values = [];
73
83
  for (let i = 0; i < buckets.length; i += 1) {
74
84
  if (i === index)
75
85
  continue;
86
+ if (firing && firing[i])
87
+ continue;
76
88
  const p95 = latencyStats(buckets[i].entries).p95Ms;
77
89
  if (p95 !== null)
78
90
  values.push(p95);
79
91
  }
80
92
  return values.length > 0 ? median(values) : null;
81
93
  }
82
- function detectForSource(source, entries) {
83
- const buckets = makeBuckets(entries);
84
- if (buckets.length < 3)
85
- return [];
86
- const firing = buckets.map((bucket, i) => {
94
+ function firingPass(buckets, firing) {
95
+ return buckets.map((bucket, i) => {
87
96
  if (bucket.errors.length < 3)
88
97
  return false;
89
98
  if (bucket.entries.length < 5)
@@ -91,9 +100,32 @@ function detectForSource(source, entries) {
91
100
  const rate = errorRate(bucket.entries);
92
101
  if (rate < 0.25)
93
102
  return false;
94
- const baseline = Math.max(median(baselineRates(buckets, i)), 0.02);
103
+ const baseline = Math.max(median(baselineRates(buckets, i, firing ?? undefined)), 0.02);
95
104
  return rate >= 2 * baseline;
96
105
  });
106
+ }
107
+ function sameFiring(a, b) {
108
+ return a.length === b.length && a.every((value, i) => value === b[i]);
109
+ }
110
+ function detectForSource(source, entries) {
111
+ const buckets = makeBuckets(entries);
112
+ if (buckets.length < 3)
113
+ return [];
114
+ // Compute firing iteratively. The first pass uses the plain baseline
115
+ // (all other buckets); later passes exclude firing buckets from the
116
+ // baseline, so a sustained spike stops inflating its own baseline
117
+ // and its early buckets start firing. Excluding firing buckets can
118
+ // only lower the baseline, so the firing set only grows and this
119
+ // reaches a fixed point within a few passes.
120
+ let firing = firingPass(buckets, null);
121
+ let next = firingPass(buckets, firing);
122
+ let guard = 0;
123
+ while (!sameFiring(firing, next) && guard < buckets.length + 1) {
124
+ firing = next;
125
+ next = firingPass(buckets, firing);
126
+ guard += 1;
127
+ }
128
+ firing = next;
97
129
  const incidents = [];
98
130
  let i = 0;
99
131
  while (i < buckets.length) {
@@ -108,11 +140,11 @@ function detectForSource(source, entries) {
108
140
  const groupEntries = group.flatMap((b) => b.entries);
109
141
  const groupErrors = group.flatMap((b) => b.errors);
110
142
  const observedRate = errorRate(groupEntries);
111
- const baseline = Math.max(median(group.flatMap((_, k) => baselineRates(buckets, i + k))), 0.02);
112
- const usualVolume = median(baselineVolumes(buckets, i));
143
+ const baseline = Math.max(median(group.flatMap((_, k) => baselineRates(buckets, i + k, firing))), 0.02);
144
+ const usualVolume = median(baselineVolumes(buckets, i, firing));
113
145
  const groupVolume = groupEntries.length / group.length;
114
146
  const groupP95 = latencyStats(groupEntries).p95Ms;
115
- const usualP95 = baselineP95(buckets, i);
147
+ const usualP95 = baselineP95(buckets, i, firing);
116
148
  const signals = [
117
149
  {
118
150
  signal: "error_rate_spike",
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"Rudow","bin":{"rudow-local-mcp":"dist/index.js"},"dependencies":{"@modelcontextprotocol/sdk":"^1.17.0"},"description":"Local-first MCP server that lets your AI coding agent read your own log files. No account, no cloud, nothing leaves the machine.","devDependencies":{"@types/node":"^22.0.0","typescript":"^5.6.0"},"engines":{"node":">=18"},"files":["dist","examples"],"homepage":"https://rudow.ai","keywords":["mcp","mcp-server","model-context-protocol","rudow","logs","observability","local-first"],"license":"MIT","name":"rudow-local-mcp","repository":{"type":"git","url":"git+https://github.com/Markera-OU/rudow-local-mcp.git"},"scripts":{"build":"tsc","start":"node dist/index.js","test":"npm run build && node --test test/*.test.mjs"},"type":"module","version":"0.1.1"}
1
+ {"author":"Rudow","bin":{"rudow-local-mcp":"dist/index.js"},"dependencies":{"@modelcontextprotocol/sdk":"^1.17.0"},"description":"Local-first MCP server that lets your AI coding agent read your own log files. No account, no cloud, nothing leaves the machine.","devDependencies":{"@types/node":"^22.0.0","typescript":"^5.6.0"},"engines":{"node":">=18"},"files":["dist","examples"],"homepage":"https://rudow.ai","keywords":["mcp","mcp-server","model-context-protocol","rudow","logs","observability","local-first"],"license":"MIT","name":"rudow-local-mcp","repository":{"type":"git","url":"git+https://github.com/Markera-OU/rudow-local-mcp.git"},"scripts":{"build":"tsc","start":"node dist/index.js","test":"npm run build && node --test test/*.test.mjs"},"type":"module","version":"0.1.2"}