@sparkleideas/shared 3.0.0-alpha.7

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 (96) hide show
  1. package/README.md +323 -0
  2. package/__tests__/hooks/bash-safety.test.ts +289 -0
  3. package/__tests__/hooks/file-organization.test.ts +335 -0
  4. package/__tests__/hooks/git-commit.test.ts +336 -0
  5. package/__tests__/hooks/index.ts +23 -0
  6. package/__tests__/hooks/session-hooks.test.ts +357 -0
  7. package/__tests__/hooks/task-hooks.test.ts +193 -0
  8. package/docs/EVENTS_IMPLEMENTATION_SUMMARY.md +388 -0
  9. package/docs/EVENTS_QUICK_REFERENCE.md +470 -0
  10. package/docs/EVENTS_README.md +352 -0
  11. package/package.json +39 -0
  12. package/src/core/config/defaults.ts +207 -0
  13. package/src/core/config/index.ts +15 -0
  14. package/src/core/config/loader.ts +271 -0
  15. package/src/core/config/schema.ts +188 -0
  16. package/src/core/config/validator.ts +209 -0
  17. package/src/core/event-bus.ts +236 -0
  18. package/src/core/index.ts +22 -0
  19. package/src/core/interfaces/agent.interface.ts +251 -0
  20. package/src/core/interfaces/coordinator.interface.ts +363 -0
  21. package/src/core/interfaces/event.interface.ts +267 -0
  22. package/src/core/interfaces/index.ts +19 -0
  23. package/src/core/interfaces/memory.interface.ts +332 -0
  24. package/src/core/interfaces/task.interface.ts +223 -0
  25. package/src/core/orchestrator/event-coordinator.ts +122 -0
  26. package/src/core/orchestrator/health-monitor.ts +214 -0
  27. package/src/core/orchestrator/index.ts +89 -0
  28. package/src/core/orchestrator/lifecycle-manager.ts +263 -0
  29. package/src/core/orchestrator/session-manager.ts +279 -0
  30. package/src/core/orchestrator/task-manager.ts +317 -0
  31. package/src/events/domain-events.ts +584 -0
  32. package/src/events/event-store.test.ts +387 -0
  33. package/src/events/event-store.ts +588 -0
  34. package/src/events/example-usage.ts +293 -0
  35. package/src/events/index.ts +90 -0
  36. package/src/events/projections.ts +561 -0
  37. package/src/events/state-reconstructor.ts +349 -0
  38. package/src/events.ts +367 -0
  39. package/src/hooks/INTEGRATION.md +658 -0
  40. package/src/hooks/README.md +532 -0
  41. package/src/hooks/example-usage.ts +499 -0
  42. package/src/hooks/executor.ts +379 -0
  43. package/src/hooks/hooks.test.ts +421 -0
  44. package/src/hooks/index.ts +131 -0
  45. package/src/hooks/registry.ts +333 -0
  46. package/src/hooks/safety/bash-safety.ts +604 -0
  47. package/src/hooks/safety/file-organization.ts +473 -0
  48. package/src/hooks/safety/git-commit.ts +623 -0
  49. package/src/hooks/safety/index.ts +46 -0
  50. package/src/hooks/session-hooks.ts +559 -0
  51. package/src/hooks/task-hooks.ts +513 -0
  52. package/src/hooks/types.ts +357 -0
  53. package/src/hooks/verify-exports.test.ts +125 -0
  54. package/src/index.ts +195 -0
  55. package/src/mcp/connection-pool.ts +438 -0
  56. package/src/mcp/index.ts +183 -0
  57. package/src/mcp/server.ts +774 -0
  58. package/src/mcp/session-manager.ts +428 -0
  59. package/src/mcp/tool-registry.ts +566 -0
  60. package/src/mcp/transport/http.ts +557 -0
  61. package/src/mcp/transport/index.ts +294 -0
  62. package/src/mcp/transport/stdio.ts +324 -0
  63. package/src/mcp/transport/websocket.ts +484 -0
  64. package/src/mcp/types.ts +565 -0
  65. package/src/plugin-interface.ts +663 -0
  66. package/src/plugin-loader.ts +638 -0
  67. package/src/plugin-registry.ts +604 -0
  68. package/src/plugins/index.ts +34 -0
  69. package/src/plugins/official/hive-mind-plugin.ts +330 -0
  70. package/src/plugins/official/index.ts +24 -0
  71. package/src/plugins/official/maestro-plugin.ts +508 -0
  72. package/src/plugins/types.ts +108 -0
  73. package/src/resilience/bulkhead.ts +277 -0
  74. package/src/resilience/circuit-breaker.ts +326 -0
  75. package/src/resilience/index.ts +26 -0
  76. package/src/resilience/rate-limiter.ts +420 -0
  77. package/src/resilience/retry.ts +224 -0
  78. package/src/security/index.ts +39 -0
  79. package/src/security/input-validation.ts +265 -0
  80. package/src/security/secure-random.ts +159 -0
  81. package/src/services/index.ts +16 -0
  82. package/src/services/v3-progress.service.ts +505 -0
  83. package/src/types/agent.types.ts +144 -0
  84. package/src/types/index.ts +22 -0
  85. package/src/types/mcp.types.ts +300 -0
  86. package/src/types/memory.types.ts +263 -0
  87. package/src/types/swarm.types.ts +255 -0
  88. package/src/types/task.types.ts +205 -0
  89. package/src/types.ts +367 -0
  90. package/src/utils/secure-logger.d.ts +69 -0
  91. package/src/utils/secure-logger.d.ts.map +1 -0
  92. package/src/utils/secure-logger.js +208 -0
  93. package/src/utils/secure-logger.js.map +1 -0
  94. package/src/utils/secure-logger.ts +257 -0
  95. package/tmp.json +0 -0
  96. package/tsconfig.json +9 -0
package/src/types.ts ADDED
@@ -0,0 +1,367 @@
1
+ /**
2
+ * V3 Claude-Flow Shared Types
3
+ * Core type definitions for the 15-agent swarm coordination system
4
+ *
5
+ * Based on ADR-002 (DDD) and ADR-003 (Single Coordination Engine)
6
+ */
7
+
8
+ // =============================================================================
9
+ // Agent Types
10
+ // =============================================================================
11
+
12
+ export type AgentId = `agent-${number}` | string;
13
+
14
+ export type AgentRole =
15
+ | 'queen-coordinator' // Agent #1
16
+ | 'security-architect' // Agent #2
17
+ | 'security-implementer' // Agent #3
18
+ | 'security-tester' // Agent #4
19
+ | 'core-architect' // Agent #5
20
+ | 'core-implementer' // Agent #6
21
+ | 'memory-specialist' // Agent #7
22
+ | 'swarm-specialist' // Agent #8
23
+ | 'mcp-specialist' // Agent #9
24
+ | 'integration-architect' // Agent #10
25
+ | 'cli-hooks-developer' // Agent #11
26
+ | 'neural-learning-dev' // Agent #12
27
+ | 'tdd-test-engineer' // Agent #13
28
+ | 'performance-engineer' // Agent #14
29
+ | 'release-engineer'; // Agent #15
30
+
31
+ export type AgentStatus =
32
+ | 'idle'
33
+ | 'active'
34
+ | 'blocked'
35
+ | 'completed'
36
+ | 'error';
37
+
38
+ export type AgentDomain =
39
+ | 'security' // Agents #2-4
40
+ | 'core' // Agents #5-9
41
+ | 'integration' // Agents #10-12
42
+ | 'quality' // Agent #13
43
+ | 'performance' // Agent #14
44
+ | 'deployment'; // Agent #15
45
+
46
+ export interface AgentCapability {
47
+ name: string;
48
+ description: string;
49
+ supportedTaskTypes: TaskType[];
50
+ }
51
+
52
+ export interface AgentDefinition {
53
+ id: AgentId;
54
+ role: AgentRole;
55
+ domain: AgentDomain;
56
+ description: string;
57
+ capabilities: AgentCapability[];
58
+ dependencies: AgentId[];
59
+ priority: number;
60
+ }
61
+
62
+ export interface AgentState {
63
+ id: AgentId;
64
+ role: AgentRole;
65
+ status: AgentStatus;
66
+ currentTask: TaskId | null;
67
+ completedTasks: TaskId[];
68
+ metrics: AgentMetrics;
69
+ lastHeartbeat: number;
70
+ }
71
+
72
+ export interface AgentMetrics {
73
+ tasksCompleted: number;
74
+ tasksFailed: number;
75
+ averageTaskDuration: number;
76
+ utilization: number;
77
+ startTime: number;
78
+ }
79
+
80
+ // =============================================================================
81
+ // Task Types
82
+ // =============================================================================
83
+
84
+ export type TaskId = `task-${string}`;
85
+
86
+ export type TaskType =
87
+ | 'security-audit'
88
+ | 'security-fix'
89
+ | 'security-test'
90
+ | 'architecture-design'
91
+ | 'implementation'
92
+ | 'memory-optimization'
93
+ | 'swarm-coordination'
94
+ | 'mcp-enhancement'
95
+ | 'integration'
96
+ | 'cli-development'
97
+ | 'neural-training'
98
+ | 'test-writing'
99
+ | 'benchmark'
100
+ | 'deployment'
101
+ | 'documentation';
102
+
103
+ export type TaskStatus =
104
+ | 'pending'
105
+ | 'queued'
106
+ | 'assigned'
107
+ | 'in-progress'
108
+ | 'blocked'
109
+ | 'completed'
110
+ | 'failed'
111
+ | 'cancelled';
112
+
113
+ export type TaskPriority =
114
+ | 'critical'
115
+ | 'high'
116
+ | 'medium'
117
+ | 'low';
118
+
119
+ export interface TaskDefinition {
120
+ id: TaskId;
121
+ type: TaskType;
122
+ title: string;
123
+ description: string;
124
+ assignedAgent: AgentId | null;
125
+ status: TaskStatus;
126
+ priority: TaskPriority;
127
+ dependencies: TaskId[];
128
+ blockedBy: TaskId[];
129
+ metadata: TaskMetadata;
130
+ createdAt: number;
131
+ updatedAt: number;
132
+ completedAt: number | null;
133
+ }
134
+
135
+ export interface TaskMetadata {
136
+ domain: AgentDomain;
137
+ phase: PhaseId;
138
+ estimatedDuration: number;
139
+ actualDuration: number | null;
140
+ retryCount: number;
141
+ maxRetries: number;
142
+ artifacts: string[];
143
+ tags: string[];
144
+ }
145
+
146
+ export interface TaskResult {
147
+ taskId: TaskId;
148
+ success: boolean;
149
+ output: unknown;
150
+ error: Error | null;
151
+ duration: number;
152
+ metrics: TaskResultMetrics;
153
+ }
154
+
155
+ export interface TaskResultMetrics {
156
+ linesOfCode: number;
157
+ testsWritten: number;
158
+ testsPassed: number;
159
+ coveragePercent: number;
160
+ performanceImpact: number;
161
+ }
162
+
163
+ // =============================================================================
164
+ // Phase Types
165
+ // =============================================================================
166
+
167
+ export type PhaseId =
168
+ | 'phase-1-foundation'
169
+ | 'phase-2-core'
170
+ | 'phase-3-integration'
171
+ | 'phase-4-release';
172
+
173
+ export interface PhaseDefinition {
174
+ id: PhaseId;
175
+ name: string;
176
+ description: string;
177
+ weeks: [number, number];
178
+ activeAgents: AgentId[];
179
+ goals: string[];
180
+ milestones: MilestoneDefinition[];
181
+ }
182
+
183
+ export interface MilestoneDefinition {
184
+ id: string;
185
+ name: string;
186
+ description: string;
187
+ criteria: MilestoneCriteria[];
188
+ status: MilestoneStatus;
189
+ completedAt: number | null;
190
+ }
191
+
192
+ export type MilestoneStatus = 'pending' | 'in-progress' | 'completed' | 'blocked';
193
+
194
+ export interface MilestoneCriteria {
195
+ description: string;
196
+ met: boolean;
197
+ evidence: string | null;
198
+ }
199
+
200
+ // =============================================================================
201
+ // Swarm Types
202
+ // =============================================================================
203
+
204
+ export type TopologyType =
205
+ | 'hierarchical-mesh'
206
+ | 'mesh'
207
+ | 'hierarchical'
208
+ | 'centralized';
209
+
210
+ export interface SwarmConfig {
211
+ topology: TopologyType;
212
+ maxAgents: number;
213
+ messageTimeout: number;
214
+ retryAttempts: number;
215
+ healthCheckInterval: number;
216
+ loadBalancingStrategy: LoadBalancingStrategy;
217
+ }
218
+
219
+ export type LoadBalancingStrategy =
220
+ | 'round-robin'
221
+ | 'least-loaded'
222
+ | 'capability-match'
223
+ | 'priority-based';
224
+
225
+ export interface SwarmState {
226
+ initialized: boolean;
227
+ topology: TopologyType;
228
+ agents: Map<AgentId, AgentState>;
229
+ tasks: Map<TaskId, TaskDefinition>;
230
+ currentPhase: PhaseId;
231
+ metrics: SwarmMetrics;
232
+ }
233
+
234
+ export interface SwarmMetrics {
235
+ totalAgents: number;
236
+ activeAgents: number;
237
+ idleAgents: number;
238
+ blockedAgents: number;
239
+ totalTasks: number;
240
+ completedTasks: number;
241
+ failedTasks: number;
242
+ pendingTasks: number;
243
+ averageTaskDuration: number;
244
+ utilization: number;
245
+ startTime: number;
246
+ lastUpdate: number;
247
+ }
248
+
249
+ // =============================================================================
250
+ // Event Types
251
+ // =============================================================================
252
+
253
+ export type EventType =
254
+ | 'agent:spawned'
255
+ | 'agent:status-changed'
256
+ | 'agent:task-assigned'
257
+ | 'agent:task-completed'
258
+ | 'agent:error'
259
+ | 'task:created'
260
+ | 'task:queued'
261
+ | 'task:assigned'
262
+ | 'task:started'
263
+ | 'task:completed'
264
+ | 'task:failed'
265
+ | 'task:blocked'
266
+ | 'swarm:initialized'
267
+ | 'swarm:phase-changed'
268
+ | 'swarm:milestone-reached'
269
+ | 'swarm:error';
270
+
271
+ export interface SwarmEvent<T = unknown> {
272
+ id: string;
273
+ type: EventType;
274
+ timestamp: number;
275
+ source: AgentId | 'swarm';
276
+ payload: T;
277
+ }
278
+
279
+ export type EventHandler<T = unknown> = (event: SwarmEvent<T>) => void | Promise<void>;
280
+
281
+ // =============================================================================
282
+ // Message Types
283
+ // =============================================================================
284
+
285
+ export type MessageType =
286
+ | 'task_assignment'
287
+ | 'task_complete'
288
+ | 'task_failed'
289
+ | 'dependency_ready'
290
+ | 'review_request'
291
+ | 'status_update'
292
+ | 'heartbeat'
293
+ | 'broadcast';
294
+
295
+ export interface SwarmMessage<T = unknown> {
296
+ id: string;
297
+ type: MessageType;
298
+ from: AgentId;
299
+ to: AgentId | 'broadcast';
300
+ payload: T;
301
+ timestamp: number;
302
+ correlationId: string | null;
303
+ }
304
+
305
+ export type MessageHandler<T = unknown> = (message: SwarmMessage<T>) => void | Promise<void>;
306
+
307
+ // =============================================================================
308
+ // Performance Targets
309
+ // =============================================================================
310
+
311
+ export interface PerformanceTargets {
312
+ flashAttention: {
313
+ minSpeedup: number;
314
+ maxSpeedup: number;
315
+ };
316
+ agentDbSearch: {
317
+ minSpeedup: number;
318
+ maxSpeedup: number;
319
+ };
320
+ memoryReduction: {
321
+ minPercent: number;
322
+ maxPercent: number;
323
+ };
324
+ codeReduction: {
325
+ targetLines: number;
326
+ currentLines: number;
327
+ };
328
+ startupTime: {
329
+ targetMs: number;
330
+ };
331
+ sonaLearning: {
332
+ targetMs: number;
333
+ };
334
+ }
335
+
336
+ export const V3_PERFORMANCE_TARGETS: PerformanceTargets = {
337
+ flashAttention: { minSpeedup: 2.49, maxSpeedup: 7.47 },
338
+ agentDbSearch: { minSpeedup: 150, maxSpeedup: 12500 },
339
+ memoryReduction: { minPercent: 50, maxPercent: 75 },
340
+ codeReduction: { targetLines: 5000, currentLines: 15000 },
341
+ startupTime: { targetMs: 500 },
342
+ sonaLearning: { targetMs: 0.05 }
343
+ };
344
+
345
+ // =============================================================================
346
+ // Utility Types
347
+ // =============================================================================
348
+
349
+ export type DeepPartial<T> = {
350
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
351
+ };
352
+
353
+ export type AsyncCallback<T = void> = () => Promise<T>;
354
+
355
+ export interface Result<T, E = Error> {
356
+ success: boolean;
357
+ value?: T;
358
+ error?: E;
359
+ }
360
+
361
+ export function success<T>(value: T): Result<T> {
362
+ return { success: true, value };
363
+ }
364
+
365
+ export function failure<E = Error>(error: E): Result<never, E> {
366
+ return { success: false, error };
367
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Secure Logger Utility
3
+ *
4
+ * Provides sanitized error logging that strips sensitive information
5
+ * before logging to prevent information disclosure.
6
+ *
7
+ * Security features:
8
+ * - Removes stack traces in production
9
+ * - Sanitizes file paths to prevent internal structure disclosure
10
+ * - Filters sensitive keys from error objects
11
+ * - Truncates long messages to prevent log injection
12
+ *
13
+ * @module @sparkleideas/shared/utils/secure-logger
14
+ */
15
+ interface LoggerConfig {
16
+ /** Environment mode */
17
+ environment: 'development' | 'production' | 'test';
18
+ /** Maximum message length */
19
+ maxMessageLength: number;
20
+ /** Whether to include stack traces */
21
+ includeStackTrace: boolean;
22
+ /** Sensitive keys to filter */
23
+ sensitiveKeys: string[];
24
+ /** Path patterns to sanitize */
25
+ pathPatterns: RegExp[];
26
+ }
27
+ export declare class SecureLogger {
28
+ private config;
29
+ private prefix;
30
+ constructor(prefix?: string, config?: Partial<LoggerConfig>);
31
+ /**
32
+ * Log an info message
33
+ */
34
+ info(message: string, data?: Record<string, unknown>): void;
35
+ /**
36
+ * Log a warning message
37
+ */
38
+ warn(message: string, data?: Record<string, unknown>): void;
39
+ /**
40
+ * Log an error (sanitized for security)
41
+ */
42
+ error(message: string, error?: unknown): void;
43
+ /**
44
+ * Log debug message (only in development)
45
+ */
46
+ debug(message: string, data?: Record<string, unknown>): void;
47
+ /**
48
+ * Create a child logger with a sub-prefix
49
+ */
50
+ child(subPrefix: string): SecureLogger;
51
+ }
52
+ /**
53
+ * Create a secure logger instance
54
+ */
55
+ export declare function createSecureLogger(prefix?: string, config?: Partial<LoggerConfig>): SecureLogger;
56
+ /**
57
+ * Default logger instance
58
+ */
59
+ export declare const logger: SecureLogger;
60
+ /**
61
+ * Sanitize an error for safe logging/display
62
+ */
63
+ export declare function sanitizeErrorForLogging(error: unknown): Record<string, unknown>;
64
+ /**
65
+ * Sanitize a message for safe logging/display
66
+ */
67
+ export declare function sanitizeMessageForLogging(message: string): string;
68
+ export default SecureLogger;
69
+ //# sourceMappingURL=secure-logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-logger.d.ts","sourceRoot":"","sources":["secure-logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,UAAU,YAAY;IACpB,uBAAuB;IACvB,WAAW,EAAE,aAAa,GAAG,YAAY,GAAG,MAAM,CAAC;IACnD,6BAA6B;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,sCAAsC;IACtC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,+BAA+B;IAC/B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,gCAAgC;IAChC,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAsHD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,GAAE,MAAW,EAAE,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM;IAKnE;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAW3D;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAW3D;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;IAW7C;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAe5D;;OAEG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY;CAIvC;AAMD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAEhG;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,cAAoC,CAAC;AAExD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE/E;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Secure Logger Utility
3
+ *
4
+ * Provides sanitized error logging that strips sensitive information
5
+ * before logging to prevent information disclosure.
6
+ *
7
+ * Security features:
8
+ * - Removes stack traces in production
9
+ * - Sanitizes file paths to prevent internal structure disclosure
10
+ * - Filters sensitive keys from error objects
11
+ * - Truncates long messages to prevent log injection
12
+ *
13
+ * @module @sparkleideas/shared/utils/secure-logger
14
+ */
15
+ const DEFAULT_CONFIG = {
16
+ environment: process.env.NODE_ENV || 'development',
17
+ maxMessageLength: 1000,
18
+ includeStackTrace: process.env.NODE_ENV === 'development',
19
+ sensitiveKeys: [
20
+ 'password', 'passwd', 'secret', 'token', 'apikey', 'api_key',
21
+ 'authorization', 'auth', 'credential', 'private', 'key',
22
+ 'session', 'cookie', 'jwt', 'bearer', 'access_token', 'refresh_token',
23
+ ],
24
+ pathPatterns: [
25
+ /\/home\/[^/]+/g, // Unix home directories
26
+ /\/Users\/[^/]+/g, // macOS home directories
27
+ /C:\\Users\\[^\\]+/gi, // Windows user directories
28
+ /\/var\/[^/]+/g, // Var directories
29
+ /\/tmp\/[^/]+/g, // Temp directories
30
+ ],
31
+ };
32
+ // ============================================================================
33
+ // Sanitization Functions
34
+ // ============================================================================
35
+ /**
36
+ * Sanitize a string message
37
+ */
38
+ function sanitizeMessage(message, config) {
39
+ let sanitized = message;
40
+ // Truncate long messages
41
+ if (sanitized.length > config.maxMessageLength) {
42
+ sanitized = sanitized.substring(0, config.maxMessageLength) + '... [truncated]';
43
+ }
44
+ // Sanitize paths
45
+ for (const pattern of config.pathPatterns) {
46
+ sanitized = sanitized.replace(pattern, '[PATH]');
47
+ }
48
+ // Remove potential sensitive data patterns
49
+ sanitized = sanitized.replace(/[a-zA-Z0-9+/]{40,}={0,2}/g, '[REDACTED_KEY]');
50
+ sanitized = sanitized.replace(/Bearer\s+[^\s]+/gi, 'Bearer [REDACTED]');
51
+ sanitized = sanitized.replace(/token[=:]\s*[^\s&]+/gi, 'token=[REDACTED]');
52
+ return sanitized;
53
+ }
54
+ /**
55
+ * Sanitize an error object
56
+ */
57
+ function sanitizeError(error, config) {
58
+ if (error === null || error === undefined) {
59
+ return { message: 'Unknown error' };
60
+ }
61
+ if (typeof error === 'string') {
62
+ return { message: sanitizeMessage(error, config) };
63
+ }
64
+ if (error instanceof Error) {
65
+ const sanitized = {
66
+ name: error.name,
67
+ message: sanitizeMessage(error.message, config),
68
+ };
69
+ // Only include stack in development
70
+ if (config.includeStackTrace && error.stack) {
71
+ sanitized.stack = sanitizeMessage(error.stack, config);
72
+ }
73
+ // Include code if present (common in Node.js errors)
74
+ if ('code' in error) {
75
+ sanitized.code = error.code;
76
+ }
77
+ return sanitized;
78
+ }
79
+ if (typeof error === 'object') {
80
+ return sanitizeObject(error, config);
81
+ }
82
+ return { message: String(error) };
83
+ }
84
+ /**
85
+ * Sanitize a plain object
86
+ */
87
+ function sanitizeObject(obj, config) {
88
+ const sanitized = {};
89
+ for (const [key, value] of Object.entries(obj)) {
90
+ const lowerKey = key.toLowerCase();
91
+ // Skip sensitive keys
92
+ if (config.sensitiveKeys.some(sk => lowerKey.includes(sk))) {
93
+ sanitized[key] = '[REDACTED]';
94
+ continue;
95
+ }
96
+ // Recursively sanitize nested objects
97
+ if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
98
+ sanitized[key] = sanitizeObject(value, config);
99
+ }
100
+ else if (typeof value === 'string') {
101
+ sanitized[key] = sanitizeMessage(value, config);
102
+ }
103
+ else {
104
+ sanitized[key] = value;
105
+ }
106
+ }
107
+ return sanitized;
108
+ }
109
+ // ============================================================================
110
+ // Logger Class
111
+ // ============================================================================
112
+ export class SecureLogger {
113
+ config;
114
+ prefix;
115
+ constructor(prefix = '', config = {}) {
116
+ this.prefix = prefix;
117
+ this.config = { ...DEFAULT_CONFIG, ...config };
118
+ }
119
+ /**
120
+ * Log an info message
121
+ */
122
+ info(message, data) {
123
+ const sanitizedMessage = sanitizeMessage(message, this.config);
124
+ const sanitizedData = data ? sanitizeObject(data, this.config) : undefined;
125
+ if (sanitizedData) {
126
+ console.info(`[INFO]${this.prefix ? ` [${this.prefix}]` : ''} ${sanitizedMessage}`, sanitizedData);
127
+ }
128
+ else {
129
+ console.info(`[INFO]${this.prefix ? ` [${this.prefix}]` : ''} ${sanitizedMessage}`);
130
+ }
131
+ }
132
+ /**
133
+ * Log a warning message
134
+ */
135
+ warn(message, data) {
136
+ const sanitizedMessage = sanitizeMessage(message, this.config);
137
+ const sanitizedData = data ? sanitizeObject(data, this.config) : undefined;
138
+ if (sanitizedData) {
139
+ console.warn(`[WARN]${this.prefix ? ` [${this.prefix}]` : ''} ${sanitizedMessage}`, sanitizedData);
140
+ }
141
+ else {
142
+ console.warn(`[WARN]${this.prefix ? ` [${this.prefix}]` : ''} ${sanitizedMessage}`);
143
+ }
144
+ }
145
+ /**
146
+ * Log an error (sanitized for security)
147
+ */
148
+ error(message, error) {
149
+ const sanitizedMessage = sanitizeMessage(message, this.config);
150
+ const sanitizedError = error ? sanitizeError(error, this.config) : undefined;
151
+ if (sanitizedError) {
152
+ console.error(`[ERROR]${this.prefix ? ` [${this.prefix}]` : ''} ${sanitizedMessage}`, sanitizedError);
153
+ }
154
+ else {
155
+ console.error(`[ERROR]${this.prefix ? ` [${this.prefix}]` : ''} ${sanitizedMessage}`);
156
+ }
157
+ }
158
+ /**
159
+ * Log debug message (only in development)
160
+ */
161
+ debug(message, data) {
162
+ if (this.config.environment !== 'development') {
163
+ return;
164
+ }
165
+ const sanitizedMessage = sanitizeMessage(message, this.config);
166
+ const sanitizedData = data ? sanitizeObject(data, this.config) : undefined;
167
+ if (sanitizedData) {
168
+ console.debug(`[DEBUG]${this.prefix ? ` [${this.prefix}]` : ''} ${sanitizedMessage}`, sanitizedData);
169
+ }
170
+ else {
171
+ console.debug(`[DEBUG]${this.prefix ? ` [${this.prefix}]` : ''} ${sanitizedMessage}`);
172
+ }
173
+ }
174
+ /**
175
+ * Create a child logger with a sub-prefix
176
+ */
177
+ child(subPrefix) {
178
+ const newPrefix = this.prefix ? `${this.prefix}:${subPrefix}` : subPrefix;
179
+ return new SecureLogger(newPrefix, this.config);
180
+ }
181
+ }
182
+ // ============================================================================
183
+ // Factory Functions
184
+ // ============================================================================
185
+ /**
186
+ * Create a secure logger instance
187
+ */
188
+ export function createSecureLogger(prefix, config) {
189
+ return new SecureLogger(prefix, config);
190
+ }
191
+ /**
192
+ * Default logger instance
193
+ */
194
+ export const logger = createSecureLogger('@sparkleideas/claude-flow');
195
+ /**
196
+ * Sanitize an error for safe logging/display
197
+ */
198
+ export function sanitizeErrorForLogging(error) {
199
+ return sanitizeError(error, DEFAULT_CONFIG);
200
+ }
201
+ /**
202
+ * Sanitize a message for safe logging/display
203
+ */
204
+ export function sanitizeMessageForLogging(message) {
205
+ return sanitizeMessage(message, DEFAULT_CONFIG);
206
+ }
207
+ export default SecureLogger;
208
+ //# sourceMappingURL=secure-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-logger.js","sourceRoot":"","sources":["secure-logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAmBH,MAAM,cAAc,GAAiB;IACnC,WAAW,EAAG,OAAO,CAAC,GAAG,CAAC,QAAwC,IAAI,aAAa;IACnF,gBAAgB,EAAE,IAAI;IACtB,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;IACzD,aAAa,EAAE;QACb,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,E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