@hyperfixi/patterns-reference 2.0.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/README.md +311 -0
- package/data/hyperfixi-extensions.json +106 -0
- package/dist/api/index.d.mts +59 -0
- package/dist/api/index.d.ts +59 -0
- package/dist/api/index.js +769 -0
- package/dist/api/index.mjs +731 -0
- package/dist/index-CBoczxz7.d.mts +296 -0
- package/dist/index-CBoczxz7.d.ts +296 -0
- package/dist/index.d.mts +403 -0
- package/dist/index.d.ts +403 -0
- package/dist/index.js +1312 -0
- package/dist/index.mjs +1240 -0
- package/dist/llm-DMR6tmkM.d.ts +123 -0
- package/dist/llm-UOOBXwj3.d.mts +123 -0
- package/dist/sync/index.d.mts +42 -0
- package/dist/sync/index.d.ts +42 -0
- package/dist/sync/index.js +28 -0
- package/dist/sync/index.mjs +23 -0
- package/package.json +92 -0
- package/src/adapters/index.ts +7 -0
- package/src/adapters/llm-adapter.ts +394 -0
- package/src/api/index.ts +52 -0
- package/src/api/language-docs.ts +529 -0
- package/src/api/llm.ts +357 -0
- package/src/api/patterns.ts +276 -0
- package/src/api/roles.ts +401 -0
- package/src/api/translations.ts +283 -0
- package/src/database/connection.ts +85 -0
- package/src/index.ts +266 -0
- package/src/registry/index.ts +7 -0
- package/src/registry/patterns-provider.ts +250 -0
- package/src/semantic-bridge.ts +204 -0
- package/src/sync/index.ts +70 -0
- package/src/types/better-sqlite3.d.ts +44 -0
- package/src/types/index.ts +434 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patterns Reference Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// Pattern Types
|
|
7
|
+
// =============================================================================
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Engine compatibility for a pattern.
|
|
11
|
+
* - 'hyperscript': only verified for official _hyperscript
|
|
12
|
+
* - 'lokascript': only verified for lokascript (not backward compatible)
|
|
13
|
+
* - 'both': verified for both engines
|
|
14
|
+
* - null: unverified
|
|
15
|
+
*/
|
|
16
|
+
export type EngineCompat = 'hyperscript' | 'lokascript' | 'both';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A pattern from the database (code_examples table).
|
|
20
|
+
*/
|
|
21
|
+
export interface Pattern {
|
|
22
|
+
id: string;
|
|
23
|
+
title: string;
|
|
24
|
+
description: string | null;
|
|
25
|
+
rawCode: string;
|
|
26
|
+
category: string | null;
|
|
27
|
+
primaryCommand: string | null;
|
|
28
|
+
tags: string[];
|
|
29
|
+
difficulty: 'beginner' | 'intermediate' | 'advanced';
|
|
30
|
+
engine: EngineCompat | null;
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Pattern with computed complexity classification.
|
|
36
|
+
*/
|
|
37
|
+
export interface ClassifiedPattern extends Pattern {
|
|
38
|
+
complexity: ComplexityLevel;
|
|
39
|
+
lineCount: number;
|
|
40
|
+
commands: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ComplexityLevel =
|
|
44
|
+
| 'simple-command'
|
|
45
|
+
| 'simple-event'
|
|
46
|
+
| 'chained-command'
|
|
47
|
+
| 'multi-line-event'
|
|
48
|
+
| 'behavior-install'
|
|
49
|
+
| 'behavior-def'
|
|
50
|
+
| 'def-function'
|
|
51
|
+
| 'complex';
|
|
52
|
+
|
|
53
|
+
// =============================================================================
|
|
54
|
+
// Translation Types
|
|
55
|
+
// =============================================================================
|
|
56
|
+
|
|
57
|
+
export type WordOrder = 'SVO' | 'SOV' | 'VSO' | 'V2';
|
|
58
|
+
export type TranslationMethod = 'auto-generated' | 'hand-crafted' | 'verified';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Pattern priority levels for translation selection.
|
|
62
|
+
* When multiple translations exist, higher priority wins.
|
|
63
|
+
*
|
|
64
|
+
* - hand-crafted: Manually written by a native speaker (highest priority)
|
|
65
|
+
* - verified: Auto-generated but verified by human review
|
|
66
|
+
* - auto-generated: Machine-generated without human verification (lowest priority)
|
|
67
|
+
*/
|
|
68
|
+
export type PatternPriority = 'hand-crafted' | 'verified' | 'auto-generated';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A translation of a pattern to a specific language.
|
|
72
|
+
*/
|
|
73
|
+
export interface Translation {
|
|
74
|
+
id: number;
|
|
75
|
+
codeExampleId: string;
|
|
76
|
+
language: string;
|
|
77
|
+
hyperscript: string;
|
|
78
|
+
wordOrder: WordOrder;
|
|
79
|
+
translationMethod: TranslationMethod;
|
|
80
|
+
confidence: number;
|
|
81
|
+
verifiedParses: boolean;
|
|
82
|
+
verifiedExecutes: boolean;
|
|
83
|
+
roleAlignmentScore: number | null; // Semantic role alignment with English (0-1)
|
|
84
|
+
createdAt: Date;
|
|
85
|
+
updatedAt: Date;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Compute priority from translation properties.
|
|
90
|
+
* hand-crafted > verified > auto-generated
|
|
91
|
+
*/
|
|
92
|
+
export function getTranslationPriority(translation: Translation): PatternPriority {
|
|
93
|
+
if (translation.translationMethod === 'hand-crafted') {
|
|
94
|
+
return 'hand-crafted';
|
|
95
|
+
}
|
|
96
|
+
if (translation.verifiedParses && translation.verifiedExecutes) {
|
|
97
|
+
return 'verified';
|
|
98
|
+
}
|
|
99
|
+
return 'auto-generated';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Translation with computed priority.
|
|
104
|
+
*/
|
|
105
|
+
export interface TranslationWithPriority extends Translation {
|
|
106
|
+
priority: PatternPriority;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Result of translation verification.
|
|
111
|
+
*/
|
|
112
|
+
export interface VerificationResult {
|
|
113
|
+
translation: Translation;
|
|
114
|
+
parseSuccess: boolean;
|
|
115
|
+
executeSuccess: boolean;
|
|
116
|
+
errorMessage: string | null;
|
|
117
|
+
confidence: number;
|
|
118
|
+
testedAt: Date;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Test result for a pattern in a specific language.
|
|
123
|
+
*/
|
|
124
|
+
export interface PatternTestResult {
|
|
125
|
+
id: number;
|
|
126
|
+
patternId: string;
|
|
127
|
+
language: string;
|
|
128
|
+
testType: 'parse' | 'execute' | 'round-trip';
|
|
129
|
+
success: boolean;
|
|
130
|
+
errorMessage: string | null;
|
|
131
|
+
testDate: Date;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Result of round-trip verification (EN → Lang → Parse → Compare).
|
|
136
|
+
*/
|
|
137
|
+
export interface RoundTripResult {
|
|
138
|
+
patternId: string;
|
|
139
|
+
language: string;
|
|
140
|
+
englishHyperscript: string;
|
|
141
|
+
translatedHyperscript: string;
|
|
142
|
+
englishAction: string;
|
|
143
|
+
translatedAction: string;
|
|
144
|
+
rolesMatch: boolean;
|
|
145
|
+
missingRoles: string[];
|
|
146
|
+
extraRoles: string[];
|
|
147
|
+
success: boolean;
|
|
148
|
+
errorMessage: string | null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// =============================================================================
|
|
152
|
+
// LLM Types
|
|
153
|
+
// =============================================================================
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* An LLM example (prompt/completion pair).
|
|
157
|
+
*/
|
|
158
|
+
export interface LLMExample {
|
|
159
|
+
id: number;
|
|
160
|
+
patternId: string;
|
|
161
|
+
language: string;
|
|
162
|
+
prompt: string;
|
|
163
|
+
completion: string;
|
|
164
|
+
qualityScore: number;
|
|
165
|
+
usageCount: number;
|
|
166
|
+
createdAt: Date;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// =============================================================================
|
|
170
|
+
// Semantic Role Types
|
|
171
|
+
// =============================================================================
|
|
172
|
+
|
|
173
|
+
// SemanticRole is imported from @lokascript/semantic
|
|
174
|
+
// See packages/semantic/src/types/grammar-types.ts for the canonical definition
|
|
175
|
+
import type { SemanticRole } from '@lokascript/semantic';
|
|
176
|
+
export type { SemanticRole };
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Role type classification.
|
|
180
|
+
*/
|
|
181
|
+
export type RoleType = 'selector' | 'literal' | 'reference' | 'expression' | 'keyword';
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* A semantic role extracted from a pattern.
|
|
185
|
+
*/
|
|
186
|
+
export interface PatternRole {
|
|
187
|
+
id: number;
|
|
188
|
+
codeExampleId: string;
|
|
189
|
+
commandIndex: number;
|
|
190
|
+
role: SemanticRole;
|
|
191
|
+
roleValue: string | null;
|
|
192
|
+
roleType: RoleType | null;
|
|
193
|
+
required: boolean;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Result of role alignment validation for translations.
|
|
198
|
+
*/
|
|
199
|
+
export interface RoleAlignmentResult {
|
|
200
|
+
translationId: number;
|
|
201
|
+
patternId: string;
|
|
202
|
+
language: string;
|
|
203
|
+
alignmentScore: number;
|
|
204
|
+
matchedRoles: SemanticRole[];
|
|
205
|
+
missingRoles: SemanticRole[];
|
|
206
|
+
extraRoles: SemanticRole[];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// =============================================================================
|
|
210
|
+
// API Types
|
|
211
|
+
// =============================================================================
|
|
212
|
+
|
|
213
|
+
export interface SearchOptions {
|
|
214
|
+
language?: string;
|
|
215
|
+
category?: string;
|
|
216
|
+
difficulty?: 'beginner' | 'intermediate' | 'advanced';
|
|
217
|
+
engine?: EngineCompat | null;
|
|
218
|
+
limit?: number;
|
|
219
|
+
offset?: number;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface TestOptions {
|
|
223
|
+
language?: string;
|
|
224
|
+
browsers?: string[];
|
|
225
|
+
runtimeVersion?: string;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface PatternStats {
|
|
229
|
+
totalPatterns: number;
|
|
230
|
+
totalTranslations: number;
|
|
231
|
+
byLanguage: Record<string, { count: number; verifiedCount: number }>;
|
|
232
|
+
byCategory: Record<string, number>;
|
|
233
|
+
avgConfidence: number;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// =============================================================================
|
|
237
|
+
// Sync Types
|
|
238
|
+
// =============================================================================
|
|
239
|
+
|
|
240
|
+
export interface SyncOptions {
|
|
241
|
+
dryRun?: boolean;
|
|
242
|
+
verbose?: boolean;
|
|
243
|
+
limit?: number;
|
|
244
|
+
languages?: string[];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface SyncResult {
|
|
248
|
+
totalExamples: number;
|
|
249
|
+
successfulExamples: number;
|
|
250
|
+
skippedExamples: number;
|
|
251
|
+
totalTranslations: number;
|
|
252
|
+
byLanguage: Record<string, number>;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface ValidationOptions {
|
|
256
|
+
verbose?: boolean;
|
|
257
|
+
languages?: string[];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface ValidationResult {
|
|
261
|
+
total: number;
|
|
262
|
+
passed: number;
|
|
263
|
+
failed: number;
|
|
264
|
+
byLanguage: Record<string, { passed: number; failed: number }>;
|
|
265
|
+
failures: Array<{ language: string; hyperscript: string; error: string }>;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export interface DiscoveryResult {
|
|
269
|
+
totalExamples: number;
|
|
270
|
+
byComplexity: Record<ComplexityLevel, number>;
|
|
271
|
+
parseable: number;
|
|
272
|
+
notParseable: number;
|
|
273
|
+
commandCoverage: Record<string, { total: number; parseable: number }>;
|
|
274
|
+
gaps: string[];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// =============================================================================
|
|
278
|
+
// Language Documentation Types (from hyperscript-lsp)
|
|
279
|
+
// =============================================================================
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* A hyperscript command definition.
|
|
283
|
+
*/
|
|
284
|
+
export interface Command {
|
|
285
|
+
id: string;
|
|
286
|
+
name: string;
|
|
287
|
+
description: string | null;
|
|
288
|
+
syntax: string | null;
|
|
289
|
+
purpose: string | null;
|
|
290
|
+
implicitTarget: string | null;
|
|
291
|
+
implicitResultTarget: string | null;
|
|
292
|
+
isBlocking: boolean;
|
|
293
|
+
hasBody: boolean;
|
|
294
|
+
createdAt: Date;
|
|
295
|
+
updatedAt: Date;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* A hyperscript expression definition.
|
|
300
|
+
*/
|
|
301
|
+
export interface Expression {
|
|
302
|
+
id: string;
|
|
303
|
+
name: string;
|
|
304
|
+
description: string | null;
|
|
305
|
+
category: string;
|
|
306
|
+
evaluatesToType: string | null;
|
|
307
|
+
precedence: number | null;
|
|
308
|
+
associativity: string | null;
|
|
309
|
+
operators: string[];
|
|
310
|
+
createdAt: Date;
|
|
311
|
+
updatedAt: Date;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* An operator for an expression.
|
|
316
|
+
*/
|
|
317
|
+
export interface ExpressionOperator {
|
|
318
|
+
id: string;
|
|
319
|
+
expressionId: string;
|
|
320
|
+
operator: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* A hyperscript keyword definition.
|
|
325
|
+
*/
|
|
326
|
+
export interface Keyword {
|
|
327
|
+
id: string;
|
|
328
|
+
name: string;
|
|
329
|
+
description: string | null;
|
|
330
|
+
contextOfUse: string | null;
|
|
331
|
+
isOptional: boolean;
|
|
332
|
+
createdAt: Date;
|
|
333
|
+
updatedAt: Date;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* A hyperscript feature (top-level construct like on, init, behavior).
|
|
338
|
+
*/
|
|
339
|
+
export interface Feature {
|
|
340
|
+
id: string;
|
|
341
|
+
name: string;
|
|
342
|
+
description: string | null;
|
|
343
|
+
syntax: string | null;
|
|
344
|
+
trigger: string | null;
|
|
345
|
+
structureDescription: string | null;
|
|
346
|
+
scopeImpact: string | null;
|
|
347
|
+
createdAt: Date;
|
|
348
|
+
updatedAt: Date;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* A special symbol (me, it, my, you, your).
|
|
353
|
+
*/
|
|
354
|
+
export interface SpecialSymbol {
|
|
355
|
+
id: string;
|
|
356
|
+
name: string;
|
|
357
|
+
symbol: string;
|
|
358
|
+
symbolType: string;
|
|
359
|
+
description: string | null;
|
|
360
|
+
typicalValue: string | null;
|
|
361
|
+
scopeImplications: string | null;
|
|
362
|
+
createdAt: Date;
|
|
363
|
+
updatedAt: Date;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Element type for searching across language elements.
|
|
368
|
+
*/
|
|
369
|
+
export type LanguageElementType =
|
|
370
|
+
| 'command'
|
|
371
|
+
| 'expression'
|
|
372
|
+
| 'keyword'
|
|
373
|
+
| 'feature'
|
|
374
|
+
| 'special_symbol';
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* A language element (union of all documentation types).
|
|
378
|
+
*/
|
|
379
|
+
export type LanguageElement =
|
|
380
|
+
| { type: 'command'; element: Command }
|
|
381
|
+
| { type: 'expression'; element: Expression }
|
|
382
|
+
| { type: 'keyword'; element: Keyword }
|
|
383
|
+
| { type: 'feature'; element: Feature }
|
|
384
|
+
| { type: 'special_symbol'; element: SpecialSymbol };
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Statistics for language documentation.
|
|
388
|
+
*/
|
|
389
|
+
export interface LanguageDocsStats {
|
|
390
|
+
commands: number;
|
|
391
|
+
expressions: number;
|
|
392
|
+
keywords: number;
|
|
393
|
+
features: number;
|
|
394
|
+
specialSymbols: number;
|
|
395
|
+
expressionOperators: number;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// =============================================================================
|
|
399
|
+
// Connection Types
|
|
400
|
+
// =============================================================================
|
|
401
|
+
|
|
402
|
+
export interface ConnectionOptions {
|
|
403
|
+
dbPath?: string;
|
|
404
|
+
readonly?: boolean;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// =============================================================================
|
|
408
|
+
// Main API Interface
|
|
409
|
+
// =============================================================================
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Main API interface for the Patterns Reference system.
|
|
413
|
+
*/
|
|
414
|
+
export interface PatternsReference {
|
|
415
|
+
// Query patterns
|
|
416
|
+
getPatternById(id: string): Promise<Pattern | null>;
|
|
417
|
+
getPatternsByCategory(category: string): Promise<Pattern[]>;
|
|
418
|
+
getPatternsByCommand(command: string): Promise<Pattern[]>;
|
|
419
|
+
searchPatterns(query: string, options?: SearchOptions): Promise<Pattern[]>;
|
|
420
|
+
|
|
421
|
+
// Translations
|
|
422
|
+
getTranslation(patternId: string, language: string): Promise<Translation | null>;
|
|
423
|
+
getAllTranslations(patternId: string): Promise<Translation[]>;
|
|
424
|
+
verifyTranslation(translation: Translation): Promise<VerificationResult>;
|
|
425
|
+
|
|
426
|
+
// LLM support
|
|
427
|
+
getLLMExamples(prompt: string, language?: string, limit?: number): Promise<LLMExample[]>;
|
|
428
|
+
|
|
429
|
+
// Statistics
|
|
430
|
+
getStats(): Promise<PatternStats>;
|
|
431
|
+
|
|
432
|
+
// Connection
|
|
433
|
+
close(): void;
|
|
434
|
+
}
|