make-laten 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +154 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +154 -14
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.js +143 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +143 -3
- package/dist/index.mjs.map +1 -1
- package/dist/mcp/server.js +148 -8
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/server.mjs +150 -10
- package/dist/mcp/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -1787,14 +1787,55 @@ var StrategyRouter = class {
|
|
|
1787
1787
|
};
|
|
1788
1788
|
|
|
1789
1789
|
// src/learn/pattern-miner.ts
|
|
1790
|
+
var import_fs = __toESM(require("fs"));
|
|
1791
|
+
var import_path3 = __toESM(require("path"));
|
|
1792
|
+
var DATA_FILE = import_path3.default.join(process.env.HOME || "~", ".make-laten", "patterns.json");
|
|
1790
1793
|
var PatternMiner = class {
|
|
1791
1794
|
operations = [];
|
|
1792
1795
|
patterns = /* @__PURE__ */ new Map();
|
|
1796
|
+
persistencePath;
|
|
1797
|
+
lastPersist = 0;
|
|
1798
|
+
constructor(options) {
|
|
1799
|
+
this.persistencePath = options?.persistencePath || DATA_FILE;
|
|
1800
|
+
this.loadFromDisk();
|
|
1801
|
+
}
|
|
1802
|
+
loadFromDisk() {
|
|
1803
|
+
try {
|
|
1804
|
+
if (import_fs.default.existsSync(this.persistencePath)) {
|
|
1805
|
+
const data = JSON.parse(import_fs.default.readFileSync(this.persistencePath, "utf-8"));
|
|
1806
|
+
if (Array.isArray(data.patterns)) {
|
|
1807
|
+
for (const p of data.patterns) {
|
|
1808
|
+
this.patterns.set(p.type, p);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
if (Array.isArray(data.operations)) {
|
|
1812
|
+
this.operations = data.operations.slice(-100);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
} catch {
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
persistToDisk() {
|
|
1819
|
+
const now = Date.now();
|
|
1820
|
+
if (now - this.lastPersist < 5e3) return;
|
|
1821
|
+
this.lastPersist = now;
|
|
1822
|
+
try {
|
|
1823
|
+
const dir = import_path3.default.dirname(this.persistencePath);
|
|
1824
|
+
if (!import_fs.default.existsSync(dir)) import_fs.default.mkdirSync(dir, { recursive: true });
|
|
1825
|
+
import_fs.default.writeFileSync(this.persistencePath, JSON.stringify({
|
|
1826
|
+
patterns: Array.from(this.patterns.values()),
|
|
1827
|
+
operations: this.operations.slice(-100)
|
|
1828
|
+
}, null, 2));
|
|
1829
|
+
} catch {
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1793
1832
|
record(operation) {
|
|
1794
1833
|
this.operations.push(operation);
|
|
1834
|
+
if (this.operations.length > 100) this.operations.shift();
|
|
1795
1835
|
if (operation.success) {
|
|
1796
1836
|
this.updatePatterns(operation);
|
|
1797
1837
|
}
|
|
1838
|
+
this.persistToDisk();
|
|
1798
1839
|
}
|
|
1799
1840
|
getPatterns() {
|
|
1800
1841
|
return Array.from(this.patterns.values());
|
|
@@ -1821,8 +1862,43 @@ var PatternMiner = class {
|
|
|
1821
1862
|
};
|
|
1822
1863
|
|
|
1823
1864
|
// src/learn/failure-learner.ts
|
|
1865
|
+
var import_fs2 = __toESM(require("fs"));
|
|
1866
|
+
var import_path4 = __toESM(require("path"));
|
|
1867
|
+
var DATA_FILE2 = import_path4.default.join(process.env.HOME || "~", ".make-laten", "failures.json");
|
|
1824
1868
|
var FailureLearner = class {
|
|
1825
1869
|
failures = /* @__PURE__ */ new Map();
|
|
1870
|
+
persistencePath;
|
|
1871
|
+
lastPersist = 0;
|
|
1872
|
+
constructor(options) {
|
|
1873
|
+
this.persistencePath = options?.persistencePath || DATA_FILE2;
|
|
1874
|
+
this.loadFromDisk();
|
|
1875
|
+
}
|
|
1876
|
+
loadFromDisk() {
|
|
1877
|
+
try {
|
|
1878
|
+
if (import_fs2.default.existsSync(this.persistencePath)) {
|
|
1879
|
+
const data = JSON.parse(import_fs2.default.readFileSync(this.persistencePath, "utf-8"));
|
|
1880
|
+
if (Array.isArray(data.failures)) {
|
|
1881
|
+
for (const f of data.failures) {
|
|
1882
|
+
this.failures.set(`${f.type}:${f.error}`, f);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
} catch {
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
persistToDisk() {
|
|
1890
|
+
const now = Date.now();
|
|
1891
|
+
if (now - this.lastPersist < 5e3) return;
|
|
1892
|
+
this.lastPersist = now;
|
|
1893
|
+
try {
|
|
1894
|
+
const dir = import_path4.default.dirname(this.persistencePath);
|
|
1895
|
+
if (!import_fs2.default.existsSync(dir)) import_fs2.default.mkdirSync(dir, { recursive: true });
|
|
1896
|
+
import_fs2.default.writeFileSync(this.persistencePath, JSON.stringify({
|
|
1897
|
+
failures: Array.from(this.failures.values())
|
|
1898
|
+
}, null, 2));
|
|
1899
|
+
} catch {
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1826
1902
|
record(failure) {
|
|
1827
1903
|
const key = `${failure.type}:${failure.error}`;
|
|
1828
1904
|
const existing = this.failures.get(key);
|
|
@@ -1836,6 +1912,7 @@ var FailureLearner = class {
|
|
|
1836
1912
|
count: 1
|
|
1837
1913
|
});
|
|
1838
1914
|
}
|
|
1915
|
+
this.persistToDisk();
|
|
1839
1916
|
}
|
|
1840
1917
|
getFailures() {
|
|
1841
1918
|
return Array.from(this.failures.values());
|
|
@@ -1862,32 +1939,95 @@ var FailureLearner = class {
|
|
|
1862
1939
|
};
|
|
1863
1940
|
|
|
1864
1941
|
// src/correct/auto-correct.ts
|
|
1942
|
+
var import_fs3 = __toESM(require("fs"));
|
|
1943
|
+
var import_path5 = __toESM(require("path"));
|
|
1944
|
+
var DEFAULT_RULES = [
|
|
1945
|
+
// Common typos
|
|
1946
|
+
{ name: "typo-teh", description: "Common typo", pattern: "teh", replacement: "the" },
|
|
1947
|
+
{ name: "typo-adn", description: "Common typo", pattern: "adn", replacement: "and" },
|
|
1948
|
+
{ name: "typo-fo", description: "Common typo", pattern: " fo ", replacement: " of " },
|
|
1949
|
+
{ name: "typo-ot", description: "Common typo", pattern: " ot ", replacement: " to " },
|
|
1950
|
+
{ name: "typo-isnt", description: "Common typo", pattern: "isnt", replacement: "isn't" },
|
|
1951
|
+
{ name: "typo-dont", description: "Common typo", pattern: "dont", replacement: "don't" },
|
|
1952
|
+
{ name: "typo-cant", description: "Common typo", pattern: "cant", replacement: "can't" },
|
|
1953
|
+
{ name: "typo-wont", description: "Common typo", pattern: "wont", replacement: "won't" },
|
|
1954
|
+
{ name: "typo-youre", description: "Common typo", pattern: "youre", replacement: "you're" },
|
|
1955
|
+
{ name: "typo-its", description: "Common typo", pattern: "its a", replacement: "it's a" },
|
|
1956
|
+
// Code patterns
|
|
1957
|
+
{ name: "code-console-log", description: "Remove console.log", pattern: /console\.log\([^)]*\);?\n?/g, replacement: "" },
|
|
1958
|
+
{ name: "code-debugger", description: "Remove debugger", pattern: /debugger;?\n?/g, replacement: "" },
|
|
1959
|
+
{ name: "code-var-let", description: "var to let", pattern: /\bvar\b/g, replacement: "let" },
|
|
1960
|
+
// Markdown
|
|
1961
|
+
{ name: "md-double-space", description: "Double space to single", pattern: " ", replacement: " " }
|
|
1962
|
+
];
|
|
1963
|
+
var DATA_FILE3 = import_path5.default.join(process.env.HOME || "~", ".make-laten", "corrections.json");
|
|
1865
1964
|
var AutoCorrect = class {
|
|
1866
|
-
rules
|
|
1965
|
+
rules;
|
|
1867
1966
|
corrections = [];
|
|
1868
1967
|
appliedCount = 0;
|
|
1968
|
+
persistencePath;
|
|
1969
|
+
constructor(options) {
|
|
1970
|
+
this.persistencePath = options?.persistencePath || DATA_FILE3;
|
|
1971
|
+
this.rules = [...DEFAULT_RULES];
|
|
1972
|
+
this.loadPersistedRules();
|
|
1973
|
+
}
|
|
1974
|
+
loadPersistedRules() {
|
|
1975
|
+
try {
|
|
1976
|
+
if (import_fs3.default.existsSync(this.persistencePath)) {
|
|
1977
|
+
const data = JSON.parse(import_fs3.default.readFileSync(this.persistencePath, "utf-8"));
|
|
1978
|
+
if (Array.isArray(data.customRules)) {
|
|
1979
|
+
this.rules.push(...data.customRules);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
} catch {
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
persistRules() {
|
|
1986
|
+
try {
|
|
1987
|
+
const dir = import_path5.default.dirname(this.persistencePath);
|
|
1988
|
+
if (!import_fs3.default.existsSync(dir)) import_fs3.default.mkdirSync(dir, { recursive: true });
|
|
1989
|
+
const existing = this.loadExistingData();
|
|
1990
|
+
existing.customRules = this.rules.filter((r) => !DEFAULT_RULES.includes(r));
|
|
1991
|
+
import_fs3.default.writeFileSync(this.persistencePath, JSON.stringify(existing, null, 2));
|
|
1992
|
+
} catch {
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
loadExistingData() {
|
|
1996
|
+
try {
|
|
1997
|
+
if (import_fs3.default.existsSync(this.persistencePath)) {
|
|
1998
|
+
return JSON.parse(import_fs3.default.readFileSync(this.persistencePath, "utf-8"));
|
|
1999
|
+
}
|
|
2000
|
+
} catch {
|
|
2001
|
+
}
|
|
2002
|
+
return { customRules: [] };
|
|
2003
|
+
}
|
|
1869
2004
|
addRule(rule) {
|
|
1870
2005
|
this.rules.push(rule);
|
|
2006
|
+
this.persistRules();
|
|
1871
2007
|
}
|
|
1872
2008
|
getRules() {
|
|
1873
2009
|
return this.rules;
|
|
1874
2010
|
}
|
|
1875
2011
|
correct(input) {
|
|
1876
2012
|
let output = input;
|
|
2013
|
+
let changed = false;
|
|
1877
2014
|
for (const rule of this.rules) {
|
|
1878
2015
|
if (typeof rule.pattern === "string") {
|
|
1879
2016
|
if (output.includes(rule.pattern)) {
|
|
1880
2017
|
output = output.split(rule.pattern).join(rule.replacement);
|
|
1881
|
-
|
|
2018
|
+
changed = true;
|
|
1882
2019
|
}
|
|
1883
2020
|
} else {
|
|
1884
2021
|
const matches = output.match(rule.pattern);
|
|
1885
2022
|
if (matches) {
|
|
1886
2023
|
output = output.replace(rule.pattern, rule.replacement);
|
|
1887
|
-
|
|
2024
|
+
changed = true;
|
|
1888
2025
|
}
|
|
1889
2026
|
}
|
|
1890
2027
|
}
|
|
2028
|
+
if (changed) {
|
|
2029
|
+
this.recordCorrection(input, output, "auto");
|
|
2030
|
+
}
|
|
1891
2031
|
return output;
|
|
1892
2032
|
}
|
|
1893
2033
|
getStats() {
|
|
@@ -1909,8 +2049,8 @@ var AutoCorrect = class {
|
|
|
1909
2049
|
};
|
|
1910
2050
|
|
|
1911
2051
|
// src/cli/commands/benchmark.ts
|
|
1912
|
-
var
|
|
1913
|
-
var
|
|
2052
|
+
var import_fs4 = __toESM(require("fs"));
|
|
2053
|
+
var import_path6 = __toESM(require("path"));
|
|
1914
2054
|
var import_child_process5 = require("child_process");
|
|
1915
2055
|
function countTokens(text) {
|
|
1916
2056
|
return Math.ceil(text.length / 4);
|
|
@@ -1924,27 +2064,27 @@ async function benchmark() {
|
|
|
1924
2064
|
const results = [];
|
|
1925
2065
|
console.log(" Compress Layer");
|
|
1926
2066
|
console.log(" " + "\u2500".repeat(50));
|
|
1927
|
-
const smallFile =
|
|
1928
|
-
if (
|
|
1929
|
-
const content =
|
|
2067
|
+
const smallFile = import_path6.default.join(projectPath, "src/index.ts");
|
|
2068
|
+
if (import_fs4.default.existsSync(smallFile)) {
|
|
2069
|
+
const content = import_fs4.default.readFileSync(smallFile, "utf-8");
|
|
1930
2070
|
const raw = countTokens(content);
|
|
1931
2071
|
const compressor = new FileReadCompressor();
|
|
1932
2072
|
const result = await compressor.compress({ content, filePath: "src/index.ts" });
|
|
1933
2073
|
const compressed = countTokens(result.content);
|
|
1934
2074
|
results.push({ name: "read (small)", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
|
|
1935
2075
|
}
|
|
1936
|
-
const mediumFile =
|
|
1937
|
-
if (
|
|
1938
|
-
const content =
|
|
2076
|
+
const mediumFile = import_path6.default.join(projectPath, "src/mcp/server.ts");
|
|
2077
|
+
if (import_fs4.default.existsSync(mediumFile)) {
|
|
2078
|
+
const content = import_fs4.default.readFileSync(mediumFile, "utf-8");
|
|
1939
2079
|
const raw = countTokens(content);
|
|
1940
2080
|
const compressor = new FileReadCompressor();
|
|
1941
2081
|
const result = await compressor.compress({ content, filePath: "src/mcp/server.ts" });
|
|
1942
2082
|
const compressed = countTokens(result.content);
|
|
1943
2083
|
results.push({ name: "read (medium)", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
|
|
1944
2084
|
}
|
|
1945
|
-
const largeFile =
|
|
1946
|
-
if (
|
|
1947
|
-
const content =
|
|
2085
|
+
const largeFile = import_path6.default.join(projectPath, "README.md");
|
|
2086
|
+
if (import_fs4.default.existsSync(largeFile)) {
|
|
2087
|
+
const content = import_fs4.default.readFileSync(largeFile, "utf-8");
|
|
1948
2088
|
const raw = countTokens(content);
|
|
1949
2089
|
const compressor = new FileReadCompressor();
|
|
1950
2090
|
const result = await compressor.compress({ content, filePath: "README.md" });
|