klyro 0.1.59 → 0.1.60

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/repl.js CHANGED
@@ -21,7 +21,7 @@ import { TuiApprovalBridge } from '../tui/approval.js';
21
21
  import { parseUnifiedDiff } from '../tui/diff-parser.js';
22
22
  import { parse } from './slash/parser.js';
23
23
  import { resolveProvider, providerHelp, lastProviderError } from '../providers.js';
24
- import { MouseFilter, MOUSE_ENABLE, MOUSE_DISABLE } from '../tui/mouse.js';
24
+ import { MouseFilter, MOUSE_ENABLE, MOUSE_DISABLE, createReadWrapper } from '../tui/mouse.js';
25
25
  import { inferProviderFromBaseURL } from '../agent/registry.js';
26
26
  import { getDefaultSessionStore } from '../persistence/session.js';
27
27
  import { buildSystemPrompt, parseImageInput } from '../context/system-prompt.js';
@@ -207,25 +207,37 @@ export async function startRepl(opts = {}) {
207
207
  catch { /* ignore */ }
208
208
  };
209
209
  // OpenCode-style wheel scrolling (§8.5, S8): Ink owns stdin and cannot see
210
- // mouse events, so tap stdin.emit — wheel deltas drive the App's scroll
211
- // hooks, everything else passes through to Ink untouched.
210
+ // mouse events, so intercept stdin reads — wheel deltas drive the App's
211
+ // scroll hooks, everything else passes through to Ink untouched.
212
+ //
213
+ // IMPORTANT: Ink 7 reads stdin via 'readable' + stdin.read() (paused mode),
214
+ // never 'data' events — so the tap wraps read(), not emit().
212
215
  const mouseFilter = new MouseFilter();
216
+ const origStdinRead = process.stdin.read.bind(process.stdin);
213
217
  const origStdinEmit = process.stdin.emit.bind(process.stdin);
214
218
  let mouseTapInstalled = false;
219
+ function dispatchWheels(wheels) {
220
+ for (const w of wheels) {
221
+ try {
222
+ if (isMounted && directHooks)
223
+ directHooks.scrollLines(w);
224
+ }
225
+ catch { /* ignore */ }
226
+ }
227
+ }
215
228
  function installMouseTap() {
216
229
  if (!isAltScreen || mouseTapInstalled)
217
230
  return;
218
231
  mouseTapInstalled = true;
219
- process.stdin.emit = (...a) => {
232
+ const stdinAny = process.stdin;
233
+ // Primary path: Ink's paused-mode read loop.
234
+ stdinAny.read = createReadWrapper(origStdinRead, mouseFilter, (d) => dispatchWheels([d]));
235
+ // Fallback path: flowing mode ('data' events), e.g. if any library
236
+ // resumes the stream. Same split, same dispatch.
237
+ stdinAny.emit = (...a) => {
220
238
  if (a[0] === 'data' && Buffer.isBuffer(a[1])) {
221
239
  const split = mouseFilter.push(a[1]);
222
- for (const w of split.wheels) {
223
- try {
224
- if (isMounted && directHooks)
225
- directHooks.scrollLines(w);
226
- }
227
- catch { /* ignore */ }
228
- }
240
+ dispatchWheels(split.wheels);
229
241
  if (split.kept.length === 0)
230
242
  return false;
231
243
  a[1] = split.kept;
@@ -238,7 +250,9 @@ export async function startRepl(opts = {}) {
238
250
  return;
239
251
  mouseTapInstalled = false;
240
252
  mouseFilter.reset();
241
- process.stdin.emit = origStdinEmit;
253
+ const stdinAny = process.stdin;
254
+ stdinAny.read = origStdinRead;
255
+ stdinAny.emit = origStdinEmit;
242
256
  }
243
257
  // Declare app before handler to avoid TDZ; handler added after render
244
258
  let app;
@@ -34,3 +34,13 @@ export declare class MouseFilter {
34
34
  }
35
35
  export declare const MOUSE_ENABLE = "\u001B[?1000h\u001B[?1006h";
36
36
  export declare const MOUSE_DISABLE = "\u001B[?1000l\u001B[?1006l";
37
+ /**
38
+ * stdin.read() wrapper implementing the tap (see repl.ts installMouseTap).
39
+ * Ink 7 consumes stdin via paused-mode read() calls, so filtering happens
40
+ * here — not on 'data' events (which never fire for Ink).
41
+ *
42
+ * Contract: sized reads pass through untouched; null passes through;
43
+ * mouse sequences are swallowed (wheels dispatched); everything else is
44
+ * returned byte-identical in its original string/Buffer shape.
45
+ */
46
+ export declare function createReadWrapper(origRead: (size?: number) => unknown, filter: MouseFilter, onWheel: (delta: number) => void): (size?: number) => unknown;
package/dist/tui/mouse.js CHANGED
@@ -92,3 +92,32 @@ export class MouseFilter {
92
92
  }
93
93
  export const MOUSE_ENABLE = '\x1b[?1000h\x1b[?1006h'; // button events + SGR coords
94
94
  export const MOUSE_DISABLE = '\x1b[?1000l\x1b[?1006l';
95
+ /**
96
+ * stdin.read() wrapper implementing the tap (see repl.ts installMouseTap).
97
+ * Ink 7 consumes stdin via paused-mode read() calls, so filtering happens
98
+ * here — not on 'data' events (which never fire for Ink).
99
+ *
100
+ * Contract: sized reads pass through untouched; null passes through;
101
+ * mouse sequences are swallowed (wheels dispatched); everything else is
102
+ * returned byte-identical in its original string/Buffer shape.
103
+ */
104
+ export function createReadWrapper(origRead, filter, onWheel) {
105
+ return (size) => {
106
+ if (size !== undefined)
107
+ return origRead(size);
108
+ const chunk = origRead();
109
+ if (chunk == null)
110
+ return chunk;
111
+ const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
112
+ const split = filter.push(buf);
113
+ for (const w of split.wheels) {
114
+ try {
115
+ onWheel(w);
116
+ }
117
+ catch { /* ignore */ }
118
+ }
119
+ if (split.kept.length === 0)
120
+ return null;
121
+ return typeof chunk === 'string' ? split.kept.toString('utf8') : split.kept;
122
+ };
123
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "klyro",
3
- "version": "0.1.59",
3
+ "version": "0.1.60",
4
4
  "description": "Klyro \u2014 autonomous coding harness CLI that streams from any OpenAI-compatible or Anthropic LLM endpoint.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",