@runtimescope/collector 0.7.2 → 0.9.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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SecureContextOptions } from 'node:tls';
2
2
 
3
- type EventType = 'network' | 'console' | 'session' | 'state' | 'render' | 'dom_snapshot' | 'performance' | 'database' | 'custom' | 'navigation' | 'recon_metadata' | 'recon_design_tokens' | 'recon_fonts' | 'recon_layout_tree' | 'recon_accessibility' | 'recon_computed_styles' | 'recon_element_snapshot' | 'recon_asset_inventory';
3
+ type EventType = 'network' | 'console' | 'session' | 'state' | 'render' | 'dom_snapshot' | 'performance' | 'database' | 'custom' | 'navigation' | 'ui' | 'recon_metadata' | 'recon_design_tokens' | 'recon_fonts' | 'recon_layout_tree' | 'recon_accessibility' | 'recon_computed_styles' | 'recon_element_snapshot' | 'recon_asset_inventory';
4
4
  interface BaseEvent {
5
5
  eventId: string;
6
6
  sessionId: string;
@@ -27,7 +27,7 @@ interface NetworkEvent extends BaseEvent {
27
27
  responseBody?: string;
28
28
  errorPhase?: 'error' | 'abort' | 'timeout';
29
29
  errorMessage?: string;
30
- source?: 'fetch' | 'xhr' | 'node-http' | 'node-https';
30
+ source?: 'fetch' | 'xhr' | 'node-http' | 'node-https' | 'workers';
31
31
  }
32
32
  type ConsoleLevel = 'log' | 'warn' | 'error' | 'info' | 'debug' | 'trace';
33
33
  interface ConsoleEvent extends BaseEvent {
@@ -44,12 +44,20 @@ interface BuildMeta {
44
44
  buildTime?: string;
45
45
  deployId?: string;
46
46
  }
47
+ interface UserContext {
48
+ id?: string;
49
+ email?: string;
50
+ name?: string;
51
+ [key: string]: unknown;
52
+ }
47
53
  interface SessionEvent extends BaseEvent {
48
54
  eventType: 'session';
49
55
  appName: string;
50
56
  connectedAt: number;
51
57
  sdkVersion: string;
52
58
  buildMeta?: BuildMeta;
59
+ user?: UserContext;
60
+ projectId?: string;
53
61
  }
54
62
  interface StateEvent extends BaseEvent {
55
63
  eventType: 'state';
@@ -113,7 +121,7 @@ interface PerformanceEvent extends BaseEvent {
113
121
  entries?: unknown[];
114
122
  }
115
123
  type DatabaseOperation = 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'OTHER';
116
- type DatabaseSource = 'prisma' | 'drizzle' | 'knex' | 'pg' | 'mysql2' | 'better-sqlite3' | 'generic';
124
+ type DatabaseSource = 'prisma' | 'drizzle' | 'knex' | 'pg' | 'mysql2' | 'better-sqlite3' | 'd1' | 'kv' | 'r2' | 'generic';
117
125
  interface DatabaseEvent extends BaseEvent {
118
126
  eventType: 'database';
119
127
  query: string;
@@ -140,10 +148,28 @@ interface CustomEvent extends BaseEvent {
140
148
  name: string;
141
149
  properties?: Record<string, unknown>;
142
150
  }
151
+ type UIInteractionAction = 'click' | 'breadcrumb';
152
+ interface UIInteractionEvent extends BaseEvent {
153
+ eventType: 'ui';
154
+ action: UIInteractionAction;
155
+ /** CSS selector or element description */
156
+ target: string;
157
+ /** Visible text (button label, link text) */
158
+ text?: string;
159
+ /** Optional extra context */
160
+ data?: Record<string, unknown>;
161
+ }
162
+ interface UIInteractionFilter {
163
+ action?: UIInteractionAction;
164
+ sinceSeconds?: number;
165
+ sessionId?: string;
166
+ projectId?: string;
167
+ }
143
168
  interface CustomEventFilter {
144
169
  name?: string;
145
170
  sinceSeconds?: number;
146
171
  sessionId?: string;
172
+ projectId?: string;
147
173
  }
148
174
  type DetectedFramework = 'react' | 'vue' | 'angular' | 'svelte' | 'solid' | 'preact' | 'htmx' | 'unknown';
149
175
  type DetectedMetaFramework = 'nextjs' | 'nuxt' | 'sveltekit' | 'remix' | 'astro' | 'gatsby' | 'unknown';
@@ -463,37 +489,43 @@ interface ReconFilter {
463
489
  reconType?: ReconEventType;
464
490
  sinceSeconds?: number;
465
491
  sessionId?: string;
492
+ projectId?: string;
466
493
  url?: string;
467
494
  }
468
495
  type ReconEventType = 'recon_metadata' | 'recon_design_tokens' | 'recon_fonts' | 'recon_layout_tree' | 'recon_accessibility' | 'recon_computed_styles' | 'recon_element_snapshot' | 'recon_asset_inventory';
469
- type RuntimeEvent = NetworkEvent | ConsoleEvent | SessionEvent | StateEvent | RenderEvent | DomSnapshotEvent | PerformanceEvent | DatabaseEvent | NavigationEvent | CustomEvent | ReconMetadataEvent | ReconDesignTokensEvent | ReconFontsEvent | ReconLayoutTreeEvent | ReconAccessibilityEvent | ReconComputedStylesEvent | ReconElementSnapshotEvent | ReconAssetInventoryEvent;
496
+ type RuntimeEvent = NetworkEvent | ConsoleEvent | SessionEvent | StateEvent | RenderEvent | DomSnapshotEvent | PerformanceEvent | DatabaseEvent | NavigationEvent | CustomEvent | UIInteractionEvent | ReconMetadataEvent | ReconDesignTokensEvent | ReconFontsEvent | ReconLayoutTreeEvent | ReconAccessibilityEvent | ReconComputedStylesEvent | ReconElementSnapshotEvent | ReconAssetInventoryEvent;
470
497
  interface NetworkFilter {
471
498
  sinceSeconds?: number;
472
499
  urlPattern?: string;
473
500
  status?: number;
474
501
  method?: string;
475
502
  sessionId?: string;
503
+ projectId?: string;
476
504
  }
477
505
  interface ConsoleFilter {
478
506
  level?: string;
479
507
  sinceSeconds?: number;
480
508
  search?: string;
481
509
  sessionId?: string;
510
+ projectId?: string;
482
511
  }
483
512
  interface StateFilter {
484
513
  storeId?: string;
485
514
  sinceSeconds?: number;
486
515
  sessionId?: string;
516
+ projectId?: string;
487
517
  }
488
518
  interface RenderFilter {
489
519
  componentName?: string;
490
520
  sinceSeconds?: number;
491
521
  sessionId?: string;
522
+ projectId?: string;
492
523
  }
493
524
  interface PerformanceFilter {
494
525
  metricName?: string;
495
526
  sinceSeconds?: number;
496
527
  sessionId?: string;
528
+ projectId?: string;
497
529
  }
498
530
  interface DatabaseFilter {
499
531
  sinceSeconds?: number;
@@ -503,6 +535,7 @@ interface DatabaseFilter {
503
535
  operation?: DatabaseOperation;
504
536
  source?: DatabaseSource;
505
537
  sessionId?: string;
538
+ projectId?: string;
506
539
  }
507
540
  interface HistoricalFilter {
508
541
  project?: string;
@@ -527,6 +560,7 @@ interface ToolResponse<T = unknown> {
527
560
  };
528
561
  eventCount: number;
529
562
  sessionId: string | null;
563
+ projectId?: string | null;
530
564
  };
531
565
  }
532
566
  interface SessionInfo {
@@ -536,9 +570,11 @@ interface SessionInfo {
536
570
  sdkVersion: string;
537
571
  eventCount: number;
538
572
  isConnected: boolean;
573
+ projectId?: string;
539
574
  }
540
575
  interface SessionInfoExtended extends SessionInfo {
541
576
  project: string;
577
+ projectId?: string;
542
578
  disconnectedAt?: number;
543
579
  buildMeta?: BuildMeta;
544
580
  }
@@ -611,6 +647,7 @@ interface HandshakePayload {
611
647
  sdkVersion: string;
612
648
  sessionId: string;
613
649
  authToken?: string;
650
+ projectId?: string;
614
651
  }
615
652
  interface EventBatchPayload {
616
653
  events: RuntimeEvent[];
@@ -667,6 +704,7 @@ interface TimelineFilter {
667
704
  sinceSeconds?: number;
668
705
  eventTypes?: EventType[];
669
706
  sessionId?: string;
707
+ projectId?: string;
670
708
  }
671
709
  type IssueSeverity = 'high' | 'medium' | 'low';
672
710
  interface DetectedIssue {
@@ -941,13 +979,17 @@ declare class EventStore {
941
979
  getSessionInfo(): SessionInfo[];
942
980
  markDisconnected(sessionId: string): void;
943
981
  getEventTimeline(filter?: TimelineFilter): RuntimeEvent[];
944
- getAllEvents(sinceSeconds?: number, sessionId?: string): RuntimeEvent[];
982
+ getAllEvents(sinceSeconds?: number, sessionId?: string, projectId?: string): RuntimeEvent[];
945
983
  getSessionIdsForProject(appName: string): string[];
984
+ getSessionIdsForProjectId(projectId: string): string[];
985
+ /** Check if an event belongs to the given projectId (via its session). */
986
+ private matchesProjectId;
946
987
  getStateEvents(filter?: StateFilter): StateEvent[];
947
988
  getRenderEvents(filter?: RenderFilter): RenderEvent[];
948
989
  getPerformanceMetrics(filter?: PerformanceFilter): PerformanceEvent[];
949
990
  getDatabaseEvents(filter?: DatabaseFilter): DatabaseEvent[];
950
991
  getCustomEvents(filter?: CustomEventFilter): CustomEvent[];
992
+ getUIInteractions(filter?: UIInteractionFilter): UIInteractionEvent[];
951
993
  private getLatestReconEvent;
952
994
  private getReconEvents;
953
995
  getReconMetadata(filter?: ReconFilter): ReconMetadataEvent | null;
@@ -1026,6 +1068,7 @@ interface ProjectConfig {
1026
1068
  name: string;
1027
1069
  createdAt: string;
1028
1070
  sdkVersion?: string;
1071
+ projectId?: string;
1029
1072
  settings: {
1030
1073
  bufferSize?: number;
1031
1074
  retentionDays?: number;
@@ -1065,6 +1108,12 @@ declare class ProjectManager {
1065
1108
  getClaudeInstructions(projectName: string): string | null;
1066
1109
  listProjects(): string[];
1067
1110
  projectExists(projectName: string): boolean;
1111
+ /** Look up the stored projectId for an appName. Returns null if none set. */
1112
+ getProjectIdForApp(appName: string): string | null;
1113
+ /** Persist a projectId for an appName in its project config. */
1114
+ setProjectIdForApp(appName: string, projectId: string): void;
1115
+ /** Resolve a projectId to an appName by scanning all project configs. Returns null if not found. */
1116
+ getAppForProjectId(projectId: string): string | null;
1068
1117
  resolveEnvVars(value: string): string;
1069
1118
  private mkdirp;
1070
1119
  private readJson;
@@ -1149,8 +1198,8 @@ declare class CollectorServer {
1149
1198
  getSqliteStore(projectName: string): SqliteStore | undefined;
1150
1199
  getSqliteStores(): Map<string, SqliteStore>;
1151
1200
  getRateLimiter(): SessionRateLimiter;
1152
- onConnect(cb: (sessionId: string, projectName: string) => void): void;
1153
- onDisconnect(cb: (sessionId: string, projectName: string) => void): void;
1201
+ onConnect(cb: (sessionId: string, projectName: string, projectId?: string) => void): void;
1202
+ onDisconnect(cb: (sessionId: string, projectName: string, projectId?: string) => void): void;
1154
1203
  start(options?: CollectorServerOptions): Promise<void>;
1155
1204
  private tryStart;
1156
1205
  private handleStartError;
@@ -1171,6 +1220,7 @@ declare class CollectorServer {
1171
1220
  getConnectedSessions(): {
1172
1221
  sessionId: string;
1173
1222
  projectName: string;
1223
+ projectId?: string;
1174
1224
  }[];
1175
1225
  /** Send a command to the SDK and await the response */
1176
1226
  sendCommand(sessionId: string, command: {
@@ -1206,6 +1256,17 @@ declare class RingBuffer<T> {
1206
1256
  */
1207
1257
  declare function detectIssues(events: RuntimeEvent[]): DetectedIssue[];
1208
1258
 
1259
+ /** Generate a new project ID (proj_ + 12 random alphanumeric chars). */
1260
+ declare function generateProjectId(): string;
1261
+ /** Validate that a string is a well-formed project ID. */
1262
+ declare function isValidProjectId(id: string): boolean;
1263
+ /**
1264
+ * Look up or create a project ID for a given appName.
1265
+ * Persists the ID in the ProjectManager config so the same appName
1266
+ * always returns the same project ID (idempotent).
1267
+ */
1268
+ declare function getOrCreateProjectId(projectManager: ProjectManager, appName: string): string;
1269
+
1209
1270
  declare function isSqliteAvailable(): boolean;
1210
1271
 
1211
1272
  declare class ApiDiscoveryEngine {
@@ -1367,6 +1428,7 @@ interface PmProject {
1367
1428
  path?: string;
1368
1429
  claudeProjectKey?: string;
1369
1430
  runtimescopeProject?: string;
1431
+ runtimeProjectId?: string;
1370
1432
  runtimeApps?: string[];
1371
1433
  phase: ProjectPhase;
1372
1434
  managementAuthorized: boolean;
@@ -1548,6 +1610,12 @@ declare class PmStore {
1548
1610
  getProject(id: string): PmProject | null;
1549
1611
  listProjects(): PmProject[];
1550
1612
  updateProject(id: string, updates: Partial<PmProject>): void;
1613
+ /**
1614
+ * Auto-link an SDK appName to a PM project.
1615
+ * Matches by: exact name, directory basename, runtimescopeProject, or existing runtimeApps.
1616
+ * Returns the project ID if linked, null if no match found.
1617
+ */
1618
+ autoLinkApp(appName: string, projectId?: string): string | null;
1551
1619
  listCategories(): string[];
1552
1620
  private mapProjectRow;
1553
1621
  createTask(task: PmTask): PmTask;
@@ -1609,6 +1677,7 @@ interface ProjectSummaryRow {
1609
1677
  category: string | null;
1610
1678
  sdk_installed: number;
1611
1679
  runtimescope_project: string | null;
1680
+ runtime_apps: string | null;
1612
1681
  session_count: number;
1613
1682
  total_cost: number;
1614
1683
  total_active_minutes: number;
@@ -1699,6 +1768,8 @@ declare class HttpServer {
1699
1768
  private activePort;
1700
1769
  private startedAt;
1701
1770
  private connectedSessionsGetter;
1771
+ private pmStore;
1772
+ private projectManager;
1702
1773
  constructor(store: EventStore, processMonitor?: ProcessMonitor, options?: {
1703
1774
  authManager?: AuthManager;
1704
1775
  allowedOrigins?: string[];
@@ -1709,6 +1780,7 @@ declare class HttpServer {
1709
1780
  sessionId: string;
1710
1781
  projectName: string;
1711
1782
  }[];
1783
+ projectManager?: ProjectManager;
1712
1784
  });
1713
1785
  private registerRoutes;
1714
1786
  /**
@@ -1752,4 +1824,23 @@ declare function calculateCostMicrodollars(model: string, inputTokens: number, o
1752
1824
  */
1753
1825
  declare function parseSessionJsonl(jsonlPath: string, sessionId: string, projectId: string): Promise<ParseResult>;
1754
1826
 
1755
- export { type ApiChangeRecord, type ApiContract, type ApiContractField, ApiDiscoveryEngine, type ApiEndpoint, type ApiEndpointHealth, type ApiKeyEntry, type AuthConfig, type AuthInfo, AuthManager, BUILT_IN_RULES, type BackgroundSpriteSheet, type BaseEvent, type BuildMeta, type BuildStatus, type CSSArchitecture, type CSSCustomProperty, type CapexClassification, type CapexSummary, CollectorServer, type CollectorServerOptions, type ColorToken, type CommandResponse, type ComputedStyleEntry, ConnectionManager, type ConsoleEvent, type ConsoleFilter, type ConsoleLevel, type CustomEvent, type CustomEventFilter, DataBrowser, type DatabaseConnectionConfig, type DatabaseEvent, type DatabaseFilter, type DatabaseOperation, type DatabaseSchema, type DatabaseSource, type DeployLog, type DetectedBuildTool, type DetectedFramework, type DetectedHosting, type DetectedIssue, type DetectedMetaFramework, type DetectedUILibrary, type DevProcess, type DevProcessType, type DomSnapshotEvent, type ElementSnapshotNode, type EventBatchPayload, EventStore, type EventType, type FontFaceInfo, type FontUsage, type FormFieldInfo, type GitCommit, type GitFileChange, type GitFileStatus, type GitStatus, type GlobalConfig, type GraphQLOperation, type HandshakePayload, type HeadingInfo, type HistoricalFilter, HttpServer, type HttpServerOptions, type IconFontInfo, type ImageAsset, type IndexSuggestion, InfraConnector, type InfraOverview, type InfrastructureConfig, type InlineSVGAsset, type InteractiveElementInfo, type IssueSeverity, type LandmarkInfo, type LayoutNode, type ManagedConnection, type MaskSpriteSheet, type MemoryFile, type MetricDelta, type NavigationEvent, type NetworkEvent, type NetworkFilter, type NormalizedQueryStats, type PerformanceEvent, type PerformanceFilter, type PerformanceMetricName, type PmCapexEntry, type PmNote, type PmProject, type PmSession, PmStore, type PmTask, type PortUsage, ProcessMonitor, type ProjectConfig, ProjectDiscovery, ProjectManager, type ProjectPhase, type ProjectStatus, type RateLimitConfig, type ReadOptions, type ReadResult, type ReconAccessibilityEvent, type ReconAssetInventoryEvent, type ReconComputedStylesEvent, type ReconDesignTokensEvent, type ReconElementSnapshotEvent, type ReconEventType, type ReconFilter, type ReconFontsEvent, type ReconLayoutTreeEvent, type ReconMetadataEvent, type RedactionRule, Redactor, type RedactorConfig, type RenderComponentProfile, type RenderEvent, type RenderFilter, RingBuffer, type RulesFiles, type RuntimeEvent, type RuntimeLog, type SVGSpriteSymbol, type SchemaColumn, type SchemaForeignKey, type SchemaIndex, SchemaIntrospector, type SchemaTable, type ServerCommand, type ServerMetricName, type ServiceInfo, type SessionDiffResult, type SessionEvent, type SessionInfo, type SessionInfoExtended, SessionManager, type SessionMetrics, SessionRateLimiter, type SessionSnapshot, type SessionStats, type SpacingValue, type SpriteFrame, SqliteStore, type SqliteStoreOptions, type StateEvent, type StateFilter, type TaskPriority, type TaskSource, type TaskStatus, type TechStackDetection, type TimelineFilter, type TlsConfig, type ToolResponse, type TypographyToken, type WSMessage, type WebVitalRating, type WorkType, type WriteOptions, type WriteResult, aggregateQueryStats, calculateActiveMinutes, calculateCostMicrodollars, compareSessions, detectIssues, detectN1Queries, detectOverfetching, detectSlowQueries, generateApiKey, isSqliteAvailable, loadTlsOptions, parseSessionJsonl, resolveTlsConfig, suggestIndexes };
1827
+ /** Find PIDs listening on `port`. Cross-platform. */
1828
+ declare function getPidsOnPort(port: number): number[];
1829
+ /** Find which ports a PID is listening on. Cross-platform. */
1830
+ declare function getListenPorts(pid: number): number[];
1831
+ /** Get the working directory of a process. Returns undefined on Windows or failure. */
1832
+ declare function getProcessCwd(pid: number): string | undefined;
1833
+ /** Find PIDs with open files/cwd in a directory. Best-effort on Windows (returns []). */
1834
+ declare function findPidsInDirectory(dir: string): number[];
1835
+ interface ProcessInfo {
1836
+ pid: number;
1837
+ cpu: number;
1838
+ mem: number;
1839
+ command: string;
1840
+ }
1841
+ /** List all running processes. Cross-platform. */
1842
+ declare function parseProcessList(): ProcessInfo[];
1843
+ /** Get RSS memory in MB for a given PID. Cross-platform. */
1844
+ declare function getProcessMemoryMB(pid: number): number;
1845
+
1846
+ export { type ApiChangeRecord, type ApiContract, type ApiContractField, ApiDiscoveryEngine, type ApiEndpoint, type ApiEndpointHealth, type ApiKeyEntry, type AuthConfig, type AuthInfo, AuthManager, BUILT_IN_RULES, type BackgroundSpriteSheet, type BaseEvent, type BuildMeta, type BuildStatus, type CSSArchitecture, type CSSCustomProperty, type CapexClassification, type CapexSummary, CollectorServer, type CollectorServerOptions, type ColorToken, type CommandResponse, type ComputedStyleEntry, ConnectionManager, type ConsoleEvent, type ConsoleFilter, type ConsoleLevel, type CustomEvent, type CustomEventFilter, DataBrowser, type DatabaseConnectionConfig, type DatabaseEvent, type DatabaseFilter, type DatabaseOperation, type DatabaseSchema, type DatabaseSource, type DeployLog, type DetectedBuildTool, type DetectedFramework, type DetectedHosting, type DetectedIssue, type DetectedMetaFramework, type DetectedUILibrary, type DevProcess, type DevProcessType, type DomSnapshotEvent, type ElementSnapshotNode, type EventBatchPayload, EventStore, type EventType, type FontFaceInfo, type FontUsage, type FormFieldInfo, type GitCommit, type GitFileChange, type GitFileStatus, type GitStatus, type GlobalConfig, type GraphQLOperation, type HandshakePayload, type HeadingInfo, type HistoricalFilter, HttpServer, type HttpServerOptions, type IconFontInfo, type ImageAsset, type IndexSuggestion, InfraConnector, type InfraOverview, type InfrastructureConfig, type InlineSVGAsset, type InteractiveElementInfo, type IssueSeverity, type LandmarkInfo, type LayoutNode, type ManagedConnection, type MaskSpriteSheet, type MemoryFile, type MetricDelta, type NavigationEvent, type NetworkEvent, type NetworkFilter, type NormalizedQueryStats, type PerformanceEvent, type PerformanceFilter, type PerformanceMetricName, type PmCapexEntry, type PmNote, type PmProject, type PmSession, PmStore, type PmTask, type PortUsage, type ProcessInfo, ProcessMonitor, type ProjectConfig, ProjectDiscovery, ProjectManager, type ProjectPhase, type ProjectStatus, type RateLimitConfig, type ReadOptions, type ReadResult, type ReconAccessibilityEvent, type ReconAssetInventoryEvent, type ReconComputedStylesEvent, type ReconDesignTokensEvent, type ReconElementSnapshotEvent, type ReconEventType, type ReconFilter, type ReconFontsEvent, type ReconLayoutTreeEvent, type ReconMetadataEvent, type RedactionRule, Redactor, type RedactorConfig, type RenderComponentProfile, type RenderEvent, type RenderFilter, RingBuffer, type RulesFiles, type RuntimeEvent, type RuntimeLog, type SVGSpriteSymbol, type SchemaColumn, type SchemaForeignKey, type SchemaIndex, SchemaIntrospector, type SchemaTable, type ServerCommand, type ServerMetricName, type ServiceInfo, type SessionDiffResult, type SessionEvent, type SessionInfo, type SessionInfoExtended, SessionManager, type SessionMetrics, SessionRateLimiter, type SessionSnapshot, type SessionStats, type SpacingValue, type SpriteFrame, SqliteStore, type SqliteStoreOptions, type StateEvent, type StateFilter, type TaskPriority, type TaskSource, type TaskStatus, type TechStackDetection, type TimelineFilter, type TlsConfig, type ToolResponse, type TypographyToken, type UIInteractionAction, type UIInteractionEvent, type UIInteractionFilter, type UserContext, type WSMessage, type WebVitalRating, type WorkType, type WriteOptions, type WriteResult, aggregateQueryStats, calculateActiveMinutes, calculateCostMicrodollars, compareSessions, detectIssues, detectN1Queries, detectOverfetching, detectSlowQueries, findPidsInDirectory, generateApiKey, generateProjectId, getListenPorts, getOrCreateProjectId, getPidsOnPort, getProcessCwd, getProcessMemoryMB, isSqliteAvailable, isValidProjectId, loadTlsOptions, parseProcessList, parseSessionJsonl, resolveTlsConfig, suggestIndexes };
package/dist/index.js CHANGED
@@ -15,12 +15,21 @@ import {
15
15
  __require,
16
16
  calculateActiveMinutes,
17
17
  calculateCostMicrodollars,
18
+ findPidsInDirectory,
18
19
  generateApiKey,
20
+ generateProjectId,
21
+ getListenPorts,
22
+ getOrCreateProjectId,
23
+ getPidsOnPort,
24
+ getProcessCwd,
25
+ getProcessMemoryMB,
19
26
  isSqliteAvailable,
27
+ isValidProjectId,
20
28
  loadTlsOptions,
29
+ parseProcessList,
21
30
  parseSessionJsonl,
22
31
  resolveTlsConfig
23
- } from "./chunk-TUFSIGGJ.js";
32
+ } from "./chunk-HZWALDZM.js";
24
33
 
25
34
  // src/issue-detector.ts
26
35
  function detectIssues(events) {
@@ -1490,7 +1499,6 @@ var DataBrowser = class {
1490
1499
  };
1491
1500
 
1492
1501
  // src/engines/process-monitor.ts
1493
- import { execSync } from "child_process";
1494
1502
  var PROCESS_PATTERNS = [
1495
1503
  [/next[\s-]dev|next-server/, "next"],
1496
1504
  [/vite/, "vite"],
@@ -1512,65 +1520,6 @@ function detectProcessType(command) {
1512
1520
  }
1513
1521
  return "unknown";
1514
1522
  }
1515
- function parsePs() {
1516
- try {
1517
- const output = execSync("ps aux", { encoding: "utf-8", timeout: 5e3 });
1518
- const lines = output.split("\n").slice(1);
1519
- const results = [];
1520
- for (const line of lines) {
1521
- const parts = line.trim().split(/\s+/);
1522
- if (parts.length < 11) continue;
1523
- const pid = parseInt(parts[1], 10);
1524
- const cpu = parseFloat(parts[2]);
1525
- const mem = parseFloat(parts[3]);
1526
- const command = parts.slice(10).join(" ");
1527
- if (isNaN(pid)) continue;
1528
- results.push({ pid, cpu, mem, command });
1529
- }
1530
- return results;
1531
- } catch {
1532
- return [];
1533
- }
1534
- }
1535
- function getListenPorts(pid) {
1536
- try {
1537
- const output = execSync(`lsof -nP -p ${pid} 2>/dev/null | grep LISTEN`, {
1538
- encoding: "utf-8",
1539
- timeout: 3e3
1540
- });
1541
- const ports = [];
1542
- for (const line of output.split("\n")) {
1543
- const match = line.match(/:(\d+)\s+\(LISTEN\)/);
1544
- if (match) {
1545
- ports.push(parseInt(match[1], 10));
1546
- }
1547
- }
1548
- return [...new Set(ports)];
1549
- } catch {
1550
- return [];
1551
- }
1552
- }
1553
- function getCwd(pid) {
1554
- try {
1555
- const output = execSync(`lsof -p ${pid} 2>/dev/null | grep cwd`, {
1556
- encoding: "utf-8",
1557
- timeout: 3e3
1558
- });
1559
- const match = output.match(/cwd\s+\w+\s+\w+\s+\d+\w?\s+\d+\s+\d+\s+\d+\s+(.+)/);
1560
- return match?.[1]?.trim();
1561
- } catch {
1562
- return void 0;
1563
- }
1564
- }
1565
- function getMemoryMB(pid) {
1566
- try {
1567
- const output = execSync(`ps -o rss= -p ${pid}`, { encoding: "utf-8", timeout: 2e3 });
1568
- const rss = parseInt(output.trim(), 10);
1569
- return isNaN(rss) ? 0 : rss / 1024;
1570
- } catch {
1571
- return 0;
1572
- }
1573
- }
1574
1523
  var ProcessMonitor = class {
1575
1524
  store;
1576
1525
  scanInterval = null;
@@ -1590,7 +1539,7 @@ var ProcessMonitor = class {
1590
1539
  }
1591
1540
  }
1592
1541
  scan() {
1593
- const allProcesses = parsePs();
1542
+ const allProcesses = parseProcessList();
1594
1543
  const relevantTypes = /* @__PURE__ */ new Set([
1595
1544
  "next",
1596
1545
  "vite",
@@ -1616,8 +1565,8 @@ var ProcessMonitor = class {
1616
1565
  foundPids.add(proc.pid);
1617
1566
  const existing = this.processes.get(proc.pid);
1618
1567
  const ports = existing?.ports ?? getListenPorts(proc.pid);
1619
- const cwd = existing?.cwd ?? getCwd(proc.pid);
1620
- const memoryMB = getMemoryMB(proc.pid);
1568
+ const cwd = existing?.cwd ?? getProcessCwd(proc.pid);
1569
+ const memoryMB = getProcessMemoryMB(proc.pid);
1621
1570
  const lastActive = this.lastActivity.get(proc.pid) ?? Date.now();
1622
1571
  const isOrphaned = Date.now() - lastActive > 30 * 60 * 1e3;
1623
1572
  this.processes.set(proc.pid, {
@@ -2102,9 +2051,18 @@ export {
2102
2051
  detectN1Queries,
2103
2052
  detectOverfetching,
2104
2053
  detectSlowQueries,
2054
+ findPidsInDirectory,
2105
2055
  generateApiKey,
2056
+ generateProjectId,
2057
+ getListenPorts,
2058
+ getOrCreateProjectId,
2059
+ getPidsOnPort,
2060
+ getProcessCwd,
2061
+ getProcessMemoryMB,
2106
2062
  isSqliteAvailable,
2063
+ isValidProjectId,
2107
2064
  loadTlsOptions,
2065
+ parseProcessList,
2108
2066
  parseSessionJsonl,
2109
2067
  resolveTlsConfig,
2110
2068
  suggestIndexes