@tiens.nguyen/gonext-local-worker 1.0.263 → 1.0.265

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/gonext-repl.mjs +46 -22
  2. package/package.json +1 -1
package/gonext-repl.mjs CHANGED
@@ -413,6 +413,11 @@ process.on("exit", disableMouse);
413
413
  // (hover/drag), bit 64 = wheel; low 2 bits = which button (0=left). A left CLICK is a press
414
414
  // (M) with motion+wheel bits clear and low bits 0; a HOVER is any event with the motion bit.
415
415
  const MOUSE_RE = /\x1b\[<(\d+);(\d+);(\d+)([Mm])/g;
416
+ // Cursor Position Report reply to our `\x1b[6n` probe: ESC [ row ; col R. We probe right after
417
+ // clearing the status (cursor is then at the status block's TOP row) to learn the thought
418
+ // line's ABSOLUTE viewport row — so hover/click hit-testing is exact even when the block isn't
419
+ // at the bottom of the screen (task #96 fix). No `<`, so it never collides with MOUSE_RE.
420
+ const DSR_RE = /\x1b\[(\d+);(\d+)R/g;
416
421
  const nextLine = () =>
417
422
  _lineQueue.length > 0
418
423
  ? Promise.resolve(_lineQueue.shift())
@@ -1220,6 +1225,8 @@ async function runAgentTurn(history) {
1220
1225
  let fullLiveThought = "";
1221
1226
  let thoughtExpanded = false;
1222
1227
  let hoverRow = -1; // last mouse viewport row (from motion events) → highlight when it's on the thought line
1228
+ let thoughtRow = -1; // absolute viewport row of the thought line (line 1), learned via \x1b[6n
1229
+ let lastDsrAt = 0; // throttle the cursor-position probe
1223
1230
  const thinkSecs = () => Math.max(1, Math.round((Date.now() - thinkingSince) / 1000));
1224
1231
 
1225
1232
  // The status is normally TWO in-place lines — the in-progress action, then the playful
@@ -1269,35 +1276,45 @@ async function runAgentTurn(history) {
1269
1276
  // Priority: a live command > the model's current Thought clause (task #64, so a
1270
1277
  // long CPU-bound step reads as what it's actually reasoning about, not "Thinking")
1271
1278
  // > the "almost done" heartbeat > the bare fallback.
1272
- const primary = runningCmd
1273
- ? `Running ${runningCmd}`
1274
- : liveThought || (almostDone ? "Almost done" : "Thinking");
1275
1279
  const max = Math.max(24, (process.stdout.columns || 80) - 14);
1276
1280
  const fit = (s) => (s.length > max ? s.slice(0, max - 1) + "…" : s);
1277
1281
  const tokLabel =
1278
1282
  dim(` · ${fmtTokens(latestCodeTokens)} tok`) +
1279
1283
  orange(` · ${fmtTokens(sessionMaxCodeTokens)} max`);
1280
- // Task #96: the thought line is "clickable" only when there's a fuller thought to reveal
1281
- // (a live command / bare "Thinking" has nothing to expand). When clicked, unfold it below
1282
- // as up to 4 wrapped GREY lines (dim). The whole status block rides the viewport bottom as
1283
- // output scrolls, so line 1 (the thought) sits at row `rows - drawn + 1` — if the mouse is
1284
- // hovering THAT row, render the label as an underlined bright-green "link".
1285
- const clickable = !!(fullLiveThought && !runningCmd);
1286
- const expLines = thoughtExpanded && clickable ? wrapThought(fullLiveThought, max, 4) : [];
1284
+ // Task #96: the thought line is "clickable" only when the fuller thought has MORE text than
1285
+ // fits on line 1 (a live command / bare "Thinking" / a thought that already fits has nothing
1286
+ // to reveal). Line 1 (what's happening now): a live command > the model's current Thought >
1287
+ // "almost done" > "Thinking". When clickable we drive line 1 from the SAME fuller string, so
1288
+ // the grey expansion CONTINUES where line 1 was cut off instead of repeating the head.
1289
+ const clickable = !!fullLiveThought && !runningCmd && fullLiveThought.length > max;
1290
+ const primary = runningCmd
1291
+ ? `Running ${runningCmd}`
1292
+ : clickable
1293
+ ? fullLiveThought
1294
+ : liveThought || (almostDone ? "Almost done" : "Thinking");
1295
+ const label = `${fit(primary)}… (${secs}s)`;
1296
+ // When clicked, unfold the REMAINDER (what fit() dropped, i.e. from char max-1 on) as up to
1297
+ // 4 wrapped GREY lines BETWEEN the thought and the playful-word line.
1298
+ const rest = clickable ? fullLiveThought.slice(max - 1).trim() : "";
1299
+ const expLines = thoughtExpanded && rest ? wrapThought(rest, max, 4) : [];
1287
1300
  const drawn = 2 + expLines.length;
1288
1301
  const rows = process.stdout.rows || 24;
1289
- const hovering = clickable && hoverRow === rows - drawn + 1;
1290
- const label = `${fit(primary)}… (${secs}s)`;
1302
+ // Hover-highlight only the THOUGHT line (line 1) its exact viewport row comes from the
1303
+ // \x1b[6n probe below (`thoughtRow`); fall back to the viewport-bottom assumption only when
1304
+ // the terminal never answered the probe.
1305
+ const tRow = thoughtRow >= 1 ? thoughtRow : rows - drawn + 1;
1306
+ const hovering = clickable && hoverRow === tRow;
1291
1307
  clearStatus();
1308
+ // Right after clearing, the cursor sits at the status block's TOP-LEFT = the thought line's
1309
+ // row. Probe for it (throttled) so hover/click hit-testing is exact wherever the block is.
1310
+ if (process.stdin.isTTY && now - lastDsrAt > 400) { lastDsrAt = now; process.stdout.write("\x1b[6n"); }
1292
1311
  // Line 1: green ● + green phase/seconds (matches the web's green streaming label), or the
1293
- // underlined bright-green hover style when the mouse is over a clickable thought.
1294
- // Line 2 (indented): the SPINNER + the playful word together, both in the cycling color.
1295
- // Task #83/#84: after the word, the running agent-code token count (dim) + per-workspace
1296
- // PEAK single-request count (orange), e.g. " ⠙ Caffeinating… · 12.3k tok · 8.1k max".
1297
- let out =
1298
- `${green(BULLET)} ${hovering ? hoverThought(label) : green(label)}` +
1299
- "\n" + ` ${color256(wc, `${glyph} ${thinkWord}…`)}${tokLabel}`;
1312
+ // underlined bright-green hover style when the mouse is over a clickable thought. Then the
1313
+ // GREY expanded lines (if any), then LAST the SPINNER + playful word + token labels
1314
+ // (task #83/#84), e.g. " ⠙ Caffeinating… · 12.3k tok · 8.1k max".
1315
+ let out = `${green(BULLET)} ${hovering ? hoverThought(label) : green(label)}`;
1300
1316
  for (const wl of expLines) out += "\n " + dim(wl);
1317
+ out += "\n" + ` ${color256(wc, `${glyph} ${thinkWord}…`)}${tokLabel}`;
1301
1318
  process.stdout.write(out);
1302
1319
  statusLines = drawn;
1303
1320
  statusShown = true;
@@ -1316,8 +1333,10 @@ async function runAgentTurn(history) {
1316
1333
  const onStatusClick = (row) => {
1317
1334
  if (!statusShown) return;
1318
1335
  const rows = process.stdout.rows || 24;
1319
- const top = rows - statusLines + 1; // 1-based viewport row of the first status line
1320
- if (row < top || row > rows) return; // click landed outside the status block
1336
+ const top = thoughtRow >= 1 ? thoughtRow : rows - statusLines + 1; // thought line row
1337
+ // Toggle only on the thought line + its grey expansion NOT the last row (the playful
1338
+ // word / token line), so a click there doesn't expand what it isn't part of.
1339
+ if (row < top || row > top + statusLines - 2) return;
1321
1340
  // Only meaningful when there IS a fuller thought to reveal; otherwise ignore the click
1322
1341
  // so we don't flicker an empty expand.
1323
1342
  if (!thoughtExpanded && !(fullLiveThought && !runningCmd)) return;
@@ -1327,7 +1346,11 @@ async function runAgentTurn(history) {
1327
1346
  const onMouseData = (chunk) => {
1328
1347
  if (!following) return;
1329
1348
  const s = chunk.toString("latin1");
1330
- if (s.indexOf("\x1b[<") === -1) return; // fast reject: no SGR mouse report in this chunk
1349
+ if (s.indexOf("\x1b[") === -1) return; // fast reject: no CSI (mouse report OR cursor reply) here
1350
+ // Cursor-position reply → the thought line's absolute row (see the \x1b[6n probe in tick).
1351
+ DSR_RE.lastIndex = 0;
1352
+ let d;
1353
+ while ((d = DSR_RE.exec(s))) thoughtRow = parseInt(d[1], 10);
1331
1354
  MOUSE_RE.lastIndex = 0;
1332
1355
  let m;
1333
1356
  while ((m = MOUSE_RE.exec(s))) {
@@ -1354,6 +1377,7 @@ async function runAgentTurn(history) {
1354
1377
  fenceThought = "";
1355
1378
  fullLiveThought = ""; // #96: the fuller thought is spent too…
1356
1379
  thoughtExpanded = false; // …and each new thinking phase starts collapsed.
1380
+ lastDsrAt = 0; // …content just scrolled → re-probe the thought row next tick.
1357
1381
  lastContentAt = Date.now();
1358
1382
  };
1359
1383
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.263",
3
+ "version": "1.0.265",
4
4
  "description": "Polls GoNext cloud API for async local LLM jobs and runs them against Ollama/OpenAI-compatible servers on this Mac",
5
5
  "type": "module",
6
6
  "license": "MIT",