@tiens.nguyen/gu-cli 1.0.941 → 1.0.943
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/budget-view.mjs +1 -1
- package/cli-token.mjs +1 -1
- package/client-expert-setup.mjs +39 -1
- package/device-login.mjs +17 -4
- package/gu-cli.mjs +3 -4
- package/gu-repl.mjs +178 -44
- package/memory-task.mjs +13 -11
- package/package.json +1 -1
- package/terminal-layout.mjs +24 -0
package/budget-view.mjs
CHANGED
|
@@ -79,7 +79,7 @@ export function budgetTable(rows, now = new Date()) {
|
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* What /budget prints, as { tone: "ok" | "warn" | "error", lines }. `site` is the web base
|
|
82
|
-
* (siteUrl(): https://
|
|
82
|
+
* (siteUrl(): https://gucli.com or GU_SITE_URL).
|
|
83
83
|
*/
|
|
84
84
|
export function budgetLines(result, { site, now = new Date() } = {}) {
|
|
85
85
|
const base = String(site || "https://gu.getmarsic.cc").replace(/\/+$/, "");
|
package/cli-token.mjs
CHANGED
|
@@ -107,7 +107,7 @@ export const TOKEN_PREFIX = "gu1";
|
|
|
107
107
|
export const STALE_AFTER_DAYS = 30;
|
|
108
108
|
export const RENEW_EVERY_MS = { client: 86_400_000, expert: 7 * 86_400_000 };
|
|
109
109
|
/** Where the notices send people. Overridable for staging. */
|
|
110
|
-
export const DEFAULT_SITE = "https://gu.getmarsic.cc
|
|
110
|
+
export const DEFAULT_SITE = "https://gucli.com"; // GH #602: the site people know; gu.getmarsic.cc only redirects
|
|
111
111
|
|
|
112
112
|
export function publicKey(env = process.env) {
|
|
113
113
|
return String(env.GU_CLI_TOKEN_PUBLIC_KEY ?? "").trim() || EMBEDDED_PUBLIC_KEY;
|
package/client-expert-setup.mjs
CHANGED
|
@@ -692,6 +692,42 @@ export function parseLicenseFlag(argv) {
|
|
|
692
692
|
return "";
|
|
693
693
|
}
|
|
694
694
|
|
|
695
|
+
/**
|
|
696
|
+
* GH #603: `gu --cloud <code>` — the Cloud link an admin sent (the page at gucli.com/cloud/<code>
|
|
697
|
+
* shows the command). The whole link pasted works too. → "CL-XXXXXXXXXXXX", or "" when absent or
|
|
698
|
+
* not a link code.
|
|
699
|
+
*/
|
|
700
|
+
export function parseCloudFlag(argv) {
|
|
701
|
+
const args = Array.isArray(argv) ? argv : [];
|
|
702
|
+
let raw = "";
|
|
703
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
704
|
+
const a = String(args[i] ?? "");
|
|
705
|
+
if (a === "--cloud") raw = String(args[i + 1] ?? "");
|
|
706
|
+
else if (a.startsWith("--cloud=")) raw = a.slice("--cloud=".length);
|
|
707
|
+
}
|
|
708
|
+
const m = /(?:^|\/)(CL-[A-Z0-9]{12})\/?$/i.exec(raw.trim());
|
|
709
|
+
return m ? m[1].toUpperCase() : "";
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* GH #603: is this Cloud link usable? Asks the hosted API's public lookup. → { ok, why, email }.
|
|
714
|
+
* Soft on a network failure (ok: true, unverified: true) — the claim after sign-in checks again.
|
|
715
|
+
*/
|
|
716
|
+
export async function checkCloudLink(code, { hostedBase, fetchImpl = fetch, timeoutMs = 8000 } = {}) {
|
|
717
|
+
try {
|
|
718
|
+
const r = await fetchImpl(`${String(hostedBase).replace(/\/+$/, "")}/api/cloud-links/${encodeURIComponent(code)}`, {
|
|
719
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
720
|
+
});
|
|
721
|
+
const body = await r.json().catch(() => ({}));
|
|
722
|
+
if (r.status === 404) return { ok: false, why: "That Cloud link doesn't exist — check you copied all of it." };
|
|
723
|
+
if (!r.ok) return { ok: true, unverified: true, why: "" };
|
|
724
|
+
if (!body.active) return { ok: false, why: "That Cloud link was removed. Ask the person who sent it for a new one." };
|
|
725
|
+
return { ok: true, why: "", email: String(body.email ?? "") };
|
|
726
|
+
} catch {
|
|
727
|
+
return { ok: true, unverified: true, why: "" };
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
695
731
|
/**
|
|
696
732
|
* What a first run DOES about the mode question.
|
|
697
733
|
*
|
|
@@ -704,7 +740,9 @@ export function parseLicenseFlag(argv) {
|
|
|
704
740
|
* what the license-gated menu is for. Pure, so the rule is a test row rather than something to
|
|
705
741
|
* re-read in the REPL.
|
|
706
742
|
*/
|
|
707
|
-
export function resolveFirstRunMode({ licenseToken, expertAvailable } = {}) {
|
|
743
|
+
export function resolveFirstRunMode({ licenseToken, expertAvailable, cloudCode = "" } = {}) {
|
|
744
|
+
// GH #603: a Cloud link decides it — no menu, no private default.
|
|
745
|
+
if (String(cloudCode ?? "").trim()) return { ask: false, mode: "client" };
|
|
708
746
|
if (String(licenseToken ?? "").trim()) return { ask: true, mode: null };
|
|
709
747
|
if (expertAvailable) return { ask: false, mode: "client-expert" };
|
|
710
748
|
return { ask: false, mode: "client" };
|
package/device-login.mjs
CHANGED
|
@@ -115,11 +115,24 @@ export async function saveWorkerKey({ apiBase = DEFAULT_API_BASE, workerKey, log
|
|
|
115
115
|
return { apiBase: base, workerKey: key, envFile };
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
/**
|
|
119
|
+
* How to open `url` in the default browser → [command, args].
|
|
120
|
+
*
|
|
121
|
+
* GH #603: Windows used execFile("start", [url]) — but `start` is a cmd.exe built-in, not a program,
|
|
122
|
+
* so it failed with ENOENT and the sign-in page never opened (the user had to copy the printed URL).
|
|
123
|
+
* explorer.exe opens a URL in the default browser, as browser-command.mjs already does, and — unlike
|
|
124
|
+
* `cmd /c start` — never reads the URL's & as a command separator.
|
|
125
|
+
*/
|
|
126
|
+
export function browserOpenCommand(url, os = platform()) {
|
|
127
|
+
if (os === "darwin") return ["open", [url]];
|
|
128
|
+
if (os === "win32") return ["explorer.exe", [url]];
|
|
129
|
+
return ["xdg-open", [url]];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function openBrowser(url) {
|
|
133
|
+
const [cmd, args] = browserOpenCommand(url);
|
|
121
134
|
try {
|
|
122
|
-
execFile(cmd,
|
|
135
|
+
execFile(cmd, args, () => {}); // best-effort; the URL is also printed
|
|
123
136
|
} catch {
|
|
124
137
|
/* the user can open it manually */
|
|
125
138
|
}
|
package/gu-cli.mjs
CHANGED
|
@@ -1081,10 +1081,9 @@ if (args[0] === "token-usage" || args[0] === "tokens") {
|
|
|
1081
1081
|
console.log(`\n Opening ${pageUrl}`);
|
|
1082
1082
|
console.log(" (the link is single-use and expires in a few minutes)\n");
|
|
1083
1083
|
try {
|
|
1084
|
-
|
|
1085
|
-
const {
|
|
1086
|
-
|
|
1087
|
-
execFile(cmd, [url], () => {});
|
|
1084
|
+
// GH #603: one helper — `start` is a cmd.exe built-in, so on Windows it never opened anything.
|
|
1085
|
+
const { openBrowser } = await import("./device-login.mjs");
|
|
1086
|
+
openBrowser(url);
|
|
1088
1087
|
} catch {
|
|
1089
1088
|
/* best-effort; the URL is printed below */
|
|
1090
1089
|
}
|
package/gu-repl.mjs
CHANGED
|
@@ -87,6 +87,8 @@ import {
|
|
|
87
87
|
otherAgentRows,
|
|
88
88
|
updateRow,
|
|
89
89
|
noticeRow,
|
|
90
|
+
midTurnCommandKind,
|
|
91
|
+
HIDDEN_COMMANDS,
|
|
90
92
|
updateNotice,
|
|
91
93
|
answerBlock,
|
|
92
94
|
updateRestartNote,
|
|
@@ -696,7 +698,7 @@ if (cliVerdict.kind === "run") {
|
|
|
696
698
|
} else if (argv.includes("--help") || argv.includes("-h")) {
|
|
697
699
|
console.log(
|
|
698
700
|
"gu — terminal agent REPL for the current folder\n\n" +
|
|
699
|
-
"Usage: gu [-v|--verbose] [--log] [--color] [--name <text>] [--license <pro token>]\n" +
|
|
701
|
+
"Usage: gu [-v|--verbose] [--log] [--color] [--name <text>] [--license <pro token>] [--cloud <code>]\n" +
|
|
700
702
|
" gu status # worker + a table of the running model servers\n" +
|
|
701
703
|
" gu start|stop|restart|logs # manage the background worker\n" +
|
|
702
704
|
" gu logs <port|pid> [-f] # tail a running model server's log\n" +
|
|
@@ -712,6 +714,8 @@ if (cliVerdict.kind === "run") {
|
|
|
712
714
|
" --license <token> pro license: a first install ASKS how this machine runs (hosted\n" +
|
|
713
715
|
" client / MLX host / private). Without it, a first install is\n" +
|
|
714
716
|
" private by default — the whole stack on this machine.\n" +
|
|
717
|
+
" --cloud <code> a Cloud link someone sent you (gucli.com/cloud/<code>): this\n" +
|
|
718
|
+
" computer uses Cloud mode, and the link is added to your account.\n" +
|
|
715
719
|
" -h, --help this help\n\n" +
|
|
716
720
|
"Auth comes from ~/.gu/worker.env; models/budgets/RAG come from your web Settings.\n" +
|
|
717
721
|
"Inside the REPL: /exit · /model · /new · /help — Ctrl-C stops following a turn.\n" +
|
|
@@ -924,7 +928,7 @@ if (!workerKey || !apiBase) {
|
|
|
924
928
|
const {
|
|
925
929
|
probeMachine, askMode, runClientExpertSetup, loadState, saveState,
|
|
926
930
|
} = await import("./client-expert-run.mjs");
|
|
927
|
-
const { clientExpertAvailable, parseLicenseFlag, resolveFirstRunMode, licenseUnverifiedLine, promptForLicenseToken } =
|
|
931
|
+
const { clientExpertAvailable, parseLicenseFlag, resolveFirstRunMode, licenseUnverifiedLine, promptForLicenseToken, parseCloudFlag, checkCloudLink } =
|
|
928
932
|
await import("./client-expert-setup.mjs");
|
|
929
933
|
const machine0 = await probeMachine();
|
|
930
934
|
const gate0 = clientExpertAvailable({ workerEnvExists: false, ...machine0 });
|
|
@@ -934,9 +938,12 @@ if (!workerKey || !apiBase) {
|
|
|
934
938
|
// three-way menu (hosted client / MLX host / private) is shown only when the run
|
|
935
939
|
// carries a pro license token: `gu --license <token>`.
|
|
936
940
|
const licenseToken0 = parseLicenseFlag(argv);
|
|
941
|
+
// GH #603: `gu --cloud <code>` — an admin's Cloud link: Cloud mode, no menu (checked first).
|
|
942
|
+
const cloudCode0 = await cloudLinkForFirstRun(parseCloudFlag(argv), checkCloudLink);
|
|
937
943
|
let plan0 = resolveFirstRunMode({
|
|
938
944
|
licenseToken: licenseToken0,
|
|
939
945
|
expertAvailable: gate0.available,
|
|
946
|
+
cloudCode: cloudCode0,
|
|
940
947
|
});
|
|
941
948
|
if (plan0.ask) {
|
|
942
949
|
// A bad token no longer picks private FOR the user: warn, and let them paste another
|
|
@@ -2567,6 +2574,19 @@ rl.on("line", (l) => {
|
|
|
2567
2574
|
void runTaskCommand();
|
|
2568
2575
|
return;
|
|
2569
2576
|
}
|
|
2577
|
+
// GH #593: any other gu command never goes to the agent as a note — it runs now, or after the turn.
|
|
2578
|
+
const cmdKind = midTurnCommandKind(queued, knownCommandWords());
|
|
2579
|
+
if (cmdKind === "now") {
|
|
2580
|
+
void runCommandDuringTurn(queued);
|
|
2581
|
+
return;
|
|
2582
|
+
}
|
|
2583
|
+
if (cmdKind === "after") {
|
|
2584
|
+
if (turnQueue.push(queued)) {
|
|
2585
|
+
console.log(GUTTER + dim(`${queued.split(/\s+/)[0]} runs when this turn ends.`));
|
|
2586
|
+
if (barPinned()) paintBar();
|
|
2587
|
+
} else process.stdout.write(dim(`\n (${turnQueue.size} questions are already queued — wait for one to run)\n`));
|
|
2588
|
+
return;
|
|
2589
|
+
}
|
|
2570
2590
|
// GH #506: with a running job, the text goes to the agent's NEXT step (appended after the
|
|
2571
2591
|
// current step's result — cache-safe). Not read by the end of the turn = the next question.
|
|
2572
2592
|
// GH #514: like chat — no notices. Pinned, it waits as a ">> " row above the input box until the agent
|
|
@@ -2859,20 +2879,27 @@ const modeLineText = () => {
|
|
|
2859
2879
|
// project's newest open task (not chosen for this session): that is how work gets misfiled.
|
|
2860
2880
|
const width = Math.max(20, process.stdout.columns || 80) - GUTTER.length - 1;
|
|
2861
2881
|
const room = width - visibleLen(base) - 3;
|
|
2862
|
-
const mem = memoryBarText(memCurrent, Math.min(room,
|
|
2882
|
+
const mem = memoryBarText(memCurrent, Math.min(room, 80), memSkills);
|
|
2863
2883
|
if (!mem.text || room < 16) return base + quick;
|
|
2864
|
-
const memPart = " " + (mem.
|
|
2884
|
+
const memPart = " " + (mem.warn ? yellow(mem.text) : dim(mem.text));
|
|
2865
2885
|
return base + memPart + (visibleLen(base + memPart + quick) <= width ? quick : "");
|
|
2866
2886
|
};
|
|
2867
2887
|
// GH #595: the memory skill's current task for this session (null = no memory here / not installed for gu).
|
|
2868
2888
|
let memCurrent = null;
|
|
2869
2889
|
let memRuntimeFound = null;
|
|
2890
|
+
// Whose skills this folder uses (/switch-skill) and whether the memory skill is in them / in the other set.
|
|
2891
|
+
let memSkills = { label: "", active: false, otherHas: false };
|
|
2870
2892
|
async function refreshMemoryTask() {
|
|
2871
2893
|
try {
|
|
2872
2894
|
const cwd = resolve(process.cwd());
|
|
2873
|
-
|
|
2895
|
+
const { readSkillSource, sourceLabel } = await import("./skill-source.mjs");
|
|
2896
|
+
const source = readSkillSource(cwd);
|
|
2897
|
+
memRuntimeFound = memoryRuntime(hooksForTurn({ cwd, source }));
|
|
2898
|
+
const other = memoryRuntime(hooksForTurn({ cwd, source: source === "claude" ? "gu" : "claude" }));
|
|
2899
|
+
const skills = { label: sourceLabel(source), active: Boolean(memRuntimeFound), otherHas: Boolean(other) };
|
|
2874
2900
|
const next = memRuntimeFound ? await currentTask({ runtime: memRuntimeFound, cwd, session: sessionForTurn(cwd)?.id ?? "" }) : null;
|
|
2875
|
-
const changed = JSON.stringify(next?.task ?? null
|
|
2901
|
+
const changed = JSON.stringify([next?.task ?? null, next?.chosen, skills]) !== JSON.stringify([memCurrent?.task ?? null, memCurrent?.chosen, memSkills]);
|
|
2902
|
+
memSkills = skills;
|
|
2876
2903
|
memCurrent = next;
|
|
2877
2904
|
if (changed && barPinned()) paintBar();
|
|
2878
2905
|
} catch {
|
|
@@ -2883,6 +2910,125 @@ async function refreshMemoryTask() {
|
|
|
2883
2910
|
* /task (GH #595): choose the task the memory files this session's work under. The list is the
|
|
2884
2911
|
* project's open tasks, newest first, the current one marked.
|
|
2885
2912
|
*/
|
|
2913
|
+
/**
|
|
2914
|
+
* GH #603: a first run started with `gu --cloud <code>`. The link is checked before anything is set
|
|
2915
|
+
* up — a removed or mistyped one says why and the run goes on as if no flag was given. → the code, or "".
|
|
2916
|
+
*/
|
|
2917
|
+
async function cloudLinkForFirstRun(code, checkCloudLink) {
|
|
2918
|
+
if (!code) return "";
|
|
2919
|
+
const { DEFAULT_API_BASE } = await import("./device-login.mjs");
|
|
2920
|
+
const hostedBase = String(process.env.GU_TOKEN_API_BASE ?? "").trim() || DEFAULT_API_BASE;
|
|
2921
|
+
const c = await checkCloudLink(code, { hostedBase });
|
|
2922
|
+
if (!c.ok) {
|
|
2923
|
+
console.log("\n" + GUTTER + yellow(c.why));
|
|
2924
|
+
return "";
|
|
2925
|
+
}
|
|
2926
|
+
console.log(
|
|
2927
|
+
"\n" + GUTTER + accent(`Cloud link ${code}`) +
|
|
2928
|
+
dim(` — this computer uses Cloud mode${c.email ? `; sign in with ${c.email}` : ""}.`)
|
|
2929
|
+
);
|
|
2930
|
+
return code;
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
/**
|
|
2934
|
+
* GH #603: after sign-in, `gu --cloud <code>` puts the link on this account (the API checks it is the
|
|
2935
|
+
* email the admin typed). Says what happened in one line; never stops gu from starting.
|
|
2936
|
+
*/
|
|
2937
|
+
async function claimCloudLinkIfAsked() {
|
|
2938
|
+
try {
|
|
2939
|
+
const { parseCloudFlag } = await import("./client-expert-setup.mjs");
|
|
2940
|
+
const code = parseCloudFlag(argv);
|
|
2941
|
+
if (!code) return;
|
|
2942
|
+
const { loadState } = await import("./client-expert-run.mjs");
|
|
2943
|
+
const st = await loadState();
|
|
2944
|
+
if (st.chosenMode === "client-expert" || isClientExpert()) {
|
|
2945
|
+
console.log(GUTTER + yellow(`This computer runs in private mode, so the Cloud link ${code} doesn't apply here.`) +
|
|
2946
|
+
dim(` To switch: gu clear, then gu --cloud ${code}`));
|
|
2947
|
+
return;
|
|
2948
|
+
}
|
|
2949
|
+
if (!workerKey) {
|
|
2950
|
+
console.log(GUTTER + yellow(`Cloud link ${code}: gu isn't signed in yet, so it couldn't be added.`) + dim(` Run gu --cloud ${code} again after signing in.`));
|
|
2951
|
+
return;
|
|
2952
|
+
}
|
|
2953
|
+
const r = await fetch(`${apiBase}/api/worker/cloud-link/claim`, {
|
|
2954
|
+
method: "POST",
|
|
2955
|
+
headers: { "Content-Type": "application/json", "X-Worker-Key": workerKey },
|
|
2956
|
+
body: JSON.stringify({ code }),
|
|
2957
|
+
signal: AbortSignal.timeout(15_000),
|
|
2958
|
+
});
|
|
2959
|
+
const body = await r.json().catch(() => ({}));
|
|
2960
|
+
if (r.ok) console.log(GUTTER + accent(`✓ Cloud link ${code} is on this account`) + dim(" — Cloud mode is ready.\n"));
|
|
2961
|
+
else console.log(GUTTER + yellow(body?.error || `Cloud link ${code} could not be added (HTTP ${r.status}).`) + "\n");
|
|
2962
|
+
} catch (e) {
|
|
2963
|
+
console.log(GUTTER + dim(`Cloud link: could not reach the server (${e instanceof Error ? e.message : e}). Run the same command again later.`));
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
|
|
2967
|
+
/** GH #536 / #593: /suggestions [on|off] — at the prompt or during a turn. */
|
|
2968
|
+
function setSuggestions(arg) {
|
|
2969
|
+
// GH #536: the suggested next message after a turn — on by default, remembered for every folder.
|
|
2970
|
+
suggestionsOn = suggestionsToggle(arg, suggestionsOn);
|
|
2971
|
+
try {
|
|
2972
|
+
mkdirSync(dirname(SUGGESTIONS_FILE), { recursive: true });
|
|
2973
|
+
writeFileSync(SUGGESTIONS_FILE, suggestionsOn ? "on\n" : "off\n");
|
|
2974
|
+
} catch {}
|
|
2975
|
+
if (!suggestionsOn) clearNextHint();
|
|
2976
|
+
console.log(
|
|
2977
|
+
GUTTER + (suggestionsOn ? accent("suggestions: ON") : dim("suggestions: OFF")) +
|
|
2978
|
+
dim(suggestionsOn
|
|
2979
|
+
? " — after some answers a next message appears in the input; Tab takes it.\n"
|
|
2980
|
+
: " — no suggested next message after a turn. /suggestions on brings it back.\n")
|
|
2981
|
+
);
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
/** GH #593: /budget — the short terminal version of web-v2's /providers budgets (#205). The server
|
|
2985
|
+
* judges Pro, the account email and "has items" (api/src/providers/terminalBudget.ts). */
|
|
2986
|
+
async function showBudget() {
|
|
2987
|
+
try {
|
|
2988
|
+
const bv = await import("./budget-view.mjs");
|
|
2989
|
+
const ct = await import("./cli-token.mjs");
|
|
2990
|
+
const { DEFAULT_API_BASE } = await import("./device-login.mjs");
|
|
2991
|
+
const state = await ct.readState(join(homedir(), ".gu"));
|
|
2992
|
+
const result = await bv.fetchProvidersBudget({
|
|
2993
|
+
apiBase,
|
|
2994
|
+
workerKey,
|
|
2995
|
+
hostedBase: String(process.env.GU_TOKEN_API_BASE ?? "").trim() || DEFAULT_API_BASE,
|
|
2996
|
+
token: state.token,
|
|
2997
|
+
});
|
|
2998
|
+
const out = bv.budgetLines(result, { site: ct.siteUrl() });
|
|
2999
|
+
for (const l of out.lines) console.log(GUTTER + (out.tone === "ok" ? l : dim(l)));
|
|
3000
|
+
console.log("");
|
|
3001
|
+
} catch (e) {
|
|
3002
|
+
console.log(GUTTER + dim(`Could not show your budgets: ${e instanceof Error ? e.message : e}\n`));
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
/** GH #593: the words gu answers to as commands — listed, aliases and hidden. */
|
|
3007
|
+
function knownCommandWords() {
|
|
3008
|
+
return [...COMMANDS.flatMap((c) => [c.name, ...(c.aliases ?? [])]), ...HIDDEN_COMMANDS].map((w) => w.toLowerCase());
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
/** GH #593: a command that only SHOWS something, typed during a turn — runs now; the turn goes on. */
|
|
3012
|
+
async function runCommandDuringTurn(line) {
|
|
3013
|
+
const word = line.split(/\s+/)[0].toLowerCase();
|
|
3014
|
+
try {
|
|
3015
|
+
if (word === "/" || word === "/help") printCommands();
|
|
3016
|
+
else if (word === "/cost" || word === "/prices") await runCostCommand(line);
|
|
3017
|
+
else if (word === "/shells") await showShells();
|
|
3018
|
+
else if (word === "/budget") await showBudget();
|
|
3019
|
+
else if (word === "/mcp") await runMcpSlashCommand(line);
|
|
3020
|
+
else if (word === "/hooks") {
|
|
3021
|
+
const { runHooksCommand } = await import("./hooks-command.mjs");
|
|
3022
|
+
const style = { ok: accent, warn: yellow, dim };
|
|
3023
|
+
await runHooksCommand([], { cwd: process.cwd(), print: (l, kind) => console.log(GUTTER + (style[kind] ?? ((x) => x))(l)) });
|
|
3024
|
+
console.log("");
|
|
3025
|
+
} else if (word === "/suggestions") setSuggestions(line.slice("/suggestions".length));
|
|
3026
|
+
} catch (e) {
|
|
3027
|
+
console.log(GUTTER + dim(`${word}: ${e instanceof Error ? e.message : e}`));
|
|
3028
|
+
}
|
|
3029
|
+
if (barPinned()) paintBar();
|
|
3030
|
+
}
|
|
3031
|
+
|
|
2886
3032
|
async function runTaskCommand() {
|
|
2887
3033
|
if (listPickerActive || approvalActive) return;
|
|
2888
3034
|
await refreshMemoryTask();
|
|
@@ -3630,7 +3776,8 @@ function zoneNotice(width) {
|
|
|
3630
3776
|
// While the token question is open it is the ONLY thing on the screen (#222): the housekeeping
|
|
3631
3777
|
// notices (new prices, new token limits) wait, and the token notice would repeat the question.
|
|
3632
3778
|
if (limitsUpdate && !tokenQuestionOpen) items.push({ key: "limits", clickable: true, paint: accent, text: `${limitsUpdate.label} (click)` });
|
|
3633
|
-
|
|
3779
|
+
// GH #602: the gu token notice ("trial · 417 days left · …") is NOT here any more — it has a row of its
|
|
3780
|
+
// own below this one (zoneTokenRow), so neither is squeezed or dropped for the other.
|
|
3634
3781
|
const agents = agentsIndicator(otherAgents);
|
|
3635
3782
|
if (agents) items.push({ key: "agents", clickable: true, paint: accent, text: `${agents} running (click)` });
|
|
3636
3783
|
const shells = shellsNotice(shellEntries, { cwd: process.cwd() });
|
|
@@ -3647,6 +3794,17 @@ function zoneNotice(width) {
|
|
|
3647
3794
|
return noticeRow(items, { width, gutter: GUTTER });
|
|
3648
3795
|
}
|
|
3649
3796
|
|
|
3797
|
+
/**
|
|
3798
|
+
* GH #602: the gu token notice on its OWN row, directly above the separator and below the clickable
|
|
3799
|
+
* notices — the owner: the update link on one line, the trial on the next, nothing squeezed together.
|
|
3800
|
+
* Cut with "…" when the window is too narrow; null when there is nothing to say.
|
|
3801
|
+
*/
|
|
3802
|
+
function zoneTokenRow(width) {
|
|
3803
|
+
if (!tokenNotice?.text || tokenQuestionOpen) return null;
|
|
3804
|
+
const paint = tokenNotice.urgent ? yellow : dim;
|
|
3805
|
+
return GUTTER + paint(clipVisible(tokenNotice.text, Math.max(10, width - GUTTER.length - 1)));
|
|
3806
|
+
}
|
|
3807
|
+
|
|
3650
3808
|
/**
|
|
3651
3809
|
* The whole frozen zone, top to bottom: a separator, a blank row, the INPUT LINE, then the
|
|
3652
3810
|
* bar's rule, token and mode rows. The blank is what lifts the separator — and the control it
|
|
@@ -3705,6 +3863,7 @@ function frozenZone() {
|
|
|
3705
3863
|
// control, the gu token notice, the agents count — is on its own NOTICE ROW above it; the head
|
|
3706
3864
|
// is just the rule, with no blank to lift a control off the typed line.
|
|
3707
3865
|
const notice = zoneNotice(width);
|
|
3866
|
+
const tokenRow = zoneTokenRow(width); // GH #602: below the clickable notices, a row of its own
|
|
3708
3867
|
const zone = inputZoneRows({
|
|
3709
3868
|
headControl: false,
|
|
3710
3869
|
width,
|
|
@@ -3754,12 +3913,12 @@ function frozenZone() {
|
|
|
3754
3913
|
ghost: nextHint && promptIdleForHint() ? dim(ghostText(nextHint)) : "",
|
|
3755
3914
|
});
|
|
3756
3915
|
const footer = footerBuilt();
|
|
3757
|
-
const rows = status.concat(notice ? [notice.row] : [], zone.rows, askHintRows(width), footer.rows);
|
|
3916
|
+
const rows = status.concat(notice ? [notice.row] : [], tokenRow ? [tokenRow] : [], zone.rows, askHintRows(width), footer.rows);
|
|
3758
3917
|
// The footer is the LAST rows of the zone, so the link's row counts from the end.
|
|
3759
3918
|
supportLinkTarget = footer.link ? { fromEnd: footer.rows.length - footer.link.rowIndex, from: footer.link.from, to: footer.link.to } : null;
|
|
3760
3919
|
// The separator is `status.length (+1 for the notice row)` rows down — everything that writes to
|
|
3761
3920
|
// or hit-tests a row by index counts from here.
|
|
3762
|
-
const sep = status.length + (notice ? 1 : 0);
|
|
3921
|
+
const sep = status.length + (notice ? 1 : 0) + (tokenRow ? 1 : 0);
|
|
3763
3922
|
updateRowTarget = notice?.spans.update ?? null;
|
|
3764
3923
|
agentsRowTarget = notice?.spans.agents ?? null;
|
|
3765
3924
|
limitsRowTarget = notice?.spans.limits ?? null;
|
|
@@ -3768,7 +3927,9 @@ function frozenZone() {
|
|
|
3768
3927
|
diskRowTarget = notice?.spans.disk ?? null;
|
|
3769
3928
|
shellsRowTarget = notice?.spans.shells ?? null;
|
|
3770
3929
|
jumpSpan = notice?.spans.jump ?? null;
|
|
3771
|
-
|
|
3930
|
+
// noticeRow: how many rows ABOVE the separator the clickable notice row is (0 = none) — 2 when the
|
|
3931
|
+
// token row sits between them (GH #602).
|
|
3932
|
+
return { ...zone, rows, statusRows: sep, noticeRow: notice ? (tokenRow ? 2 : 1) : 0 };
|
|
3772
3933
|
}
|
|
3773
3934
|
/**
|
|
3774
3935
|
* Put the output position back at column 0 of its own row — without printing anything.
|
|
@@ -3834,7 +3995,7 @@ function paintBar() {
|
|
|
3834
3995
|
// looking at rather than re-deriving them from rl.line at a width this may not be.
|
|
3835
3996
|
inputRowTexts = zone.rows.slice((zone.statusRows ?? 0) + head);
|
|
3836
3997
|
// THE NOTICE ROW is the one directly above the separator (#318) — never the separator itself.
|
|
3837
|
-
const noticeAbs = zone.noticeRow ? sepAbs -
|
|
3998
|
+
const noticeAbs = zone.noticeRow ? sepAbs - zone.noticeRow : 0;
|
|
3838
3999
|
jumpRowTarget = scrolledBack() && jumpSpan ? { row: noticeAbs, ...jumpSpan } : null;
|
|
3839
4000
|
updateRowAbs = updateRowTarget || agentsRowTarget || limitsRowTarget || logsRowTarget || gudbRowTarget || diskRowTarget || shellsRowTarget ? noticeAbs : 0;
|
|
3840
4001
|
// preserveCaret:false — the save slot holds the OUTPUT position (see regionUi), and the caret
|
|
@@ -15448,7 +15609,7 @@ async function main() {
|
|
|
15448
15609
|
}
|
|
15449
15610
|
try {
|
|
15450
15611
|
const { loadState, saveState, askMode } = await import("./client-expert-run.mjs");
|
|
15451
|
-
const { clientExpertAvailable, expertPlanPending, shouldAskMode, parseLicenseFlag, resolveFirstRunMode, promptForLicenseToken } =
|
|
15612
|
+
const { clientExpertAvailable, expertPlanPending, shouldAskMode, parseLicenseFlag, resolveFirstRunMode, promptForLicenseToken, parseCloudFlag, checkCloudLink } =
|
|
15452
15613
|
await import("./client-expert-setup.mjs");
|
|
15453
15614
|
const st = await loadState();
|
|
15454
15615
|
const { probeMachine } = await import("./client-expert-run.mjs");
|
|
@@ -15469,6 +15630,7 @@ async function main() {
|
|
|
15469
15630
|
let plan = resolveFirstRunMode({
|
|
15470
15631
|
licenseToken: licenseToken1,
|
|
15471
15632
|
expertAvailable: gate.available,
|
|
15633
|
+
cloudCode: await cloudLinkForFirstRun(parseCloudFlag(argv), checkCloudLink), // GH #603
|
|
15472
15634
|
});
|
|
15473
15635
|
if (plan.ask) {
|
|
15474
15636
|
// Same as the first run: warn and re-ask on a bad token instead of silently picking
|
|
@@ -15531,6 +15693,7 @@ async function main() {
|
|
|
15531
15693
|
} catch {
|
|
15532
15694
|
/* never block the REPL on the mode question — the banner still shows what is configured */
|
|
15533
15695
|
}
|
|
15696
|
+
await claimCloudLinkIfAsked(); // GH #603: `gu --cloud <code>` — this account takes the link
|
|
15534
15697
|
|
|
15535
15698
|
try {
|
|
15536
15699
|
const ctl = await import("./daemon-control.mjs");
|
|
@@ -16663,19 +16826,7 @@ async function main() {
|
|
|
16663
16826
|
continue;
|
|
16664
16827
|
}
|
|
16665
16828
|
if (line === "/suggestions" || line.startsWith("/suggestions ")) {
|
|
16666
|
-
|
|
16667
|
-
suggestionsOn = suggestionsToggle(line.slice("/suggestions".length), suggestionsOn);
|
|
16668
|
-
try {
|
|
16669
|
-
mkdirSync(dirname(SUGGESTIONS_FILE), { recursive: true });
|
|
16670
|
-
writeFileSync(SUGGESTIONS_FILE, suggestionsOn ? "on\n" : "off\n");
|
|
16671
|
-
} catch {}
|
|
16672
|
-
if (!suggestionsOn) clearNextHint();
|
|
16673
|
-
console.log(
|
|
16674
|
-
GUTTER + (suggestionsOn ? accent("suggestions: ON") : dim("suggestions: OFF")) +
|
|
16675
|
-
dim(suggestionsOn
|
|
16676
|
-
? " — after some answers a next message appears in the input; Tab takes it.\n"
|
|
16677
|
-
: " — no suggested next message after a turn. /suggestions on brings it back.\n")
|
|
16678
|
-
);
|
|
16829
|
+
setSuggestions(line.slice("/suggestions".length));
|
|
16679
16830
|
continue;
|
|
16680
16831
|
}
|
|
16681
16832
|
if (line === "/hover") {
|
|
@@ -16789,6 +16940,7 @@ async function main() {
|
|
|
16789
16940
|
}
|
|
16790
16941
|
if (line === "/switch-skill" || line.startsWith("/switch-skill ")) {
|
|
16791
16942
|
await runSwitchSkillCommand(line);
|
|
16943
|
+
void refreshMemoryTask(); // GH #595: the bar says whose skills, and whether the memory is in them
|
|
16792
16944
|
continue;
|
|
16793
16945
|
}
|
|
16794
16946
|
if (line === "/skill-pack" || line.startsWith("/skill-pack ")) {
|
|
@@ -16946,25 +17098,7 @@ async function main() {
|
|
|
16946
17098
|
continue;
|
|
16947
17099
|
}
|
|
16948
17100
|
if (line === "/budget") {
|
|
16949
|
-
|
|
16950
|
-
// the account email and "has items" (api/src/providers/terminalBudget.ts).
|
|
16951
|
-
try {
|
|
16952
|
-
const bv = await import("./budget-view.mjs");
|
|
16953
|
-
const ct = await import("./cli-token.mjs");
|
|
16954
|
-
const { DEFAULT_API_BASE } = await import("./device-login.mjs");
|
|
16955
|
-
const state = await ct.readState(join(homedir(), ".gu"));
|
|
16956
|
-
const result = await bv.fetchProvidersBudget({
|
|
16957
|
-
apiBase,
|
|
16958
|
-
workerKey,
|
|
16959
|
-
hostedBase: String(process.env.GU_TOKEN_API_BASE ?? "").trim() || DEFAULT_API_BASE,
|
|
16960
|
-
token: state.token,
|
|
16961
|
-
});
|
|
16962
|
-
const out = bv.budgetLines(result, { site: ct.siteUrl() });
|
|
16963
|
-
for (const l of out.lines) console.log(GUTTER + (out.tone === "ok" ? l : dim(l)));
|
|
16964
|
-
console.log("");
|
|
16965
|
-
} catch (e) {
|
|
16966
|
-
console.log(GUTTER + dim(`Could not show your budgets: ${e instanceof Error ? e.message : e}\n`));
|
|
16967
|
-
}
|
|
17101
|
+
await showBudget();
|
|
16968
17102
|
continue;
|
|
16969
17103
|
}
|
|
16970
17104
|
if (line === "/tokens") {
|
package/memory-task.mjs
CHANGED
|
@@ -60,18 +60,20 @@ const clip = (s, n) => {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
* The bar's text
|
|
64
|
-
*
|
|
65
|
-
*
|
|
63
|
+
* The bar's text → { text, warn } ("" when the memory skill is in neither skill set).
|
|
64
|
+
*
|
|
65
|
+
* GH #601 (owner, with a screenshot): "memory" in yellow and (/task) in yellow — NO task title after
|
|
66
|
+
* it; the task is what /task shows and changes. Whose skills stays, as one word (GH #595: a folder uses
|
|
67
|
+
* Claude Code's skills or gu's own, /switch-skill, and only one set may have the memory skill):
|
|
68
|
+
* "◆ gu's memory (/task)". Memory only in the OTHER set → "◆ gu's memory off — /switch-skill".
|
|
66
69
|
*/
|
|
67
|
-
export function memoryBarText(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return { text: head + clip(cur.task.title, titleRoom) + tail, guess: !cur.chosen };
|
|
70
|
+
export function memoryBarText(_cur, room = 40, { label = "", active = true, otherHas = false } = {}) {
|
|
71
|
+
const whose = /claude/i.test(label) ? "Claude's " : label ? "gu's " : "";
|
|
72
|
+
if (!active) {
|
|
73
|
+
if (!otherHas) return { text: "", warn: false };
|
|
74
|
+
return { text: clip(`◆ ${whose}memory off — /switch-skill`, room), warn: true };
|
|
75
|
+
}
|
|
76
|
+
return { text: clip(`◆ ${whose}memory`, Math.max(4, room - 9)) + " (/task)", warn: true };
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
/** The /task picker's rows: the open tasks, the current one marked. */
|
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.943",
|
|
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
|
@@ -1977,6 +1977,9 @@ export function classifyTurnFailure(message) {
|
|
|
1977
1977
|
// backend patterns below and was captioned "the coding model's backend failed … /model to switch
|
|
1978
1978
|
// coder" — wrong on both counts, and switching coder cannot help. The message itself already
|
|
1979
1979
|
// says the next step. Both wordings: this gu's, and 1.0.724's ("could not be loaded (HTTP 503)").
|
|
1980
|
+
// ACCESS — GH #603: the account's Cloud link was removed. Nothing ran and nothing in gu fixes it;
|
|
1981
|
+
// "/model to switch coder" or "continue" would both be wrong.
|
|
1982
|
+
if (/Your Cloud access was removed/i.test(t)) return "access";
|
|
1980
1983
|
if (/The agent couldn't start|The agent's prompt (could not be loaded|could not be used)|agent's prompt templates could not be loaded/i.test(t)) {
|
|
1981
1984
|
return "setup";
|
|
1982
1985
|
}
|
|
@@ -2086,6 +2089,7 @@ export function retryAdvice({ resumable = true, failures = 1, kind = "task", min
|
|
|
2086
2089
|
// GitHub #129: name the missing piece and the one step that fixes it.
|
|
2087
2090
|
return 'the agent framework (smolagents + openai) is not installed in this machine\'s Python, so nothing ran — run /doctor to install it, or restart gu and answer yes to "Install the agent framework now?", then "continue" sends your question again.';
|
|
2088
2091
|
}
|
|
2092
|
+
if (kind === "access") return null; // GH #603: the message says who to ask; retrying can't help
|
|
2089
2093
|
if (kind === "setup") {
|
|
2090
2094
|
// Nothing ran, so there is nothing to diagnose in the model or the question — only the step the
|
|
2091
2095
|
// message above names. "continue" is right AFTER that step, never before.
|
|
@@ -3653,3 +3657,23 @@ export function commandBlockRows(text, { width = 80, indent = " ", collapsed =
|
|
|
3653
3657
|
const hidden = rows.length - maxRows;
|
|
3654
3658
|
return [...rows.slice(0, maxRows), clipVisible(indent + `… +${hidden} more rows — click to expand (ctrl+o)`, width)];
|
|
3655
3659
|
}
|
|
3660
|
+
|
|
3661
|
+
/**
|
|
3662
|
+
* GH #593: a slash command typed DURING a turn — never a note to the agent.
|
|
3663
|
+
* "now" — only shows something, so it runs at once (the turn keeps going);
|
|
3664
|
+
* "after" — changes the session or needs the screen, so it runs when the turn ends;
|
|
3665
|
+
* null — not one of gu's commands ("/Users/me/app is broken" stays a message to the agent).
|
|
3666
|
+
* /model and /task have their own mid-turn handling (GH #588, #595) and are not decided here.
|
|
3667
|
+
*/
|
|
3668
|
+
export const MID_TURN_NOW = new Set(["/", "/help", "/cost", "/prices", "/shells", "/suggestions", "/budget"]);
|
|
3669
|
+
// Shown, not changed — but only bare: "/mcp add …" and "/hooks off" change things and wait.
|
|
3670
|
+
export const MID_TURN_NOW_BARE = new Set(["/mcp", "/hooks"]);
|
|
3671
|
+
export function midTurnCommandKind(line, known = []) {
|
|
3672
|
+
const s = String(line ?? "").trim();
|
|
3673
|
+
if (!s.startsWith("/")) return null;
|
|
3674
|
+
const word = s.split(/\s+/)[0].toLowerCase();
|
|
3675
|
+
const bare = word === s.toLowerCase();
|
|
3676
|
+
if (MID_TURN_NOW.has(word)) return "now";
|
|
3677
|
+
if (MID_TURN_NOW_BARE.has(word)) return bare ? "now" : "after";
|
|
3678
|
+
return known.includes(word) ? "after" : null;
|
|
3679
|
+
}
|