@probelabs/probe 0.6.0-rc207 → 0.6.0-rc208

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.
@@ -85,9 +85,11 @@ export class BashPermissionChecker {
85
85
  * @param {boolean} [config.disableDefaultAllow] - Disable default allow list
86
86
  * @param {boolean} [config.disableDefaultDeny] - Disable default deny list
87
87
  * @param {boolean} [config.debug] - Enable debug logging
88
+ * @param {Object} [config.tracer] - Optional tracer for telemetry
88
89
  */
89
90
  constructor(config = {}) {
90
91
  this.debug = config.debug || false;
92
+ this.tracer = config.tracer || null;
91
93
 
92
94
  // Build allow patterns
93
95
  this.allowPatterns = [];
@@ -122,6 +124,27 @@ export class BashPermissionChecker {
122
124
  if (this.debug) {
123
125
  console.log(`[BashPermissions] Total patterns - Allow: ${this.allowPatterns.length}, Deny: ${this.denyPatterns.length}`);
124
126
  }
127
+
128
+ // Record initialization event
129
+ this.recordBashEvent('permissions.initialized', {
130
+ allowPatternCount: this.allowPatterns.length,
131
+ denyPatternCount: this.denyPatterns.length,
132
+ hasCustomAllowPatterns: !!(config.allow && config.allow.length > 0),
133
+ hasCustomDenyPatterns: !!(config.deny && config.deny.length > 0),
134
+ disableDefaultAllow: !!config.disableDefaultAllow,
135
+ disableDefaultDeny: !!config.disableDefaultDeny
136
+ });
137
+ }
138
+
139
+ /**
140
+ * Record a bash telemetry event if tracer is available
141
+ * @param {string} eventType - Event type (e.g., 'permission.checked', 'permission.denied')
142
+ * @param {Object} data - Event data
143
+ */
144
+ recordBashEvent(eventType, data = {}) {
145
+ if (this.tracer && typeof this.tracer.recordBashEvent === 'function') {
146
+ this.tracer.recordBashEvent(eventType, data);
147
+ }
125
148
  }
126
149
 
127
150
  /**
@@ -131,11 +154,17 @@ export class BashPermissionChecker {
131
154
  */
132
155
  check(command) {
133
156
  if (!command || typeof command !== 'string') {
134
- return {
157
+ const result = {
135
158
  allowed: false,
136
159
  reason: 'Invalid or empty command',
137
160
  command: command
138
161
  };
162
+ this.recordBashEvent('permission.denied', {
163
+ command: String(command),
164
+ reason: result.reason,
165
+ isComplex: false
166
+ });
167
+ return result;
139
168
  }
140
169
 
141
170
  // Check if this is a complex command
@@ -150,19 +179,32 @@ export class BashPermissionChecker {
150
179
  const parsed = parseCommand(command);
151
180
 
152
181
  if (parsed.error) {
153
- return {
182
+ const result = {
154
183
  allowed: false,
155
184
  reason: parsed.error,
156
185
  command: command
157
186
  };
187
+ this.recordBashEvent('permission.denied', {
188
+ command,
189
+ reason: result.reason,
190
+ isComplex: false,
191
+ parseError: true
192
+ });
193
+ return result;
158
194
  }
159
195
 
160
196
  if (!parsed.command) {
161
- return {
197
+ const result = {
162
198
  allowed: false,
163
199
  reason: 'No valid command found',
164
200
  command: command
165
201
  };
202
+ this.recordBashEvent('permission.denied', {
203
+ command,
204
+ reason: result.reason,
205
+ isComplex: false
206
+ });
207
+ return result;
166
208
  }
167
209
 
168
210
  if (this.debug) {
@@ -173,24 +215,39 @@ export class BashPermissionChecker {
173
215
  // Check deny patterns first (deny takes precedence)
174
216
  if (matchesAnyPattern(parsed, this.denyPatterns)) {
175
217
  const matchedPatterns = this.denyPatterns.filter(pattern => matchesPattern(parsed, pattern));
176
- return {
218
+ const result = {
177
219
  allowed: false,
178
220
  reason: `Command matches deny pattern: ${matchedPatterns[0]}`,
179
221
  command: command,
180
222
  parsed: parsed,
181
223
  matchedPatterns: matchedPatterns
182
224
  };
225
+ this.recordBashEvent('permission.denied', {
226
+ command,
227
+ parsedCommand: parsed.command,
228
+ reason: 'matches_deny_pattern',
229
+ matchedPattern: matchedPatterns[0],
230
+ isComplex: false
231
+ });
232
+ return result;
183
233
  }
184
234
 
185
235
  // Check allow patterns
186
236
  if (this.allowPatterns.length > 0) {
187
237
  if (!matchesAnyPattern(parsed, this.allowPatterns)) {
188
- return {
238
+ const result = {
189
239
  allowed: false,
190
240
  reason: 'Command not in allow list',
191
241
  command: command,
192
242
  parsed: parsed
193
243
  };
244
+ this.recordBashEvent('permission.denied', {
245
+ command,
246
+ parsedCommand: parsed.command,
247
+ reason: 'not_in_allow_list',
248
+ isComplex: false
249
+ });
250
+ return result;
194
251
  }
195
252
  }
196
253
 
@@ -206,6 +263,12 @@ export class BashPermissionChecker {
206
263
  console.log(`[BashPermissions] ALLOWED - command passed all checks`);
207
264
  }
208
265
 
266
+ this.recordBashEvent('permission.allowed', {
267
+ command,
268
+ parsedCommand: parsed.command,
269
+ isComplex: false
270
+ });
271
+
209
272
  return result;
210
273
  }
211
274
 
@@ -235,13 +298,20 @@ export class BashPermissionChecker {
235
298
  if (this.debug) {
236
299
  console.log(`[BashPermissions] DENIED - matches complex deny pattern: ${pattern}`);
237
300
  }
238
- return {
301
+ const result = {
239
302
  allowed: false,
240
303
  reason: `Command matches deny pattern: ${pattern}`,
241
304
  command: command,
242
305
  isComplex: true,
243
306
  matchedPatterns: [pattern]
244
307
  };
308
+ this.recordBashEvent('permission.denied', {
309
+ command,
310
+ reason: 'matches_deny_pattern',
311
+ matchedPattern: pattern,
312
+ isComplex: true
313
+ });
314
+ return result;
245
315
  }
246
316
  }
247
317
 
@@ -251,12 +321,18 @@ export class BashPermissionChecker {
251
321
  if (this.debug) {
252
322
  console.log(`[BashPermissions] ALLOWED - matches complex allow pattern: ${pattern}`);
253
323
  }
254
- return {
324
+ const result = {
255
325
  allowed: true,
256
326
  command: command,
257
327
  isComplex: true,
258
328
  matchedPattern: pattern
259
329
  };
330
+ this.recordBashEvent('permission.allowed', {
331
+ command,
332
+ matchedPattern: pattern,
333
+ isComplex: true
334
+ });
335
+ return result;
260
336
  }
261
337
  }
262
338
 
@@ -264,6 +340,11 @@ export class BashPermissionChecker {
264
340
  if (this.debug) {
265
341
  console.log(`[BashPermissions] DENIED - no matching complex pattern found`);
266
342
  }
343
+ this.recordBashEvent('permission.denied', {
344
+ command,
345
+ reason: 'no_matching_complex_pattern',
346
+ isComplex: true
347
+ });
267
348
  return {
268
349
  allowed: false,
269
350
  reason: 'Complex shell commands require explicit allow patterns (e.g., "cd * && git *")',