make-laten 1.2.1 → 1.2.2

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.
@@ -1672,36 +1672,284 @@ var GitStatusCompressor = class {
1672
1672
  }
1673
1673
  };
1674
1674
 
1675
+ // src/route/tool-router.ts
1676
+ var ToolRouter = class {
1677
+ rules = [
1678
+ {
1679
+ matcher: (input) => input.type === "file",
1680
+ compressor: "file-read",
1681
+ confidence: 0.95,
1682
+ reason: "File read detected"
1683
+ },
1684
+ {
1685
+ matcher: (input) => input.type === "grep",
1686
+ compressor: "grep",
1687
+ confidence: 0.95,
1688
+ reason: "Grep results detected"
1689
+ },
1690
+ {
1691
+ matcher: (input) => input.type === "git-diff",
1692
+ compressor: "git-diff",
1693
+ confidence: 0.95,
1694
+ reason: "Git diff detected"
1695
+ }
1696
+ ];
1697
+ route(input) {
1698
+ for (const rule of this.rules) {
1699
+ if (rule.matcher(input)) {
1700
+ return {
1701
+ tool: "compress",
1702
+ compressor: rule.compressor,
1703
+ confidence: rule.confidence,
1704
+ reason: rule.reason
1705
+ };
1706
+ }
1707
+ }
1708
+ return {
1709
+ tool: "compress",
1710
+ confidence: 0.1,
1711
+ reason: "No matching route found"
1712
+ };
1713
+ }
1714
+ addRule(rule) {
1715
+ this.rules.push(rule);
1716
+ }
1717
+ };
1718
+
1719
+ // src/route/strategy-router.ts
1720
+ var StrategyRouter = class {
1721
+ thresholds = {
1722
+ small: 500,
1723
+ large: 5e3
1724
+ };
1725
+ select(context) {
1726
+ if (context.userPreference) {
1727
+ return {
1728
+ strategy: context.userPreference,
1729
+ reason: `User preference: ${context.userPreference}`,
1730
+ savings: this.estimateSavings(context.userPreference)
1731
+ };
1732
+ }
1733
+ const fileSize = context.fileSize || 0;
1734
+ if (fileSize >= this.thresholds.large) {
1735
+ return {
1736
+ strategy: "aggressive",
1737
+ reason: `large file (${fileSize} bytes)`,
1738
+ savings: 0.6
1739
+ };
1740
+ }
1741
+ if (fileSize <= this.thresholds.small) {
1742
+ return {
1743
+ strategy: "conservative",
1744
+ reason: `small file (${fileSize} bytes)`,
1745
+ savings: 0.2
1746
+ };
1747
+ }
1748
+ return {
1749
+ strategy: "balanced",
1750
+ reason: `Medium file (${fileSize} bytes)`,
1751
+ savings: 0.4
1752
+ };
1753
+ }
1754
+ estimateSavings(strategy) {
1755
+ switch (strategy) {
1756
+ case "aggressive":
1757
+ return 0.6;
1758
+ case "balanced":
1759
+ return 0.4;
1760
+ case "conservative":
1761
+ return 0.2;
1762
+ }
1763
+ }
1764
+ };
1765
+
1766
+ // src/learn/pattern-miner.ts
1767
+ var PatternMiner = class {
1768
+ operations = [];
1769
+ patterns = /* @__PURE__ */ new Map();
1770
+ record(operation) {
1771
+ this.operations.push(operation);
1772
+ if (operation.success) {
1773
+ this.updatePatterns(operation);
1774
+ }
1775
+ }
1776
+ getPatterns() {
1777
+ return Array.from(this.patterns.values());
1778
+ }
1779
+ getPatternsByType(type) {
1780
+ return this.getPatterns().filter((p) => p.type === type);
1781
+ }
1782
+ updatePatterns(operation) {
1783
+ const key = operation.type;
1784
+ const existing = this.patterns.get(key);
1785
+ if (existing) {
1786
+ existing.count++;
1787
+ existing.confidence = Math.min(0.99, existing.confidence + 0.05);
1788
+ } else {
1789
+ this.patterns.set(key, {
1790
+ id: `p${this.patterns.size + 1}`,
1791
+ type: operation.type,
1792
+ pattern: JSON.stringify(operation.input),
1793
+ confidence: 0.5,
1794
+ count: 1
1795
+ });
1796
+ }
1797
+ }
1798
+ };
1799
+
1800
+ // src/learn/failure-learner.ts
1801
+ var FailureLearner = class {
1802
+ failures = /* @__PURE__ */ new Map();
1803
+ record(failure) {
1804
+ const key = `${failure.type}:${failure.error}`;
1805
+ const existing = this.failures.get(key);
1806
+ if (existing) {
1807
+ existing.count++;
1808
+ } else {
1809
+ this.failures.set(key, {
1810
+ id: `f${this.failures.size + 1}`,
1811
+ ...failure,
1812
+ timestamp: Date.now(),
1813
+ count: 1
1814
+ });
1815
+ }
1816
+ }
1817
+ getFailures() {
1818
+ return Array.from(this.failures.values());
1819
+ }
1820
+ getFailuresByType(type) {
1821
+ return this.getFailures().filter((f) => f.type === type);
1822
+ }
1823
+ getSuggestions(type) {
1824
+ const failures = Array.from(this.failures.values()).filter((f) => f.type === type);
1825
+ const suggestions = [];
1826
+ for (const failure of failures) {
1827
+ if (failure.error.includes("not found")) {
1828
+ suggestions.push("check if file exists before processing");
1829
+ }
1830
+ if (failure.error.includes("permission")) {
1831
+ suggestions.push("verify file permissions");
1832
+ }
1833
+ if (failure.count > 2) {
1834
+ suggestions.push(`recurring issue: ${failure.error}`);
1835
+ }
1836
+ }
1837
+ return [...new Set(suggestions)];
1838
+ }
1839
+ };
1840
+
1841
+ // src/correct/auto-correct.ts
1842
+ var AutoCorrect = class {
1843
+ rules = [];
1844
+ corrections = [];
1845
+ appliedCount = 0;
1846
+ addRule(rule) {
1847
+ this.rules.push(rule);
1848
+ }
1849
+ getRules() {
1850
+ return this.rules;
1851
+ }
1852
+ correct(input) {
1853
+ let output = input;
1854
+ for (const rule of this.rules) {
1855
+ if (typeof rule.pattern === "string") {
1856
+ if (output.includes(rule.pattern)) {
1857
+ output = output.split(rule.pattern).join(rule.replacement);
1858
+ this.recordCorrection(input, output, rule.name);
1859
+ }
1860
+ } else {
1861
+ const matches = output.match(rule.pattern);
1862
+ if (matches) {
1863
+ output = output.replace(rule.pattern, rule.replacement);
1864
+ this.recordCorrection(input, output, rule.name);
1865
+ }
1866
+ }
1867
+ }
1868
+ return output;
1869
+ }
1870
+ getStats() {
1871
+ return {
1872
+ applied: this.appliedCount,
1873
+ corrections: this.corrections
1874
+ };
1875
+ }
1876
+ recordCorrection(original, corrected, ruleName) {
1877
+ this.appliedCount++;
1878
+ this.corrections.push({
1879
+ id: `c${this.corrections.length + 1}`,
1880
+ original,
1881
+ corrected,
1882
+ rule: ruleName,
1883
+ confidence: 0.9
1884
+ });
1885
+ }
1886
+ };
1887
+
1675
1888
  // src/cli/commands/benchmark.ts
1676
1889
  import fs4 from "fs";
1677
1890
  import path3 from "path";
1678
1891
  import { execSync } from "child_process";
1892
+ function countTokens(text) {
1893
+ return Math.ceil(text.length / 4);
1894
+ }
1679
1895
  async function benchmark() {
1680
- const fileCompressor = new FileReadCompressor();
1681
- const diffCompressor = new GitDiffCompressor();
1682
- const statusCompressor = new GitStatusCompressor();
1683
1896
  const projectPath = process.cwd();
1684
1897
  console.log("");
1685
- console.log(" make-laten benchmark");
1686
- console.log(" ===================");
1898
+ console.log(" make-laten benchmark (17 tools)");
1899
+ console.log(" ================================");
1687
1900
  console.log("");
1688
1901
  const results = [];
1689
- const testFiles = ["src/index.ts", "package.json", "README.md", "src/mcp/server.ts"];
1690
- for (const file of testFiles) {
1691
- const full = path3.join(projectPath, file);
1692
- if (!fs4.existsSync(full)) continue;
1693
- const content = fs4.readFileSync(full, "utf-8");
1694
- const raw = Math.round(content.length / 4);
1695
- const result = await fileCompressor.compress({ content, filePath: file });
1696
- const compressed = Math.round(result.content.length / 4);
1697
- results.push({ name: `read ${file}`, raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
1902
+ console.log(" Compress Layer");
1903
+ 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");
1907
+ const raw = countTokens(content);
1908
+ const compressor = new FileReadCompressor();
1909
+ const result = await compressor.compress({ content, filePath: "src/index.ts" });
1910
+ const compressed = countTokens(result.content);
1911
+ results.push({ name: "read (small)", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
1912
+ }
1913
+ const mediumFile = path3.join(projectPath, "src/mcp/server.ts");
1914
+ if (fs4.existsSync(mediumFile)) {
1915
+ const content = fs4.readFileSync(mediumFile, "utf-8");
1916
+ const raw = countTokens(content);
1917
+ const compressor = new FileReadCompressor();
1918
+ const result = await compressor.compress({ content, filePath: "src/mcp/server.ts" });
1919
+ const compressed = countTokens(result.content);
1920
+ results.push({ name: "read (medium)", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
1921
+ }
1922
+ const largeFile = path3.join(projectPath, "README.md");
1923
+ if (fs4.existsSync(largeFile)) {
1924
+ const content = fs4.readFileSync(largeFile, "utf-8");
1925
+ const raw = countTokens(content);
1926
+ const compressor = new FileReadCompressor();
1927
+ const result = await compressor.compress({ content, filePath: "README.md" });
1928
+ const compressed = countTokens(result.content);
1929
+ results.push({ name: "read (large)", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
1930
+ }
1931
+ try {
1932
+ const grepResult = execSync('grep -rn "export" src/ 2>/dev/null | head -30', { cwd: projectPath, encoding: "utf-8" }).trim();
1933
+ if (grepResult) {
1934
+ const raw = countTokens(grepResult);
1935
+ const matches = grepResult.split("\n").filter(Boolean).map((line) => {
1936
+ const parts = line.split(":");
1937
+ return { file: parts[0], line: parseInt(parts[1], 10) || 0, content: parts.slice(2).join(":").trim() };
1938
+ });
1939
+ const compressor = new GrepCompressor();
1940
+ const result = await compressor.compress({ results: matches, pattern: "export", directory: "src/" });
1941
+ const compressed = countTokens(result.content);
1942
+ results.push({ name: "grep", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
1943
+ }
1944
+ } catch {
1698
1945
  }
1699
1946
  try {
1700
1947
  const diff = execSync('git diff HEAD~1 2>/dev/null || echo ""', { cwd: projectPath, encoding: "utf-8" }).trim();
1701
1948
  if (diff) {
1702
- const raw = Math.round(diff.length / 4);
1703
- const result = await diffCompressor.compress({ diff });
1704
- const compressed = Math.round(result.content.length / 4);
1949
+ const raw = countTokens(diff);
1950
+ const compressor = new GitDiffCompressor();
1951
+ const result = await compressor.compress({ diff });
1952
+ const compressed = countTokens(result.content);
1705
1953
  results.push({ name: "git-diff", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
1706
1954
  }
1707
1955
  } catch {
@@ -1709,23 +1957,108 @@ async function benchmark() {
1709
1957
  try {
1710
1958
  const status = execSync('git status --porcelain 2>/dev/null || echo ""', { cwd: projectPath, encoding: "utf-8" }).trim();
1711
1959
  if (status) {
1712
- const raw = Math.round(status.length / 4);
1713
- const result = await statusCompressor.compress({ status });
1714
- const compressed = Math.round(result.content.length / 4);
1960
+ const raw = countTokens(status);
1961
+ const compressor = new GitStatusCompressor();
1962
+ const result = await compressor.compress({ status });
1963
+ const compressed = countTokens(result.content);
1715
1964
  results.push({ name: "git-status", raw, compressed, savings: Math.round((1 - compressed / raw) * 100) });
1716
1965
  }
1717
1966
  } catch {
1718
1967
  }
1719
- console.log(" Command".padEnd(28) + "Raw".padEnd(10) + "Compressed".padEnd(12) + "Savings");
1720
- console.log(" " + "\u2500".repeat(60));
1721
- for (const r of results) {
1722
- console.log(` ${r.name}`.padEnd(28) + `${r.raw}`.padEnd(10) + `${r.compressed}`.padEnd(12) + `${r.savings}%`);
1968
+ console.log("");
1969
+ console.log(" Route Layer");
1970
+ console.log(" " + "\u2500".repeat(50));
1971
+ const router = new ToolRouter();
1972
+ const strategyRouter = new StrategyRouter();
1973
+ const routeTests = [
1974
+ { type: "file", content: "test" },
1975
+ { type: "grep", content: "test" },
1976
+ { type: "git-diff", content: "test" }
1977
+ ];
1978
+ for (const test of routeTests) {
1979
+ const route = router.route(test);
1980
+ console.log(` route(${test.type}) \u2192 ${route.compressor || "none"} (${Math.round(route.confidence * 100)}%)`);
1981
+ }
1982
+ const strategies = [
1983
+ { fileSize: 100, pref: void 0 },
1984
+ { fileSize: 1e3, pref: void 0 },
1985
+ { fileSize: 1e4, pref: void 0 },
1986
+ { fileSize: 0, pref: "aggressive" }
1987
+ ];
1988
+ for (const s of strategies) {
1989
+ const strategy = strategyRouter.select({ fileSize: s.fileSize, userPreference: s.pref });
1990
+ console.log(` strategy(${s.fileSize || s.pref}) \u2192 ${strategy.strategy} (savings: ${Math.round(strategy.savings * 100)}%)`);
1991
+ }
1992
+ console.log("");
1993
+ console.log(" Cache Layer");
1994
+ console.log(" " + "\u2500".repeat(50));
1995
+ const cache = new SessionCache();
1996
+ cache.set("test:key1", { content: "value1", metadata: {} });
1997
+ cache.set("test:key2", { content: "value2", metadata: {} });
1998
+ cache.get("test:key1");
1999
+ cache.get("test:key1");
2000
+ cache.get("test:key2");
2001
+ cache.get("test:miss");
2002
+ const cacheStats = cache.stats();
2003
+ console.log(` L1 Session: ${cacheStats.size} entries, ${cacheStats.hits} hits, ${cacheStats.misses} misses, ${Math.round(cacheStats.hitRate * 100)}% hit rate`);
2004
+ console.log("");
2005
+ console.log(" Learn Layer");
2006
+ console.log(" " + "\u2500".repeat(50));
2007
+ const miner = new PatternMiner();
2008
+ miner.record({ type: "file-read", input: { file: "a.ts" }, success: true });
2009
+ miner.record({ type: "file-read", input: { file: "b.ts" }, success: true });
2010
+ miner.record({ type: "grep", input: { pattern: "test" }, success: true });
2011
+ miner.record({ type: "git-diff", input: {}, success: true });
2012
+ const learner = new FailureLearner();
2013
+ learner.record({ type: "file-read", error: "File not found", success: false });
2014
+ learner.record({ type: "grep", error: "Permission denied", success: false });
2015
+ const patterns = miner.getPatterns();
2016
+ const failures = learner.getFailures();
2017
+ console.log(` Patterns: ${patterns.length} learned`);
2018
+ for (const p of patterns.slice(0, 3)) {
2019
+ console.log(` - ${p.type}: confidence ${Math.round(p.confidence * 100)}%, count ${p.count}`);
2020
+ }
2021
+ console.log(` Failures: ${failures.length} recorded`);
2022
+ for (const f of failures.slice(0, 3)) {
2023
+ const suggestions = learner.getSuggestions(f.type);
2024
+ console.log(` - ${f.type}: ${f.error} \u2192 ${suggestions[0] || "none"}`);
1723
2025
  }
2026
+ console.log("");
2027
+ console.log(" Correct Layer");
2028
+ console.log(" " + "\u2500".repeat(50));
2029
+ const correct = new AutoCorrect();
2030
+ correct.addRule({ name: "typo", description: "Fix common typo", pattern: "teh", replacement: "the" });
2031
+ correct.addRule({ name: "typo2", description: "Fix common typo", pattern: "adn", replacement: "and" });
2032
+ const testText = "teh quick brown fox adn teh cat";
2033
+ const corrected = correct.correct(testText);
2034
+ const correctStats = correct.getStats();
2035
+ console.log(` Input: "${testText}"`);
2036
+ console.log(` Output: "${corrected}"`);
2037
+ console.log(` Corrections applied: ${correctStats.applied}`);
2038
+ console.log("");
2039
+ console.log(" Web Layer");
2040
+ console.log(" " + "\u2500".repeat(50));
2041
+ const webRouter = new WebRouter();
2042
+ const webStats = webRouter.getCacheStats();
2043
+ console.log(` Cache: ${webStats.fetchSize} fetch, ${webStats.searchSize} search`);
2044
+ console.log(` Backends: duckduckgo (default)`);
2045
+ console.log(` Features: semantic extraction, compression, caching`);
2046
+ console.log("");
2047
+ console.log(" Summary");
2048
+ console.log(" " + "\u2500".repeat(50));
1724
2049
  const totalRaw = results.reduce((s, r) => s + r.raw, 0);
1725
2050
  const totalCompressed = results.reduce((s, r) => s + r.compressed, 0);
1726
2051
  const savings = Math.round((1 - totalCompressed / totalRaw) * 100);
2052
+ console.log(" Command".padEnd(20) + "Raw".padEnd(10) + "Compressed".padEnd(12) + "Savings");
2053
+ console.log(" " + "\u2500".repeat(50));
2054
+ for (const r of results) {
2055
+ console.log(` ${r.name}`.padEnd(20) + `${r.raw}`.padEnd(10) + `${r.compressed}`.padEnd(12) + `${r.savings}%`);
2056
+ }
2057
+ console.log(" " + "\u2500".repeat(50));
2058
+ console.log(` ${"Total".padEnd(20)}${totalRaw}`.padEnd(10) + `${totalCompressed}`.padEnd(12) + `${savings}%`);
1727
2059
  console.log("");
1728
- console.log(` Total: ${totalRaw} \u2192 ${totalCompressed} tokens (${savings}% saved)`);
2060
+ console.log(` 17 tools exposed via MCP`);
2061
+ console.log(` 4 layers: compress, route, cache, learn`);
1729
2062
  console.log("");
1730
2063
  }
1731
2064
  benchmark();