@the-magic-tower/fixhive-opencode-plugin 0.1.13 → 0.1.14

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,618 +1,35 @@
1
- import { Plugin } from '@opencode-ai/plugin';
2
- import Database from 'better-sqlite3';
3
-
4
1
  /**
5
- * FixHive OpenCode Plugin
6
- * Community-based error knowledge sharing plugin for OpenCode
7
- */
8
-
9
- /**
10
- * FixHive Plugin Factory
11
- */
12
- declare const FixHivePlugin: Plugin;
13
-
14
- /**
15
- * FixHive Type Definitions
16
- * Community-based error knowledge sharing for OpenCode
17
- */
18
- type ErrorType = 'runtime' | 'build' | 'lint' | 'test' | 'network' | 'permission' | 'dependency' | 'syntax' | 'type_error' | 'unknown';
19
- type ErrorStatus = 'unresolved' | 'resolved' | 'uploaded';
20
- type Language = 'typescript' | 'javascript' | 'python' | 'rust' | 'go' | 'java' | 'ruby' | 'php' | 'csharp' | 'cpp' | 'other';
21
- type Severity = 'critical' | 'error' | 'warning';
22
- interface LocalErrorRecord {
23
- id: string;
24
- errorHash: string;
25
- errorType: ErrorType;
26
- errorMessage: string;
27
- errorStack?: string;
28
- language?: Language;
29
- framework?: string;
30
- toolName: string;
31
- toolInput: Record<string, unknown>;
32
- sessionId: string;
33
- status: ErrorStatus;
34
- resolution?: string;
35
- resolutionCode?: string;
36
- createdAt: string;
37
- resolvedAt?: string;
38
- uploadedAt?: string;
39
- cloudKnowledgeId?: string;
40
- }
41
- interface QueryCacheEntry {
42
- id: string;
43
- errorHash: string;
44
- results: CloudKnowledgeEntry[];
45
- createdAt: string;
46
- expiresAt: string;
47
- }
48
- interface LocalStats {
49
- totalErrors: number;
50
- resolvedErrors: number;
51
- uploadedErrors: number;
52
- }
53
- interface CloudKnowledgeEntry {
54
- id: string;
55
- errorHash: string;
56
- errorType: ErrorType;
57
- errorMessage: string;
58
- errorStack?: string;
59
- language: Language;
60
- framework?: string;
61
- dependencies?: Record<string, string>;
62
- embedding?: number[];
63
- resolutionDescription: string;
64
- resolutionCode?: string;
65
- resolutionSteps?: string[];
66
- contributorId: string;
67
- upvotes: number;
68
- downvotes: number;
69
- usageCount: number;
70
- createdAt: string;
71
- updatedAt: string;
72
- isVerified: boolean;
73
- similarity?: number;
74
- }
75
- interface DuplicateCheckResult {
76
- isDuplicate: boolean;
77
- existingId?: string;
78
- similarityScore: number;
79
- }
80
- interface ContributorStats {
81
- contributionCount: number;
82
- helpedCount: number;
83
- totalUpvotes: number;
84
- }
85
- interface DetectedSignal {
86
- type: 'exit_code' | 'stderr' | 'pattern' | 'stack_trace';
87
- weight: number;
88
- value: string | number;
89
- description: string;
90
- }
91
- interface ErrorDetectionResult {
92
- detected: boolean;
93
- confidence: number;
94
- errorType: ErrorType;
95
- severity: Severity;
96
- signals: DetectedSignal[];
97
- errorMessage: string;
98
- errorStack?: string;
99
- rawOutput: string;
100
- }
101
- interface StackFrame {
102
- function: string;
103
- file: string;
104
- line: number;
105
- column?: number;
106
- isProjectCode: boolean;
107
- }
108
- interface StackTraceInfo {
109
- hasStackTrace: boolean;
110
- language: string | null;
111
- frames: string[];
112
- }
113
- interface FixHiveContext {
114
- sessionId: string;
115
- projectDirectory: string;
116
- language?: Language;
117
- framework?: string;
118
- }
119
- interface ToolOutput {
120
- tool: string;
121
- output: string;
122
- exitCode?: number;
123
- stderr?: string;
124
- metadata?: Record<string, unknown>;
125
- }
126
- interface PrivacyFilterRule {
127
- name: string;
128
- category: 'secret' | 'identity' | 'infrastructure' | 'path' | 'environment';
129
- pattern: RegExp;
130
- replacement: string | ((match: string, ...groups: string[]) => string);
131
- priority: number;
132
- }
133
- interface SanitizedContent {
134
- original: string;
135
- sanitized: string;
136
- redactedCount: number;
137
- appliedFilters: string[];
138
- }
139
- interface FilterContext {
140
- projectRoot: string;
141
- homeDir: string;
142
- commonPaths: Map<string, string>;
143
- }
144
- interface SearchRequest {
145
- errorMessage: string;
146
- errorStack?: string;
147
- language?: Language;
148
- framework?: string;
149
- limit?: number;
150
- threshold?: number;
151
- }
152
- interface SearchResponse {
153
- results: CloudKnowledgeEntry[];
154
- queryTime: number;
155
- cached: boolean;
156
- }
157
- interface UploadRequest {
158
- errorRecord: LocalErrorRecord;
159
- resolution: string;
160
- resolutionCode?: string;
161
- resolutionSteps?: string[];
162
- }
163
- interface UploadResponse {
164
- success: boolean;
165
- knowledgeId?: string;
166
- isDuplicate: boolean;
167
- existingId?: string;
168
- message: string;
169
- }
170
- interface QueryKnowledgeArgs {
171
- errorMessage: string;
172
- language?: string;
173
- framework?: string;
174
- limit?: number;
175
- }
176
- interface SubmitResolutionArgs {
177
- errorId: string;
178
- resolution: string;
179
- resolutionCode?: string;
180
- }
181
- interface ListErrorsArgs {
182
- status?: ErrorStatus;
183
- limit?: number;
184
- }
185
- interface MarkResolvedArgs {
186
- errorId: string;
187
- resolution: string;
188
- resolutionCode?: string;
189
- upload?: boolean;
190
- }
191
- interface VoteArgs {
192
- knowledgeId: string;
193
- helpful: boolean;
194
- }
195
- interface FixHiveConfig {
196
- supabaseUrl: string;
197
- supabaseAnonKey: string;
198
- openaiApiKey?: string;
199
- contributorId: string;
200
- cacheExpirationMs: number;
201
- embeddingModel: string;
202
- embeddingDimensions: number;
203
- similarityThreshold: number;
204
- maxSearchResults: number;
205
- }
206
- interface PartialConfig {
207
- supabaseUrl?: string;
208
- supabaseAnonKey?: string;
209
- openaiApiKey?: string;
210
- contributorId?: string;
211
- cacheExpirationMs?: number;
212
- }
213
- type FixHiveEvent = {
214
- type: 'error:detected';
215
- payload: LocalErrorRecord;
216
- } | {
217
- type: 'error:resolved';
218
- payload: {
219
- errorId: string;
220
- resolution: string;
221
- };
222
- } | {
223
- type: 'solution:uploaded';
224
- payload: {
225
- knowledgeId: string;
226
- };
227
- } | {
228
- type: 'solution:found';
229
- payload: CloudKnowledgeEntry[];
230
- };
231
-
232
- /**
233
- * FixHive Privacy Filter
234
- * Sanitizes sensitive information from error messages before sharing
235
- */
236
-
237
- /**
238
- * Privacy Filter Pipeline
239
- * Applies multiple filtering rules to sanitize sensitive content
240
- */
241
- declare class PrivacyFilter {
242
- private rules;
243
- constructor(customRules?: PrivacyFilterRule[]);
244
- /**
245
- * Sanitize content by applying all filter rules
246
- */
247
- sanitize(content: string, context?: FilterContext): SanitizedContent;
248
- /**
249
- * Generalize file paths while keeping meaningful structure
250
- */
251
- private generalizePaths;
252
- /**
253
- * Add a custom filter rule
254
- */
255
- addRule(rule: PrivacyFilterRule): void;
256
- /**
257
- * Remove a filter rule by name
258
- */
259
- removeRule(name: string): boolean;
260
- /**
261
- * Get all current rules
262
- */
263
- getRules(): ReadonlyArray<PrivacyFilterRule>;
264
- /**
265
- * Check if content contains sensitive data
266
- * Note: Always reset regex lastIndex BEFORE testing to prevent state pollution
267
- */
268
- containsSensitiveData(content: string): boolean;
269
- }
270
- /**
271
- * Create default filter context from project directory
272
- */
273
- declare function createFilterContext(projectDirectory: string): FilterContext;
274
- declare const defaultPrivacyFilter: PrivacyFilter;
275
-
276
- /**
277
- * FixHive Error Detector
278
- * Detects errors from tool outputs using multi-signal analysis
279
- */
280
-
281
- /**
282
- * Error Detector Class
283
- * Analyzes tool outputs to detect errors
284
- */
285
- declare class ErrorDetector {
286
- private privacyFilter;
287
- constructor(privacyFilter?: PrivacyFilter);
288
- /**
289
- * Detect if output contains an error
290
- */
291
- detect(toolOutput: ToolOutput): ErrorDetectionResult;
292
- /**
293
- * Check if content contains error keywords
294
- */
295
- private containsErrorKeywords;
296
- /**
297
- * Detect error patterns in content
298
- */
299
- private detectErrorPatterns;
300
- /**
301
- * Detect stack traces in content
302
- */
303
- private detectStackTrace;
304
- /**
305
- * Calculate confidence score from signals
306
- */
307
- private calculateConfidence;
308
- /**
309
- * Classify error type based on signals and content
310
- */
311
- private classifyErrorType;
312
- /**
313
- * Determine severity from signals and exit code
314
- */
315
- private determineSeverity;
316
- /**
317
- * Extract error message and stack from output
318
- */
319
- private extractErrorDetails;
320
- /**
321
- * Check if a line looks like an error message
322
- */
323
- private isErrorLine;
324
- }
325
- declare const defaultErrorDetector: ErrorDetector;
326
-
327
- /**
328
- * FixHive Hash Utilities
329
- * Generates fingerprints and hashes for error deduplication
330
- */
331
- /**
332
- * Generate SHA-256 hash of content
333
- */
334
- declare function sha256(content: string): string;
335
- /**
336
- * Generate a shortened hash (first 16 characters)
337
- */
338
- declare function shortHash(content: string): string;
339
- /**
340
- * Generate error fingerprint for matching similar errors
341
- * Normalizes variable parts (paths, numbers, hashes) before hashing
342
- */
343
- declare function generateErrorFingerprint(errorMessage: string, errorStack?: string): string;
344
- /**
345
- * Normalize error content by replacing variable parts
346
- */
347
- declare function normalizeErrorContent(content: string): string;
348
- /**
349
- * Generate contributor ID (anonymous hash)
350
- * Uses machine-specific information to create a stable anonymous ID
351
- */
352
- declare function generateContributorId(): string;
353
- /**
354
- * Generate session-specific hash
355
- */
356
- declare function generateSessionHash(sessionId: string): string;
357
- /**
358
- * Compare two fingerprints for similarity
359
- * Returns true if they're identical (exact match)
360
- */
361
- declare function fingerprintsMatch(fp1: string, fp2: string): boolean;
362
- /**
363
- * Calculate simple string similarity (Jaccard index)
364
- * Used as a fallback when embeddings aren't available
365
- */
366
- declare function calculateStringSimilarity(str1: string, str2: string): number;
367
-
368
- /**
369
- * FixHive Local Store
370
- * SQLite-based local storage for error records and caching
371
- */
372
-
373
- /**
374
- * Local Store Class
375
- * Manages SQLite database for error records and caching
376
- */
377
- declare class LocalStore {
378
- private db;
379
- constructor(projectDirectory: string);
380
- /**
381
- * Create a new error record
382
- */
383
- createErrorRecord(data: Omit<LocalErrorRecord, 'id' | 'errorHash' | 'status' | 'createdAt'>): LocalErrorRecord;
384
- /**
385
- * Get error record by ID
386
- */
387
- getErrorById(id: string): LocalErrorRecord | null;
388
- /**
389
- * Get errors by session
390
- */
391
- getSessionErrors(sessionId: string, options?: {
392
- status?: ErrorStatus;
393
- limit?: number;
394
- }): LocalErrorRecord[];
395
- /**
396
- * Get unresolved errors for a session
397
- */
398
- getUnresolvedErrors(sessionId: string): LocalErrorRecord[];
399
- /**
400
- * Get recent errors across all sessions
401
- */
402
- getRecentErrors(limit?: number): LocalErrorRecord[];
403
- /**
404
- * Mark error as resolved
405
- */
406
- markResolved(id: string, data: {
407
- resolution: string;
408
- resolutionCode?: string;
409
- }): LocalErrorRecord | null;
410
- /**
411
- * Mark error as uploaded to cloud
412
- */
413
- markUploaded(id: string, cloudKnowledgeId: string): void;
414
- /**
415
- * Find similar errors by hash
416
- */
417
- findSimilarErrors(errorHash: string): LocalErrorRecord[];
418
- /**
419
- * Get cached query results
420
- */
421
- getCachedResults(errorHash: string): CloudKnowledgeEntry[] | null;
422
- /**
423
- * Cache query results
424
- */
425
- cacheResults(errorHash: string, results: CloudKnowledgeEntry[], expirationMs?: number): void;
426
- /**
427
- * Clear expired cache entries
428
- */
429
- clearExpiredCache(): number;
430
- /**
431
- * Get usage statistics
432
- */
433
- getStats(): LocalStats;
434
- /**
435
- * Allowed stat column names for incrementStat (whitelist to prevent SQL injection)
436
- */
437
- private static readonly ALLOWED_STATS;
438
- /**
439
- * Increment a stat counter
440
- * @throws Error if stat name is not in the allowed whitelist
441
- */
442
- private incrementStat;
443
- /**
444
- * Get preference value
445
- */
446
- getPreference(key: string): string | null;
447
- /**
448
- * Set preference value
449
- */
450
- setPreference(key: string, value: string): void;
451
- /**
452
- * Convert database row to LocalErrorRecord
453
- */
454
- private rowToRecord;
455
- /**
456
- * Close database connection
457
- */
458
- close(): void;
459
- /**
460
- * Get database for advanced queries
461
- */
462
- getDatabase(): Database.Database;
463
- }
464
-
465
- /**
466
- * FixHive Database Migrations
467
- * SQLite schema setup and migrations
468
- */
469
-
470
- /**
471
- * Run all migrations on the database
472
- */
473
- declare function runMigrations(db: Database.Database): void;
474
-
475
- /**
476
- * FixHive Cloud Client
477
- * Supabase client for cloud knowledge base operations
478
- */
479
-
480
- /**
481
- * Cloud Client Configuration
482
- */
483
- interface CloudClientConfig {
484
- supabaseUrl: string;
485
- supabaseAnonKey: string;
486
- openaiApiKey?: string;
487
- contributorId?: string;
488
- similarityThreshold?: number;
489
- }
490
- /**
491
- * Cloud Client Class
492
- * Manages communication with Supabase cloud database
493
- */
494
- declare class CloudClient {
495
- private supabase;
496
- private embedding;
497
- private contributorId;
498
- private similarityThreshold;
499
- private constructor();
500
- /**
501
- * Create a CloudClient instance (async factory for Bun compatibility)
502
- */
503
- static create(config: CloudClientConfig): Promise<CloudClient>;
504
- /**
505
- * Search for similar errors in cloud knowledge base
506
- */
507
- searchSimilar(request: SearchRequest): Promise<SearchResponse>;
508
- /**
509
- * Fallback text-based search
510
- */
511
- private searchByText;
512
- /**
513
- * Upload a resolution to cloud knowledge base
514
- */
515
- uploadResolution(request: UploadRequest): Promise<UploadResponse>;
516
- /**
517
- * Check for duplicate entries
518
- */
519
- checkDuplicate(errorHash: string, embedding: number[]): Promise<DuplicateCheckResult>;
520
- /**
521
- * Vote on a knowledge entry (with duplicate vote prevention)
522
- */
523
- vote(knowledgeId: string, helpful: boolean): Promise<{
524
- success: boolean;
525
- error?: string;
526
- }>;
527
- /**
528
- * Report an entry for review
529
- */
530
- reportEntry(knowledgeId: string, reason?: string): Promise<{
531
- success: boolean;
532
- }>;
533
- /**
534
- * Report helpful usage
535
- */
536
- reportHelpful(knowledgeId: string): Promise<void>;
537
- /**
538
- * Get contributor statistics
539
- */
540
- getContributorStats(): Promise<ContributorStats>;
541
- /**
542
- * Get entry by ID
543
- */
544
- getEntry(id: string): Promise<CloudKnowledgeEntry | null>;
545
- /**
546
- * Map database row to CloudKnowledgeEntry
547
- */
548
- private mapToKnowledgeEntry;
549
- /**
550
- * Get contributor ID
551
- */
552
- getContributorId(): string;
553
- /**
554
- * Check if embedding service is available
555
- */
556
- hasEmbeddingService(): boolean;
557
- }
558
- /**
559
- * Create cloud client with config (async for Bun compatibility)
560
- */
561
- declare function createCloudClient(config: CloudClientConfig): Promise<CloudClient>;
562
-
563
- /**
564
- * FixHive Embedding Service
565
- * Generates text embeddings for semantic search using OpenAI
566
- */
567
- /**
568
- * Embedding Service Class
569
- * Generates embeddings for error messages and solutions
570
- */
571
- declare class EmbeddingService {
572
- private client;
573
- private model;
574
- private dimensions;
575
- constructor(apiKey: string, model?: string, dimensions?: number);
576
- /**
577
- * Generate embedding for a single text
578
- */
579
- generate(text: string): Promise<number[]>;
580
- /**
581
- * Generate embeddings for multiple texts
582
- */
583
- generateBatch(texts: string[]): Promise<number[][]>;
584
- /**
585
- * Generate embedding for error context
586
- * Combines error message, stack trace, and context
587
- */
588
- generateErrorEmbedding(errorMessage: string, errorStack?: string, context?: {
589
- language?: string;
590
- framework?: string;
591
- }): Promise<number[]>;
592
- /**
593
- * Truncate text to fit within model limits
594
- */
595
- private truncateText;
596
- /**
597
- * Calculate cosine similarity between two embeddings
598
- */
599
- static cosineSimilarity(a: number[], b: number[]): number;
600
- /**
601
- * Get embedding dimensions
602
- */
603
- getDimensions(): number;
604
- /**
605
- * Get model name
606
- */
607
- getModel(): string;
608
- }
609
- /**
610
- * Create embedding service with config
611
- */
612
- declare function createEmbeddingService(config: {
613
- apiKey: string;
614
- model?: string;
615
- dimensions?: number;
616
- }): EmbeddingService;
617
-
618
- export { CloudClient, type CloudKnowledgeEntry, type ContributorStats, type DetectedSignal, type DuplicateCheckResult, EmbeddingService, type ErrorDetectionResult, ErrorDetector, type ErrorStatus, type ErrorType, type FilterContext, type FixHiveConfig, type FixHiveContext, type FixHiveEvent, FixHivePlugin, type Language, type ListErrorsArgs, type LocalErrorRecord, type LocalStats, LocalStore, type MarkResolvedArgs, type PartialConfig, PrivacyFilter, type PrivacyFilterRule, type QueryCacheEntry, type QueryKnowledgeArgs, type SanitizedContent, type SearchRequest, type SearchResponse, type Severity, type StackFrame, type StackTraceInfo, type SubmitResolutionArgs, type ToolOutput, type UploadRequest, type UploadResponse, type VoteArgs, calculateStringSimilarity, createCloudClient, createEmbeddingService, createFilterContext, FixHivePlugin as default, defaultErrorDetector, defaultPrivacyFilter, fingerprintsMatch, generateContributorId, generateErrorFingerprint, generateSessionHash, normalizeErrorContent, runMigrations, sha256, shortHash };
2
+ * FixHive - Community-based Error Knowledge Sharing for OpenCode
3
+ *
4
+ * @module @fixhive/opencode-plugin
5
+ * @description
6
+ * FixHive is an OpenCode plugin that automatically captures errors during
7
+ * development sessions, queries a community knowledge base for solutions,
8
+ * and shares resolved errors with other developers.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // In your OpenCode plugin configuration
13
+ * import FixHivePlugin from '@fixhive/opencode-plugin';
14
+ *
15
+ * export default FixHivePlugin;
16
+ * ```
17
+ *
18
+ * @example
19
+ * ```bash
20
+ * # Environment variables
21
+ * FIXHIVE_SUPABASE_URL=https://your-project.supabase.co
22
+ * FIXHIVE_SUPABASE_KEY=your-anon-key
23
+ * OPENAI_API_KEY=sk-... # Optional, for embeddings
24
+ * ```
25
+ */
26
+ export { FixHivePlugin, default } from './plugin/index.js';
27
+ export { ErrorDetector, defaultErrorDetector } from './core/error-detector.js';
28
+ export { PrivacyFilter, defaultPrivacyFilter, createFilterContext } from './core/privacy-filter.js';
29
+ export { sha256, shortHash, generateErrorFingerprint, normalizeErrorContent, generateContributorId, generateSessionHash, fingerprintsMatch, calculateStringSimilarity, } from './core/hash.js';
30
+ export { LocalStore } from './storage/local-store.js';
31
+ export { runMigrations } from './storage/migrations.js';
32
+ export { CloudClient, createCloudClient } from './cloud/client.js';
33
+ export { EmbeddingService, createEmbeddingService } from './cloud/embedding.js';
34
+ export type { ErrorType, ErrorStatus, Language, Severity, LocalErrorRecord, QueryCacheEntry, LocalStats, CloudKnowledgeEntry, DuplicateCheckResult, ContributorStats, DetectedSignal, ErrorDetectionResult, StackFrame, StackTraceInfo, FixHiveContext, ToolOutput, PrivacyFilterRule, SanitizedContent, FilterContext, SearchRequest, SearchResponse, UploadRequest, UploadResponse, QueryKnowledgeArgs, SubmitResolutionArgs, ListErrorsArgs, MarkResolvedArgs, VoteArgs, FixHiveConfig, PartialConfig, FixHiveEvent, } from './types/index.js';
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG3D,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpG,OAAO,EACL,MAAM,EACN,SAAS,EACT,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGhF,YAAY,EAEV,SAAS,EACT,WAAW,EACX,QAAQ,EACR,QAAQ,EAGR,gBAAgB,EAChB,eAAe,EACf,UAAU,EAGV,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAGhB,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,cAAc,EAGd,cAAc,EACd,UAAU,EAGV,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EAGb,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EAGd,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,QAAQ,EAGR,aAAa,EACb,aAAa,EAGb,YAAY,GACb,MAAM,kBAAkB,CAAC"}