@hyperfixi/patterns-reference 2.5.1 → 2.7.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 +16 -21
- package/data/engine-verification.json +865 -0
- package/data/patterns.db +0 -0
- package/dist/api/index.d.mts +2 -2
- package/dist/api/index.d.ts +2 -2
- package/dist/{index-BhzKat9K.d.mts → index-1ENU9L4F.d.mts} +1 -1
- package/dist/{index-BhzKat9K.d.ts → index-1ENU9L4F.d.ts} +1 -1
- package/dist/index.d.mts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +73 -1
- package/dist/index.mjs +70 -3
- package/dist/{llm-B7pwZ472.d.ts → llm-BfjUr-al.d.mts} +6 -5
- package/dist/{llm-4zwmAvZ8.d.mts → llm-FVj71n77.d.ts} +6 -5
- package/dist/sync/index.d.mts +41 -2
- package/dist/sync/index.d.ts +41 -2
- package/dist/sync/index.js +71 -0
- package/dist/sync/index.mjs +68 -1
- package/package.json +10 -7
- package/src/api/patterns.ts +6 -4
- package/src/database/connection.ts +9 -0
- package/src/index.ts +6 -0
- package/src/sync/db-stamp.ts +111 -0
- package/src/sync/index.ts +9 -0
- package/src/sync/span-mask.ts +166 -0
- package/src/sync/translation-checks.ts +282 -0
package/data/patterns.db
CHANGED
|
Binary file
|
package/dist/api/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations,
|
|
2
|
-
import {
|
|
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-BfjUr-al.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
|
/**
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations,
|
|
2
|
-
import {
|
|
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-FVj71n77.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 {
|
|
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 {
|
|
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 {
|
|
2
|
-
export {
|
|
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,
|
|
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-BfjUr-al.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 {
|
|
2
|
-
export {
|
|
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,
|
|
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-FVj71n77.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) {
|
|
@@ -155,7 +160,8 @@ async function getPatternStats(connOptions) {
|
|
|
155
160
|
};
|
|
156
161
|
}
|
|
157
162
|
async function getBehaviorPatterns(options) {
|
|
158
|
-
|
|
163
|
+
const patterns = await getPatternsByCategory("behavior", options);
|
|
164
|
+
return patterns.filter((p) => /^\s*behavior\s/.test(p.rawCode));
|
|
159
165
|
}
|
|
160
166
|
function mapRowToPattern(row) {
|
|
161
167
|
return {
|
|
@@ -812,6 +818,67 @@ async function getLanguageDocsStats(options) {
|
|
|
812
818
|
expressionOperators: getCount("expression_operators")
|
|
813
819
|
};
|
|
814
820
|
}
|
|
821
|
+
function repoRootFromDbPath(dbPath) {
|
|
822
|
+
return path.resolve(path.dirname(dbPath), "..", "..", "..");
|
|
823
|
+
}
|
|
824
|
+
function walkTsFiles(dir, acc) {
|
|
825
|
+
if (!fs.existsSync(dir)) return;
|
|
826
|
+
for (const name of fs.readdirSync(dir).sort()) {
|
|
827
|
+
if (name === "node_modules" || name === "dist" || name === "__tests__") continue;
|
|
828
|
+
const full = path.join(dir, name);
|
|
829
|
+
const st = fs.statSync(full);
|
|
830
|
+
if (st.isDirectory()) {
|
|
831
|
+
walkTsFiles(full, acc);
|
|
832
|
+
} else if (name.endsWith(".ts") && !name.endsWith(".test.ts") && !name.endsWith(".d.ts")) {
|
|
833
|
+
acc.push(full);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
function dbInputFiles(dbPath) {
|
|
838
|
+
const root = repoRootFromDbPath(dbPath);
|
|
839
|
+
const files = [];
|
|
840
|
+
walkTsFiles(path.join(root, "packages", "i18n", "src"), files);
|
|
841
|
+
walkTsFiles(path.join(root, "packages", "semantic", "src"), files);
|
|
842
|
+
const pr = path.join(root, "packages", "patterns-reference");
|
|
843
|
+
for (const f of [
|
|
844
|
+
path.join(pr, "scripts", "init-db.ts"),
|
|
845
|
+
path.join(pr, "scripts", "sync-translations.ts"),
|
|
846
|
+
path.join(pr, "src", "sync", "span-mask.ts"),
|
|
847
|
+
// Committed engine-verification results are seeded into the engine
|
|
848
|
+
// column by init-db.ts, so they are DB input too.
|
|
849
|
+
path.join(pr, "data", "engine-verification.json")
|
|
850
|
+
]) {
|
|
851
|
+
if (fs.existsSync(f)) files.push(f);
|
|
852
|
+
}
|
|
853
|
+
return files.sort();
|
|
854
|
+
}
|
|
855
|
+
function computeDbInputHash(dbPath) {
|
|
856
|
+
const root = repoRootFromDbPath(dbPath);
|
|
857
|
+
const files = dbInputFiles(dbPath);
|
|
858
|
+
const h = crypto.createHash("sha256");
|
|
859
|
+
h.update(`files:${files.length}\0`);
|
|
860
|
+
for (const f of files) {
|
|
861
|
+
h.update(path.relative(root, f).split(path.sep).join("/"));
|
|
862
|
+
h.update("\0");
|
|
863
|
+
h.update(fs.readFileSync(f));
|
|
864
|
+
h.update("\0");
|
|
865
|
+
}
|
|
866
|
+
return h.digest("hex");
|
|
867
|
+
}
|
|
868
|
+
function dbStampPath(dbPath) {
|
|
869
|
+
return `${dbPath}.stamp`;
|
|
870
|
+
}
|
|
871
|
+
function writeDbStamp(dbPath) {
|
|
872
|
+
fs.writeFileSync(dbStampPath(dbPath), `${computeDbInputHash(dbPath)}
|
|
873
|
+
`, "utf8");
|
|
874
|
+
}
|
|
875
|
+
function checkDbStamp(dbPath) {
|
|
876
|
+
const sp = dbStampPath(dbPath);
|
|
877
|
+
if (!fs.existsSync(sp)) return { status: "unstamped" };
|
|
878
|
+
const expected = fs.readFileSync(sp, "utf8").trim();
|
|
879
|
+
const actual = computeDbInputHash(dbPath);
|
|
880
|
+
return actual === expected ? { status: "ok" } : { status: "stale", expected, actual };
|
|
881
|
+
}
|
|
815
882
|
|
|
816
883
|
// src/sync/index.ts
|
|
817
884
|
async function syncTranslations(_options = {}) {
|
|
@@ -1281,10 +1348,13 @@ exports.VERSION = VERSION;
|
|
|
1281
1348
|
exports.addLLMExample = addLLMExample;
|
|
1282
1349
|
exports.buildFewShotContext = buildFewShotContext;
|
|
1283
1350
|
exports.buildFewShotContextSync = buildFewShotContextSync;
|
|
1351
|
+
exports.checkDbStamp = checkDbStamp;
|
|
1284
1352
|
exports.closeDatabase = closeDatabase;
|
|
1353
|
+
exports.computeDbInputHash = computeDbInputHash;
|
|
1285
1354
|
exports.createLLMAdapter = createLLMAdapter;
|
|
1286
1355
|
exports.createPatternsProvider = createPatternsProvider;
|
|
1287
1356
|
exports.createPatternsReference = createPatternsReference;
|
|
1357
|
+
exports.dbStampPath = dbStampPath;
|
|
1288
1358
|
exports.discoverPatterns = discoverPatterns;
|
|
1289
1359
|
exports.findExamplesByCommand = findExamplesByCommand;
|
|
1290
1360
|
exports.findRelevantExamples = findRelevantExamples;
|
|
@@ -1300,6 +1370,7 @@ exports.getBridgeProvider = getBridgeProvider;
|
|
|
1300
1370
|
exports.getCommandByName = getCommandByName;
|
|
1301
1371
|
exports.getCurrentDbPath = getCurrentDbPath;
|
|
1302
1372
|
exports.getDatabase = getDatabase;
|
|
1373
|
+
exports.getDefaultDbPath = getDefaultDbPath;
|
|
1303
1374
|
exports.getDefaultProvider = getDefaultProvider;
|
|
1304
1375
|
exports.getExamplesByCommand = getExamplesByCommand;
|
|
1305
1376
|
exports.getExpressionByName = getExpressionByName;
|
|
@@ -1343,3 +1414,4 @@ exports.uninitializeSemanticIntegration = uninitializeSemanticIntegration;
|
|
|
1343
1414
|
exports.updateQualityScore = updateQualityScore;
|
|
1344
1415
|
exports.validateAllTranslations = validateAllTranslations;
|
|
1345
1416
|
exports.verifyTranslation = verifyTranslation;
|
|
1417
|
+
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) {
|
|
@@ -147,7 +152,8 @@ async function getPatternStats(connOptions) {
|
|
|
147
152
|
};
|
|
148
153
|
}
|
|
149
154
|
async function getBehaviorPatterns(options) {
|
|
150
|
-
|
|
155
|
+
const patterns = await getPatternsByCategory("behavior", options);
|
|
156
|
+
return patterns.filter((p) => /^\s*behavior\s/.test(p.rawCode));
|
|
151
157
|
}
|
|
152
158
|
function mapRowToPattern(row) {
|
|
153
159
|
return {
|
|
@@ -804,6 +810,67 @@ async function getLanguageDocsStats(options) {
|
|
|
804
810
|
expressionOperators: getCount("expression_operators")
|
|
805
811
|
};
|
|
806
812
|
}
|
|
813
|
+
function repoRootFromDbPath(dbPath) {
|
|
814
|
+
return resolve(dirname(dbPath), "..", "..", "..");
|
|
815
|
+
}
|
|
816
|
+
function walkTsFiles(dir, acc) {
|
|
817
|
+
if (!existsSync(dir)) return;
|
|
818
|
+
for (const name of readdirSync(dir).sort()) {
|
|
819
|
+
if (name === "node_modules" || name === "dist" || name === "__tests__") continue;
|
|
820
|
+
const full = join(dir, name);
|
|
821
|
+
const st = statSync(full);
|
|
822
|
+
if (st.isDirectory()) {
|
|
823
|
+
walkTsFiles(full, acc);
|
|
824
|
+
} else if (name.endsWith(".ts") && !name.endsWith(".test.ts") && !name.endsWith(".d.ts")) {
|
|
825
|
+
acc.push(full);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
function dbInputFiles(dbPath) {
|
|
830
|
+
const root = repoRootFromDbPath(dbPath);
|
|
831
|
+
const files = [];
|
|
832
|
+
walkTsFiles(join(root, "packages", "i18n", "src"), files);
|
|
833
|
+
walkTsFiles(join(root, "packages", "semantic", "src"), files);
|
|
834
|
+
const pr = join(root, "packages", "patterns-reference");
|
|
835
|
+
for (const f of [
|
|
836
|
+
join(pr, "scripts", "init-db.ts"),
|
|
837
|
+
join(pr, "scripts", "sync-translations.ts"),
|
|
838
|
+
join(pr, "src", "sync", "span-mask.ts"),
|
|
839
|
+
// Committed engine-verification results are seeded into the engine
|
|
840
|
+
// column by init-db.ts, so they are DB input too.
|
|
841
|
+
join(pr, "data", "engine-verification.json")
|
|
842
|
+
]) {
|
|
843
|
+
if (existsSync(f)) files.push(f);
|
|
844
|
+
}
|
|
845
|
+
return files.sort();
|
|
846
|
+
}
|
|
847
|
+
function computeDbInputHash(dbPath) {
|
|
848
|
+
const root = repoRootFromDbPath(dbPath);
|
|
849
|
+
const files = dbInputFiles(dbPath);
|
|
850
|
+
const h = createHash("sha256");
|
|
851
|
+
h.update(`files:${files.length}\0`);
|
|
852
|
+
for (const f of files) {
|
|
853
|
+
h.update(relative(root, f).split(sep).join("/"));
|
|
854
|
+
h.update("\0");
|
|
855
|
+
h.update(readFileSync(f));
|
|
856
|
+
h.update("\0");
|
|
857
|
+
}
|
|
858
|
+
return h.digest("hex");
|
|
859
|
+
}
|
|
860
|
+
function dbStampPath(dbPath) {
|
|
861
|
+
return `${dbPath}.stamp`;
|
|
862
|
+
}
|
|
863
|
+
function writeDbStamp(dbPath) {
|
|
864
|
+
writeFileSync(dbStampPath(dbPath), `${computeDbInputHash(dbPath)}
|
|
865
|
+
`, "utf8");
|
|
866
|
+
}
|
|
867
|
+
function checkDbStamp(dbPath) {
|
|
868
|
+
const sp = dbStampPath(dbPath);
|
|
869
|
+
if (!existsSync(sp)) return { status: "unstamped" };
|
|
870
|
+
const expected = readFileSync(sp, "utf8").trim();
|
|
871
|
+
const actual = computeDbInputHash(dbPath);
|
|
872
|
+
return actual === expected ? { status: "ok" } : { status: "stale", expected, actual };
|
|
873
|
+
}
|
|
807
874
|
|
|
808
875
|
// src/sync/index.ts
|
|
809
876
|
async function syncTranslations(_options = {}) {
|
|
@@ -1268,4 +1335,4 @@ function createPatternsReference(options) {
|
|
|
1268
1335
|
}
|
|
1269
1336
|
var VERSION = "0.1.0";
|
|
1270
1337
|
|
|
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 };
|
|
1338
|
+
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 {
|
|
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
|
|
@@ -33,9 +33,10 @@ declare function getPatternStats(connOptions?: ConnectionOptions): Promise<Patte
|
|
|
33
33
|
/**
|
|
34
34
|
* Get behavior definition patterns.
|
|
35
35
|
*
|
|
36
|
-
* Returns
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* Returns installable behavior definitions (behavior Name(params) ... end)
|
|
37
|
+
* that can be compiled and registered with a LokaScript runtime. The
|
|
38
|
+
* 'behavior' category also holds usage examples (`install Draggable`,
|
|
39
|
+
* `tell #modal …`), so filter to actual definitions by source shape.
|
|
39
40
|
*/
|
|
40
41
|
declare function getBehaviorPatterns(options?: ConnectionOptions): Promise<Pattern[]>;
|
|
41
42
|
|
|
@@ -128,4 +129,4 @@ declare function getLLMStats(options?: ConnectionOptions): Promise<{
|
|
|
128
129
|
totalUsage: number;
|
|
129
130
|
}>;
|
|
130
131
|
|
|
131
|
-
export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c,
|
|
132
|
+
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 {
|
|
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
|
|
@@ -33,9 +33,10 @@ declare function getPatternStats(connOptions?: ConnectionOptions): Promise<Patte
|
|
|
33
33
|
/**
|
|
34
34
|
* Get behavior definition patterns.
|
|
35
35
|
*
|
|
36
|
-
* Returns
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* Returns installable behavior definitions (behavior Name(params) ... end)
|
|
37
|
+
* that can be compiled and registered with a LokaScript runtime. The
|
|
38
|
+
* 'behavior' category also holds usage examples (`install Draggable`,
|
|
39
|
+
* `tell #modal …`), so filter to actual definitions by source shape.
|
|
39
40
|
*/
|
|
40
41
|
declare function getBehaviorPatterns(options?: ConnectionOptions): Promise<Pattern[]>;
|
|
41
42
|
|
|
@@ -128,4 +129,4 @@ declare function getLLMStats(options?: ConnectionOptions): Promise<{
|
|
|
128
129
|
totalUsage: number;
|
|
129
130
|
}>;
|
|
130
131
|
|
|
131
|
-
export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c,
|
|
132
|
+
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 };
|
package/dist/sync/index.d.mts
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
|
-
import { D as DiscoveryResult, m as SyncOptions, n as SyncResult, V as ValidationOptions, q as ValidationResult } from '../index-
|
|
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 };
|
package/dist/sync/index.d.ts
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
|
-
import { D as DiscoveryResult, m as SyncOptions, n as SyncResult, V as ValidationOptions, q as ValidationResult } from '../index-
|
|
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 };
|
package/dist/sync/index.js
CHANGED
|
@@ -1,5 +1,72 @@
|
|
|
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
|
+
// Committed engine-verification results are seeded into the engine
|
|
35
|
+
// column by init-db.ts, so they are DB input too.
|
|
36
|
+
path.join(pr, "data", "engine-verification.json")
|
|
37
|
+
]) {
|
|
38
|
+
if (fs.existsSync(f)) files.push(f);
|
|
39
|
+
}
|
|
40
|
+
return files.sort();
|
|
41
|
+
}
|
|
42
|
+
function computeDbInputHash(dbPath) {
|
|
43
|
+
const root = repoRootFromDbPath(dbPath);
|
|
44
|
+
const files = dbInputFiles(dbPath);
|
|
45
|
+
const h = crypto.createHash("sha256");
|
|
46
|
+
h.update(`files:${files.length}\0`);
|
|
47
|
+
for (const f of files) {
|
|
48
|
+
h.update(path.relative(root, f).split(path.sep).join("/"));
|
|
49
|
+
h.update("\0");
|
|
50
|
+
h.update(fs.readFileSync(f));
|
|
51
|
+
h.update("\0");
|
|
52
|
+
}
|
|
53
|
+
return h.digest("hex");
|
|
54
|
+
}
|
|
55
|
+
function dbStampPath(dbPath) {
|
|
56
|
+
return `${dbPath}.stamp`;
|
|
57
|
+
}
|
|
58
|
+
function writeDbStamp(dbPath) {
|
|
59
|
+
fs.writeFileSync(dbStampPath(dbPath), `${computeDbInputHash(dbPath)}
|
|
60
|
+
`, "utf8");
|
|
61
|
+
}
|
|
62
|
+
function checkDbStamp(dbPath) {
|
|
63
|
+
const sp = dbStampPath(dbPath);
|
|
64
|
+
if (!fs.existsSync(sp)) return { status: "unstamped" };
|
|
65
|
+
const expected = fs.readFileSync(sp, "utf8").trim();
|
|
66
|
+
const actual = computeDbInputHash(dbPath);
|
|
67
|
+
return actual === expected ? { status: "ok" } : { status: "stale", expected, actual };
|
|
68
|
+
}
|
|
69
|
+
|
|
3
70
|
// src/sync/index.ts
|
|
4
71
|
async function syncTranslations(_options = {}) {
|
|
5
72
|
throw new Error(
|
|
@@ -22,7 +89,11 @@ async function seedLLMExamples(_dryRun = false) {
|
|
|
22
89
|
);
|
|
23
90
|
}
|
|
24
91
|
|
|
92
|
+
exports.checkDbStamp = checkDbStamp;
|
|
93
|
+
exports.computeDbInputHash = computeDbInputHash;
|
|
94
|
+
exports.dbStampPath = dbStampPath;
|
|
25
95
|
exports.discoverPatterns = discoverPatterns;
|
|
26
96
|
exports.seedLLMExamples = seedLLMExamples;
|
|
27
97
|
exports.syncTranslations = syncTranslations;
|
|
28
98
|
exports.validateAllTranslations = validateAllTranslations;
|
|
99
|
+
exports.writeDbStamp = writeDbStamp;
|