@a-company/sentinel 0.2.0 → 3.6.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.
@@ -74,7 +74,7 @@ type CreateIncidentInput = Omit<SymbolicIncidentRecord, 'id' | 'notes' | 'relate
74
74
  status?: IncidentStatus;
75
75
  };
76
76
  type PatternSource = 'manual' | 'suggested' | 'imported' | 'community';
77
- type ResolutionStrategy = 'retry' | 'fallback' | 'fix-data' | 'fix-code' | 'ignore' | 'escalate';
77
+ type ResolutionStrategy = 'retry' | 'fallback' | 'fix-data' | 'fix-code' | 'rollback' | 'config-change' | 'scale-up' | 'investigate' | 'ignore' | 'escalate';
78
78
  type PatternPriority = 'low' | 'medium' | 'high' | 'critical';
79
79
  /**
80
80
  * Symbol criteria for pattern matching
@@ -378,267 +378,204 @@ interface PracticeEventQuery {
378
378
  limit?: number;
379
379
  offset?: number;
380
380
  }
381
-
382
- /**
383
- * Paradigm Sentinel - SQLite Storage Layer
384
- *
385
- * Persistent storage for incidents, patterns, groups, and resolutions.
386
- * Uses sql.js for pure JavaScript SQLite (no native compilation needed).
387
- */
388
-
389
- declare class SentinelStorage {
390
- private db;
391
- private dbPath;
392
- private incidentCounter;
393
- private initialized;
394
- constructor(dbPath?: string);
395
- private getDefaultDbPath;
396
- private createSchema;
397
- private save;
398
- recordIncident(input: CreateIncidentInput): string;
399
- private initializeSync;
400
- /**
401
- * Run schema migrations from older versions
402
- */
403
- private migrateSchema;
404
- /**
405
- * Ensure the storage is ready for use. Must be called once before using storage methods.
406
- */
407
- ensureReady(): Promise<void>;
408
- getIncident(id: string): SymbolicIncidentRecord | null;
409
- getRecentIncidents(options?: IncidentQueryOptions): SymbolicIncidentRecord[];
410
- updateIncident(id: string, updates: Partial<SymbolicIncidentRecord>): void;
411
- addIncidentNote(incidentId: string, note: Omit<IncidentNote, 'id'>): void;
412
- linkIncidents(incidentId: string, relatedId: string): void;
413
- getIncidentCount(options?: IncidentQueryOptions): number;
414
- addPattern(input: CreatePatternInput): string;
415
- getPattern(id: string): FailurePattern | null;
416
- getAllPatterns(options?: PatternQueryOptions): FailurePattern[];
417
- updatePattern(id: string, updates: Partial<FailurePattern>): void;
418
- deletePattern(id: string): void;
419
- updatePatternConfidence(patternId: string, event: 'matched' | 'resolved' | 'recurred'): void;
420
- createGroup(input: CreateGroupInput): string;
421
- getGroup(id: string): IncidentGroup | null;
422
- getGroups(options?: {
423
- limit?: number;
424
- }): IncidentGroup[];
425
- addToGroup(groupId: string, incidentId: string): void;
426
- recordResolution(resolution: {
427
- incidentId: string;
428
- patternId?: string;
429
- commitHash?: string;
430
- prUrl?: string;
431
- notes?: string;
432
- }): void;
433
- markRecurred(incidentId: string): void;
434
- getResolutionHistory(options?: ResolutionQueryOptions): ResolutionRecord[];
435
- getStats(period: {
436
- start: string;
437
- end: string;
438
- }): SentinelStats;
439
- getSymbolHealth(symbol: string): SymbolHealth;
440
- exportPatterns(options?: {
441
- includePrivate?: boolean;
442
- }): PatternExport;
443
- importPatterns(data: PatternExport, options?: {
444
- overwrite?: boolean;
445
- }): {
446
- imported: number;
447
- skipped: number;
448
- };
449
- exportBackup(): BackupExport;
450
- importBackup(data: BackupExport): void;
451
- private rowToIncident;
452
- private rowToPattern;
453
- private rowToGroup;
454
- recordPracticeEvent(input: PracticeEventInput): string;
455
- getPracticeEvents(options?: PracticeEventQuery): PracticeEvent[];
456
- getPracticeEventCount(options?: PracticeEventQuery): number;
457
- getComplianceRate(options?: PracticeEventQuery): {
458
- total: number;
459
- followed: number;
460
- skipped: number;
461
- partial: number;
462
- rate: number;
381
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
382
+ type LogSymbolType = 'component' | 'gate' | 'signal' | 'flow' | 'aspect' | 'raw';
383
+ interface LogEntry {
384
+ id: string;
385
+ timestamp: string;
386
+ level: LogLevel;
387
+ symbol: string;
388
+ symbolType: LogSymbolType;
389
+ message: string;
390
+ data?: Record<string, unknown>;
391
+ service: string;
392
+ sessionId?: string;
393
+ correlationId?: string;
394
+ durationMs?: number;
395
+ environment?: string;
396
+ }
397
+ interface LogEntryInput {
398
+ id?: string;
399
+ timestamp?: string;
400
+ level: LogLevel;
401
+ symbol: string;
402
+ symbolType?: LogSymbolType;
403
+ message: string;
404
+ data?: Record<string, unknown>;
405
+ service: string;
406
+ sessionId?: string;
407
+ correlationId?: string;
408
+ durationMs?: number;
409
+ environment?: string;
410
+ }
411
+ interface LogQueryOptions {
412
+ level?: LogLevel;
413
+ symbol?: string;
414
+ service?: string;
415
+ sessionId?: string;
416
+ correlationId?: string;
417
+ search?: string;
418
+ since?: string;
419
+ until?: string;
420
+ limit?: number;
421
+ offset?: number;
422
+ }
423
+ interface ServiceInfo {
424
+ name: string;
425
+ version?: string;
426
+ pid?: number;
427
+ startedAt: string;
428
+ lastSeenAt: string;
429
+ environment?: string;
430
+ metadata?: Record<string, unknown>;
431
+ }
432
+ interface ServiceRegistration {
433
+ name: string;
434
+ version?: string;
435
+ pid?: number;
436
+ environment?: string;
437
+ metadata?: Record<string, unknown>;
438
+ }
439
+ interface AppState {
440
+ service: string;
441
+ sessionId: string;
442
+ timestamp: string;
443
+ state: Record<string, unknown>;
444
+ activeFlows?: string[];
445
+ activeGates?: string[];
446
+ }
447
+ interface SymbolValidationResult {
448
+ symbol: string;
449
+ known: boolean;
450
+ type?: string;
451
+ definedIn?: string;
452
+ suggestion?: string;
453
+ }
454
+ interface CorsConfig {
455
+ origin?: string | string[];
456
+ credentials?: boolean;
457
+ }
458
+ interface SentinelServerConfig {
459
+ port: number;
460
+ maxLogs: number;
461
+ maxBatchSize: number;
462
+ wsMaxSubscribers: number;
463
+ pruneIntervalInserts: number;
464
+ logRetentionDays: number;
465
+ auth: AuthConfig;
466
+ rateLimit: RateLimitConfig;
467
+ cors?: CorsConfig;
468
+ tls?: {
469
+ cert: string;
470
+ key: string;
463
471
  };
464
- private rowToPracticeEvent;
465
- close(): void;
466
472
  }
467
-
468
- /**
469
- * Paradigm Sentinel - Pattern Matching Engine
470
- *
471
- * Matches incidents against failure patterns using symbolic context,
472
- * error text, and missing signals.
473
- */
474
-
475
- declare class PatternMatcher {
476
- private storage;
477
- constructor(storage: SentinelStorage);
478
- /**
479
- * Match an incident against all patterns and return ranked results
480
- */
481
- match(incident: SymbolicIncidentRecord, config?: Partial<MatcherConfig>): PatternMatch[];
482
- /**
483
- * Test a pattern against historical incidents
484
- */
485
- testPattern(pattern: FailurePattern, limit?: number): PatternTestResult;
486
- /**
487
- * Score how well a pattern matches an incident
488
- */
489
- private scoreMatch;
490
- /**
491
- * Match symbols between pattern and incident
492
- */
493
- private matchSymbols;
494
- /**
495
- * Match a single symbol value (supports wildcards)
496
- */
497
- private matchSingleSymbol;
498
- /**
499
- * Match error text keywords and regex
500
- */
501
- private matchErrorText;
502
- /**
503
- * Match missing signals from flow position
504
- */
505
- private matchMissingSignals;
506
- /**
507
- * Check if pattern's environment filter matches incident
508
- */
509
- private matchEnvironment;
473
+ interface AuthConfig {
474
+ enabled: boolean;
475
+ tokens: AuthToken[];
510
476
  }
511
-
512
- /**
513
- * Sentinel SDK
514
- *
515
- * The developer-facing API for capturing errors with symbolic context.
516
- * Wraps the core storage and pattern matching engine.
517
- *
518
- * Usage:
519
- * import { Sentinel } from '@a-company/sentinel';
520
- * const sentinel = new Sentinel({ project: 'my-app' });
521
- * sentinel.capture(new Error('Payment failed'), { component: '#checkout' });
522
- */
523
-
524
- /**
525
- * Flow tracker for monitoring multi-step flows.
526
- *
527
- * Usage:
528
- * const flow = sentinel.flow('$checkout-flow');
529
- * flow.expect('!payment-authorized', '!order-created');
530
- * flow.gate('^authenticated', true);
531
- * flow.signal('!payment-authorized');
532
- * flow.complete();
533
- */
534
- declare class FlowTracker {
535
- private flowId;
536
- private sentinel;
537
- private actual;
538
- private expected;
539
- private completed;
540
- constructor(flowId: string, sentinel: Sentinel);
541
- /** Declare which signals/gates are expected in this flow */
542
- expect(...symbols: string[]): this;
543
- /** Record a generic step in the flow */
544
- step(symbol: string): this;
545
- /** Record a gate check result */
546
- gate(id: string, passed: boolean): this;
547
- /** Record a signal emission */
548
- signal(id: string, _data?: object): this;
549
- /** Mark the flow as successfully completed */
550
- complete(): void;
551
- /** Capture an error with full flow position context */
552
- fail(error: Error): void;
477
+ interface AuthToken {
478
+ id: string;
479
+ name: string;
480
+ token: string;
481
+ permissions: AuthPermission[];
482
+ createdAt: string;
483
+ expiresAt?: string;
553
484
  }
554
- /**
555
- * The main Sentinel SDK class.
556
- *
557
- * Usage:
558
- * const sentinel = new Sentinel({ project: 'my-app', environment: 'production' });
559
- *
560
- * // Capture errors with symbolic context
561
- * sentinel.capture(error, { component: '#checkout', gate: '^payment-validated' });
562
- *
563
- * // Component context for scoped captures
564
- * const ctx = sentinel.component('#checkout');
565
- * ctx.capture(error);
566
- *
567
- * // Flow tracking
568
- * const flow = sentinel.flow('$checkout-flow');
569
- * flow.gate('^authenticated', true);
570
- * flow.signal('!payment-authorized');
571
- * flow.complete();
572
- */
573
- declare class Sentinel {
574
- private storage;
575
- private matcher;
576
- private config;
577
- private ready;
578
- private readyPromise;
579
- private seeded;
580
- constructor(config: SentinelConfig);
581
- /** Explicitly initialize storage. Optional — auto-called on first capture. */
582
- init(): Promise<void>;
583
- private doInit;
584
- private ensureReady;
585
- /**
586
- * Create a component context for scoped error capture.
587
- *
588
- * @param id - Component symbol (e.g. '#checkout' or 'checkout')
589
- * @returns ComponentContext with capture() and wrap() methods
590
- */
591
- component(id: string): ComponentContext;
592
- /**
593
- * Record a gate check result.
594
- * If the gate fails, auto-captures an incident.
595
- *
596
- * @param id - Gate symbol (e.g. '^authenticated' or 'authenticated')
597
- * @param passed - Whether the gate passed
598
- */
599
- gate(id: string, passed: boolean): void;
600
- /**
601
- * Record a signal emission. Primarily for flow tracking context.
602
- *
603
- * @param id - Signal symbol (e.g. '!payment-authorized' or 'payment-authorized')
604
- */
605
- signal(id: string, _data?: object): void;
606
- /**
607
- * Create a flow tracker for monitoring multi-step operations.
608
- *
609
- * @param id - Flow symbol (e.g. '$checkout-flow' or 'checkout-flow')
610
- * @returns FlowTracker instance
611
- */
612
- flow(id: string): FlowTracker;
613
- /**
614
- * Capture an error with symbolic context.
615
- *
616
- * @param error - The error to capture
617
- * @param context - Symbolic context (component, gate, flow, signal)
618
- * @param flowPosition - Optional flow position data
619
- * @returns Incident ID (e.g. 'INC-001')
620
- */
621
- capture(error: Error, context?: Partial<SymbolicContext>, flowPosition?: FlowPosition): string;
622
- /**
623
- * Get pattern matches for a captured incident.
624
- *
625
- * @param incidentId - The incident ID to match
626
- * @returns Array of pattern matches sorted by confidence
627
- */
628
- match(incidentId: string): PatternMatch[];
629
- /**
630
- * Create Express error-handling middleware.
631
- *
632
- * Usage:
633
- * app.use(sentinel.express());
634
- */
635
- express(): any;
636
- /** Close the database connection. Call when shutting down. */
637
- close(): void;
638
- /** Get the underlying storage instance (for advanced usage). */
639
- getStorage(): SentinelStorage;
640
- /** Get the underlying pattern matcher (for advanced usage). */
641
- getMatcher(): PatternMatcher;
485
+ type AuthPermission = 'read' | 'write' | 'admin';
486
+ declare const DEFAULT_AUTH_CONFIG: AuthConfig;
487
+ type MetricType = 'counter' | 'gauge' | 'histogram';
488
+ interface MetricEntry {
489
+ id: string;
490
+ timestamp: string;
491
+ name: string;
492
+ type: MetricType;
493
+ value: number;
494
+ tags: Record<string, string>;
495
+ service: string;
496
+ environment?: string;
497
+ }
498
+ interface MetricInput {
499
+ name: string;
500
+ type: MetricType;
501
+ value: number;
502
+ tags?: Record<string, string>;
503
+ service: string;
504
+ timestamp?: string;
505
+ environment?: string;
506
+ }
507
+ interface MetricQueryOptions {
508
+ name?: string;
509
+ type?: MetricType;
510
+ service?: string;
511
+ tag?: string;
512
+ since?: string;
513
+ until?: string;
514
+ limit?: number;
515
+ offset?: number;
516
+ }
517
+ interface MetricAggregation {
518
+ name: string;
519
+ count: number;
520
+ sum: number;
521
+ min: number;
522
+ max: number;
523
+ avg: number;
524
+ p50?: number;
525
+ p95?: number;
526
+ p99?: number;
527
+ }
528
+ interface HistogramBucket {
529
+ le: number;
530
+ count: number;
531
+ }
532
+ interface RateLimitConfig {
533
+ enabled: boolean;
534
+ global: RateLimitRule;
535
+ perService: Record<string, RateLimitRule>;
536
+ }
537
+ interface RateLimitRule {
538
+ maxRequestsPerMinute: number;
539
+ maxEntriesPerBatch: number;
540
+ samplingRate: number;
541
+ }
542
+ declare const DEFAULT_RATE_LIMIT_CONFIG: RateLimitConfig;
543
+ declare const DEFAULT_SERVER_CONFIG: SentinelServerConfig;
544
+ interface TraceSpan {
545
+ traceId: string;
546
+ spanId: string;
547
+ parentSpanId?: string;
548
+ service: string;
549
+ symbol: string;
550
+ operation: string;
551
+ startTime: string;
552
+ endTime?: string;
553
+ durationMs?: number;
554
+ status: 'ok' | 'error';
555
+ tags: Record<string, string>;
556
+ logs: string[];
557
+ }
558
+ interface TraceSpanInput {
559
+ traceId: string;
560
+ spanId?: string;
561
+ parentSpanId?: string;
562
+ service: string;
563
+ symbol: string;
564
+ operation: string;
565
+ startTime?: string;
566
+ endTime?: string;
567
+ durationMs?: number;
568
+ status?: 'ok' | 'error';
569
+ tags?: Record<string, string>;
570
+ logIds?: string[];
571
+ }
572
+ interface TraceView {
573
+ traceId: string;
574
+ spans: TraceSpan[];
575
+ services: string[];
576
+ totalDurationMs: number;
577
+ startTime: string;
578
+ endTime: string;
642
579
  }
643
580
 
644
- export { type SymbolResolutionTime as $, type PatternRecurrence as A, type BackupExport as B, type ComponentContext as C, type DayCount as D, type EnrichedIncident as E, type FlowTimeline as F, type PatternResolution as G, type PatternSource as H, type IncidentGroup as I, type PatternSymbolCriteria as J, type PatternTestResult as K, type PracticeCategory as L, type MatchedCriteria as M, type PracticeEvent as N, type PracticeEventInput as O, type PatternCandidate as P, type PracticeEventQuery as Q, type PracticeResult as R, SentinelStorage as S, type Resolution as T, type ResolutionQueryOptions as U, type ResolutionRecord as V, type ResolutionStrategy as W, Sentinel as X, type SentinelConfig as Y, type SymbolHotspot as Z, type SymbolIncidentCount as _, type SymbolicIncidentRecord as a, type SymbolicContext as a0, type SentinelStats as b, type SymbolHealth as c, type SymbolEnrichment as d, type FailurePattern as e, type PatternExport as f, type CreateGroupInput as g, type CreateIncidentInput as h, type CreatePatternInput as i, type Environment as j, type ErrorDetails as k, type FlowEvent as l, type FlowEventType as m, type FlowPosition as n, FlowTracker as o, type IncidentNote as p, type IncidentQueryOptions as q, type IncidentStatus as r, type MatcherConfig as s, type PatternConfidence as t, type PatternCriteria as u, type PatternEffectiveness as v, type PatternMatch as w, PatternMatcher as x, type PatternPriority as y, type PatternQueryOptions as z };
581
+ export { type PatternResolution as $, type AppState as A, type BackupExport as B, type ComponentContext as C, DEFAULT_AUTH_CONFIG as D, type EnrichedIncident as E, type FlowTimeline as F, type LogQueryOptions as G, type HistogramBucket as H, type IncidentGroup as I, type LogSymbolType as J, type MatcherConfig as K, type LogEntry as L, type MatchedCriteria as M, type MetricAggregation as N, type MetricEntry as O, type PatternCandidate as P, type MetricInput as Q, type MetricQueryOptions as R, type SentinelServerConfig as S, type MetricType as T, type PatternConfidence as U, type PatternCriteria as V, type PatternEffectiveness as W, type PatternMatch as X, type PatternPriority as Y, type PatternQueryOptions as Z, type PatternRecurrence as _, type SymbolicIncidentRecord as a, type PatternSource as a0, type PatternSymbolCriteria as a1, type PatternTestResult as a2, type PracticeCategory as a3, type PracticeEvent as a4, type PracticeEventInput as a5, type PracticeEventQuery as a6, type PracticeResult as a7, type RateLimitConfig as a8, type RateLimitRule as a9, type Resolution as aa, type ResolutionQueryOptions as ab, type ResolutionRecord as ac, type ResolutionStrategy as ad, type SentinelConfig as ae, type ServiceInfo as af, type ServiceRegistration as ag, type SymbolHotspot as ah, type SymbolIncidentCount as ai, type SymbolResolutionTime as aj, type SymbolValidationResult as ak, type SymbolicContext as al, type TraceSpan as am, type TraceSpanInput as an, type TraceView as ao, type SentinelStats as b, type SymbolHealth as c, type SymbolEnrichment as d, type FailurePattern as e, type PatternExport as f, type AuthConfig as g, type AuthPermission as h, type AuthToken as i, type CorsConfig as j, type CreateGroupInput as k, type CreateIncidentInput as l, type CreatePatternInput as m, DEFAULT_RATE_LIMIT_CONFIG as n, DEFAULT_SERVER_CONFIG as o, type DayCount as p, type Environment as q, type ErrorDetails as r, type FlowEvent as s, type FlowEventType as t, type FlowPosition as u, type IncidentNote as v, type IncidentQueryOptions as w, type IncidentStatus as x, type LogEntryInput as y, type LogLevel as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-company/sentinel",
3
- "version": "0.2.0",
3
+ "version": "3.6.0",
4
4
  "description": "Semantic error monitoring — errors that speak your language",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -29,6 +29,18 @@
29
29
  "./hono": {
30
30
  "types": "./dist/adapters/hono.d.ts",
31
31
  "import": "./dist/adapters/hono.js"
32
+ },
33
+ "./transport": {
34
+ "types": "./dist/transport.d.ts",
35
+ "import": "./dist/transport.js"
36
+ }
37
+ },
38
+ "peerDependencies": {
39
+ "@a-company/paradigm-logger": ">=1.1.0"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "@a-company/paradigm-logger": {
43
+ "optional": true
32
44
  }
33
45
  },
34
46
  "files": [
@@ -53,6 +65,7 @@
53
65
  "simple-git": "^3.22.0",
54
66
  "sql.js": "^1.10.3",
55
67
  "uuid": "^9.0.0",
68
+ "ws": "^8.19.0",
56
69
  "zod": "^3.23.0"
57
70
  },
58
71
  "devDependencies": {
@@ -61,6 +74,7 @@
61
74
  "@types/react": "^18.2.45",
62
75
  "@types/react-dom": "^18.2.18",
63
76
  "@types/uuid": "^9.0.7",
77
+ "@types/ws": "^8.18.1",
64
78
  "@vitejs/plugin-react": "^4.2.1",
65
79
  "react": "^18.2.0",
66
80
  "react-dom": "^18.2.0",