@tiens.nguyen/gu-cli 1.0.939 → 1.0.941

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 (68) hide show
  1. package/README.md +17 -7
  2. package/agent-deps-preflight.mjs +1 -1
  3. package/autocompact.mjs +2 -2
  4. package/browser-bridge.mjs +2 -2
  5. package/browser-chrome.mjs +2 -2
  6. package/browser-command.mjs +4 -4
  7. package/browser-extension/README.md +6 -6
  8. package/clear-logs.mjs +3 -3
  9. package/clear-state.mjs +3 -3
  10. package/cli-token.mjs +8 -8
  11. package/client-expert-api.mjs +9 -9
  12. package/client-expert-run.mjs +7 -7
  13. package/client-expert-setup.mjs +4 -4
  14. package/command-allow.mjs +1 -1
  15. package/conversation-archive.mjs +2 -2
  16. package/credential-recovery.mjs +1 -1
  17. package/daemon-control.mjs +4 -4
  18. package/device-login.mjs +3 -3
  19. package/free-model.mjs +1 -1
  20. package/full-log-command.mjs +1 -1
  21. package/gonext_agent_chat.py +160 -89
  22. package/gu-cli.mjs +55 -29
  23. package/gu-home-move.mjs +193 -0
  24. package/gu-repl.mjs +342 -59
  25. package/gu_browser.py +3 -3
  26. package/gu_free_budget.py +2 -2
  27. package/gu_gif.py +1 -1
  28. package/gu_hooks.py +1 -1
  29. package/gu_turn_notes.py +2 -2
  30. package/gu_turn_trail.py +138 -0
  31. package/gudb-size.mjs +198 -0
  32. package/hooks-config.mjs +4 -4
  33. package/image-paste.mjs +8 -8
  34. package/install-path.mjs +1 -1
  35. package/log-level.mjs +1 -1
  36. package/log-policy.mjs +1 -1
  37. package/lsp-host.mjs +2 -2
  38. package/lsp-registry.mjs +9 -9
  39. package/mcp-command.mjs +1 -1
  40. package/mcp-config.mjs +5 -5
  41. package/memory-task.mjs +85 -0
  42. package/model-doctor.mjs +10 -10
  43. package/mongo-mac.mjs +2 -2
  44. package/mongo-windows.mjs +3 -3
  45. package/next-suggestion.mjs +13 -8
  46. package/package.json +5 -1
  47. package/platform-tools.mjs +3 -3
  48. package/poll-errors.mjs +2 -2
  49. package/prompt_scaffold_check.py +1 -1
  50. package/proxy-store.mjs +1 -1
  51. package/python-unix.mjs +6 -6
  52. package/python-windows.mjs +1 -1
  53. package/rag-selftest.mjs +2 -2
  54. package/resume-memory.mjs +1 -1
  55. package/scripts/image-paste-check.mjs +1 -1
  56. package/setup-fixes.mjs +4 -4
  57. package/shell-details.mjs +2 -2
  58. package/skill-install.mjs +9 -9
  59. package/skill-package.mjs +10 -10
  60. package/skill-source.mjs +4 -4
  61. package/skills-copy.mjs +15 -15
  62. package/skills.mjs +4 -4
  63. package/support-bundle.mjs +6 -6
  64. package/support-report.mjs +5 -5
  65. package/terminal-layout.mjs +25 -1
  66. package/turn-notes.mjs +2 -2
  67. package/version-check.mjs +1 -1
  68. package/workspace-revert.mjs +2 -2
@@ -2495,7 +2495,7 @@ def _looks_like_scratchpad(stripped: str) -> bool:
2495
2495
  # THE CODE-AGENT SCAFFOLD IS NOT IN THIS FILE (task #246). The fixed system prompt — the
2496
2496
  # Thought → Code → Observation rules that replace smolagents' stock ~9.9k-char template — is served
2497
2497
  # by the API (GET /api/worker/prompt-scaffold) and never shipped in the gu package. The worker
2498
- # gets it once per job — from ~/.gonext/prompt-scaffolds/code-agent.txt if YOU put one there (gu
2498
+ # gets it once per job — from ~/.gu/prompt-scaffolds/code-agent.txt if YOU put one there (gu
2499
2499
  # never writes it), else from the API — and if it cannot, the turn stops with the reason. There is
2500
2500
  # no bundled copy to fall back to: the point is that the text is not in what gu ships.
2501
2501
  #
@@ -2522,11 +2522,11 @@ _SCAFFOLD_REQUIRED = _psc.SCAFFOLD_REQUIRED
2522
2522
  # client name with error 1010 before the API sees the request. Every direct call to the gu service
2523
2523
  # names itself instead; the default API host (chat-api-v2) is not behind Cloudflare, gucli.com is.
2524
2524
  def _internal_label() -> str:
2525
- """Our own machines only: GU_INTERNAL_LABEL or ~/.gonext/internal-label (real users have neither)."""
2525
+ """Our own machines only: GU_INTERNAL_LABEL or ~/.gu/internal-label (real users have neither)."""
2526
2526
  v = os.environ.get("GU_INTERNAL_LABEL", "").strip()
2527
2527
  if not v:
2528
2528
  try:
2529
- v = open(os.path.join(os.path.expanduser("~"), ".gonext", "internal-label"), encoding="utf-8").read().strip()
2529
+ v = open(os.path.join(os.path.expanduser("~"), ".gu", "internal-label"), encoding="utf-8").read().strip()
2530
2530
  except OSError:
2531
2531
  v = ""
2532
2532
  return re.sub(r"[^A-Za-z0-9._-]", "", v)[:40]
@@ -2538,7 +2538,7 @@ _GU_UA = "gu-agent/1.0 (+https://gucli.com" + (f"; internal:{_internal_label()}"
2538
2538
  def _load_prompt_scaffold(api_base: str, worker_key: str):
2539
2539
  """The scaffold for this turn → (template, version, source).
2540
2540
 
2541
- YOUR LOCAL FILE FIRST (~/.gonext/prompt-scaffolds/code-agent.txt): when it exists it is used and
2541
+ YOUR LOCAL FILE FIRST (~/.gu/prompt-scaffolds/code-agent.txt): when it exists it is used and
2542
2542
  the API is not asked. Otherwise the API's version (the database's). Either way it passes the
2543
2543
  three checks in _scaffold_problem, and a failure stops the turn with the reason — a broken local
2544
2544
  file is NOT quietly replaced by the database version, or an edit that broke it would look like
@@ -3562,7 +3562,7 @@ def _repair_request(kwargs: dict, err):
3562
3562
 
3563
3563
 
3564
3564
  def _shape_path() -> str:
3565
- return os.path.join(os.path.expanduser("~"), ".gonext", "request-shapes.json")
3565
+ return os.path.join(os.path.expanduser("~"), ".gu", "request-shapes.json")
3566
3566
 
3567
3567
 
3568
3568
  def _shape_entries() -> dict:
@@ -4644,7 +4644,7 @@ def _ctx_learned_path() -> str:
4644
4644
  forget. Persisting turns that into once ever — which is what "we should not have to tell it"
4645
4645
  actually requires.
4646
4646
  """
4647
- return os.path.join(os.path.expanduser("~"), ".gonext", "context-windows.json")
4647
+ return os.path.join(os.path.expanduser("~"), ".gu", "context-windows.json")
4648
4648
 
4649
4649
 
4650
4650
  def _load_learned_windows() -> dict:
@@ -4701,7 +4701,7 @@ _UNKNOWN_CTX_COMPACT_AT = 24000
4701
4701
 
4702
4702
  def _autocompact_path() -> str:
4703
4703
  """The user's autocompact choice (GH #538), written by gu's startup question and /autocompact."""
4704
- return os.path.join(os.path.expanduser("~"), ".gonext", "autocompact.json")
4704
+ return os.path.join(os.path.expanduser("~"), ".gu", "autocompact.json")
4705
4705
 
4706
4706
 
4707
4707
  def _autocompact_cap(model_id: str = "") -> int:
@@ -6632,7 +6632,7 @@ def _rag_source_key(url: str) -> str:
6632
6632
  def _rag_known_sources() -> list:
6633
6633
  """Every knowledge base that exists for THIS folder, by its original key.
6634
6634
 
6635
- The keys on disk are hashes (~/.gonext/rag/<sha(activeFolder)>/<sha(sourceKey)>/), so they
6635
+ The keys on disk are hashes (~/.gu/rag/<sha(activeFolder)>/<sha(sourceKey)>/), so they
6636
6636
  cannot be reversed — but each index writes a manifest carrying "sourceUrl", the key as it
6637
6637
  was given. Reading those back is the only way to answer "what IS indexed here?", which is
6638
6638
  what turns "No knowledge base found" from a dead end into something actionable.
@@ -6648,7 +6648,7 @@ def _rag_known_sources() -> list:
6648
6648
  try:
6649
6649
  folder = _WS_ACTIVE or os.getcwd()
6650
6650
  fhash = hashlib.sha256(os.path.realpath(folder).encode("utf-8")).hexdigest()[:32]
6651
- base = os.path.join(os.path.expanduser("~"), ".gonext", "rag", fhash)
6651
+ base = os.path.join(os.path.expanduser("~"), ".gu", "rag", fhash)
6652
6652
  out = []
6653
6653
  for name in sorted(os.listdir(base)):
6654
6654
  mpath = os.path.join(base, name, "manifest.json")
@@ -6755,7 +6755,7 @@ def _rag_assert_safe_url(url: str) -> None:
6755
6755
 
6756
6756
  def _rag_workdir(source_key: str) -> str:
6757
6757
  import os
6758
- base = os.path.join(os.path.expanduser("~"), ".gonext", "rag-work", source_key)
6758
+ base = os.path.join(os.path.expanduser("~"), ".gu", "rag-work", source_key)
6759
6759
  os.makedirs(base, exist_ok=True)
6760
6760
  return base
6761
6761
 
@@ -6763,7 +6763,7 @@ def _rag_workdir(source_key: str) -> str:
6763
6763
  def _rag_base_dir(source_key: str) -> str:
6764
6764
  """Where a URL's downloaded/unzipped files should live. Prefer the active terminal
6765
6765
  workspace (the folder the `gu` REPL was opened from) so files land in the
6766
- user's project; otherwise fall back to the per-URL cache dir under ~/.gonext."""
6766
+ user's project; otherwise fall back to the per-URL cache dir under ~/.gu."""
6767
6767
  import os
6768
6768
  if _WS_ACTIVE:
6769
6769
  os.makedirs(_WS_ACTIVE, exist_ok=True)
@@ -7004,14 +7004,14 @@ def _rag_resolve_embed_model(configured: str, served: str) -> str:
7004
7004
 
7005
7005
  def _rag_local_index_dir(source_url: str) -> str:
7006
7006
  """Local RAG index dir for a source, scoped PER-FOLDER (task #97): the vector shards
7007
- live at ~/.gonext/rag/<sha256(activeFolder)>/<sha256(sourceUrl)>/. Keying on the active
7007
+ live at ~/.gu/rag/<sha256(activeFolder)>/<sha256(sourceUrl)>/. Keying on the active
7008
7008
  terminal folder (the SAME sha256 scheme the REPL uses for its session files) isolates
7009
7009
  each project's knowledge base, so the same URL indexed from two folders stays separate."""
7010
7010
  import hashlib
7011
7011
  import os
7012
7012
  folder = _WS_ACTIVE or os.getcwd()
7013
7013
  fhash = hashlib.sha256(os.path.realpath(folder).encode("utf-8")).hexdigest()[:32]
7014
- base = os.path.join(os.path.expanduser("~"), ".gonext", "rag", fhash,
7014
+ base = os.path.join(os.path.expanduser("~"), ".gu", "rag", fhash,
7015
7015
  _rag_source_key(source_url))
7016
7016
  os.makedirs(base, exist_ok=True)
7017
7017
  return base
@@ -7019,7 +7019,7 @@ def _rag_local_index_dir(source_url: str) -> str:
7019
7019
 
7020
7020
  def _rag_download(url: str, dest_path: str = "") -> tuple:
7021
7021
  """Download a public URL with SSRF + size guards — IDEMPOTENT per URL. Every URL
7022
- maps to a deterministic work dir (~/.gonext/rag-work/<urlHash>/); relative
7022
+ maps to a deterministic work dir (~/.gu/rag-work/<urlHash>/); relative
7023
7023
  dest_paths are contained there (never the process cwd, which is the user's home),
7024
7024
  and a repeat call for an already-downloaded URL reuses the cached file instantly
7025
7025
  (follow-up questions re-run the pipeline cheaply). Returns (path, cached)."""
@@ -7089,7 +7089,7 @@ def _rag_resolve_zip(zip_path: str) -> str:
7089
7089
  if os.path.isfile(cand):
7090
7090
  return cand
7091
7091
  hits = _glob.glob(os.path.join(
7092
- os.path.expanduser("~"), ".gonext", "rag-work", "*", base))
7092
+ os.path.expanduser("~"), ".gu", "rag-work", "*", base))
7093
7093
  if hits:
7094
7094
  return hits[0]
7095
7095
  return zp
@@ -7219,7 +7219,7 @@ def _rag_iter_text_files(root: str):
7219
7219
 
7220
7220
  def _rg_binary(env=None):
7221
7221
  """The ripgrep to use, or "" for none. GU_RG=0 turns it off; GU_RG=<path> picks one; then PATH,
7222
- then gu's own copy in ~/.gonext/bin."""
7222
+ then gu's own copy in ~/.gu/bin."""
7223
7223
  import os
7224
7224
  env = os.environ if env is None else env
7225
7225
  want = (env.get("GU_RG") or "").strip()
@@ -7238,7 +7238,7 @@ def _rg_binary(env=None):
7238
7238
  cand = os.path.join(d, exe)
7239
7239
  if os.path.isfile(cand) and os.access(cand, os.X_OK):
7240
7240
  return cand
7241
- own = os.path.join(os.path.expanduser("~"), ".gonext", "bin", exe)
7241
+ own = os.path.join(os.path.expanduser("~"), ".gu", "bin", exe)
7242
7242
  return own if os.path.isfile(own) and os.access(own, os.X_OK) else ""
7243
7243
 
7244
7244
 
@@ -7731,14 +7731,14 @@ def _rag_parse_location(loc: str):
7731
7731
  return bucket, prefix.strip("/")
7732
7732
 
7733
7733
 
7734
- # Registered workspace roots (from ~/.gonext/workspaces.json via the worker) — set
7734
+ # Registered workspace roots (from ~/.gu/workspaces.json via the worker) — set
7735
7735
  # per-run by run_agent_chat. Reads are allowed in any of them; WRITES additionally
7736
7736
  # require _ws_write_allowed (workspace root + not inside .git/).
7737
7737
  _WS_ROOTS: list = [] # [{"name": str, "path": realpath str, "allowRun": bool}]
7738
7738
 
7739
7739
  # The active terminal workspace: the folder the `gu` REPL was launched from
7740
7740
  # (passed through as payload.activeWorkspace). When set, download_file/unzip_file put
7741
- # their output HERE instead of the shared ~/.gonext/rag-work cache, so files land in
7741
+ # their output HERE instead of the shared ~/.gu/rag-work cache, so files land in
7742
7742
  # the user's actual project folder. Only honoured if it's a registered workspace root.
7743
7743
  _WS_ACTIVE: str = ""
7744
7744
 
@@ -7794,7 +7794,7 @@ def _ws_strip_echoed_root(base: str, rel: str, need_parent: bool = False) -> str
7794
7794
 
7795
7795
 
7796
7796
  def _rag_read_allowed(path: str) -> str:
7797
- """Resolve `path` and ensure it stays within a safe root (temp dir, ~/.gonext, the
7797
+ """Resolve `path` and ensure it stays within a safe root (temp dir, ~/.gu, the
7798
7798
  active terminal folder, or a registered workspace) — so the agent's file tools can't
7799
7799
  read arbitrary files like ~/.ssh. Relative paths anchor to the terminal workspace
7800
7800
  (where downloads/unzips land), because the model routinely passes bare names like
@@ -7804,7 +7804,7 @@ def _rag_read_allowed(path: str) -> str:
7804
7804
  daemon is often launched from ~/Projects (the PARENT of every workspace), so trusting
7805
7805
  os.getcwd() let `grep_repo(path="/Users/joseph/Projects")` read EVERY project on disk
7806
7806
  — including other repos' secrets. Reads are confined to the registered/active
7807
- workspaces + ~/.gonext + the temp dir. Fail-closed: no workspace ⇒ no repo reads."""
7807
+ workspaces + ~/.gu + the temp dir. Fail-closed: no workspace ⇒ no repo reads."""
7808
7808
  import os
7809
7809
  import tempfile
7810
7810
  expanded = os.path.expanduser((path or "").strip())
@@ -7820,7 +7820,7 @@ def _rag_read_allowed(path: str) -> str:
7820
7820
  rp = os.path.realpath(expanded)
7821
7821
  roots = [
7822
7822
  os.path.realpath(tempfile.gettempdir()),
7823
- os.path.realpath(os.path.join(os.path.expanduser("~"), ".gonext")),
7823
+ os.path.realpath(os.path.join(os.path.expanduser("~"), ".gu")),
7824
7824
  ] + [w["path"] for w in _WS_ROOTS]
7825
7825
  # The active terminal folder (download/unzip target) — allow reading what we just
7826
7826
  # extracted there, even when it isn't a registered workspace.
@@ -7917,13 +7917,13 @@ def _workspace_overview(roots, max_entries: int = 40) -> str:
7917
7917
  def _turn_checkpoint_path(workspace: str) -> str:
7918
7918
  """Path to the interrupted-turn checkpoint for a given workspace. Keyed by a hash
7919
7919
  of the workspace path (same sha256-slice convention as _rag_source_key) — but a
7920
- separate file/purpose from the REPL's own ~/.gonext/sessions: this holds one
7920
+ separate file/purpose from the REPL's own ~/.gu/sessions: this holds one
7921
7921
  in-PROGRESS turn's step trace, written incrementally as the agent works, not
7922
7922
  completed Q&A history."""
7923
7923
  import hashlib
7924
7924
  import os
7925
7925
  h = hashlib.sha256(workspace.encode("utf-8")).hexdigest()[:32]
7926
- base = os.path.join(os.path.expanduser("~"), ".gonext", "agent-turns")
7926
+ base = os.path.join(os.path.expanduser("~"), ".gu", "agent-turns")
7927
7927
  os.makedirs(base, exist_ok=True)
7928
7928
  return os.path.join(base, f"{h}.json")
7929
7929
 
@@ -7960,7 +7960,7 @@ def _load_turn_checkpoint(workspace: str):
7960
7960
  That window is not theoretical: it is the reported bug. Changing the coding model is
7961
7961
  exactly what makes a turn die before step 1 — a new coder with a missing or stale API
7962
7962
  key, or a name the server does not have, raises on the FIRST model call. The user saw
7963
- ~/.gonext/agent-turns emptied "only when I change model" and concluded the model
7963
+ ~/.gu/agent-turns emptied "only when I change model" and concluded the model
7964
7964
  switch deleted it; nothing on that path touches the file. The consume did, on behalf
7965
7965
  of a turn that never ran.
7966
7966
 
@@ -8301,7 +8301,7 @@ def _ws_backup_root() -> str:
8301
8301
  import time as _t
8302
8302
  if _WS_RUN_ID is None:
8303
8303
  _WS_RUN_ID = _t.strftime("%Y%m%d-%H%M%S", _t.localtime())
8304
- root = os.path.join(os.path.expanduser("~"), ".gonext", "workspace-backups", _WS_RUN_ID)
8304
+ root = os.path.join(os.path.expanduser("~"), ".gu", "workspace-backups", _WS_RUN_ID)
8305
8305
  os.makedirs(root, exist_ok=True)
8306
8306
  return root
8307
8307
 
@@ -8316,7 +8316,7 @@ _KILL_BY_NAME_RE = re.compile(
8316
8316
  r"(?:pkill|killall)\s+(?:-\S+\s+)*['\"]?|get-process\s+(?:-name\s+)?['\"]?)"
8317
8317
  r"(node|python|python3|py|pythonw|gu|gu-cli|gu-repl)(?:\.exe)?\b")
8318
8318
  _GU_OWN_CMD_RE = re.compile(
8319
- r"(?i)(gu-repl\.mjs|gu-cli\.mjs|gonext_agent_chat\.py|gu-local-worker|[\\/]\.gonext[\\/]api[\\/])")
8319
+ r"(?i)(gu-repl\.mjs|gu-cli\.mjs|gonext_agent_chat\.py|gu-local-worker|[\\/]\.gu[\\/]api[\\/])")
8320
8320
 
8321
8321
 
8322
8322
  def _gu_kill_refusal(command: str, own: dict) -> str:
@@ -8339,10 +8339,10 @@ def _gu_kill_refusal(command: str, own: dict) -> str:
8339
8339
 
8340
8340
  def _gu_own_processes() -> dict:
8341
8341
  """pid → what it is, for every process that is gu: this turn and its parent, the pid files
8342
- in ~/.gonext, and any process whose command line is gu's (the REPL, the worker, the API)."""
8342
+ in ~/.gu, and any process whose command line is gu's (the REPL, the worker, the API)."""
8343
8343
  import subprocess
8344
8344
  own = {os.getpid(): "this turn", os.getppid(): "the gu worker running this turn"}
8345
- gdir = os.path.join(os.path.expanduser("~"), ".gonext")
8345
+ gdir = os.path.join(os.path.expanduser("~"), ".gu")
8346
8346
  for name, what in (("local-api.pid", "gu's local API"), ("worker.pid", "the gu worker")):
8347
8347
  try:
8348
8348
  with open(os.path.join(gdir, name), encoding="utf-8") as fh:
@@ -9056,7 +9056,7 @@ def _ws_shell_command_risk(scan, denyset, wd="", allowset=None, roots=None, env_
9056
9056
  cur = os.path.normpath(os.path.join(cur or os.getcwd(),
9057
9057
  os.path.expanduser(_shell_path_to_native(a[1]))))
9058
9058
  cwds[id(c)] = cur
9059
- # GH #515: gu sources <workspace>/.gonext/env ITSELF before every line (#181), so a line that sources
9059
+ # GH #515: gu sources <workspace>/.gu/env ITSELF before every line (#181), so a line that sources
9060
9060
  # that same file adds nothing — never ask. Another file the user said yes to for good is not asked
9061
9061
  # while it is unchanged, and only when nothing but `cd` (or such sources) runs before it in the line:
9062
9062
  # anything else could rewrite it first.
@@ -9229,7 +9229,7 @@ def _ws_ps_command_risk(scan, denyset, wd="", allowset=None, roots=None):
9229
9229
  return (None, None, None)
9230
9230
 
9231
9231
 
9232
- def _with_attribution_text(command, scan, settings):
9232
+ def _with_attribution_text(command, scan, settings, powershell=False):
9233
9233
  """_with_attribution for a SHELL line: the co-author trailer is inserted into the text right
9234
9234
  after each top-level `git … commit` word. → (command, note). A gh pr create body written as a
9235
9235
  heredoc cannot be appended to safely, so it is left alone and said so in the note."""
@@ -9251,6 +9251,31 @@ def _with_attribution_text(command, scan, settings):
9251
9251
  notes.append(f"co-author trailer added ({name})")
9252
9252
  if settings.get("pr") and any(c["argv"][:3] == ["gh", "pr", "create"] for c in cmds):
9253
9253
  notes.append("PR footer not added (shell form)")
9254
+ # A comment's --body in a bash line: its literal text is re-quoted with the co-author line added.
9255
+ # Only when the word has no $ or ` (the shell would expand those) and only for bash: PowerShell
9256
+ # quotes differently. A body from a file or heredoc is left alone, and the note says so.
9257
+ footer = _comment_footer(settings)
9258
+ if footer and not powershell:
9259
+ edits = []
9260
+ for c in cmds:
9261
+ verb = _gh_verb(c["argv"])
9262
+ if verb not in _GH_COMMENTS:
9263
+ continue
9264
+ at = _body_at(c["argv"])
9265
+ if not at or footer in at[1] or (email and email.lower() in at[1].lower()):
9266
+ if not at:
9267
+ notes.append(f"co-author line not added ({verb[0]} {verb[1]} body from a file)")
9268
+ continue
9269
+ k, body, inline = at
9270
+ a, b = c["spans"][k]
9271
+ if "$" in command[a:b] or "`" in command[a:b]:
9272
+ notes.append(f"co-author line not added ({verb[0]} {verb[1]} body uses $ or `)")
9273
+ continue
9274
+ new = body.rstrip() + f"\n\n{footer}"
9275
+ edits.append((a, b, _shlex.quote("--body=" + new if inline else new)))
9276
+ notes.append(f"co-author line added to the {verb[0]} {verb[1]} ({name})")
9277
+ for a, b, text in sorted(edits, reverse=True):
9278
+ command = command[:a] + text + command[b:]
9254
9279
  return command, "; ".join(notes)
9255
9280
 
9256
9281
 
@@ -9458,10 +9483,10 @@ _BG_LINE = ("A LONG job (build, deploy, big test run) → run_command(…, backg
9458
9483
  "polls; a build whose result you need next is simpler as one run_command(…, "
9459
9484
  "timeout_seconds=600). A command still running at its timeout moves to the background "
9460
9485
  "by itself instead of being killed. Setup every command needs (exports) goes ONCE in "
9461
- "<workspace>/.gonext/env, which gu sources before each command by itself (never `source` "
9486
+ "<workspace>/.gu/env, which gu sources before each command by itself (never `source` "
9462
9487
  "it in a command). A recipe that WORKED "
9463
9488
  "after effort (a login, build flags, a deploy path) or a short project summary goes as "
9464
- "ONE line in <workspace>/.gonext/notes.md, shown at the start of every later turn.\n")
9489
+ "ONE line in <workspace>/.gu/notes.md, shown at the start of every later turn.\n")
9465
9490
 
9466
9491
 
9467
9492
  # What to do instead, said where quoting broke — in gu's own pre-check (an unbalanced quote never
@@ -9614,12 +9639,12 @@ _WS_NOTES_CAP = 1500
9614
9639
 
9615
9640
 
9616
9641
  def _ws_notes_line(root: str, cap: int = _WS_NOTES_CAP) -> str:
9617
- """<workspace>/.gonext/notes.md shown in every turn's context (GitHub #184, turn review #389):
9642
+ """<workspace>/.gu/notes.md shown in every turn's context (GitHub #184, turn review #389):
9618
9643
  a recipe that worked (turn #7 spent ~15 steps rediscovering turn #6's App Store login) and a
9619
9644
  short project summary (turns #4/#5/#8 each re-read the same docs). Capped; "" when absent."""
9620
9645
  if not root:
9621
9646
  return ""
9622
- p = os.path.join(root, ".gonext", "notes.md")
9647
+ p = os.path.join(root, ".gu", "notes.md")
9623
9648
  try:
9624
9649
  with open(p, encoding="utf-8", errors="replace") as fh:
9625
9650
  txt = fh.read(cap + 1).strip()
@@ -9629,7 +9654,7 @@ def _ws_notes_line(root: str, cap: int = _WS_NOTES_CAP) -> str:
9629
9654
  return ""
9630
9655
  if len(txt) > cap:
9631
9656
  txt = txt[:cap].rstrip() + " …(cut — keep notes.md short)"
9632
- return (" WORKSPACE NOTES (.gonext/notes.md — recipes and facts saved by earlier turns; use them "
9657
+ return (" WORKSPACE NOTES (.gu/notes.md — recipes and facts saved by earlier turns; use them "
9633
9658
  "before rediscovering):\n" + "\n".join(f" {l}" for l in txt.splitlines()) + "\n")
9634
9659
 
9635
9660
 
@@ -10180,11 +10205,37 @@ def _ws_delete_outside_reason(argv, wd, roots=None):
10180
10205
  # run_command itself (after the risk gate, just before the spawn), not left to the model: a rule
10181
10206
  # in the prompt is followed most of the time. Only commits gu makes; the user's own are untouched.
10182
10207
  #
10183
- # Settings, ~/.gonext/settings.json then <project>/.gonext/settings.json (the project wins):
10208
+ # Settings, ~/.gu/settings.json then <project>/.gu/settings.json (the project wins):
10184
10209
  # "attribution": {"commit": true, "pr": true, "name": "gu", "email": "…"}
10185
- _ATTRIBUTION_DEFAULT = {"commit": True, "pr": True, "name": "gu",
10210
+ _ATTRIBUTION_DEFAULT = {"commit": True, "pr": True, "comment": True, "name": "gu",
10186
10211
  "email": "334027377+gu-marsic-agent@users.noreply.github.com"}
10187
10212
  _PR_FOOTER = "Generated with gu"
10213
+ # Comments and issues gu writes on GitHub end with the same co-author line as its commits, so a board
10214
+ # (sunday#37) can show gu next to the person who posted them. "comment": false in the settings turns it off.
10215
+ _GH_COMMENTS = (("issue", "comment"), ("pr", "comment"), ("issue", "create"))
10216
+
10217
+
10218
+ def _gh_verb(argv):
10219
+ """("pr", "create"), ("issue", "comment")… for a gh command, else None."""
10220
+ if len(argv) >= 3 and os.path.basename(str(argv[0])).lower() in ("gh", "gh.exe"):
10221
+ return (argv[1], argv[2])
10222
+ return None
10223
+
10224
+
10225
+ def _comment_footer(settings):
10226
+ name = str(settings.get("name") or "").strip()
10227
+ email = str(settings.get("email") or "").strip()
10228
+ return f"Co-Authored-By: {name} <{email}>" if settings.get("comment") and name and email else ""
10229
+
10230
+
10231
+ def _body_at(argv):
10232
+ """(index, value, is "--body=" form) of the body given on the command line, or None."""
10233
+ for k, a in enumerate(argv):
10234
+ if a in ("--body", "-b") and k + 1 < len(argv):
10235
+ return k + 1, argv[k + 1], False
10236
+ if a.startswith("--body="):
10237
+ return k, a[len("--body="):], True
10238
+ return None
10188
10239
  _GIT_GLOBAL_WITH_VALUE = {"-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path",
10189
10240
  "--super-prefix", "--config-env"}
10190
10241
 
@@ -10193,12 +10244,12 @@ def _attribution_settings(wd="", home=None, roots=None):
10193
10244
  """The attribution settings in force for a command run in `wd`."""
10194
10245
  out = dict(_ATTRIBUTION_DEFAULT)
10195
10246
  home = home or os.path.expanduser("~")
10196
- places = [os.path.join(home, ".gonext", "settings.json")]
10247
+ places = [os.path.join(home, ".gu", "settings.json")]
10197
10248
  wd_real = os.path.realpath(wd) if wd else ""
10198
10249
  for r in (_WS_ROOTS if roots is None else roots):
10199
10250
  p = os.path.realpath(r.get("path") or "")
10200
10251
  if p and wd_real and (wd_real == p or wd_real.startswith(p.rstrip(os.sep) + os.sep)):
10201
- places.append(os.path.join(p, ".gonext", "settings.json"))
10252
+ places.append(os.path.join(p, ".gu", "settings.json"))
10202
10253
  break
10203
10254
  for path in places:
10204
10255
  try:
@@ -10233,7 +10284,8 @@ def _with_attribution(argv, settings):
10233
10284
 
10234
10285
  git commit → `--trailer "Co-Authored-By: gu <email>"` (git ≥ 2.32; git places it after any
10235
10286
  other trailers and skips it when the same one is already last). Skipped when the message
10236
- already names that email (the model wrote it itself). gh pr create → a footer on --body.
10287
+ already names that email (the model wrote it itself). gh pr create → a footer on --body;
10288
+ gh issue comment / pr comment / issue create → the same co-author line at the end of --body.
10237
10289
  """
10238
10290
  argv = list(argv)
10239
10291
  name = str(settings.get("name") or "").strip()
@@ -10244,30 +10296,30 @@ def _with_attribution(argv, settings):
10244
10296
  return argv, ""
10245
10297
  return argv[:i + 1] + ["--trailer", f"Co-Authored-By: {name} <{email}>"] + argv[i + 1:], \
10246
10298
  f"co-author trailer added ({name})"
10247
- if (argv[:3] == ["gh", "pr", "create"] or (argv and os.path.basename(argv[0]).lower() == "gh.exe"
10248
- and argv[1:3] == ["pr", "create"])) and settings.get("pr"):
10249
- for k, a in enumerate(argv):
10250
- if a in ("--body", "-b") and k + 1 < len(argv):
10251
- if _PR_FOOTER not in argv[k + 1]:
10252
- argv[k + 1] = argv[k + 1].rstrip() + f"\n\n{_PR_FOOTER}"
10253
- return argv, "PR footer added"
10254
- return argv, ""
10255
- if a.startswith("--body="):
10256
- if _PR_FOOTER not in a:
10257
- argv[k] = a.rstrip() + f"\n\n{_PR_FOOTER}"
10258
- return argv, "PR footer added"
10259
- return argv, ""
10299
+ verb = _gh_verb(argv)
10300
+ footer, note = "", ""
10301
+ if verb == ("pr", "create") and settings.get("pr"):
10302
+ footer, note = _PR_FOOTER, "PR footer added"
10303
+ elif verb in _GH_COMMENTS:
10304
+ footer, note = _comment_footer(settings), f"co-author line added to the {verb[0]} {verb[1]} ({name})"
10305
+ if footer:
10306
+ at = _body_at(argv)
10307
+ if at and footer not in at[1] and not (email and email.lower() in at[1].lower()):
10308
+ k, body, inline = at
10309
+ body = body.rstrip() + f"\n\n{footer}"
10310
+ argv[k] = ("--body=" + body) if inline else body
10311
+ return argv, note
10260
10312
  return argv, ""
10261
10313
 
10262
10314
 
10263
- # GH #215: "Yes, always in this folder" for the SOFT destructive question. ~/.gonext/command-allow.json
10315
+ # GH #215: "Yes, always in this folder" for the SOFT destructive question. ~/.gu/command-allow.json
10264
10316
  # ({"folders": [...]}) is written by the terminal (command-allow.mjs). It never covers a hard reason
10265
10317
  # (sudo, denylist, delete outside the project) - those keep asking.
10266
10318
  _CMD_ALLOW_ASK = "a destructive command"
10267
10319
 
10268
10320
 
10269
10321
  def _cmd_allow_path():
10270
- return os.environ.get("GU_COMMAND_ALLOW") or os.path.join(os.path.expanduser("~"), ".gonext", "command-allow.json")
10322
+ return os.environ.get("GU_COMMAND_ALLOW") or os.path.join(os.path.expanduser("~"), ".gu", "command-allow.json")
10271
10323
 
10272
10324
 
10273
10325
  def _cmd_source_allowed(path, wd):
@@ -10423,7 +10475,7 @@ def _ws_request_approval(api_base, worker_key, job_id, command, reason, deadline
10423
10475
  # bun dev, a custom `make serve`, anything. (An earlier version pattern-matched command
10424
10476
  # names like "npm start"; rejected as unwinnable hardcode — same lesson as task #37.)
10425
10477
  # Detected servers are left running in their own process group (start_new_session),
10426
- # recorded in ~/.gonext/servers.json, and stoppable via the stop_server tool.
10478
+ # recorded in ~/.gu/servers.json, and stoppable via the stop_server tool.
10427
10479
 
10428
10480
 
10429
10481
  # Windows has no process groups in the POSIX sense, no pgrep, and no lsof — and os.setsid /
@@ -10808,7 +10860,7 @@ def _ws_gui_pids(pgid: int) -> list:
10808
10860
 
10809
10861
  def _ws_servers_path() -> str:
10810
10862
  import os
10811
- base = os.path.join(os.path.expanduser("~"), ".gonext")
10863
+ base = os.path.join(os.path.expanduser("~"), ".gu")
10812
10864
  os.makedirs(base, exist_ok=True)
10813
10865
  return os.path.join(base, "servers.json")
10814
10866
 
@@ -10883,7 +10935,7 @@ _FG_SHELL_AFTER_S = 4 # a foreground command shows up as a shell after this man
10883
10935
 
10884
10936
  def _shells_path() -> str:
10885
10937
  import os
10886
- base = os.path.join(os.path.expanduser("~"), ".gonext")
10938
+ base = os.path.join(os.path.expanduser("~"), ".gu")
10887
10939
  os.makedirs(base, exist_ok=True)
10888
10940
  return os.path.join(base, "shells.json")
10889
10941
 
@@ -11250,7 +11302,7 @@ def _run_state_path() -> str:
11250
11302
  import atexit
11251
11303
  import time as _t
11252
11304
  if not _RUN_STATE["path"]:
11253
- d = os.path.join(os.path.expanduser("~"), ".gonext", "run-state")
11305
+ d = os.path.join(os.path.expanduser("~"), ".gu", "run-state")
11254
11306
  os.makedirs(d, exist_ok=True)
11255
11307
  # A background shell that ends after its turn rewrites its file; sweep day-old ones.
11256
11308
  try:
@@ -11369,20 +11421,20 @@ def _run_state_set_cwd(cwd: str) -> None:
11369
11421
 
11370
11422
 
11371
11423
  def _ws_env_file(root: str = "") -> str:
11372
- """<workspace>/.gonext/env when it exists, else "" (GitHub #181, turn review #389): the setup
11424
+ """<workspace>/.gu/env when it exists, else "" (GitHub #181, turn review #389): the setup
11373
11425
  every command needs (`export DEVELOPER_DIR=…; export LC_ALL=…`) is written there ONCE and
11374
11426
  sourced before each run_command line, instead of being repeated on every call."""
11375
11427
  try:
11376
11428
  root = root or _default_ws_root()
11377
11429
  except Exception: # noqa: BLE001
11378
11430
  return ""
11379
- p = os.path.join(root or "", ".gonext", "env")
11431
+ p = os.path.join(root or "", ".gu", "env")
11380
11432
  return p if root and os.path.isfile(p) else ""
11381
11433
 
11382
11434
 
11383
11435
  def _run_state_wrapper() -> str:
11384
11436
  """The outer script: $1 the line, $2 the exit file, $3 the state file, $4 the env file."""
11385
- # $4: the workspace's .gonext/env (GitHub #181) — sourced first, so this turn's own exports win.
11437
+ # $4: the workspace's .gu/env (GitHub #181) — sourced first, so this turn's own exports win.
11386
11438
  return ('[ -n "$4" ] && [ -f "$4" ] && . "$4" >/dev/null 2>&1; [ -f "$3" ] && . "$3" >/dev/null 2>&1; '
11387
11439
  "trap '__gu_rc=$?; echo $__gu_rc > \"$2\"; "
11388
11440
  f"export -p | grep -vE \"{_RUN_STATE_SKIP}\" > \"$3.tmp\" 2>/dev/null && mv -f \"$3.tmp\" \"$3\"; "
@@ -11410,11 +11462,11 @@ def _ws_scrubbed_env() -> dict:
11410
11462
  # PowerShell finds its own modules (Microsoft.PowerShell.*) through it (#374).
11411
11463
  "PSModulePath")
11412
11464
  env = {k: os.environ[k] for k in keep if k in os.environ}
11413
- # gu's own Python environment (~/.gonext/venv) FIRST on PATH: the document skills (xlsx, pptx, docx, pdf) are run as
11465
+ # gu's own Python environment (~/.gu/venv) FIRST on PATH: the document skills (xlsx, pptx, docx, pdf) are run as
11414
11466
  # `python scripts/...` and their libraries were installed there by `gu-cli deps`. Without this a bare `python` is the
11415
11467
  # system one (on Windows 11 often the Microsoft Store stub) and every import fails.
11416
11468
  try:
11417
- venv_bin = os.path.join(os.path.expanduser("~"), ".gonext", "venv", "Scripts" if os.name == "nt" else "bin")
11469
+ venv_bin = os.path.join(os.path.expanduser("~"), ".gu", "venv", "Scripts" if os.name == "nt" else "bin")
11418
11470
  if os.path.isdir(venv_bin):
11419
11471
  env["PATH"] = venv_bin + os.pathsep + env.get("PATH", "")
11420
11472
  env["VIRTUAL_ENV"] = os.path.dirname(venv_bin)
@@ -11422,7 +11474,7 @@ def _ws_scrubbed_env() -> dict:
11422
11474
  pass
11423
11475
  # The docx / pptx skills `require('docx')` / `require('pptxgenjs')`; `gu-cli deps` installs them here.
11424
11476
  try:
11425
- node_libs = os.path.join(os.path.expanduser("~"), ".gonext", "node-libs", "node_modules")
11477
+ node_libs = os.path.join(os.path.expanduser("~"), ".gu", "node-libs", "node_modules")
11426
11478
  if os.path.isdir(node_libs):
11427
11479
  env["NODE_PATH"] = node_libs + (os.pathsep + env["NODE_PATH"] if env.get("NODE_PATH") else "")
11428
11480
  except Exception:
@@ -11552,10 +11604,10 @@ def _rag_s3_client(region: str, akid: str, secret: str):
11552
11604
 
11553
11605
 
11554
11606
  # PASTED IMAGES (task #284). The REPL sends "[Image #1: <file>]" in the message text (the API
11555
- # passes text only); the file is in ~/.gonext/images, copied there at paste time. The CURRENT
11607
+ # passes text only); the file is in ~/.gu/images, copied there at paste time. The CURRENT
11556
11608
  # question's images are attached to the request for a Claude coder (the adapter turns them into
11557
11609
  # Anthropic image blocks); the model reads "[Image #1]". Older messages keep only the label —
11558
- # their images are not re-sent. Files are read from ~/.gonext/images and nowhere else: the
11610
+ # their images are not re-sent. Files are read from ~/.gu/images and nowhere else: the
11559
11611
  # marker is text, and text can be typed.
11560
11612
  _IMAGE_MARKER_RE = re.compile(r"\[Image #(\d+): ([^\]\n]+)\]")
11561
11613
  _MAX_TURN_IMAGES = 20
@@ -11564,7 +11616,7 @@ _MAX_TURN_IMAGES = 20
11564
11616
  def _take_image_markers(messages, images_dir=None):
11565
11617
  """Rewrite the markers in `messages` (in place). → the latest user message's image files,
11566
11618
  in order, as [(label, path)] — only files that exist inside the images folder."""
11567
- root = os.path.realpath(images_dir or os.path.join(os.path.expanduser("~"), ".gonext", "images"))
11619
+ root = os.path.realpath(images_dir or os.path.join(os.path.expanduser("~"), ".gu", "images"))
11568
11620
  last_user = max((i for i, m in enumerate(messages) if isinstance(m, dict) and m.get("role") == "user"),
11569
11621
  default=-1)
11570
11622
  found = []
@@ -11692,13 +11744,13 @@ def _image_coders():
11692
11744
  def _cloud_image_coders():
11693
11745
  """GH #528: the models the cloud list says take images — [{host, exact}].
11694
11746
 
11695
- From the cloud token table this job read (_CLOUD_LIMITS), else from ~/.gonext/image-models.json,
11747
+ From the cloud token table this job read (_CLOUD_LIMITS), else from ~/.gu/image-models.json,
11696
11748
  which the CLI writes from the same table: the CLI's Ctrl+V gate and this one stay the same list."""
11697
11749
  rows = [r for r in _CLOUD_LIMITS["rows"] if r.get("images") and r.get("host") and not r.get("regex")]
11698
11750
  if rows:
11699
11751
  return [{"host": r["host"], "exact": str(r["model"]).strip().lower()} for r in rows]
11700
11752
  try:
11701
- path = os.path.join(os.path.expanduser("~"), ".gonext", "image-models.json")
11753
+ path = os.path.join(os.path.expanduser("~"), ".gu", "image-models.json")
11702
11754
  with open(path, encoding="utf-8") as f:
11703
11755
  saved = json.load(f).get("coders") or []
11704
11756
  return [c for c in saved if isinstance(c, dict) and c.get("host") and c.get("exact")]
@@ -11916,8 +11968,8 @@ def run_agent_chat(cfg):
11916
11968
  return _ws_request_approval(worker_api_base, worker_api_key, _job_id, command, "", deadline_s=45)
11917
11969
  return _lsp_code_check(_lsp_cfg, _lsp_turn, rp, content, changed,
11918
11970
  _WS_ACTIVE or _default_ws_root(), ask=_ask, emit=_emit, log=_log)
11919
- # Skills and MCP servers (task #269). The worker scans ~/.gonext/skills, ~/.gonext/mcp.json and
11920
- # this folder's .gonext/skills + .mcp.json for every turn; none present = neither appears
11971
+ # Skills and MCP servers (task #269). The worker scans ~/.gu/skills, ~/.gu/mcp.json and
11972
+ # this folder's .gu/skills + .mcp.json for every turn; none present = neither appears
11921
11973
  # anywhere in the prompt. Names only here — a skill's body is read when it is used.
11922
11974
  import gu_skills as _skills_mod
11923
11975
  _skills = _skills_mod.clean_list(cfg.get("skills"))
@@ -12097,7 +12149,10 @@ def run_agent_chat(cfg):
12097
12149
  # HOOKS (task #270): onStart on the first turn of a gu session, onAsk on every question. What
12098
12150
  # they print goes in beside the task; exit 2 from onAsk stops the turn before any model call.
12099
12151
  import gu_hooks as _hooks_mod
12100
- _hooks = _hooks_mod.from_cfg(cfg, _log)
12152
+ # GH #584: the between-turns RAG index pass (ragIndexOnly) gets the turn's own config: it is NOT a turn,
12153
+ # so no hooks. Its onAsk saved the question a second time, after onTurnEnd, so the memory skill thought
12154
+ # every gu session in a local-RAG folder was still unfinished — and never offered it to "where were we".
12155
+ _hooks = None if cfg.get("ragIndexOnly") else _hooks_mod.from_cfg(cfg, _log)
12101
12156
  _hook_context = ""
12102
12157
  if _hooks:
12103
12158
  _hr_parts, _hr_warn = [], []
@@ -12198,7 +12253,7 @@ def run_agent_chat(cfg):
12198
12253
  _boto3_ok = True
12199
12254
  except Exception: # noqa: BLE001
12200
12255
  _boto3_ok = False
12201
- # RAG storage backend (task #97): "local" keeps the index on disk under ~/.gonext,
12256
+ # RAG storage backend (task #97): "local" keeps the index on disk under ~/.gu,
12202
12257
  # PER-FOLDER, and needs NO S3 creds / boto3 — only the embedding server. "cloud" (default,
12203
12258
  # and what the web app always uses) stores it on the user's own S3 bucket via boto3. The
12204
12259
  # terminal REPL picks this per-folder and sends it as cfg.ragMode.
@@ -12283,12 +12338,12 @@ def run_agent_chat(cfg):
12283
12338
  coding_base_url, agent_base_url,
12284
12339
  )
12285
12340
  if _RAG_CLOUD_SYNC:
12286
- _store = "LOCAL (~/.gonext/rag, per-folder) + MIRRORED to your S3 bucket"
12341
+ _store = "LOCAL (~/.gu/rag, per-folder) + MIRRORED to your S3 bucket"
12287
12342
  elif _RAG_CLOUD_SYNC_WANTED:
12288
- _store = ("LOCAL (~/.gonext/rag, per-folder); cloud sync is ON but UNAVAILABLE "
12343
+ _store = ("LOCAL (~/.gu/rag, per-folder); cloud sync is ON but UNAVAILABLE "
12289
12344
  "(needs RAG AWS credentials + boto3) - staying local only")
12290
12345
  elif _RAG_LOCAL:
12291
- _store = "LOCAL (index under ~/.gonext/rag, per-folder)"
12346
+ _store = "LOCAL (index under ~/.gu/rag, per-folder)"
12292
12347
  else:
12293
12348
  _store = "cloud (S3)"
12294
12349
  _log(
@@ -12400,10 +12455,10 @@ def run_agent_chat(cfg):
12400
12455
  _WS_RUN_DENYLIST = _split_cmds(cfg.get("runDenylist"))
12401
12456
  # Active terminal workspace: the folder the `gu` REPL was launched from (sent as
12402
12457
  # payload.activeWorkspace = the terminal's cwd). download_file / unzip_file put their
12403
- # output HERE instead of the shared ~/.gonext/rag-work cache, so files land where the
12458
+ # output HERE instead of the shared ~/.gu/rag-work cache, so files land where the
12404
12459
  # user opened the terminal. Honoured for any real directory the user explicitly opened
12405
12460
  # the terminal in — these tools already write outside registered workspaces (to
12406
- # ~/.gonext), so this is not a new write boundary; the code-EDIT tools stay gated on
12461
+ # ~/.gu), so this is not a new write boundary; the code-EDIT tools stay gated on
12407
12462
  # _WS_ROOTS (registered workspaces) via _ws_write_allowed, unchanged.
12408
12463
  _WS_ACTIVE = ""
12409
12464
  _aw_raw = str(cfg.get("activeWorkspace") or "").strip()
@@ -12431,7 +12486,7 @@ def run_agent_chat(cfg):
12431
12486
  if _remote_ws:
12432
12487
  # HARD-DISABLE the workspace tools. Leaving them pointed at a scratch folder on THIS
12433
12488
  # machine let the agent "succeed" at work the user never asked for: observed live, a
12434
- # client asked for a folder and the agent created it under ~/.gonext/web-agent-work on
12489
+ # client asked for a folder and the agent created it under ~/.gu/web-agent-work on
12435
12490
  # the MODEL machine, then reported "Done ✅". Silently acting on the wrong filesystem
12436
12491
  # is worse than refusing — the user believes their folder changed when it did not.
12437
12492
  _WS_ROOTS = []
@@ -12565,7 +12620,7 @@ def run_agent_chat(cfg):
12565
12620
  all. A snapshot must REPLACE, not accumulate.
12566
12621
 
12567
12622
  Backend-agnostic on purpose: same mechanism either way, only the store differs —
12568
- local disk under ~/.gonext/rag, or the user's own S3 bucket (what the web app uses).
12623
+ local disk under ~/.gu/rag, or the user's own S3 bucket (what the web app uses).
12569
12624
  """
12570
12625
  import glob as _glob
12571
12626
  import os
@@ -13176,6 +13231,15 @@ def run_agent_chat(cfg):
13176
13231
  "continue the investigation/edit from here:\n"
13177
13232
  f"Previous task: {_ck.get('task', '')}\n" + "\n".join(_kept)
13178
13233
  )
13234
+ # GH #585: how the earlier turns of this conversation got their answers (commands,
13235
+ # servers, files) — the history above holds only the answers.
13236
+ import gu_turn_trail as _trail_mod
13237
+ _trail = _trail_mod.block(_WS_ACTIVE, [m.get("content", "") for m in messages[:last_user_idx]
13238
+ if m.get("role") == "user"],
13239
+ local_model=_is_local_url(coding_base_url))
13240
+ if _trail:
13241
+ _log(f"turn trail: {len(_trail)} chars of earlier turns' steps folded into the task")
13242
+ task_text += "\n\n" + _trail
13179
13243
 
13180
13244
  # ORDER (task #86 — prefix-cache fix): STATIC first, VARIABLE last.
13181
13245
  # The ~16k-char tool reference is byte-identical between turns; leading with it
@@ -13701,7 +13765,7 @@ def run_agent_chat(cfg):
13701
13765
  """
13702
13766
  # A FILE, read here (task #269 follow-up): "a PDF of this .txt file" used to be caught by
13703
13767
  # a keyword fast-path that rendered the REQUEST's own words. The same reach as
13704
- # read_text_file — registered workspaces, the terminal folder, ~/.gonext, the temp dir.
13768
+ # read_text_file — registered workspaces, the terminal folder, ~/.gu, the temp dir.
13705
13769
  if (path or "").strip():
13706
13770
  import os as _os_pdf
13707
13771
  try:
@@ -16618,7 +16682,7 @@ def run_agent_chat(cfg):
16618
16682
  """
16619
16683
  # SAME mechanism as rag_index (chunk -> embed -> shard + manifest) and the SAME
16620
16684
  # storage abstraction: ragMode decides where the JSON shards land — local disk
16621
- # under ~/.gonext/rag for the terminal, the user's own S3 bucket for the web app.
16685
+ # under ~/.gu/rag for the terminal, the user's own S3 bucket for the web app.
16622
16686
  # The only thing special here is the KEY: the folder path instead of a source URL.
16623
16687
  if not _RAG_AVAILABLE:
16624
16688
  msg = _rag_unavailable_msg()
@@ -17498,7 +17562,7 @@ def run_agent_chat(cfg):
17498
17562
  # what lets a server OUTLIVE this job process, and what lets a timeout
17499
17563
  # kill take the runner's whole child tree (npm's node child etc. — the
17500
17564
  # old subprocess.run timeout killed only the direct child, leaking it).
17501
- logs_dir = os.path.join(os.path.expanduser("~"), ".gonext", "run-logs")
17565
+ logs_dir = os.path.join(os.path.expanduser("~"), ".gu", "run-logs")
17502
17566
  os.makedirs(logs_dir, exist_ok=True)
17503
17567
  log_path = os.path.join(logs_dir, f"{_t.strftime('%Y%m%d-%H%M%S')}-{os.getpid()}.log")
17504
17568
  log_fh = open(log_path, "wb")
@@ -17512,7 +17576,7 @@ def run_agent_chat(cfg):
17512
17576
  _gp = _ps_mod()
17513
17577
  _cmd_text, _attrib_note = _with_attribution_text(
17514
17578
  command, dict(_scan, commands=_gp.ps_commands(_scan["tokens"])),
17515
- _attribution_settings(wd))
17579
+ _attribution_settings(wd), powershell=True)
17516
17580
  _ps_cmd = log_path[:-4] + ".cmd.ps1"
17517
17581
  _ps_wrap = log_path[:-4] + ".ps1"
17518
17582
  with open(_ps_cmd, "w", encoding="utf-8") as _fh:
@@ -18062,7 +18126,7 @@ def run_agent_chat(cfg):
18062
18126
 
18063
18127
  # ASK FIRST (#150), the way Claude Code does: the first browser call of a turn asks the user
18064
18128
  # (Allow once / Always in this folder / No), unless this folder is on the "always" list in
18065
- # ~/.gonext/browser-allow.json. A "No" holds for the rest of the turn.
18129
+ # ~/.gu/browser-allow.json. A "No" holds for the rest of the turn.
18066
18130
  _browser_consent = {"ok": False, "no": False, "where": ""}
18067
18131
  import gu_gif as _gu_gif
18068
18132
  _gif = _gu_gif.GifRecorder() # GH #548: browser(action="record_start" … "record_stop")
@@ -18444,7 +18508,7 @@ def run_agent_chat(cfg):
18444
18508
  verdict = _mcp_mod.decide(allow, deny, server, tool_name, _ask)
18445
18509
  if verdict == "deny":
18446
18510
  return False, (f"MCP tool {server}/{tool_name} is blocked by a deny rule in "
18447
- "~/.gonext/mcp.json. Do not call it again; carry on without it.")
18511
+ "~/.gu/mcp.json. Do not call it again; carry on without it.")
18448
18512
  if verdict == "allow" or (server, tool_name) in _mcp_turn_allowed:
18449
18513
  return True, ""
18450
18514
  if not (_interactive_approval and _job_id and worker_api_base and worker_api_key):
@@ -18475,9 +18539,12 @@ def run_agent_chat(cfg):
18475
18539
  _log(f"onToolDone hooks on {_n_wrapped} tool(s)")
18476
18540
  # Fill in the numbered tool list now that the REAL tool objects exist — see
18477
18541
  # _render_numbered_tool_list and the {{TOOL_LIST}} placeholder left in tool_hint.
18542
+ # The FIRST one only (the tool reference comes first): the task below it can quote the
18543
+ # placeholder — an earlier turn's step that grepped for it (GH #585) — and is left as it is.
18478
18544
  task_with_hint = task_with_hint.replace(
18479
18545
  "{{TOOL_LIST}}",
18480
18546
  f"You have {len(agent_tools)} tools:\n" + _render_numbered_tool_list(agent_tools),
18547
+ 1,
18481
18548
  )
18482
18549
  agent_kwargs = dict(
18483
18550
  tools=agent_tools,
@@ -18512,7 +18579,7 @@ def run_agent_chat(cfg):
18512
18579
  # logged; the text never is.
18513
18580
  _scaffold, _scaffold_version, _scaffold_source = _load_prompt_scaffold(worker_api_base, worker_api_key)
18514
18581
  # A LOCAL FILE IS USED SILENTLY — no line, no location (the user's call: "if it is on
18515
- # .gonext location, not say anything"). Only a BROKEN one speaks, and without the path.
18582
+ # .gu location, not say anything"). Only a BROKEN one speaks, and without the path.
18516
18583
  try:
18517
18584
  import yaml as _yaml
18518
18585
  import os as _os
@@ -18719,6 +18786,10 @@ def run_agent_chat(cfg):
18719
18786
  except Exception as _ce: # noqa: BLE001
18720
18787
  _log(f"browser cleanup skipped: {type(_ce).__name__}: {_ce}")
18721
18788
  _emit({"type": "final", "text": final_text})
18789
+ # GH #585: the answer says WHAT was found, not how; the next turn gets the steps too.
18790
+ if _WS_ACTIVE and _turn_steps and not cfg.get("ragIndexOnly"):
18791
+ import gu_turn_trail as _trail_mod
18792
+ _log(f"turn trail: {_trail_mod.save(_WS_ACTIVE, latest_user_text, _turn_steps)} step(s) kept for the next turns")
18722
18793
  # onTurnEnd (task #270): after the answer is out, so a slow hook never delays it.
18723
18794
  if _hooks and _hooks.has("onTurnEnd"):
18724
18795
  _te = _hooks.run("onTurnEnd", {"question": latest_user_text, "answer": final_text,