@tiens.nguyen/gu-cli 1.0.931 → 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/autocompact.mjs +136 -0
- package/browser-bridge.mjs +8 -0
- package/browser-extension/README.md +4 -0
- package/browser-extension/actions.js +366 -5
- package/browser-extension/background.js +104 -14
- package/browser-extension/manifest.json +1 -1
- package/browser-extension/popup.html +83 -15
- package/browser-extension/popup.js +145 -35
- package/clear-state.mjs +12 -1
- package/cli-token.mjs +6 -3
- package/client-expert-api.mjs +109 -20
- package/client-expert-run.mjs +263 -120
- package/client-expert-setup.mjs +3 -2
- package/coding-provider-setup.mjs +27 -0
- package/free-model.mjs +33 -6
- package/gonext_agent_chat.py +748 -27
- package/gu-cli.mjs +90 -6
- package/gu-repl.mjs +545 -29
- package/gu_browser.py +83 -9
- package/gu_gif.py +101 -0
- package/gu_turn_notes.py +29 -2
- package/install-path.mjs +52 -20
- package/lsp-client.mjs +267 -0
- package/lsp-host.mjs +391 -0
- package/lsp-registry.mjs +568 -0
- package/model-doctor.mjs +34 -7
- package/model-prices.mjs +22 -0
- package/next-suggestion.mjs +137 -0
- package/package.json +10 -1
- package/powershell-alias.mjs +12 -1
- package/python-unix.mjs +120 -0
- package/setup-fixes.mjs +245 -0
- package/step-group.mjs +59 -18
- package/terminal-layout.mjs +82 -3
- package/turn-notes.mjs +65 -0
- package/win-shell.mjs +26 -0
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// other tabs are never read, captured or controlled. What each command does is in actions.js,
|
|
11
11
|
// shared with gu's own Chrome window (browser-chrome.mjs).
|
|
12
12
|
|
|
13
|
-
import { enableDomains, forgetTab, hideFrame, onCdpEvent, runAction } from "./actions.js";
|
|
13
|
+
import { enableDomains, forgetTab, getLastStep, hideFrame, onCdpEvent, runAction } from "./actions.js";
|
|
14
14
|
|
|
15
15
|
const DEFAULT_PORT = 4127;
|
|
16
16
|
const VERSION = chrome.runtime.getManifest().version;
|
|
@@ -20,6 +20,20 @@ let connecting = false; // set before the first await: startup fires connect() s
|
|
|
20
20
|
let pingTimer = null;
|
|
21
21
|
const attached = new Set();
|
|
22
22
|
const notes = []; // why gu opened or adopted a tab — handed to the next command's answer (GH #428)
|
|
23
|
+
// GH #551: what gu is doing now (for the popup), and the Stop button.
|
|
24
|
+
let busy = null; // { text, since } while a command runs
|
|
25
|
+
let stoppedAt = 0; // when the user pressed Stop; commands are refused until the turn's cleanup
|
|
26
|
+
const STOP_HOLDS_MS = 120000; // a Stop never outlives the turn it was meant for by much
|
|
27
|
+
export const STOPPED_ERROR = "The user pressed Stop in Chrome. Stop now: do not use the browser or any other tool again, and tell the user you stopped.";
|
|
28
|
+
// While a command runs, the popup says it in the present tense. Never what is being typed.
|
|
29
|
+
const NOW = {
|
|
30
|
+
open: "opening a page", read: "reading the page", screenshot: "taking a screenshot", click: "clicking",
|
|
31
|
+
double_click: "double-clicking", right_click: "right-clicking", hover: "pointing", type: "typing",
|
|
32
|
+
key: "pressing keys", scroll: "scrolling", back: "going back", reload: "reloading", wait: "waiting for the page",
|
|
33
|
+
console: "reading the console", network: "reading network requests", resize: "resizing", upload: "uploading a file",
|
|
34
|
+
js: "checking the page", switch: "switching tab", tabs: "listing its tabs", close: "closing a tab", cleanup: "finishing",
|
|
35
|
+
};
|
|
36
|
+
const stopping = () => stoppedAt && Date.now() - stoppedAt < STOP_HOLDS_MS;
|
|
23
37
|
|
|
24
38
|
// ── connection ──────────────────────────────────────────────────────────────────────────────
|
|
25
39
|
async function bridgePort() {
|
|
@@ -85,7 +99,16 @@ chrome.runtime.onStartup.addListener(() => connect());
|
|
|
85
99
|
chrome.runtime.onInstalled.addListener(() => connect());
|
|
86
100
|
chrome.runtime.onMessage.addListener((msg, _sender, reply) => {
|
|
87
101
|
if (msg?.type === "status") {
|
|
88
|
-
|
|
102
|
+
// GH #551: the popup's whole picture — connection, what gu does, its tabs, a Stop under way.
|
|
103
|
+
popupState().then(reply);
|
|
104
|
+
return true;
|
|
105
|
+
} else if (msg?.type === "stop") {
|
|
106
|
+
const open = Boolean(ws && ws.readyState === WebSocket.OPEN);
|
|
107
|
+
if (open) {
|
|
108
|
+
stoppedAt = Date.now();
|
|
109
|
+
ws.send(JSON.stringify({ type: "stop" }));
|
|
110
|
+
}
|
|
111
|
+
reply({ ok: open, error: open ? undefined : "not connected to gu" });
|
|
89
112
|
} else if (msg?.type === "reconnect") {
|
|
90
113
|
connect().then(() => reply({ ok: true }));
|
|
91
114
|
return true;
|
|
@@ -116,14 +139,41 @@ async function onCommand(sock, data) {
|
|
|
116
139
|
}
|
|
117
140
|
if (!msg || msg.id === undefined) return;
|
|
118
141
|
let reply;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
reply = { id: msg.id, ok: false, error:
|
|
142
|
+
const action = String(msg.action || "").toLowerCase();
|
|
143
|
+
if (action === "cleanup") stoppedAt = 0; // the turn is over: a new one may use the browser again
|
|
144
|
+
if (stopping() && !["cleanup", "status", "tabs"].includes(action)) {
|
|
145
|
+
reply = { id: msg.id, ok: false, error: STOPPED_ERROR };
|
|
146
|
+
} else {
|
|
147
|
+
busy = { text: NOW[action] || "working", since: Date.now() };
|
|
148
|
+
try {
|
|
149
|
+
reply = { id: msg.id, ok: true, result: await run(msg) };
|
|
150
|
+
} catch (e) {
|
|
151
|
+
reply = { id: msg.id, ok: false, error: String(e?.message || e) };
|
|
152
|
+
} finally {
|
|
153
|
+
busy = null;
|
|
154
|
+
}
|
|
123
155
|
}
|
|
124
156
|
if (sock.readyState === WebSocket.OPEN) sock.send(JSON.stringify(reply));
|
|
125
157
|
}
|
|
126
158
|
|
|
159
|
+
/** Everything the popup shows (GH #551). Titles come from Chrome, so they are always current. */
|
|
160
|
+
async function popupState() {
|
|
161
|
+
const s = await state();
|
|
162
|
+
const live = await liveTabs();
|
|
163
|
+
const cur = (live.find((t) => t.id === s.current) || live[live.length - 1] || {}).id;
|
|
164
|
+
const last = getLastStep();
|
|
165
|
+
const tabTitle = (id) => live.find((t) => t.id === id)?.title || "";
|
|
166
|
+
return {
|
|
167
|
+
connected: Boolean(ws && ws.readyState === WebSocket.OPEN),
|
|
168
|
+
version: VERSION,
|
|
169
|
+
working: live.length > 0,
|
|
170
|
+
stopping: Boolean(stopping()),
|
|
171
|
+
busy: busy && { text: busy.text, since: busy.since },
|
|
172
|
+
last: last && live.some((t) => t.id === last.tab) ? { text: last.text, at: last.at, tab: last.tab, title: tabTitle(last.tab) } : null,
|
|
173
|
+
tabs: live.map((t) => ({ id: t.id, windowId: t.windowId, title: t.title, url: t.url, favicon: t.favIconUrl || "", shared: s.shared.includes(t.id), current: t.id === cur })),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
127
177
|
// ── gu's tabs ───────────────────────────────────────────────────────────────────────────────
|
|
128
178
|
async function state() {
|
|
129
179
|
const s = await chrome.storage.session.get(["tabs", "current", "group", "shared"]);
|
|
@@ -184,8 +234,31 @@ chrome.tabs.onCreated.addListener(async (tab) => {
|
|
|
184
234
|
});
|
|
185
235
|
|
|
186
236
|
// ── DevTools protocol ───────────────────────────────────────────────────────────────────────
|
|
237
|
+
// A tab Chrome is not drawing (its group folded, its window minimized) never takes mouse or key
|
|
238
|
+
// input: the call just waits. Seen live — every scroll hung 35 s while the "gu" group was folded.
|
|
239
|
+
// So input gives up quickly, with the reason, instead of eating the command's whole timeout.
|
|
240
|
+
const inputTimeoutMs = () => globalThis.GU_INPUT_TIMEOUT_MS ?? 10000;
|
|
187
241
|
function cdp(tabId, method, params = {}) {
|
|
188
|
-
|
|
242
|
+
const call = chrome.debugger.sendCommand({ tabId }, method, params);
|
|
243
|
+
if (!method.startsWith("Input.")) return call;
|
|
244
|
+
let timer;
|
|
245
|
+
return Promise.race([
|
|
246
|
+
call,
|
|
247
|
+
new Promise((_, reject) => (timer = setTimeout(() => reject(new Error(
|
|
248
|
+
"Chrome did not take the mouse/keyboard input in time — gu's tab is not being drawn (its window minimized?). " +
|
|
249
|
+
"Ask the user to bring that Chrome window back, then try again.")), inputTimeoutMs()))),
|
|
250
|
+
]).finally(() => clearTimeout(timer));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** gu's tab in a FOLDED tab group gets no input (above): unfold the group first, and say so. */
|
|
254
|
+
const NEEDS_DRAWING = new Set(["click", "double_click", "right_click", "hover", "type", "key", "scroll", "upload", "screenshot"]);
|
|
255
|
+
async function unfoldGroupOf(tabId) {
|
|
256
|
+
const tab = await chrome.tabs.get(tabId).catch(() => null);
|
|
257
|
+
if (!tab || tab.groupId == null || tab.groupId < 0) return;
|
|
258
|
+
const group = await chrome.tabGroups.get(tab.groupId).catch(() => null);
|
|
259
|
+
if (!group?.collapsed) return;
|
|
260
|
+
await chrome.tabGroups.update(tab.groupId, { collapsed: false }).catch(() => {});
|
|
261
|
+
notes.push("gu's tab group was folded, so Chrome had paused its page — gu unfolded the group to carry on");
|
|
189
262
|
}
|
|
190
263
|
|
|
191
264
|
chrome.debugger.onDetach.addListener((src) => attached.delete(src.tabId));
|
|
@@ -216,14 +289,19 @@ const host = {
|
|
|
216
289
|
let tab = newTab ? null : tabs.find((t) => t.id === s.current) || tabs[tabs.length - 1];
|
|
217
290
|
// #422: never bring the tab or the window to the front — gu drives it over the debugger, which
|
|
218
291
|
// works on a background tab, so the user's own tab and window keep the focus.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
292
|
+
// Attach BEFORE navigating, so "network" and "console" see the page's own load (#546): a new
|
|
293
|
+
// tab starts blank. A tab that can't be debugged where it is now is navigated first, and
|
|
294
|
+
// runAction attaches after (and says why if it still can't).
|
|
295
|
+
const reused = Boolean(tab);
|
|
296
|
+
if (!reused) {
|
|
297
|
+
tab = await chrome.tabs.create({ url: "about:blank", active: false });
|
|
224
298
|
await addToGroup(tab.id);
|
|
225
|
-
notes.push(`opened NEW tab ${tab.id} in the "gu" group because ${newTab ? "new_tab was set" : "gu had no tab open yet"}`);
|
|
226
299
|
}
|
|
300
|
+
await this.attach(tab.id).catch(() => {});
|
|
301
|
+
tab = await chrome.tabs.update(tab.id, { url });
|
|
302
|
+
notes.push(reused
|
|
303
|
+
? `reused gu's current tab ${tab.id} (navigated it) — pass new_tab to open another`
|
|
304
|
+
: `opened NEW tab ${tab.id} in the "gu" group because ${newTab ? "new_tab was set" : "gu had no tab open yet"}`);
|
|
227
305
|
await saveState({ current: tab.id });
|
|
228
306
|
return tab.id;
|
|
229
307
|
},
|
|
@@ -248,7 +326,8 @@ const host = {
|
|
|
248
326
|
},
|
|
249
327
|
async info(tabId) {
|
|
250
328
|
const t = await chrome.tabs.get(tabId).catch(() => null);
|
|
251
|
-
|
|
329
|
+
// A navigation not yet committed still shows the old page as "complete": that is loading.
|
|
330
|
+
return t ? { url: t.url, title: t.title, status: t.pendingUrl ? "loading" : t.status } : null;
|
|
252
331
|
},
|
|
253
332
|
async activate(tabId) {
|
|
254
333
|
await chrome.tabs.update(tabId, { active: true });
|
|
@@ -288,6 +367,13 @@ const host = {
|
|
|
288
367
|
async function run(cmd) {
|
|
289
368
|
const a = String(cmd.action || "").toLowerCase();
|
|
290
369
|
if (a === "status") return { version: VERSION, installType: await installType() };
|
|
370
|
+
if (a === "reload_self") {
|
|
371
|
+
// GH #551: a developer (unpacked) copy picks up its changed files without anyone clicking
|
|
372
|
+
// reload on chrome://extensions. Never the store copy: Chrome updates that one itself.
|
|
373
|
+
if ((await installType()) !== "development") throw new Error("only a developer (unpacked) install reloads itself");
|
|
374
|
+
setTimeout(() => chrome.runtime.reload(), 300); // answer first, then reload
|
|
375
|
+
return { reloading: VERSION };
|
|
376
|
+
}
|
|
291
377
|
if (a === "uninstall_self") {
|
|
292
378
|
// /browser cleanup (#147): a developer copy removes itself. Never the store copy — that one
|
|
293
379
|
// the user removes, or keeps.
|
|
@@ -295,5 +381,9 @@ async function run(cmd) {
|
|
|
295
381
|
setTimeout(() => chrome.management.uninstallSelf({ showConfirmDialog: false }).catch(() => {}), 200);
|
|
296
382
|
return { uninstalling: chrome.runtime.id };
|
|
297
383
|
}
|
|
384
|
+
if (NEEDS_DRAWING.has(a)) {
|
|
385
|
+
const id = await host.current().catch(() => null);
|
|
386
|
+
if (id != null) await unfoldGroupOf(id);
|
|
387
|
+
}
|
|
298
388
|
return runAction(cmd, host);
|
|
299
389
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "gu browser",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.13",
|
|
5
5
|
"description": "Lets the gu coding agent open, see and operate web pages in its own tabs (tab group \"gu\") with a real mouse and keyboard.",
|
|
6
6
|
"minimum_chrome_version": "116",
|
|
7
7
|
"icons": {
|
|
@@ -3,24 +3,92 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<style>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
:root {
|
|
7
|
+
--bg: #ffffff; --fg: #1d1b26; --muted: #6b6779; --line: #ece9f3; --card: #f7f5fb;
|
|
8
|
+
--accent: #7c3aed; --accent-fg: #ffffff; --ok: #1f9d5c; --stop: #dc2626; --stop-hover: #b91c1c;
|
|
9
|
+
}
|
|
10
|
+
@media (prefers-color-scheme: dark) {
|
|
11
|
+
:root { --bg: #1b1922; --fg: #eceaf3; --muted: #a29fb2; --line: #2e2b38; --card: #24212d; --accent: #a78bfa; --accent-fg: #160f2b; --ok: #3ccf86; --stop: #ef4444; --stop-hover: #f87171; }
|
|
12
|
+
}
|
|
13
|
+
* { box-sizing: border-box; }
|
|
14
|
+
body { margin: 0; width: 320px; font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; color: var(--fg); background: var(--bg); }
|
|
15
|
+
header { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
|
|
16
|
+
header img { width: 24px; height: 24px; border-radius: 6px; }
|
|
17
|
+
header h1 { flex: 1; margin: 0; font-size: 14px; font-weight: 650; }
|
|
18
|
+
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
|
|
19
|
+
.chip i { width: 8px; height: 8px; border-radius: 50%; background: #9b98a8; }
|
|
20
|
+
.chip.on i { background: var(--ok); }
|
|
21
|
+
section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
|
|
22
|
+
section:last-of-type { border-bottom: 0; }
|
|
23
|
+
h2 { margin: 0 0 8px; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
|
|
24
|
+
.muted { color: var(--muted); }
|
|
25
|
+
p { margin: 0; }
|
|
26
|
+
.activity { display: flex; gap: 10px; align-items: flex-start; }
|
|
27
|
+
.pulse { flex: none; width: 10px; height: 10px; margin-top: 4px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 var(--accent); animation: pulse 1.4s infinite; }
|
|
28
|
+
.idle .pulse { animation: none; background: #9b98a8; }
|
|
29
|
+
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(124, 58, 237, .5); } 70% { box-shadow: 0 0 0 8px rgba(124, 58, 237, 0); } 100% { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0); } }
|
|
30
|
+
.what { font-weight: 600; word-break: break-word; }
|
|
31
|
+
.where { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
|
|
32
|
+
button { flex: none; white-space: nowrap; font: inherit; font-weight: 600; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--fg); padding: 7px 12px; cursor: pointer; }
|
|
33
|
+
button:hover:not(:disabled) { border-color: var(--accent); }
|
|
34
|
+
button:disabled { opacity: .55; cursor: default; }
|
|
35
|
+
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
|
|
36
|
+
button.stop { width: 100%; margin-top: 10px; background: var(--stop); border-color: var(--stop); color: #fff; display: flex; align-items: center; justify-content: center; gap: 8px; }
|
|
37
|
+
button.stop:hover:not(:disabled) { background: var(--stop-hover); border-color: var(--stop-hover); }
|
|
38
|
+
button.stop b { width: 10px; height: 10px; background: #fff; border-radius: 2px; }
|
|
39
|
+
ul { list-style: none; margin: 0; padding: 0; }
|
|
40
|
+
li { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
|
|
41
|
+
li + li { border-top: 1px solid var(--line); }
|
|
42
|
+
li img, li .noicon { flex: none; width: 16px; height: 16px; border-radius: 3px; background: var(--card); }
|
|
43
|
+
li .t { flex: 1; min-width: 0; }
|
|
44
|
+
li .t div { display: flex; align-items: center; gap: 4px; min-width: 0; }
|
|
45
|
+
li .t div span.name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
46
|
+
li .t small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
47
|
+
li .t small { color: var(--muted); font-size: 11px; }
|
|
48
|
+
.tag { flex: none; font-size: 10px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 4px; }
|
|
49
|
+
.icon { padding: 3px 7px; font-weight: 500; font-size: 12px; }
|
|
50
|
+
.row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
|
|
51
|
+
footer { padding: 10px 14px; font-size: 12px; color: var(--muted); background: var(--card); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
52
|
+
code { font: 12px ui-monospace, Menlo, monospace; }
|
|
53
|
+
[hidden] { display: none !important; }
|
|
13
54
|
</style>
|
|
14
55
|
</head>
|
|
15
56
|
<body>
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
57
|
+
<header>
|
|
58
|
+
<img src="icons/icon32.png" alt="">
|
|
59
|
+
<h1>gu browser</h1>
|
|
60
|
+
<span id="conn" class="chip"><i></i><span id="connText">checking…</span></span>
|
|
61
|
+
</header>
|
|
62
|
+
|
|
63
|
+
<section id="now">
|
|
64
|
+
<h2>Now</h2>
|
|
65
|
+
<div id="activity" class="activity idle">
|
|
66
|
+
<span class="pulse"></span>
|
|
67
|
+
<div>
|
|
68
|
+
<p id="what" class="what">Idle</p>
|
|
69
|
+
<p id="where" class="where muted">gu opens its tabs here when its agent needs the browser.</p>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
<button id="stop" class="stop" hidden><b></b><span id="stopText">Stop gu</span></button>
|
|
73
|
+
</section>
|
|
74
|
+
|
|
75
|
+
<section id="tabsBox" hidden>
|
|
76
|
+
<h2>gu's tabs</h2>
|
|
77
|
+
<ul id="tabs"></ul>
|
|
78
|
+
</section>
|
|
79
|
+
|
|
80
|
+
<section id="thisTab">
|
|
81
|
+
<h2>This tab</h2>
|
|
82
|
+
<div class="row">
|
|
83
|
+
<p id="tabLabel" class="muted">…</p>
|
|
84
|
+
<button id="share" hidden>Let gu use it</button>
|
|
85
|
+
</div>
|
|
86
|
+
</section>
|
|
87
|
+
|
|
88
|
+
<footer>
|
|
89
|
+
<span id="hint">Your other tabs are never read or touched.</span>
|
|
90
|
+
<button id="retry" class="primary" hidden>Connect now</button>
|
|
91
|
+
</footer>
|
|
24
92
|
<script src="popup.js"></script>
|
|
25
93
|
</body>
|
|
26
94
|
</html>
|
|
@@ -1,45 +1,155 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
// The gu browser popup (GH #551): connection, what gu is doing, Stop, gu's tabs, and sharing this
|
|
2
|
+
// tab (#150). Everything comes from the background's "status" answer; it refreshes while open.
|
|
3
|
+
const $ = (id) => document.getElementById(id);
|
|
4
|
+
const send = (msg) => chrome.runtime.sendMessage(msg);
|
|
5
|
+
|
|
6
|
+
function ago(ms) {
|
|
7
|
+
const s = Math.max(0, Math.round((Date.now() - ms) / 1000));
|
|
8
|
+
if (s < 5) return "just now";
|
|
9
|
+
if (s < 60) return `${s} s ago`;
|
|
10
|
+
const m = Math.round(s / 60);
|
|
11
|
+
return m < 60 ? `${m} min ago` : `${Math.round(m / 60)} h ago`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function host(url) {
|
|
15
|
+
try {
|
|
16
|
+
return new URL(url).host || url;
|
|
17
|
+
} catch {
|
|
18
|
+
return url || "";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let stopPressed = false;
|
|
23
|
+
|
|
24
|
+
function render(s) {
|
|
25
|
+
s = s || {};
|
|
26
|
+
const on = Boolean(s.connected);
|
|
27
|
+
$("conn").className = on ? "chip on" : "chip";
|
|
28
|
+
$("connText").textContent = on ? `Connected · v${s.version}` : "Not connected";
|
|
29
|
+
$("retry").hidden = on;
|
|
30
|
+
$("hint").textContent = on
|
|
31
|
+
? "Your other tabs are never read or touched."
|
|
32
|
+
: "gu connects when its agent needs the browser. /browser in the gu terminal shows why.";
|
|
33
|
+
|
|
34
|
+
// Now: working (with what and where) or idle.
|
|
35
|
+
const tabs = s.tabs || [];
|
|
36
|
+
const working = Boolean(s.working);
|
|
37
|
+
$("activity").className = working && !s.stopping ? "activity" : "activity idle";
|
|
38
|
+
if (s.stopping) {
|
|
39
|
+
$("what").textContent = "Stopping gu…";
|
|
40
|
+
$("where").textContent = "gu ends its turn; the terminal says when it stopped.";
|
|
41
|
+
} else if (working) {
|
|
42
|
+
const cur = tabs.find((t) => t.current) || tabs[0];
|
|
43
|
+
const tabName = (id) => tabs.find((t) => t.id === id)?.title || host(tabs.find((t) => t.id === id)?.url);
|
|
44
|
+
if (s.busy) {
|
|
45
|
+
$("what").textContent = `${s.busy.text[0].toUpperCase()}${s.busy.text.slice(1)}…`;
|
|
46
|
+
$("where").textContent = cur ? `in ${cur.title || host(cur.url)}` : "";
|
|
47
|
+
} else if (s.last) {
|
|
48
|
+
$("what").textContent = `${s.last.text[0].toUpperCase()}${s.last.text.slice(1)}`;
|
|
49
|
+
$("where").textContent = `${ago(s.last.at)} · in ${tabName(s.last.tab) || "gu's tab"}`;
|
|
50
|
+
} else {
|
|
51
|
+
$("what").textContent = "Working";
|
|
52
|
+
$("where").textContent = cur ? `in ${cur.title || host(cur.url)}` : "";
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
$("what").textContent = "Idle";
|
|
56
|
+
$("where").textContent = "gu opens its tabs here when its agent needs the browser.";
|
|
57
|
+
}
|
|
58
|
+
$("stop").hidden = !(on && (working || s.stopping));
|
|
59
|
+
$("stop").disabled = Boolean(s.stopping) || stopPressed;
|
|
60
|
+
$("stopText").textContent = s.stopping || stopPressed ? "Stopping…" : "Stop gu";
|
|
61
|
+
|
|
62
|
+
// gu's tabs.
|
|
63
|
+
$("tabsBox").hidden = !tabs.length;
|
|
64
|
+
const ul = $("tabs");
|
|
65
|
+
ul.replaceChildren(...tabs.map((t) => {
|
|
66
|
+
const li = document.createElement("li");
|
|
67
|
+
const icon = document.createElement(t.favicon ? "img" : "span");
|
|
68
|
+
if (t.favicon) icon.src = t.favicon;
|
|
69
|
+
else icon.className = "noicon";
|
|
70
|
+
const txt = document.createElement("div");
|
|
71
|
+
txt.className = "t";
|
|
72
|
+
const title = document.createElement("div");
|
|
73
|
+
const name = document.createElement("span");
|
|
74
|
+
name.className = "name";
|
|
75
|
+
name.textContent = t.title || host(t.url) || "New tab";
|
|
76
|
+
title.append(name);
|
|
77
|
+
if (t.shared) {
|
|
78
|
+
const tag = document.createElement("span");
|
|
79
|
+
tag.className = "tag";
|
|
80
|
+
tag.textContent = "SHARED";
|
|
81
|
+
title.append(tag);
|
|
82
|
+
}
|
|
83
|
+
const small = document.createElement("small");
|
|
84
|
+
small.textContent = host(t.url);
|
|
85
|
+
txt.append(title, small);
|
|
86
|
+
const show = document.createElement("button");
|
|
87
|
+
show.className = "icon";
|
|
88
|
+
show.textContent = "Show";
|
|
89
|
+
show.title = "Bring this tab to the front";
|
|
90
|
+
show.onclick = async () => {
|
|
91
|
+
await chrome.tabs.update(t.id, { active: true });
|
|
92
|
+
if (t.windowId != null) await chrome.windows.update(t.windowId, { focused: true }).catch(() => {});
|
|
93
|
+
};
|
|
94
|
+
const close = document.createElement("button");
|
|
95
|
+
close.className = "icon";
|
|
96
|
+
close.textContent = t.shared ? "Unshare" : "Close";
|
|
97
|
+
close.title = t.shared ? "Take this tab back from gu (it stays open)" : "Close this tab of gu's";
|
|
98
|
+
close.onclick = async () => {
|
|
99
|
+
if (t.shared) await send({ type: "unshare", tabId: t.id });
|
|
100
|
+
else await chrome.tabs.remove(t.id).catch(() => {});
|
|
101
|
+
refresh();
|
|
102
|
+
};
|
|
103
|
+
li.append(icon, txt, show, close);
|
|
104
|
+
return li;
|
|
105
|
+
}));
|
|
12
106
|
}
|
|
13
107
|
|
|
14
|
-
function
|
|
15
|
-
|
|
108
|
+
async function refresh() {
|
|
109
|
+
render(await send({ type: "status" }).catch(() => null));
|
|
110
|
+
showThisTab();
|
|
16
111
|
}
|
|
17
112
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
113
|
+
$("stop").onclick = async () => {
|
|
114
|
+
stopPressed = true;
|
|
115
|
+
$("stop").disabled = true;
|
|
116
|
+
$("stopText").textContent = "Stopping…";
|
|
117
|
+
const r = await send({ type: "stop" }).catch(() => null);
|
|
118
|
+
if (!r || !r.ok) {
|
|
119
|
+
stopPressed = false;
|
|
120
|
+
$("where").textContent = `Could not reach gu (${(r && r.error) || "no answer"}) — press Ctrl+C in the gu terminal.`;
|
|
121
|
+
}
|
|
122
|
+
refresh();
|
|
21
123
|
};
|
|
22
|
-
check();
|
|
23
124
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const shareBtn = document.getElementById("share");
|
|
125
|
+
$("retry").onclick = () => {
|
|
126
|
+
$("connText").textContent = "Connecting…";
|
|
127
|
+
send({ type: "reconnect" }).then(() => setTimeout(refresh, 600));
|
|
128
|
+
};
|
|
29
129
|
|
|
30
|
-
|
|
130
|
+
// "Let gu use this tab" (#150): hand gu one of your own tabs; "Stop sharing" takes it back.
|
|
131
|
+
async function showThisTab() {
|
|
31
132
|
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
133
|
+
const label = $("tabLabel");
|
|
134
|
+
const btn = $("share");
|
|
135
|
+
if (!tab || !/^(https?|file):/i.test(tab.url || "")) {
|
|
136
|
+
label.textContent = "Chrome's own pages (settings, the Web Store, new tabs) can't be shared with gu.";
|
|
137
|
+
btn.hidden = true;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const { shared } = (await send({ type: "tabState", tabId: tab.id })) || {};
|
|
141
|
+
label.textContent = shared ? "gu can use this tab." : "This tab is yours — gu can't see it.";
|
|
142
|
+
btn.hidden = false;
|
|
143
|
+
btn.textContent = shared ? "Stop sharing" : "Share with gu";
|
|
144
|
+
btn.className = shared ? "" : "primary";
|
|
145
|
+
btn.onclick = async () => {
|
|
146
|
+
btn.disabled = true;
|
|
147
|
+
const r = await send({ type: shared ? "unshare" : "share", tabId: tab.id });
|
|
148
|
+
btn.disabled = false;
|
|
149
|
+
if (r && r.ok === false) label.textContent = r.error;
|
|
150
|
+
refresh();
|
|
43
151
|
};
|
|
44
152
|
}
|
|
45
|
-
|
|
153
|
+
|
|
154
|
+
refresh();
|
|
155
|
+
setInterval(refresh, 1000);
|
package/clear-state.mjs
CHANGED
|
@@ -39,12 +39,20 @@ export const STATE_ITEMS = [
|
|
|
39
39
|
{ path: "cli-token.json", group: "identity",
|
|
40
40
|
what: "the gu token (plan + computers)", cost: "asked for again at the next start (a free trial comes back with the days it had left)" },
|
|
41
41
|
{ path: "prefs.json", group: "identity", what: "CLI preferences", cost: "defaults return" },
|
|
42
|
+
// GH #552: which database Local mode chose. Left behind, the next setup skips the choice.
|
|
43
|
+
{ path: "local-db", group: "identity",
|
|
44
|
+
what: "which database Local mode uses", cost: "setup chooses again" },
|
|
42
45
|
{ path: "wizard-state.json", group: "identity",
|
|
43
46
|
what: "installer progress", cost: "the wizard starts over" },
|
|
44
47
|
|
|
45
48
|
// --- work you may actually want -----------------------------------------------------
|
|
46
49
|
{ path: "sessions", group: "work",
|
|
47
50
|
what: "per-folder conversation history and choices", cost: "every folder forgets its chat" },
|
|
51
|
+
// GH #552: Local mode's built-in database (GH #534) — a file, so the file goes; before this it
|
|
52
|
+
// survived gu clear and the "fresh" setup inherited its settings, keys and conversations.
|
|
53
|
+
{ path: "gudb", group: "work",
|
|
54
|
+
what: "the built-in database (conversations, settings, worker keys)",
|
|
55
|
+
cost: "every conversation on this machine is deleted" },
|
|
48
56
|
{ path: "workspaces.json", group: "work",
|
|
49
57
|
what: "registered workspaces", cost: "folders must be re-registered" },
|
|
50
58
|
{ path: "active-workspace.json", group: "work", what: "the active folder", cost: "-" },
|
|
@@ -142,9 +150,12 @@ export async function clearState(items) {
|
|
|
142
150
|
*
|
|
143
151
|
* "Starts from the beginning" has to mean it, or it is worse than not offering the command.
|
|
144
152
|
*/
|
|
145
|
-
export function localDatabaseItem({ apiBase }) {
|
|
153
|
+
export function localDatabaseItem({ apiBase, localDb = "" }) {
|
|
146
154
|
const local = /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\])(:|\/|$)/i.test(String(apiBase ?? ""));
|
|
147
155
|
if (!local) return null;
|
|
156
|
+
// GH #552: on the built-in database there is no MongoDB to drop — its file is the "gudb"
|
|
157
|
+
// item above and goes with the rest.
|
|
158
|
+
if (localDb === "gudb") return null;
|
|
148
159
|
return {
|
|
149
160
|
group: "work",
|
|
150
161
|
what: "the local MongoDB database (conversations, settings, worker keys)",
|
package/cli-token.mjs
CHANGED
|
@@ -732,7 +732,7 @@ export async function redeemPromo({ hostedBase, device, code, fetchImpl = fetch,
|
|
|
732
732
|
* trial (no account) or an account. Returns { ok: true, days, token } — the token already carries the
|
|
733
733
|
* extra days — or { ok: false, why, error } where error is the service's own sentence. Never throws.
|
|
734
734
|
*/
|
|
735
|
-
export async function redeemVoucher({ mode, apiBase, hostedBase, token, device, code, fetchImpl = fetch, timeoutMs = 8000 }) {
|
|
735
|
+
export async function redeemVoucher({ mode, apiBase, hostedBase, token, device, code, ageConfirmed = false, fetchImpl = fetch, timeoutMs = 8000 }) {
|
|
736
736
|
const base = String(mode === "expert" ? hostedBase : apiBase || hostedBase).replace(/\/+$/, "");
|
|
737
737
|
if (!token) return { ok: false, why: "no-token", error: "This computer has no gu token yet — restart gu to get the free trial, then try again." };
|
|
738
738
|
if (!base) return { ok: false, why: "no-api", error: "No gu service address is set on this computer." };
|
|
@@ -740,7 +740,8 @@ export async function redeemVoucher({ mode, apiBase, hostedBase, token, device,
|
|
|
740
740
|
const res = await fetchImpl(`${base}/api/billing/cli-token/voucher`, {
|
|
741
741
|
method: "POST",
|
|
742
742
|
headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
|
|
743
|
-
|
|
743
|
+
// GH #567: a gu + Gemini code is sent again with ageConfirmed once the person said they are 18 or older.
|
|
744
|
+
body: JSON.stringify({ code: String(code ?? ""), ...(device ? { device } : {}), ...(ageConfirmed ? { ageConfirmed: true } : {}) }),
|
|
744
745
|
signal: AbortSignal.timeout(timeoutMs),
|
|
745
746
|
});
|
|
746
747
|
const data = await res.json().catch(() => null);
|
|
@@ -748,7 +749,7 @@ export async function redeemVoucher({ mode, apiBase, hostedBase, token, device,
|
|
|
748
749
|
const error = typeof data?.error === "string" && data.error
|
|
749
750
|
? data.error
|
|
750
751
|
: res.status === 404 ? "This gu service does not take vouchers yet." : `The gu service answered HTTP ${res.status}.`;
|
|
751
|
-
return { ok: false, why: typeof data?.why === "string" ? data.why : `http-${res.status}`, error };
|
|
752
|
+
return { ok: false, why: typeof data?.why === "string" ? data.why : `http-${res.status}`, error, ...(Number(data?.months) ? { months: Number(data.months) } : {}) };
|
|
752
753
|
}
|
|
753
754
|
return {
|
|
754
755
|
ok: true,
|
|
@@ -756,6 +757,8 @@ export async function redeemVoucher({ mode, apiBase, hostedBase, token, device,
|
|
|
756
757
|
token: typeof data?.token === "string" ? data.token : "",
|
|
757
758
|
// #557: a free-model code carries a monthly allowance, not days.
|
|
758
759
|
...(data?.kind === "model-tokens" ? { kind: "model-tokens", centsPerMonth: Number(data.centsPerMonth ?? 0), months: Number(data.months ?? 0) } : {}),
|
|
760
|
+
// GH #567: gu + Gemini — months of the subscription; Google sets the project up, then the preset carries Gemini.
|
|
761
|
+
...(data?.kind === "gemini" ? { kind: "gemini", months: Number(data.months ?? 0), paidUntil: typeof data.paidUntil === "string" ? data.paidUntil : "" } : {}),
|
|
759
762
|
};
|
|
760
763
|
} catch (e) {
|
|
761
764
|
return { ok: false, why: "network", error: e?.name === "TimeoutError" ? "The gu service did not answer in time. Try again." : "Can't reach the gu service right now." };
|