@0perator/operator 0.1.159 → 0.1.161

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/CHANGELOG.md CHANGED
@@ -4,6 +4,23 @@ Operator is AXE's terminal coding agent (npm `@0perator/operator`), running on A
4
4
  Newest first. Every release bumps `src/cli.tsx` VERSION + `package.json`, adds an entry here, and ships to
5
5
  npm + both git remotes (memjar/kode, axetechnologies/kode). Test counts are the full suite at that release.
6
6
 
7
+ ## 0.1.161 — 2026-09-30 — TUI: MouseProvider + hooks (Phase 1 mouse layer mechanism)
8
+ - Builds on the SGR parser: `MouseProvider` (fullscreen-only) enables 1002+1006 tracking, parses stdin,
9
+ dispatches wheel→`useOnWheel` and left-press→hit-tested-region `onClick` (`useClickRegion`), and disables
10
+ on unmount + process `exit` (crash-safety — a stuck tracking mode after a crash is the #1 real mouse bug;
11
+ relies on `exit`, not signal handlers, so Ctrl-C is unchanged). `mouse.ts` gains pure `hitTest`. Inline
12
+ mode = disabled no-op (native scroll+copy preserved). Tested via ink-testing-library with simulated SGR
13
+ stdin. Next: wire into App.tsx fullscreen + click-to-select panels. Suite 732 green (+2).
14
+
15
+ ## 0.1.160 — 2026-09-30 — TUI: SGR mouse parser (Phase 1 foundation) + Aurora speed plan
16
+ - New `src/ui/mouse.ts`: a pure SGR (mode 1006) mouse-sequence parser (`CSI < Cb;Cx;Cy M/m`) decoding
17
+ press/release/drag/move/wheel + shift/alt/ctrl, plus `MOUSE_ON`/`MOUSE_OFF` (mode 1002 button-event +
18
+ 1006, never 1003 any-event). The foundation the `MouseProvider` (next increment) feeds stdin to and
19
+ hit-tests against Ink `measureElement` bounds, fullscreen-only. Pure, 9 tests. Also lands the Aurora
20
+ speed-amplification plan (7-agent research): ngram-mod MoE draft-length fix (n 3/8→24/64, a verified
21
+ live misconfig) + `--backend-sampling` applied to the serve plist; EAGLE3/MTP ruled out (broken for
22
+ qwen35moe / net-loss on Metal). Suite 730 green (+9).
23
+
7
24
  ## 0.1.159 — 2026-09-29 — fix: checkpoint no longer wedges on a stale git index lock
8
25
  - **The recurring "checkpoints don't work" bug, root-caused + fixed.** The 0.1.148 SIGKILL-on-timeout
9
26
  hardening made checkpoints un-hangable — but a `git` killed mid-add/commit leaves `.git/index.lock`
@@ -0,0 +1,81 @@
1
+ // Phase 1 mouse layer — the Ink provider on top of the pure parser (mouse.ts). Enables SGR tracking only
2
+ // in FULLSCREEN (inline keeps the terminal's native scroll + copy), parses stdin via parseMouse, and
3
+ // dispatches: wheel → useOnWheel subscribers (global, no hit-test), left-press → the hit-tested region's
4
+ // onClick (components register their measured bounds). Disables on unmount AND on process 'exit' — a
5
+ // tracking mode left enabled after a crash captures every click until a manual reset (the #1 real mouse
6
+ // bug). We rely on 'exit' (fires after the app's own SIGINT/SIGTERM handlers call process.exit) rather
7
+ // than adding our own signal handlers, so Ctrl-C behaviour is unchanged. Blueprint: _ai-docs/architecture/
8
+ // tui-enterprise-upgrade.md.
9
+ import React, { createContext, useCallback, useContext, useEffect, useRef } from "react";
10
+ import { useStdin } from "ink";
11
+ import { parseMouse, hitTest, MOUSE_ON, MOUSE_OFF } from "./mouse.js";
12
+ const Ctx = createContext({ enabled: false, registerRegion: () => () => { }, onWheel: () => () => { } });
13
+ export function MouseProvider({ enabled, children }) {
14
+ const { stdin, setRawMode, isRawModeSupported } = useStdin();
15
+ const regions = useRef(new Map());
16
+ const wheels = useRef(new Set());
17
+ const registerRegion = useCallback((r, onClick) => {
18
+ regions.current.set(r.id, { r, onClick });
19
+ return () => { regions.current.delete(r.id); };
20
+ }, []);
21
+ const onWheel = useCallback((h) => {
22
+ wheels.current.add(h);
23
+ return () => { wheels.current.delete(h); };
24
+ }, []);
25
+ useEffect(() => {
26
+ if (!enabled || !stdin)
27
+ return;
28
+ let off = false;
29
+ const disable = () => { if (off)
30
+ return; off = true; try {
31
+ process.stdout.write(MOUSE_OFF);
32
+ }
33
+ catch { /* stream gone */ } };
34
+ try {
35
+ if (isRawModeSupported)
36
+ setRawMode?.(true);
37
+ }
38
+ catch { /* */ }
39
+ try {
40
+ process.stdout.write(MOUSE_ON);
41
+ }
42
+ catch { /* */ }
43
+ const onData = (buf) => {
44
+ for (const e of parseMouse(typeof buf === "string" ? buf : buf.toString("utf8"))) {
45
+ if (e.action === "wheel-up" || e.action === "wheel-down") {
46
+ for (const h of wheels.current)
47
+ h(e);
48
+ continue;
49
+ }
50
+ if (e.action === "press" && e.button === "left") {
51
+ const hit = hitTest([...regions.current.values()].map((v) => v.r), e.x, e.y);
52
+ if (hit)
53
+ regions.current.get(hit.id)?.onClick(e);
54
+ }
55
+ }
56
+ };
57
+ stdin.on("data", onData);
58
+ const onExit = () => disable(); // fires on normal exit + after the app's signal handlers call process.exit
59
+ process.on("exit", onExit);
60
+ return () => { stdin.off("data", onData); process.off("exit", onExit); disable(); };
61
+ }, [enabled, stdin, setRawMode, isRawModeSupported]);
62
+ return React.createElement(Ctx.Provider, { value: { enabled, registerRegion, onWheel } }, children);
63
+ }
64
+ /** The mouse context: `enabled` (false in inline mode) + registerRegion/onWheel. */
65
+ export const useMouse = () => useContext(Ctx);
66
+ /** Subscribe to wheel-scroll events (global; no hit-testing). Auto-unsubscribes on unmount. A no-op when
67
+ * the provider is disabled (inline mode) since nothing dispatches. */
68
+ export function useOnWheel(handler) {
69
+ const { onWheel } = useMouse();
70
+ useEffect(() => onWheel(handler), [onWheel, handler]);
71
+ }
72
+ /** Register a clickable region (absolute terminal-cell bounds, e.g. from Ink measureElement + position).
73
+ * The provider calls `onClick` on a left-press inside it. Auto-unregisters on unmount / bounds change. */
74
+ export function useClickRegion(region, onClick) {
75
+ const { registerRegion } = useMouse();
76
+ useEffect(() => {
77
+ if (!region)
78
+ return;
79
+ return registerRegion(region, onClick);
80
+ }, [registerRegion, region?.id, region?.x, region?.y, region?.width, region?.height, onClick]);
81
+ }
@@ -0,0 +1,65 @@
1
+ // Pure SGR (mode 1006) mouse-sequence parser — the foundation of the Phase 1 mouse layer
2
+ // (fullscreen-only; blueprint: _ai-docs/architecture/tui-enterprise-upgrade.md). Ink has no mouse API,
3
+ // so MouseProvider (next increment) enables tracking, feeds raw stdin chunks to parseMouse(), and
4
+ // dispatches the normalized events to hit-tested regions (Ink measureElement bounds). This module is
5
+ // pure string→events (no Ink/node deps), unit-tested like osc.ts/capabilities.ts.
6
+ //
7
+ // Only SGR is parsed — `CSI < Cb ; Cx ; Cy (M|m)` — the one modern-terminal encoding (every terminal in
8
+ // the vtdn.dev matrix): decimal coords with no 223-column ceiling and an unambiguous press/release via
9
+ // the final M/m. Legacy X10/1000, urxvt/1015 and UTF-8/1005 are never emitted, so never parsed.
10
+ // CSI < Cb ; Cx ; Cy M|m — global so we can walk every event in a chunk.
11
+ const SGR = /\x1b\[<(\d+);(\d+);(\d+)([Mm])/g;
12
+ /** Parse every SGR mouse event in a stdin chunk, in order. Non-mouse bytes (keyboard) are ignored — the
13
+ * caller routes those to Ink's own input. Decodes Cb: low 2 bits = button (0 left / 1 middle / 2 right),
14
+ * +4 shift, +8 alt, +16 ctrl, +32 motion-while-held, +64 wheel (65 = wheel down, 64 = wheel up). */
15
+ export function parseMouse(chunk) {
16
+ const out = [];
17
+ SGR.lastIndex = 0;
18
+ let m;
19
+ while ((m = SGR.exec(chunk)) !== null) {
20
+ const cb = Number(m[1]);
21
+ const x = Number(m[2]);
22
+ const y = Number(m[3]);
23
+ const released = m[4] === "m";
24
+ const shift = (cb & 4) !== 0;
25
+ const alt = (cb & 8) !== 0;
26
+ const ctrl = (cb & 16) !== 0;
27
+ let button;
28
+ let action;
29
+ if ((cb & 64) !== 0) {
30
+ // wheel: 64 = up, 65 = down (low bit distinguishes); no button, never a release.
31
+ button = "none";
32
+ action = (cb & 1) !== 0 ? "wheel-down" : "wheel-up";
33
+ }
34
+ else {
35
+ const low = cb & 3;
36
+ button = low === 0 ? "left" : low === 1 ? "middle" : low === 2 ? "right" : "none";
37
+ if (released)
38
+ action = "release";
39
+ else if ((cb & 32) !== 0)
40
+ action = button === "none" ? "move" : "drag";
41
+ else
42
+ action = "press";
43
+ }
44
+ out.push({ x, y, button, action, shift, alt, ctrl });
45
+ }
46
+ return out;
47
+ }
48
+ /** The LAST matching region containing (x,y) — last-registered wins, so a child/overlay registered after
49
+ * its parent takes the hit (matches paint order). Returns null when the point hits no region. Pure. */
50
+ export function hitTest(regions, x, y) {
51
+ let hit = null;
52
+ for (const r of regions) {
53
+ if (x >= r.x && x < r.x + r.width && y >= r.y && y < r.y + r.height)
54
+ hit = r;
55
+ }
56
+ return hit;
57
+ }
58
+ // Enable/disable SGR mouse tracking. Mode 1002 (button-event) = press + release + drag-while-held + wheel
59
+ // — the practical default for a scrollable/clickable TUI; NEVER 1003 (any-event floods stdin on every
60
+ // move). Paired with 1006 (SGR encoding). Written to stdout ONLY in fullscreen (inline keeps the
61
+ // terminal's native scroll + copy). MOUSE_OFF must run in a try/finally + on exit/SIGINT/SIGTERM/
62
+ // uncaughtException — a tracking mode left enabled after a crash captures every click until a manual
63
+ // reset (the single most common real-world mouse bug across every project surveyed).
64
+ export const MOUSE_ON = "\x1b[?1002h\x1b[?1006h";
65
+ export const MOUSE_OFF = "\x1b[?1006l\x1b[?1002l";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.159",
3
+ "version": "0.1.161",
4
4
  "description": "Operator (KODE) — TypeScript + Ink terminal coding agent. Full-frame render, single-engine core shared across CLI/web/mobile; runs against a local Aurora model.",
5
5
  "type": "module",
6
6
  "bin": {