@tiens.nguyen/gu-cli 1.0.936 → 1.0.938

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/gu-repl.mjs CHANGED
@@ -1128,7 +1128,7 @@ const COMMANDS = [
1128
1128
  { 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
1129
  { name: "/support", desc: "send the gu support team a request with gu's logs attached (secrets masked) — shows what goes first, then asks" },
1130
1130
  { 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: "/prices", usage: "/prices [update]", desc: "the price table and the cache table, and what the last turn and this session cost — \"update\" applies gu's newest published tables" },
1131
+ { 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
1132
  // ONE name, /new (user, #278). /reset and /clear still work (HIDDEN_COMMANDS) for habit and
1133
1133
  // for Claude Code users — not to be confused with `gu clear` in a shell, which wipes gu's state.
1134
1134
  { name: "/new", desc: "start a new conversation in this folder — the old one is kept (archived); the folder's settings stay" },
@@ -1792,11 +1792,6 @@ function applyClick({ row, col }) {
1792
1792
  void runUpdate();
1793
1793
  return;
1794
1794
  }
1795
- if (pricesRowTarget && row === updateRowAbs &&
1796
- col - 1 >= pricesRowTarget.from && col - 1 < pricesRowTarget.to) {
1797
- void runPricesUpdate();
1798
- return;
1799
- }
1800
1795
  if (limitsRowTarget && row === updateRowAbs &&
1801
1796
  col - 1 >= limitsRowTarget.from && col - 1 < limitsRowTarget.to) {
1802
1797
  void runLimitsSeen();
@@ -3524,14 +3519,6 @@ function syncBarPinning() {
3524
3519
  * update), a standing fact about the licence (the gu token notice — yellow only when urgent), and
3525
3520
  * other agents. Dropped whole, lowest first, when they do not all fit.
3526
3521
  */
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
3522
  function zoneNotice(width) {
3536
3523
  const items = [];
3537
3524
  if (scrolledBack()) {
@@ -3544,7 +3531,6 @@ function zoneNotice(width) {
3544
3531
  }
3545
3532
  // While the token question is open it is the ONLY thing on the screen (#222): the housekeeping
3546
3533
  // 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
3534
  if (limitsUpdate && !tokenQuestionOpen) items.push({ key: "limits", clickable: true, paint: accent, text: `${limitsUpdate.label} (click)` });
3549
3535
  if (tokenNotice?.text && !tokenQuestionOpen) items.push({ key: "token", paint: tokenNotice.urgent ? yellow : dim, text: tokenNotice.text });
3550
3536
  const agents = agentsIndicator(otherAgents);
@@ -3672,7 +3658,6 @@ function frozenZone() {
3672
3658
  const sep = status.length + (notice ? 1 : 0);
3673
3659
  updateRowTarget = notice?.spans.update ?? null;
3674
3660
  agentsRowTarget = notice?.spans.agents ?? null;
3675
- pricesRowTarget = notice?.spans.prices ?? null;
3676
3661
  limitsRowTarget = notice?.spans.limits ?? null;
3677
3662
  logsRowTarget = notice?.spans.logs ?? null;
3678
3663
  shellsRowTarget = notice?.spans.shells ?? null;
@@ -3745,7 +3730,7 @@ function paintBar() {
3745
3730
  // THE NOTICE ROW is the one directly above the separator (#318) — never the separator itself.
3746
3731
  const noticeAbs = zone.noticeRow ? sepAbs - 1 : 0;
3747
3732
  jumpRowTarget = scrolledBack() && jumpSpan ? { row: noticeAbs, ...jumpSpan } : null;
3748
- updateRowAbs = updateRowTarget || agentsRowTarget || pricesRowTarget || limitsRowTarget || logsRowTarget || shellsRowTarget ? noticeAbs : 0;
3733
+ updateRowAbs = updateRowTarget || agentsRowTarget || limitsRowTarget || logsRowTarget || shellsRowTarget ? noticeAbs : 0;
3749
3734
  // preserveCaret:false — the save slot holds the OUTPUT position (see regionUi), and the caret
3750
3735
  // is parked on the input line right after, so there is nothing to preserve here.
3751
3736
  ui(
@@ -3905,8 +3890,6 @@ let updateRowTarget = null;
3905
3890
  let updateRowAbs = 0;
3906
3891
  // …and the agents indicator, which shares that row when no update is pending (task #195).
3907
3892
  let agentsRowTarget = null;
3908
- // …and "new prices updated <date>" (#323).
3909
- let pricesRowTarget = null;
3910
3893
  // …and "output token limits updated <date>" — the cloud token table changed.
3911
3894
  let limitsRowTarget = null;
3912
3895
  // …and "clear logs · 175 MB" (#329), shown only once the logs are worth a row.
@@ -9312,6 +9295,22 @@ function activeCodingModelId() {
9312
9295
  return m.includes("::") ? m.slice(m.indexOf("::") + 2) : m || defaultCodingModel;
9313
9296
  }
9314
9297
 
9298
+ /** The price row a turn on this server + model is charged at — the bar's cost and /cost use the same one. */
9299
+ async function priceFor(rows, url, model) {
9300
+ const mp = await import("./model-prices.mjs");
9301
+ // GH #533: on the free model's key the allowance charges the PROMO's price (its own, else the dearest
9302
+ // listed) — the bar shows that, even when the published table has a (pay-as-you-go estimate) row too.
9303
+ let price = null;
9304
+ if (freeModel) {
9305
+ const fm = await import("./free-model.mjs");
9306
+ price = fm.freeModelPriceRow(freeModel, url, model);
9307
+ }
9308
+ price ??= mp.findPrice(rows, url, model);
9309
+ // GH #570: OpenRouter models are not in the table; their price comes from OpenRouter's own public list.
9310
+ if (!price && mp.hostOf(url) === "openrouter.ai") price = mp.findPrice(await openRouterPrices(), url, model);
9311
+ return price;
9312
+ }
9313
+
9315
9314
  /** After a turn: what its prompt tokens cost, added to the session total. Never throws. */
9316
9315
  async function noteTurnCost(inputTokens, breakdown, coder = null) {
9317
9316
  try {
@@ -9321,16 +9320,7 @@ async function noteTurnCost(inputTokens, breakdown, coder = null) {
9321
9320
  const rows = await loadPrices();
9322
9321
  const url = coder?.url ?? activeCodingUrl();
9323
9322
  const model = coder?.model ?? activeCodingModelId();
9324
- // GH #533: on the free model's key the allowance charges the PROMO's price (its own, else the dearest
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);
9323
+ const price = await priceFor(rows, url, model);
9334
9324
  const cache = readTurnCache(breakdown) ?? { cached: 0, cacheReported: false, firstIn: 0 };
9335
9325
  const c = mp.turnCost({ input: inputTokens, ...cache, price });
9336
9326
  if (!c) {
@@ -9348,11 +9338,6 @@ async function noteTurnCost(inputTokens, breakdown, coder = null) {
9348
9338
  }
9349
9339
  }
9350
9340
 
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
9341
  // ---------------------------------------------------------------------------------------------
9357
9342
  // THE FREE MODEL (task #557, GH #433) — free-model.mjs has the rules; this is the wiring.
9358
9343
  // A model-tokens voucher gives a monthly allowance of the owner's key. The preset (server, key,
@@ -9579,21 +9564,49 @@ async function addGeminiWhenReady(token) {
9579
9564
  return true;
9580
9565
  }
9581
9566
 
9582
- async function runPricesCommand(line = "/prices") {
9567
+ /**
9568
+ * /cost (GH #574; /prices is the same command) — what this session and the last turn cost, and the price
9569
+ * of the coding model in use. Prices keep themselves up to date (refreshPriceUpdate); `/cost all` shows
9570
+ * the whole price and cache tables.
9571
+ */
9572
+ async function runCostCommand(line = "/cost") {
9583
9573
  const mp = await import("./model-prices.mjs");
9584
9574
  console.log("");
9585
- if (line.trim().slice("/prices".length).trim() === "update") {
9575
+ const arg = line.trim().replace(/^\/(cost|prices)/, "").trim();
9576
+ if (arg === "update") {
9586
9577
  await runPricesUpdate();
9587
9578
  return;
9588
9579
  }
9589
9580
  const rows = await withPendingStatus("reading prices", () => loadPrices({ force: true }));
9581
+ const width = process.stdout.columns || 80;
9582
+ const url = activeCodingUrl();
9583
+ const model = activeCodingModelId();
9584
+ if (arg !== "all") {
9585
+ console.log(GUTTER + "this session: " + (sessionCostTurns
9586
+ ? mp.formatUsd(sessionCostUsd, { estimated: sessionCostEstimated }) + dim(` over ${sessionCostTurns} turn${sessionCostTurns === 1 ? "" : "s"}`)
9587
+ : dim("$0 — no priced turn yet")));
9588
+ if (lastTurnCost?.usd != null) {
9589
+ const share = lastTurnCost.input ? Math.round((100 * lastTurnCost.cachedTokens) / lastTurnCost.input) : 0;
9590
+ console.log(GUTTER + `last turn: ${mp.formatUsd(lastTurnCost.usd, { estimated: lastTurnCost.estimated })}` +
9591
+ dim(` — ${lastTurnCost.input.toLocaleString("en-US")} prompt tokens, ${share}% cached`));
9592
+ }
9593
+ const p = model ? await priceFor(rows, url, model) : null;
9594
+ // Only the prices there are: a promo row has an input price alone (no "— cached · — out").
9595
+ const parts = [["in", p?.input], ["cached", p?.cachedInput], ["out", p?.output]]
9596
+ .filter(([, v]) => Number.isFinite(v))
9597
+ .map(([k, v]) => `${mp.formatUsd(v)} ${k}`);
9598
+ if (p && parts.length) {
9599
+ console.log(GUTTER + `${model}: ` + dim(`${parts.join(" · ")} per 1M tokens`));
9600
+ } else if (model) {
9601
+ console.log(GUTTER + dim(`${model}: no price — a model on your own server costs nothing here.`));
9602
+ }
9603
+ console.log(GUTTER + dim("Prompt tokens only; output is not counted yet. /cost all shows every price.") + "\n");
9604
+ return;
9605
+ }
9590
9606
  if (!rows.length) {
9591
9607
  console.log(GUTTER + yellow("no prices — the local API is older than this gu, or unreachable.") + "\n");
9592
9608
  return;
9593
9609
  }
9594
- const width = process.stdout.columns || 80;
9595
- const url = activeCodingUrl();
9596
- const model = activeCodingModelId();
9597
9610
  const paint = (l) => (l.startsWith("▸") ? accent(l) : /^[a-z0-9.-]+\.[a-z]+(:\d+)?( |$)/i.test(l) ? l : dim(l));
9598
9611
  console.log(GUTTER + "Prices");
9599
9612
  for (const l of mp.priceTableLines(rows, { width, current: { url, model }, version: priceVersion })) console.log(GUTTER + paint(l));
@@ -9602,7 +9615,6 @@ async function runPricesCommand(line = "/prices") {
9602
9615
  for (const l of mp.cacheShareLines({ yours: rows, width, current: { url, model } })) console.log(GUTTER + paint(l));
9603
9616
  console.log("");
9604
9617
  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
9618
  if (!mp.findPrice(rows, url, model)) {
9607
9619
  for (const r of wrapBlock(mp.noPriceLine({ model, host: mp.hostOf(url) }), GUTTER, width)) console.log(GUTTER + yellow(r));
9608
9620
  }
@@ -9616,11 +9628,10 @@ async function runPricesCommand(line = "/prices") {
9616
9628
  }
9617
9629
 
9618
9630
  // ---------------------------------------------------------------------------------------------
9619
- // "NEW PRICES UPDATED <date>" (#323): the hosted API's newest published tables, checked at start
9620
- // and hourly beside the version check; when newer than what this account applied, a clickable item
9621
- // on the notice row. A click (or /prices update) writes both tables into the user's own Mongo.
9631
+ // PUBLISHED PRICES (#323, GH #574): the hosted API's newest published tables, checked at start and
9632
+ // hourly beside the version check; when newer than what this account applied, they are applied by
9633
+ // themselves — no notice, nothing to click. `/cost update` does the same by hand, and says what changed.
9622
9634
  // ---------------------------------------------------------------------------------------------
9623
- let priceUpdate = null; // { publishedAt, tables } while newer tables wait
9624
9635
  let priceUpdateBusy = false;
9625
9636
 
9626
9637
  async function fetchPublishedTables() {
@@ -9636,49 +9647,46 @@ async function fetchPublishedTables() {
9636
9647
  }
9637
9648
  }
9638
9649
 
9639
- /** Are newer tables published? Fails silently to "no" — like the version check. */
9650
+ /** Newer tables published? Apply them, quietly. Fails silently — like the version check. */
9640
9651
  async function refreshPriceUpdate() {
9641
9652
  try {
9642
9653
  const mp = await import("./model-prices.mjs");
9643
9654
  const tables = await fetchPublishedTables();
9644
9655
  if (!tables) return;
9645
9656
  await loadPrices({ force: true });
9646
- const was = Boolean(priceUpdate);
9647
- priceUpdate = mp.hasNewerPublished(pricePublishedAt, tables.publishedAt) ? { publishedAt: tables.publishedAt, tables } : null;
9648
- if (Boolean(priceUpdate) !== was && barPinned()) paintBar();
9657
+ if (mp.hasNewerPublished(pricePublishedAt, tables.publishedAt)) await runPricesUpdate({ tables, quiet: true });
9649
9658
  } catch {
9650
- /* a price notice is never worth an error */
9659
+ /* a price update is never worth an error */
9651
9660
  }
9652
9661
  }
9653
9662
 
9654
- /** Apply gu's newest published tables to this account's Mongo — the notice's click. */
9655
- async function runPricesUpdate() {
9663
+ /** Apply gu's newest published tables to this account's Mongo — by itself (quiet), or by /cost update. */
9664
+ async function runPricesUpdate({ tables: given = null, quiet = false } = {}) {
9656
9665
  if (priceUpdateBusy) return;
9657
9666
  priceUpdateBusy = true;
9667
+ const say = (l) => { if (!quiet) console.log(l); };
9658
9668
  try {
9659
9669
  const mp = await import("./model-prices.mjs");
9660
- const tables = (await fetchPublishedTables()) ?? priceUpdate?.tables ?? null;
9670
+ const tables = given ?? (await fetchPublishedTables());
9661
9671
  if (!tables) {
9662
- console.log(GUTTER + yellow("couldn't reach gu's published prices — try again later.") + "\n");
9672
+ say(GUTTER + yellow("couldn't reach gu's published prices — try again later.") + "\n");
9663
9673
  return;
9664
9674
  }
9665
9675
  const current = await loadPrices({ force: true });
9666
9676
  const m = mp.mergePublishedTables(current, tables);
9667
9677
  if (!m.ok) {
9668
- console.log(GUTTER + yellow(`prices not updated — ${m.problem}`) + "\n");
9678
+ say(GUTTER + yellow(`prices not updated — ${m.problem}`) + "\n");
9669
9679
  return;
9670
9680
  }
9671
9681
  const res = await priceApi("PUT", { version: m.version, publishedAt: m.publishedAt, rows: m.rows, removes: [] });
9672
9682
  if (res?.error) {
9673
- console.log(GUTTER + red(`couldn't save the prices — ${res.error}. Nothing changed.`) + "\n");
9683
+ say(GUTTER + red(`couldn't save the prices — ${res.error}. Nothing changed.`) + "\n");
9674
9684
  return;
9675
9685
  }
9676
9686
  await loadPrices({ force: true });
9677
- priceUpdate = null;
9678
9687
  const d = m.diff;
9679
- console.log(GUTTER + accent(`✓ ${mp.priceUpdateLabel(m.publishedAt).replace(/^new prices updated/, "prices updated to gu's tables of")}`) +
9680
- dim(` — ${d.added.length} new · ${d.changed.length} changed · ${d.unchanged} unchanged. /prices shows them.`) + "\n");
9681
- if (barPinned()) paintBar();
9688
+ say(GUTTER + accent(`✓ ${mp.priceUpdateLabel(m.publishedAt).replace(/^new prices updated/, "prices updated to gu's tables of")}`) +
9689
+ dim(` — ${d.added.length} new · ${d.changed.length} changed · ${d.unchanged} unchanged. /cost all shows them.`) + "\n");
9682
9690
  } finally {
9683
9691
  priceUpdateBusy = false;
9684
9692
  }
@@ -16624,8 +16632,8 @@ async function main() {
16624
16632
  );
16625
16633
  continue;
16626
16634
  }
16627
- if (line === "/prices" || line.startsWith("/prices ")) {
16628
- await runPricesCommand(line);
16635
+ if (line === "/cost" || line.startsWith("/cost ") || line === "/prices" || line.startsWith("/prices ")) {
16636
+ await runCostCommand(line);
16629
16637
  continue;
16630
16638
  }
16631
16639
  if (line === "/voucher" || line.startsWith("/voucher ")) {
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
- "/prices shows what the last turn and this session cost",
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.936",
3
+ "version": "1.0.938",
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",
@@ -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