codemaxxing 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/dist/index.js +65 -60
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1745,93 +1745,98 @@ const pasteEvents = new EventEmitter();
1745
1745
  // Enable bracketed paste mode — terminal wraps pastes in escape sequences
1746
1746
  process.stdout.write("\x1b[?2004h");
1747
1747
  // Intercept stdin to handle pasted content
1748
- // Bracketed paste: \x1b[200~ ... \x1b[201~
1749
- let pasteBuffer = "";
1750
- let inPaste = false;
1751
- let rawBurstBuffer = "";
1752
- let rawBurstTimer = null;
1753
- const RAW_PASTE_WINDOW_MS = 35;
1754
- function emitPasteChunk(content) {
1748
+ // Strategy: patch emit('data') instead of push() — this is the ONE path all data
1749
+ // must travel through to reach Ink's listeners, regardless of how the TTY/stream
1750
+ // delivers it internally.
1751
+ //
1752
+ // Two detection layers:
1753
+ // 1. Bracketed paste escape sequences (\x1b[200~ ... \x1b[201~)
1754
+ // 2. Burst buffering — accumulate rapid-fire chunks over a short window and check
1755
+ // whether the combined content looks like a multiline paste.
1756
+ let bracketedBuffer = "";
1757
+ let inBracketedPaste = false;
1758
+ let burstBuffer = "";
1759
+ let burstTimer = null;
1760
+ const BURST_WINDOW_MS = 25; // Short enough to feel instant, long enough to catch paste bursts
1761
+ const origEmit = process.stdin.emit.bind(process.stdin);
1762
+ function handlePasteContent(content) {
1755
1763
  const normalized = content.replace(/\r\n/g, "\n").trim();
1756
1764
  if (!normalized)
1757
- return true;
1765
+ return;
1758
1766
  const lineCount = normalized.split("\n").length;
1759
1767
  if (lineCount > 2) {
1768
+ // Real multiline paste → badge it
1760
1769
  pasteEvents.emit("paste", { content: normalized, lines: lineCount });
1761
- return true;
1770
+ return;
1762
1771
  }
1772
+ // Short paste (1-2 lines) → collapse to single line and forward as normal input
1763
1773
  const sanitized = normalized.replace(/\n/g, " ");
1764
1774
  if (sanitized) {
1765
- origPush(sanitized, "utf-8");
1775
+ origEmit("data", sanitized);
1766
1776
  }
1767
- return true;
1768
1777
  }
1769
- function looksLikeRawMultilinePaste(data) {
1770
- const normalized = data.replace(/\x1b\[20[01]~/g, "");
1771
- const newlineMatches = normalized.match(/\r?\n/g) ?? [];
1772
- const newlineCount = newlineMatches.length;
1773
- const contentLength = normalized.replace(/[\r\n]/g, "").trim().length;
1774
- // Catch real multiline pastes while avoiding normal Enter presses.
1775
- return newlineCount >= 2 || (newlineCount >= 1 && contentLength >= 40);
1778
+ function looksLikeMultilinePaste(data) {
1779
+ const clean = data.replace(/\x1b\[[0-9;]*[A-Za-z]/g, ""); // Strip all ANSI escapes
1780
+ const newlines = (clean.match(/\r?\n/g) ?? []).length;
1781
+ const printable = clean.replace(/[\r\n]/g, "").trim().length;
1782
+ return newlines >= 2 || (newlines >= 1 && printable >= 40);
1776
1783
  }
1777
- function flushRawBurstBuffer() {
1778
- if (!rawBurstBuffer)
1779
- return;
1780
- const buffered = rawBurstBuffer;
1781
- rawBurstBuffer = "";
1782
- if (looksLikeRawMultilinePaste(buffered)) {
1783
- emitPasteChunk(buffered);
1784
+ function flushBurst() {
1785
+ if (!burstBuffer)
1784
1786
  return;
1787
+ const buffered = burstBuffer;
1788
+ burstBuffer = "";
1789
+ if (looksLikeMultilinePaste(buffered)) {
1790
+ handlePasteContent(buffered);
1791
+ }
1792
+ else {
1793
+ // Normal typing — forward to Ink
1794
+ origEmit("data", buffered);
1785
1795
  }
1786
- origPush(Buffer.from(buffered), undefined);
1787
- }
1788
- function scheduleRawBurstFlush() {
1789
- if (rawBurstTimer)
1790
- clearTimeout(rawBurstTimer);
1791
- rawBurstTimer = setTimeout(() => {
1792
- rawBurstTimer = null;
1793
- flushRawBurstBuffer();
1794
- }, RAW_PASTE_WINDOW_MS);
1795
1796
  }
1796
- const origPush = process.stdin.push.bind(process.stdin);
1797
- process.stdin.push = function (chunk, encoding) {
1798
- if (chunk === null) {
1799
- if (rawBurstTimer) {
1800
- clearTimeout(rawBurstTimer);
1801
- rawBurstTimer = null;
1802
- }
1803
- flushRawBurstBuffer();
1804
- return origPush(chunk, encoding);
1797
+ process.stdin.emit = function (event, ...args) {
1798
+ // Pass through non-data events untouched
1799
+ if (event !== "data") {
1800
+ return origEmit(event, ...args);
1805
1801
  }
1802
+ const chunk = args[0];
1806
1803
  let data = typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString("utf-8") : String(chunk);
1804
+ // ── Bracketed paste handling ──
1807
1805
  const hasStart = data.includes("\x1b[200~");
1808
1806
  const hasEnd = data.includes("\x1b[201~");
1809
- if (hasStart || hasEnd || inPaste) {
1810
- if (rawBurstTimer) {
1811
- clearTimeout(rawBurstTimer);
1812
- rawBurstTimer = null;
1813
- }
1814
- flushRawBurstBuffer();
1815
- }
1816
1807
  if (hasStart) {
1817
- inPaste = true;
1808
+ // Flush any pending burst before entering bracketed mode
1809
+ if (burstTimer) {
1810
+ clearTimeout(burstTimer);
1811
+ burstTimer = null;
1812
+ }
1813
+ flushBurst();
1814
+ inBracketedPaste = true;
1818
1815
  data = data.replace(/\x1b\[200~/g, "");
1819
1816
  }
1820
1817
  if (hasEnd) {
1821
1818
  data = data.replace(/\x1b\[201~/g, "");
1822
- pasteBuffer += data;
1823
- inPaste = false;
1824
- const content = pasteBuffer;
1825
- pasteBuffer = "";
1826
- return emitPasteChunk(content);
1819
+ bracketedBuffer += data;
1820
+ inBracketedPaste = false;
1821
+ const content = bracketedBuffer;
1822
+ bracketedBuffer = "";
1823
+ handlePasteContent(content);
1824
+ return true;
1827
1825
  }
1828
- if (inPaste) {
1829
- pasteBuffer += data;
1826
+ if (inBracketedPaste) {
1827
+ bracketedBuffer += data;
1830
1828
  return true;
1831
1829
  }
1830
+ // ── Burst buffering for non-bracketed paste ──
1831
+ // Strip stray bracketed paste markers that might appear outside a proper pair
1832
1832
  data = data.replace(/\x1b\[20[01]~/g, "");
1833
- rawBurstBuffer += data;
1834
- scheduleRawBurstFlush();
1833
+ burstBuffer += data;
1834
+ if (burstTimer)
1835
+ clearTimeout(burstTimer);
1836
+ burstTimer = setTimeout(() => {
1837
+ burstTimer = null;
1838
+ flushBurst();
1839
+ }, BURST_WINDOW_MS);
1835
1840
  return true;
1836
1841
  };
1837
1842
  // Disable bracketed paste on exit
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemaxxing",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Open-source terminal coding agent. Connect any LLM. Max your code.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {