@a-company/paradigm 3.17.1 → 3.18.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.
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // ../paradigm-mcp/node_modules/.pnpm/@a-company+sentinel@3.5.0/node_modules/@a-company/sentinel/dist/chunk-VQ3SIN7S.js
3
+ // ../sentinel/dist/chunk-VQ3SIN7S.js
4
4
  import { v4 as uuidv4 } from "uuid";
5
5
  var DEFAULTS = {
6
6
  url: "http://localhost:3838",
@@ -413,14 +413,14 @@ function enableSentinel(logger, clientOrOptions) {
413
413
  return transport;
414
414
  }
415
415
 
416
- // ../paradigm-mcp/node_modules/.pnpm/@a-company+sentinel@3.5.0/node_modules/@a-company/sentinel/dist/chunk-FOF7CPJ6.js
416
+ // ../sentinel/dist/chunk-NTX74ZPM.js
417
417
  import initSqlJs from "sql.js";
418
418
  import { v4 as uuidv42 } from "uuid";
419
419
  import * as path from "path";
420
420
  import * as fs from "fs";
421
421
  import * as fs2 from "fs";
422
422
  import * as path2 from "path";
423
- var SCHEMA_VERSION = 4;
423
+ var SCHEMA_VERSION = 5;
424
424
  var DEFAULT_CONFIDENCE = {
425
425
  score: 50,
426
426
  timesMatched: 0,
@@ -851,6 +851,54 @@ var SentinelStorage = class {
851
851
  this.db.run(
852
852
  "INSERT OR REPLACE INTO metadata (key, value) VALUES ('schema_version', '4')"
853
853
  );
854
+ currentVersion = 4;
855
+ }
856
+ if (currentVersion < 5) {
857
+ try {
858
+ this.db.run(`
859
+ CREATE TABLE IF NOT EXISTS schemas (
860
+ id TEXT PRIMARY KEY,
861
+ version TEXT NOT NULL,
862
+ name TEXT NOT NULL,
863
+ description TEXT,
864
+ scope_json TEXT NOT NULL,
865
+ event_types_json TEXT NOT NULL,
866
+ causality_json TEXT,
867
+ visualization_json TEXT,
868
+ tags_json TEXT DEFAULT '[]',
869
+ registered_at TEXT NOT NULL,
870
+ updated_at TEXT NOT NULL
871
+ );
872
+
873
+ CREATE TABLE IF NOT EXISTS events (
874
+ id TEXT PRIMARY KEY,
875
+ schema_id TEXT NOT NULL,
876
+ event_type TEXT NOT NULL,
877
+ category TEXT NOT NULL,
878
+ timestamp TEXT NOT NULL,
879
+ scope_value TEXT,
880
+ scope_ordinal INTEGER,
881
+ session_id TEXT,
882
+ service TEXT NOT NULL,
883
+ data_json TEXT,
884
+ severity TEXT DEFAULT 'info',
885
+ parent_event_id TEXT,
886
+ depth INTEGER DEFAULT 0
887
+ );
888
+
889
+ CREATE INDEX IF NOT EXISTS idx_events_schema ON events(schema_id);
890
+ CREATE INDEX IF NOT EXISTS idx_events_type ON events(event_type);
891
+ CREATE INDEX IF NOT EXISTS idx_events_scope ON events(schema_id, scope_value);
892
+ CREATE INDEX IF NOT EXISTS idx_events_scope_ord ON events(schema_id, scope_ordinal);
893
+ CREATE INDEX IF NOT EXISTS idx_events_session ON events(session_id);
894
+ CREATE INDEX IF NOT EXISTS idx_events_timestamp ON events(timestamp);
895
+ CREATE INDEX IF NOT EXISTS idx_events_service ON events(service);
896
+ `);
897
+ } catch {
898
+ }
899
+ this.db.run(
900
+ "INSERT OR REPLACE INTO metadata (key, value) VALUES ('schema_version', '5')"
901
+ );
854
902
  }
855
903
  }
856
904
  /**
@@ -2439,6 +2487,341 @@ var SentinelStorage = class {
2439
2487
  logs: obj.log_ids_json ? JSON.parse(obj.log_ids_json) : []
2440
2488
  };
2441
2489
  }
2490
+ // ─── Schema Registry ─────────────────────────────────────────────
2491
+ registerSchema(schema) {
2492
+ this.initializeSync();
2493
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2494
+ this.db.run(
2495
+ `INSERT INTO schemas (
2496
+ id, version, name, description, scope_json, event_types_json,
2497
+ causality_json, visualization_json, tags_json, registered_at, updated_at
2498
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2499
+ ON CONFLICT(id) DO UPDATE SET
2500
+ version = excluded.version,
2501
+ name = excluded.name,
2502
+ description = excluded.description,
2503
+ scope_json = excluded.scope_json,
2504
+ event_types_json = excluded.event_types_json,
2505
+ causality_json = excluded.causality_json,
2506
+ visualization_json = excluded.visualization_json,
2507
+ tags_json = excluded.tags_json,
2508
+ updated_at = excluded.updated_at`,
2509
+ [
2510
+ schema.id,
2511
+ schema.version,
2512
+ schema.name,
2513
+ schema.description || null,
2514
+ JSON.stringify(schema.scope),
2515
+ JSON.stringify(schema.eventTypes),
2516
+ schema.causality ? JSON.stringify(schema.causality) : null,
2517
+ schema.visualization ? JSON.stringify(schema.visualization) : null,
2518
+ JSON.stringify(schema.tags || []),
2519
+ now,
2520
+ now
2521
+ ]
2522
+ );
2523
+ this.save();
2524
+ return {
2525
+ id: schema.id,
2526
+ version: schema.version,
2527
+ name: schema.name,
2528
+ description: schema.description,
2529
+ scope: schema.scope,
2530
+ eventTypes: schema.eventTypes,
2531
+ causality: schema.causality,
2532
+ visualization: schema.visualization,
2533
+ tags: schema.tags || [],
2534
+ registeredAt: now,
2535
+ updatedAt: now
2536
+ };
2537
+ }
2538
+ getSchema(id) {
2539
+ this.initializeSync();
2540
+ const result = this.db.exec("SELECT * FROM schemas WHERE id = ?", [id]);
2541
+ if (result.length === 0 || result[0].values.length === 0) return null;
2542
+ return this.rowToSchema(result[0].columns, result[0].values[0]);
2543
+ }
2544
+ listSchemas() {
2545
+ this.initializeSync();
2546
+ const result = this.db.exec("SELECT * FROM schemas ORDER BY name ASC");
2547
+ if (result.length === 0) return [];
2548
+ return result[0].values.map(
2549
+ (row) => this.rowToSchema(result[0].columns, row)
2550
+ );
2551
+ }
2552
+ rowToSchema(columns, row) {
2553
+ const obj = {};
2554
+ columns.forEach((col, i) => {
2555
+ obj[col] = row[i];
2556
+ });
2557
+ return {
2558
+ id: obj.id,
2559
+ version: obj.version,
2560
+ name: obj.name,
2561
+ description: obj.description || void 0,
2562
+ scope: JSON.parse(obj.scope_json),
2563
+ eventTypes: JSON.parse(obj.event_types_json),
2564
+ causality: obj.causality_json ? JSON.parse(obj.causality_json) : void 0,
2565
+ visualization: obj.visualization_json ? JSON.parse(obj.visualization_json) : void 0,
2566
+ tags: JSON.parse(obj.tags_json || "[]"),
2567
+ registeredAt: obj.registered_at,
2568
+ updatedAt: obj.updated_at
2569
+ };
2570
+ }
2571
+ // ─── Generic Events ────────────────────────────────────────────
2572
+ insertEventBatch(schemaId, service, inputs) {
2573
+ this.initializeSync();
2574
+ const schema = this.getSchema(schemaId);
2575
+ const typeMap = /* @__PURE__ */ new Map();
2576
+ if (schema) {
2577
+ for (const et of schema.eventTypes) {
2578
+ typeMap.set(et.type, {
2579
+ category: et.category,
2580
+ severity: et.severity || "info"
2581
+ });
2582
+ }
2583
+ }
2584
+ let accepted = 0;
2585
+ const errors = [];
2586
+ for (const input of inputs) {
2587
+ try {
2588
+ const id = input.id || uuidv42();
2589
+ const timestamp = input.timestamp || (/* @__PURE__ */ new Date()).toISOString();
2590
+ const resolved = typeMap.get(input.type);
2591
+ const category = resolved?.category || "unknown";
2592
+ const severity = input.severity || resolved?.severity || "info";
2593
+ const scopeValue = input.scopeValue != null ? String(input.scopeValue) : null;
2594
+ const scopeOrdinal = typeof input.scopeValue === "number" ? input.scopeValue : null;
2595
+ this.db.run(
2596
+ `INSERT INTO events (
2597
+ id, schema_id, event_type, category, timestamp, scope_value,
2598
+ scope_ordinal, session_id, service, data_json, severity,
2599
+ parent_event_id, depth
2600
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
2601
+ [
2602
+ id,
2603
+ schemaId,
2604
+ input.type,
2605
+ category,
2606
+ timestamp,
2607
+ scopeValue,
2608
+ scopeOrdinal,
2609
+ input.sessionId || null,
2610
+ service,
2611
+ input.data ? JSON.stringify(input.data) : null,
2612
+ severity,
2613
+ input.parentEventId || null,
2614
+ input.depth ?? 0
2615
+ ]
2616
+ );
2617
+ accepted++;
2618
+ } catch (err) {
2619
+ errors.push(err instanceof Error ? err.message : String(err));
2620
+ }
2621
+ }
2622
+ this.save();
2623
+ return { accepted, errors };
2624
+ }
2625
+ queryEvents(options = {}) {
2626
+ this.initializeSync();
2627
+ const { limit = 100, offset = 0 } = options;
2628
+ const conditions = [];
2629
+ const params = [];
2630
+ if (options.schemaId) {
2631
+ conditions.push("schema_id = ?");
2632
+ params.push(options.schemaId);
2633
+ }
2634
+ if (options.eventType) {
2635
+ conditions.push("event_type = ?");
2636
+ params.push(options.eventType);
2637
+ }
2638
+ if (options.category) {
2639
+ conditions.push("category = ?");
2640
+ params.push(options.category);
2641
+ }
2642
+ if (options.service) {
2643
+ conditions.push("service = ?");
2644
+ params.push(options.service);
2645
+ }
2646
+ if (options.sessionId) {
2647
+ conditions.push("session_id = ?");
2648
+ params.push(options.sessionId);
2649
+ }
2650
+ if (options.scopeValue) {
2651
+ conditions.push("scope_value = ?");
2652
+ params.push(options.scopeValue);
2653
+ }
2654
+ if (options.scopeFrom) {
2655
+ conditions.push("scope_value >= ?");
2656
+ params.push(options.scopeFrom);
2657
+ }
2658
+ if (options.scopeTo) {
2659
+ conditions.push("scope_value <= ?");
2660
+ params.push(options.scopeTo);
2661
+ }
2662
+ if (options.severity) {
2663
+ conditions.push("severity = ?");
2664
+ params.push(options.severity);
2665
+ }
2666
+ if (options.since) {
2667
+ conditions.push("timestamp >= ?");
2668
+ params.push(options.since);
2669
+ }
2670
+ if (options.until) {
2671
+ conditions.push("timestamp <= ?");
2672
+ params.push(options.until);
2673
+ }
2674
+ if (options.search) {
2675
+ conditions.push("data_json LIKE ?");
2676
+ params.push(`%${options.search}%`);
2677
+ }
2678
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
2679
+ const result = this.db.exec(
2680
+ `SELECT * FROM events ${whereClause} ORDER BY timestamp DESC LIMIT ? OFFSET ?`,
2681
+ [...params, limit, offset]
2682
+ );
2683
+ if (result.length === 0) return [];
2684
+ return result[0].values.map(
2685
+ (row) => this.rowToGenericEvent(result[0].columns, row)
2686
+ );
2687
+ }
2688
+ queryEventsByScope(schemaId, scopeValue) {
2689
+ this.initializeSync();
2690
+ const result = this.db.exec(
2691
+ `SELECT * FROM events
2692
+ WHERE schema_id = ? AND scope_value = ?
2693
+ ORDER BY timestamp ASC`,
2694
+ [schemaId, scopeValue]
2695
+ );
2696
+ if (result.length === 0) return [];
2697
+ return result[0].values.map(
2698
+ (row) => this.rowToGenericEvent(result[0].columns, row)
2699
+ );
2700
+ }
2701
+ getEventScopes(schemaId, options = {}) {
2702
+ this.initializeSync();
2703
+ const { limit = 100, offset = 0 } = options;
2704
+ const conditions = ["schema_id = ?"];
2705
+ const params = [schemaId];
2706
+ if (options.sessionId) {
2707
+ conditions.push("session_id = ?");
2708
+ params.push(options.sessionId);
2709
+ }
2710
+ const whereClause = `WHERE ${conditions.join(" AND ")}`;
2711
+ const result = this.db.exec(
2712
+ `SELECT
2713
+ scope_value,
2714
+ MIN(scope_ordinal) as scope_ordinal,
2715
+ COUNT(*) as event_count,
2716
+ MIN(timestamp) as first_timestamp,
2717
+ MAX(timestamp) as last_timestamp
2718
+ FROM events
2719
+ ${whereClause}
2720
+ AND scope_value IS NOT NULL
2721
+ GROUP BY scope_value
2722
+ ORDER BY MIN(COALESCE(scope_ordinal, 0)) DESC, MIN(timestamp) DESC
2723
+ LIMIT ? OFFSET ?`,
2724
+ [...params, limit, offset]
2725
+ );
2726
+ if (result.length === 0) return [];
2727
+ const scopes = [];
2728
+ for (const row of result[0].values) {
2729
+ const scopeValue = row[0];
2730
+ const scopeOrdinal = row[1] != null ? row[1] : void 0;
2731
+ const eventCount = row[2];
2732
+ const firstTimestamp = row[3];
2733
+ const lastTimestamp = row[4];
2734
+ const catResult = this.db.exec(
2735
+ `SELECT category, COUNT(*) as count FROM events
2736
+ WHERE schema_id = ? AND scope_value = ?
2737
+ GROUP BY category`,
2738
+ [schemaId, scopeValue]
2739
+ );
2740
+ const categories = {};
2741
+ if (catResult.length > 0) {
2742
+ for (const catRow of catResult[0].values) {
2743
+ categories[catRow[0]] = catRow[1];
2744
+ }
2745
+ }
2746
+ scopes.push({
2747
+ scopeValue,
2748
+ scopeOrdinal,
2749
+ eventCount,
2750
+ categories,
2751
+ firstTimestamp,
2752
+ lastTimestamp
2753
+ });
2754
+ }
2755
+ return scopes;
2756
+ }
2757
+ getEventCount(options = {}) {
2758
+ this.initializeSync();
2759
+ const conditions = [];
2760
+ const params = [];
2761
+ if (options.schemaId) {
2762
+ conditions.push("schema_id = ?");
2763
+ params.push(options.schemaId);
2764
+ }
2765
+ if (options.eventType) {
2766
+ conditions.push("event_type = ?");
2767
+ params.push(options.eventType);
2768
+ }
2769
+ if (options.service) {
2770
+ conditions.push("service = ?");
2771
+ params.push(options.service);
2772
+ }
2773
+ if (options.since) {
2774
+ conditions.push("timestamp >= ?");
2775
+ params.push(options.since);
2776
+ }
2777
+ if (options.until) {
2778
+ conditions.push("timestamp <= ?");
2779
+ params.push(options.until);
2780
+ }
2781
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
2782
+ const result = this.db.exec(
2783
+ `SELECT COUNT(*) as count FROM events ${whereClause}`,
2784
+ params
2785
+ );
2786
+ if (result.length === 0 || result[0].values.length === 0) return 0;
2787
+ return result[0].values[0][0];
2788
+ }
2789
+ pruneEvents(maxCount) {
2790
+ this.initializeSync();
2791
+ if (maxCount <= 0) return 0;
2792
+ const currentCount = this.getEventCount();
2793
+ if (currentCount <= maxCount) return 0;
2794
+ const deleteCount = currentCount - maxCount;
2795
+ this.db.run(
2796
+ `DELETE FROM events WHERE id IN (
2797
+ SELECT id FROM events ORDER BY timestamp ASC LIMIT ?
2798
+ )`,
2799
+ [deleteCount]
2800
+ );
2801
+ this.save();
2802
+ return deleteCount;
2803
+ }
2804
+ rowToGenericEvent(columns, row) {
2805
+ const obj = {};
2806
+ columns.forEach((col, i) => {
2807
+ obj[col] = row[i];
2808
+ });
2809
+ return {
2810
+ id: obj.id,
2811
+ schemaId: obj.schema_id,
2812
+ eventType: obj.event_type,
2813
+ category: obj.category,
2814
+ timestamp: obj.timestamp,
2815
+ scopeValue: obj.scope_value || void 0,
2816
+ scopeOrdinal: obj.scope_ordinal != null ? obj.scope_ordinal : void 0,
2817
+ sessionId: obj.session_id || void 0,
2818
+ service: obj.service,
2819
+ data: obj.data_json ? JSON.parse(obj.data_json) : void 0,
2820
+ severity: obj.severity || "info",
2821
+ parentEventId: obj.parent_event_id || void 0,
2822
+ depth: obj.depth || 0
2823
+ };
2824
+ }
2442
2825
  close() {
2443
2826
  if (this.db) {
2444
2827
  this.save();
@@ -2641,7 +3024,7 @@ function loadServerConfig(projectDir) {
2641
3024
  return config;
2642
3025
  }
2643
3026
 
2644
- // ../paradigm-mcp/node_modules/.pnpm/@a-company+sentinel@3.5.0/node_modules/@a-company/sentinel/dist/index.js
3027
+ // ../sentinel/dist/index.js
2645
3028
  import * as path3 from "path";
2646
3029
  import * as fs3 from "fs";
2647
3030
  import { fileURLToPath } from "url";
@@ -4803,6 +5186,150 @@ var PatternImporter = class {
4803
5186
  };
4804
5187
  }
4805
5188
  };
5189
+ var PARADIGM_SCHEMA = {
5190
+ id: "paradigm-logger",
5191
+ version: "1.0.0",
5192
+ name: "Paradigm Logger",
5193
+ description: "Structured logs from @a-company/paradigm-logger with symbolic context",
5194
+ scope: {
5195
+ field: "correlationId",
5196
+ type: "string",
5197
+ label: "Correlation",
5198
+ ordering: "independent",
5199
+ sessionField: "sessionId"
5200
+ },
5201
+ eventTypes: [
5202
+ {
5203
+ type: "log:debug",
5204
+ category: "logs",
5205
+ label: "Debug Log",
5206
+ severity: "debug",
5207
+ frequency: "high",
5208
+ fields: [
5209
+ { name: "symbol", type: "string", indexed: true, display: true },
5210
+ { name: "symbolType", type: "string", indexed: true, display: true },
5211
+ { name: "message", type: "string", display: true },
5212
+ { name: "service", type: "string", indexed: true, display: true },
5213
+ { name: "durationMs", type: "number", display: true }
5214
+ ]
5215
+ },
5216
+ {
5217
+ type: "log:info",
5218
+ category: "logs",
5219
+ label: "Info Log",
5220
+ severity: "info",
5221
+ frequency: "high",
5222
+ fields: [
5223
+ { name: "symbol", type: "string", indexed: true, display: true },
5224
+ { name: "symbolType", type: "string", indexed: true, display: true },
5225
+ { name: "message", type: "string", display: true },
5226
+ { name: "service", type: "string", indexed: true, display: true },
5227
+ { name: "durationMs", type: "number", display: true }
5228
+ ]
5229
+ },
5230
+ {
5231
+ type: "log:warn",
5232
+ category: "logs",
5233
+ label: "Warning Log",
5234
+ severity: "warn",
5235
+ frequency: "medium",
5236
+ fields: [
5237
+ { name: "symbol", type: "string", indexed: true, display: true },
5238
+ { name: "symbolType", type: "string", indexed: true, display: true },
5239
+ { name: "message", type: "string", display: true },
5240
+ { name: "service", type: "string", indexed: true, display: true }
5241
+ ]
5242
+ },
5243
+ {
5244
+ type: "log:error",
5245
+ category: "logs",
5246
+ label: "Error Log",
5247
+ severity: "error",
5248
+ frequency: "low",
5249
+ fields: [
5250
+ { name: "symbol", type: "string", indexed: true, display: true },
5251
+ { name: "symbolType", type: "string", indexed: true, display: true },
5252
+ { name: "message", type: "string", display: true },
5253
+ { name: "service", type: "string", indexed: true, display: true }
5254
+ ]
5255
+ },
5256
+ {
5257
+ type: "metric:counter",
5258
+ category: "metrics",
5259
+ label: "Counter Metric",
5260
+ severity: "info",
5261
+ frequency: "high",
5262
+ fields: [
5263
+ { name: "name", type: "string", indexed: true, display: true },
5264
+ { name: "value", type: "number", display: true },
5265
+ { name: "tags", type: "object" }
5266
+ ]
5267
+ },
5268
+ {
5269
+ type: "metric:gauge",
5270
+ category: "metrics",
5271
+ label: "Gauge Metric",
5272
+ severity: "info",
5273
+ frequency: "medium",
5274
+ fields: [
5275
+ { name: "name", type: "string", indexed: true, display: true },
5276
+ { name: "value", type: "number", display: true },
5277
+ { name: "tags", type: "object" }
5278
+ ]
5279
+ },
5280
+ {
5281
+ type: "metric:histogram",
5282
+ category: "metrics",
5283
+ label: "Histogram Metric",
5284
+ severity: "info",
5285
+ frequency: "medium",
5286
+ fields: [
5287
+ { name: "name", type: "string", indexed: true, display: true },
5288
+ { name: "value", type: "number", display: true },
5289
+ { name: "tags", type: "object" }
5290
+ ]
5291
+ },
5292
+ {
5293
+ type: "trace:span",
5294
+ category: "traces",
5295
+ label: "Trace Span",
5296
+ severity: "info",
5297
+ frequency: "medium",
5298
+ fields: [
5299
+ { name: "traceId", type: "string", indexed: true, display: true },
5300
+ { name: "spanId", type: "string", indexed: true },
5301
+ { name: "operation", type: "string", display: true },
5302
+ { name: "durationMs", type: "number", display: true },
5303
+ { name: "status", type: "string", display: true }
5304
+ ]
5305
+ },
5306
+ {
5307
+ type: "incident:recorded",
5308
+ category: "incidents",
5309
+ label: "Incident Recorded",
5310
+ severity: "error",
5311
+ frequency: "low",
5312
+ fields: [
5313
+ { name: "incidentId", type: "string", indexed: true, display: true },
5314
+ { name: "errorMessage", type: "string", display: true },
5315
+ { name: "symbols", type: "object" },
5316
+ { name: "environment", type: "string", display: true }
5317
+ ]
5318
+ }
5319
+ ],
5320
+ visualization: {
5321
+ defaultView: "table",
5322
+ categoryColors: {
5323
+ logs: "#3b82f6",
5324
+ metrics: "#22c55e",
5325
+ traces: "#a855f7",
5326
+ incidents: "#ef4444"
5327
+ },
5328
+ summaryFields: ["symbol", "message", "service"],
5329
+ defaultExcluded: ["log:debug"]
5330
+ },
5331
+ tags: ["builtin", "paradigm"]
5332
+ };
4806
5333
 
4807
5334
  export {
4808
5335
  SentinelClient,
@@ -4830,5 +5357,6 @@ export {
4830
5357
  StatsCalculator,
4831
5358
  ContextEnricher,
4832
5359
  PatternSuggester,
4833
- PatternImporter
5360
+ PatternImporter,
5361
+ PARADIGM_SCHEMA
4834
5362
  };