@tiens.nguyen/gu-cli 1.0.928 → 1.0.929
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 +57 -3
- package/gonext_agent_chat.py +29 -5
- package/gu-repl.mjs +27 -3
- package/image-paste.mjs +59 -8
- package/package.json +1 -1
package/cli-token.mjs
CHANGED
|
@@ -28,10 +28,31 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import { createHash, createPublicKey, verify } from "node:crypto";
|
|
30
30
|
import { execFile } from "node:child_process";
|
|
31
|
+
import { readFileSync } from "node:fs";
|
|
31
32
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
32
33
|
import { hostname as osHostname, userInfo } from "node:os";
|
|
33
34
|
import { dirname, join } from "node:path";
|
|
34
35
|
|
|
36
|
+
/** This gu's version (package.json), "" when it cannot be read. */
|
|
37
|
+
export const GU_VERSION = (() => {
|
|
38
|
+
try {
|
|
39
|
+
return String(JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version ?? "");
|
|
40
|
+
} catch {
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
})();
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* GH #529: gu's version and mode on the requests it already makes to the gu service, so the admin
|
|
47
|
+
* Users page can say which versions are in use. Nothing else about the computer or the user.
|
|
48
|
+
*/
|
|
49
|
+
export function guHeaders(mode, version = GU_VERSION) {
|
|
50
|
+
return {
|
|
51
|
+
...(version ? { "x-gu-version": String(version) } : {}),
|
|
52
|
+
...(mode ? { "x-gu-mode": String(mode) } : {}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
35
56
|
/** The public half of the API's CLI_TOKEN_PRIVATE_KEY, base64 SPKI DER (Ed25519). Generated 2026-09-17. */
|
|
36
57
|
export const EMBEDDED_PUBLIC_KEY = "MCowBQYDK2VwAyEA2xkKnY+xWGoS4Nvc7DEHCCurdQQYZGl/x7kPp+gDmvY=";
|
|
37
58
|
|
|
@@ -153,14 +174,14 @@ export async function trialDevice(opts = {}) {
|
|
|
153
174
|
* { ok: false, why: "no-device" | "unreachable" | "http-NNN" | "bad-response" }
|
|
154
175
|
* Never throws.
|
|
155
176
|
*/
|
|
156
|
-
export async function claimTrial({ hostedBase, device, fetchImpl = fetch, timeoutMs = 8000 }) {
|
|
177
|
+
export async function claimTrial({ hostedBase, device, mode = "", fetchImpl = fetch, timeoutMs = 8000 }) {
|
|
157
178
|
if (!device) return { ok: false, why: "no-device" };
|
|
158
179
|
const base = String(hostedBase ?? "").replace(/\/+$/, "");
|
|
159
180
|
if (!base) return { ok: false, why: "unreachable" };
|
|
160
181
|
try {
|
|
161
182
|
const res = await fetchImpl(`${base}/api/billing/cli-token/trial`, {
|
|
162
183
|
method: "POST",
|
|
163
|
-
headers: { "content-type": "application/json" },
|
|
184
|
+
headers: { "content-type": "application/json", ...guHeaders(mode) },
|
|
164
185
|
body: JSON.stringify({ device }),
|
|
165
186
|
signal: AbortSignal.timeout(timeoutMs),
|
|
166
187
|
});
|
|
@@ -572,7 +593,7 @@ export async function renewToken({ mode, apiBase, hostedBase, token, workerKey,
|
|
|
572
593
|
const base = String(mode === "expert" ? hostedBase : apiBase || hostedBase).replace(/\/+$/, "");
|
|
573
594
|
const body = JSON.stringify(device ? { device } : {});
|
|
574
595
|
let url;
|
|
575
|
-
const headers = { "content-type": "application/json" };
|
|
596
|
+
const headers = { "content-type": "application/json", ...guHeaders(mode) };
|
|
576
597
|
if (token) {
|
|
577
598
|
url = `${base}/api/billing/cli-token/renew`;
|
|
578
599
|
headers.authorization = `Bearer ${token}`;
|
|
@@ -593,6 +614,39 @@ export async function renewToken({ mode, apiBase, hostedBase, token, workerKey,
|
|
|
593
614
|
}
|
|
594
615
|
}
|
|
595
616
|
|
|
617
|
+
/**
|
|
618
|
+
* GH #529: "gu ran on this computer today" — POST /api/billing/cli-token/seen with the token, once a
|
|
619
|
+
* UTC day (the day is kept in ~/.gonext/cli-token-seen). It is what lets the admin page count users
|
|
620
|
+
* rather than installs. → { ok, why? }. Never throws; a failure is retried at the next hourly tick.
|
|
621
|
+
*/
|
|
622
|
+
export const SEEN_FILE = "cli-token-seen";
|
|
623
|
+
export const utcDay = (d = new Date()) => d.toISOString().slice(0, 10);
|
|
624
|
+
|
|
625
|
+
export async function reportSeen({ dir, mode, apiBase, hostedBase, token, device, now = new Date(), fetchImpl = fetch, timeoutMs = 8000 }) {
|
|
626
|
+
if (!token || !device) return { ok: false, why: "no-credential" };
|
|
627
|
+
const file = join(dir, SEEN_FILE);
|
|
628
|
+
const today = utcDay(now);
|
|
629
|
+
const last = await readFile(file, "utf8").then((t) => t.trim(), () => "");
|
|
630
|
+
if (last === today) return { ok: true, why: "already" };
|
|
631
|
+
const base = String(mode === "expert" ? hostedBase : apiBase || hostedBase).replace(/\/+$/, "");
|
|
632
|
+
if (!base) return { ok: false, why: "no-api" };
|
|
633
|
+
try {
|
|
634
|
+
const res = await fetchImpl(`${base}/api/billing/cli-token/seen`, {
|
|
635
|
+
method: "POST",
|
|
636
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${token}`, ...guHeaders(mode) },
|
|
637
|
+
body: JSON.stringify({ device }),
|
|
638
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
639
|
+
});
|
|
640
|
+
// 404: a gu service from before this call existed — nothing to retry until it is updated.
|
|
641
|
+
if (!res.ok && res.status !== 404) return { ok: false, why: `http-${res.status}` };
|
|
642
|
+
await mkdir(dir, { recursive: true });
|
|
643
|
+
await writeFile(file, today + "\n", "utf8");
|
|
644
|
+
return { ok: true };
|
|
645
|
+
} catch (e) {
|
|
646
|
+
return { ok: false, why: e?.name === "TimeoutError" ? "timeout" : "network" };
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
596
650
|
/**
|
|
597
651
|
* A free-model promo code with NO token (the computer's trial ended, or it never had one): the code is the
|
|
598
652
|
* credential, and the answer carries a token for this computer that runs for the code's months. Never throws.
|
package/gonext_agent_chat.py
CHANGED
|
@@ -4536,6 +4536,8 @@ def _fetch_cloud_limits(api_base: str, timeout: float = 5.0) -> int:
|
|
|
4536
4536
|
"regex": r.get("origin") == "table",
|
|
4537
4537
|
"ctx": r.get("contextWindow") if isinstance(r.get("contextWindow"), int) and r.get("contextWindow") > 0 else 0,
|
|
4538
4538
|
"out": r.get("maxOutput") if isinstance(r.get("maxOutput"), int) and r.get("maxOutput") > 0 else 0,
|
|
4539
|
+
# GH #528: the model takes images (the admin Models page, from the providers' catalogs).
|
|
4540
|
+
"images": r.get("images") is True,
|
|
4539
4541
|
})
|
|
4540
4542
|
_CLOUD_LIMITS["rows"] = rows
|
|
4541
4543
|
_log(f"cloud token table: {len(rows)} rows")
|
|
@@ -11349,9 +11351,9 @@ def _prepare_image(path):
|
|
|
11349
11351
|
return im
|
|
11350
11352
|
|
|
11351
11353
|
|
|
11352
|
-
# WHICH CODERS MAY BE SENT IMAGES (#284, #316) — the SAME
|
|
11353
|
-
#
|
|
11354
|
-
#
|
|
11354
|
+
# WHICH CODERS MAY BE SENT IMAGES (#284, #316, GH #528) — the SAME lists the CLI gates Ctrl+V with:
|
|
11355
|
+
# image-capable-coders.json beside this file (Claude, Kimi K3 — verified by hand), plus every model the
|
|
11356
|
+
# cloud token table marks images: true (the admin Models page; the owner chose to trust the catalog).
|
|
11355
11357
|
def _image_coders():
|
|
11356
11358
|
# GU_IMAGE_CODERS_FILE: tests only — a stand-in coder on 127.0.0.1 is put on the list there.
|
|
11357
11359
|
path = os.environ.get("GU_IMAGE_CODERS_FILE") or os.path.join(
|
|
@@ -11364,12 +11366,34 @@ def _image_coders():
|
|
|
11364
11366
|
return [{"host": "api.anthropic.com"}]
|
|
11365
11367
|
|
|
11366
11368
|
|
|
11369
|
+
def _cloud_image_coders():
|
|
11370
|
+
"""GH #528: the models the cloud list says take images — [{host, exact}].
|
|
11371
|
+
|
|
11372
|
+
From the cloud token table this job read (_CLOUD_LIMITS), else from ~/.gonext/image-models.json,
|
|
11373
|
+
which the CLI writes from the same table: the CLI's Ctrl+V gate and this one stay the same list."""
|
|
11374
|
+
rows = [r for r in _CLOUD_LIMITS["rows"] if r.get("images") and r.get("host") and not r.get("regex")]
|
|
11375
|
+
if rows:
|
|
11376
|
+
return [{"host": r["host"], "exact": str(r["model"]).strip().lower()} for r in rows]
|
|
11377
|
+
try:
|
|
11378
|
+
path = os.path.join(os.path.expanduser("~"), ".gonext", "image-models.json")
|
|
11379
|
+
with open(path, encoding="utf-8") as f:
|
|
11380
|
+
saved = json.load(f).get("coders") or []
|
|
11381
|
+
return [c for c in saved if isinstance(c, dict) and c.get("host") and c.get("exact")]
|
|
11382
|
+
except Exception: # noqa: BLE001
|
|
11383
|
+
return []
|
|
11384
|
+
|
|
11385
|
+
|
|
11367
11386
|
def _coder_takes_images(url, model, coders=None):
|
|
11368
11387
|
"""May the question's pasted images be sent to this coding server + model?"""
|
|
11369
11388
|
host = (urlparse(url or "").hostname or "").lower().rstrip(".")
|
|
11370
11389
|
name = str(model or "").split("::")[-1].strip()
|
|
11371
|
-
for c in (coders if coders is not None else _image_coders()):
|
|
11372
|
-
if c.get("host")
|
|
11390
|
+
for c in (coders if coders is not None else _image_coders() + _cloud_image_coders()):
|
|
11391
|
+
if c.get("host") != host:
|
|
11392
|
+
continue
|
|
11393
|
+
if c.get("exact"):
|
|
11394
|
+
if c["exact"] == name.lower():
|
|
11395
|
+
return True
|
|
11396
|
+
elif not c.get("model") or re.search(c["model"], name, re.I):
|
|
11373
11397
|
return True
|
|
11374
11398
|
return False
|
|
11375
11399
|
|
package/gu-repl.mjs
CHANGED
|
@@ -172,7 +172,7 @@ import {
|
|
|
172
172
|
} from "./model-fallback.mjs";
|
|
173
173
|
import { codingChoiceTags, coderDisplayName, coderWhere, whereOfActiveCoder } from "./coding-choice-tags.mjs";
|
|
174
174
|
import { TITLE_POP, TITLE_PUSH, idleTitle, needsSummary, summariseForTitle, titleModel, titleSeq, trimTitle } from "./terminal-title.mjs";
|
|
175
|
-
import { IMAGE_NEEDS_CLAUDE, coderTakesImagesFor, clipboardImageToFile, fitImageNotice, imageMarkersForDisplay, createImageStore, imagePasteKey, imagePathFromPaste, isClaudeCoderUrl, isImagePasteKey, storeImageFile } from "./image-paste.mjs";
|
|
175
|
+
import { IMAGE_NEEDS_CLAUDE, coderTakesImagesFor, loadCloudImageCoders, saveCloudImageCoders, clipboardImageToFile, fitImageNotice, imageMarkersForDisplay, createImageStore, imagePasteKey, imagePathFromPaste, isClaudeCoderUrl, isImagePasteKey, storeImageFile } from "./image-paste.mjs";
|
|
176
176
|
import {
|
|
177
177
|
isDoubleClick,
|
|
178
178
|
clickRun,
|
|
@@ -2042,8 +2042,12 @@ function showImageNotice(text) {
|
|
|
2042
2042
|
imageNoticeTimer.unref?.();
|
|
2043
2043
|
if (barPinned()) paintBar();
|
|
2044
2044
|
}
|
|
2045
|
-
/**
|
|
2046
|
-
|
|
2045
|
+
/**
|
|
2046
|
+
* Images go to the coding model when it takes them: Claude, Kimi K3 (image-capable-coders.json), and
|
|
2047
|
+
* since GH #528 every model the cloud list marks `images: true` — read from ~/.gonext/image-models.json
|
|
2048
|
+
* at start, refreshed with the cloud token table (refreshLimitsUpdate).
|
|
2049
|
+
*/
|
|
2050
|
+
loadCloudImageCoders();
|
|
2047
2051
|
const coderTakesImages = () => coderTakesImagesFor(sessionCodingUrl || defaultCodingUrl, sessionCodingModel || defaultCodingModel);
|
|
2048
2052
|
function insertAtCaret(text) {
|
|
2049
2053
|
dropSelectedInputText();
|
|
@@ -2762,6 +2766,19 @@ async function refreshCliToken() {
|
|
|
2762
2766
|
await ct.writeState(dir, state).catch(() => {});
|
|
2763
2767
|
tokenNotice = noticeNow();
|
|
2764
2768
|
}
|
|
2769
|
+
// GH #529: once a UTC day, "gu ran here today" — counted on the admin Users page.
|
|
2770
|
+
if (state.token && process.env.GU_NO_UPDATE_CHECK !== "1") {
|
|
2771
|
+
const { DEFAULT_API_BASE } = await import("./device-login.mjs");
|
|
2772
|
+
const device = await ct.thisDevice({ instanceId: myInstanceId || "" }).catch(() => null);
|
|
2773
|
+
await ct.reportSeen({
|
|
2774
|
+
dir,
|
|
2775
|
+
mode,
|
|
2776
|
+
apiBase,
|
|
2777
|
+
hostedBase: String(process.env.GU_TOKEN_API_BASE ?? "").trim() || DEFAULT_API_BASE,
|
|
2778
|
+
token: state.token,
|
|
2779
|
+
device,
|
|
2780
|
+
}).catch(() => {});
|
|
2781
|
+
}
|
|
2765
2782
|
if (!licenceDecided) {
|
|
2766
2783
|
licenceDecided = true;
|
|
2767
2784
|
const d = ct.enforcementDecision({ token: state.token, publicKeyB64: pk, site, deviceId: await thisDeviceId(ct) });
|
|
@@ -9272,6 +9289,13 @@ async function refreshLimitsUpdate() {
|
|
|
9272
9289
|
const ln = await import("./model-limits-notice.mjs");
|
|
9273
9290
|
const cloud = await fetchCloudLimits();
|
|
9274
9291
|
if (!cloud) return;
|
|
9292
|
+
// GH #528: which models take images — kept on disk for the next start and for the agent.
|
|
9293
|
+
// An empty table (not filled yet) keeps what was saved rather than forgetting it.
|
|
9294
|
+
if (cloud.rows.length) {
|
|
9295
|
+
const before = coderTakesImages();
|
|
9296
|
+
saveCloudImageCoders(cloud.rows);
|
|
9297
|
+
if (coderTakesImages() !== before && barPinned()) paintBar();
|
|
9298
|
+
}
|
|
9275
9299
|
const seenAt = await readLimitsSeen();
|
|
9276
9300
|
const was = Boolean(limitsUpdate);
|
|
9277
9301
|
if (!seenAt && cloud.updatedAt) {
|
package/image-paste.mjs
CHANGED
|
@@ -3,8 +3,9 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
* Pasting an image into the gu input (task #284).
|
|
4
4
|
*
|
|
5
5
|
* The image goes to the CODING model, the way Claude Code does it — no OCR step: the model sees
|
|
6
|
-
* the screenshot itself.
|
|
7
|
-
*
|
|
6
|
+
* the screenshot itself. Only a coder that takes images may receive one (coderTakesImagesFor: Claude,
|
|
7
|
+
* Kimi K3, and since GH #528 every model the cloud list marks images:true); with any other coder a
|
|
8
|
+
* paste is refused and the bar says to pick another model.
|
|
8
9
|
*
|
|
9
10
|
* How it reaches the model. The API passes the message TEXT and nothing else, so the image rides
|
|
10
11
|
* in the text as a marker: the input shows "[Image #1]" (like "[Pasted text #1]"), and the line
|
|
@@ -21,7 +22,7 @@ import { readFileSync } from "node:fs";
|
|
|
21
22
|
* most reliable way; Windows Terminal quotes a path with spaces.
|
|
22
23
|
*/
|
|
23
24
|
import { spawnSync } from "node:child_process";
|
|
24
|
-
import { chmodSync, closeSync, copyFileSync, existsSync, mkdirSync, openSync, readSync, rmSync, statSync } from "node:fs";
|
|
25
|
+
import { chmodSync, closeSync, copyFileSync, existsSync, mkdirSync, openSync, readSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
25
26
|
import { homedir } from "node:os";
|
|
26
27
|
import path, { join } from "node:path";
|
|
27
28
|
|
|
@@ -72,8 +73,42 @@ export const imagesDir = (home = homedir()) => join(home, ".gonext", "images");
|
|
|
72
73
|
*/
|
|
73
74
|
export const IMAGE_CODERS = JSON.parse(readFileSync(new URL("./image-capable-coders.json", import.meta.url), "utf8")).coders;
|
|
74
75
|
|
|
76
|
+
/**
|
|
77
|
+
* GH #528: THE CLOUD MODEL LIST. Rows of GET /api/model-limits with `images: true` (filled from the
|
|
78
|
+
* providers' catalogs on the admin Models page) — the owner chose to trust the catalog. A row names
|
|
79
|
+
* one model on one server exactly. Pure.
|
|
80
|
+
*/
|
|
81
|
+
export function cloudImageCoders(rows) {
|
|
82
|
+
const out = [];
|
|
83
|
+
for (const r of Array.isArray(rows) ? rows : []) {
|
|
84
|
+
if (!r || r.images !== true || r.origin === "table") continue;
|
|
85
|
+
const host = String(r.host ?? "").trim().toLowerCase();
|
|
86
|
+
const exact = String(r.model ?? "").trim().toLowerCase();
|
|
87
|
+
if (host && exact) out.push({ host, exact });
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The cloud list this gu last read, kept in ~/.gonext/image-models.json so a start without network
|
|
94
|
+
* still knows it — and so the agent (gonext_agent_chat.py) reads the very same list.
|
|
95
|
+
*/
|
|
96
|
+
export const imageModelsFile = (home = homedir()) => join(home, ".gonext", "image-models.json");
|
|
97
|
+
let cloudCoders = [];
|
|
98
|
+
export function setCloudImageCoders(list) {
|
|
99
|
+
cloudCoders = Array.isArray(list) ? list.filter((c) => c && c.host && c.exact) : [];
|
|
100
|
+
}
|
|
101
|
+
export function loadCloudImageCoders(home = homedir()) {
|
|
102
|
+
try {
|
|
103
|
+
setCloudImageCoders(JSON.parse(readFileSync(imageModelsFile(home), "utf8")).coders);
|
|
104
|
+
} catch {
|
|
105
|
+
setCloudImageCoders([]);
|
|
106
|
+
}
|
|
107
|
+
return cloudCoders;
|
|
108
|
+
}
|
|
109
|
+
|
|
75
110
|
/** May a pasted image be sent to this coder? `model` may be a qualified id ("openai::kimi-k3"). */
|
|
76
|
-
export function coderTakesImagesFor(url, model = "", coders = IMAGE_CODERS) {
|
|
111
|
+
export function coderTakesImagesFor(url, model = "", coders = [...IMAGE_CODERS, ...cloudCoders]) {
|
|
77
112
|
let host = "";
|
|
78
113
|
try {
|
|
79
114
|
host = new URL(String(url ?? "")).hostname.toLowerCase().replace(/\.$/, "");
|
|
@@ -81,7 +116,22 @@ export function coderTakesImagesFor(url, model = "", coders = IMAGE_CODERS) {
|
|
|
81
116
|
return false;
|
|
82
117
|
}
|
|
83
118
|
const name = String(model ?? "").split("::").pop().trim();
|
|
84
|
-
return coders.some(
|
|
119
|
+
return coders.some(
|
|
120
|
+
(c) => c.host === host && (c.exact ? c.exact === name.toLowerCase() : !c.model || new RegExp(c.model, "i").test(name))
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Save the cloud list for the next start and for the agent. Best effort; → the coders saved. */
|
|
125
|
+
export function saveCloudImageCoders(rows, home = homedir()) {
|
|
126
|
+
const coders = cloudImageCoders(rows);
|
|
127
|
+
try {
|
|
128
|
+
mkdirSync(join(home, ".gonext"), { recursive: true });
|
|
129
|
+
writeFileSync(imageModelsFile(home), JSON.stringify({ savedAt: new Date().toISOString(), coders }, null, 1) + "\n");
|
|
130
|
+
} catch {
|
|
131
|
+
/* not saved: this session still uses it */
|
|
132
|
+
}
|
|
133
|
+
setCloudImageCoders(coders);
|
|
134
|
+
return coders;
|
|
85
135
|
}
|
|
86
136
|
|
|
87
137
|
/** Is this coding server Claude's own API? (Kept for callers that ask exactly that.) */
|
|
@@ -93,11 +143,12 @@ export function isClaudeCoderUrl(url) {
|
|
|
93
143
|
}
|
|
94
144
|
}
|
|
95
145
|
|
|
96
|
-
// The name is historical (#284 was Claude-only)
|
|
146
|
+
// The name is historical (#284 was Claude-only). Since GH #528 every model the cloud list says takes
|
|
147
|
+
// images does (Claude, Kimi, Gemini, Qwen…), so the notice names no model.
|
|
97
148
|
export const IMAGE_NEEDS_CLAUDE =
|
|
98
|
-
"
|
|
149
|
+
"this coding model does not take images — pick one that does with /model";
|
|
99
150
|
/** The same, for a window too narrow for the full sentence: the fix (/model) must survive. */
|
|
100
|
-
export const IMAGE_NEEDS_CLAUDE_SHORT = "
|
|
151
|
+
export const IMAGE_NEEDS_CLAUDE_SHORT = "model takes no images — /model";
|
|
101
152
|
|
|
102
153
|
/**
|
|
103
154
|
* The notice as it fits `cols` columns (#54): the full sentence, else its short form, else the
|
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.929",
|
|
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",
|