@tiens.nguyen/gu-cli 1.0.936 → 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 +34 -2
- package/gonext_agent_chat.py +1 -1
- package/gu-repl.mjs +87 -64
- package/gu_free_budget.py +9 -7
- package/gu_mcp.py +22 -2
- package/hints.mjs +1 -1
- package/package.json +1 -1
- package/terminal-layout.mjs +1 -0
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
|
|
245
|
-
const Name =
|
|
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.
|
package/gonext_agent_chat.py
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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");
|
|
@@ -1128,7 +1141,7 @@ const COMMANDS = [
|
|
|
1128
1141
|
{ name: "/voucher", usage: "/voucher CODE", desc: "use a voucher code — free days for this computer's trial or your free account, or a free model allowance" },
|
|
1129
1142
|
{ name: "/support", desc: "send the gu support team a request with gu's logs attached (secrets masked) — shows what goes first, then asks" },
|
|
1130
1143
|
{ name: "/clear-logs", desc: "show what gu's logs, RAG indexes and old API versions take on disk, then ask what to clear — the logs first" },
|
|
1131
|
-
{ name: "/
|
|
1144
|
+
{ name: "/cost", usage: "/cost [all]", desc: "what this session and the last turn cost, and the price of the model in use — \"all\" shows every price (prices update by themselves)" },
|
|
1132
1145
|
// ONE name, /new (user, #278). /reset and /clear still work (HIDDEN_COMMANDS) for habit and
|
|
1133
1146
|
// for Claude Code users — not to be confused with `gu clear` in a shell, which wipes gu's state.
|
|
1134
1147
|
{ name: "/new", desc: "start a new conversation in this folder — the old one is kept (archived); the folder's settings stay" },
|
|
@@ -1792,11 +1805,6 @@ function applyClick({ row, col }) {
|
|
|
1792
1805
|
void runUpdate();
|
|
1793
1806
|
return;
|
|
1794
1807
|
}
|
|
1795
|
-
if (pricesRowTarget && row === updateRowAbs &&
|
|
1796
|
-
col - 1 >= pricesRowTarget.from && col - 1 < pricesRowTarget.to) {
|
|
1797
|
-
void runPricesUpdate();
|
|
1798
|
-
return;
|
|
1799
|
-
}
|
|
1800
1808
|
if (limitsRowTarget && row === updateRowAbs &&
|
|
1801
1809
|
col - 1 >= limitsRowTarget.from && col - 1 < limitsRowTarget.to) {
|
|
1802
1810
|
void runLimitsSeen();
|
|
@@ -3524,14 +3532,6 @@ function syncBarPinning() {
|
|
|
3524
3532
|
* update), a standing fact about the licence (the gu token notice — yellow only when urgent), and
|
|
3525
3533
|
* other agents. Dropped whole, lowest first, when they do not all fit.
|
|
3526
3534
|
*/
|
|
3527
|
-
/** The notice's text (sync — zoneNotice runs on every paint): "new prices updated 1 Oct 2026". */
|
|
3528
|
-
function priceUpdateText() {
|
|
3529
|
-
const d = new Date(priceUpdate?.publishedAt ?? "");
|
|
3530
|
-
if (Number.isNaN(d.getTime())) return "new prices updated";
|
|
3531
|
-
const m = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][d.getUTCMonth()];
|
|
3532
|
-
return `new prices updated ${d.getUTCDate()} ${m} ${d.getUTCFullYear()}`;
|
|
3533
|
-
}
|
|
3534
|
-
|
|
3535
3535
|
function zoneNotice(width) {
|
|
3536
3536
|
const items = [];
|
|
3537
3537
|
if (scrolledBack()) {
|
|
@@ -3544,7 +3544,6 @@ function zoneNotice(width) {
|
|
|
3544
3544
|
}
|
|
3545
3545
|
// While the token question is open it is the ONLY thing on the screen (#222): the housekeeping
|
|
3546
3546
|
// notices (new prices, new token limits) wait, and the token notice would repeat the question.
|
|
3547
|
-
if (priceUpdate && !tokenQuestionOpen) items.push({ key: "prices", clickable: true, paint: accent, text: `${priceUpdateText()} (click)` });
|
|
3548
3547
|
if (limitsUpdate && !tokenQuestionOpen) items.push({ key: "limits", clickable: true, paint: accent, text: `${limitsUpdate.label} (click)` });
|
|
3549
3548
|
if (tokenNotice?.text && !tokenQuestionOpen) items.push({ key: "token", paint: tokenNotice.urgent ? yellow : dim, text: tokenNotice.text });
|
|
3550
3549
|
const agents = agentsIndicator(otherAgents);
|
|
@@ -3672,7 +3671,6 @@ function frozenZone() {
|
|
|
3672
3671
|
const sep = status.length + (notice ? 1 : 0);
|
|
3673
3672
|
updateRowTarget = notice?.spans.update ?? null;
|
|
3674
3673
|
agentsRowTarget = notice?.spans.agents ?? null;
|
|
3675
|
-
pricesRowTarget = notice?.spans.prices ?? null;
|
|
3676
3674
|
limitsRowTarget = notice?.spans.limits ?? null;
|
|
3677
3675
|
logsRowTarget = notice?.spans.logs ?? null;
|
|
3678
3676
|
shellsRowTarget = notice?.spans.shells ?? null;
|
|
@@ -3745,7 +3743,7 @@ function paintBar() {
|
|
|
3745
3743
|
// THE NOTICE ROW is the one directly above the separator (#318) — never the separator itself.
|
|
3746
3744
|
const noticeAbs = zone.noticeRow ? sepAbs - 1 : 0;
|
|
3747
3745
|
jumpRowTarget = scrolledBack() && jumpSpan ? { row: noticeAbs, ...jumpSpan } : null;
|
|
3748
|
-
updateRowAbs = updateRowTarget || agentsRowTarget ||
|
|
3746
|
+
updateRowAbs = updateRowTarget || agentsRowTarget || limitsRowTarget || logsRowTarget || shellsRowTarget ? noticeAbs : 0;
|
|
3749
3747
|
// preserveCaret:false — the save slot holds the OUTPUT position (see regionUi), and the caret
|
|
3750
3748
|
// is parked on the input line right after, so there is nothing to preserve here.
|
|
3751
3749
|
ui(
|
|
@@ -3905,8 +3903,6 @@ let updateRowTarget = null;
|
|
|
3905
3903
|
let updateRowAbs = 0;
|
|
3906
3904
|
// …and the agents indicator, which shares that row when no update is pending (task #195).
|
|
3907
3905
|
let agentsRowTarget = null;
|
|
3908
|
-
// …and "new prices updated <date>" (#323).
|
|
3909
|
-
let pricesRowTarget = null;
|
|
3910
3906
|
// …and "output token limits updated <date>" — the cloud token table changed.
|
|
3911
3907
|
let limitsRowTarget = null;
|
|
3912
3908
|
// …and "clear logs · 175 MB" (#329), shown only once the logs are worth a row.
|
|
@@ -9312,6 +9308,22 @@ function activeCodingModelId() {
|
|
|
9312
9308
|
return m.includes("::") ? m.slice(m.indexOf("::") + 2) : m || defaultCodingModel;
|
|
9313
9309
|
}
|
|
9314
9310
|
|
|
9311
|
+
/** The price row a turn on this server + model is charged at — the bar's cost and /cost use the same one. */
|
|
9312
|
+
async function priceFor(rows, url, model) {
|
|
9313
|
+
const mp = await import("./model-prices.mjs");
|
|
9314
|
+
// GH #533: on the free model's key the allowance charges the PROMO's price (its own, else the dearest
|
|
9315
|
+
// listed) — the bar shows that, even when the published table has a (pay-as-you-go estimate) row too.
|
|
9316
|
+
let price = null;
|
|
9317
|
+
if (freeModel) {
|
|
9318
|
+
const fm = await import("./free-model.mjs");
|
|
9319
|
+
price = fm.freeModelPriceRow(freeModel, url, model);
|
|
9320
|
+
}
|
|
9321
|
+
price ??= mp.findPrice(rows, url, model);
|
|
9322
|
+
// GH #570: OpenRouter models are not in the table; their price comes from OpenRouter's own public list.
|
|
9323
|
+
if (!price && mp.hostOf(url) === "openrouter.ai") price = mp.findPrice(await openRouterPrices(), url, model);
|
|
9324
|
+
return price;
|
|
9325
|
+
}
|
|
9326
|
+
|
|
9315
9327
|
/** After a turn: what its prompt tokens cost, added to the session total. Never throws. */
|
|
9316
9328
|
async function noteTurnCost(inputTokens, breakdown, coder = null) {
|
|
9317
9329
|
try {
|
|
@@ -9321,16 +9333,7 @@ async function noteTurnCost(inputTokens, breakdown, coder = null) {
|
|
|
9321
9333
|
const rows = await loadPrices();
|
|
9322
9334
|
const url = coder?.url ?? activeCodingUrl();
|
|
9323
9335
|
const model = coder?.model ?? activeCodingModelId();
|
|
9324
|
-
|
|
9325
|
-
// listed) — the bar shows that, even when the published table has a (pay-as-you-go estimate) row too.
|
|
9326
|
-
let price = null;
|
|
9327
|
-
if (freeModel) {
|
|
9328
|
-
const fm = await import("./free-model.mjs");
|
|
9329
|
-
price = fm.freeModelPriceRow(freeModel, url, model);
|
|
9330
|
-
}
|
|
9331
|
-
price ??= mp.findPrice(rows, url, model);
|
|
9332
|
-
// GH #570: OpenRouter models are not in the table; their price comes from OpenRouter's own public list.
|
|
9333
|
-
if (!price && mp.hostOf(url) === "openrouter.ai") price = mp.findPrice(await openRouterPrices(), url, model);
|
|
9336
|
+
const price = await priceFor(rows, url, model);
|
|
9334
9337
|
const cache = readTurnCache(breakdown) ?? { cached: 0, cacheReported: false, firstIn: 0 };
|
|
9335
9338
|
const c = mp.turnCost({ input: inputTokens, ...cache, price });
|
|
9336
9339
|
if (!c) {
|
|
@@ -9348,11 +9351,6 @@ async function noteTurnCost(inputTokens, breakdown, coder = null) {
|
|
|
9348
9351
|
}
|
|
9349
9352
|
}
|
|
9350
9353
|
|
|
9351
|
-
/**
|
|
9352
|
-
* /prices (#323) — the price table and the cache table this account's estimates use, the coder in
|
|
9353
|
-
* use marked; what the last turn and this session cost; and, when gu has published newer tables,
|
|
9354
|
-
* that they are waiting. `/prices update` applies them — the same as clicking the notice.
|
|
9355
|
-
*/
|
|
9356
9354
|
// ---------------------------------------------------------------------------------------------
|
|
9357
9355
|
// THE FREE MODEL (task #557, GH #433) — free-model.mjs has the rules; this is the wiring.
|
|
9358
9356
|
// A model-tokens voucher gives a monthly allowance of the owner's key. The preset (server, key,
|
|
@@ -9419,7 +9417,9 @@ async function setUpFreeModel({ token, announce = false } = {}) {
|
|
|
9419
9417
|
: `✓ ${agentM} is now your agent model and ${got.preset.model} your coding model.`) +
|
|
9420
9418
|
dim(" Free use renews each month; /model switches back to your own."));
|
|
9421
9419
|
// GH #511: say plainly that setup is over and what to do now — the one line a new person needs.
|
|
9422
|
-
|
|
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.")));
|
|
9423
9423
|
}
|
|
9424
9424
|
return true;
|
|
9425
9425
|
} catch (e) {
|
|
@@ -9445,7 +9445,7 @@ async function freeModelAtStart() {
|
|
|
9445
9445
|
|
|
9446
9446
|
/** After a turn on the free model: count it, say a notice once per level, tell the service. Never throws. */
|
|
9447
9447
|
// GH #507: how the agent's pause answer starts (gu_free_budget.py PAUSE_HEAD).
|
|
9448
|
-
const ALLOWANCE_PAUSE_PREFIX = "Paused
|
|
9448
|
+
const ALLOWANCE_PAUSE_PREFIX = "Paused — this month's free-model allowance is used up";
|
|
9449
9449
|
|
|
9450
9450
|
async function noteFreeModelTurn(inputTokens, breakdown, outputTokens, coder, aux = null, paused = false) {
|
|
9451
9451
|
try {
|
|
@@ -9579,21 +9579,49 @@ async function addGeminiWhenReady(token) {
|
|
|
9579
9579
|
return true;
|
|
9580
9580
|
}
|
|
9581
9581
|
|
|
9582
|
-
|
|
9582
|
+
/**
|
|
9583
|
+
* /cost (GH #574; /prices is the same command) — what this session and the last turn cost, and the price
|
|
9584
|
+
* of the coding model in use. Prices keep themselves up to date (refreshPriceUpdate); `/cost all` shows
|
|
9585
|
+
* the whole price and cache tables.
|
|
9586
|
+
*/
|
|
9587
|
+
async function runCostCommand(line = "/cost") {
|
|
9583
9588
|
const mp = await import("./model-prices.mjs");
|
|
9584
9589
|
console.log("");
|
|
9585
|
-
|
|
9590
|
+
const arg = line.trim().replace(/^\/(cost|prices)/, "").trim();
|
|
9591
|
+
if (arg === "update") {
|
|
9586
9592
|
await runPricesUpdate();
|
|
9587
9593
|
return;
|
|
9588
9594
|
}
|
|
9589
9595
|
const rows = await withPendingStatus("reading prices", () => loadPrices({ force: true }));
|
|
9596
|
+
const width = process.stdout.columns || 80;
|
|
9597
|
+
const url = activeCodingUrl();
|
|
9598
|
+
const model = activeCodingModelId();
|
|
9599
|
+
if (arg !== "all") {
|
|
9600
|
+
console.log(GUTTER + "this session: " + (sessionCostTurns
|
|
9601
|
+
? mp.formatUsd(sessionCostUsd, { estimated: sessionCostEstimated }) + dim(` over ${sessionCostTurns} turn${sessionCostTurns === 1 ? "" : "s"}`)
|
|
9602
|
+
: dim("$0 — no priced turn yet")));
|
|
9603
|
+
if (lastTurnCost?.usd != null) {
|
|
9604
|
+
const share = lastTurnCost.input ? Math.round((100 * lastTurnCost.cachedTokens) / lastTurnCost.input) : 0;
|
|
9605
|
+
console.log(GUTTER + `last turn: ${mp.formatUsd(lastTurnCost.usd, { estimated: lastTurnCost.estimated })}` +
|
|
9606
|
+
dim(` — ${lastTurnCost.input.toLocaleString("en-US")} prompt tokens, ${share}% cached`));
|
|
9607
|
+
}
|
|
9608
|
+
const p = model ? await priceFor(rows, url, model) : null;
|
|
9609
|
+
// Only the prices there are: a promo row has an input price alone (no "— cached · — out").
|
|
9610
|
+
const parts = [["in", p?.input], ["cached", p?.cachedInput], ["out", p?.output]]
|
|
9611
|
+
.filter(([, v]) => Number.isFinite(v))
|
|
9612
|
+
.map(([k, v]) => `${mp.formatUsd(v)} ${k}`);
|
|
9613
|
+
if (p && parts.length) {
|
|
9614
|
+
console.log(GUTTER + `${model}: ` + dim(`${parts.join(" · ")} per 1M tokens`));
|
|
9615
|
+
} else if (model) {
|
|
9616
|
+
console.log(GUTTER + dim(`${model}: no price — a model on your own server costs nothing here.`));
|
|
9617
|
+
}
|
|
9618
|
+
console.log(GUTTER + dim("Prompt tokens only; output is not counted yet. /cost all shows every price.") + "\n");
|
|
9619
|
+
return;
|
|
9620
|
+
}
|
|
9590
9621
|
if (!rows.length) {
|
|
9591
9622
|
console.log(GUTTER + yellow("no prices — the local API is older than this gu, or unreachable.") + "\n");
|
|
9592
9623
|
return;
|
|
9593
9624
|
}
|
|
9594
|
-
const width = process.stdout.columns || 80;
|
|
9595
|
-
const url = activeCodingUrl();
|
|
9596
|
-
const model = activeCodingModelId();
|
|
9597
9625
|
const paint = (l) => (l.startsWith("▸") ? accent(l) : /^[a-z0-9.-]+\.[a-z]+(:\d+)?( |$)/i.test(l) ? l : dim(l));
|
|
9598
9626
|
console.log(GUTTER + "Prices");
|
|
9599
9627
|
for (const l of mp.priceTableLines(rows, { width, current: { url, model }, version: priceVersion })) console.log(GUTTER + paint(l));
|
|
@@ -9602,7 +9630,6 @@ async function runPricesCommand(line = "/prices") {
|
|
|
9602
9630
|
for (const l of mp.cacheShareLines({ yours: rows, width, current: { url, model } })) console.log(GUTTER + paint(l));
|
|
9603
9631
|
console.log("");
|
|
9604
9632
|
console.log(GUTTER + dim(pricePublishedAt ? `from gu's tables published ${new Date(pricePublishedAt).toLocaleString()}` : "gu's built-in tables (none published applied yet)"));
|
|
9605
|
-
if (priceUpdate) console.log(GUTTER + accent(`${mp.priceUpdateLabel(priceUpdate.publishedAt)} — click it below, or /prices update`));
|
|
9606
9633
|
if (!mp.findPrice(rows, url, model)) {
|
|
9607
9634
|
for (const r of wrapBlock(mp.noPriceLine({ model, host: mp.hostOf(url) }), GUTTER, width)) console.log(GUTTER + yellow(r));
|
|
9608
9635
|
}
|
|
@@ -9616,11 +9643,10 @@ async function runPricesCommand(line = "/prices") {
|
|
|
9616
9643
|
}
|
|
9617
9644
|
|
|
9618
9645
|
// ---------------------------------------------------------------------------------------------
|
|
9619
|
-
//
|
|
9620
|
-
//
|
|
9621
|
-
//
|
|
9646
|
+
// PUBLISHED PRICES (#323, GH #574): the hosted API's newest published tables, checked at start and
|
|
9647
|
+
// hourly beside the version check; when newer than what this account applied, they are applied by
|
|
9648
|
+
// themselves — no notice, nothing to click. `/cost update` does the same by hand, and says what changed.
|
|
9622
9649
|
// ---------------------------------------------------------------------------------------------
|
|
9623
|
-
let priceUpdate = null; // { publishedAt, tables } while newer tables wait
|
|
9624
9650
|
let priceUpdateBusy = false;
|
|
9625
9651
|
|
|
9626
9652
|
async function fetchPublishedTables() {
|
|
@@ -9636,49 +9662,46 @@ async function fetchPublishedTables() {
|
|
|
9636
9662
|
}
|
|
9637
9663
|
}
|
|
9638
9664
|
|
|
9639
|
-
/**
|
|
9665
|
+
/** Newer tables published? Apply them, quietly. Fails silently — like the version check. */
|
|
9640
9666
|
async function refreshPriceUpdate() {
|
|
9641
9667
|
try {
|
|
9642
9668
|
const mp = await import("./model-prices.mjs");
|
|
9643
9669
|
const tables = await fetchPublishedTables();
|
|
9644
9670
|
if (!tables) return;
|
|
9645
9671
|
await loadPrices({ force: true });
|
|
9646
|
-
|
|
9647
|
-
priceUpdate = mp.hasNewerPublished(pricePublishedAt, tables.publishedAt) ? { publishedAt: tables.publishedAt, tables } : null;
|
|
9648
|
-
if (Boolean(priceUpdate) !== was && barPinned()) paintBar();
|
|
9672
|
+
if (mp.hasNewerPublished(pricePublishedAt, tables.publishedAt)) await runPricesUpdate({ tables, quiet: true });
|
|
9649
9673
|
} catch {
|
|
9650
|
-
/* a price
|
|
9674
|
+
/* a price update is never worth an error */
|
|
9651
9675
|
}
|
|
9652
9676
|
}
|
|
9653
9677
|
|
|
9654
|
-
/** Apply gu's newest published tables to this account's Mongo —
|
|
9655
|
-
async function runPricesUpdate() {
|
|
9678
|
+
/** Apply gu's newest published tables to this account's Mongo — by itself (quiet), or by /cost update. */
|
|
9679
|
+
async function runPricesUpdate({ tables: given = null, quiet = false } = {}) {
|
|
9656
9680
|
if (priceUpdateBusy) return;
|
|
9657
9681
|
priceUpdateBusy = true;
|
|
9682
|
+
const say = (l) => { if (!quiet) console.log(l); };
|
|
9658
9683
|
try {
|
|
9659
9684
|
const mp = await import("./model-prices.mjs");
|
|
9660
|
-
const tables = (await fetchPublishedTables())
|
|
9685
|
+
const tables = given ?? (await fetchPublishedTables());
|
|
9661
9686
|
if (!tables) {
|
|
9662
|
-
|
|
9687
|
+
say(GUTTER + yellow("couldn't reach gu's published prices — try again later.") + "\n");
|
|
9663
9688
|
return;
|
|
9664
9689
|
}
|
|
9665
9690
|
const current = await loadPrices({ force: true });
|
|
9666
9691
|
const m = mp.mergePublishedTables(current, tables);
|
|
9667
9692
|
if (!m.ok) {
|
|
9668
|
-
|
|
9693
|
+
say(GUTTER + yellow(`prices not updated — ${m.problem}`) + "\n");
|
|
9669
9694
|
return;
|
|
9670
9695
|
}
|
|
9671
9696
|
const res = await priceApi("PUT", { version: m.version, publishedAt: m.publishedAt, rows: m.rows, removes: [] });
|
|
9672
9697
|
if (res?.error) {
|
|
9673
|
-
|
|
9698
|
+
say(GUTTER + red(`couldn't save the prices — ${res.error}. Nothing changed.`) + "\n");
|
|
9674
9699
|
return;
|
|
9675
9700
|
}
|
|
9676
9701
|
await loadPrices({ force: true });
|
|
9677
|
-
priceUpdate = null;
|
|
9678
9702
|
const d = m.diff;
|
|
9679
|
-
|
|
9680
|
-
dim(` — ${d.added.length} new · ${d.changed.length} changed · ${d.unchanged} unchanged. /
|
|
9681
|
-
if (barPinned()) paintBar();
|
|
9703
|
+
say(GUTTER + accent(`✓ ${mp.priceUpdateLabel(m.publishedAt).replace(/^new prices updated/, "prices updated to gu's tables of")}`) +
|
|
9704
|
+
dim(` — ${d.added.length} new · ${d.changed.length} changed · ${d.unchanged} unchanged. /cost all shows them.`) + "\n");
|
|
9682
9705
|
} finally {
|
|
9683
9706
|
priceUpdateBusy = false;
|
|
9684
9707
|
}
|
|
@@ -16624,8 +16647,8 @@ async function main() {
|
|
|
16624
16647
|
);
|
|
16625
16648
|
continue;
|
|
16626
16649
|
}
|
|
16627
|
-
if (line === "/prices" || line.startsWith("/prices ")) {
|
|
16628
|
-
await
|
|
16650
|
+
if (line === "/cost" || line.startsWith("/cost ") || line === "/prices" || line.startsWith("/prices ")) {
|
|
16651
|
+
await runCostCommand(line);
|
|
16629
16652
|
continue;
|
|
16630
16653
|
}
|
|
16631
16654
|
if (line === "/voucher" || line.startsWith("/voucher ")) {
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
|
155
|
-
"this is not your allowance).
|
|
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,
|
|
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
|
-
[
|
|
83
|
-
stderr=subprocess.PIPE, cwd=self.cwd, 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/hints.mjs
CHANGED
|
@@ -19,7 +19,7 @@ export const HINTS = [
|
|
|
19
19
|
"/new starts a new conversation in this folder — the old one is kept",
|
|
20
20
|
"/doctor checks that every configured model really answers",
|
|
21
21
|
"/tokens shows how big the last prompt was and how much of it was RAG",
|
|
22
|
-
"/
|
|
22
|
+
"/cost shows what the last turn and this session cost",
|
|
23
23
|
"/context-window tells gu how big your coding model's context is",
|
|
24
24
|
"/mcp lists the MCP servers and adds one step by step",
|
|
25
25
|
"/hooks lists the commands gu runs on start, ask and turn end",
|
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.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",
|
package/terminal-layout.mjs
CHANGED
|
@@ -2765,6 +2765,7 @@ export const HIDDEN_COMMANDS = [
|
|
|
2765
2765
|
"/hover", // in-turn mouse capture — behaviour unchanged, just hidden
|
|
2766
2766
|
"/reset", // the old name of /new (#278) — still works, one name is offered
|
|
2767
2767
|
"/clear", // Claude Code's name for it — still works, likewise unlisted
|
|
2768
|
+
"/prices", // the old name of /cost (GH #574) — still works, one name is offered
|
|
2768
2769
|
"/full-log", // administrators only (#52): needs an ADMIN token from the web admin
|
|
2769
2770
|
// page — typing it still works, and that token check is the gate
|
|
2770
2771
|
"/reset-output-token-global", // pending a rename to /reset-global-token that also resets
|