@tiens.nguyen/gu-cli 1.0.843 → 1.0.844

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.
@@ -223,3 +223,19 @@ export function embedNotice({ state, model } = {}) {
223
223
  if (state === "off" && model) return `⚠ RAG is switched off — ${model} is set · /embed-model turns it on`;
224
224
  return "⚠ no embed model — RAG is off · /embed-model";
225
225
  }
226
+
227
+ /**
228
+ * WHICH SETUP ROWS THE BOTTOM BAR SHOWS (first-run noise, #188). A fresh install used to stack
229
+ * three warnings at once. Now they come in order of need, and pure (no OS-specific logic):
230
+ * - nothing to answer with → ONLY "coding model not set" (the one thing to do first);
231
+ * - a coding model exists but no agent model → the agent row (the coding model stands in);
232
+ * - no embed model → NOTHING until embedding was actually needed (`embedNeeded`: the agent tried
233
+ * a RAG tool, or the user opened /embed-model), then the embed row.
234
+ */
235
+ export function setupNoticeRows({ noModel = false, agentMissing = false, embedMissing = false, embedNeeded = false, embedWhy } = {}) {
236
+ if (noModel) return ["⚠ coding model not set · /model"];
237
+ return [
238
+ ...(agentMissing ? ["⚠ agent model not set — using the coding model · /agent-model"] : []),
239
+ ...(embedMissing && embedNeeded ? [embedNotice(embedWhy) || "⚠ no embed model — RAG is off · /embed-model"] : []),
240
+ ];
241
+ }
@@ -6662,6 +6662,13 @@ def _looks_like_timeout(err) -> bool:
6662
6662
  return isinstance(err, TimeoutError) or "timed out" in str(err or "").lower()
6663
6663
 
6664
6664
 
6665
+ # What to tell the user/model to use when RAG can't run. NEVER the bare word "grep": on Windows 11
6666
+ # there is no grep, and people read it as the shell command. grep_repo is gu's own tool (pure Python
6667
+ # re + file walk), so it works the same on Windows, macOS and Linux. (issue #186)
6668
+ _NO_RAG_ALTERNATIVE = ("the built-in code search instead (grep_repo / read_file_lines — they run "
6669
+ "inside gu, so no shell grep is needed, also on Windows 11)")
6670
+
6671
+
6665
6672
  def _rag_embed_failure_hint(err) -> str:
6666
6673
  """One line a user can act on, from an embedding failure.
6667
6674
 
@@ -14343,20 +14350,26 @@ def run_agent_chat(cfg):
14343
14350
  the wrong place. The embedding model is the usual one and has no fallback: chat
14344
14351
  and code model servers don't embed, so nothing can stand in for it.
14345
14352
  """
14353
+ # #188: the terminal keeps the embed warning off the bar until embedding is actually
14354
+ # needed — this is that moment. A step, so it works when the agent is on another machine.
14355
+ try:
14356
+ _emit({"type": "step", "text": "__EMBEDNEEDED__::" + ("rag-off" if not rag_enabled else "no-embedder")})
14357
+ except Exception: # noqa: BLE001
14358
+ pass
14346
14359
  if not rag_enabled:
14347
14360
  return ("Error: RAG is turned off for this account — enable it in "
14348
- "Settings -> Agent -> RAG. Use grep_repo/read_file_lines instead.")
14361
+ "Settings -> Agent -> RAG. Meanwhile, use " + _NO_RAG_ALTERNATIVE + ".")
14349
14362
  if not rag_embed_base:
14350
14363
  if _CLIENT_MODE:
14351
14364
  # This machine runs the agent but hosts no models — `doctor` here can't
14352
14365
  # help, and pointing the user at it would waste their time.
14353
- return ("Error: EMBEDDING MODEL NOT FOUND — this machine runs the agent but "
14366
+ return ("Error: the RAG embedding model is not set up here — this machine runs the agent but "
14354
14367
  "hosts no models, so there is no embedder here. RAG runs on your MODEL "
14355
- "machine; use grep_repo / read_file_lines for this project instead.")
14356
- return ("Error: EMBEDDING MODEL NOT FOUND — no embedding server is configured, "
14357
- "and there is no fallback (chat/code model servers cannot embed). Set the "
14368
+ "machine; for this project, use " + _NO_RAG_ALTERNATIVE + ".")
14369
+ return ("Error: the RAG embedding model is not set up yet — no embedding server is "
14370
+ "configured, and chat/code model servers cannot stand in for it. Set the "
14358
14371
  "embedding model folder in Settings -> Agent -> RAG, or run "
14359
- "`gu-cli doctor` to download and start it. Use grep_repo meanwhile.")
14372
+ "`gu-cli doctor` to download and start it. Meanwhile, use " + _NO_RAG_ALTERNATIVE + ".")
14360
14373
  if not _RAG_LOCAL:
14361
14374
  return ("Error: cloud RAG needs AWS credentials in Settings -> Agent -> RAG "
14362
14375
  "(or switch the terminal to local with /rag-cloud off).")
@@ -14837,7 +14850,7 @@ def run_agent_chat(cfg):
14837
14850
  "text": f"RAG indexing failed → {_rag_embed_failure_hint(e)}"})
14838
14851
  out = (f"Error: indexing failed: {type(e).__name__}: {e}. "
14839
14852
  f"The embedding server is {rag_embed_base or '(not configured)'} — check it is "
14840
- f"running (gu status / gu-cli doctor). Use grep_repo meanwhile.")
14853
+ f"running (gu status / gu-cli doctor). Meanwhile, use {_NO_RAG_ALTERNATIVE}.")
14841
14854
  _last_obs["text"] = out
14842
14855
  return out
14843
14856
 
@@ -14858,7 +14871,7 @@ def run_agent_chat(cfg):
14858
14871
  query, ((a, r) for a, r, _e in _rag_iter_text_files(root)))
14859
14872
  except Exception as e: # noqa: BLE001
14860
14873
  msg = (f"RAG is unavailable ({why}) and the keyword fallback failed: "
14861
- f"{type(e).__name__}: {e}. Use grep_repo(pattern) / read_file_lines.")
14874
+ f"{type(e).__name__}: {e}. Use {_NO_RAG_ALTERNATIVE}.")
14862
14875
  _last_obs["text"] = msg
14863
14876
  return msg
14864
14877
  _search_tally_bump("grep", res["hits"], " | ".join(res["terms"]) or query)
package/gu-repl.mjs CHANGED
@@ -151,7 +151,7 @@ import { codingBannerLabel, isOllamaCloudUrl, SECRET_KEY_HINT } from "./coding-k
151
151
  import { questionEchoText, thoughtPrintSeq, wrapDiffText } from "./terminal-layout.mjs";
152
152
  import { globalPrefixOf } from "./install-path.mjs";
153
153
  import { firstGuOnPath, pathGuMismatch, guOnPathIsCurrent, updateAttemptRecord, repeatUpdateNotice } from "./update-verify.mjs";
154
- import { embedNotice, embedState } from "./embed-model-command.mjs";
154
+ import { embedNotice, embedState, setupNoticeRows } from "./embed-model-command.mjs";
155
155
  import {
156
156
  MODELFALLBACK_PREFIX, fallbackAfterTurn, fallbackHistoryLine, fallbackNotice, keyMissingNotice,
157
157
  parseModelFallback,
@@ -1741,10 +1741,25 @@ let embedMissing = false; // no embed model chosen → RAG is off until /embed-m
1741
1741
  let embedWhy = { state: "unset", model: "" };
1742
1742
  // One footer row; the two halves are independent so a model that IS set is never named.
1743
1743
  // ONE SHORT ROW EACH (#317): joined, they ran past 80 columns and were cut mid-word.
1744
- const missingNoticeRows = () => [
1745
- ...(agentMissing ? ["⚠ agent model not set — using the coding model · /agent-model"] : []),
1746
- ...(embedMissing ? [embedNotice(embedWhy) || "⚠ no embed model — RAG is off · /embed-model"] : []),
1747
- ];
1744
+ // FIRST-RUN QUIET (#188): no model at all → only "coding model not set"; the embed row waits
1745
+ // until embedding is actually needed (`embedNeeded`).
1746
+ let embedNeeded = false;
1747
+ const missingNoticeRows = () =>
1748
+ setupNoticeRows({ noModel: noModelAtAll, agentMissing, embedMissing, embedNeeded, embedWhy });
1749
+ async function refreshNoModelAtAll() {
1750
+ try {
1751
+ const refreshed = await fetchAgentPayload([{ role: "user", content: "." }]);
1752
+ if (refreshed?.payload) noModelAtAll = nothingToAnswerWith(refreshed.payload);
1753
+ } catch {
1754
+ /* cannot ask → keep what the bar says */
1755
+ }
1756
+ if (barPinned()) paintBar();
1757
+ }
1758
+ function markEmbedNeeded() {
1759
+ if (embedNeeded) return;
1760
+ embedNeeded = true;
1761
+ if (barPinned()) paintBar();
1762
+ }
1748
1763
 
1749
1764
  // ANOTHER MODEL STOOD IN (task #343). The agent reports it as a __MODELFALLBACK__:: step; it is
1750
1765
  // held here and shown in YELLOW on the bar — from the moment it happens, through the rest of the
@@ -7386,13 +7401,19 @@ function settingsArg(line, word) {
7386
7401
  * and gu's readline would keep reading the keys meant for the editor. Everything is switched off
7387
7402
  * first and switched back on — and the view repainted from the transcript — whatever happens.
7388
7403
  */
7389
- function withTerminalHandedOver(run) {
7404
+ function withTerminalHandedOver(run, { keepScreen = false } = {}) {
7405
+ // keepScreen — a GUI editor (Notepad, VS Code…) runs in its own window (#188): the screen, the
7406
+ // pinned bar and the scroll region stay exactly as they are. Clearing and re-cutting them was
7407
+ // the Windows 11 bug: ESC[2J pushes the screen into conhost/Windows Terminal scrollback, the
7408
+ // re-pin's newlines moved the live rows further down, and the name prompt was drawn BELOW the
7409
+ // visible window — typing showed nothing until the user scrolled down.
7390
7410
  const wasPinned = barPinned();
7391
7411
  const hadClick = _clickEnabled;
7412
+ const hadHover = _mouseEnabled;
7392
7413
  disableMouse();
7393
7414
  disableClickToPosition();
7394
7415
  ui(PASTE_MODE_OFF);
7395
- unpinBar();
7416
+ if (!keepScreen) unpinBar();
7396
7417
  const wasRaw = Boolean(process.stdin.isRaw);
7397
7418
  try {
7398
7419
  process.stdin.setRawMode?.(false);
@@ -7410,11 +7431,25 @@ function withTerminalHandedOver(run) {
7410
7431
  }
7411
7432
  rl.resume();
7412
7433
  ui(PASTE_MODE_ON);
7434
+ if (hadHover) enableMouse();
7413
7435
  if (hadClick) enableClickToPosition();
7414
- if (wasPinned) {
7415
- ui("\x1b[2J");
7436
+ // The window may have been resized while the editor ran, and no resize event reached us.
7437
+ try {
7438
+ process.stdout._refreshSize?.();
7439
+ } catch {
7440
+ /* not a TTY */
7441
+ }
7442
+ if (wasPinned && !keepScreen) {
7443
+ // HOME, then erase to the end — not ESC[2J: on Windows that scrolls the whole screen into
7444
+ // scrollback and leaves the live rows below what the user sees (#188). From row 1 the
7445
+ // first pin's newlines scroll nothing, and the repaint puts the transcript back.
7446
+ ui("\x1b[H\x1b[J");
7416
7447
  pinBar();
7417
7448
  paintLiveTail();
7449
+ } else if (wasPinned && !barPinned()) {
7450
+ pinBar();
7451
+ } else if (keepScreen && barPinned()) {
7452
+ paintBar();
7418
7453
  }
7419
7454
  }
7420
7455
  }
@@ -7565,7 +7600,7 @@ async function runOpenPresetsCommand(line) {
7565
7600
  const editor = ed.pickEditor({ readOnly: true });
7566
7601
  if (editor && process.stdin.isTTY) {
7567
7602
  console.log(GUTTER + dim(`Opening ${basename(editor.cmd)} read-only (${editor.saveHint}).`));
7568
- const r = withTerminalHandedOver(() => ed.editText(text, { editor, fileName: "gu-setup.json" }));
7603
+ const r = withTerminalHandedOver(() => ed.editText(text, { editor, fileName: "gu-setup.json" }), { keepScreen: ed.isGuiEditor(editor) });
7569
7604
  if (!r.ok) console.log(GUTTER + yellow(`couldn't show it — ${r.why}.`));
7570
7605
  } else {
7571
7606
  console.log(GUTTER + yellow(editor ? "an editor needs a terminal." : ed.NO_EDITOR_HINT + "."));
@@ -7604,7 +7639,7 @@ async function runOpenPresetsCommand(line) {
7604
7639
  console.log(GUTTER + dim(`Opening "${name}" in ${basename(editor.cmd)} — save a change, or just quit.`));
7605
7640
  let text = initial;
7606
7641
  for (;;) {
7607
- const r = withTerminalHandedOver(() => ed.editText(text, { editor, fileName: `${name}.json` }));
7642
+ const r = withTerminalHandedOver(() => ed.editText(text, { editor, fileName: `${name}.json` }), { keepScreen: ed.isGuiEditor(editor) });
7608
7643
  if (!r.ok) {
7609
7644
  console.log(GUTTER + `Not changed — ${r.why}.` + "\n");
7610
7645
  return;
@@ -7846,7 +7881,7 @@ async function fixPresetInEditor(ed, text, { editor = ed.pickEditor() } = {}) {
7846
7881
  }
7847
7882
  let t = text;
7848
7883
  for (;;) {
7849
- const r = withTerminalHandedOver(() => ed.editText(t, { editor, fileName: "preset.json" }));
7884
+ const r = withTerminalHandedOver(() => ed.editText(t, { editor, fileName: "preset.json" }), { keepScreen: ed.isGuiEditor(editor) });
7850
7885
  if (!r.ok) {
7851
7886
  console.log(GUTTER + `Not saved — ${r.why}.`);
7852
7887
  return null;
@@ -10681,6 +10716,8 @@ const RAGFILE_PREFIX = "__RAGFILE__::";
10681
10716
  // been written yet — otherwise the row would be blank and the flag would look broken, which
10682
10717
  // is exactly what happens on a client whose embedder is unreachable.
10683
10718
  const RAGSTATE_PREFIX = "__RAGSTATE__::";
10719
+ // The agent needed an embedder (a RAG tool ran) and none is set up: only now does the bar say so (#188).
10720
+ const EMBEDNEEDED_PREFIX = "__EMBEDNEEDED__::";
10684
10721
  // The tool ABOUT to run: "<label>\t<call>" (task #177). Swallowed from scrollback like
10685
10722
  // "Running → …" — it belongs to the live block, and the finished bullet replaces it.
10686
10723
  const RUNTOOL_PREFIX = "__RUNTOOL__::";
@@ -12558,6 +12595,11 @@ async function runAgentTurn(history, { attachJobId = "", ownJob = false } = {})
12558
12595
  lastContentAt = Date.now();
12559
12596
  continue;
12560
12597
  }
12598
+ if (line.startsWith(EMBEDNEEDED_PREFIX)) {
12599
+ markEmbedNeeded();
12600
+ lastContentAt = Date.now();
12601
+ continue;
12602
+ }
12561
12603
  if (line.startsWith(RAGSTATE_PREFIX)) {
12562
12604
  lastRagState = line.slice(RAGSTATE_PREFIX.length).trim();
12563
12605
  lastContentAt = Date.now();
@@ -14431,6 +14473,7 @@ async function main() {
14431
14473
  }
14432
14474
  if (line === "/model") {
14433
14475
  await chooseModel();
14476
+ await refreshNoModelAtAll(); // #188: a coding model may have just been set → drop its row
14434
14477
  continue;
14435
14478
  }
14436
14479
  if (line === "/provider" || line === "/providers") {
@@ -14439,11 +14482,13 @@ async function main() {
14439
14482
  }
14440
14483
  if (line === "/agent-model") {
14441
14484
  await chooseAgentModel();
14485
+ await refreshNoModelAtAll();
14442
14486
  agentMissing = false; // Task #14: an agent model was just chosen → clear its warning
14443
14487
  setModelFallback(null); // #343: so is the stand-in a fallback warning named
14444
14488
  continue;
14445
14489
  }
14446
14490
  if (line === "/embed-model") {
14491
+ markEmbedNeeded(); // #188: the person is asking about it — now the row is relevant
14447
14492
  await chooseEmbedModel();
14448
14493
  // Read back what is SAVED (#347). The warning used to be cleared here whatever happened —
14449
14494
  // a cancelled menu or a failed save removed it for the session, and it returned at the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gu-cli",
3
- "version": "1.0.843",
3
+ "version": "1.0.844",
4
4
  "description": "Gu CLI — the gu terminal plus the local worker that runs agent / OCR / PDF / embedding jobs on your Mac (Ollama / MLX / OpenAI-compatible).",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/preset-editor.mjs CHANGED
@@ -33,6 +33,17 @@ const clean = (v) => (typeof v === "string" ? v.trim() : "");
33
33
  /** GUI editors — no use in an SSH session or on a server with no display: they hang or fail. */
34
34
  const GUI_EDITORS = /^(code|code-insiders|cursor|codium|subl|sublime_text|gedit|kate|kwrite|mousepad|xed|pluma|atom|mate|zed|gvim|mvim|macvim|notepad\+\+|notepad|textedit|bbedit|open|xdg-open)(\.exe)?$/i;
35
35
 
36
+ /**
37
+ * Does `editor` open its OWN WINDOW (Notepad, VS Code, …) instead of drawing in this terminal? Such an
38
+ * editor never touches the terminal, so gu must not clear or re-cut the screen around it (#188: on
39
+ * Windows 11 that clear pushed the screen into scrollback and the name prompt was drawn below the
40
+ * visible window — "I can't type until I scroll down").
41
+ */
42
+ export function isGuiEditor(editor) {
43
+ const base = String(editor?.cmd ?? "").split(/[\\/]/).pop();
44
+ return Boolean(base) && GUI_EDITORS.test(base);
45
+ }
46
+
36
47
  /**
37
48
  * Are we in a terminal with no graphical display — an SSH session, or a Linux server? (#322: the user
38
49
  * often runs gu on an Ubuntu server over SSH.)