@tiens.nguyen/gu-cli 1.0.842 → 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.
- package/embed-model-command.mjs +16 -0
- package/gonext_agent_chat.py +105 -18
- package/gu-repl.mjs +57 -12
- package/package.json +1 -1
- package/preset-editor.mjs +11 -0
- package/shell-details.mjs +13 -3
package/embed-model-command.mjs
CHANGED
|
@@ -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
|
+
}
|
package/gonext_agent_chat.py
CHANGED
|
@@ -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
|
|
|
@@ -8312,8 +8319,13 @@ _BROWSER_LINE = (
|
|
|
8312
8319
|
|
|
8313
8320
|
# Background shells (task #360). Never `&` (refused) — background=True is the way to say it.
|
|
8314
8321
|
_BG_LINE = ("A LONG job (build, deploy, big test run) → run_command(…, background=True), then "
|
|
8315
|
-
"shell_output(<id>, wait_seconds
|
|
8316
|
-
"
|
|
8322
|
+
"shell_output(<id>, wait_seconds=540) to wait for it in ONE call — never several short "
|
|
8323
|
+
"polls; a build whose result you need next is simpler as one run_command(…, "
|
|
8324
|
+
"timeout_seconds=600). A command still running at its timeout moves to the background "
|
|
8325
|
+
"by itself instead of being killed. Setup every command needs (exports) goes ONCE in "
|
|
8326
|
+
"<workspace>/.gonext/env, which is sourced before each command. A recipe that WORKED "
|
|
8327
|
+
"after effort (a login, build flags, a deploy path) or a short project summary goes as "
|
|
8328
|
+
"ONE line in <workspace>/.gonext/notes.md, shown at the start of every later turn.\n")
|
|
8317
8329
|
|
|
8318
8330
|
|
|
8319
8331
|
# What to do instead, said where quoting broke — in gu's own pre-check (an unbalanced quote never
|
|
@@ -8438,6 +8450,29 @@ def _test_commands_line(root: str) -> str:
|
|
|
8438
8450
|
return line
|
|
8439
8451
|
|
|
8440
8452
|
|
|
8453
|
+
_WS_NOTES_CAP = 1500
|
|
8454
|
+
|
|
8455
|
+
|
|
8456
|
+
def _ws_notes_line(root: str, cap: int = _WS_NOTES_CAP) -> str:
|
|
8457
|
+
"""<workspace>/.gonext/notes.md shown in every turn's context (GitHub #184, turn review #389):
|
|
8458
|
+
a recipe that worked (turn #7 spent ~15 steps rediscovering turn #6's App Store login) and a
|
|
8459
|
+
short project summary (turns #4/#5/#8 each re-read the same docs). Capped; "" when absent."""
|
|
8460
|
+
if not root:
|
|
8461
|
+
return ""
|
|
8462
|
+
p = os.path.join(root, ".gonext", "notes.md")
|
|
8463
|
+
try:
|
|
8464
|
+
with open(p, encoding="utf-8", errors="replace") as fh:
|
|
8465
|
+
txt = fh.read(cap + 1).strip()
|
|
8466
|
+
except OSError:
|
|
8467
|
+
return ""
|
|
8468
|
+
if not txt:
|
|
8469
|
+
return ""
|
|
8470
|
+
if len(txt) > cap:
|
|
8471
|
+
txt = txt[:cap].rstrip() + " …(cut — keep notes.md short)"
|
|
8472
|
+
return (" WORKSPACE NOTES (.gonext/notes.md — recipes and facts saved by earlier turns; use them "
|
|
8473
|
+
"before rediscovering):\n" + "\n".join(f" {l}" for l in txt.splitlines()) + "\n")
|
|
8474
|
+
|
|
8475
|
+
|
|
8441
8476
|
def _test_digest(output: str, cwd: str = "") -> str:
|
|
8442
8477
|
"""gu_test_digest.digest, or "" if the module is missing — a summary must never fail a command."""
|
|
8443
8478
|
try:
|
|
@@ -9895,6 +9930,25 @@ def _patch_dotted_imports() -> bool:
|
|
|
9895
9930
|
return True
|
|
9896
9931
|
|
|
9897
9932
|
|
|
9933
|
+
_SANDBOX_PREIMPORTS = "import json\nimport re\nimport base64\n"
|
|
9934
|
+
|
|
9935
|
+
|
|
9936
|
+
def _preimport_sandbox(agent) -> bool:
|
|
9937
|
+
"""json, re and base64 are already imported in the agent's code sandbox (GitHub #183, turn
|
|
9938
|
+
review #389): a step that used json.loads without its own `import json` failed and cost a
|
|
9939
|
+
whole step. Runs through the executor's own import check, so nothing new is allowed. False
|
|
9940
|
+
when there is no Python executor (ToolCallingAgent) or the import is refused."""
|
|
9941
|
+
ex = getattr(agent, "python_executor", None)
|
|
9942
|
+
if ex is None:
|
|
9943
|
+
return False
|
|
9944
|
+
try:
|
|
9945
|
+
ex(_SANDBOX_PREIMPORTS)
|
|
9946
|
+
return True
|
|
9947
|
+
except Exception as e: # noqa: BLE001
|
|
9948
|
+
_log(f"sandbox pre-import skipped: {type(e).__name__}: {e}")
|
|
9949
|
+
return False
|
|
9950
|
+
|
|
9951
|
+
|
|
9898
9952
|
def _run_state_cwd() -> str:
|
|
9899
9953
|
"""The folder the last shell line ended in, this turn — or ""."""
|
|
9900
9954
|
p = _RUN_STATE["path"]
|
|
@@ -9916,9 +9970,22 @@ def _run_state_set_cwd(cwd: str) -> None:
|
|
|
9916
9970
|
pass
|
|
9917
9971
|
|
|
9918
9972
|
|
|
9973
|
+
def _ws_env_file(root: str = "") -> str:
|
|
9974
|
+
"""<workspace>/.gonext/env when it exists, else "" (GitHub #181, turn review #389): the setup
|
|
9975
|
+
every command needs (`export DEVELOPER_DIR=…; export LC_ALL=…`) is written there ONCE and
|
|
9976
|
+
sourced before each run_command line, instead of being repeated on every call."""
|
|
9977
|
+
try:
|
|
9978
|
+
root = root or _default_ws_root()
|
|
9979
|
+
except Exception: # noqa: BLE001
|
|
9980
|
+
return ""
|
|
9981
|
+
p = os.path.join(root or "", ".gonext", "env")
|
|
9982
|
+
return p if root and os.path.isfile(p) else ""
|
|
9983
|
+
|
|
9984
|
+
|
|
9919
9985
|
def _run_state_wrapper() -> str:
|
|
9920
|
-
"""The outer script: $1 the line, $2 the exit file, $3 the state file."""
|
|
9921
|
-
|
|
9986
|
+
"""The outer script: $1 the line, $2 the exit file, $3 the state file, $4 the env file."""
|
|
9987
|
+
# $4: the workspace's .gonext/env (GitHub #181) — sourced first, so this turn's own exports win.
|
|
9988
|
+
return ('[ -n "$4" ] && [ -f "$4" ] && . "$4" >/dev/null 2>&1; [ -f "$3" ] && . "$3" >/dev/null 2>&1; '
|
|
9922
9989
|
"trap '__gu_rc=$?; echo $__gu_rc > \"$2\"; "
|
|
9923
9990
|
f"export -p | grep -vE \"{_RUN_STATE_SKIP}\" > \"$3.tmp\" 2>/dev/null && mv -f \"$3.tmp\" \"$3\"; "
|
|
9924
9991
|
"pwd > \"$3.cwd\"; exit $__gu_rc' EXIT; "
|
|
@@ -11266,6 +11333,7 @@ def run_agent_chat(cfg):
|
|
|
11266
11333
|
_ws_current_line
|
|
11267
11334
|
+ f" Other registered workspaces (use only if the user names them): {_ws_names}\n"
|
|
11268
11335
|
+ _ws_tests_line
|
|
11336
|
+
+ _ws_notes_line(_WS_ACTIVE or "")
|
|
11269
11337
|
+ _ws_servers_line
|
|
11270
11338
|
+ f" Current folder contents:\n"
|
|
11271
11339
|
+ "\n".join(f" {line}" for line in _ws_overview.splitlines()) + "\n"
|
|
@@ -12336,10 +12404,14 @@ def run_agent_chat(cfg):
|
|
|
12336
12404
|
if _completion_gate["nudged"]:
|
|
12337
12405
|
return True # already nudged once this turn — accept, never loop
|
|
12338
12406
|
ans = str(final_answer if final_answer is not None else "")
|
|
12339
|
-
|
|
12407
|
+
_m = _PUNT_RE.search(ans)
|
|
12408
|
+
if _m:
|
|
12340
12409
|
_completion_gate["nudged"] = True
|
|
12410
|
+
# GitHub #185: quote the words that tripped the gate, so a finished task is fixed by
|
|
12411
|
+
# rewording that phrase instead of redoing the work (turn review #389, item 7).
|
|
12341
12412
|
raise ValueError(
|
|
12342
|
-
"NOT DONE YET — your answer hands the work back to the user
|
|
12413
|
+
f"NOT DONE YET — your answer hands the work back to the user (it says \"{_m.group(0)}\"). "
|
|
12414
|
+
"If the work IS done and verified, just drop that phrase and answer again. Otherwise do ONE of these, "
|
|
12343
12415
|
"then call final_answer:\n"
|
|
12344
12416
|
" 1) DO it yourself with your tools, VERIFY it — run it, run the test, or "
|
|
12345
12417
|
"re-read the file to confirm the change took — and answer WITH that evidence; OR\n"
|
|
@@ -14278,20 +14350,26 @@ def run_agent_chat(cfg):
|
|
|
14278
14350
|
the wrong place. The embedding model is the usual one and has no fallback: chat
|
|
14279
14351
|
and code model servers don't embed, so nothing can stand in for it.
|
|
14280
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
|
|
14281
14359
|
if not rag_enabled:
|
|
14282
14360
|
return ("Error: RAG is turned off for this account — enable it in "
|
|
14283
|
-
"Settings -> Agent -> RAG.
|
|
14361
|
+
"Settings -> Agent -> RAG. Meanwhile, use " + _NO_RAG_ALTERNATIVE + ".")
|
|
14284
14362
|
if not rag_embed_base:
|
|
14285
14363
|
if _CLIENT_MODE:
|
|
14286
14364
|
# This machine runs the agent but hosts no models — `doctor` here can't
|
|
14287
14365
|
# help, and pointing the user at it would waste their time.
|
|
14288
|
-
return ("Error:
|
|
14366
|
+
return ("Error: the RAG embedding model is not set up here — this machine runs the agent but "
|
|
14289
14367
|
"hosts no models, so there is no embedder here. RAG runs on your MODEL "
|
|
14290
|
-
"machine;
|
|
14291
|
-
return ("Error:
|
|
14292
|
-
"and
|
|
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 "
|
|
14293
14371
|
"embedding model folder in Settings -> Agent -> RAG, or run "
|
|
14294
|
-
"`gu-cli doctor` to download and start it.
|
|
14372
|
+
"`gu-cli doctor` to download and start it. Meanwhile, use " + _NO_RAG_ALTERNATIVE + ".")
|
|
14295
14373
|
if not _RAG_LOCAL:
|
|
14296
14374
|
return ("Error: cloud RAG needs AWS credentials in Settings -> Agent -> RAG "
|
|
14297
14375
|
"(or switch the terminal to local with /rag-cloud off).")
|
|
@@ -14772,7 +14850,7 @@ def run_agent_chat(cfg):
|
|
|
14772
14850
|
"text": f"RAG indexing failed → {_rag_embed_failure_hint(e)}"})
|
|
14773
14851
|
out = (f"Error: indexing failed: {type(e).__name__}: {e}. "
|
|
14774
14852
|
f"The embedding server is {rag_embed_base or '(not configured)'} — check it is "
|
|
14775
|
-
f"running (gu status / gu-cli doctor).
|
|
14853
|
+
f"running (gu status / gu-cli doctor). Meanwhile, use {_NO_RAG_ALTERNATIVE}.")
|
|
14776
14854
|
_last_obs["text"] = out
|
|
14777
14855
|
return out
|
|
14778
14856
|
|
|
@@ -14793,7 +14871,7 @@ def run_agent_chat(cfg):
|
|
|
14793
14871
|
query, ((a, r) for a, r, _e in _rag_iter_text_files(root)))
|
|
14794
14872
|
except Exception as e: # noqa: BLE001
|
|
14795
14873
|
msg = (f"RAG is unavailable ({why}) and the keyword fallback failed: "
|
|
14796
|
-
f"{type(e).__name__}: {e}. Use
|
|
14874
|
+
f"{type(e).__name__}: {e}. Use {_NO_RAG_ALTERNATIVE}.")
|
|
14797
14875
|
_last_obs["text"] = msg
|
|
14798
14876
|
return msg
|
|
14799
14877
|
_search_tally_bump("grep", res["hits"], " | ".join(res["terms"]) or query)
|
|
@@ -15387,7 +15465,7 @@ def run_agent_chat(cfg):
|
|
|
15387
15465
|
if (_scan and not _ps) else []
|
|
15388
15466
|
_builtin = sorted({w for w in _words if w in _SHELL_STATE_BUILTINS})
|
|
15389
15467
|
_use_shell = bool(_scan) and (_ps or _shell_needed(_scan) or bool(_builtin) or bool(
|
|
15390
|
-
_RUN_STATE["path"] and os.path.exists(_RUN_STATE["path"])))
|
|
15468
|
+
_RUN_STATE["path"] and os.path.exists(_RUN_STATE["path"])) or bool(_ws_env_file()))
|
|
15391
15469
|
_bg_err = ((_ps_background_error(_scan) if _ps else _shell_background_error(_scan))
|
|
15392
15470
|
if _use_shell else None)
|
|
15393
15471
|
if _bg_err:
|
|
@@ -15602,7 +15680,8 @@ def run_agent_chat(cfg):
|
|
|
15602
15680
|
# Git Bash reads C:/x, not C:\x, inside the line it runs.
|
|
15603
15681
|
_fs = (lambda x: x.replace("\\", "/")) if _IS_WINDOWS else (lambda x: x)
|
|
15604
15682
|
argv = [_shell_bin, "-c", _run_state_wrapper(),
|
|
15605
|
-
_fs(_shell_bin), _cmd_text, _fs(exit_path), _fs(_run_state_path())
|
|
15683
|
+
_fs(_shell_bin), _cmd_text, _fs(exit_path), _fs(_run_state_path()),
|
|
15684
|
+
_fs(_ws_env_file())]
|
|
15606
15685
|
else:
|
|
15607
15686
|
argv, _attrib_note = _with_attribution(argv, _attribution_settings(wd))
|
|
15608
15687
|
if _attrib_note:
|
|
@@ -15943,7 +16022,14 @@ def run_agent_chat(cfg):
|
|
|
15943
16022
|
if _dg:
|
|
15944
16023
|
head += "\n" + _dg
|
|
15945
16024
|
tail_note = ""
|
|
15946
|
-
if not new.strip() and int(sh.get("read_offset") or 0)
|
|
16025
|
+
if not new.strip() and st["state"] != "running" and int(sh.get("read_offset") or 0) > 0:
|
|
16026
|
+
# GitHub #182: the end was read by an earlier poll — say how it ended anyway,
|
|
16027
|
+
# rather than "No new output" that sends the agent to grep the log.
|
|
16028
|
+
lt = _file_tail(str(sh.get("log") or ""), 3000).strip()
|
|
16029
|
+
if lt:
|
|
16030
|
+
tail_note = (f"\nIt has ended; the end of its output (read before):\n"
|
|
16031
|
+
f"{_ws_distill_output(lt)}")
|
|
16032
|
+
elif not new.strip() and int(sh.get("read_offset") or 0) == 0:
|
|
15947
16033
|
lf = _shell_log_file(str(sh.get("command") or ""), str(sh.get("workdir") or ""))
|
|
15948
16034
|
lt = _file_tail(lf).strip() if lf else ""
|
|
15949
16035
|
if lt:
|
|
@@ -16395,7 +16481,7 @@ def run_agent_chat(cfg):
|
|
|
16395
16481
|
# so this wall clock is a last-resort backstop, not the primary guard.
|
|
16396
16482
|
agent_kwargs["executor_kwargs"] = {"timeout_seconds": 660}
|
|
16397
16483
|
agent_kwargs["additional_authorized_imports"] = [
|
|
16398
|
-
"json", "base64", "urllib", "urllib.request", "urllib.error"
|
|
16484
|
+
"json", "base64", "re", "urllib", "urllib.request", "urllib.error"
|
|
16399
16485
|
]
|
|
16400
16486
|
# THE SYSTEM PROMPT IS THE API'S SCAFFOLD (task #246): the stock templates are loaded
|
|
16401
16487
|
# for everything else (planning, final-answer, managed agents) and ONLY system_prompt
|
|
@@ -16421,6 +16507,7 @@ def run_agent_chat(cfg):
|
|
|
16421
16507
|
_log(f"prompt scaffold code-agent {'local file' if _scaffold_source != 'api' else f'v{_scaffold_version}'}")
|
|
16422
16508
|
agent = _ToolAgent(**agent_kwargs)
|
|
16423
16509
|
_agent_ref["a"] = agent # let step_callback trim this agent's step memory (#63)
|
|
16510
|
+
_preimport_sandbox(agent)
|
|
16424
16511
|
# At the step budget the run ends WITHOUT final_answer (_maxsteps_partial hit). Offer
|
|
16425
16512
|
# to keep going instead of dead-ending (task #80): a terminal user says Yes → extend
|
|
16426
16513
|
# the budget to a large ceiling and CONTINUE with the existing memory (reset=False,
|
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
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
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
|
-
|
|
7415
|
-
|
|
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.
|
|
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.)
|
package/shell-details.mjs
CHANGED
|
@@ -368,13 +368,23 @@ export function markAnnounced(ids, { path = shellsPath() } = {}) {
|
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
/** The recap question the terminal asks for finished shells. */
|
|
371
|
-
export function recapQuestion(entries) {
|
|
371
|
+
export function recapQuestion(entries, { tailLines = 40 } = {}) {
|
|
372
372
|
const parts = entries.map(({ rec, st }) =>
|
|
373
373
|
`shell ${rec.id} ${statusText(st)} after ${fmtRuntime(st.runtime)} (${String(rec.command ?? "").replace(/\s+/g, " ").trim().slice(0, 120)})`);
|
|
374
374
|
const ids = entries.map(({ rec }) => `shell_output('${rec.id}')`).join(", ");
|
|
375
|
+
// GitHub #180 (turn review #389): every recap turn spent its first step on shell_output just to
|
|
376
|
+
// see the result. The end of each shell's output goes in the question itself; several finished
|
|
377
|
+
// shells share one question.
|
|
378
|
+
const tails = entries.map(({ rec }) => {
|
|
379
|
+
const t = rec.log ? logTail(rec.log, { lines: tailLines }) : [];
|
|
380
|
+
return t.length ? `\n--- end of shell ${rec.id} output ---\n${t.map((l) => l.slice(0, 300)).join("\n")}` : "";
|
|
381
|
+
}).join("");
|
|
382
|
+
const read = tails ? `The last lines of the output are below — call ${ids} only if you need more.`
|
|
383
|
+
: `Read the result with ${ids}.`;
|
|
375
384
|
// #376: come back to the work, not only report on it — a failed build is the next thing to fix,
|
|
376
385
|
// a finished one may be the step before the next; a recap only when nothing is left to do.
|
|
377
386
|
return `[gu: background ${entries.length === 1 ? "shell" : "shells"} finished — ${parts.join("; ")}] `
|
|
378
|
-
+
|
|
379
|
-
+ `were doing, carry on with the next step now. If nothing is left to do, tell me in one or two lines what happened
|
|
387
|
+
+ `${read} If it failed, find out why and fix it. If it was a step of the task you `
|
|
388
|
+
+ `were doing, carry on with the next step now. If nothing is left to do, tell me in one or two lines what happened.`
|
|
389
|
+
+ tails;
|
|
380
390
|
}
|