mcp-event-intelligence 0.4.0 → 0.5.0

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 (40) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +102 -14
  3. package/SECURITY.md +4 -4
  4. package/bin/mcp-event-intelligence.mjs +3 -3
  5. package/dist/src/composite/engine.d.ts +6 -0
  6. package/dist/src/composite/engine.js +599 -10
  7. package/dist/src/composite/matching.js +45 -0
  8. package/dist/src/intelligenceProtocol/activationSchemas.d.ts +2 -0
  9. package/dist/src/intelligenceProtocol/activationSchemas.js +1 -0
  10. package/dist/src/intelligenceProtocol/index.d.ts +9 -2
  11. package/dist/src/intelligenceProtocol/index.js +5 -1
  12. package/dist/src/intelligenceProtocol/operatorRegistry.d.ts +567 -0
  13. package/dist/src/intelligenceProtocol/operatorRegistry.js +477 -0
  14. package/dist/src/intelligenceProtocol/patternV2Schemas.d.ts +188 -0
  15. package/dist/src/intelligenceProtocol/patternV2Schemas.js +801 -0
  16. package/dist/src/intelligenceProtocol/schemas.d.ts +4 -0
  17. package/dist/src/intelligenceProtocol/schemas.js +2 -0
  18. package/dist/src/intelligenceProtocol/triggerPlanSchemas.d.ts +177 -4
  19. package/dist/src/intelligenceProtocol/triggerPlanSchemas.js +37 -4
  20. package/dist/src/intelligenceProtocol/triggerSchemas.d.ts +256 -0
  21. package/dist/src/intelligenceProtocol/triggerSchemas.js +161 -2
  22. package/dist/src/mcpEvents/consumer.d.ts +1 -0
  23. package/dist/src/mcpEvents/consumer.js +1 -0
  24. package/dist/src/patternV2/evaluator.d.ts +43 -0
  25. package/dist/src/patternV2/evaluator.js +927 -0
  26. package/dist/src/patternV2/legacyCompiler.d.ts +3 -0
  27. package/dist/src/patternV2/legacyCompiler.js +184 -0
  28. package/package.json +5 -2
  29. package/scripts/host-integration.d.mts +7 -0
  30. package/scripts/host-integration.mjs +9 -0
  31. package/scripts/lib/activation-hydrator.mjs +1 -0
  32. package/scripts/lib/composite-event-consumer.mjs +2 -0
  33. package/scripts/lib/derived-event-coordinator.mjs +75 -1
  34. package/scripts/lib/mcp-events-client.mjs +62 -24
  35. package/scripts/lib/mcp-events-compatibility.mjs +54 -0
  36. package/scripts/lib/trigger-control-plane.mjs +154 -0
  37. package/scripts/lib/trigger-inspector.mjs +15 -0
  38. package/scripts/lib/trigger-planner.mjs +190 -12
  39. package/scripts/mcp-stdio-server.mjs +38 -53
  40. package/server.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,64 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0] - 2026-09-30
4
+
5
+ ### Pattern AST v2 / advanced CEP
6
+
7
+ - add additive recursive Pattern AST v2 while keeping legacy composite triggers executable;
8
+ - add nested `allOf` / `anyOf` / `sequence`, explicit `next` / `followedBy` / `followedByAny` contiguity, repeat/optional quantifiers and greedy/lazy matching;
9
+ - add bounded negative patterns (`notNext`, `notFollowedBy`) and first-class calendar/absence/debounce/rate/distinct temporal nodes;
10
+ - add within/sliding/tumbling/hopping/session/count windows;
11
+ - add cross-event arithmetic comparisons plus startsWith/endsWith/regex/notIn/between/isNull/type predicates;
12
+ - add sum/avg/min/max/count/countDistinct/first/last/nth/stddev/percentile aggregates and derived-event measures;
13
+ - add changed/changedFrom/increasedBy/decreasedBy/delta/percentChange/stableFor/crossesAbove/crossesBelow state operators;
14
+ - add partitioned durable CEP buffers, overlap/after-match selection policies, bounded candidate budgets and bounded event-time retention;
15
+ - add vendor-neutral first-class `semantic` nodes behind `SemanticEvaluator`; TypeSafe Jev remains optional and explicit;
16
+ - enforce per-node semantic timeout, trigger-level semantic-evaluation budgets and audit every semantic decision, including rejects;
17
+ - validate Pattern v2 refs, partition dimensions, durations, payload paths and derived measures against live source contracts;
18
+ - add `compileLegacyTriggerToPatternV2()` for compatibility/migration and differential verification;
19
+ - expose the complete v2 language through `describeTriggerLanguage()` / `trigger_language_describe`;
20
+ - add end-to-end coverage for advanced predicates, quantifiers, contiguity, windows, arithmetic, state, semantic evaluation, partition isolation, negative deadlines and derived measures.
21
+
22
+ ### Event-time correctness
23
+
24
+ - preserve host `receivedAt` separately from provider `occurredAt` through correlation evidence, derived lineage and activation hydration;
25
+ - sequence and window evaluation no longer depend on delivery order;
26
+ - partial matches are selected by compatible event-time span and can be re-anchored when an earlier event arrives late;
27
+ - add explicit `eventTime.allowedLatenessMs` watermarks for bounded late-event tolerance;
28
+ - events older than the watermark may finish retained compatible partials but cannot seed stale windows;
29
+ - late events outside `withinMs` are isolated instead of creating false composite matches.
30
+
31
+ ### Agent authoring language
32
+
33
+ - add a versioned, self-describing trigger operator registry;
34
+ - add embedded `host.describeTriggerLanguage()` / scoped discovery;
35
+ - add non-mutating MCP `trigger_language_describe` with category/operator filtering;
36
+ - make the MCP `trigger_plan` tool reuse the package's canonical `TriggerPlanInputSchema` instead of maintaining a duplicate input schema;
37
+ - expose all canonical temporal operators through `TriggerPlanInput.temporal`;
38
+ - validate temporal event references and `distinct.path` against live source schemas before compilation;
39
+ - add registry/schema parity tests so supported operators cannot silently drift out of the agent-visible catalog.
40
+
41
+ ### Trigger composition
42
+
43
+ - add explicit `conditionOnly: true` programs with no runtime target, continuation or derived output;
44
+ - agent-friendly planning can compile condition-only programs;
45
+ - identical active `(connection, event, arguments)` clauses share one upstream MCP EventSubscription with observable local fan-out count.
46
+
47
+ ### MCP Events compatibility
48
+
49
+ - external draft assumptions are centralized behind a versioned compatibility profile instead of being spread through the runtime;
50
+ - the current default profile remains the 2026-09-25 experimental extension snapshot;
51
+ - host-owned/embedded integration remains the primary architecture; standalone/provider-native paths are compatibility surfaces, not a new deployment requirement.
52
+
53
+
54
+ ### Compatibility
55
+
56
+ - Pattern AST v2 is additive; legacy composite/temporal triggers remain executable unchanged;
57
+ - the internal persisted Event Intelligence protocol/schema identifiers remain on the v0.1 compatibility line;
58
+ - `compileLegacyTriggerToPatternV2()` is available for migration/differential verification without forcing existing persisted triggers to rewrite;
59
+ - MCP Events remains experimental and isolated behind the versioned compatibility profile.
60
+
61
+
3
62
  ## [0.4.0] - 2026-09-25
4
63
 
5
64
  Current MCP Events draft alignment.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![CI](https://github.com/sarooo17/event-intelligence/actions/workflows/ci.yml/badge.svg)](https://github.com/sarooo17/event-intelligence/actions/workflows/ci.yml)
6
6
  [![npm](https://img.shields.io/npm/v/mcp-event-intelligence.svg)](https://www.npmjs.com/package/mcp-event-intelligence)
7
- [![MCP Registry](https://img.shields.io/badge/MCP%20Registry-v0.4.0-5b5bd6)](https://registry.modelcontextprotocol.io/?q=io.github.sarooo17%2Fevent-intelligence)
7
+ [![MCP Registry](https://img.shields.io/badge/MCP%20Registry-v0.5.0-5b5bd6)](https://registry.modelcontextprotocol.io/?q=io.github.sarooo17%2Fevent-intelligence)
8
8
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
9
9
 
10
10
  MCP Event Intelligence is an experimental event runtime for agents that need to react to **future conditions over multiple event sources** without keeping an LLM or agent loop alive.
@@ -19,7 +19,7 @@ An agent can express an intent such as:
19
19
 
20
20
  > When this PR is merged, the production deploy succeeds, and no error is observed for 10 minutes, wake this task and review the release.
21
21
 
22
- Event Intelligence persists that continuation independently of the model, waits for the world to satisfy it, and wakes the host only when necessary.
22
+ Event Intelligence persists the future condition independently of the model, waits for the world to satisfy it, and wakes the host only when the condition has an activation target. Conditions may also exist without an agent continuation; higher-level facts are composed separately through derived-event triggers.
23
23
 
24
24
  ## Embed it in an existing agent host
25
25
 
@@ -59,7 +59,17 @@ Event Intelligence enumerates the host registry automatically. GitHub, Gmail, pr
59
59
 
60
60
  ### Agent-first trigger flow
61
61
 
62
- Agents no longer need to construct the low-level trigger DSL directly for common cases. Ask EI to compile an agent-friendly plan against the event sources that are actually available:
62
+ Agents do not need to construct the low-level trigger DSL directly. The public authoring flow is self-describing: discover the live event sources, inspect the trigger language only when needed, then ask EI to compile an agent-friendly plan against the sources that are actually available:
63
+
64
+ ```js
65
+ const temporalLanguage = ei.describeTriggerLanguage({
66
+ category: 'temporal',
67
+ });
68
+
69
+ // returns the supported temporal operators, required fields and examples
70
+ ```
71
+
72
+ The same catalog is available through the optional MCP control plane as `trigger_language_describe`. This keeps operator discovery out of the agent's permanent prompt/context and makes new operators discoverable on demand.
63
73
 
64
74
  ```js
65
75
  const plan = await ei.planTrigger({
@@ -91,9 +101,78 @@ await ei.triggerControl.createTrigger({
91
101
  });
92
102
  ```
93
103
 
94
- `planTrigger()` is deterministic. It does not call a model. It resolves event names to live source/server IDs, validates predicate paths against advertised payload schemas, compiles `all` / `any` / `sequence` / `count`, and returns the canonical trigger definition plus the required connection IDs.
104
+ `planTrigger()` is deterministic. It does not call a model. It resolves event names to live source/server IDs, validates predicate paths against advertised payload schemas, compiles `all` / `any` / `sequence` / `count`, accepts the canonical temporal operator set (`calendar`, `absence`, `not`, `unless`, `after`, `until`, `debounce`, `threshold`, `rate`, `distinct`), and returns the canonical trigger definition plus the required connection IDs.
105
+
106
+ The canonical trigger definition remains the engine IR/advanced API. Agents should normally author through `planTrigger()` / `trigger_plan`, using `describeTriggerLanguage()` / `trigger_language_describe` for operator discovery.
107
+
108
+ ### Pattern AST v2: advanced CEP
109
+
110
+ For advanced event programs, `TriggerPlanInput.patternV2` is the preferred authoring surface. Event declarations still describe discovered MCP event sources once; the recursive AST refers to those aliases and composes them without duplicating transport/provider configuration.
111
+
112
+ ```js
113
+ const plan = await ei.planTrigger({
114
+ events: [
115
+ { id: 'order', event: 'erpnext.sales_order.created' },
116
+ { id: 'failure', event: 'payments.failed' },
117
+ { id: 'ticket', event: 'support.ticket.created' },
118
+ ],
119
+ withinMs: 30 * 60 * 1000,
120
+ patternV2: {
121
+ version: '2',
122
+ partitionBy: [{
123
+ key: 'customer',
124
+ fields: [
125
+ { ref: 'order', path: 'customer' },
126
+ { ref: 'failure', path: 'customer' },
127
+ { ref: 'ticket', path: 'customer' },
128
+ ],
129
+ }],
130
+ root: {
131
+ kind: 'aggregate',
132
+ function: 'sum',
133
+ ref: 'order',
134
+ path: 'grand_total',
135
+ op: 'gte',
136
+ value: 10000,
137
+ child: {
138
+ kind: 'sequence',
139
+ contiguity: 'followedBy',
140
+ children: [
141
+ { kind: 'event', ref: 'order' },
142
+ {
143
+ kind: 'repeat',
144
+ child: { kind: 'event', ref: 'failure' },
145
+ min: 2,
146
+ max: 5,
147
+ mode: 'greedy',
148
+ },
149
+ {
150
+ kind: 'optional',
151
+ child: { kind: 'event', ref: 'ticket' },
152
+ mode: 'greedy',
153
+ },
154
+ ],
155
+ },
156
+ },
157
+ },
158
+ target: {
159
+ runtime: 'agent',
160
+ kind: 'conversation',
161
+ id: 'chat-42',
162
+ },
163
+ continuation: {
164
+ instruction: 'Review this customer payment-risk pattern.',
165
+ },
166
+ });
167
+ ```
168
+
169
+ Pattern AST v2 adds nested boolean/sequence patterns, strict and relaxed contiguity, repeat/optional quantifiers, negative look-ahead, streaming windows, cross-event comparisons, aggregates, state-transition operators, partitioning, overlap/after-match policies and deterministic derived measures.
170
+
171
+ The runtime is **deterministic first**. A first-class `semantic` node is available only when structural data cannot express the condition reliably. It is vendor-neutral and calls the configured `SemanticEvaluator`; the bundled TypeSafe Jev adapter is optional when `TYPESAFE_API_KEY` is present. Semantic calls are explicit, bounded, timed out and audit-recorded; ordinary CEP execution requires no model API.
95
172
 
96
- The persisted `continuation` answers a separate question from the trigger condition: **what should the agent do after the future condition becomes true?**
173
+ Legacy `expression + temporal + correlation` triggers remain supported. `compileLegacyTriggerToPatternV2()` provides an additive compatibility path rather than forcing stored v1 triggers to migrate synchronously.
174
+
175
+ The persisted `continuation` answers a separate question from the trigger condition: **what should the agent do after the future condition becomes true?** A trigger can instead set `conditionOnly: true` and persist only the condition state, with no runtime target or continuation.
97
176
 
98
177
  The wire wake remains deliberately small and reference-only. Embedded hosts also receive an Activation Envelope as the second wake argument. The same envelope can be reconstructed later:
99
178
 
@@ -215,6 +294,7 @@ production ERP connector itself.
215
294
  - `events/poll` with server-directed `nextPollMs`, nullable cursors and bounded page draining;
216
295
  - host-owned push and webhook delivery adapters feeding the same EventOccurrence pipeline;
217
296
  - persistent opaque cursors and per-subscription delivery state;
297
+ - shared upstream subscriptions fan out to every active trigger using the same `(connection, event, arguments)` tuple;
218
298
  - per-scope source/cursor isolation for shared hosts;
219
299
  - single-flight polling per connection plus bounded `hasMore` batch draining;
220
300
  - automatic event-source registration;
@@ -244,7 +324,7 @@ Poll, push and webhook are treated only as delivery mechanisms. All three normal
244
324
  - event-source discovery;
245
325
  - agent-friendly deterministic trigger planning/compilation;
246
326
  - MCP subscription `arguments` validated against each source `inputSchema`, kept distinct from EI payload predicates;
247
- - `eq`, `neq`, `contains`, `in`, `exists`, `gt`, `gte`, `lt`, `lte` predicates;
327
+ - structured predicates including `eq`, `neq`, `contains`, `startsWith`, `endsWith`, `regex`, `in`, `notIn`, `between`, `exists`, `isNull`, `type`, `gt`, `gte`, `lt`, `lte`;
248
328
  - persisted continuation contracts separated from trigger conditions;
249
329
  - Activation Envelope hydration with matched event evidence;
250
330
  - embedded wake callbacks receive `(packet, activation)`;
@@ -306,10 +386,12 @@ This project does **not** propose a replacement for MCP Events and does not clai
306
386
 
307
387
  ## AI and API keys
308
388
 
309
- Event Intelligence has one optional AI boundary: **semantic correlation**.
389
+ Event Intelligence has one optional AI boundary: **explicit semantic evaluation**.
310
390
 
311
- - `TYPESAFE_API_KEY` enables the bundled TypeSafe Jev evaluator when a trigger explicitly requests semantic correlation.
391
+ - Pattern AST v2 exposes a vendor-neutral `semantic` node; legacy `semanticCorrelation` is the compatibility form.
392
+ - `TYPESAFE_API_KEY` enables the bundled TypeSafe Jev evaluator when a trigger explicitly requests semantic evaluation.
312
393
  - embedded hosts may inject a compatible `semanticEvaluator` instead.
394
+ - deterministic predicates, patterns, windows, aggregations, state changes, deadlines and derived measures never require an AI evaluator.
313
395
  - there is no bundled OpenAI planner and no OpenAI API dependency.
314
396
 
315
397
  The agent/harness is already responsible for natural-language reasoning. It can use `trigger_plan` / `planTrigger()` to compile common requests deterministically against discovered source schemas, or submit a canonical trigger definition directly for advanced cases. Deterministic correlation, temporal logic, persistence, derived events and wake delivery require no model API.
@@ -334,7 +416,9 @@ The v0.4 acceptance suite verifies:
334
416
 
335
417
  A separate live regression also verified real GitHub webhook ingress into the MCP EventOccurrence / composite fan-in path.
336
418
 
337
- ## Standalone reference service
419
+ ## Reference/debug service
420
+
421
+ The HTTP service remains useful for local development, conformance work and provider-native regression tests. It is **not** the primary integration model and does not replace the embedded host-owned package path above.
338
422
 
339
423
  ### Requirements
340
424
 
@@ -362,13 +446,13 @@ The standalone service supports manual/provider-native event ingress. It does no
362
446
  ### Docker
363
447
 
364
448
  ```bash
365
- docker build -t mcp-event-intelligence:0.4.0 .
449
+ docker build -t mcp-event-intelligence:0.5.0 .
366
450
 
367
451
  docker run --rm \
368
452
  -p 3000:3000 \
369
453
  -v mcp-event-intelligence-data:/data \
370
454
  -e SERVICE_AUTH_TOKEN="$(openssl rand -hex 32)" \
371
- mcp-event-intelligence:0.4.0
455
+ mcp-event-intelligence:0.5.0
372
456
  ```
373
457
 
374
458
  ## Optional MCP control plane
@@ -414,7 +498,11 @@ The detailed execution model, clocks, lifecycle, persistence and trust boundarie
414
498
 
415
499
  ### Event-time vs processing-time
416
500
 
417
- Normal event windows use event `occurredAt`.
501
+ Normal event windows use event `occurredAt`; MCP ingress also preserves host `receivedAt` when available. Delivery order does not define event order.
502
+
503
+ Out-of-order events are matched against compatible event-time windows. A late event may re-anchor a partial match to an earlier `occurredAt` only when the complete event-time span still fits `withinMs`; otherwise it starts a separate partial window and cannot create a false sequence.
504
+
505
+ Triggers may set `eventTime.allowedLatenessMs` (default `0`). EI maintains an event-time watermark per trigger/correlation stream: old partial windows are retained until their expiry falls behind `maxObservedEventTime - allowedLatenessMs`. An event older than the watermark can still complete a retained compatible partial, but cannot seed a new stale window.
418
506
 
419
507
  Absence/deadline progression uses Event Intelligence processing time. This separation is explicit and tested.
420
508
 
@@ -432,7 +520,7 @@ It uses stable wake IDs, persisted delivery state, atomic claim leases, bounded
432
520
 
433
521
  A derived event says **what became true at a point in history**.
434
522
 
435
- v0.3 intentionally does not implement a mutable current-state/facts database.
523
+ Event Intelligence intentionally does not implement a mutable current-state/facts database.
436
524
 
437
525
  ## Security
438
526
 
@@ -457,7 +545,7 @@ io.github.sarooo17/event-intelligence
457
545
 
458
546
  ## Project status
459
547
 
460
- **v0.4.x reference implementation / experimental.**
548
+ **v0.5.x reference implementation / experimental.**
461
549
 
462
550
  The architecture is implemented and exercised end-to-end. Storage is now injectable and scoped, while the bundled JSONL backend remains a single-process reference implementation. Remaining work is primarily production database adapters/HA validation, scale benchmarks and upstream feedback.
463
551
 
package/SECURITY.md CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  ## Supported versions
4
4
 
5
- The public package is pre-1.0. Security fixes are supported on the current 0.3.x line.
5
+ The public package is pre-1.0. Security fixes are supported on the current 0.5.x line.
6
6
 
7
7
  | Version | Supported |
8
8
  | --- | --- |
9
- | 0.3.x | Yes |
10
- | < 0.3 | No |
9
+ | 0.5.x | Yes |
10
+ | < 0.5 | No |
11
11
 
12
12
  ## Reporting a vulnerability
13
13
 
@@ -26,7 +26,7 @@ Useful reports include:
26
26
 
27
27
  ## Security boundaries
28
28
 
29
- Event Intelligence 0.3.x is an experimental reference implementation with scoped multi-tenant host support. It is not a turnkey hardened hosted service.
29
+ Event Intelligence 0.5.x is an experimental reference implementation with scoped multi-tenant host support. It is not a turnkey hardened hosted service.
30
30
 
31
31
  Important defaults and constraints:
32
32
 
@@ -4,14 +4,14 @@ const args = process.argv.slice(2);
4
4
  const flags = new Set(args);
5
5
 
6
6
  if (flags.has('--version') || flags.has('-v')) {
7
- console.log('0.4.0');
7
+ console.log('0.5.0');
8
8
  process.exit(0);
9
9
  }
10
10
 
11
11
  if (flags.has('--help') || flags.has('-h')) {
12
- console.log(`MCP Event Intelligence v0.4
12
+ console.log(`MCP Event Intelligence v0.5
13
13
 
14
- Durable temporal event intelligence for sleeping agents.
14
+ MCP-native complex event processing for durable agents.
15
15
 
16
16
  Usage:
17
17
  mcp-event-intelligence Start the HTTP reference service
@@ -19,8 +19,14 @@ export declare class CompositeTriggerEngine {
19
19
  markFired(matchId: string, wakeId: string): Promise<TriggerMatchRecord>;
20
20
  markDerivedEmitted(matchId: string, derivedEventId: string): Promise<TriggerMatchRecord>;
21
21
  private ingestTimerEvent;
22
+ private patternPartitionKey;
23
+ private patternBufferId;
24
+ private patternDecisionRecord;
25
+ private applyPatternV2;
26
+ private evaluatePatternV2Buffer;
22
27
  private applyEvent;
23
28
  private finalizeEligible;
29
+ private branchMatch;
24
30
  private newMatch;
25
31
  private latestMatch;
26
32
  }