make-laten 1.2.1 → 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 +499 -26
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +499 -26
- 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/index.js
CHANGED
|
@@ -1727,14 +1727,55 @@ function createDetector() {
|
|
|
1727
1727
|
}
|
|
1728
1728
|
|
|
1729
1729
|
// src/learn/pattern-miner.ts
|
|
1730
|
+
var import_fs = __toESM(require("fs"));
|
|
1731
|
+
var import_path5 = __toESM(require("path"));
|
|
1732
|
+
var DATA_FILE = import_path5.default.join(process.env.HOME || "~", ".make-laten", "patterns.json");
|
|
1730
1733
|
var PatternMiner = class {
|
|
1731
1734
|
operations = [];
|
|
1732
1735
|
patterns = /* @__PURE__ */ new Map();
|
|
1736
|
+
persistencePath;
|
|
1737
|
+
lastPersist = 0;
|
|
1738
|
+
constructor(options) {
|
|
1739
|
+
this.persistencePath = options?.persistencePath || DATA_FILE;
|
|
1740
|
+
this.loadFromDisk();
|
|
1741
|
+
}
|
|
1742
|
+
loadFromDisk() {
|
|
1743
|
+
try {
|
|
1744
|
+
if (import_fs.default.existsSync(this.persistencePath)) {
|
|
1745
|
+
const data = JSON.parse(import_fs.default.readFileSync(this.persistencePath, "utf-8"));
|
|
1746
|
+
if (Array.isArray(data.patterns)) {
|
|
1747
|
+
for (const p of data.patterns) {
|
|
1748
|
+
this.patterns.set(p.type, p);
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
if (Array.isArray(data.operations)) {
|
|
1752
|
+
this.operations = data.operations.slice(-100);
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
} catch {
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
persistToDisk() {
|
|
1759
|
+
const now = Date.now();
|
|
1760
|
+
if (now - this.lastPersist < 5e3) return;
|
|
1761
|
+
this.lastPersist = now;
|
|
1762
|
+
try {
|
|
1763
|
+
const dir = import_path5.default.dirname(this.persistencePath);
|
|
1764
|
+
if (!import_fs.default.existsSync(dir)) import_fs.default.mkdirSync(dir, { recursive: true });
|
|
1765
|
+
import_fs.default.writeFileSync(this.persistencePath, JSON.stringify({
|
|
1766
|
+
patterns: Array.from(this.patterns.values()),
|
|
1767
|
+
operations: this.operations.slice(-100)
|
|
1768
|
+
}, null, 2));
|
|
1769
|
+
} catch {
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1733
1772
|
record(operation) {
|
|
1734
1773
|
this.operations.push(operation);
|
|
1774
|
+
if (this.operations.length > 100) this.operations.shift();
|
|
1735
1775
|
if (operation.success) {
|
|
1736
1776
|
this.updatePatterns(operation);
|
|
1737
1777
|
}
|
|
1778
|
+
this.persistToDisk();
|
|
1738
1779
|
}
|
|
1739
1780
|
getPatterns() {
|
|
1740
1781
|
return Array.from(this.patterns.values());
|
|
@@ -1761,8 +1802,43 @@ var PatternMiner = class {
|
|
|
1761
1802
|
};
|
|
1762
1803
|
|
|
1763
1804
|
// src/learn/failure-learner.ts
|
|
1805
|
+
var import_fs2 = __toESM(require("fs"));
|
|
1806
|
+
var import_path6 = __toESM(require("path"));
|
|
1807
|
+
var DATA_FILE2 = import_path6.default.join(process.env.HOME || "~", ".make-laten", "failures.json");
|
|
1764
1808
|
var FailureLearner = class {
|
|
1765
1809
|
failures = /* @__PURE__ */ new Map();
|
|
1810
|
+
persistencePath;
|
|
1811
|
+
lastPersist = 0;
|
|
1812
|
+
constructor(options) {
|
|
1813
|
+
this.persistencePath = options?.persistencePath || DATA_FILE2;
|
|
1814
|
+
this.loadFromDisk();
|
|
1815
|
+
}
|
|
1816
|
+
loadFromDisk() {
|
|
1817
|
+
try {
|
|
1818
|
+
if (import_fs2.default.existsSync(this.persistencePath)) {
|
|
1819
|
+
const data = JSON.parse(import_fs2.default.readFileSync(this.persistencePath, "utf-8"));
|
|
1820
|
+
if (Array.isArray(data.failures)) {
|
|
1821
|
+
for (const f of data.failures) {
|
|
1822
|
+
this.failures.set(`${f.type}:${f.error}`, f);
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
} catch {
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
persistToDisk() {
|
|
1830
|
+
const now = Date.now();
|
|
1831
|
+
if (now - this.lastPersist < 5e3) return;
|
|
1832
|
+
this.lastPersist = now;
|
|
1833
|
+
try {
|
|
1834
|
+
const dir = import_path6.default.dirname(this.persistencePath);
|
|
1835
|
+
if (!import_fs2.default.existsSync(dir)) import_fs2.default.mkdirSync(dir, { recursive: true });
|
|
1836
|
+
import_fs2.default.writeFileSync(this.persistencePath, JSON.stringify({
|
|
1837
|
+
failures: Array.from(this.failures.values())
|
|
1838
|
+
}, null, 2));
|
|
1839
|
+
} catch {
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1766
1842
|
record(failure) {
|
|
1767
1843
|
const key = `${failure.type}:${failure.error}`;
|
|
1768
1844
|
const existing = this.failures.get(key);
|
|
@@ -1776,6 +1852,7 @@ var FailureLearner = class {
|
|
|
1776
1852
|
count: 1
|
|
1777
1853
|
});
|
|
1778
1854
|
}
|
|
1855
|
+
this.persistToDisk();
|
|
1779
1856
|
}
|
|
1780
1857
|
getFailures() {
|
|
1781
1858
|
return Array.from(this.failures.values());
|
|
@@ -1822,32 +1899,95 @@ function createLearner() {
|
|
|
1822
1899
|
}
|
|
1823
1900
|
|
|
1824
1901
|
// src/correct/auto-correct.ts
|
|
1902
|
+
var import_fs3 = __toESM(require("fs"));
|
|
1903
|
+
var import_path7 = __toESM(require("path"));
|
|
1904
|
+
var DEFAULT_RULES = [
|
|
1905
|
+
// Common typos
|
|
1906
|
+
{ name: "typo-teh", description: "Common typo", pattern: "teh", replacement: "the" },
|
|
1907
|
+
{ name: "typo-adn", description: "Common typo", pattern: "adn", replacement: "and" },
|
|
1908
|
+
{ name: "typo-fo", description: "Common typo", pattern: " fo ", replacement: " of " },
|
|
1909
|
+
{ name: "typo-ot", description: "Common typo", pattern: " ot ", replacement: " to " },
|
|
1910
|
+
{ name: "typo-isnt", description: "Common typo", pattern: "isnt", replacement: "isn't" },
|
|
1911
|
+
{ name: "typo-dont", description: "Common typo", pattern: "dont", replacement: "don't" },
|
|
1912
|
+
{ name: "typo-cant", description: "Common typo", pattern: "cant", replacement: "can't" },
|
|
1913
|
+
{ name: "typo-wont", description: "Common typo", pattern: "wont", replacement: "won't" },
|
|
1914
|
+
{ name: "typo-youre", description: "Common typo", pattern: "youre", replacement: "you're" },
|
|
1915
|
+
{ name: "typo-its", description: "Common typo", pattern: "its a", replacement: "it's a" },
|
|
1916
|
+
// Code patterns
|
|
1917
|
+
{ name: "code-console-log", description: "Remove console.log", pattern: /console\.log\([^)]*\);?\n?/g, replacement: "" },
|
|
1918
|
+
{ name: "code-debugger", description: "Remove debugger", pattern: /debugger;?\n?/g, replacement: "" },
|
|
1919
|
+
{ name: "code-var-let", description: "var to let", pattern: /\bvar\b/g, replacement: "let" },
|
|
1920
|
+
// Markdown
|
|
1921
|
+
{ name: "md-double-space", description: "Double space to single", pattern: " ", replacement: " " }
|
|
1922
|
+
];
|
|
1923
|
+
var DATA_FILE3 = import_path7.default.join(process.env.HOME || "~", ".make-laten", "corrections.json");
|
|
1825
1924
|
var AutoCorrect = class {
|
|
1826
|
-
rules
|
|
1925
|
+
rules;
|
|
1827
1926
|
corrections = [];
|
|
1828
1927
|
appliedCount = 0;
|
|
1928
|
+
persistencePath;
|
|
1929
|
+
constructor(options) {
|
|
1930
|
+
this.persistencePath = options?.persistencePath || DATA_FILE3;
|
|
1931
|
+
this.rules = [...DEFAULT_RULES];
|
|
1932
|
+
this.loadPersistedRules();
|
|
1933
|
+
}
|
|
1934
|
+
loadPersistedRules() {
|
|
1935
|
+
try {
|
|
1936
|
+
if (import_fs3.default.existsSync(this.persistencePath)) {
|
|
1937
|
+
const data = JSON.parse(import_fs3.default.readFileSync(this.persistencePath, "utf-8"));
|
|
1938
|
+
if (Array.isArray(data.customRules)) {
|
|
1939
|
+
this.rules.push(...data.customRules);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
} catch {
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
persistRules() {
|
|
1946
|
+
try {
|
|
1947
|
+
const dir = import_path7.default.dirname(this.persistencePath);
|
|
1948
|
+
if (!import_fs3.default.existsSync(dir)) import_fs3.default.mkdirSync(dir, { recursive: true });
|
|
1949
|
+
const existing = this.loadExistingData();
|
|
1950
|
+
existing.customRules = this.rules.filter((r) => !DEFAULT_RULES.includes(r));
|
|
1951
|
+
import_fs3.default.writeFileSync(this.persistencePath, JSON.stringify(existing, null, 2));
|
|
1952
|
+
} catch {
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
loadExistingData() {
|
|
1956
|
+
try {
|
|
1957
|
+
if (import_fs3.default.existsSync(this.persistencePath)) {
|
|
1958
|
+
return JSON.parse(import_fs3.default.readFileSync(this.persistencePath, "utf-8"));
|
|
1959
|
+
}
|
|
1960
|
+
} catch {
|
|
1961
|
+
}
|
|
1962
|
+
return { customRules: [] };
|
|
1963
|
+
}
|
|
1829
1964
|
addRule(rule) {
|
|
1830
1965
|
this.rules.push(rule);
|
|
1966
|
+
this.persistRules();
|
|
1831
1967
|
}
|
|
1832
1968
|
getRules() {
|
|
1833
1969
|
return this.rules;
|
|
1834
1970
|
}
|
|
1835
1971
|
correct(input) {
|
|
1836
1972
|
let output = input;
|
|
1973
|
+
let changed = false;
|
|
1837
1974
|
for (const rule of this.rules) {
|
|
1838
1975
|
if (typeof rule.pattern === "string") {
|
|
1839
1976
|
if (output.includes(rule.pattern)) {
|
|
1840
1977
|
output = output.split(rule.pattern).join(rule.replacement);
|
|
1841
|
-
|
|
1978
|
+
changed = true;
|
|
1842
1979
|
}
|
|
1843
1980
|
} else {
|
|
1844
1981
|
const matches = output.match(rule.pattern);
|
|
1845
1982
|
if (matches) {
|
|
1846
1983
|
output = output.replace(rule.pattern, rule.replacement);
|
|
1847
|
-
|
|
1984
|
+
changed = true;
|
|
1848
1985
|
}
|
|
1849
1986
|
}
|
|
1850
1987
|
}
|
|
1988
|
+
if (changed) {
|
|
1989
|
+
this.recordCorrection(input, output, "auto");
|
|
1990
|
+
}
|
|
1851
1991
|
return output;
|
|
1852
1992
|
}
|
|
1853
1993
|
getStats() {
|