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/index.mjs
CHANGED
|
@@ -1625,14 +1625,55 @@ function createDetector() {
|
|
|
1625
1625
|
}
|
|
1626
1626
|
|
|
1627
1627
|
// src/learn/pattern-miner.ts
|
|
1628
|
+
import fs5 from "fs";
|
|
1629
|
+
import path5 from "path";
|
|
1630
|
+
var DATA_FILE = path5.join(process.env.HOME || "~", ".make-laten", "patterns.json");
|
|
1628
1631
|
var PatternMiner = class {
|
|
1629
1632
|
operations = [];
|
|
1630
1633
|
patterns = /* @__PURE__ */ new Map();
|
|
1634
|
+
persistencePath;
|
|
1635
|
+
lastPersist = 0;
|
|
1636
|
+
constructor(options) {
|
|
1637
|
+
this.persistencePath = options?.persistencePath || DATA_FILE;
|
|
1638
|
+
this.loadFromDisk();
|
|
1639
|
+
}
|
|
1640
|
+
loadFromDisk() {
|
|
1641
|
+
try {
|
|
1642
|
+
if (fs5.existsSync(this.persistencePath)) {
|
|
1643
|
+
const data = JSON.parse(fs5.readFileSync(this.persistencePath, "utf-8"));
|
|
1644
|
+
if (Array.isArray(data.patterns)) {
|
|
1645
|
+
for (const p of data.patterns) {
|
|
1646
|
+
this.patterns.set(p.type, p);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
if (Array.isArray(data.operations)) {
|
|
1650
|
+
this.operations = data.operations.slice(-100);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
} catch {
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
persistToDisk() {
|
|
1657
|
+
const now = Date.now();
|
|
1658
|
+
if (now - this.lastPersist < 5e3) return;
|
|
1659
|
+
this.lastPersist = now;
|
|
1660
|
+
try {
|
|
1661
|
+
const dir = path5.dirname(this.persistencePath);
|
|
1662
|
+
if (!fs5.existsSync(dir)) fs5.mkdirSync(dir, { recursive: true });
|
|
1663
|
+
fs5.writeFileSync(this.persistencePath, JSON.stringify({
|
|
1664
|
+
patterns: Array.from(this.patterns.values()),
|
|
1665
|
+
operations: this.operations.slice(-100)
|
|
1666
|
+
}, null, 2));
|
|
1667
|
+
} catch {
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1631
1670
|
record(operation) {
|
|
1632
1671
|
this.operations.push(operation);
|
|
1672
|
+
if (this.operations.length > 100) this.operations.shift();
|
|
1633
1673
|
if (operation.success) {
|
|
1634
1674
|
this.updatePatterns(operation);
|
|
1635
1675
|
}
|
|
1676
|
+
this.persistToDisk();
|
|
1636
1677
|
}
|
|
1637
1678
|
getPatterns() {
|
|
1638
1679
|
return Array.from(this.patterns.values());
|
|
@@ -1659,8 +1700,43 @@ var PatternMiner = class {
|
|
|
1659
1700
|
};
|
|
1660
1701
|
|
|
1661
1702
|
// src/learn/failure-learner.ts
|
|
1703
|
+
import fs6 from "fs";
|
|
1704
|
+
import path6 from "path";
|
|
1705
|
+
var DATA_FILE2 = path6.join(process.env.HOME || "~", ".make-laten", "failures.json");
|
|
1662
1706
|
var FailureLearner = class {
|
|
1663
1707
|
failures = /* @__PURE__ */ new Map();
|
|
1708
|
+
persistencePath;
|
|
1709
|
+
lastPersist = 0;
|
|
1710
|
+
constructor(options) {
|
|
1711
|
+
this.persistencePath = options?.persistencePath || DATA_FILE2;
|
|
1712
|
+
this.loadFromDisk();
|
|
1713
|
+
}
|
|
1714
|
+
loadFromDisk() {
|
|
1715
|
+
try {
|
|
1716
|
+
if (fs6.existsSync(this.persistencePath)) {
|
|
1717
|
+
const data = JSON.parse(fs6.readFileSync(this.persistencePath, "utf-8"));
|
|
1718
|
+
if (Array.isArray(data.failures)) {
|
|
1719
|
+
for (const f of data.failures) {
|
|
1720
|
+
this.failures.set(`${f.type}:${f.error}`, f);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
} catch {
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
persistToDisk() {
|
|
1728
|
+
const now = Date.now();
|
|
1729
|
+
if (now - this.lastPersist < 5e3) return;
|
|
1730
|
+
this.lastPersist = now;
|
|
1731
|
+
try {
|
|
1732
|
+
const dir = path6.dirname(this.persistencePath);
|
|
1733
|
+
if (!fs6.existsSync(dir)) fs6.mkdirSync(dir, { recursive: true });
|
|
1734
|
+
fs6.writeFileSync(this.persistencePath, JSON.stringify({
|
|
1735
|
+
failures: Array.from(this.failures.values())
|
|
1736
|
+
}, null, 2));
|
|
1737
|
+
} catch {
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1664
1740
|
record(failure) {
|
|
1665
1741
|
const key = `${failure.type}:${failure.error}`;
|
|
1666
1742
|
const existing = this.failures.get(key);
|
|
@@ -1674,6 +1750,7 @@ var FailureLearner = class {
|
|
|
1674
1750
|
count: 1
|
|
1675
1751
|
});
|
|
1676
1752
|
}
|
|
1753
|
+
this.persistToDisk();
|
|
1677
1754
|
}
|
|
1678
1755
|
getFailures() {
|
|
1679
1756
|
return Array.from(this.failures.values());
|
|
@@ -1720,32 +1797,95 @@ function createLearner() {
|
|
|
1720
1797
|
}
|
|
1721
1798
|
|
|
1722
1799
|
// src/correct/auto-correct.ts
|
|
1800
|
+
import fs7 from "fs";
|
|
1801
|
+
import path7 from "path";
|
|
1802
|
+
var DEFAULT_RULES = [
|
|
1803
|
+
// Common typos
|
|
1804
|
+
{ name: "typo-teh", description: "Common typo", pattern: "teh", replacement: "the" },
|
|
1805
|
+
{ name: "typo-adn", description: "Common typo", pattern: "adn", replacement: "and" },
|
|
1806
|
+
{ name: "typo-fo", description: "Common typo", pattern: " fo ", replacement: " of " },
|
|
1807
|
+
{ name: "typo-ot", description: "Common typo", pattern: " ot ", replacement: " to " },
|
|
1808
|
+
{ name: "typo-isnt", description: "Common typo", pattern: "isnt", replacement: "isn't" },
|
|
1809
|
+
{ name: "typo-dont", description: "Common typo", pattern: "dont", replacement: "don't" },
|
|
1810
|
+
{ name: "typo-cant", description: "Common typo", pattern: "cant", replacement: "can't" },
|
|
1811
|
+
{ name: "typo-wont", description: "Common typo", pattern: "wont", replacement: "won't" },
|
|
1812
|
+
{ name: "typo-youre", description: "Common typo", pattern: "youre", replacement: "you're" },
|
|
1813
|
+
{ name: "typo-its", description: "Common typo", pattern: "its a", replacement: "it's a" },
|
|
1814
|
+
// Code patterns
|
|
1815
|
+
{ name: "code-console-log", description: "Remove console.log", pattern: /console\.log\([^)]*\);?\n?/g, replacement: "" },
|
|
1816
|
+
{ name: "code-debugger", description: "Remove debugger", pattern: /debugger;?\n?/g, replacement: "" },
|
|
1817
|
+
{ name: "code-var-let", description: "var to let", pattern: /\bvar\b/g, replacement: "let" },
|
|
1818
|
+
// Markdown
|
|
1819
|
+
{ name: "md-double-space", description: "Double space to single", pattern: " ", replacement: " " }
|
|
1820
|
+
];
|
|
1821
|
+
var DATA_FILE3 = path7.join(process.env.HOME || "~", ".make-laten", "corrections.json");
|
|
1723
1822
|
var AutoCorrect = class {
|
|
1724
|
-
rules
|
|
1823
|
+
rules;
|
|
1725
1824
|
corrections = [];
|
|
1726
1825
|
appliedCount = 0;
|
|
1826
|
+
persistencePath;
|
|
1827
|
+
constructor(options) {
|
|
1828
|
+
this.persistencePath = options?.persistencePath || DATA_FILE3;
|
|
1829
|
+
this.rules = [...DEFAULT_RULES];
|
|
1830
|
+
this.loadPersistedRules();
|
|
1831
|
+
}
|
|
1832
|
+
loadPersistedRules() {
|
|
1833
|
+
try {
|
|
1834
|
+
if (fs7.existsSync(this.persistencePath)) {
|
|
1835
|
+
const data = JSON.parse(fs7.readFileSync(this.persistencePath, "utf-8"));
|
|
1836
|
+
if (Array.isArray(data.customRules)) {
|
|
1837
|
+
this.rules.push(...data.customRules);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
} catch {
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
persistRules() {
|
|
1844
|
+
try {
|
|
1845
|
+
const dir = path7.dirname(this.persistencePath);
|
|
1846
|
+
if (!fs7.existsSync(dir)) fs7.mkdirSync(dir, { recursive: true });
|
|
1847
|
+
const existing = this.loadExistingData();
|
|
1848
|
+
existing.customRules = this.rules.filter((r) => !DEFAULT_RULES.includes(r));
|
|
1849
|
+
fs7.writeFileSync(this.persistencePath, JSON.stringify(existing, null, 2));
|
|
1850
|
+
} catch {
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
loadExistingData() {
|
|
1854
|
+
try {
|
|
1855
|
+
if (fs7.existsSync(this.persistencePath)) {
|
|
1856
|
+
return JSON.parse(fs7.readFileSync(this.persistencePath, "utf-8"));
|
|
1857
|
+
}
|
|
1858
|
+
} catch {
|
|
1859
|
+
}
|
|
1860
|
+
return { customRules: [] };
|
|
1861
|
+
}
|
|
1727
1862
|
addRule(rule) {
|
|
1728
1863
|
this.rules.push(rule);
|
|
1864
|
+
this.persistRules();
|
|
1729
1865
|
}
|
|
1730
1866
|
getRules() {
|
|
1731
1867
|
return this.rules;
|
|
1732
1868
|
}
|
|
1733
1869
|
correct(input) {
|
|
1734
1870
|
let output = input;
|
|
1871
|
+
let changed = false;
|
|
1735
1872
|
for (const rule of this.rules) {
|
|
1736
1873
|
if (typeof rule.pattern === "string") {
|
|
1737
1874
|
if (output.includes(rule.pattern)) {
|
|
1738
1875
|
output = output.split(rule.pattern).join(rule.replacement);
|
|
1739
|
-
|
|
1876
|
+
changed = true;
|
|
1740
1877
|
}
|
|
1741
1878
|
} else {
|
|
1742
1879
|
const matches = output.match(rule.pattern);
|
|
1743
1880
|
if (matches) {
|
|
1744
1881
|
output = output.replace(rule.pattern, rule.replacement);
|
|
1745
|
-
|
|
1882
|
+
changed = true;
|
|
1746
1883
|
}
|
|
1747
1884
|
}
|
|
1748
1885
|
}
|
|
1886
|
+
if (changed) {
|
|
1887
|
+
this.recordCorrection(input, output, "auto");
|
|
1888
|
+
}
|
|
1749
1889
|
return output;
|
|
1750
1890
|
}
|
|
1751
1891
|
getStats() {
|