@tiens.nguyen/gu-cli 1.0.938 → 1.0.939

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/free-model.mjs CHANGED
@@ -234,6 +234,12 @@ export function stateFromPreset(preset, prev, now = new Date()) {
234
234
  /**
235
235
  * The line to show, or null. `over` is the refusal itself; warn/low are shown once per level.
236
236
  */
237
+ /** What to call a slot: an extra provider's label; the main slot is "Gemini" on Google's server (GH #580), else "free model". */
238
+ function slotName(slot, url) {
239
+ if (slot.extra) return slot.label;
240
+ return /generativelanguage\.googleapis\.com/.test(String(url)) ? "Gemini" : "free model";
241
+ }
242
+
237
243
  export function notice(state, now = new Date(), url = "") {
238
244
  const s = current(state, now);
239
245
  if (!s) return null;
@@ -241,8 +247,8 @@ export function notice(state, now = new Date(), url = "") {
241
247
  if (!slot.allowanceMicro) return null;
242
248
  const level = levelFor(slot.spentMicro, slot.allowanceMicro);
243
249
  const pct = Math.min(100, Math.floor((100 * slot.spentMicro) / slot.allowanceMicro));
244
- const name = slot.extra ? slot.label : "free model";
245
- const Name = slot.extra ? slot.label : "Free model";
250
+ const name = slotName(slot, url);
251
+ const Name = name === "free model" ? "Free model" : name;
246
252
  if (level === "over") {
247
253
  const other = slot.extra ? " — or another free model with /model —" : "";
248
254
  return { level, text: `Your ${name} allowance for this month is used up. Add your own model key with /model${other} — or a local one with Ollama — to keep going; it renews on the 1st.` };
@@ -252,6 +258,32 @@ export function notice(state, now = new Date(), url = "") {
252
258
  return { level, text: null };
253
259
  }
254
260
 
261
+ const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
262
+
263
+ /** GH #580: the day a month's allowance comes back — the 1st of the month after `period` ("2026-12" → "1 Jan 2027"). */
264
+ export function renewsOn(period) {
265
+ const [y, m] = String(period ?? "").split("-").map(Number);
266
+ if (!y || !m) return "the 1st";
267
+ const d = new Date(Date.UTC(y, m, 1));
268
+ return `1 ${MONTHS[d.getUTCMonth()]} ${d.getUTCFullYear()}`;
269
+ }
270
+
271
+ /**
272
+ * GH #580: said INSTEAD of "Ready — type your first question" when the model just set up has nothing left this
273
+ * month — e.g. a second Gemini code after the first month's allowance was spent: a code adds its month at the
274
+ * END, it does not refill this one (owner, 2026-12-04). → the sentence, or null when there is allowance left.
275
+ */
276
+ export function spentAtSetup(state, url, now = new Date(), { redeemed = false } = {}) {
277
+ const s = current(state, now);
278
+ if (!s) return null;
279
+ const slot = slotFor(s, url);
280
+ if (!slot.allowanceMicro || slot.spentMicro < slot.allowanceMicro) return null;
281
+ const name = slotName(slot, url);
282
+ const Name = name === "free model" ? "The free model" : name;
283
+ return `This month's ${name} allowance is already used up${redeemed ? " — your code adds its month at the end, it does not refill this one" : ""}. ` +
284
+ `${Name} works again on ${renewsOn(s.period)}; until then, /model switches to your own key.`;
285
+ }
286
+
255
287
  /**
256
288
  * Is a NEW turn on this coder refused? Only at the START of a turn — never mid-turn — and only when
257
289
  * the coder IS the free model (any provider; each has its own allowance). → the sentence, or null.
@@ -14179,7 +14179,7 @@ def run_agent_chat(cfg):
14179
14179
  _fb_aux = [dict(v) for v in _AUX_USAGE.values()]
14180
14180
  if _fb_b.after_step(_fb_b.turn_spent(_fb_in, _fb_cached, _fb_cached > 0, _fb_out, _fb_aux)):
14181
14181
  _FREE_TURN["hit"] = True
14182
- _emit({"type": "step", "text": "Pausing — this month's free-model allowance is used up"})
14182
+ # GH #579: no "Pausing — …" step line — the answer's first line says it, once, in yellow.
14183
14183
  _log(f"step {step_num}: free-model allowance would not cover the next step → pausing the turn")
14184
14184
  agent.interrupt()
14185
14185
  except Exception as e: # noqa: BLE001
package/gu-repl.mjs CHANGED
@@ -335,7 +335,20 @@ const wrapBlock = (text, indent, width) => {
335
335
  // indented to the shared text column (GUTTER) so it lines up with the bullets' text and the
336
336
  // rest of the output, with inline **bold** rendered per row (after wrapping, so the width math
337
337
  // is on visible text).
338
- const renderAnswer = (answer) =>
338
+ // GH #579: a pause answer (gu_free_budget.py) opens with ONE "Paused — …" line: that line is the warning colour.
339
+ const PAUSE_LINE_RE = /^Paused — /;
340
+ const renderAnswer = (answer) => {
341
+ const s = String(answer ?? "");
342
+ if (PAUSE_LINE_RE.test(s)) {
343
+ const nl = s.indexOf("\n");
344
+ const head = nl < 0 ? s : s.slice(0, nl);
345
+ const rest = nl < 0 ? "" : s.slice(nl);
346
+ const headRows = wrapBlock(head, GUTTER, process.stdout.columns || 80).map((l) => (l.length ? GUTTER + yellow(l) : l));
347
+ return headRows.join("\n") + (rest ? "\n" + renderAnswerRows(rest.replace(/^\n/, "")) : "");
348
+ }
349
+ return renderAnswerRows(s);
350
+ };
351
+ const renderAnswerRows = (answer) =>
339
352
  wrapBlock(answer, GUTTER, process.stdout.columns || 80)
340
353
  .map((l) => (l.length ? GUTTER + renderMdBold(l) : l))
341
354
  .join("\n");
@@ -9404,7 +9417,9 @@ async function setUpFreeModel({ token, announce = false } = {}) {
9404
9417
  : `✓ ${agentM} is now your agent model and ${got.preset.model} your coding model.`) +
9405
9418
  dim(" Free use renews each month; /model switches back to your own."));
9406
9419
  // GH #511: say plainly that setup is over and what to do now — the one line a new person needs.
9407
- console.log(GUTTER + bold("Ready — type your first question below and press Enter."));
9420
+ // GH #580: unless this month's allowance is already spent — then say that, and when it comes back.
9421
+ const spent = fm.spentAtSetup(freeModel, got.preset.baseUrl, new Date(), { redeemed: announce });
9422
+ console.log(GUTTER + (spent ? yellow(spent) : bold("Ready — type your first question below and press Enter.")));
9408
9423
  }
9409
9424
  return true;
9410
9425
  } catch (e) {
@@ -9430,7 +9445,7 @@ async function freeModelAtStart() {
9430
9445
 
9431
9446
  /** After a turn on the free model: count it, say a notice once per level, tell the service. Never throws. */
9432
9447
  // GH #507: how the agent's pause answer starts (gu_free_budget.py PAUSE_HEAD).
9433
- const ALLOWANCE_PAUSE_PREFIX = "Paused: this month's free-model allowance is used up";
9448
+ const ALLOWANCE_PAUSE_PREFIX = "Paused — this month's free-model allowance is used up";
9434
9449
 
9435
9450
  async function noteFreeModelTurn(inputTokens, breakdown, outputTokens, coder, aux = null, paused = false) {
9436
9451
  try {
package/gu_free_budget.py CHANGED
@@ -147,18 +147,20 @@ def load(coder_url: str, coder_model: str, path: str | None = None):
147
147
  return None
148
148
 
149
149
 
150
- PAUSE_HEAD = ("Paused: this month's free-model allowance is used up, so I stopped before the next step. "
151
- "The steps that ran are finished; nothing was left half-done.")
152
- PAUSE_WAYS = ("To keep going, add your own model key with /model, a local model with Ollama, or a new "
150
+ # GH #579: said ONCE, as the answer's first line — gu shows a first line starting "Paused — " in the warning
151
+ # colour. (A "Pausing — …" step line used to say the same just above it.)
152
+ PAUSE_HEAD = "Paused — this month's free-model allowance is used up."
153
+ PAUSE_WAYS = ("I stopped before the next step; the steps that ran are finished, nothing was left half-done. "
154
+ "To keep going, add your own model key with /model, a local model with Ollama, or a new "
153
155
  "code with /voucher, then type continue. The free model renews on the 1st.")
154
- OUT_OF_CREDIT = ("Paused: the free model can't take more requests right now (its account is out of credit; "
155
- "this is not your allowance). The steps that ran are finished.")
156
+ OUT_OF_CREDIT = ("Paused — the free model can't take more requests right now (its account is out of credit; "
157
+ "this is not your allowance).")
156
158
 
157
159
 
158
160
  def pause_message(recap: str = "", out_of_credit: bool = False) -> str:
159
161
  head = OUT_OF_CREDIT if out_of_credit else PAUSE_HEAD
160
- ways = ("Add your own model key with /model, or a local model with Ollama, then type continue."
161
- if out_of_credit else PAUSE_WAYS)
162
+ ways = ("The steps that ran are finished. Add your own model key with /model, or a local model with Ollama, "
163
+ "then type continue." if out_of_credit else PAUSE_WAYS)
162
164
  body = [head, "", ways]
163
165
  if recap.strip():
164
166
  body += ["", recap.strip()]
package/gu_mcp.py CHANGED
@@ -27,6 +27,7 @@ import json
27
27
  import os
28
28
  import queue
29
29
  import re
30
+ import shutil
30
31
  import subprocess
31
32
  import sys
32
33
  import threading
@@ -55,6 +56,23 @@ def server_env(extra: dict | None) -> dict:
55
56
  return env
56
57
 
57
58
 
59
+ # GH #577: interpreters an MCP config may name by FULL path. That path is often a versioned folder
60
+ # (/opt/homebrew/Cellar/node/26.12.0/bin/node, ~/.nvm/versions/node/v22.x/bin/node) that an upgrade deletes.
61
+ _INTERPRETERS = {"node", "node.exe", "npx", "npx.cmd", "python", "python3", "python.exe", "uv", "uvx", "bun", "deno"}
62
+
63
+
64
+ def resolve_command(command: str, path: str | None = None) -> str:
65
+ """The command to start: as saved, unless it is a full path to an interpreter that is GONE — then the same
66
+ program found on PATH. Anything else is left exactly as saved (a missing custom binary still says so)."""
67
+ if command and os.path.isabs(command) and not os.path.exists(command):
68
+ base = os.path.basename(command)
69
+ if base.lower() in _INTERPRETERS:
70
+ found = shutil.which(base, path=path)
71
+ if found:
72
+ return found
73
+ return command
74
+
75
+
58
76
  class McpError(Exception):
59
77
  """A server that could not be reached or answered with an error — the message says which."""
60
78
 
@@ -77,10 +95,12 @@ class StdioMcpClient:
77
95
 
78
96
  # ---- process ----------------------------------------------------------------------------
79
97
  def start(self) -> None:
98
+ env = server_env(self.env)
99
+ command = resolve_command(self.command, env.get("PATH"))
80
100
  try:
81
101
  self.proc = subprocess.Popen(
82
- [self.command, *self.args], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
83
- stderr=subprocess.PIPE, cwd=self.cwd, env=server_env(self.env),
102
+ [command, *self.args], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
103
+ stderr=subprocess.PIPE, cwd=self.cwd, env=env,
84
104
  text=True, encoding="utf-8", errors="replace", bufsize=1,
85
105
  )
86
106
  except FileNotFoundError:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gu-cli",
3
- "version": "1.0.938",
3
+ "version": "1.0.939",
4
4
  "description": "gu: the coding agent in your terminal. It reads your repo, makes the change and runs the tests, with your own models (Ollama or any OpenAI-compatible provider). Free installs keep the agent, its API and its database on your machine. macOS, Linux and Windows.",
5
5
  "keywords": [
6
6
  "ai",