@tiens.nguyen/gu-cli 1.0.905 → 1.0.907
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/browser-bridge.mjs +2 -1
- package/browser-chrome.mjs +5 -4
- package/browser-extension/actions.js +14 -3
- package/browser-extension/background.js +47 -11
- package/browser-extension/manifest.json +1 -1
- package/gonext_agent_chat.py +172 -9
- package/gu-cli.mjs +4 -2
- package/gu-repl.mjs +85 -36
- package/gu_browser.py +76 -3
- package/gu_mcp.py +23 -1
- package/mcp-command.mjs +4 -2
- package/mcp-config.mjs +22 -1
- package/model-doctor.mjs +78 -1
- package/package.json +1 -1
- package/skills/core/docx/SKILL.md +1 -1
- package/skills/core/docx/scripts/__pycache__/accept_changes.cpython-314.pyc +0 -0
- package/skills/core/docx/scripts/accept_changes.py +8 -6
- package/skills/core/docx/scripts/office/__pycache__/soffice.cpython-314.pyc +0 -0
- package/skills/core/docx/scripts/office/soffice.py +35 -3
- package/skills/core/pdf/SKILL.md +1 -1
- package/skills/core/pdf/scripts/convert_pdf_to_images.py +1 -0
- package/skills/core/pptx/SKILL.md +1 -1
- package/skills/core/pptx/scripts/office/__pycache__/soffice.cpython-314.pyc +0 -0
- package/skills/core/pptx/scripts/office/soffice.py +35 -3
- package/skills/core/xlsx/SKILL.md +1 -1
- package/skills/core/xlsx/scripts/__pycache__/recalc.cpython-314.pyc +0 -0
- package/skills/core/xlsx/scripts/office/__pycache__/soffice.cpython-314.pyc +0 -0
- package/skills/core/xlsx/scripts/office/soffice.py +35 -3
- package/skills/core/xlsx/scripts/recalc.py +6 -3
- package/skills.mjs +2 -1
- package/terminal-layout.mjs +23 -0
package/browser-bridge.mjs
CHANGED
|
@@ -165,7 +165,7 @@ export function startBridge({ port = DEFAULT_PORT, token = randomBytes(24).toStr
|
|
|
165
165
|
id: ext ? extId(ext.origin) : null,
|
|
166
166
|
installType: ext?.installType || null,
|
|
167
167
|
ownChrome: Boolean(own?.running),
|
|
168
|
-
refused: [...refused].filter(([, at]) => at > since).map(([id, at]) => ({ id, at })),
|
|
168
|
+
refused: [...refused].filter(([id, at]) => at > since && !(ext && id === extId(ext.origin))).map(([id, at]) => ({ id, at })),
|
|
169
169
|
pid: process.pid,
|
|
170
170
|
});
|
|
171
171
|
}
|
|
@@ -218,6 +218,7 @@ export function startBridge({ port = DEFAULT_PORT, token = randomBytes(24).toStr
|
|
|
218
218
|
}
|
|
219
219
|
if (ext) ext.socket.destroy();
|
|
220
220
|
ext = { socket, version: null, installType: null, origin };
|
|
221
|
+
refused.delete(extId(origin)); // it was turned away earlier but holds the connection now: not "refused" any more
|
|
221
222
|
log(`extension connected (${origin})`);
|
|
222
223
|
let buf = Buffer.alloc(0);
|
|
223
224
|
let parts = [];
|
package/browser-chrome.mjs
CHANGED
|
@@ -192,19 +192,19 @@ export class OwnChrome {
|
|
|
192
192
|
const pages = await this.pages();
|
|
193
193
|
const reuse = newTab ? null : pages.find((t) => t.targetId === this.current) || pages[0];
|
|
194
194
|
// A new tab starts blank and is navigated once attached, so its load events are seen.
|
|
195
|
-
const id = reuse ? reuse.targetId : (await this.send("Target.createTarget", { url: "about:blank" })).targetId;
|
|
195
|
+
const id = reuse ? reuse.targetId : (await this.send("Target.createTarget", { url: "about:blank", background: true })).targetId;
|
|
196
196
|
await this.host().attach(id);
|
|
197
197
|
this.loading.add(id);
|
|
198
198
|
await this.cdp(id, "Page.navigate", { url });
|
|
199
|
-
this.current = id;
|
|
200
|
-
|
|
199
|
+
this.current = id; // gu does not bring the tab to the front (#422)
|
|
200
|
+
(this.notes ??= []).push(reuse ? `reused gu's current tab ${id} in gu's own Chrome window (navigated it) — pass new_tab to open another`
|
|
201
|
+
: `opened NEW tab ${id} in gu's own Chrome window because ${newTab ? "new_tab was set" : "gu had no tab open yet"}`);
|
|
201
202
|
return id;
|
|
202
203
|
},
|
|
203
204
|
tabs: async () => (await this.pages()).map((t) => ({ id: t.targetId, title: t.title, url: t.url, current: t.targetId === this.current })),
|
|
204
205
|
switchTo: async (id) => {
|
|
205
206
|
if (!(await this.pages()).some((t) => t.targetId === id)) return false;
|
|
206
207
|
this.current = id;
|
|
207
|
-
await this.send("Target.activateTarget", { targetId: id }).catch(() => {});
|
|
208
208
|
return true;
|
|
209
209
|
},
|
|
210
210
|
current: async () => {
|
|
@@ -226,6 +226,7 @@ export class OwnChrome {
|
|
|
226
226
|
},
|
|
227
227
|
activate: (id) => this.send("Target.activateTarget", { targetId: id }).catch(() => {}),
|
|
228
228
|
close: (id) => this.send("Target.closeTarget", { targetId: id }),
|
|
229
|
+
takeNotes: () => (this.notes ??= []).splice(0),
|
|
229
230
|
};
|
|
230
231
|
}
|
|
231
232
|
|
|
@@ -303,7 +303,9 @@ async function after(host, tabId, extra = {}) {
|
|
|
303
303
|
const dl = dialogs.get(tabId) || [];
|
|
304
304
|
freshErrors.delete(tabId);
|
|
305
305
|
dialogs.delete(tabId);
|
|
306
|
-
|
|
306
|
+
// GH #428: why a tab was opened or adopted, so the user and the model are never left guessing.
|
|
307
|
+
const notes = host.takeNotes ? host.takeNotes() : [];
|
|
308
|
+
return { tab: tabId, url: t?.url || "", title: t?.title || "", errors: errs, dialogs: dl, notes, ...extra };
|
|
307
309
|
}
|
|
308
310
|
|
|
309
311
|
export async function runAction(cmd, host) {
|
|
@@ -314,12 +316,15 @@ export async function runAction(cmd, host) {
|
|
|
314
316
|
const id = await host.open(url, Boolean(cmd.new_tab));
|
|
315
317
|
await host.attach(id);
|
|
316
318
|
await waitLoaded(host, id);
|
|
319
|
+
if (cmd.focus) await host.activate(id); // opt-in (GH #428): show the user where gu works
|
|
317
320
|
return after(host, id);
|
|
318
321
|
}
|
|
319
322
|
if (a === "tabs") return { tabs: await host.tabs() };
|
|
323
|
+
if (a === "cleanup") return host.cleanup ? host.cleanup() : { closed: [], released: [] }; // end of turn (GH #428)
|
|
320
324
|
if (a === "switch") {
|
|
321
325
|
const id = cmd.tab;
|
|
322
326
|
if (!(await host.switchTo(id))) throw new Error(`tab ${cmd.tab} is not one of gu's tabs — see action "tabs"`);
|
|
327
|
+
if (cmd.focus) await host.activate(Number.isNaN(Number(id)) ? id : Number(id));
|
|
323
328
|
return after(host, id);
|
|
324
329
|
}
|
|
325
330
|
const id = await host.current();
|
|
@@ -333,10 +338,16 @@ export async function runAction(cmd, host) {
|
|
|
333
338
|
case "read":
|
|
334
339
|
return { ...(await evaluate(host, id, `(${readPage})(${JSON.stringify({ maxText: cmd.max_text || 6000 })})`)), ...(await after(host, id)) };
|
|
335
340
|
case "screenshot": {
|
|
336
|
-
|
|
341
|
+
// #422: try the background tab first; only when that fails or stalls is the TAB (never the
|
|
342
|
+
// window) brought forward, because some Chrome versions do not paint a hidden tab.
|
|
343
|
+
const grab = () => host.cdp(id, "Page.captureScreenshot", { format: "jpeg", quality: 80 });
|
|
344
|
+
let shot = await Promise.race([grab().catch(() => null), sleep(cmd.shot_wait_ms || 4000).then(() => null)]);
|
|
345
|
+
if (!shot) {
|
|
346
|
+
await host.activate(id);
|
|
347
|
+
shot = await grab();
|
|
348
|
+
}
|
|
337
349
|
const m = await host.cdp(id, "Page.getLayoutMetrics");
|
|
338
350
|
const vp = m.cssVisualViewport || m.visualViewport || {};
|
|
339
|
-
const shot = await host.cdp(id, "Page.captureScreenshot", { format: "jpeg", quality: 80 });
|
|
340
351
|
return { ...(await after(host, id)), image: shot.data, mime: "image/jpeg", width: Math.round(vp.clientWidth), height: Math.round(vp.clientHeight) };
|
|
341
352
|
}
|
|
342
353
|
case "click":
|
|
@@ -19,6 +19,7 @@ let ws = null;
|
|
|
19
19
|
let connecting = false; // set before the first await: startup fires connect() several times at once
|
|
20
20
|
let pingTimer = null;
|
|
21
21
|
const attached = new Set();
|
|
22
|
+
const notes = []; // why gu opened or adopted a tab — handed to the next command's answer (GH #428)
|
|
22
23
|
|
|
23
24
|
// ── connection ──────────────────────────────────────────────────────────────────────────────
|
|
24
25
|
async function bridgePort() {
|
|
@@ -94,7 +95,8 @@ chrome.runtime.onMessage.addListener((msg, _sender, reply) => {
|
|
|
94
95
|
} else if (msg?.type === "share") {
|
|
95
96
|
// "Let gu use this tab" (#150): the user hands gu a tab of their own.
|
|
96
97
|
addToGroup(msg.tabId)
|
|
97
|
-
.then(() =>
|
|
98
|
+
.then(() => state())
|
|
99
|
+
.then((s) => saveState({ current: msg.tabId, shared: s.shared.includes(msg.tabId) ? s.shared : [...s.shared, msg.tabId] }))
|
|
98
100
|
.then(() => reply({ ok: true }), (e) => reply({ ok: false, error: String(e?.message || e) }));
|
|
99
101
|
return true;
|
|
100
102
|
} else if (msg?.type === "unshare") {
|
|
@@ -124,8 +126,8 @@ async function onCommand(sock, data) {
|
|
|
124
126
|
|
|
125
127
|
// ── gu's tabs ───────────────────────────────────────────────────────────────────────────────
|
|
126
128
|
async function state() {
|
|
127
|
-
const s = await chrome.storage.session.get(["tabs", "current", "group"]);
|
|
128
|
-
return { tabs: s.tabs || [], current: s.current ?? null, group: s.group ?? null };
|
|
129
|
+
const s = await chrome.storage.session.get(["tabs", "current", "group", "shared"]);
|
|
130
|
+
return { tabs: s.tabs || [], current: s.current ?? null, group: s.group ?? null, shared: s.shared || [] };
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
async function saveState(patch) {
|
|
@@ -162,7 +164,7 @@ async function addToGroup(tabId) {
|
|
|
162
164
|
// "Stop sharing": the tab leaves the group, gu lets go of it, and never touches it again.
|
|
163
165
|
async function unshare(tabId) {
|
|
164
166
|
const s = await state();
|
|
165
|
-
await saveState({ tabs: s.tabs.filter((t) => t !== tabId), current: s.current === tabId ? null : s.current });
|
|
167
|
+
await saveState({ tabs: s.tabs.filter((t) => t !== tabId), shared: s.shared.filter((t) => t !== tabId), current: s.current === tabId ? null : s.current });
|
|
166
168
|
await chrome.tabs.ungroup(tabId).catch(() => {});
|
|
167
169
|
if (attached.has(tabId)) await chrome.debugger.detach({ tabId }).catch(() => {});
|
|
168
170
|
attached.delete(tabId);
|
|
@@ -175,6 +177,7 @@ chrome.tabs.onCreated.addListener(async (tab) => {
|
|
|
175
177
|
if (tab.openerTabId != null && s.tabs.includes(tab.openerTabId)) {
|
|
176
178
|
await addToGroup(tab.id).catch(() => {});
|
|
177
179
|
await saveState({ current: tab.id });
|
|
180
|
+
notes.push(`tab ${tab.id} was opened by gu's tab ${tab.openerTabId} (link or popup) — added to gu's group and now gu's current tab`);
|
|
178
181
|
}
|
|
179
182
|
});
|
|
180
183
|
|
|
@@ -209,24 +212,30 @@ const host = {
|
|
|
209
212
|
const tabs = await liveTabs();
|
|
210
213
|
const s = await state();
|
|
211
214
|
let tab = newTab ? null : tabs.find((t) => t.id === s.current) || tabs[tabs.length - 1];
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
+
// #422: never bring the tab or the window to the front — gu drives it over the debugger, which
|
|
216
|
+
// works on a background tab, so the user's own tab and window keep the focus.
|
|
217
|
+
if (tab) {
|
|
218
|
+
tab = await chrome.tabs.update(tab.id, { url });
|
|
219
|
+
notes.push(`reused gu's current tab ${tab.id} (navigated it) — pass new_tab to open another`);
|
|
220
|
+
} else {
|
|
221
|
+
tab = await chrome.tabs.create({ url, active: false });
|
|
215
222
|
await addToGroup(tab.id);
|
|
223
|
+
notes.push(`opened NEW tab ${tab.id} in the "gu" group because ${newTab ? "new_tab was set" : "gu had no tab open yet"}`);
|
|
216
224
|
}
|
|
217
225
|
await saveState({ current: tab.id });
|
|
218
|
-
await chrome.windows.update(tab.windowId, { focused: true }).catch(() => {});
|
|
219
226
|
return tab.id;
|
|
220
227
|
},
|
|
221
228
|
async tabs() {
|
|
222
229
|
const s = await state();
|
|
223
|
-
|
|
230
|
+
const live = await liveTabs();
|
|
231
|
+
// Same rule as current(): when the stored current tab is gone, gu acts on the last tab, so mark that one.
|
|
232
|
+
const curId = (live.find((t) => t.id === s.current) || live[live.length - 1] || {}).id;
|
|
233
|
+
return live.map((t) => ({ id: t.id, title: t.title, url: t.url, current: t.id === curId, shared: s.shared.includes(t.id) }));
|
|
224
234
|
},
|
|
225
235
|
async switchTo(tabId) {
|
|
226
236
|
const id = Number(tabId);
|
|
227
237
|
if (!(await liveTabs()).some((t) => t.id === id)) return false;
|
|
228
|
-
await
|
|
229
|
-
await saveState({ current: id });
|
|
238
|
+
await saveState({ current: id }); // gu's current tab only — the user's visible tab is left alone (#422)
|
|
230
239
|
return true;
|
|
231
240
|
},
|
|
232
241
|
async current() {
|
|
@@ -245,6 +254,33 @@ const host = {
|
|
|
245
254
|
async close(tabId) {
|
|
246
255
|
await chrome.tabs.remove(tabId);
|
|
247
256
|
},
|
|
257
|
+
takeNotes() {
|
|
258
|
+
return notes.splice(0);
|
|
259
|
+
},
|
|
260
|
+
// End of a turn (GH #428): close the tabs gu opened; a tab the user shared is only let go of
|
|
261
|
+
// (taken out of the group, debugger detached) and stays open.
|
|
262
|
+
async cleanup() {
|
|
263
|
+
const s = await state();
|
|
264
|
+
const closed = [];
|
|
265
|
+
const released = [];
|
|
266
|
+
for (const id of s.tabs) {
|
|
267
|
+
if (s.shared.includes(id)) {
|
|
268
|
+
await unshare(id).catch(() => {});
|
|
269
|
+
released.push(id);
|
|
270
|
+
} else {
|
|
271
|
+
try {
|
|
272
|
+
await chrome.tabs.remove(id);
|
|
273
|
+
closed.push(id);
|
|
274
|
+
} catch {
|
|
275
|
+
/* already closed */
|
|
276
|
+
}
|
|
277
|
+
attached.delete(id);
|
|
278
|
+
forgetTab(id);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
await saveState({ tabs: [], shared: [], current: null, group: null });
|
|
282
|
+
return { closed, released };
|
|
283
|
+
},
|
|
248
284
|
};
|
|
249
285
|
|
|
250
286
|
async function run(cmd) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "gu browser",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.9",
|
|
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": {
|
package/gonext_agent_chat.py
CHANGED
|
@@ -5076,6 +5076,66 @@ def _dsml_to_code_block(text):
|
|
|
5076
5076
|
return (prose + "\n" if prose else "") + "<code>\n" + body + "\n</code>"
|
|
5077
5077
|
|
|
5078
5078
|
|
|
5079
|
+
# DeepSeek DSML calls to ANY tool (issue #420). Seen live: a DSML invoke name="python_interpreter"
|
|
5080
|
+
# with a DSML parameter name="content" string="true" holding plain Python. The #119 reading only
|
|
5081
|
+
# knew name="code", so this reached the user as the final answer and nothing ran. A python /
|
|
5082
|
+
# code invoke IS the code; any other tool becomes print(tool(k=v)).
|
|
5083
|
+
_DSML_T = r"<[^<>\n]{0,8}DSML[^<>\n]{0,8}"
|
|
5084
|
+
_DSML_CLOSE_T = r"</[^<>\n]{0,8}DSML[^<>\n]{0,8}"
|
|
5085
|
+
_DSML_INVOKE = re.compile(_DSML_T + r"invoke\s+name\s*=\s*[\x22\x27]([A-Za-z_]\w*)[\x22\x27]\s*>")
|
|
5086
|
+
_DSML_PARAM = re.compile(
|
|
5087
|
+
_DSML_T + r"parameter\s+name\s*=\s*[\x22\x27]([A-Za-z_]\w*)[\x22\x27]"
|
|
5088
|
+
r"(?:\s+string\s*=\s*[\x22\x27](true|false)[\x22\x27])?\s*>([\s\S]*?)"
|
|
5089
|
+
r"(?:" + _DSML_CLOSE_T + r"parameter\s*>|" + _DSML_CLOSE_T + r"invoke\s*>|" + _DSML_CLOSE_T
|
|
5090
|
+
+ r"calls\s*>|(?=" + _DSML_T + r"parameter\b)|(?=" + _DSML_T + r"invoke\b)|$)")
|
|
5091
|
+
_DSML_CODE_TOOLS = {"python_interpreter", "code", "python", "run_python"}
|
|
5092
|
+
_DSML_BLOCK = re.compile(_DSML_T + r"calls\s*>[\s\S]*?(?:" + _DSML_CLOSE_T + r"calls\s*>|$)")
|
|
5093
|
+
_DSML_STRAY = re.compile(r"</?[^<>\n]{0,8}DSML[^<>]*>")
|
|
5094
|
+
|
|
5095
|
+
|
|
5096
|
+
def _dsml_calls_to_code_block(text):
|
|
5097
|
+
"""Rewrite DSML invoke/parameter calls of any tool into a code block, or return the text
|
|
5098
|
+
unchanged (no code tag already, and the result must COMPILE)."""
|
|
5099
|
+
if not text or "DSML" not in text or re.search(r"<\s*/?\s*code\b", text, re.I):
|
|
5100
|
+
return text
|
|
5101
|
+
invokes = list(_DSML_INVOKE.finditer(text))
|
|
5102
|
+
if not invokes:
|
|
5103
|
+
return text
|
|
5104
|
+
parts = []
|
|
5105
|
+
for i, m in enumerate(invokes):
|
|
5106
|
+
seg = text[m.end(): invokes[i + 1].start() if i + 1 < len(invokes) else len(text)]
|
|
5107
|
+
params = [(pm.group(1), pm.group(2), pm.group(3)) for pm in _DSML_PARAM.finditer(seg)]
|
|
5108
|
+
name = m.group(1)
|
|
5109
|
+
if name in _DSML_CODE_TOOLS:
|
|
5110
|
+
if not params or not params[0][2].strip():
|
|
5111
|
+
return text
|
|
5112
|
+
parts.append(params[0][2].strip("\n"))
|
|
5113
|
+
else:
|
|
5114
|
+
args = []
|
|
5115
|
+
for k, flag, val in params:
|
|
5116
|
+
val = val.strip("\n")
|
|
5117
|
+
lit = repr(val)
|
|
5118
|
+
if flag == "false":
|
|
5119
|
+
if val in _TC_JSON_WORDS:
|
|
5120
|
+
lit = _TC_JSON_WORDS[val]
|
|
5121
|
+
else:
|
|
5122
|
+
try:
|
|
5123
|
+
json.loads(val)
|
|
5124
|
+
lit = val
|
|
5125
|
+
except Exception: # noqa: BLE001
|
|
5126
|
+
lit = repr(val)
|
|
5127
|
+
args.append(k + "=" + lit)
|
|
5128
|
+
parts.append("print(" + name + "(" + ", ".join(args) + "))")
|
|
5129
|
+
body = "\n".join(parts)
|
|
5130
|
+
try:
|
|
5131
|
+
compile(body, "<gu-code>", "exec")
|
|
5132
|
+
except Exception: # noqa: BLE001
|
|
5133
|
+
return text
|
|
5134
|
+
first = _DSML_ANY.search(text)
|
|
5135
|
+
prose = text[:first.start()].rstrip() if first else ""
|
|
5136
|
+
return (prose + "\n" if prose else "") + "<" "code>\n" + body + "\n</" "code>"
|
|
5137
|
+
|
|
5138
|
+
|
|
5079
5139
|
# DeepSeek plain tool-call markup (issue #133). Besides the DSML form above, DeepSeek-family
|
|
5080
5140
|
# models answer with <tool_calls><invoke name="X"><parameter name="k" string="true">v</parameter>
|
|
5081
5141
|
# </invoke></tool_calls>. That matched nothing, so it reached the user as the FINAL answer (an
|
|
@@ -5091,6 +5151,9 @@ _TC_JSON_WORDS = {"true": "True", "false": "False", "null": "None"}
|
|
|
5091
5151
|
|
|
5092
5152
|
def _strip_toolcall_markup(text):
|
|
5093
5153
|
"""Remove tool_calls/invoke/parameter markup from text that is shown to the user."""
|
|
5154
|
+
if text and "DSML" in text:
|
|
5155
|
+
# DSML calls (#420): drop the whole calls block (its parameters hold code, not prose).
|
|
5156
|
+
text = _DSML_STRAY.sub("", _DSML_BLOCK.sub("", text)).strip()
|
|
5094
5157
|
if not text or ("<tool_calls" not in text and "<invoke" not in text and "<parameter" not in text):
|
|
5095
5158
|
return text
|
|
5096
5159
|
return _TC_STRAY.sub("", _TC_BLOCK.sub("", text)).strip()
|
|
@@ -5196,6 +5259,10 @@ def _canonicalise_code_reply(text):
|
|
|
5196
5259
|
if _dsml != text:
|
|
5197
5260
|
_log("DSML tool-call markup converted to a code block (#119)")
|
|
5198
5261
|
return _dsml
|
|
5262
|
+
_dsml2 = _dsml_calls_to_code_block(text)
|
|
5263
|
+
if _dsml2 != text:
|
|
5264
|
+
_log("DSML tool-call (any tool) converted to a code block (#420)")
|
|
5265
|
+
return _dsml2
|
|
5199
5266
|
_tc = _toolcalls_to_code_block(text)
|
|
5200
5267
|
if _tc != text:
|
|
5201
5268
|
_log("tool_calls/invoke markup converted to a code block (#133)")
|
|
@@ -8308,6 +8375,7 @@ def _ws_shell_command_risk(scan, denyset, wd="", allowset=None, roots=None):
|
|
|
8308
8375
|
for c in every:
|
|
8309
8376
|
here = cwds.get(id(c), wd)
|
|
8310
8377
|
if (_WS_DESTRUCTIVE_RE.search(" ".join(c["argv"]))
|
|
8378
|
+
and not _ws_readonly_argv(c["argv"])
|
|
8311
8379
|
and not _agent_created_owns_delete(c["argv"], wd)
|
|
8312
8380
|
and not _ws_delete_inside_only(c["argv"], here, roots)):
|
|
8313
8381
|
return (None, None, "a destructive command (deletes files / wipes disk / powers off)")
|
|
@@ -9150,6 +9218,55 @@ _WS_DESTRUCTIVE_RE = re.compile(
|
|
|
9150
9218
|
)
|
|
9151
9219
|
|
|
9152
9220
|
|
|
9221
|
+
# READ-ONLY COMMANDS NEVER ASK (GH: "cd / ls still ask to allow"). cd, ls, cat, grep, git status …
|
|
9222
|
+
# change nothing, so neither the "accept edits is off" blanket question nor the destructive-word
|
|
9223
|
+
# regex (which matched ARGUMENTS such as `ls dd`, `cat reboot.md`, `grep shutdown`) applies to a
|
|
9224
|
+
# line made only of them. A redirect to a file, `sed -i`, `find -delete`, `env x` etc. are not here.
|
|
9225
|
+
_WS_READONLY_CMDS = {
|
|
9226
|
+
"cd", "ls", "pwd", "cat", "head", "tail", "wc", "echo", "printf", "which", "type", "file",
|
|
9227
|
+
"stat", "du", "df", "tree", "grep", "egrep", "fgrep", "rg", "basename", "dirname", "realpath",
|
|
9228
|
+
"readlink", "whoami", "date", "uname", "cut", "diff", "test", "[", "true",
|
|
9229
|
+
"false", "id", "hostname", "nl", "less", "more", "tr", "column", "jq", "lsof", "ps",
|
|
9230
|
+
}
|
|
9231
|
+
_WS_READONLY_GIT = {"status", "log", "diff", "show", "rev-parse", "ls-files", "blame",
|
|
9232
|
+
"describe", "shortlog", "ls-remote"}
|
|
9233
|
+
|
|
9234
|
+
|
|
9235
|
+
def _ws_readonly_argv(argv):
|
|
9236
|
+
"""True when this one simple command only reads."""
|
|
9237
|
+
if not argv:
|
|
9238
|
+
return False
|
|
9239
|
+
r = os.path.basename(argv[0])
|
|
9240
|
+
if r in _WS_READONLY_CMDS:
|
|
9241
|
+
return True
|
|
9242
|
+
if r == "git":
|
|
9243
|
+
rest = [x for x in argv[1:] if not x.startswith("-")]
|
|
9244
|
+
return bool(rest) and rest[0] in _WS_READONLY_GIT and "--set" not in argv \
|
|
9245
|
+
and not any(x.startswith("--output") for x in argv)
|
|
9246
|
+
return False
|
|
9247
|
+
|
|
9248
|
+
|
|
9249
|
+
def _ws_shell_all_readonly(scan):
|
|
9250
|
+
"""True when EVERY simple command in a shell line (inside $( ) too) only reads and nothing
|
|
9251
|
+
is redirected into a file (2>/dev/null and 2>&1 are fine)."""
|
|
9252
|
+
try:
|
|
9253
|
+
if not scan or scan.get("error"):
|
|
9254
|
+
return False
|
|
9255
|
+
top, inner = _shell_all_commands(scan)
|
|
9256
|
+
every = top + inner
|
|
9257
|
+
if not every:
|
|
9258
|
+
return False
|
|
9259
|
+
for c in every:
|
|
9260
|
+
if not _ws_readonly_argv(c["argv"]):
|
|
9261
|
+
return False
|
|
9262
|
+
for _o, tgt in c["redirects"]:
|
|
9263
|
+
if tgt and tgt != "/dev/null" and not tgt.startswith("&"):
|
|
9264
|
+
return False
|
|
9265
|
+
return True
|
|
9266
|
+
except Exception: # noqa: BLE001
|
|
9267
|
+
return False
|
|
9268
|
+
|
|
9269
|
+
|
|
9153
9270
|
# A DELETE OUTSIDE THE PROJECT IS THE USER'S CALL (runaway fix, 09-25). The destructive pattern
|
|
9154
9271
|
# above only knows `rm -r` / `rm -f`, so `rm a.img b.img` sailed through: an unattended agent,
|
|
9155
9272
|
# short of disk space, deleted two OTHER emulators' userdata-qemu.img in ~/.android/avd — files
|
|
@@ -9457,7 +9574,8 @@ def _ws_command_risk(command, argv, denyset, wd=""):
|
|
|
9457
9574
|
outside = _ws_delete_outside_reason(argv, wd)
|
|
9458
9575
|
if outside:
|
|
9459
9576
|
return (outside, outside)
|
|
9460
|
-
if (_WS_DESTRUCTIVE_RE.search(cmd) and not
|
|
9577
|
+
if (_WS_DESTRUCTIVE_RE.search(cmd) and not _ws_readonly_argv(argv)
|
|
9578
|
+
and not _agent_created_owns_delete(argv, wd)
|
|
9461
9579
|
and not _ws_delete_inside_only(argv, wd)):
|
|
9462
9580
|
return (None, "a destructive command (deletes files / wipes disk / powers off)")
|
|
9463
9581
|
return (None, None)
|
|
@@ -10519,6 +10637,23 @@ def _ws_scrubbed_env() -> dict:
|
|
|
10519
10637
|
# PowerShell finds its own modules (Microsoft.PowerShell.*) through it (#374).
|
|
10520
10638
|
"PSModulePath")
|
|
10521
10639
|
env = {k: os.environ[k] for k in keep if k in os.environ}
|
|
10640
|
+
# gu's own Python environment (~/.gonext/venv) FIRST on PATH: the document skills (xlsx, pptx, docx, pdf) are run as
|
|
10641
|
+
# `python scripts/...` and their libraries were installed there by `gu-cli deps`. Without this a bare `python` is the
|
|
10642
|
+
# system one (on Windows 11 often the Microsoft Store stub) and every import fails.
|
|
10643
|
+
try:
|
|
10644
|
+
venv_bin = os.path.join(os.path.expanduser("~"), ".gonext", "venv", "Scripts" if os.name == "nt" else "bin")
|
|
10645
|
+
if os.path.isdir(venv_bin):
|
|
10646
|
+
env["PATH"] = venv_bin + os.pathsep + env.get("PATH", "")
|
|
10647
|
+
env["VIRTUAL_ENV"] = os.path.dirname(venv_bin)
|
|
10648
|
+
except Exception:
|
|
10649
|
+
pass
|
|
10650
|
+
# The docx / pptx skills `require('docx')` / `require('pptxgenjs')`; `gu-cli deps` installs them here.
|
|
10651
|
+
try:
|
|
10652
|
+
node_libs = os.path.join(os.path.expanduser("~"), ".gonext", "node-libs", "node_modules")
|
|
10653
|
+
if os.path.isdir(node_libs):
|
|
10654
|
+
env["NODE_PATH"] = node_libs + (os.pathsep + env["NODE_PATH"] if env.get("NODE_PATH") else "")
|
|
10655
|
+
except Exception:
|
|
10656
|
+
pass
|
|
10522
10657
|
# CI=1 makes watch-mode test runners (CRA's `npm test`, jest --watch) run ONCE and
|
|
10523
10658
|
# exit instead of sitting in interactive watch mode until the timeout kills them.
|
|
10524
10659
|
env["CI"] = "1"
|
|
@@ -16087,7 +16222,9 @@ def run_agent_chat(cfg):
|
|
|
16087
16222
|
# the FLOOR, not the whole policy: sudo and rm -rf ask either way, and turning
|
|
16088
16223
|
# the toggle off raises the bar to every command. Off is the cautious setting,
|
|
16089
16224
|
# so it may only ever add questions — never remove one.
|
|
16090
|
-
|
|
16225
|
+
_ro_line = (not _ps) and ((_use_shell and _ws_shell_all_readonly(_scan))
|
|
16226
|
+
or (not _use_shell and _ws_readonly_argv(argv)))
|
|
16227
|
+
if not _ask_reason and not _accept_edits and not _ro_line:
|
|
16091
16228
|
# gu-repl.mjs approvalPrompt matches this prefix to offer "Yes for all later ones" (#200)
|
|
16092
16229
|
_ask_reason = "accept edits is off, so every command is confirmed first"
|
|
16093
16230
|
# ELEVATION: find out what we are ALLOWED to do before asking, so the question
|
|
@@ -16116,7 +16253,7 @@ def run_agent_chat(cfg):
|
|
|
16116
16253
|
and _cmd_allowed_in(wd or _WS_ACTIVE or _default_ws_root())):
|
|
16117
16254
|
# accept-edits OFF still confirms every command, so only the destructive
|
|
16118
16255
|
# question is dropped, not that one.
|
|
16119
|
-
_ask_reason = None if _accept_edits else (
|
|
16256
|
+
_ask_reason = None if (_accept_edits or _ro_line) else (
|
|
16120
16257
|
"accept edits is off, so every command is confirmed first")
|
|
16121
16258
|
if _ask_reason:
|
|
16122
16259
|
if _priv and _facts:
|
|
@@ -16742,7 +16879,7 @@ def run_agent_chat(cfg):
|
|
|
16742
16879
|
def browser(action: str, url: str = "", ref: int = 0, x: int = -1, y: int = -1,
|
|
16743
16880
|
text: str = "", clear: bool = False, submit: bool = False,
|
|
16744
16881
|
direction: str = "", amount: int = 0, seconds: int = 0, tab: str = "",
|
|
16745
|
-
new_tab: bool = False) -> str:
|
|
16882
|
+
new_tab: bool = False, focus: bool = False) -> str:
|
|
16746
16883
|
"""Use a REAL Chrome browser like a person does — open a page, see it, click with the mouse, type with the keyboard — to test a UI flow, check a page renders, fill a form or click through an app. The first call asks the user's permission. It uses the user's Chrome through the gu extension when that is installed, otherwise gu's own Chrome window (a separate profile: not logged in to the user's accounts). Loop: open → read (or screenshot) → click / type → read again to check what happened. Only gu's own tabs, and tabs the user shared, are used. If the answer starts BROWSER NOT AVAILABLE, stop and tell the user (the answer says what to do).
|
|
16747
16884
|
|
|
16748
16885
|
Args:
|
|
@@ -16759,6 +16896,7 @@ def run_agent_chat(cfg):
|
|
|
16759
16896
|
seconds: wait only — 1 to 30
|
|
16760
16897
|
tab: switch only — a tab id from tabs (a number, or an id like "8F3A…" in gu's own window)
|
|
16761
16898
|
new_tab: open only — open in a new tab instead of the current gu tab
|
|
16899
|
+
focus: open / switch only — also bring that tab to the front so the user can see where gu works (off by default: the user's own tab keeps the focus)
|
|
16762
16900
|
"""
|
|
16763
16901
|
import gu_browser as _gb
|
|
16764
16902
|
a = (action or "").strip().lower().replace(" ", "_").replace("-", "_")
|
|
@@ -16777,7 +16915,7 @@ def run_agent_chat(cfg):
|
|
|
16777
16915
|
cmd["x"], cmd["y"] = float(x), float(y)
|
|
16778
16916
|
if text:
|
|
16779
16917
|
cmd["text"] = str(text)
|
|
16780
|
-
for k, v in (("clear", clear), ("submit", submit), ("new_tab", new_tab)):
|
|
16918
|
+
for k, v in (("clear", clear), ("submit", submit), ("new_tab", new_tab), ("focus", focus)):
|
|
16781
16919
|
if v:
|
|
16782
16920
|
cmd[k] = True
|
|
16783
16921
|
if direction:
|
|
@@ -16805,8 +16943,9 @@ def run_agent_chat(cfg):
|
|
|
16805
16943
|
_browser_consent["ext_checked"] = True
|
|
16806
16944
|
_ext_ok, _browser_consent["ext_note"] = _gb.ensure_extension(
|
|
16807
16945
|
log=_log, emit=lambda t: _emit({"type": "step", "text": t}))
|
|
16946
|
+
# GH #428: GU_BROWSER_FALLBACK=off stops gu from silently using its own Chrome window.
|
|
16808
16947
|
ok, res, not_connected = _gb.command(
|
|
16809
|
-
cmd, log=_log, own=
|
|
16948
|
+
cmd, log=_log, own=_gb.own_allowed(),
|
|
16810
16949
|
on_wait=lambda: _emit({"type": "step", "text": "Waiting for Chrome to connect…"}))
|
|
16811
16950
|
where = res.pop("_backend", "") if ok and isinstance(res, dict) else ""
|
|
16812
16951
|
if where and where != _browser_consent["where"]:
|
|
@@ -16829,9 +16968,23 @@ def run_agent_chat(cfg):
|
|
|
16829
16968
|
+ _gb.format_result("read", res))
|
|
16830
16969
|
else:
|
|
16831
16970
|
msg = _gb.format_result(a, res)
|
|
16971
|
+
if a == "tabs":
|
|
16972
|
+
_pl = _gb.profile_line() # GH #428: which Chrome profile/extension gu is using
|
|
16973
|
+
if _pl:
|
|
16974
|
+
msg += "\n" + _pl
|
|
16975
|
+
if a in ("open", "click", "double_click", "right_click", "type", "key", "back", "reload"):
|
|
16976
|
+
# GH #421: show the page after an action, so the model needs no extra `read` step
|
|
16977
|
+
try:
|
|
16978
|
+
ok2, res2, _nc2 = _gb.command({"action": "read"}, log=_log, own=_gb.own_allowed())
|
|
16979
|
+
if ok2 and isinstance(res2, dict):
|
|
16980
|
+
res2.pop("_backend", None)
|
|
16981
|
+
msg = msg.replace("\n(read or screenshot to see the page now)", "") \
|
|
16982
|
+
+ "\n--- the page now (no need to read again) ---\n" + _gb.format_read(res2)
|
|
16983
|
+
except Exception: # noqa: BLE001
|
|
16984
|
+
pass
|
|
16832
16985
|
if ok and where == "chrome" and a == "open":
|
|
16833
|
-
msg = ("(gu's own Chrome window — a separate
|
|
16834
|
-
"accounts.)\n" + msg)
|
|
16986
|
+
msg = ("(NO gu extension is connected, so this is gu's own Chrome window — a separate "
|
|
16987
|
+
"profile, NOT signed in to the user's accounts. Say so if it matters to the task.)\n" + msg)
|
|
16835
16988
|
if ok and where == "chrome" and _browser_consent.get("ext_note"):
|
|
16836
16989
|
msg = _browser_consent.pop("ext_note") + "\n" + msg
|
|
16837
16990
|
except Exception as ex: # noqa: BLE001
|
|
@@ -16968,7 +17121,8 @@ def run_agent_chat(cfg):
|
|
|
16968
17121
|
every call: an "Always allow" answered a moment ago was written there."""
|
|
16969
17122
|
allow, deny = _mcp_mod.read_rules(_mcp_cfg.get("configPath"),
|
|
16970
17123
|
_mcp_cfg.get("allow") or [], _mcp_cfg.get("deny") or [])
|
|
16971
|
-
|
|
17124
|
+
_ask = _mcp_mod.read_ask(_mcp_cfg.get("configPath"), _mcp_cfg.get("ask") or [])
|
|
17125
|
+
verdict = _mcp_mod.decide(allow, deny, server, tool_name, _ask)
|
|
16972
17126
|
if verdict == "deny":
|
|
16973
17127
|
return False, (f"MCP tool {server}/{tool_name} is blocked by a deny rule in "
|
|
16974
17128
|
"~/.gonext/mcp.json. Do not call it again; carry on without it.")
|
|
@@ -17197,6 +17351,15 @@ def run_agent_chat(cfg):
|
|
|
17197
17351
|
or _fallback_recap(_turn_steps, _last_obs.get("text"))
|
|
17198
17352
|
or "[No result]")
|
|
17199
17353
|
_log(f"done (deterministic, no summarizer call): {len(final_text)} chars")
|
|
17354
|
+
# GH #428: close the Chrome tabs gu opened this turn (shared tabs are only let go of).
|
|
17355
|
+
try:
|
|
17356
|
+
if _browser_consent.get("ok"):
|
|
17357
|
+
import gu_browser as _gb_end
|
|
17358
|
+
_ct = _gb_end.cleanup(log=_log)
|
|
17359
|
+
if _ct:
|
|
17360
|
+
_log(f"browser cleanup: {_ct}")
|
|
17361
|
+
except Exception as _ce: # noqa: BLE001
|
|
17362
|
+
_log(f"browser cleanup skipped: {type(_ce).__name__}: {_ce}")
|
|
17200
17363
|
_emit({"type": "final", "text": final_text})
|
|
17201
17364
|
# onTurnEnd (task #270): after the answer is out, so a slow hook never delays it.
|
|
17202
17365
|
if _hooks and _hooks.has("onTurnEnd"):
|
package/gu-cli.mjs
CHANGED
|
@@ -126,7 +126,7 @@ Usage:
|
|
|
126
126
|
gu-cli stop [--models] # stop the daemon (--models: the model servers too)
|
|
127
127
|
gu-cli logs [--lines N] [-f] # tail the background daemon log
|
|
128
128
|
gu-cli logs <port|pid|chat|embed> [-f] # tail a MODEL server's log (e.g. logs 8090 -f)
|
|
129
|
-
gu-cli deps # install the agent's Python packages (smolagents + openai)
|
|
129
|
+
gu-cli deps # install the agent's Python packages (smolagents + openai) and the document skills' libraries
|
|
130
130
|
gu-cli doctor [--client] # set up models here (--client: agent deps only,
|
|
131
131
|
# models stay on another machine)
|
|
132
132
|
gu-cli api <start|stop|restart|status|upgrade> # the LOCAL API (Local/Client Expert only);
|
|
@@ -1832,9 +1832,11 @@ if (args[0] === "deps") {
|
|
|
1832
1832
|
return typed === "" ? defYes : /^y(es)?$/.test(typed);
|
|
1833
1833
|
},
|
|
1834
1834
|
modelHost: false,
|
|
1835
|
-
agreed: ["agentLibs"],
|
|
1835
|
+
agreed: ["agentLibs", "skillsLibs"],
|
|
1836
|
+
skillsPack: true,
|
|
1836
1837
|
});
|
|
1837
1838
|
const ok = out.agentLibs === "installed" || out.agentLibs === "present";
|
|
1839
|
+
if (ok && out.skillsLibs === "failed") console.log("\n ! some of the document skills' Python libraries did not install — see " + md.PIP_LOG_FILE);
|
|
1838
1840
|
console.log(ok ? "\n ✓ the agent framework is ready." : "\n ✗ the agent framework is not installed — see the message above and " + md.PIP_LOG_FILE);
|
|
1839
1841
|
process.exit(ok ? 0 : 1);
|
|
1840
1842
|
}
|