@hyperfixi/patterns-reference 2.5.1 → 2.6.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 CHANGED
@@ -12,9 +12,9 @@ npm install @hyperfixi/patterns-reference
12
12
 
13
13
  The package ships with a **pre-populated SQLite database** containing:
14
14
 
15
- - 106 code examples covering hyperscript commands and real-world UI patterns
16
- - 1,378 translations (106 patterns × 13 languages)
17
- - 414 LLM few-shot examples for code generation
15
+ - 164 code examples covering hyperscript commands and real-world UI patterns
16
+ - 3,936 translations (164 patterns × 24 languages)
17
+ - 648 LLM few-shot examples for code generation
18
18
 
19
19
  No setup required - just install and use:
20
20
 
@@ -132,7 +132,7 @@ These scripts are for contributors regenerating the database. **End users don't
132
132
  | `npm run populate` | Full database setup (init + translations + LLM examples) |
133
133
  | `npm run db:init` | Initialize database with seed patterns |
134
134
  | `npm run db:init:force` | Reinitialize database (overwrites existing) |
135
- | `npm run sync:translations` | Generate translations for all 13 languages |
135
+ | `npm run sync:translations` | Generate translations for all 24 languages |
136
136
  | `npm run seed:llm` | Generate LLM few-shot examples |
137
137
  | `npm run validate` | Validate all patterns parse correctly |
138
138
  | `npm run validate:fix` | Validate and update verified_parses flag |
@@ -185,23 +185,18 @@ Prompt/completion pairs for few-shot learning.
185
185
 
186
186
  ## Supported Languages
187
187
 
188
- The database supports 13 languages with different word orders:
189
-
190
- | Language | Code | Word Order |
191
- | ---------- | ---- | ---------- |
192
- | English | en | SVO |
193
- | Spanish | es | SVO |
194
- | French | fr | SVO |
195
- | Portuguese | pt | SVO |
196
- | Indonesian | id | SVO |
197
- | Swahili | sw | SVO |
198
- | Chinese | zh | SVO |
199
- | Japanese | ja | SOV |
200
- | Korean | ko | SOV |
201
- | Turkish | tr | SOV |
202
- | Quechua | qu | SOV |
203
- | Arabic | ar | VSO |
204
- | German | de | V2 |
188
+ The database supports 24 languages with different word orders:
189
+
190
+ | Word Order | Languages |
191
+ | ---------- | ------------------------------------------ |
192
+ | SVO | en, es, fr, pt, it, id, ms, sw, zh, vi, tl |
193
+ | SOV | ja, ko, tr, qu, hi, bn |
194
+ | VSO | ar |
195
+ | V2 | de |
196
+ | Other | ru, uk, pl, th, he |
197
+
198
+ Languages are derived dynamically from `KNOWN_PROFILES` in `@lokascript/semantic`;
199
+ adding a profile there automatically picks up in the next `npm run sync:translations`.
205
200
 
206
201
  ## Integration with @lokascript/semantic
207
202
 
package/data/patterns.db CHANGED
Binary file
@@ -1,5 +1,5 @@
1
- export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, e as getExamplesByCommand, f as getHighConfidenceTranslations, h as getHighQualityExamples, i as getLLMExamples, j as getLLMStats, k as getMostUsedExamples, l as getPatternById, m as getPatternStats, n as getPatternsByCategory, o as getPatternsByCommand, p as getTranslation, q as getTranslationStats, r as getTranslationsByLanguage, s as getVerifiedTranslations, t as getWordOrder, u as searchPatterns, v as updateQualityScore, w as verifyTranslation } from '../llm-4zwmAvZ8.mjs';
2
- import { c as ConnectionOptions, i as PatternRole, P as Pattern, R as RoleType } from '../index-BhzKat9K.mjs';
1
+ export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getExamplesByCommand, e as getHighConfidenceTranslations, f as getHighQualityExamples, h as getLLMExamples, i as getLLMStats, j as getMostUsedExamples, k as getPatternById, l as getPatternStats, m as getPatternsByCategory, n as getPatternsByCommand, o as getTranslation, p as getTranslationStats, q as getTranslationsByLanguage, r as getVerifiedTranslations, s as getWordOrder, t as searchPatterns, u as updateQualityScore, v as verifyTranslation } from '../llm-BS3mf0VG.mjs';
2
+ import { C as ConnectionOptions, P as PatternRole, a as Pattern, R as RoleType } from '../index-1ENU9L4F.mjs';
3
3
  import { SemanticRole } from '@lokascript/semantic';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, e as getExamplesByCommand, f as getHighConfidenceTranslations, h as getHighQualityExamples, i as getLLMExamples, j as getLLMStats, k as getMostUsedExamples, l as getPatternById, m as getPatternStats, n as getPatternsByCategory, o as getPatternsByCommand, p as getTranslation, q as getTranslationStats, r as getTranslationsByLanguage, s as getVerifiedTranslations, t as getWordOrder, u as searchPatterns, v as updateQualityScore, w as verifyTranslation } from '../llm-B7pwZ472.js';
2
- import { c as ConnectionOptions, i as PatternRole, P as Pattern, R as RoleType } from '../index-BhzKat9K.js';
1
+ export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getExamplesByCommand, e as getHighConfidenceTranslations, f as getHighQualityExamples, h as getLLMExamples, i as getLLMStats, j as getMostUsedExamples, k as getPatternById, l as getPatternStats, m as getPatternsByCategory, n as getPatternsByCommand, o as getTranslation, p as getTranslationStats, q as getTranslationsByLanguage, r as getVerifiedTranslations, s as getWordOrder, t as searchPatterns, u as updateQualityScore, v as verifyTranslation } from '../llm-DkGTC6X7.js';
2
+ import { C as ConnectionOptions, P as PatternRole, a as Pattern, R as RoleType } from '../index-1ENU9L4F.js';
3
3
  import { SemanticRole } from '@lokascript/semantic';
4
4
 
5
5
  /**
@@ -293,4 +293,4 @@ interface PatternsReference {
293
293
  close(): void;
294
294
  }
295
295
 
296
- export type { ClassifiedPattern as C, DiscoveryResult as D, EngineCompat as E, Feature as F, Keyword as K, LLMExample as L, Pattern as P, RoleType as R, SearchOptions as S, TestOptions as T, ValidationOptions as V, WordOrder as W, Command as a, ComplexityLevel as b, ConnectionOptions as c, Expression as d, ExpressionOperator as e, LanguageDocsStats as f, LanguageElement as g, LanguageElementType as h, PatternRole as i, PatternStats as j, PatternsReference as k, SpecialSymbol as l, SyncOptions as m, SyncResult as n, Translation as o, TranslationMethod as p, ValidationResult as q, VerificationResult as r };
296
+ export type { ConnectionOptions as C, DiscoveryResult as D, Expression as E, Feature as F, Keyword as K, LanguageDocsStats as L, PatternRole as P, RoleType as R, SpecialSymbol as S, TestOptions as T, ValidationOptions as V, WordOrder as W, Pattern as a, Command as b, LanguageElementType as c, LanguageElement as d, LLMExample as e, PatternsReference as f, ClassifiedPattern as g, ComplexityLevel as h, EngineCompat as i, ExpressionOperator as j, PatternStats as k, SearchOptions as l, SyncOptions as m, SyncResult as n, Translation as o, TranslationMethod as p, ValidationResult as q, VerificationResult as r };
@@ -293,4 +293,4 @@ interface PatternsReference {
293
293
  close(): void;
294
294
  }
295
295
 
296
- export type { ClassifiedPattern as C, DiscoveryResult as D, EngineCompat as E, Feature as F, Keyword as K, LLMExample as L, Pattern as P, RoleType as R, SearchOptions as S, TestOptions as T, ValidationOptions as V, WordOrder as W, Command as a, ComplexityLevel as b, ConnectionOptions as c, Expression as d, ExpressionOperator as e, LanguageDocsStats as f, LanguageElement as g, LanguageElementType as h, PatternRole as i, PatternStats as j, PatternsReference as k, SpecialSymbol as l, SyncOptions as m, SyncResult as n, Translation as o, TranslationMethod as p, ValidationResult as q, VerificationResult as r };
296
+ export type { ConnectionOptions as C, DiscoveryResult as D, Expression as E, Feature as F, Keyword as K, LanguageDocsStats as L, PatternRole as P, RoleType as R, SpecialSymbol as S, TestOptions as T, ValidationOptions as V, WordOrder as W, Pattern as a, Command as b, LanguageElementType as c, LanguageElement as d, LLMExample as e, PatternsReference as f, ClassifiedPattern as g, ComplexityLevel as h, EngineCompat as i, ExpressionOperator as j, PatternStats as k, SearchOptions as l, SyncOptions as m, SyncResult as n, Translation as o, TranslationMethod as p, ValidationResult as q, VerificationResult as r };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { c as ConnectionOptions, a as Command, d as Expression, F as Feature, K as Keyword, l as SpecialSymbol, f as LanguageDocsStats, h as LanguageElementType, g as LanguageElement, L as LLMExample, k as PatternsReference } from './index-BhzKat9K.mjs';
2
- export { C as ClassifiedPattern, b as ComplexityLevel, D as DiscoveryResult, E as EngineCompat, e as ExpressionOperator, P as Pattern, j as PatternStats, S as SearchOptions, m as SyncOptions, n as SyncResult, T as TestOptions, o as Translation, p as TranslationMethod, V as ValidationOptions, q as ValidationResult, r as VerificationResult, W as WordOrder } from './index-BhzKat9K.mjs';
1
+ import { C as ConnectionOptions, b as Command, E as Expression, F as Feature, K as Keyword, S as SpecialSymbol, L as LanguageDocsStats, c as LanguageElementType, d as LanguageElement, e as LLMExample, f as PatternsReference } from './index-1ENU9L4F.mjs';
2
+ export { g as ClassifiedPattern, h as ComplexityLevel, D as DiscoveryResult, i as EngineCompat, j as ExpressionOperator, a as Pattern, k as PatternStats, l as SearchOptions, m as SyncOptions, n as SyncResult, T as TestOptions, o as Translation, p as TranslationMethod, V as ValidationOptions, q as ValidationResult, r as VerificationResult, W as WordOrder } from './index-1ENU9L4F.mjs';
3
3
  import Database from 'better-sqlite3';
4
- export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getBehaviorPatterns, e as getExamplesByCommand, f as getHighConfidenceTranslations, h as getHighQualityExamples, i as getLLMExamples, j as getLLMStats, k as getMostUsedExamples, l as getPatternById, m as getPatternStats, n as getPatternsByCategory, o as getPatternsByCommand, p as getTranslation, q as getTranslationStats, r as getTranslationsByLanguage, s as getVerifiedTranslations, t as getWordOrder, u as searchPatterns, v as updateQualityScore, w as verifyTranslation } from './llm-4zwmAvZ8.mjs';
5
- export { discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations } from './sync/index.mjs';
4
+ export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, w as getBehaviorPatterns, d as getExamplesByCommand, e as getHighConfidenceTranslations, f as getHighQualityExamples, h as getLLMExamples, i as getLLMStats, j as getMostUsedExamples, k as getPatternById, l as getPatternStats, m as getPatternsByCategory, n as getPatternsByCommand, o as getTranslation, p as getTranslationStats, q as getTranslationsByLanguage, r as getVerifiedTranslations, s as getWordOrder, t as searchPatterns, u as updateQualityScore, v as verifyTranslation } from './llm-BS3mf0VG.mjs';
5
+ export { DbStampStatus, checkDbStamp, computeDbInputHash, dbStampPath, discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations, writeDbStamp } from './sync/index.mjs';
6
6
  import '@lokascript/semantic';
7
7
 
8
8
  /**
@@ -11,6 +11,12 @@ import '@lokascript/semantic';
11
11
  * Provides singleton connection to the patterns-reference SQLite database.
12
12
  */
13
13
 
14
+ /**
15
+ * The resolved default DB path (honouring `LSP_DB_PATH` / `HYPERSCRIPT_LSP_DB`).
16
+ * Exposed so callers (e.g. the multilingual gate's freshness check) can target the
17
+ * exact DB that `getDatabase()` opens.
18
+ */
19
+ declare function getDefaultDbPath(): string;
14
20
  /**
15
21
  * Get database connection (lazy singleton).
16
22
  */
@@ -455,4 +461,4 @@ declare function createPatternsReference(options?: ConnectionOptions): PatternsR
455
461
  */
456
462
  declare const VERSION = "0.1.0";
457
463
 
458
- export { type BehaviorRuntime, Command, ConnectionOptions, DatabasePatternsProvider, Expression, Feature, type IntegrationResult, Keyword, LLMExample, type LLMExampleRecord, LanguageDocsStats, LanguageElement, LanguageElementType, type LoadBehaviorsOptions, type LoadBehaviorsResult, type PatternEntry, PatternsReference, type PatternsSource, type SemanticIntegrationOptions, SpecialSymbol, VERSION, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllSpecialSymbols, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultProvider, getExpressionByName, getExpressionsByCategory, getFeatureByName, getKeywordByName, getLLMExampleStats, getLanguageDocsStats, getSpecialSymbolByName, getSupportedLanguages, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, loadBehaviors, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, trackExampleUsage, uninitializeSemanticIntegration };
464
+ export { type BehaviorRuntime, Command, ConnectionOptions, DatabasePatternsProvider, Expression, Feature, type IntegrationResult, Keyword, LLMExample, type LLMExampleRecord, LanguageDocsStats, LanguageElement, LanguageElementType, type LoadBehaviorsOptions, type LoadBehaviorsResult, type PatternEntry, PatternsReference, type PatternsSource, type SemanticIntegrationOptions, SpecialSymbol, VERSION, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllSpecialSymbols, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultDbPath, getDefaultProvider, getExpressionByName, getExpressionsByCategory, getFeatureByName, getKeywordByName, getLLMExampleStats, getLanguageDocsStats, getSpecialSymbolByName, getSupportedLanguages, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, loadBehaviors, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, trackExampleUsage, uninitializeSemanticIntegration };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { c as ConnectionOptions, a as Command, d as Expression, F as Feature, K as Keyword, l as SpecialSymbol, f as LanguageDocsStats, h as LanguageElementType, g as LanguageElement, L as LLMExample, k as PatternsReference } from './index-BhzKat9K.js';
2
- export { C as ClassifiedPattern, b as ComplexityLevel, D as DiscoveryResult, E as EngineCompat, e as ExpressionOperator, P as Pattern, j as PatternStats, S as SearchOptions, m as SyncOptions, n as SyncResult, T as TestOptions, o as Translation, p as TranslationMethod, V as ValidationOptions, q as ValidationResult, r as VerificationResult, W as WordOrder } from './index-BhzKat9K.js';
1
+ import { C as ConnectionOptions, b as Command, E as Expression, F as Feature, K as Keyword, S as SpecialSymbol, L as LanguageDocsStats, c as LanguageElementType, d as LanguageElement, e as LLMExample, f as PatternsReference } from './index-1ENU9L4F.js';
2
+ export { g as ClassifiedPattern, h as ComplexityLevel, D as DiscoveryResult, i as EngineCompat, j as ExpressionOperator, a as Pattern, k as PatternStats, l as SearchOptions, m as SyncOptions, n as SyncResult, T as TestOptions, o as Translation, p as TranslationMethod, V as ValidationOptions, q as ValidationResult, r as VerificationResult, W as WordOrder } from './index-1ENU9L4F.js';
3
3
  import Database from 'better-sqlite3';
4
- export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getBehaviorPatterns, e as getExamplesByCommand, f as getHighConfidenceTranslations, h as getHighQualityExamples, i as getLLMExamples, j as getLLMStats, k as getMostUsedExamples, l as getPatternById, m as getPatternStats, n as getPatternsByCategory, o as getPatternsByCommand, p as getTranslation, q as getTranslationStats, r as getTranslationsByLanguage, s as getVerifiedTranslations, t as getWordOrder, u as searchPatterns, v as updateQualityScore, w as verifyTranslation } from './llm-B7pwZ472.js';
5
- export { discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations } from './sync/index.js';
4
+ export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, w as getBehaviorPatterns, d as getExamplesByCommand, e as getHighConfidenceTranslations, f as getHighQualityExamples, h as getLLMExamples, i as getLLMStats, j as getMostUsedExamples, k as getPatternById, l as getPatternStats, m as getPatternsByCategory, n as getPatternsByCommand, o as getTranslation, p as getTranslationStats, q as getTranslationsByLanguage, r as getVerifiedTranslations, s as getWordOrder, t as searchPatterns, u as updateQualityScore, v as verifyTranslation } from './llm-DkGTC6X7.js';
5
+ export { DbStampStatus, checkDbStamp, computeDbInputHash, dbStampPath, discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations, writeDbStamp } from './sync/index.js';
6
6
  import '@lokascript/semantic';
7
7
 
8
8
  /**
@@ -11,6 +11,12 @@ import '@lokascript/semantic';
11
11
  * Provides singleton connection to the patterns-reference SQLite database.
12
12
  */
13
13
 
14
+ /**
15
+ * The resolved default DB path (honouring `LSP_DB_PATH` / `HYPERSCRIPT_LSP_DB`).
16
+ * Exposed so callers (e.g. the multilingual gate's freshness check) can target the
17
+ * exact DB that `getDatabase()` opens.
18
+ */
19
+ declare function getDefaultDbPath(): string;
14
20
  /**
15
21
  * Get database connection (lazy singleton).
16
22
  */
@@ -455,4 +461,4 @@ declare function createPatternsReference(options?: ConnectionOptions): PatternsR
455
461
  */
456
462
  declare const VERSION = "0.1.0";
457
463
 
458
- export { type BehaviorRuntime, Command, ConnectionOptions, DatabasePatternsProvider, Expression, Feature, type IntegrationResult, Keyword, LLMExample, type LLMExampleRecord, LanguageDocsStats, LanguageElement, LanguageElementType, type LoadBehaviorsOptions, type LoadBehaviorsResult, type PatternEntry, PatternsReference, type PatternsSource, type SemanticIntegrationOptions, SpecialSymbol, VERSION, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllSpecialSymbols, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultProvider, getExpressionByName, getExpressionsByCategory, getFeatureByName, getKeywordByName, getLLMExampleStats, getLanguageDocsStats, getSpecialSymbolByName, getSupportedLanguages, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, loadBehaviors, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, trackExampleUsage, uninitializeSemanticIntegration };
464
+ export { type BehaviorRuntime, Command, ConnectionOptions, DatabasePatternsProvider, Expression, Feature, type IntegrationResult, Keyword, LLMExample, type LLMExampleRecord, LanguageDocsStats, LanguageElement, LanguageElementType, type LoadBehaviorsOptions, type LoadBehaviorsResult, type PatternEntry, PatternsReference, type PatternsSource, type SemanticIntegrationOptions, SpecialSymbol, VERSION, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllSpecialSymbols, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultDbPath, getDefaultProvider, getExpressionByName, getExpressionsByCategory, getFeatureByName, getKeywordByName, getLLMExampleStats, getLanguageDocsStats, getSpecialSymbolByName, getSupportedLanguages, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, loadBehaviors, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, trackExampleUsage, uninitializeSemanticIntegration };
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@
3
3
  var Database = require('better-sqlite3');
4
4
  var url = require('url');
5
5
  var path = require('path');
6
+ var crypto = require('crypto');
7
+ var fs = require('fs');
6
8
 
7
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
10
 
@@ -16,6 +18,9 @@ var __dirname$1 = path.dirname(__filename2);
16
18
  var DEFAULT_DB_PATH = process.env.LSP_DB_PATH || process.env.HYPERSCRIPT_LSP_DB || path.join(__dirname$1, "../data/patterns.db");
17
19
  var dbInstance = null;
18
20
  var currentDbPath = null;
21
+ function getDefaultDbPath() {
22
+ return DEFAULT_DB_PATH;
23
+ }
19
24
  function getDatabase(options = {}) {
20
25
  const dbPath = options.dbPath ?? DEFAULT_DB_PATH;
21
26
  if (dbInstance !== null && currentDbPath === dbPath) {
@@ -812,6 +817,64 @@ async function getLanguageDocsStats(options) {
812
817
  expressionOperators: getCount("expression_operators")
813
818
  };
814
819
  }
820
+ function repoRootFromDbPath(dbPath) {
821
+ return path.resolve(path.dirname(dbPath), "..", "..", "..");
822
+ }
823
+ function walkTsFiles(dir, acc) {
824
+ if (!fs.existsSync(dir)) return;
825
+ for (const name of fs.readdirSync(dir).sort()) {
826
+ if (name === "node_modules" || name === "dist" || name === "__tests__") continue;
827
+ const full = path.join(dir, name);
828
+ const st = fs.statSync(full);
829
+ if (st.isDirectory()) {
830
+ walkTsFiles(full, acc);
831
+ } else if (name.endsWith(".ts") && !name.endsWith(".test.ts") && !name.endsWith(".d.ts")) {
832
+ acc.push(full);
833
+ }
834
+ }
835
+ }
836
+ function dbInputFiles(dbPath) {
837
+ const root = repoRootFromDbPath(dbPath);
838
+ const files = [];
839
+ walkTsFiles(path.join(root, "packages", "i18n", "src"), files);
840
+ walkTsFiles(path.join(root, "packages", "semantic", "src"), files);
841
+ const pr = path.join(root, "packages", "patterns-reference");
842
+ for (const f of [
843
+ path.join(pr, "scripts", "init-db.ts"),
844
+ path.join(pr, "scripts", "sync-translations.ts"),
845
+ path.join(pr, "src", "sync", "span-mask.ts")
846
+ ]) {
847
+ if (fs.existsSync(f)) files.push(f);
848
+ }
849
+ return files.sort();
850
+ }
851
+ function computeDbInputHash(dbPath) {
852
+ const root = repoRootFromDbPath(dbPath);
853
+ const files = dbInputFiles(dbPath);
854
+ const h = crypto.createHash("sha256");
855
+ h.update(`files:${files.length}\0`);
856
+ for (const f of files) {
857
+ h.update(path.relative(root, f).split(path.sep).join("/"));
858
+ h.update("\0");
859
+ h.update(fs.readFileSync(f));
860
+ h.update("\0");
861
+ }
862
+ return h.digest("hex");
863
+ }
864
+ function dbStampPath(dbPath) {
865
+ return `${dbPath}.stamp`;
866
+ }
867
+ function writeDbStamp(dbPath) {
868
+ fs.writeFileSync(dbStampPath(dbPath), `${computeDbInputHash(dbPath)}
869
+ `, "utf8");
870
+ }
871
+ function checkDbStamp(dbPath) {
872
+ const sp = dbStampPath(dbPath);
873
+ if (!fs.existsSync(sp)) return { status: "unstamped" };
874
+ const expected = fs.readFileSync(sp, "utf8").trim();
875
+ const actual = computeDbInputHash(dbPath);
876
+ return actual === expected ? { status: "ok" } : { status: "stale", expected, actual };
877
+ }
815
878
 
816
879
  // src/sync/index.ts
817
880
  async function syncTranslations(_options = {}) {
@@ -1281,10 +1344,13 @@ exports.VERSION = VERSION;
1281
1344
  exports.addLLMExample = addLLMExample;
1282
1345
  exports.buildFewShotContext = buildFewShotContext;
1283
1346
  exports.buildFewShotContextSync = buildFewShotContextSync;
1347
+ exports.checkDbStamp = checkDbStamp;
1284
1348
  exports.closeDatabase = closeDatabase;
1349
+ exports.computeDbInputHash = computeDbInputHash;
1285
1350
  exports.createLLMAdapter = createLLMAdapter;
1286
1351
  exports.createPatternsProvider = createPatternsProvider;
1287
1352
  exports.createPatternsReference = createPatternsReference;
1353
+ exports.dbStampPath = dbStampPath;
1288
1354
  exports.discoverPatterns = discoverPatterns;
1289
1355
  exports.findExamplesByCommand = findExamplesByCommand;
1290
1356
  exports.findRelevantExamples = findRelevantExamples;
@@ -1300,6 +1366,7 @@ exports.getBridgeProvider = getBridgeProvider;
1300
1366
  exports.getCommandByName = getCommandByName;
1301
1367
  exports.getCurrentDbPath = getCurrentDbPath;
1302
1368
  exports.getDatabase = getDatabase;
1369
+ exports.getDefaultDbPath = getDefaultDbPath;
1303
1370
  exports.getDefaultProvider = getDefaultProvider;
1304
1371
  exports.getExamplesByCommand = getExamplesByCommand;
1305
1372
  exports.getExpressionByName = getExpressionByName;
@@ -1343,3 +1410,4 @@ exports.uninitializeSemanticIntegration = uninitializeSemanticIntegration;
1343
1410
  exports.updateQualityScore = updateQualityScore;
1344
1411
  exports.validateAllTranslations = validateAllTranslations;
1345
1412
  exports.verifyTranslation = verifyTranslation;
1413
+ exports.writeDbStamp = writeDbStamp;
package/dist/index.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  import Database from 'better-sqlite3';
2
2
  import { fileURLToPath } from 'url';
3
- import { dirname, join } from 'path';
3
+ import { dirname, join, relative, sep, resolve } from 'path';
4
+ import { createHash } from 'crypto';
5
+ import { readFileSync, writeFileSync, existsSync, readdirSync, statSync } from 'fs';
4
6
 
5
7
  // src/database/connection.ts
6
8
  var __filename$1 = fileURLToPath(import.meta.url);
@@ -8,6 +10,9 @@ var __dirname$1 = dirname(__filename$1);
8
10
  var DEFAULT_DB_PATH = process.env.LSP_DB_PATH || process.env.HYPERSCRIPT_LSP_DB || join(__dirname$1, "../data/patterns.db");
9
11
  var dbInstance = null;
10
12
  var currentDbPath = null;
13
+ function getDefaultDbPath() {
14
+ return DEFAULT_DB_PATH;
15
+ }
11
16
  function getDatabase(options = {}) {
12
17
  const dbPath = options.dbPath ?? DEFAULT_DB_PATH;
13
18
  if (dbInstance !== null && currentDbPath === dbPath) {
@@ -804,6 +809,64 @@ async function getLanguageDocsStats(options) {
804
809
  expressionOperators: getCount("expression_operators")
805
810
  };
806
811
  }
812
+ function repoRootFromDbPath(dbPath) {
813
+ return resolve(dirname(dbPath), "..", "..", "..");
814
+ }
815
+ function walkTsFiles(dir, acc) {
816
+ if (!existsSync(dir)) return;
817
+ for (const name of readdirSync(dir).sort()) {
818
+ if (name === "node_modules" || name === "dist" || name === "__tests__") continue;
819
+ const full = join(dir, name);
820
+ const st = statSync(full);
821
+ if (st.isDirectory()) {
822
+ walkTsFiles(full, acc);
823
+ } else if (name.endsWith(".ts") && !name.endsWith(".test.ts") && !name.endsWith(".d.ts")) {
824
+ acc.push(full);
825
+ }
826
+ }
827
+ }
828
+ function dbInputFiles(dbPath) {
829
+ const root = repoRootFromDbPath(dbPath);
830
+ const files = [];
831
+ walkTsFiles(join(root, "packages", "i18n", "src"), files);
832
+ walkTsFiles(join(root, "packages", "semantic", "src"), files);
833
+ const pr = join(root, "packages", "patterns-reference");
834
+ for (const f of [
835
+ join(pr, "scripts", "init-db.ts"),
836
+ join(pr, "scripts", "sync-translations.ts"),
837
+ join(pr, "src", "sync", "span-mask.ts")
838
+ ]) {
839
+ if (existsSync(f)) files.push(f);
840
+ }
841
+ return files.sort();
842
+ }
843
+ function computeDbInputHash(dbPath) {
844
+ const root = repoRootFromDbPath(dbPath);
845
+ const files = dbInputFiles(dbPath);
846
+ const h = createHash("sha256");
847
+ h.update(`files:${files.length}\0`);
848
+ for (const f of files) {
849
+ h.update(relative(root, f).split(sep).join("/"));
850
+ h.update("\0");
851
+ h.update(readFileSync(f));
852
+ h.update("\0");
853
+ }
854
+ return h.digest("hex");
855
+ }
856
+ function dbStampPath(dbPath) {
857
+ return `${dbPath}.stamp`;
858
+ }
859
+ function writeDbStamp(dbPath) {
860
+ writeFileSync(dbStampPath(dbPath), `${computeDbInputHash(dbPath)}
861
+ `, "utf8");
862
+ }
863
+ function checkDbStamp(dbPath) {
864
+ const sp = dbStampPath(dbPath);
865
+ if (!existsSync(sp)) return { status: "unstamped" };
866
+ const expected = readFileSync(sp, "utf8").trim();
867
+ const actual = computeDbInputHash(dbPath);
868
+ return actual === expected ? { status: "ok" } : { status: "stale", expected, actual };
869
+ }
807
870
 
808
871
  // src/sync/index.ts
809
872
  async function syncTranslations(_options = {}) {
@@ -1268,4 +1331,4 @@ function createPatternsReference(options) {
1268
1331
  }
1269
1332
  var VERSION = "0.1.0";
1270
1333
 
1271
- export { DatabasePatternsProvider, VERSION, addLLMExample, buildFewShotContext, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, discoverPatterns, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllPatterns, getAllSpecialSymbols, getAllTranslations, getBehaviorPatterns, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultProvider, getExamplesByCommand, getExpressionByName, getExpressionsByCategory, getFeatureByName, getHighConfidenceTranslations, getHighQualityExamples, getKeywordByName, getLLMExampleStats, getLLMExamples, getLLMStats, getLanguageDocsStats, getMostUsedExamples, getPatternById, getPatternStats, getPatternsByCategory, getPatternsByCommand, getSpecialSymbolByName, getSupportedLanguages, getTranslation, getTranslationStats, getTranslationsByLanguage, getVerifiedTranslations, getWordOrder, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, loadBehaviors, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, searchPatterns, seedLLMExamples, syncTranslations, trackExampleUsage, uninitializeSemanticIntegration, updateQualityScore, validateAllTranslations, verifyTranslation };
1334
+ export { DatabasePatternsProvider, VERSION, addLLMExample, buildFewShotContext, buildFewShotContextSync, checkDbStamp, closeDatabase, computeDbInputHash, createLLMAdapter, createPatternsProvider, createPatternsReference, dbStampPath, discoverPatterns, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllPatterns, getAllSpecialSymbols, getAllTranslations, getBehaviorPatterns, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultDbPath, getDefaultProvider, getExamplesByCommand, getExpressionByName, getExpressionsByCategory, getFeatureByName, getHighConfidenceTranslations, getHighQualityExamples, getKeywordByName, getLLMExampleStats, getLLMExamples, getLLMStats, getLanguageDocsStats, getMostUsedExamples, getPatternById, getPatternStats, getPatternsByCategory, getPatternsByCommand, getSpecialSymbolByName, getSupportedLanguages, getTranslation, getTranslationStats, getTranslationsByLanguage, getVerifiedTranslations, getWordOrder, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, loadBehaviors, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, searchPatterns, seedLLMExamples, syncTranslations, trackExampleUsage, uninitializeSemanticIntegration, updateQualityScore, validateAllTranslations, verifyTranslation, writeDbStamp };
@@ -1,4 +1,4 @@
1
- import { S as SearchOptions, c as ConnectionOptions, P as Pattern, j as PatternStats, o as Translation, W as WordOrder, r as VerificationResult, L as LLMExample } from './index-BhzKat9K.mjs';
1
+ import { l as SearchOptions, C as ConnectionOptions, a as Pattern, k as PatternStats, o as Translation, W as WordOrder, r as VerificationResult, e as LLMExample } from './index-1ENU9L4F.mjs';
2
2
 
3
3
  /**
4
4
  * Pattern Queries API
@@ -128,4 +128,4 @@ declare function getLLMStats(options?: ConnectionOptions): Promise<{
128
128
  totalUsage: number;
129
129
  }>;
130
130
 
131
- export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c, getBehaviorPatterns as d, getExamplesByCommand as e, getHighConfidenceTranslations as f, getAllPatterns as g, getHighQualityExamples as h, getLLMExamples as i, getLLMStats as j, getMostUsedExamples as k, getPatternById as l, getPatternStats as m, getPatternsByCategory as n, getPatternsByCommand as o, getTranslation as p, getTranslationStats as q, getTranslationsByLanguage as r, getVerifiedTranslations as s, getWordOrder as t, searchPatterns as u, updateQualityScore as v, verifyTranslation as w };
131
+ export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c, getExamplesByCommand as d, getHighConfidenceTranslations as e, getHighQualityExamples as f, getAllPatterns as g, getLLMExamples as h, getLLMStats as i, getMostUsedExamples as j, getPatternById as k, getPatternStats as l, getPatternsByCategory as m, getPatternsByCommand as n, getTranslation as o, getTranslationStats as p, getTranslationsByLanguage as q, getVerifiedTranslations as r, getWordOrder as s, searchPatterns as t, updateQualityScore as u, verifyTranslation as v, getBehaviorPatterns as w };
@@ -1,4 +1,4 @@
1
- import { S as SearchOptions, c as ConnectionOptions, P as Pattern, j as PatternStats, o as Translation, W as WordOrder, r as VerificationResult, L as LLMExample } from './index-BhzKat9K.js';
1
+ import { l as SearchOptions, C as ConnectionOptions, a as Pattern, k as PatternStats, o as Translation, W as WordOrder, r as VerificationResult, e as LLMExample } from './index-1ENU9L4F.js';
2
2
 
3
3
  /**
4
4
  * Pattern Queries API
@@ -128,4 +128,4 @@ declare function getLLMStats(options?: ConnectionOptions): Promise<{
128
128
  totalUsage: number;
129
129
  }>;
130
130
 
131
- export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c, getBehaviorPatterns as d, getExamplesByCommand as e, getHighConfidenceTranslations as f, getAllPatterns as g, getHighQualityExamples as h, getLLMExamples as i, getLLMStats as j, getMostUsedExamples as k, getPatternById as l, getPatternStats as m, getPatternsByCategory as n, getPatternsByCommand as o, getTranslation as p, getTranslationStats as q, getTranslationsByLanguage as r, getVerifiedTranslations as s, getWordOrder as t, searchPatterns as u, updateQualityScore as v, verifyTranslation as w };
131
+ export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c, getExamplesByCommand as d, getHighConfidenceTranslations as e, getHighQualityExamples as f, getAllPatterns as g, getLLMExamples as h, getLLMStats as i, getMostUsedExamples as j, getPatternById as k, getPatternStats as l, getPatternsByCategory as m, getPatternsByCommand as n, getTranslation as o, getTranslationStats as p, getTranslationsByLanguage as q, getVerifiedTranslations as r, getWordOrder as s, searchPatterns as t, updateQualityScore as u, verifyTranslation as v, getBehaviorPatterns as w };
@@ -1,6 +1,45 @@
1
- import { D as DiscoveryResult, m as SyncOptions, n as SyncResult, V as ValidationOptions, q as ValidationResult } from '../index-BhzKat9K.mjs';
1
+ import { D as DiscoveryResult, m as SyncOptions, n as SyncResult, V as ValidationOptions, q as ValidationResult } from '../index-1ENU9L4F.mjs';
2
2
  import '@lokascript/semantic';
3
3
 
4
+ /**
5
+ * DB provenance stamp — guards against running the multilingual gate against a
6
+ * `patterns.db` that was generated from *different* source than is currently checked
7
+ * out (the cross-branch "phantom regression" footgun).
8
+ *
9
+ * The DB's content (transformer translation text + stored parser confidence /
10
+ * verified_parses) is determined by the i18n + semantic **source**, plus the seed and
11
+ * sync scripts. We hash that source (not the gitignored, build-non-deterministic
12
+ * `dist/`) so the stamp catches a branch / source change regardless of whether `dist`
13
+ * happened to be rebuilt. `sync-translations` writes the stamp next to the DB; the
14
+ * gate verifies it before trusting a comparison against the committed baseline.
15
+ *
16
+ * The stamp file (`patterns.db.stamp`) is a **local** artifact (gitignored) — it
17
+ * records "what source produced *my* local DB", which is exactly what the gate needs
18
+ * to confirm the DB is fresh for the current working tree.
19
+ */
20
+ /**
21
+ * Compute the provenance hash of the DB's source inputs. Stable across machines (it
22
+ * hashes committed source, keyed by repo-relative path).
23
+ */
24
+ declare function computeDbInputHash(dbPath: string): string;
25
+ declare function dbStampPath(dbPath: string): string;
26
+ /** Write the provenance stamp next to the DB (called at the end of sync). */
27
+ declare function writeDbStamp(dbPath: string): void;
28
+ type DbStampStatus = {
29
+ status: 'ok';
30
+ } | {
31
+ status: 'unstamped';
32
+ } | {
33
+ status: 'stale';
34
+ expected: string;
35
+ actual: string;
36
+ };
37
+ /**
38
+ * Verify the DB's stamp against the current source. `unstamped` (no sidecar) is
39
+ * returned when the DB predates this guard — callers should warn, not hard-fail.
40
+ */
41
+ declare function checkDbStamp(dbPath: string): DbStampStatus;
42
+
4
43
  /**
5
44
  * Sync Module
6
45
  *
@@ -39,4 +78,4 @@ declare function seedLLMExamples(_dryRun?: boolean): Promise<{
39
78
  count: number;
40
79
  }>;
41
80
 
42
- export { DiscoveryResult, SyncOptions, SyncResult, ValidationOptions, ValidationResult, discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations };
81
+ export { type DbStampStatus, DiscoveryResult, SyncOptions, SyncResult, ValidationOptions, ValidationResult, checkDbStamp, computeDbInputHash, dbStampPath, discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations, writeDbStamp };
@@ -1,6 +1,45 @@
1
- import { D as DiscoveryResult, m as SyncOptions, n as SyncResult, V as ValidationOptions, q as ValidationResult } from '../index-BhzKat9K.js';
1
+ import { D as DiscoveryResult, m as SyncOptions, n as SyncResult, V as ValidationOptions, q as ValidationResult } from '../index-1ENU9L4F.js';
2
2
  import '@lokascript/semantic';
3
3
 
4
+ /**
5
+ * DB provenance stamp — guards against running the multilingual gate against a
6
+ * `patterns.db` that was generated from *different* source than is currently checked
7
+ * out (the cross-branch "phantom regression" footgun).
8
+ *
9
+ * The DB's content (transformer translation text + stored parser confidence /
10
+ * verified_parses) is determined by the i18n + semantic **source**, plus the seed and
11
+ * sync scripts. We hash that source (not the gitignored, build-non-deterministic
12
+ * `dist/`) so the stamp catches a branch / source change regardless of whether `dist`
13
+ * happened to be rebuilt. `sync-translations` writes the stamp next to the DB; the
14
+ * gate verifies it before trusting a comparison against the committed baseline.
15
+ *
16
+ * The stamp file (`patterns.db.stamp`) is a **local** artifact (gitignored) — it
17
+ * records "what source produced *my* local DB", which is exactly what the gate needs
18
+ * to confirm the DB is fresh for the current working tree.
19
+ */
20
+ /**
21
+ * Compute the provenance hash of the DB's source inputs. Stable across machines (it
22
+ * hashes committed source, keyed by repo-relative path).
23
+ */
24
+ declare function computeDbInputHash(dbPath: string): string;
25
+ declare function dbStampPath(dbPath: string): string;
26
+ /** Write the provenance stamp next to the DB (called at the end of sync). */
27
+ declare function writeDbStamp(dbPath: string): void;
28
+ type DbStampStatus = {
29
+ status: 'ok';
30
+ } | {
31
+ status: 'unstamped';
32
+ } | {
33
+ status: 'stale';
34
+ expected: string;
35
+ actual: string;
36
+ };
37
+ /**
38
+ * Verify the DB's stamp against the current source. `unstamped` (no sidecar) is
39
+ * returned when the DB predates this guard — callers should warn, not hard-fail.
40
+ */
41
+ declare function checkDbStamp(dbPath: string): DbStampStatus;
42
+
4
43
  /**
5
44
  * Sync Module
6
45
  *
@@ -39,4 +78,4 @@ declare function seedLLMExamples(_dryRun?: boolean): Promise<{
39
78
  count: number;
40
79
  }>;
41
80
 
42
- export { DiscoveryResult, SyncOptions, SyncResult, ValidationOptions, ValidationResult, discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations };
81
+ export { type DbStampStatus, DiscoveryResult, SyncOptions, SyncResult, ValidationOptions, ValidationResult, checkDbStamp, computeDbInputHash, dbStampPath, discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations, writeDbStamp };
@@ -1,5 +1,69 @@
1
1
  'use strict';
2
2
 
3
+ var crypto = require('crypto');
4
+ var fs = require('fs');
5
+ var path = require('path');
6
+
7
+ // src/sync/db-stamp.ts
8
+ function repoRootFromDbPath(dbPath) {
9
+ return path.resolve(path.dirname(dbPath), "..", "..", "..");
10
+ }
11
+ function walkTsFiles(dir, acc) {
12
+ if (!fs.existsSync(dir)) return;
13
+ for (const name of fs.readdirSync(dir).sort()) {
14
+ if (name === "node_modules" || name === "dist" || name === "__tests__") continue;
15
+ const full = path.join(dir, name);
16
+ const st = fs.statSync(full);
17
+ if (st.isDirectory()) {
18
+ walkTsFiles(full, acc);
19
+ } else if (name.endsWith(".ts") && !name.endsWith(".test.ts") && !name.endsWith(".d.ts")) {
20
+ acc.push(full);
21
+ }
22
+ }
23
+ }
24
+ function dbInputFiles(dbPath) {
25
+ const root = repoRootFromDbPath(dbPath);
26
+ const files = [];
27
+ walkTsFiles(path.join(root, "packages", "i18n", "src"), files);
28
+ walkTsFiles(path.join(root, "packages", "semantic", "src"), files);
29
+ const pr = path.join(root, "packages", "patterns-reference");
30
+ for (const f of [
31
+ path.join(pr, "scripts", "init-db.ts"),
32
+ path.join(pr, "scripts", "sync-translations.ts"),
33
+ path.join(pr, "src", "sync", "span-mask.ts")
34
+ ]) {
35
+ if (fs.existsSync(f)) files.push(f);
36
+ }
37
+ return files.sort();
38
+ }
39
+ function computeDbInputHash(dbPath) {
40
+ const root = repoRootFromDbPath(dbPath);
41
+ const files = dbInputFiles(dbPath);
42
+ const h = crypto.createHash("sha256");
43
+ h.update(`files:${files.length}\0`);
44
+ for (const f of files) {
45
+ h.update(path.relative(root, f).split(path.sep).join("/"));
46
+ h.update("\0");
47
+ h.update(fs.readFileSync(f));
48
+ h.update("\0");
49
+ }
50
+ return h.digest("hex");
51
+ }
52
+ function dbStampPath(dbPath) {
53
+ return `${dbPath}.stamp`;
54
+ }
55
+ function writeDbStamp(dbPath) {
56
+ fs.writeFileSync(dbStampPath(dbPath), `${computeDbInputHash(dbPath)}
57
+ `, "utf8");
58
+ }
59
+ function checkDbStamp(dbPath) {
60
+ const sp = dbStampPath(dbPath);
61
+ if (!fs.existsSync(sp)) return { status: "unstamped" };
62
+ const expected = fs.readFileSync(sp, "utf8").trim();
63
+ const actual = computeDbInputHash(dbPath);
64
+ return actual === expected ? { status: "ok" } : { status: "stale", expected, actual };
65
+ }
66
+
3
67
  // src/sync/index.ts
4
68
  async function syncTranslations(_options = {}) {
5
69
  throw new Error(
@@ -22,7 +86,11 @@ async function seedLLMExamples(_dryRun = false) {
22
86
  );
23
87
  }
24
88
 
89
+ exports.checkDbStamp = checkDbStamp;
90
+ exports.computeDbInputHash = computeDbInputHash;
91
+ exports.dbStampPath = dbStampPath;
25
92
  exports.discoverPatterns = discoverPatterns;
26
93
  exports.seedLLMExamples = seedLLMExamples;
27
94
  exports.syncTranslations = syncTranslations;
28
95
  exports.validateAllTranslations = validateAllTranslations;
96
+ exports.writeDbStamp = writeDbStamp;