@tiens.nguyen/gu-cli 1.0.849 → 1.0.851
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/gonext_agent_chat.py +56 -14
- package/gu-repl.mjs +67 -6
- package/package.json +1 -1
- package/shell-details.mjs +27 -8
- package/terminal-viewport.mjs +26 -0
package/gonext_agent_chat.py
CHANGED
|
@@ -9562,6 +9562,9 @@ _SHELLS_KEEP = 20 # newest records kept, running or not
|
|
|
9562
9562
|
_SHELLS_KEEP_DONE_S = 86400 # a finished shell is listed for a day
|
|
9563
9563
|
|
|
9564
9564
|
|
|
9565
|
+
_FG_SHELL_AFTER_S = 4 # a foreground command shows up as a shell after this many seconds (#407)
|
|
9566
|
+
|
|
9567
|
+
|
|
9565
9568
|
def _shells_path() -> str:
|
|
9566
9569
|
import os
|
|
9567
9570
|
base = os.path.join(os.path.expanduser("~"), ".gonext")
|
|
@@ -9612,12 +9615,12 @@ def _shell_exit_code(s: dict):
|
|
|
9612
9615
|
return (None, None)
|
|
9613
9616
|
|
|
9614
9617
|
|
|
9615
|
-
def
|
|
9616
|
-
"""
|
|
9617
|
-
|
|
9618
|
-
to _shells_load() OUTSIDE any lock then _shells_save() the grown list — a
|
|
9619
|
-
own save in between silently dropped
|
|
9620
|
-
link disappeared for a live background task."""
|
|
9618
|
+
def _shells_edit(mutate) -> None:
|
|
9619
|
+
"""Rewrite shells.json under an exclusive lock, RE-READING the file inside the lock so two
|
|
9620
|
+
overlapping turns do not overwrite each other's change (#387). `mutate(shells) -> shells`.
|
|
9621
|
+
_to_background used to _shells_load() OUTSIDE any lock then _shells_save() the grown list — a
|
|
9622
|
+
concurrent reader's own save in between silently dropped the record, and the repl's "N shells
|
|
9623
|
+
running (click)" link disappeared for a live background task."""
|
|
9621
9624
|
import fcntl # macOS/Linux posix lock; the workspace here is the user's Mac
|
|
9622
9625
|
import json as _json
|
|
9623
9626
|
import os
|
|
@@ -9633,7 +9636,7 @@ def _shells_add_new(rec: dict) -> None:
|
|
|
9633
9636
|
except Exception: # noqa: BLE001
|
|
9634
9637
|
shells = []
|
|
9635
9638
|
shells = [s for s in shells if isinstance(s, dict) and s.get("pid")]
|
|
9636
|
-
shells
|
|
9639
|
+
shells = mutate(shells)
|
|
9637
9640
|
# Same prune policy as _shells_save so the file stays bounded.
|
|
9638
9641
|
now = _t.time()
|
|
9639
9642
|
kept = []
|
|
@@ -9655,9 +9658,21 @@ def _shells_add_new(rec: dict) -> None:
|
|
|
9655
9658
|
os.close(lock_fd)
|
|
9656
9659
|
except OSError:
|
|
9657
9660
|
pass
|
|
9661
|
+
|
|
9662
|
+
|
|
9663
|
+
def _shells_add_new(rec: dict) -> None:
|
|
9664
|
+
"""Register one record. A record with the same pid is REPLACED, not duplicated (#407): a
|
|
9665
|
+
command shown early as a foreground shell becomes the background shell in place."""
|
|
9666
|
+
key = str(rec.get("id") or rec.get("pid")) # a real record's id is its pid
|
|
9667
|
+
_shells_edit(lambda shells: [s for s in shells if str(s.get("id") or s.get("pid")) != key] + [rec])
|
|
9658
9668
|
_log(f"shells.json +1 → pid {rec.get('pid')} registered (#387)")
|
|
9659
9669
|
|
|
9660
9670
|
|
|
9671
|
+
def _shells_drop(pid) -> None:
|
|
9672
|
+
"""Remove a record — a foreground command that finished inline (its result went to the model)."""
|
|
9673
|
+
_shells_edit(lambda shells: [s for s in shells if str(s.get("id") or s.get("pid")) != str(pid)])
|
|
9674
|
+
|
|
9675
|
+
|
|
9661
9676
|
def _shell_state(s: dict, alive=None, now=None) -> dict:
|
|
9662
9677
|
"""{state, code, runtime, ended} for a shell record. state: running | exited (0) | failed |
|
|
9663
9678
|
killed | ended (gone, exit code unknown). `alive` is injectable so tests need no process."""
|
|
@@ -9668,7 +9683,8 @@ def _shell_state(s: dict, alive=None, now=None) -> dict:
|
|
|
9668
9683
|
if alive is None:
|
|
9669
9684
|
alive = code is None and bool(_ws_record_pids(s))
|
|
9670
9685
|
if alive and code is None and not s.get("killed"):
|
|
9671
|
-
return {"state": "running", "code": None, "runtime": max(0.0, now - started), "ended": now
|
|
9686
|
+
return {"state": "running", "code": None, "runtime": max(0.0, now - started), "ended": now,
|
|
9687
|
+
"foreground": bool(s.get("foreground"))}
|
|
9672
9688
|
ended = float(s.get("ended") or code_at or now)
|
|
9673
9689
|
if s.get("killed"):
|
|
9674
9690
|
state = "killed"
|
|
@@ -9690,7 +9706,7 @@ def _fmt_runtime(seconds: float) -> str:
|
|
|
9690
9706
|
|
|
9691
9707
|
def _shell_status_text(st: dict) -> str:
|
|
9692
9708
|
if st["state"] == "running":
|
|
9693
|
-
return "running"
|
|
9709
|
+
return "running (foreground, still waiting)" if st.get("foreground") else "running"
|
|
9694
9710
|
if st["state"] in ("exited", "failed"):
|
|
9695
9711
|
return f"exited {st['code']}"
|
|
9696
9712
|
# WHO STOPPED IT (#362/#143). A bare "killed" read as a crash — "shell got status killed why?"
|
|
@@ -15670,6 +15686,7 @@ def run_agent_chat(cfg):
|
|
|
15670
15686
|
# the toggle off raises the bar to every command. Off is the cautious setting,
|
|
15671
15687
|
# so it may only ever add questions — never remove one.
|
|
15672
15688
|
if not _ask_reason and not _accept_edits:
|
|
15689
|
+
# gu-repl.mjs approvalPrompt matches this prefix to offer "Yes for all later ones" (#200)
|
|
15673
15690
|
_ask_reason = "accept edits is off, so every command is confirmed first"
|
|
15674
15691
|
# ELEVATION: find out what we are ALLOWED to do before asking, so the question
|
|
15675
15692
|
# states it. "this needs root and sudo needs a password we cannot type" is a
|
|
@@ -15783,15 +15800,27 @@ def run_agent_chat(cfg):
|
|
|
15783
15800
|
)
|
|
15784
15801
|
_INFLIGHT_CMDS.add(proc.pid) # killed with the agent until it is classified
|
|
15785
15802
|
start = _t.time()
|
|
15786
|
-
|
|
15787
|
-
|
|
15788
|
-
|
|
15789
|
-
|
|
15803
|
+
# SHOWN EARLY (#407, GitHub #198): a command that runs past _FG_SHELL_AFTER_S is
|
|
15804
|
+
# listed as a shell (foreground: true) so the header and /shells show what the
|
|
15805
|
+
# user is waiting for, instead of nothing until the timeout hands it off.
|
|
15806
|
+
# shown = record written; bg = _to_background took over (keep the record).
|
|
15807
|
+
_fg = {"shown": False, "bg": False}
|
|
15808
|
+
|
|
15809
|
+
def _fg_record(foreground: bool = False) -> dict:
|
|
15810
|
+
rec = {
|
|
15790
15811
|
"id": str(proc.pid), "pid": proc.pid, "pgid": proc.pid,
|
|
15791
15812
|
"command": command, "workdir": wd, "log": log_path,
|
|
15792
15813
|
"exit_file": exit_path if _use_shell else "",
|
|
15793
15814
|
"started": start, "started_at": _t.strftime("%Y-%m-%d %H:%M:%S"),
|
|
15794
|
-
}
|
|
15815
|
+
}
|
|
15816
|
+
if foreground:
|
|
15817
|
+
rec["foreground"] = True
|
|
15818
|
+
return rec
|
|
15819
|
+
|
|
15820
|
+
def _to_background(why: str) -> str:
|
|
15821
|
+
"""Leave the command running as a background shell; say so to the model."""
|
|
15822
|
+
_fg["bg"] = True # same pid → replaces the early foreground record, no duplicate
|
|
15823
|
+
_shells_add_new(_fg_record())
|
|
15795
15824
|
_emit({"type": "step", "text":
|
|
15796
15825
|
f"Running in background → {_trim_words(command)} (shell {proc.pid})"})
|
|
15797
15826
|
tail = _ws_distill_output(_read_log())
|
|
@@ -15941,6 +15970,12 @@ def run_agent_chat(cfg):
|
|
|
15941
15970
|
+ (f"\nStartup output:\n{tail}" if tail.strip() else ""))
|
|
15942
15971
|
_last_obs["text"] = result
|
|
15943
15972
|
return result
|
|
15973
|
+
if not _fg["shown"] and _t.time() - start >= _FG_SHELL_AFTER_S:
|
|
15974
|
+
_fg["shown"] = True
|
|
15975
|
+
try:
|
|
15976
|
+
_shells_add_new(_fg_record(foreground=True))
|
|
15977
|
+
except Exception as _ex: # noqa: BLE001 — a display aid must never fail the run
|
|
15978
|
+
_log(f"foreground shell record failed: {_ex}")
|
|
15944
15979
|
# A job sent to the background on purpose, once it has had its 3s to show
|
|
15945
15980
|
# it is neither a server nor an app.
|
|
15946
15981
|
if background and _t.time() - start >= 3:
|
|
@@ -15964,6 +15999,13 @@ def run_agent_chat(cfg):
|
|
|
15964
15999
|
# (tracked in the servers file for stop_server): no longer in flight either way.
|
|
15965
16000
|
if proc is not None:
|
|
15966
16001
|
_INFLIGHT_CMDS.discard(proc.pid)
|
|
16002
|
+
# It finished inline (result went to the model) or became a server/app (tracked
|
|
16003
|
+
# in servers.json): the early foreground record has done its job (#407).
|
|
16004
|
+
if _fg["shown"] and not _fg["bg"]:
|
|
16005
|
+
try:
|
|
16006
|
+
_shells_drop(proc.pid)
|
|
16007
|
+
except Exception as _ex: # noqa: BLE001
|
|
16008
|
+
_log(f"foreground shell drop failed: {_ex}")
|
|
15967
16009
|
try:
|
|
15968
16010
|
log_fh.close()
|
|
15969
16011
|
except Exception: # noqa: BLE001
|
package/gu-repl.mjs
CHANGED
|
@@ -141,7 +141,7 @@ import { completedFlush, splitLiveStream } from "./completed-flush.mjs";
|
|
|
141
141
|
import { isScaffoldStep, isGroupableStep, stepGroupMark, stepGroupRows, relativizePaths } from "./step-group.mjs";
|
|
142
142
|
import { clearLogsNoticeText } from "./clear-logs.mjs";
|
|
143
143
|
import { allowIn, allowedIn, bridgeCommand, browserReport, bridgeStatus, extensionDir, findDevInstalls, helpInstall, installExtensionFiles, installSteps, localLeftovers, openExtensionsPage, removeLocalFiles, STORE_URL, stopBridge } from "./browser-command.mjs";
|
|
144
|
-
import { commandLogFile, killShell, logTail, markAnnounced, readShells, recapQuestion, shellsToRecap, statusText as shellStatusText, renderShellDetails, shellPanelRows, shellPickerLabel, shellState, shellsNotice } from "./shell-details.mjs";
|
|
144
|
+
import { commandLogFile, killShell, logTail, markAnnounced, readShells, recapQuestion, runningShells, shellsToRecap, statusText as shellStatusText, renderShellDetails, shellPanelRows, shellPickerLabel, shellState, shellsNotice } from "./shell-details.mjs";
|
|
145
145
|
import { discoverSkills, matchSkillCommand } from "./skills.mjs";
|
|
146
146
|
import { appendNew, archivePathFor, archivedWorkspaceKey, markReset, seedArchive } from "./conversation-archive.mjs";
|
|
147
147
|
import { addAllowRule, listServers as listMcpServers } from "./mcp-config.mjs";
|
|
@@ -200,6 +200,8 @@ import {
|
|
|
200
200
|
viewportRowsForLines,
|
|
201
201
|
dragReduce,
|
|
202
202
|
dragEventKind,
|
|
203
|
+
dragEdgeDirection,
|
|
204
|
+
shiftDragAnchor,
|
|
203
205
|
selectionText,
|
|
204
206
|
isEmptySelection,
|
|
205
207
|
selectionCoversLines,
|
|
@@ -1450,10 +1452,15 @@ function applyMouseReport(report) {
|
|
|
1450
1452
|
if (scrolledBack()) renderScrollback();
|
|
1451
1453
|
else paintLiveTail();
|
|
1452
1454
|
paintBar();
|
|
1455
|
+
// GH #201 — AUTOSCROLL. A pointer on the top/bottom row keeps scrolling the view so
|
|
1456
|
+
// the selection can grow past what fits on screen; it repeats on a timer because
|
|
1457
|
+
// an any-motion report only arrives when the pointer MOVES, not while it is held.
|
|
1458
|
+
startDragAutoscroll(dragEdgeDirection(Number(rowStr), transcriptRows()));
|
|
1453
1459
|
}
|
|
1454
1460
|
return; // mid-drag: hover must not also fire on this motion
|
|
1455
1461
|
}
|
|
1456
1462
|
if (act) { // the button came up: commit or cancel
|
|
1463
|
+
stopDragAutoscroll();
|
|
1457
1464
|
const had = liveSelection;
|
|
1458
1465
|
liveSelection = null;
|
|
1459
1466
|
// Repaint only if a highlight was on screen — through the painter that owns the view
|
|
@@ -2993,7 +3000,7 @@ function zoneNotice(width) {
|
|
|
2993
3000
|
if (tokenNotice?.text) items.push({ key: "token", paint: tokenNotice.urgent ? yellow : dim, text: tokenNotice.text });
|
|
2994
3001
|
const agents = agentsIndicator(otherAgents);
|
|
2995
3002
|
if (agents) items.push({ key: "agents", clickable: true, paint: accent, text: `${agents} running (click)` });
|
|
2996
|
-
const shells = shellsNotice(shellEntries, {
|
|
3003
|
+
const shells = shellsNotice(shellEntries, { cwd: process.cwd() });
|
|
2997
3004
|
if (shells) items.push({ key: "shells", clickable: true, paint: shells.tone === "warn" ? yellow : accent, text: shells.text });
|
|
2998
3005
|
// LAST, so it is the first to give way on a narrow window: housekeeping, never urgent (#329).
|
|
2999
3006
|
const logs = clearLogsNoticeText(logsBytes);
|
|
@@ -3390,6 +3397,36 @@ const screenRows = () => {
|
|
|
3390
3397
|
const pad = currentPad(rows.length);
|
|
3391
3398
|
return applySelectionHighlight(pad ? [...rows, ...Array(pad).fill("")] : rows, liveSelection);
|
|
3392
3399
|
};
|
|
3400
|
+
// GH #201 — autoscroll while dragging a selection against the top/bottom edge.
|
|
3401
|
+
const DRAG_SCROLL_LINES = 2;
|
|
3402
|
+
const DRAG_SCROLL_MS = 80;
|
|
3403
|
+
let dragEdgeDir = 0;
|
|
3404
|
+
let dragEdgeTimer = null;
|
|
3405
|
+
function stopDragAutoscroll() {
|
|
3406
|
+
dragEdgeDir = 0;
|
|
3407
|
+
if (dragEdgeTimer) { clearInterval(dragEdgeTimer); dragEdgeTimer = null; }
|
|
3408
|
+
}
|
|
3409
|
+
function dragAutoscrollStep() {
|
|
3410
|
+
if (!dragState || !dragState.moved || !dragEdgeDir || !barPinned()) { stopDragAutoscroll(); return; }
|
|
3411
|
+
const before = scrollOffset;
|
|
3412
|
+
scrollView(dragEdgeDir * DRAG_SCROLL_LINES);
|
|
3413
|
+
const d = scrollOffset - before;
|
|
3414
|
+
if (!d) return; // already at the first line / the live tail
|
|
3415
|
+
// The view moved d lines: keep the anchor on the text it was on, then re-aim the highlight.
|
|
3416
|
+
dragState = shiftDragAnchor(dragState, d);
|
|
3417
|
+
liveSelection = toAbsoluteSelection({ start: dragState.anchor, end: dragState.focus });
|
|
3418
|
+
if (scrolledBack()) renderScrollback();
|
|
3419
|
+
else paintLiveTail();
|
|
3420
|
+
paintBar();
|
|
3421
|
+
}
|
|
3422
|
+
function startDragAutoscroll(dir) {
|
|
3423
|
+
if (!dir) { stopDragAutoscroll(); return; }
|
|
3424
|
+
dragEdgeDir = dir;
|
|
3425
|
+
if (!dragEdgeTimer) {
|
|
3426
|
+
dragEdgeTimer = setInterval(dragAutoscrollStep, DRAG_SCROLL_MS);
|
|
3427
|
+
dragEdgeTimer.unref?.();
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3393
3430
|
/**
|
|
3394
3431
|
* Abandon any drag in progress and take its highlight off screen (task #177).
|
|
3395
3432
|
*
|
|
@@ -3404,6 +3441,7 @@ const screenRows = () => {
|
|
|
3404
3441
|
* painting per resize event is the mistake suspendClickForResize exists to avoid.
|
|
3405
3442
|
*/
|
|
3406
3443
|
function endDrag({ repaint = true } = {}) {
|
|
3444
|
+
stopDragAutoscroll();
|
|
3407
3445
|
dragState = null;
|
|
3408
3446
|
const hadInput = inputSelection !== null;
|
|
3409
3447
|
const hadLive = liveSelection !== null;
|
|
@@ -9589,9 +9627,9 @@ const shellsViewed = new Set();
|
|
|
9589
9627
|
const SHELLS_SINCE = Date.now() / 1000; // a shell that ended before this terminal opened is old news
|
|
9590
9628
|
const SHELLS_MS = 1000;
|
|
9591
9629
|
function refreshShells() {
|
|
9592
|
-
const before = shellsNotice(shellEntries, {
|
|
9630
|
+
const before = shellsNotice(shellEntries, { cwd: process.cwd() })?.text ?? "";
|
|
9593
9631
|
shellEntries = readShells().map((rec) => ({ rec, st: shellState(rec) }));
|
|
9594
|
-
const after = shellsNotice(shellEntries, {
|
|
9632
|
+
const after = shellsNotice(shellEntries, { cwd: process.cwd() })?.text ?? "";
|
|
9595
9633
|
if (after !== before) paintBar();
|
|
9596
9634
|
wakeForShells();
|
|
9597
9635
|
}
|
|
@@ -9738,9 +9776,10 @@ async function showShells() {
|
|
|
9738
9776
|
if (listPickerActive || approvalActive) return;
|
|
9739
9777
|
const width = Math.max(20, process.stdout.columns || 80);
|
|
9740
9778
|
refreshShells();
|
|
9741
|
-
|
|
9779
|
+
// RUNNING ONES ONLY, the same list the header counts (#405/#406) — finished shells are not listed.
|
|
9780
|
+
const entries = runningShells(shellEntries, { cwd: process.cwd() }).reverse(); // newest first
|
|
9742
9781
|
if (!entries.length) {
|
|
9743
|
-
console.log("\n" + GUTTER + dim("No background shells. A long command the agent runs moves here instead of being stopped.\n"));
|
|
9782
|
+
console.log("\n" + GUTTER + dim("No running background shells. A long command the agent runs moves here instead of being stopped.\n"));
|
|
9744
9783
|
paintBar();
|
|
9745
9784
|
return;
|
|
9746
9785
|
}
|
|
@@ -10854,6 +10893,28 @@ async function approvalPrompt(command) {
|
|
|
10854
10893
|
const tab = command.indexOf("\t");
|
|
10855
10894
|
const shown = tab < 0 ? command : command.slice(0, tab);
|
|
10856
10895
|
const why = tab < 0 ? "" : command.slice(tab + 1).trim();
|
|
10896
|
+
// GH #200 — "Yes for all later ones". ONLY for the soft question the agent asks because the
|
|
10897
|
+
// accept-edits switch is off (the reason text comes from gonext_agent_chat.py: "accept edits
|
|
10898
|
+
// is off, so every command is confirmed first"). That choice flips the switch back on, through
|
|
10899
|
+
// the same path Shift+Tab uses, so the running agent re-reads it before its next command and
|
|
10900
|
+
// the bar shows it. Risky commands (sudo, rm -rf, denylist) keep the plain Yes/No: a blanket
|
|
10901
|
+
// "yes" must never cover those.
|
|
10902
|
+
if (process.stdin.isTTY && editMode === "manual" && why.startsWith("accept edits is off")) {
|
|
10903
|
+
process.stdout.write(
|
|
10904
|
+
"\n" + yellow("⚠ Allow running this command?") + "\n" + indentBlock(shown, { paint: dim }) + "\n" +
|
|
10905
|
+
indentBlock(why, { paint: dim }) + "\n"
|
|
10906
|
+
);
|
|
10907
|
+
const idx = await pickFromList(
|
|
10908
|
+
["Yes", "Yes for all later ones (turns accept edits on)", "No"],
|
|
10909
|
+
0,
|
|
10910
|
+
{ timeoutMs: 170000, timeoutIndex: 2 }
|
|
10911
|
+
);
|
|
10912
|
+
if (idx === 1 && editMode === "manual") {
|
|
10913
|
+
switchEditMode();
|
|
10914
|
+
process.stdout.write(dim(" (won't ask for later commands — shift+tab to go back to manual)\n"));
|
|
10915
|
+
}
|
|
10916
|
+
return { allow: idx === 0 || idx === 1, dontAsk: false };
|
|
10917
|
+
}
|
|
10857
10918
|
const allow = await new Promise((resolve) => {
|
|
10858
10919
|
if (!process.stdin.isTTY) {
|
|
10859
10920
|
process.stdout.write("\n" + GUTTER + dim(`(approval needed for: ${shown}${why ? ` — ${why}` : ""} — no interactive terminal, skipping)`) + "\n");
|
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.851",
|
|
4
4
|
"description": "Gu CLI — the gu terminal plus the local worker that runs agent / OCR / PDF / embedding jobs on your Mac (Ollama / MLX / OpenAI-compatible).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/shell-details.mjs
CHANGED
|
@@ -92,7 +92,7 @@ export function shellState(rec, { alive, exit, now = Date.now() / 1000 } = {}) {
|
|
|
92
92
|
const started = rec?.started != null ? Number(rec.started) : now;
|
|
93
93
|
const ex = exit === undefined ? readExit(rec) : exit;
|
|
94
94
|
const live = alive === undefined ? !ex && isAlive(rec) : alive;
|
|
95
|
-
if (live && !ex && !rec?.killed) return { state: "running", code: null, runtime: Math.max(0, now - started), ended: now };
|
|
95
|
+
if (live && !ex && !rec?.killed) return { state: "running", code: null, runtime: Math.max(0, now - started), ended: now, foreground: Boolean(rec?.foreground) };
|
|
96
96
|
const ended = Number(rec?.ended) || ex?.at || now;
|
|
97
97
|
const state = rec?.killed ? "killed" : !ex ? "ended" : ex.code === 0 ? "exited" : "failed";
|
|
98
98
|
return { state, code: ex ? ex.code : null, runtime: Math.max(0, ended - started), ended, by: String(rec?.killed_by ?? "") };
|
|
@@ -109,7 +109,7 @@ export function fmtRuntime(seconds) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export function statusText(st) {
|
|
112
|
-
if (st.state === "running") return "running";
|
|
112
|
+
if (st.state === "running") return st.foreground ? "running (foreground, still waiting)" : "running";
|
|
113
113
|
if (st.state === "exited" || st.state === "failed") return `exited ${st.code}`;
|
|
114
114
|
// Who stopped it (#362/#143): a bare "killed" read as a crash when the agent had stopped its own
|
|
115
115
|
// search on purpose.
|
|
@@ -117,13 +117,24 @@ export function statusText(st) {
|
|
|
117
117
|
return "ended (exit code unknown)";
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* THE ONE "WHICH SHELLS COUNT" PREDICATE (#405/#406, GitHub #196/#197): still running, and — when a
|
|
122
|
+
* `cwd` is given — this project's (shells.json is shared by every folder). The header count
|
|
123
|
+
* ("N shells running") and the shells list both come from this, so they cannot disagree and the
|
|
124
|
+
* list never shows exited / killed ones.
|
|
125
|
+
*/
|
|
126
|
+
export function runningShells(entries, { cwd } = {}) {
|
|
127
|
+
const mine = cwd ? sameProject(cwd) : () => true;
|
|
128
|
+
return entries.filter((e) => e.st.state === "running" && mine(e.rec?.workdir));
|
|
129
|
+
}
|
|
130
|
+
|
|
120
131
|
/** The bottom notice row's shell control while a shell is running, else null. */
|
|
121
|
-
export function shellsNotice(entries) {
|
|
132
|
+
export function shellsNotice(entries, { cwd } = {}) {
|
|
122
133
|
// ONLY WHILE SOMETHING RUNS (#376, GitHub #157). A finished shell used to keep "shell exited 0
|
|
123
134
|
// (click)" on the row until it was opened — a done build still asking for attention. When one
|
|
124
135
|
// finishes, the agent hears about it (a recap turn, or the next step of the turn it is in), and
|
|
125
136
|
// /shells still lists every shell with its output.
|
|
126
|
-
const running = entries
|
|
137
|
+
const running = runningShells(entries, { cwd });
|
|
127
138
|
if (!running.length) return null;
|
|
128
139
|
const one = running.length === 1;
|
|
129
140
|
// No runtime here: it would change the row every second, and the bar repaints on change.
|
|
@@ -320,6 +331,17 @@ export async function killShell(rec, { path = shellsPath(), platform = process.p
|
|
|
320
331
|
* and never one you stopped yourself.
|
|
321
332
|
*/
|
|
322
333
|
export function shellsToRecap(entries, { cwd = process.cwd(), since = 0 } = {}) {
|
|
334
|
+
const under = sameProject(cwd);
|
|
335
|
+
return entries
|
|
336
|
+
// A foreground record (#407) is a command the agent is still waiting on inline — its result goes
|
|
337
|
+
// to the model; if the worker died mid-wait the leftover is not "a shell that finished".
|
|
338
|
+
.filter(({ rec, st }) => st.state !== "running" && st.state !== "killed" && !rec.foreground && !rec.seen && !rec.announced
|
|
339
|
+
&& st.ended >= since && under(rec.workdir))
|
|
340
|
+
.map((e) => e.rec);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** (workdir) => is it inside the project this `cwd` belongs to. */
|
|
344
|
+
export function sameProject(cwd) {
|
|
323
345
|
// The nearest folder that still exists, resolved (macOS: /var → /private/var), plus the rest —
|
|
324
346
|
// a build may have deleted the folder it ran in.
|
|
325
347
|
const real = (p) => {
|
|
@@ -338,10 +360,7 @@ export function shellsToRecap(entries, { cwd = process.cwd(), since = 0 } = {})
|
|
|
338
360
|
const w = real(wd).replace(/\/+$/, "");
|
|
339
361
|
return Boolean(w) && (w === base || w.startsWith(base + "/"));
|
|
340
362
|
};
|
|
341
|
-
return
|
|
342
|
-
.filter(({ rec, st }) => st.state !== "running" && st.state !== "killed" && !rec.seen && !rec.announced
|
|
343
|
-
&& st.ended >= since && under(rec.workdir))
|
|
344
|
-
.map((e) => e.rec);
|
|
363
|
+
return under;
|
|
345
364
|
}
|
|
346
365
|
|
|
347
366
|
/** The nearest folder at or above `dir` holding .git — or `dir` itself when there is none. */
|
package/terminal-viewport.mjs
CHANGED
|
@@ -589,6 +589,32 @@ export function dragEventKind(btn, press) {
|
|
|
589
589
|
return (b & 0b11) === 0 ? "press" : null;
|
|
590
590
|
}
|
|
591
591
|
|
|
592
|
+
/**
|
|
593
|
+
* Which way a drag should auto-scroll (GH #201): +1 = back into history (pointer on the top
|
|
594
|
+
* row or above it), -1 = toward the live tail (pointer on the last transcript row or below it),
|
|
595
|
+
* 0 = inside the view. `row` is the 1-based viewport row, `height` the transcript rows shown.
|
|
596
|
+
* Rows are clamped by the terminal, so "on the edge row" has to count as "past it".
|
|
597
|
+
*/
|
|
598
|
+
export function dragEdgeDirection(row, height) {
|
|
599
|
+
const r = Number(row) | 0;
|
|
600
|
+
const h = Math.max(1, Number(height) | 0);
|
|
601
|
+
if (h < 3) return 0; // too short to tell an edge from the middle
|
|
602
|
+
if (r <= 1) return 1;
|
|
603
|
+
if (r >= h) return -1;
|
|
604
|
+
return 0;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* The drag state after the view scrolled by `delta` lines (positive = back into history).
|
|
609
|
+
* The anchor is in SCREEN rows, and content moves `delta` rows down the screen when the view
|
|
610
|
+
* goes back, so the anchor moves with it — it may leave the screen, which is the point: the
|
|
611
|
+
* absolute row it names is unchanged. Pure; null in, null out.
|
|
612
|
+
*/
|
|
613
|
+
export function shiftDragAnchor(state, delta) {
|
|
614
|
+
if (!state || !delta) return state;
|
|
615
|
+
return { ...state, anchor: { row: state.anchor.row + delta, col: state.anchor.col } };
|
|
616
|
+
}
|
|
617
|
+
|
|
592
618
|
// The selection's colours (task #178). THE LOGO'S COLOUR, as a BACKGROUND — not as text.
|
|
593
619
|
//
|
|
594
620
|
// 105 is bright magenta, the sixteen-colour palette's purple, following the accent from cyan to
|