@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
package/step-group.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isSoftFailCommand } from "./terminal-layout.mjs";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* A TURN'S LOOK-UPS AS ONE LINE (task #326) — pure helpers; gu-repl.mjs does the drawing.
|
|
3
5
|
*
|
|
@@ -10,7 +12,8 @@
|
|
|
10
12
|
*
|
|
11
13
|
* WHAT IS GROUPED: a neutral step of the shape "Label → detail" — the agent telling us what it
|
|
12
14
|
* looked at. NOT grouped, because each is something the user must be able to see at a glance:
|
|
13
|
-
* a failure
|
|
15
|
+
* a failure that is not a command's (✗), an edit card, an approval, the answer. A FAILED COMMAND
|
|
16
|
+
* joins the group too (GH #530) and the row says so in red: "Ran 2 shell commands · 1 failed".
|
|
14
17
|
*
|
|
15
18
|
* NOTHING HERE KNOWS A TOOL'S NAME. The kind is whatever stands before the arrow, so a tool added
|
|
16
19
|
* tomorrow is counted with no change here — the same rule the tool list itself follows (#37).
|
|
@@ -42,22 +45,24 @@ export function stepLabel(text) {
|
|
|
42
45
|
return /^[A-Za-z][A-Za-z0-9 _.\-/]*$/.test(label) ? label : "";
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
// A COMMAND
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// A COMMAND joins the group too (#383, GitHub #173): a turn that checks eight tools printed eight
|
|
49
|
+
// "✓ Command finished → …" rows in a column. They are activity, like the look-ups — one counted
|
|
50
|
+
// row, a click from the commands. GH #530: so does a FAILED command. It used to stand alone under
|
|
51
|
+
// a red ✗; now no row has a mark and the group's row ends "· 1 failed" in red — the one part
|
|
52
|
+
// that asks for attention. A look-up that found nothing (grep exits 1) is not counted as failed.
|
|
53
|
+
const COMMAND_STEP = /^Command (?:finished|failed) → (.*)$/;
|
|
54
|
+
export const isCommandStep = (text) => COMMAND_STEP.test(String(text ?? "").trim());
|
|
50
55
|
|
|
51
|
-
/**
|
|
52
|
-
export function
|
|
53
|
-
|
|
54
|
-
return
|
|
56
|
+
/** A command that really failed — not a grep/pgrep/which that simply found nothing. */
|
|
57
|
+
export function isFailedCommandStep(text) {
|
|
58
|
+
const m = /^Command failed → (.*)$/.exec(String(text ?? "").trim());
|
|
59
|
+
return Boolean(m) && !isSoftFailCommand(m[1]);
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
/**
|
|
58
|
-
export function
|
|
59
|
-
|
|
60
|
-
return
|
|
62
|
+
/** Does this step join a group? `kind` is bulletKind()'s: neutral look-ups, and commands. */
|
|
63
|
+
export function isGroupableStep(text, kind) {
|
|
64
|
+
if (kind === "ok" || kind === "fail" || kind === "soft") return isCommandStep(text);
|
|
65
|
+
return kind === "info" && !isScaffoldStep(text) && stepLabel(text) !== "";
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
// "Searching code" reads as work in progress; a finished group is said in the past. Only the first
|
|
@@ -74,16 +79,52 @@ function pastLabel(label) {
|
|
|
74
79
|
return past ? [past, ...rest].join(" ") : label;
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* "Searched code 3× · read lines 2× · ran 2 shell commands · 1 failed" — kinds in the order they
|
|
84
|
+
* first happened; the failed count follows the commands it belongs to.
|
|
85
|
+
*/
|
|
78
86
|
export function stepGroupSummary(items) {
|
|
79
87
|
const counts = new Map();
|
|
88
|
+
let failed = 0;
|
|
80
89
|
for (const it of items ?? []) {
|
|
81
|
-
const label = stepLabel(it) || String(it ?? "").trim();
|
|
90
|
+
const label = isCommandStep(it) ? COMMANDS : stepLabel(it) || String(it ?? "").trim();
|
|
82
91
|
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
92
|
+
if (isFailedCommandStep(it)) failed++;
|
|
83
93
|
}
|
|
84
|
-
|
|
85
|
-
.map(([label, n]) =>
|
|
94
|
+
const text = [...counts]
|
|
95
|
+
.map(([label, n]) =>
|
|
96
|
+
label === COMMANDS
|
|
97
|
+
? `ran ${n} shell command${n > 1 ? "s" : ""}` + (failed ? ` · ${failed} failed` : "")
|
|
98
|
+
: pastLabel(label) + (n > 1 ? ` ${n}×` : "")
|
|
99
|
+
)
|
|
86
100
|
.join(" · ");
|
|
101
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
102
|
+
}
|
|
103
|
+
const COMMANDS = "\0commands";
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A group row cut into the pieces the terminal paints differently (GH #530): the command count
|
|
107
|
+
* ("2" in "Ran 2 shell commands") and the failure ("1 failed", or "failed" in a lone
|
|
108
|
+
* "Command failed → …" row) — everything else is plain. Pure; the caller owns the colours.
|
|
109
|
+
* → [{ text, style: "count" | "failed" | null }]
|
|
110
|
+
*/
|
|
111
|
+
export function stepRowSpans(text) {
|
|
112
|
+
const t = String(text ?? "");
|
|
113
|
+
const spans = [];
|
|
114
|
+
let rest = t;
|
|
115
|
+
const count = /^(.*?\b[Rr]an )(\d+)( shell commands?)/.exec(rest);
|
|
116
|
+
if (count) {
|
|
117
|
+
spans.push({ text: count[1], style: null }, { text: count[2], style: "count" });
|
|
118
|
+
rest = rest.slice(count[1].length + count[2].length);
|
|
119
|
+
}
|
|
120
|
+
const fail = /\b\d+ failed\b/.exec(rest) ?? (isFailedCommandStep(rest) ? /failed/.exec(rest) : null);
|
|
121
|
+
if (fail) {
|
|
122
|
+
if (fail.index) spans.push({ text: rest.slice(0, fail.index), style: null });
|
|
123
|
+
spans.push({ text: fail[0], style: "failed" });
|
|
124
|
+
rest = rest.slice(fail.index + fail[0].length);
|
|
125
|
+
}
|
|
126
|
+
if (rest) spans.push({ text: rest, style: null });
|
|
127
|
+
return spans;
|
|
87
128
|
}
|
|
88
129
|
|
|
89
130
|
function wrapWords(text, width) {
|
package/terminal-layout.mjs
CHANGED
|
@@ -587,7 +587,8 @@ function mouseTextVerdict(text, plainLeads) {
|
|
|
587
587
|
if (body === "") return { kind: "partial" };
|
|
588
588
|
continue;
|
|
589
589
|
}
|
|
590
|
-
if (body === "I" || body === "O"
|
|
590
|
+
if (body === "I" || body === "O") return { kind: "done", report: null, focus: body === "I" ? "in" : "out" };
|
|
591
|
+
if (WIN32_BODY_DONE.test(body)) return { kind: "done", report: null };
|
|
591
592
|
if (body.length <= 40 && WIN32_BODY_PART.test(body)) return { kind: "partial" };
|
|
592
593
|
}
|
|
593
594
|
return { kind: "bad" };
|
|
@@ -620,7 +621,7 @@ export function createMouseReportReader() {
|
|
|
620
621
|
if (v.kind === "partial") return { action: "hold" };
|
|
621
622
|
held = null;
|
|
622
623
|
// Whole in one key ("\x1b[O"): node would drop it anyway, but it is ours to drop.
|
|
623
|
-
if (v.kind === "done") return { action: "consume", report: v.report };
|
|
624
|
+
if (v.kind === "done") return { action: "consume", report: v.report, focus: v.focus ?? null };
|
|
624
625
|
return { action: "pass" };
|
|
625
626
|
}
|
|
626
627
|
held.push([str, key]);
|
|
@@ -628,7 +629,7 @@ export function createMouseReportReader() {
|
|
|
628
629
|
const v = mouseTextVerdict(text, plainLeads);
|
|
629
630
|
if (v.kind === "done") {
|
|
630
631
|
held = null;
|
|
631
|
-
return { action: "consume", report: v.report };
|
|
632
|
+
return { action: "consume", report: v.report, focus: v.focus ?? null };
|
|
632
633
|
}
|
|
633
634
|
if (v.kind === "partial") return { action: "hold" };
|
|
634
635
|
// Not a report. If the key that broke it could START one ("[" after "[", an Esc), keep it.
|
|
@@ -650,6 +651,80 @@ export function createMouseReportReader() {
|
|
|
650
651
|
};
|
|
651
652
|
}
|
|
652
653
|
|
|
654
|
+
/**
|
|
655
|
+
* The terminal's focus report as node's keypress parser delivers it: "\x1b[I" (the window got
|
|
656
|
+
* focus) or "\x1b[O" (it lost it), sent because gu asks for them with ?1004h (GH #558).
|
|
657
|
+
* "in" | "out" | null. Not typing: a key listener that treats it as one would, for example,
|
|
658
|
+
* jump a scrolled-back view to the bottom every time the user switched windows.
|
|
659
|
+
*/
|
|
660
|
+
export function focusReport(key) {
|
|
661
|
+
const seq = key?.sequence;
|
|
662
|
+
return seq === "\x1b[I" ? "in" : seq === "\x1b[O" ? "out" : null;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* NEVER LEAVE A WINDOW REPORTING THE MOUSE TO NOBODY (GH #558).
|
|
667
|
+
*
|
|
668
|
+
* gu reports mouse motion at its prompt (?1003h). It switches that off when it exits, but a gu
|
|
669
|
+
* that dies without exiting cannot: an SSH connection reset (the remote machine went away), a
|
|
670
|
+
* kill -9, a closed lid. The terminal then keeps sending every mouse move — to the user's shell,
|
|
671
|
+
* which prints "35;72;42M35;73;42M…" with each move. Reported live after an SSH session to a
|
|
672
|
+
* deleted VM dropped.
|
|
673
|
+
*
|
|
674
|
+
* Nothing can reach the terminal after the connection is gone, so the mouse is let go BEFORE:
|
|
675
|
+
* - when the window loses focus (focus reporting, ?1004h) — taken back on focus-in;
|
|
676
|
+
* - over SSH, after `idleMs` with no input at the prompt (a locked screen may send no
|
|
677
|
+
* focus-out) — taken back on the next key or focus-in.
|
|
678
|
+
* A user at the window loses nothing: the window has focus and they are using it.
|
|
679
|
+
*
|
|
680
|
+
* `release()` / `restore()` write the terminal modes (the caller knows which mode is on);
|
|
681
|
+
* this only decides WHEN. `arm()` starts the idle clock without taking the mouse back — a
|
|
682
|
+
* prompt that appears while the user is away must not re-grab it.
|
|
683
|
+
*/
|
|
684
|
+
export function createMouseParking({ release, restore, idleMs = 0, setTimer = setTimeout, clearTimer = clearTimeout } = {}) {
|
|
685
|
+
let parked = false;
|
|
686
|
+
let timer = null;
|
|
687
|
+
const stopClock = () => {
|
|
688
|
+
if (timer) clearTimer(timer);
|
|
689
|
+
timer = null;
|
|
690
|
+
};
|
|
691
|
+
const park = () => {
|
|
692
|
+
stopClock();
|
|
693
|
+
if (parked) return;
|
|
694
|
+
parked = true;
|
|
695
|
+
release();
|
|
696
|
+
};
|
|
697
|
+
const unpark = () => {
|
|
698
|
+
if (!parked) return;
|
|
699
|
+
parked = false;
|
|
700
|
+
restore();
|
|
701
|
+
};
|
|
702
|
+
const arm = () => {
|
|
703
|
+
if (!(idleMs > 0) || parked) return;
|
|
704
|
+
stopClock();
|
|
705
|
+
timer = setTimer(() => {
|
|
706
|
+
timer = null;
|
|
707
|
+
park();
|
|
708
|
+
}, idleMs);
|
|
709
|
+
timer?.unref?.();
|
|
710
|
+
};
|
|
711
|
+
return {
|
|
712
|
+
parked: () => parked,
|
|
713
|
+
focusOut: park,
|
|
714
|
+
focusIn() {
|
|
715
|
+
unpark();
|
|
716
|
+
arm();
|
|
717
|
+
},
|
|
718
|
+
/** A key, a paste, a mouse report: someone is here. */
|
|
719
|
+
activity() {
|
|
720
|
+
unpark();
|
|
721
|
+
arm();
|
|
722
|
+
},
|
|
723
|
+
arm,
|
|
724
|
+
stop: stopClock,
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
|
|
653
728
|
/** Last line of defence at submit: a report that got past every reader is not a question. */
|
|
654
729
|
export function stripLeakedMouseReports(line) {
|
|
655
730
|
return String(line)
|
|
@@ -1043,6 +1118,9 @@ export const INPUT_HEAD_ROWS = 2;
|
|
|
1043
1118
|
export function inputZoneRows({
|
|
1044
1119
|
width, prompt = ">> ", promptCols = 3, line = "", cursor = 0, rule,
|
|
1045
1120
|
maxRows = 10, selection = null, highlight = null,
|
|
1121
|
+
// GH #536: a suggested next message, ALREADY PAINTED (dim), drawn after the prompt while the line
|
|
1122
|
+
// is empty. Display only: it is not text — the caret stays at the start and no offset sees it.
|
|
1123
|
+
ghost = "",
|
|
1046
1124
|
// Does the separator carry a control this time? Defaults TRUE so any caller that has not been
|
|
1047
1125
|
// told about this keeps the old, roomier layout rather than silently losing a row.
|
|
1048
1126
|
headControl = true,
|
|
@@ -1107,6 +1185,7 @@ export function inputZoneRows({
|
|
|
1107
1185
|
|
|
1108
1186
|
const rows = shown.map((s, i) => {
|
|
1109
1187
|
const head = top + i === 0 ? prompt : " ".repeat(promptCols);
|
|
1188
|
+
if (!text && ghost && top + i === 0) return clipVisible(head + ghost, w - 1);
|
|
1110
1189
|
let row = clipVisible(head + text.slice(s.from, s.to), w - 1);
|
|
1111
1190
|
// The selection is held in TEXT OFFSETS, so it survives a rewrap: the same characters stay
|
|
1112
1191
|
// selected at any width. Each row paints only its own slice of it.
|
package/turn-notes.mjs
CHANGED
|
@@ -28,9 +28,62 @@ export function sendNote(jobId, text, home) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// ---- SEND NOW (GH #560) ------------------------------------------------------------------------
|
|
32
|
+
// Claude Code's "Queued · ctrl+x ctrl+s to send now". A note is read after the agent's current step;
|
|
33
|
+
// during a long command that step can be minutes away. Ctrl+X Ctrl+S creates <jobId>.now and the
|
|
34
|
+
// agent stops WAITING on the command — it goes on in the background, never killed — so the step ends
|
|
35
|
+
// and the note is read. A model reply in progress is not cut (tokens already paid): the note follows it.
|
|
36
|
+
export const nowPath = (jobId, home) => join(notesDir(home), `${safe(jobId)}.now`);
|
|
37
|
+
|
|
38
|
+
/** Ask the running turn to read its waiting notes now → true when the request was written. */
|
|
39
|
+
export function sendNow(jobId, home) {
|
|
40
|
+
if (!safe(jobId)) return false;
|
|
41
|
+
try {
|
|
42
|
+
mkdirSync(notesDir(home), { recursive: true, mode: 0o700 });
|
|
43
|
+
appendFileSync(nowPath(jobId, home), "", { mode: 0o600 });
|
|
44
|
+
return true;
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const CHORD_WINDOW_MS = 1500;
|
|
51
|
+
|
|
52
|
+
/** Ctrl+X then Ctrl+S within CHORD_WINDOW_MS. feed(key) → true when the chord completes. */
|
|
53
|
+
export function createSendNowChord({ windowMs = CHORD_WINDOW_MS, now = () => Date.now() } = {}) {
|
|
54
|
+
let xAt = 0;
|
|
55
|
+
return {
|
|
56
|
+
feed(key) {
|
|
57
|
+
if (!key || !key.ctrl) {
|
|
58
|
+
xAt = 0;
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (key.name === "x") {
|
|
62
|
+
xAt = now();
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const hit = key.name === "s" && xAt > 0 && now() - xAt <= windowMs;
|
|
66
|
+
xAt = 0;
|
|
67
|
+
return hit;
|
|
68
|
+
},
|
|
69
|
+
/** A Ctrl+X is waiting for its Ctrl+S. */
|
|
70
|
+
get armed() {
|
|
71
|
+
return xAt > 0 && now() - xAt <= windowMs;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The dim line under what waits (GH #560). notes: waiting for the running turn; queued: for after it. */
|
|
77
|
+
export function waitingLabel({ notes = 0, queued = 0, sending = false } = {}) {
|
|
78
|
+
if (notes > 0) return sending ? "⎿ Sending now · the agent reads it next" : "⎿ Queued · Ctrl+X Ctrl+S to send now";
|
|
79
|
+
if (queued > 0) return "⎿ Queued · runs after this turn";
|
|
80
|
+
return "";
|
|
81
|
+
}
|
|
82
|
+
|
|
31
83
|
/** The notes the agent never took, oldest first; the file is removed. [] when none. */
|
|
32
84
|
export function takeUnread(jobId, home) {
|
|
33
85
|
if (!safe(jobId)) return [];
|
|
86
|
+
rmSync(nowPath(jobId, home), { force: true }); // the turn is over: a send-now request is spent
|
|
34
87
|
const path = notesPath(jobId, home);
|
|
35
88
|
if (!existsSync(path)) return [];
|
|
36
89
|
const taken = `${path}.back-${process.pid}-${Date.now()}`;
|
|
@@ -87,3 +140,15 @@ export function questionWithNotes(question, notes) {
|
|
|
87
140
|
const added = (notes ?? []).map((t) => String(t).trim()).filter(Boolean);
|
|
88
141
|
return added.length ? `${question}\n\n[Added by the user while you were working]\n${added.join("\n\n")}` : question;
|
|
89
142
|
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* GH #562: the agent's one-line answer to what was typed during the turn (its say() tool), like Claude Code's
|
|
146
|
+
* "Noted: …" — shown as normal text right under the user's message, and the turn goes on.
|
|
147
|
+
*/
|
|
148
|
+
export const SAY_PREFIX = "__SAY__::";
|
|
149
|
+
|
|
150
|
+
/** → the line to show, or "" when this step line is not one. */
|
|
151
|
+
export function parseSay(line) {
|
|
152
|
+
const s = String(line ?? "").trim();
|
|
153
|
+
return s.startsWith(SAY_PREFIX) ? s.slice(SAY_PREFIX.length).trim() : "";
|
|
154
|
+
}
|
package/win-shell.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DEP0190 (GH #557 follow-up): Node 24 warns "Passing args to a child process with shell option
|
|
3
|
+
* true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated"
|
|
4
|
+
* whenever an args array goes with `shell: true` — and the warning landed in the middle of gu's
|
|
5
|
+
* Windows output. A shell is still needed on Windows (npm is npm.cmd, and a .cmd runs only
|
|
6
|
+
* through cmd.exe), so the command is handed over the way the shell takes it anyway: ONE string,
|
|
7
|
+
* each part quoted where cmd.exe needs it, no args array.
|
|
8
|
+
*
|
|
9
|
+
* → { cmd, args, shell } for spawn/execFile. Off Windows nothing changes: no shell, args as given.
|
|
10
|
+
*/
|
|
11
|
+
const PLAIN = /^[\w\-.=:\\/@,+]+$/;
|
|
12
|
+
|
|
13
|
+
/** One argument for a cmd.exe command line. */
|
|
14
|
+
export function cmdQuote(arg) {
|
|
15
|
+
const s = String(arg);
|
|
16
|
+
if (s !== "" && PLAIN.test(s)) return s;
|
|
17
|
+
// Inside quotes cmd.exe still treats `"` as the end, so a double quote is doubled. `%` and `!`
|
|
18
|
+
// would still expand; nothing gu passes here contains them except, possibly, a home folder,
|
|
19
|
+
// and that is no worse than the plain concatenation this replaces.
|
|
20
|
+
return `"${s.replace(/"/g, '""')}"`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function shellCommand(cmd, args = [], { platform = process.platform } = {}) {
|
|
24
|
+
if (platform !== "win32") return { cmd, args: [...args], shell: false };
|
|
25
|
+
return { cmd: [cmd, ...args].map(cmdQuote).join(" "), args: [], shell: true };
|
|
26
|
+
}
|