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.
@@ -1764,14 +1764,55 @@ var StrategyRouter = class {
1764
1764
  };
1765
1765
 
1766
1766
  // src/learn/pattern-miner.ts
1767
+ import fs4 from "fs";
1768
+ import path3 from "path";
1769
+ var DATA_FILE = path3.join(process.env.HOME || "~", ".make-laten", "patterns.json");
1767
1770
  var PatternMiner = class {
1768
1771
  operations = [];
1769
1772
  patterns = /* @__PURE__ */ new Map();
1773
+ persistencePath;
1774
+ lastPersist = 0;
1775
+ constructor(options) {
1776
+ this.persistencePath = options?.persistencePath || DATA_FILE;
1777
+ this.loadFromDisk();
1778
+ }
1779
+ loadFromDisk() {
1780
+ try {
1781
+ if (fs4.existsSync(this.persistencePath)) {
1782
+ const data = JSON.parse(fs4.readFileSync(this.persistencePath, "utf-8"));
1783
+ if (Array.isArray(data.patterns)) {
1784
+ for (const p of data.patterns) {
1785
+ this.patterns.set(p.type, p);
1786
+ }
1787
+ }
1788
+ if (Array.isArray(data.operations)) {
1789
+ this.operations = data.operations.slice(-100);
1790
+ }
1791
+ }
1792
+ } catch {
1793
+ }
1794
+ }
1795
+ persistToDisk() {
1796
+ const now = Date.now();
1797
+ if (now - this.lastPersist < 5e3) return;
1798
+ this.lastPersist = now;
1799
+ try {
1800
+ const dir = path3.dirname(this.persistencePath);
1801
+ if (!fs4.existsSync(dir)) fs4.mkdirSync(dir, { recursive: true });
1802
+ fs4.writeFileSync(this.persistencePath, JSON.stringify({
1803
+ patterns: Array.from(this.patterns.values()),
1804
+ operations: this.operations.slice(-100)
1805
+ }, null, 2));
1806
+ } catch {
1807
+ }
1808
+ }
1770
1809
  record(operation) {
1771
1810
  this.operations.push(operation);
1811
+ if (this.operations.length > 100) this.operations.shift();
1772
1812
  if (operation.success) {
1773
1813
  this.updatePatterns(operation);
1774
1814
  }
1815
+ this.persistToDisk();
1775
1816
  }
1776
1817
  getPatterns() {
1777
1818
  return Array.from(this.patterns.values());
@@ -1798,8 +1839,43 @@ var PatternMiner = class {
1798
1839
  };
1799
1840
 
1800
1841
  // src/learn/failure-learner.ts
1842
+ import fs5 from "fs";
1843
+ import path4 from "path";
1844
+ var DATA_FILE2 = path4.join(process.env.HOME || "~", ".make-laten", "failures.json");
1801
1845
  var FailureLearner = class {
1802
1846
  failures = /* @__PURE__ */ new Map();
1847
+ persistencePath;
1848
+ lastPersist = 0;
1849
+ constructor(options) {
1850
+ this.persistencePath = options?.persistencePath || DATA_FILE2;
1851
+ this.loadFromDisk();
1852
+ }
1853
+ loadFromDisk() {
1854
+ try {
1855
+ if (fs5.existsSync(this.persistencePath)) {
1856
+ const data = JSON.parse(fs5.readFileSync(this.persistencePath, "utf-8"));
1857
+ if (Array.isArray(data.failures)) {
1858
+ for (const f of data.failures) {
1859
+ this.failures.set(`${f.type}:${f.error}`, f);
1860
+ }
1861
+ }
1862
+ }
1863
+ } catch {
1864
+ }
1865
+ }
1866
+ persistToDisk() {
1867
+ const now = Date.now();
1868
+ if (now - this.lastPersist < 5e3) return;
1869
+ this.lastPersist = now;
1870
+ try {
1871
+ const dir = path4.dirname(this.persistencePath);
1872
+ if (!fs5.existsSync(dir)) fs5.mkdirSync(dir, { recursive: true });
1873
+ fs5.writeFileSync(this.persistencePath, JSON.stringify({
1874
+ failures: Array.from(this.failures.values())
1875
+ }, null, 2));
1876
+ } catch {
1877
+ }
1878
+ }
1803
1879
  record(failure) {
1804
1880
  const key = `${failure.type}:${failure.error}`;
1805
1881
  const existing = this.failures.get(key);
@@ -1813,6 +1889,7 @@ var FailureLearner = class {
1813
1889
  count: 1
1814
1890
  });
1815
1891
  }
1892
+ this.persistToDisk();
1816
1893
  }
1817
1894
  getFailures() {
1818
1895
  return Array.from(this.failures.values());
@@ -1839,32 +1916,95 @@ var FailureLearner = class {
1839
1916
  };
1840
1917
 
1841
1918
  // src/correct/auto-correct.ts
1919
+ import fs6 from "fs";
1920
+ import path5 from "path";
1921
+ var DEFAULT_RULES = [
1922
+ // Common typos
1923
+ { name: "typo-teh", description: "Common typo", pattern: "teh", replacement: "the" },
1924
+ { name: "typo-adn", description: "Common typo", pattern: "adn", replacement: "and" },
1925
+ { name: "typo-fo", description: "Common typo", pattern: " fo ", replacement: " of " },
1926
+ { name: "typo-ot", description: "Common typo", pattern: " ot ", replacement: " to " },
1927
+ { name: "typo-isnt", description: "Common typo", pattern: "isnt", replacement: "isn't" },
1928
+ { name: "typo-dont", description: "Common typo", pattern: "dont", replacement: "don't" },
1929
+ { name: "typo-cant", description: "Common typo", pattern: "cant", replacement: "can't" },
1930
+ { name: "typo-wont", description: "Common typo", pattern: "wont", replacement: "won't" },
1931
+ { name: "typo-youre", description: "Common typo", pattern: "youre", replacement: "you're" },
1932
+ { name: "typo-its", description: "Common typo", pattern: "its a", replacement: "it's a" },
1933
+ // Code patterns
1934
+ { name: "code-console-log", description: "Remove console.log", pattern: /console\.log\([^)]*\);?\n?/g, replacement: "" },
1935
+ { name: "code-debugger", description: "Remove debugger", pattern: /debugger;?\n?/g, replacement: "" },
1936
+ { name: "code-var-let", description: "var to let", pattern: /\bvar\b/g, replacement: "let" },
1937
+ // Markdown
1938
+ { name: "md-double-space", description: "Double space to single", pattern: " ", replacement: " " }
1939
+ ];
1940
+ var DATA_FILE3 = path5.join(process.env.HOME || "~", ".make-laten", "corrections.json");
1842
1941
  var AutoCorrect = class {
1843
- rules = [];
1942
+ rules;
1844
1943
  corrections = [];
1845
1944
  appliedCount = 0;
1945
+ persistencePath;
1946
+ constructor(options) {
1947
+ this.persistencePath = options?.persistencePath || DATA_FILE3;
1948
+ this.rules = [...DEFAULT_RULES];
1949
+ this.loadPersistedRules();
1950
+ }
1951
+ loadPersistedRules() {
1952
+ try {
1953
+ if (fs6.existsSync(this.persistencePath)) {
1954
+ const data = JSON.parse(fs6.readFileSync(this.persistencePath, "utf-8"));
1955
+ if (Array.isArray(data.customRules)) {
1956
+ this.rules.push(...data.customRules);
1957
+ }
1958
+ }
1959
+ } catch {
1960
+ }
1961
+ }
1962
+ persistRules() {
1963
+ try {
1964
+ const dir = path5.dirname(this.persistencePath);
1965
+ if (!fs6.existsSync(dir)) fs6.mkdirSync(dir, { recursive: true });
1966
+ const existing = this.loadExistingData();
1967
+ existing.customRules = this.rules.filter((r) => !DEFAULT_RULES.includes(r));
1968
+ fs6.writeFileSync(this.persistencePath, JSON.stringify(existing, null, 2));
1969
+ } catch {
1970
+ }
1971
+ }
1972
+ loadExistingData() {
1973
+ try {
1974
+ if (fs6.existsSync(this.persistencePath)) {
1975
+ return JSON.parse(fs6.readFileSync(this.persistencePath, "utf-8"));
1976
+ }
1977
+ } catch {
1978
+ }
1979
+ return { customRules: [] };
1980
+ }
1846
1981
  addRule(rule) {
1847
1982
  this.rules.push(rule);
1983
+ this.persistRules();
1848
1984
  }
1849
1985
  getRules() {
1850
1986
  return this.rules;
1851
1987
  }
1852
1988
  correct(input) {
1853
1989
  let output = input;
1990
+ let changed = false;
1854
1991
  for (const rule of this.rules) {
1855
1992
  if (typeof rule.pattern === "string") {
1856
1993
  if (output.includes(rule.pattern)) {
1857
1994
  output = output.split(rule.pattern).join(rule.replacement);
1858
- this.recordCorrection(input, output, rule.name);
1995
+ changed = true;
1859
1996
  }
1860
1997
  } else {
1861
1998
  const matches = output.match(rule.pattern);
1862
1999
  if (matches) {
1863
2000
  output = output.replace(rule.pattern, rule.replacement);
1864
- this.recordCorrection(input, output, rule.name);
2001
+ changed = true;
1865
2002
  }
1866
2003
  }
1867
2004
  }
2005
+ if (changed) {
2006
+ this.recordCorrection(input, output, "auto");
2007
+ }
1868
2008
  return output;
1869
2009
  }
1870
2010
  getStats() {
@@ -1886,8 +2026,8 @@ var AutoCorrect = class {
1886
2026
  };
1887
2027
 
1888
2028
  // src/cli/commands/benchmark.ts
1889
- import fs4 from "fs";
1890
- import path3 from "path";
2029
+ import fs7 from "fs";
2030
+ import path6 from "path";
1891
2031
  import { execSync } from "child_process";
1892
2032
  function countTokens(text) {
1893
2033
  return Math.ceil(text.length / 4);
@@ -1901,27 +2041,27 @@ async function benchmark() {
1901
2041
  const results = [];
1902
2042
  console.log(" Compress Layer");
1903
2043
  console.log(" " + "\u2500".repeat(50));
1904
- const smallFile = path3.join(projectPath, "src/index.ts");
1905
- if (fs4.existsSync(smallFile)) {
1906
- const content = fs4.readFileSync(smallFile, "utf-8");
2044
+ const smallFile = path6.join(projectPath, "src/index.ts");
2045
+ if (fs7.existsSync(smallFile)) {
2046
+ const content = fs7.readFileSync(smallFile, "utf-8");
1907
2047
  const raw = countTokens(content);
1908
2048
  const compressor = new FileReadCompressor();
1909
2049
  const result = await compressor.compress({ content, filePath: "src/index.ts" });
1910
2050
  const compressed = countTokens(result.content);
1911
2051
  results.push({ name: "read (small)", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
1912
2052
  }
1913
- const mediumFile = path3.join(projectPath, "src/mcp/server.ts");
1914
- if (fs4.existsSync(mediumFile)) {
1915
- const content = fs4.readFileSync(mediumFile, "utf-8");
2053
+ const mediumFile = path6.join(projectPath, "src/mcp/server.ts");
2054
+ if (fs7.existsSync(mediumFile)) {
2055
+ const content = fs7.readFileSync(mediumFile, "utf-8");
1916
2056
  const raw = countTokens(content);
1917
2057
  const compressor = new FileReadCompressor();
1918
2058
  const result = await compressor.compress({ content, filePath: "src/mcp/server.ts" });
1919
2059
  const compressed = countTokens(result.content);
1920
2060
  results.push({ name: "read (medium)", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
1921
2061
  }
1922
- const largeFile = path3.join(projectPath, "README.md");
1923
- if (fs4.existsSync(largeFile)) {
1924
- const content = fs4.readFileSync(largeFile, "utf-8");
2062
+ const largeFile = path6.join(projectPath, "README.md");
2063
+ if (fs7.existsSync(largeFile)) {
2064
+ const content = fs7.readFileSync(largeFile, "utf-8");
1925
2065
  const raw = countTokens(content);
1926
2066
  const compressor = new FileReadCompressor();
1927
2067
  const result = await compressor.compress({ content, filePath: "README.md" });