@tiens.nguyen/gu-cli 1.0.932 → 1.0.935
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/cli-token.mjs +6 -3
- package/client-expert-api.mjs +4 -0
- package/client-expert-run.mjs +84 -0
- package/coding-provider-setup.mjs +27 -0
- package/free-model.mjs +33 -6
- package/gonext_agent_chat.py +298 -13
- package/gu-cli.mjs +46 -0
- package/gu-repl.mjs +137 -5
- package/gu_turn_notes.py +29 -2
- package/model-doctor.mjs +29 -5
- package/model-prices.mjs +22 -0
- package/package.json +2 -1
- package/python-unix.mjs +120 -0
- package/setup-fixes.mjs +6 -1
- package/turn-notes.mjs +65 -0
package/gu-repl.mjs
CHANGED
|
@@ -161,7 +161,7 @@ import { codingBannerLabel, isOllamaCloudUrl, SECRET_KEY_HINT } from "./coding-k
|
|
|
161
161
|
import { questionEchoText, thoughtPrintSeq, wrapDiffText } from "./terminal-layout.mjs";
|
|
162
162
|
import { focusReport, createMouseParking } from "./terminal-layout.mjs"; // GH #558
|
|
163
163
|
import { createTurnQueue, droppedNote } from "./turn-queue.mjs"; // GH #429: questions typed during a turn wait here
|
|
164
|
-
import { sendNote, takeUnread, sweepOldNotes, parseUserNote, questionWithNotes, USERNOTE_PREFIX } from "./turn-notes.mjs"; // GH #506: …or go to the running turn
|
|
164
|
+
import { sendNote, sendNow, createSendNowChord, waitingLabel, takeUnread, sweepOldNotes, parseUserNote, parseSay, questionWithNotes, USERNOTE_PREFIX, SAY_PREFIX } from "./turn-notes.mjs"; // GH #506: …or go to the running turn
|
|
165
165
|
import { globalPrefixOf } from "./install-path.mjs";
|
|
166
166
|
import { indentBlock, commandBlockRows, wrapIndented } from "./terminal-layout.mjs"; // every line of an Allow-prompt detail indented (#189); wrapped + collapsible command (#204)
|
|
167
167
|
import { firstGuOnPath, pathGuMismatch, guOnPathIsCurrent, updateAttemptRecord, repeatUpdateNotice } from "./update-verify.mjs";
|
|
@@ -1296,7 +1296,8 @@ function pastQuestion(text) {
|
|
|
1296
1296
|
function waitingNoteRows() {
|
|
1297
1297
|
if (!following) return [];
|
|
1298
1298
|
const width = Math.max(20, process.stdout.columns || 80);
|
|
1299
|
-
const
|
|
1299
|
+
const notes = waitingNotes.filter((n) => !n.shown);
|
|
1300
|
+
const texts = [...notes.map((n) => n.text), ...turnQueue.list()];
|
|
1300
1301
|
const rows = [];
|
|
1301
1302
|
for (const t of texts) {
|
|
1302
1303
|
const lines = pastQuestion(t).replace(/\n+$/, "").split("\n").map((l) => stripAnsiEscapes(l));
|
|
@@ -1304,7 +1305,10 @@ function waitingNoteRows() {
|
|
|
1304
1305
|
if (lines.length > 3) rows.push(dim(`${GUTTER}… ${lines.length - 3} more line(s)`));
|
|
1305
1306
|
}
|
|
1306
1307
|
if (!rows.length) return [];
|
|
1307
|
-
|
|
1308
|
+
// GH #560: say what happens to it, as Claude Code does ("⎿ Queued · ctrl+x ctrl+s to send now").
|
|
1309
|
+
const label = waitingLabel({ notes: waitingNotes.length, queued: turnQueue.size, sending: sendNowPending });
|
|
1310
|
+
const body = rows.length > 6 ? [...rows.slice(0, 5), dim(`${GUTTER}… ${rows.length - 5} more line(s) waiting`)] : rows;
|
|
1311
|
+
return ["", ...body, ...(label ? [dim(clipVisible(`${GUTTER}${label}`, width - 1))] : [])];
|
|
1308
1312
|
}
|
|
1309
1313
|
function flushPendingEcho() {
|
|
1310
1314
|
if (pendingEcho === null) return;
|
|
@@ -2533,7 +2537,8 @@ rl.on("line", (l) => {
|
|
|
2533
2537
|
if (queued && currentJobId && !cancelRequested && sendNote(currentJobId, queued)) {
|
|
2534
2538
|
waitingNotes.push({ text: queued, shown: !barPinned() });
|
|
2535
2539
|
if (barPinned()) paintBar();
|
|
2536
|
-
|
|
2540
|
+
// GH #566: unpinned, the message goes straight into the history — and its hint with it, or there was none at all.
|
|
2541
|
+
else process.stdout.write("\n" + pastQuestion(queued) + dim(`${GUTTER}${waitingLabel({ notes: 1 })}`) + "\n");
|
|
2537
2542
|
return;
|
|
2538
2543
|
}
|
|
2539
2544
|
if (queued) {
|
|
@@ -5192,6 +5197,21 @@ if (process.stdin.isTTY) {
|
|
|
5192
5197
|
// so the switch did nothing while the agent was thinking — which is exactly when a user
|
|
5193
5198
|
// watching it reach for commands wants to change it.
|
|
5194
5199
|
if (key && key.name === "tab" && key.shift) switchEditMode();
|
|
5200
|
+
// GH #560: Ctrl+X Ctrl+S — what was typed for the running turn is read NOW (see turn-notes.mjs).
|
|
5201
|
+
if (sendNowChord.feed(key)) {
|
|
5202
|
+
if (waitingNotes.length && currentJobId && !cancelRequested && sendNow(currentJobId)) {
|
|
5203
|
+
sendNowPending = true;
|
|
5204
|
+
}
|
|
5205
|
+
rl.line = typedDuringTurn ? turnDraft : "";
|
|
5206
|
+
rl.cursor = rl.line.length;
|
|
5207
|
+
if (barPinned()) paintBar();
|
|
5208
|
+
return;
|
|
5209
|
+
}
|
|
5210
|
+
if (sendNowChord.armed) {
|
|
5211
|
+
rl.line = typedDuringTurn ? turnDraft : "";
|
|
5212
|
+
rl.cursor = rl.line.length;
|
|
5213
|
+
return;
|
|
5214
|
+
}
|
|
5195
5215
|
// A printable key (or Enter after one) means the user is typing a question that will not
|
|
5196
5216
|
// be sent — say so in the input row now, not after they have typed the whole thing (#258).
|
|
5197
5217
|
// Not every printable key is typing: a mouse report or cursor reply whose ESC came alone
|
|
@@ -6842,6 +6862,35 @@ async function chooseCodingModelFrom(ps, all, question, current, { back = false
|
|
|
6842
6862
|
* unlisted one may be exactly right.
|
|
6843
6863
|
*/
|
|
6844
6864
|
async function chooseFromModelList(all, question, current = 0, { back = false, notes = null } = {}) {
|
|
6865
|
+
// GH #570: a long "company/model" list (OpenRouter: 436 models) is picked in two steps — the company, then its
|
|
6866
|
+
// models — instead of one endless scroll. ← back from the models returns to the companies.
|
|
6867
|
+
const cs = await import("./coding-provider-setup.mjs");
|
|
6868
|
+
const groups = cs.modelGroups(all);
|
|
6869
|
+
if (groups) {
|
|
6870
|
+
const cur = typeof current === "string" ? current : all[Number(current) || 0] ?? "";
|
|
6871
|
+
let gAt = Math.max(0, groups.findIndex((g) => g.ids.includes(cur)));
|
|
6872
|
+
for (;;) {
|
|
6873
|
+
const gi = await pickFromList([...groups.map((g) => `${g.name}${dim(` (${g.ids.length})`)}`), "type a model name…"], gAt, {
|
|
6874
|
+
back,
|
|
6875
|
+
header: () => [dim(` ${question} — first the company (${PICK_HINT})`)],
|
|
6876
|
+
headerRows: 1,
|
|
6877
|
+
});
|
|
6878
|
+
if (gi === PICK_BACK) return BACK;
|
|
6879
|
+
if (gi < 0) return null;
|
|
6880
|
+
if (gi === groups.length) {
|
|
6881
|
+
const typed = (await ask(" model name: ")).trim();
|
|
6882
|
+
return typed || null;
|
|
6883
|
+
}
|
|
6884
|
+
gAt = gi;
|
|
6885
|
+
const ids = groups[gi].ids;
|
|
6886
|
+
const r = await chooseFromModelList(ids, question, Math.max(0, ids.indexOf(cur)), {
|
|
6887
|
+
back: true,
|
|
6888
|
+
notes: notes ? ids.map((id) => notes[all.indexOf(id)]) : null,
|
|
6889
|
+
});
|
|
6890
|
+
if (r === BACK) continue;
|
|
6891
|
+
return r;
|
|
6892
|
+
}
|
|
6893
|
+
}
|
|
6845
6894
|
// `notes` (GH #397): a dim note per row ("an audio/speech model"), as /agent-model's own list has.
|
|
6846
6895
|
const rows = [...all.map((m, i) => (notes?.[i] ? `${m}${dim(` · ${notes[i]}`)}` : m)), "type a model name…"];
|
|
6847
6896
|
const at = typeof current === "string" ? all.indexOf(current) : Number(current) || 0;
|
|
@@ -9243,6 +9292,20 @@ async function loadPrices({ force = false } = {}) {
|
|
|
9243
9292
|
return priceRows;
|
|
9244
9293
|
}
|
|
9245
9294
|
|
|
9295
|
+
/** GH #570: OpenRouter's published prices, fetched once per session (public, no key); [] when unreachable. */
|
|
9296
|
+
let openRouterPriceRows = null;
|
|
9297
|
+
async function openRouterPrices() {
|
|
9298
|
+
if (openRouterPriceRows) return openRouterPriceRows;
|
|
9299
|
+
try {
|
|
9300
|
+
const mp = await import("./model-prices.mjs");
|
|
9301
|
+
const r = await fetch("https://openrouter.ai/api/v1/models", { signal: AbortSignal.timeout(8000) });
|
|
9302
|
+
openRouterPriceRows = r.ok ? mp.openRouterPriceRows(await r.json()) : [];
|
|
9303
|
+
} catch {
|
|
9304
|
+
openRouterPriceRows = [];
|
|
9305
|
+
}
|
|
9306
|
+
return openRouterPriceRows;
|
|
9307
|
+
}
|
|
9308
|
+
|
|
9246
9309
|
/** The coder model id in use — the folder's /model pick ("<kind>::<model>") or the account default. */
|
|
9247
9310
|
function activeCodingModelId() {
|
|
9248
9311
|
const m = String(sessionCodingModel || "");
|
|
@@ -9266,6 +9329,8 @@ async function noteTurnCost(inputTokens, breakdown, coder = null) {
|
|
|
9266
9329
|
price = fm.freeModelPriceRow(freeModel, url, model);
|
|
9267
9330
|
}
|
|
9268
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);
|
|
9269
9334
|
const cache = readTurnCache(breakdown) ?? { cached: 0, cacheReported: false, firstIn: 0 };
|
|
9270
9335
|
const c = mp.turnCost({ input: inputTokens, ...cache, price });
|
|
9271
9336
|
if (!c) {
|
|
@@ -9428,7 +9493,7 @@ async function runVoucherCommand(line = "/voucher") {
|
|
|
9428
9493
|
const state = await ct.readState(dir);
|
|
9429
9494
|
const { DEFAULT_API_BASE } = await import("./device-login.mjs");
|
|
9430
9495
|
const device = await ct.thisDevice({ instanceId: myInstanceId || "" }).catch(() => null);
|
|
9431
|
-
const
|
|
9496
|
+
const redeem = (ageConfirmed) => withPendingStatus("checking the voucher", () =>
|
|
9432
9497
|
ct.redeemVoucher({
|
|
9433
9498
|
mode: isClientExpert() ? "expert" : "client",
|
|
9434
9499
|
apiBase,
|
|
@@ -9436,8 +9501,28 @@ async function runVoucherCommand(line = "/voucher") {
|
|
|
9436
9501
|
token: state.token,
|
|
9437
9502
|
device,
|
|
9438
9503
|
code,
|
|
9504
|
+
ageConfirmed,
|
|
9439
9505
|
})
|
|
9440
9506
|
);
|
|
9507
|
+
let r = await redeem(false);
|
|
9508
|
+
// GH #567: a gu + Gemini code — the same 18+ question the web page asks, here; nothing is used on a no.
|
|
9509
|
+
if (!r.ok && r.why === "gemini-age") {
|
|
9510
|
+
const m = Number(r.months) || 1;
|
|
9511
|
+
console.log(GUTTER + `This code is ${accent("gu + Gemini")} — ${m} month${m === 1 ? "" : "s"} of Google's Gemini models in gu.`);
|
|
9512
|
+
const a = String((await askOr("", () => ask(`${GUTTER}Are you 18 or older? [y/N]: `))) ?? "").trim().toLowerCase();
|
|
9513
|
+
if (!/^y(es)?$/.test(a)) {
|
|
9514
|
+
console.log(GUTTER + dim("Not used — the code is still good.") + "\n");
|
|
9515
|
+
return;
|
|
9516
|
+
}
|
|
9517
|
+
r = await redeem(true);
|
|
9518
|
+
}
|
|
9519
|
+
if (r.ok && r.kind === "gemini") {
|
|
9520
|
+
console.log(GUTTER + accent(`✓ gu + Gemini: ${r.months} month${r.months === 1 ? "" : "s"}`) + (r.paidUntil ? dim(` (until ${ct.shortDate(r.paidUntil)})`) : "") + ".");
|
|
9521
|
+
await addGeminiWhenReady(r.token || state.token);
|
|
9522
|
+
console.log("");
|
|
9523
|
+
if (barPinned()) paintBar();
|
|
9524
|
+
return;
|
|
9525
|
+
}
|
|
9441
9526
|
if (!r.ok) {
|
|
9442
9527
|
console.log(GUTTER + yellow(r.error) + "\n");
|
|
9443
9528
|
return;
|
|
@@ -9466,6 +9551,34 @@ async function runVoucherCommand(line = "/voucher") {
|
|
|
9466
9551
|
if (barPinned()) paintBar();
|
|
9467
9552
|
}
|
|
9468
9553
|
|
|
9554
|
+
/**
|
|
9555
|
+
* GH #567: after a gu + Gemini code, Google sets up this holder's own project (about a minute). Ask for the preset
|
|
9556
|
+
* until it carries Gemini with its key, then apply it: the Gemini provider and its models go into /model by
|
|
9557
|
+
* themselves — nobody adds a provider by hand. After 90 s it stops waiting: every start of gu fetches the preset.
|
|
9558
|
+
*/
|
|
9559
|
+
const GEMINI_HOST_RE = /generativelanguage\.googleapis\.com/;
|
|
9560
|
+
async function addGeminiWhenReady(token) {
|
|
9561
|
+
const fm = await import("./free-model.mjs");
|
|
9562
|
+
const gemOf = (p) => fm.presetProviders(p).find((x) => GEMINI_HOST_RE.test(x.baseUrl) && x.apiKey);
|
|
9563
|
+
const ready = await withPendingStatus("Google is setting up your Gemini (about a minute)", async () => {
|
|
9564
|
+
for (const started = Date.now(); Date.now() - started < 90_000; await new Promise((res) => setTimeout(res, 8_000))) {
|
|
9565
|
+
const got = await fm.fetchPreset({ hostedBase: await freeModelHostedBase(), token }).catch(() => ({ ok: false }));
|
|
9566
|
+
if (got.ok && gemOf(got.preset)) return got.preset;
|
|
9567
|
+
}
|
|
9568
|
+
return null;
|
|
9569
|
+
});
|
|
9570
|
+
if (!ready) {
|
|
9571
|
+
console.log(GUTTER + dim("Gemini is still being set up — gu adds it to /model by itself at its next start."));
|
|
9572
|
+
return false;
|
|
9573
|
+
}
|
|
9574
|
+
// GH #569: applied as a fresh choice, like loading a preset by hand — the Gemini row, its key and its models are added
|
|
9575
|
+
// and its model is chosen (the service puts the code redeemed last first), whatever plan this computer is on.
|
|
9576
|
+
await setUpFreeModel({ token, announce: true });
|
|
9577
|
+
const ids = (gemOf(ready)?.models ?? []).map((m) => m.id);
|
|
9578
|
+
console.log(GUTTER + accent("✓ Gemini added to /model") + dim(ids.length ? ` — ${ids.join(", ")}` : ""));
|
|
9579
|
+
return true;
|
|
9580
|
+
}
|
|
9581
|
+
|
|
9469
9582
|
async function runPricesCommand(line = "/prices") {
|
|
9470
9583
|
const mp = await import("./model-prices.mjs");
|
|
9471
9584
|
console.log("");
|
|
@@ -12017,6 +12130,8 @@ let followingAttached = false;
|
|
|
12017
12130
|
let followAborted = false;
|
|
12018
12131
|
// GH #506/#514: what was typed during this turn — waiting for the agent, and what it has read.
|
|
12019
12132
|
let waitingNotes = []; // {text, shown} — shown: already in the history (unpinned)
|
|
12133
|
+
let sendNowPending = false; // GH #560: Ctrl+X Ctrl+S pressed; cleared when the agent reads the notes
|
|
12134
|
+
const sendNowChord = createSendNowChord();
|
|
12020
12135
|
let readNotes = []; // texts the agent read, kept with this turn's question
|
|
12021
12136
|
let currentJobId = null; // the running turn's jobId — so Ctrl+C can cancel it server-side
|
|
12022
12137
|
let cancelRequested = false; // a cancel POST has been sent for the current turn
|
|
@@ -14276,6 +14391,7 @@ async function runAgentTurn(history, { attachJobId = "", ownJob = false } = {})
|
|
|
14276
14391
|
// GH #514: the agent just read what was typed — it becomes part of the history HERE, between its steps.
|
|
14277
14392
|
if (line.startsWith(USERNOTE_PREFIX)) {
|
|
14278
14393
|
const taken = waitingNotes.splice(0, parseUserNote(line));
|
|
14394
|
+
if (!waitingNotes.length) sendNowPending = false; // GH #560
|
|
14279
14395
|
if (taken.length) {
|
|
14280
14396
|
readNotes.push(...taken.map((n) => n.text));
|
|
14281
14397
|
const unseen = taken.filter((n) => !n.shown);
|
|
@@ -14289,6 +14405,21 @@ async function runAgentTurn(history, { attachJobId = "", ownJob = false } = {})
|
|
|
14289
14405
|
lastContentAt = Date.now();
|
|
14290
14406
|
continue;
|
|
14291
14407
|
}
|
|
14408
|
+
// GH #562: the agent answered, in one line, what was typed during the turn — normal text, under that message.
|
|
14409
|
+
if (line.startsWith(SAY_PREFIX)) {
|
|
14410
|
+
const said = parseSay(line);
|
|
14411
|
+
if (said) {
|
|
14412
|
+
releaseHeldThought();
|
|
14413
|
+
onContent();
|
|
14414
|
+
// The answer's own shape: wrapped at the text column, the ● hanging in the gutter on its first row.
|
|
14415
|
+
const rows = wrapBlock(said, GUTTER, process.stdout.columns || 80).map((l) => renderMdBold(l));
|
|
14416
|
+
const block = rows.map((l, i) => (i === 0 ? markLine("●") : GUTTER) + l).join("\n");
|
|
14417
|
+
process.stdout.write((lastWasBlank ? "" : "\n") + block + "\n\n");
|
|
14418
|
+
lastWasBlank = true;
|
|
14419
|
+
}
|
|
14420
|
+
lastContentAt = Date.now();
|
|
14421
|
+
continue;
|
|
14422
|
+
}
|
|
14292
14423
|
if (line.startsWith(MODELFALLBACK_PREFIX)) {
|
|
14293
14424
|
const fb = parseModelFallback(line);
|
|
14294
14425
|
if (fb) {
|
|
@@ -14940,6 +15071,7 @@ async function runAgentTurn(history, { attachJobId = "", ownJob = false } = {})
|
|
|
14940
15071
|
}
|
|
14941
15072
|
currentJobId = null;
|
|
14942
15073
|
waitingNotes = [];
|
|
15074
|
+
sendNowPending = false;
|
|
14943
15075
|
// Drop anything typed (but not submitted) during the turn — echo was muted, so it's
|
|
14944
15076
|
// invisible; without this it would surface on the next prompt.
|
|
14945
15077
|
rl.line = "";
|
package/gu_turn_notes.py
CHANGED
|
@@ -17,8 +17,11 @@ import re
|
|
|
17
17
|
import time
|
|
18
18
|
|
|
19
19
|
NOTE_HEAD = "----- A NOTE FROM THE USER (typed while you were working) -----"
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
# GH #562: answered at once, in one line, and the turn goes on — like Claude Code. The answer goes through
|
|
21
|
+
# say(), which gu prints as normal text right under the user's message.
|
|
22
|
+
NOTE_TAIL = ("Answer it FIRST, in one short line, with say(\"...\") — what you will do about it: now, or after the "
|
|
23
|
+
"current work. Then go on with the task in the same step. It adds to the task; it replaces the task, "
|
|
24
|
+
"or stops it, only if it says so.")
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
def notes_dir() -> str:
|
|
@@ -66,6 +69,29 @@ def take_notes(job_id: str) -> list[str]:
|
|
|
66
69
|
return texts
|
|
67
70
|
|
|
68
71
|
|
|
72
|
+
def now_path(job_id: str) -> str:
|
|
73
|
+
"""GH #560: gu creates this when the user presses Ctrl+X Ctrl+S ("send now")."""
|
|
74
|
+
return os.path.join(notes_dir(), _safe(job_id) + ".now")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def send_now_requested(job_id: str) -> bool:
|
|
78
|
+
"""True when the user asked for their message to be read NOW: a command the agent is waiting on
|
|
79
|
+
gives way (it is handed to the background, never killed) so the step ends and the note is read."""
|
|
80
|
+
if not _safe(job_id):
|
|
81
|
+
return False
|
|
82
|
+
try:
|
|
83
|
+
return os.path.exists(now_path(job_id))
|
|
84
|
+
except OSError:
|
|
85
|
+
return False
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def clear_send_now(job_id: str) -> None:
|
|
89
|
+
try:
|
|
90
|
+
os.remove(now_path(job_id))
|
|
91
|
+
except OSError:
|
|
92
|
+
pass
|
|
93
|
+
|
|
94
|
+
|
|
69
95
|
def note_block(texts: list[str]) -> str:
|
|
70
96
|
"""The text added after a step's observations."""
|
|
71
97
|
body = "\n\n".join(texts)
|
|
@@ -83,6 +109,7 @@ def add_to_step(step_log, job_id: str) -> int:
|
|
|
83
109
|
texts = take_notes(job_id)
|
|
84
110
|
if not texts:
|
|
85
111
|
return 0
|
|
112
|
+
clear_send_now(job_id) # GH #560: honoured — the note reaches the model with this step
|
|
86
113
|
obs = getattr(step_log, "observations", None)
|
|
87
114
|
head = obs + "\n\n" if isinstance(obs, str) and obs.strip() else ""
|
|
88
115
|
step_log.observations = head + note_block(texts)
|
package/model-doctor.mjs
CHANGED
|
@@ -191,12 +191,14 @@ function runPip(python, pkgs, extraArgs = [], { log = () => {}, timeoutMs = PIP_
|
|
|
191
191
|
clearTimeout(limit);
|
|
192
192
|
resolve(r);
|
|
193
193
|
};
|
|
194
|
-
|
|
194
|
+
// GH #564: in the installer (GU_PIP_QUIET=1) pip's download list stays in the log; "… still installing" shows it is alive.
|
|
195
|
+
const echo = process.env.GU_PIP_QUIET !== "1";
|
|
196
|
+
child.stdout?.on("data", (d) => { keep(d); if (echo) process.stdout.write(d); });
|
|
195
197
|
child.stderr?.on("data", (d) => {
|
|
196
198
|
const s = String(d);
|
|
197
199
|
err += s;
|
|
198
200
|
keep(s);
|
|
199
|
-
process.stderr.write(s);
|
|
201
|
+
if (echo) process.stderr.write(s);
|
|
200
202
|
});
|
|
201
203
|
const beat = setInterval(() => log(` … still installing (${Math.round((Date.now() - started) / 1000)} s)`), 15_000);
|
|
202
204
|
const limit = setTimeout(() => {
|
|
@@ -208,7 +210,14 @@ function runPip(python, pkgs, extraArgs = [], { log = () => {}, timeoutMs = PIP_
|
|
|
208
210
|
}
|
|
209
211
|
finish({ code: 124, err: `pip did not finish within ${Math.round(timeoutMs / 60000)} minutes`, timedOut: true });
|
|
210
212
|
}, timeoutMs);
|
|
211
|
-
child.on("exit", (code) =>
|
|
213
|
+
child.on("exit", (code) => {
|
|
214
|
+
// Quiet (the installer): pip's errors are shown only for a real failure — not for the ones gu answers itself
|
|
215
|
+
// (PEP 668 → gu's own environment; no pip → a venv brings it), whose block of text read like a failed install.
|
|
216
|
+
if (!echo && code && !/externally-managed-environment|No module named pip/.test(err)) {
|
|
217
|
+
process.stderr.write(err.trim().split("\n").slice(-12).join("\n") + "\n");
|
|
218
|
+
}
|
|
219
|
+
finish({ code: code ?? 1, err });
|
|
220
|
+
});
|
|
212
221
|
child.on("error", (e) => finish({ code: -1, err: String(e?.message ?? e) }));
|
|
213
222
|
});
|
|
214
223
|
}
|
|
@@ -1438,11 +1447,11 @@ export async function ensureSkillsNodeLibs({ log, install = npmInstallInto, dir
|
|
|
1438
1447
|
* (smolagents + openai) — required to run the agent?" — the same question twice in a row on
|
|
1439
1448
|
* every first install. A yes that was just given is not asked for again.
|
|
1440
1449
|
*/
|
|
1441
|
-
export async function ensureAgentDeps({ log, confirm, modelHost = canHostMlxModels(), agreed = [], os = platform(), installPython = null, skillsPack = false }) {
|
|
1450
|
+
export async function ensureAgentDeps({ log, confirm, modelHost = canHostMlxModels(), agreed = [], os = platform(), installPython = null, skillsPack = false, pythonBuild = undefined }) {
|
|
1442
1451
|
const out = {};
|
|
1443
1452
|
log("");
|
|
1444
1453
|
log(" Checking the agent's dependencies…");
|
|
1445
|
-
// python3 — the whole agent runs on it.
|
|
1454
|
+
// python3 — the whole agent runs on it. gu offers to install it for this user: Windows (GH #363), macOS/Linux (GH #564).
|
|
1446
1455
|
if (!(await pyHasModule("sys")) && os === "win32") {
|
|
1447
1456
|
const yes = await confirm(
|
|
1448
1457
|
"Python 3 is not installed, and the agent runs on it. Install Python 3.12 for your user only? (about 25 MB from python.org; no administrator needed)",
|
|
@@ -1456,6 +1465,21 @@ export async function ensureAgentDeps({ log, confirm, modelHost = canHostMlxMode
|
|
|
1456
1465
|
else log(yellow(` could not install Python: ${r.error ?? "unknown error"}`));
|
|
1457
1466
|
}
|
|
1458
1467
|
}
|
|
1468
|
+
// GH #564: macOS and Linux — no Python, Apple's 3.9, or Debian's without venv: gu offers its own, for this user.
|
|
1469
|
+
if (os !== "win32") {
|
|
1470
|
+
const pu = await import("./python-unix.mjs");
|
|
1471
|
+
const probe = (code) => new Promise((resolve) => {
|
|
1472
|
+
execFile(python3Bin(), ["-c", code], { timeout: 30000 }, (err, stdout) => resolve({ ok: !err, out: String(stdout ?? "") }));
|
|
1473
|
+
});
|
|
1474
|
+
const usable = await pu.pythonUsable(probe);
|
|
1475
|
+
const build = pythonBuild === undefined ? pu.pythonBuildFor({ platform: os }) : pythonBuild;
|
|
1476
|
+
if (!usable.ok && build && (await confirm(pu.pythonOfferText(usable, build), true))) {
|
|
1477
|
+
log(` Installing Python ${pu.PYTHON_UNIX.version} …`);
|
|
1478
|
+
const r = await (installPython ?? pu.installPythonUnix)({ build, log });
|
|
1479
|
+
if (r.ok) log(` ✓ Python ${pu.PYTHON_UNIX.version} installed for your user (~/.gonext/python)`);
|
|
1480
|
+
else log(yellow(` could not install Python: ${r.error ?? "unknown error"}`));
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1459
1483
|
if (!(await pyHasModule("sys"))) {
|
|
1460
1484
|
log(yellow(` ${python3Bin()} not found. Install Python 3 — ${pythonInstallHint()} —`));
|
|
1461
1485
|
log(" then run `gu-cli doctor` again.");
|
package/model-prices.mjs
CHANGED
|
@@ -205,6 +205,28 @@ export function costSegment(last) {
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
/** The line /prices prints when the coder in use has no price — why, and that nothing is broken. */
|
|
208
|
+
/**
|
|
209
|
+
* GH #570: OpenRouter publishes every model's price in its public GET /api/v1/models — per TOKEN, as strings.
|
|
210
|
+
* → price rows like the table's ({ host: "openrouter.ai", model, input, cachedInput?, output }, $ per million tokens);
|
|
211
|
+
* a model with no usable prompt price is left out (never a misleading $0 for an unknown one). Pure.
|
|
212
|
+
*/
|
|
213
|
+
export function openRouterPriceRows(json) {
|
|
214
|
+
const perM = (v) => {
|
|
215
|
+
const n = Number(v);
|
|
216
|
+
return Number.isFinite(n) && n >= 0 ? Math.round(n * 1e6 * 1e6) / 1e6 : null;
|
|
217
|
+
};
|
|
218
|
+
const out = [];
|
|
219
|
+
for (const m of Array.isArray(json?.data) ? json.data : []) {
|
|
220
|
+
const id = typeof m?.id === "string" ? m.id.trim().toLowerCase() : "";
|
|
221
|
+
const input = perM(m?.pricing?.prompt);
|
|
222
|
+
if (!id || input == null || Number(m?.pricing?.prompt) < 0) continue;
|
|
223
|
+
const cached = perM(m?.pricing?.input_cache_read);
|
|
224
|
+
const output = perM(m?.pricing?.completion);
|
|
225
|
+
out.push({ host: "openrouter.ai", model: id, input, ...(cached != null ? { cachedInput: cached } : {}), ...(output != null ? { output } : {}) });
|
|
226
|
+
}
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
|
|
208
230
|
export function noPriceLine({ model = "", host = "" } = {}) {
|
|
209
231
|
const what = `${model || "the coder"}${host ? ` at ${host}` : ""}`;
|
|
210
232
|
return `no price for ${what} — its turns show "no price" on the bar instead of a cost. The table prices hosted providers; a model on your own server has none.`;
|
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.935",
|
|
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",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"mongo-mac.mjs",
|
|
81
81
|
"mongo-windows.mjs",
|
|
82
82
|
"python-windows.mjs",
|
|
83
|
+
"python-unix.mjs",
|
|
83
84
|
"terminal-hover.mjs",
|
|
84
85
|
"terminal-layout.mjs",
|
|
85
86
|
"turn-queue.mjs",
|
package/python-unix.mjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PYTHON ON A MAC OR LINUX THAT HAS NONE GU CAN USE (GH #564).
|
|
3
|
+
*
|
|
4
|
+
* Measured on clean machines (2026-12-03): a Mac without the Command Line Tools has only Apple's stub python3 (it opens
|
|
5
|
+
* an "install the developer tools" window); a Mac WITH them has Python 3.9, too old for the agent's libraries (pip:
|
|
6
|
+
* "No matching distribution found for smolagents"); Ubuntu Server has python3 without venv/pip (python3-venv is its own
|
|
7
|
+
* package). On all three the agent could not run, and gu could only say "install Python".
|
|
8
|
+
*
|
|
9
|
+
* Like the Windows path (python-windows.mjs: python.org, for this user), gu now offers to bring its own: a standalone
|
|
10
|
+
* CPython build (python-build-standalone — the builds uv and others install), unpacked into ~/.gonext/python. No
|
|
11
|
+
* administrator, no sudo, nothing outside ~/.gonext. The archive is checked against a SHA-256 pinned HERE, so a changed
|
|
12
|
+
* file on the server is refused, never run. Bump the release on purpose, with its four hashes.
|
|
13
|
+
*
|
|
14
|
+
* Pure parts are separate; the download and the shell are injected so tests never fetch or unpack anything.
|
|
15
|
+
*/
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
import { execFile } from "node:child_process";
|
|
18
|
+
import { existsSync } from "node:fs";
|
|
19
|
+
import { mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
20
|
+
import { homedir } from "node:os";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
|
|
23
|
+
export const PYTHON_UNIX = {
|
|
24
|
+
version: "3.12.16",
|
|
25
|
+
release: "20261201",
|
|
26
|
+
// From the release's SHA256SUMS, checked against GitHub's own digest of each file (2026-12-03).
|
|
27
|
+
builds: {
|
|
28
|
+
"darwin-arm64": { triple: "aarch64-apple-darwin", sha256: "0e261d16dc690890b864c7e4895dd353b2b90d53177822ad3c16c5949e1417c2", mb: 25 },
|
|
29
|
+
"darwin-x64": { triple: "x86_64-apple-darwin", sha256: "5f511089f588c511ed3c26bbbc1de5047dcbead229d2a715160f4dd159c0180e", mb: 25 },
|
|
30
|
+
"linux-arm64": { triple: "aarch64-unknown-linux-gnu", sha256: "e1ce94941e27f99e4cdbabdfe5e82d05a35b76afbae977b8531d4afcd35b2566", mb: 53 },
|
|
31
|
+
"linux-x64": { triple: "x86_64-unknown-linux-gnu", sha256: "ed82eead6b80ced86c75b6c7ecaa204e2dc4cb5b780eea0475f68414595afe55", mb: 68 },
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** The build for this computer, or null (Windows, another CPU, a Linux without glibc such as Alpine). Pure. */
|
|
36
|
+
export function pythonBuildFor({ platform = process.platform, arch = process.arch, glibc = glibcVersion() } = {}) {
|
|
37
|
+
if (platform === "linux" && !glibc) return null; // the gnu builds need glibc; musl (Alpine) cannot run them
|
|
38
|
+
const b = PYTHON_UNIX.builds[`${platform}-${arch}`];
|
|
39
|
+
if (!b) return null;
|
|
40
|
+
const name = `cpython-${PYTHON_UNIX.version}+${PYTHON_UNIX.release}-${b.triple}-install_only.tar.gz`;
|
|
41
|
+
return {
|
|
42
|
+
...b,
|
|
43
|
+
name,
|
|
44
|
+
url: `https://github.com/astral-sh/python-build-standalone/releases/download/${PYTHON_UNIX.release}/${encodeURIComponent(name)}`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function glibcVersion() {
|
|
49
|
+
try {
|
|
50
|
+
return process.report?.getReport?.()?.header?.glibcVersionRuntime || "";
|
|
51
|
+
} catch {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Can the agent run on this Python? → { ok, why }. "3.9.6" → too old; no venv/ensurepip (Debian's split) → cannot make
|
|
58
|
+
* gu's own environment. `probe(code)` runs `python3 -c code` → { ok, out }. Pure apart from the probe.
|
|
59
|
+
*/
|
|
60
|
+
export async function pythonUsable(probe) {
|
|
61
|
+
const v = await probe("import sys; print('%d.%d.%d' % sys.version_info[:3])");
|
|
62
|
+
if (!v.ok) return { ok: false, why: "none", version: "" };
|
|
63
|
+
const version = String(v.out).trim();
|
|
64
|
+
const [maj, min] = version.split(".").map(Number);
|
|
65
|
+
if (!(maj > 3 || (maj === 3 && min >= 10))) return { ok: false, why: "old", version };
|
|
66
|
+
const venv = await probe("import venv, ensurepip");
|
|
67
|
+
if (!venv.ok) return { ok: false, why: "no-venv", version };
|
|
68
|
+
return { ok: true, why: "", version };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The question gu asks, in words that say what changes. Pure. */
|
|
72
|
+
export function pythonOfferText(usable, build) {
|
|
73
|
+
const have =
|
|
74
|
+
usable.why === "old" ? `this computer has Python ${usable.version}, too old for it` :
|
|
75
|
+
usable.why === "no-venv" ? `this computer's Python ${usable.version} cannot make gu's own environment (no venv)` :
|
|
76
|
+
"this computer has none gu can use";
|
|
77
|
+
return `The agent runs on Python 3.10 or newer, and ${have}. Install Python ${PYTHON_UNIX.version} for your user only? ` +
|
|
78
|
+
`(about ${build.mb} MB, into ~/.gonext/python; no password, nothing system-wide)`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const sh = (file, args) =>
|
|
82
|
+
new Promise((resolve) => {
|
|
83
|
+
execFile(file, args, { timeout: 600000 }, (err, stdout, stderr) => resolve({ code: err ? (err.code ?? 1) : 0, out: String(stdout), err: String(stderr) }));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Download, check, unpack, and make gu's own environment (~/.gonext/venv) from it. → { ok, python?, error? }
|
|
88
|
+
* An older ~/.gonext/venv (made from a Python the agent cannot use) is moved aside, never deleted.
|
|
89
|
+
*/
|
|
90
|
+
export async function installPythonUnix({ dir = join(homedir(), ".gonext"), build = pythonBuildFor(), fetchFn = fetch, run = sh, log = () => {} } = {}) {
|
|
91
|
+
if (!build) return { ok: false, error: "there is no standalone Python build for this computer" };
|
|
92
|
+
const archive = join(dir, build.name);
|
|
93
|
+
try {
|
|
94
|
+
await mkdir(dir, { recursive: true });
|
|
95
|
+
const res = await fetchFn(build.url, { redirect: "follow" });
|
|
96
|
+
if (!res.ok) return { ok: false, error: `download failed (HTTP ${res.status})` };
|
|
97
|
+
const bytes = Buffer.from(await res.arrayBuffer());
|
|
98
|
+
const got = createHash("sha256").update(bytes).digest("hex");
|
|
99
|
+
if (got !== build.sha256) return { ok: false, error: "the download did not match its pinned checksum, so it was NOT installed" };
|
|
100
|
+
await writeFile(archive, bytes);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return { ok: false, error: `download failed: ${e?.message ?? e}` };
|
|
103
|
+
}
|
|
104
|
+
// The archive holds one folder, python/ — unpacked fresh, so a half-finished earlier try leaves nothing behind.
|
|
105
|
+
const home = join(dir, "python");
|
|
106
|
+
await rm(home, { recursive: true, force: true });
|
|
107
|
+
const untar = await run("tar", ["-xzf", archive, "-C", dir]);
|
|
108
|
+
await rm(archive, { force: true }).catch(() => {});
|
|
109
|
+
const python = join(home, "bin", "python3"); // platform-ok: the standalone build's own file, macOS/Linux only (Windows uses python-windows.mjs)
|
|
110
|
+
if (untar.code !== 0 || !existsSync(python)) return { ok: false, error: `could not unpack it: ${untar.err.trim().split("\n")[0] || "tar failed"}` };
|
|
111
|
+
const venv = join(dir, "venv");
|
|
112
|
+
if (existsSync(venv)) {
|
|
113
|
+
const aside = `${venv}-old-${Date.now()}`;
|
|
114
|
+
await rename(venv, aside).catch(() => {});
|
|
115
|
+
log(` · the earlier environment was kept as ${aside}`);
|
|
116
|
+
}
|
|
117
|
+
const made = await run(python, ["-m", "venv", venv]);
|
|
118
|
+
if (made.code !== 0) return { ok: false, error: `could not make gu's environment: ${made.err.trim().split("\n").pop()}` };
|
|
119
|
+
return { ok: true, python: join(venv, "bin", "python") };
|
|
120
|
+
}
|
package/setup-fixes.mjs
CHANGED
|
@@ -106,7 +106,12 @@ export async function posixFixes({ binDir, home = homedir(), envPath = process.e
|
|
|
106
106
|
const ip = await import("./install-path.mjs");
|
|
107
107
|
const { stableBinDir } = await import("./env-check.mjs");
|
|
108
108
|
const stable = stableBinDir(binDir);
|
|
109
|
-
|
|
109
|
+
// GH #564: also the same folder under another name — the installer puts ~/.local/share/gu/node/bin (a link to
|
|
110
|
+
// node-v26…/bin) on PATH, and the first gu added the versioned spelling a second time.
|
|
111
|
+
const { realpathSync } = await import("node:fs");
|
|
112
|
+
const real = (p) => { try { return realpathSync(p); } catch { return p; } };
|
|
113
|
+
const want = real(binDir);
|
|
114
|
+
if (envPath.split(":").some((p) => p && (p === binDir || p === stable || real(p) === want))) return { done, failed };
|
|
110
115
|
const r = ip.addPathBlock({ dir: stable, home });
|
|
111
116
|
if (r.wrote) done.push(SAID.posixPath(stable, r.wrote.replace(home, "~")));
|
|
112
117
|
else if (!r.already) failed.push(SAID.posixPathFailed(stable));
|
package/turn-notes.mjs
CHANGED
|
@@ -28,9 +28,62 @@ export function sendNote(jobId, text, home) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// ---- SEND NOW (GH #560) ------------------------------------------------------------------------
|
|
32
|
+
// Claude Code's "Queued · ctrl+x ctrl+s to send now". A note is read after the agent's current step;
|
|
33
|
+
// during a long command that step can be minutes away. Ctrl+X Ctrl+S creates <jobId>.now and the
|
|
34
|
+
// agent stops WAITING on the command — it goes on in the background, never killed — so the step ends
|
|
35
|
+
// and the note is read. A model reply in progress is not cut (tokens already paid): the note follows it.
|
|
36
|
+
export const nowPath = (jobId, home) => join(notesDir(home), `${safe(jobId)}.now`);
|
|
37
|
+
|
|
38
|
+
/** Ask the running turn to read its waiting notes now → true when the request was written. */
|
|
39
|
+
export function sendNow(jobId, home) {
|
|
40
|
+
if (!safe(jobId)) return false;
|
|
41
|
+
try {
|
|
42
|
+
mkdirSync(notesDir(home), { recursive: true, mode: 0o700 });
|
|
43
|
+
appendFileSync(nowPath(jobId, home), "", { mode: 0o600 });
|
|
44
|
+
return true;
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const CHORD_WINDOW_MS = 1500;
|
|
51
|
+
|
|
52
|
+
/** Ctrl+X then Ctrl+S within CHORD_WINDOW_MS. feed(key) → true when the chord completes. */
|
|
53
|
+
export function createSendNowChord({ windowMs = CHORD_WINDOW_MS, now = () => Date.now() } = {}) {
|
|
54
|
+
let xAt = 0;
|
|
55
|
+
return {
|
|
56
|
+
feed(key) {
|
|
57
|
+
if (!key || !key.ctrl) {
|
|
58
|
+
xAt = 0;
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (key.name === "x") {
|
|
62
|
+
xAt = now();
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const hit = key.name === "s" && xAt > 0 && now() - xAt <= windowMs;
|
|
66
|
+
xAt = 0;
|
|
67
|
+
return hit;
|
|
68
|
+
},
|
|
69
|
+
/** A Ctrl+X is waiting for its Ctrl+S. */
|
|
70
|
+
get armed() {
|
|
71
|
+
return xAt > 0 && now() - xAt <= windowMs;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The dim line under what waits (GH #560). notes: waiting for the running turn; queued: for after it. */
|
|
77
|
+
export function waitingLabel({ notes = 0, queued = 0, sending = false } = {}) {
|
|
78
|
+
if (notes > 0) return sending ? "⎿ Sending now · the agent reads it next" : "⎿ Queued · Ctrl+X Ctrl+S to send now";
|
|
79
|
+
if (queued > 0) return "⎿ Queued · runs after this turn";
|
|
80
|
+
return "";
|
|
81
|
+
}
|
|
82
|
+
|
|
31
83
|
/** The notes the agent never took, oldest first; the file is removed. [] when none. */
|
|
32
84
|
export function takeUnread(jobId, home) {
|
|
33
85
|
if (!safe(jobId)) return [];
|
|
86
|
+
rmSync(nowPath(jobId, home), { force: true }); // the turn is over: a send-now request is spent
|
|
34
87
|
const path = notesPath(jobId, home);
|
|
35
88
|
if (!existsSync(path)) return [];
|
|
36
89
|
const taken = `${path}.back-${process.pid}-${Date.now()}`;
|
|
@@ -87,3 +140,15 @@ export function questionWithNotes(question, notes) {
|
|
|
87
140
|
const added = (notes ?? []).map((t) => String(t).trim()).filter(Boolean);
|
|
88
141
|
return added.length ? `${question}\n\n[Added by the user while you were working]\n${added.join("\n\n")}` : question;
|
|
89
142
|
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* GH #562: the agent's one-line answer to what was typed during the turn (its say() tool), like Claude Code's
|
|
146
|
+
* "Noted: …" — shown as normal text right under the user's message, and the turn goes on.
|
|
147
|
+
*/
|
|
148
|
+
export const SAY_PREFIX = "__SAY__::";
|
|
149
|
+
|
|
150
|
+
/** → the line to show, or "" when this step line is not one. */
|
|
151
|
+
export function parseSay(line) {
|
|
152
|
+
const s = String(line ?? "").trim();
|
|
153
|
+
return s.startsWith(SAY_PREFIX) ? s.slice(SAY_PREFIX.length).trim() : "";
|
|
154
|
+
}
|