@gapi/gcli 1.8.271 → 1.8.273

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.
@@ -0,0 +1,14 @@
1
+ ## 2026-11-18 - local-workspaces: Browser terminal PTY starts at the browser's size (stty), not 80 columns
2
+
3
+ **Feature:** local-workspaces · **Type:** fix
4
+
5
+ - The shell under `script` asked its PTY for the size (80x24), not COLUMNS:
6
+ commands wrapped at 80 columns in a wide editor (seen in a cloud
7
+ workspace). `shellCommand(size)` now runs `stty cols C rows R; exec shell
8
+ -i` inside the PTY (linux `script -qfec`, macOS `script -q /dev/null
9
+ /bin/sh -c`). The size comes from the browser, so `dimension()` lets only
10
+ integers 10..1000 into the command line.
11
+ - Resize after start is still not passed (plan 36 follow-up).
12
+ - **Test:** `npx jest test/workspace-terminals.spec.ts --forceExit` (12).
13
+ - **Debug:** `stty size` in the terminal shows what the shell sees.
14
+ - **Verification:** 12/12, lint clean.
@@ -0,0 +1,18 @@
1
+ ## 2026-11-18 - local-workspaces: One-way terminal input + resize frames: typing never waits for a round trip
2
+
3
+ **Feature:** local-workspaces · **Type:** feat
4
+
5
+ - Tunnel frames `input` ({ sessionId, data }) and `resize` ({ sessionId,
6
+ cols, rows }) next to `approval`: handled in `WorkspaceConnection
7
+ .onTerminalNotice`, no reply. Before, every keystroke batch was a full
8
+ request/response to this machine (~400 ms through the free sandbox) and
9
+ the browser queued them. The backend sends these frames only to gcli
10
+ >= 1.8.273 (older ones get the request/response `terminal/input`).
11
+ - `TerminalManager.resize`: the shell's PTY (`/proc/<pid>/fd/0` on linux,
12
+ `ps -o tty=` on macOS) gets `stty -F <pts> cols C rows R`; the kernel sends
13
+ SIGWINCH. Only with a PTY (`script`); never throws.
14
+ - **Test:** `npx jest test/workspace-terminals.spec.ts --forceExit` (14):
15
+ real shell opens at 30x100, resize -> `stty size` = 40 150.
16
+ - **Debug:** `stty size` in the browser terminal; a frame for a closed
17
+ session is dropped silently.
18
+ - **Verification:** 14/14, lint clean.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gapi/gcli",
3
- "version": "1.8.271",
3
+ "version": "1.8.273",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Stradivario/gapi.git"
package/release/index.js CHANGED
@@ -324599,15 +324599,52 @@ ${this.text}` : this.text;
324599
324599
  });
324600
324600
 
324601
324601
  // src/commands/workspace/terminals.ts
324602
- function shellCommand() {
324603
- if (process.platform === "win32") {
324602
+ function shellTty(scriptPid) {
324603
+ try {
324604
+ if (process.platform === "linux") {
324605
+ const child = (0, import_fs13.readdirSync)("/proc").filter((name2) => /^\d+$/.test(name2)).find((pid) => {
324606
+ try {
324607
+ const stat2 = (0, import_fs13.readFileSync)(`/proc/${pid}/stat`, "utf8");
324608
+ return Number(stat2.slice(stat2.lastIndexOf(")") + 2).split(" ")[1]) === scriptPid;
324609
+ } catch {
324610
+ return false;
324611
+ }
324612
+ });
324613
+ if (!child) return null;
324614
+ const tty = (0, import_fs13.readlinkSync)(`/proc/${child}/fd/0`);
324615
+ return tty.startsWith("/dev/pts/") ? tty : null;
324616
+ }
324617
+ if (process.platform === "darwin") {
324618
+ const children = (0, import_child_process8.spawnSync)("pgrep", ["-P", String(scriptPid)], {
324619
+ encoding: "utf8"
324620
+ }).stdout.trim();
324621
+ const pid = children.split("\n")[0];
324622
+ if (!pid) return null;
324623
+ const tty = (0, import_child_process8.spawnSync)("ps", ["-o", "tty=", "-p", pid], {
324624
+ encoding: "utf8"
324625
+ }).stdout.trim();
324626
+ return tty && tty !== "??" ? `/dev/${tty}` : null;
324627
+ }
324628
+ } catch {
324629
+ }
324630
+ return null;
324631
+ }
324632
+ function dimension(value, fallback) {
324633
+ const n = Math.trunc(Number(value));
324634
+ return Number.isFinite(n) && n >= 10 && n <= 1e3 ? n : fallback;
324635
+ }
324636
+ function shellCommand(size = {}, platform2 = process.platform, hasScript = () => !(0, import_child_process8.spawnSync)("script", ["--version"]).error) {
324637
+ if (platform2 === "win32") {
324604
324638
  return [process.env.ComSpec || "cmd.exe", []];
324605
324639
  }
324606
324640
  const shell = process.env.SHELL || "/bin/sh";
324607
- if ((0, import_child_process8.spawnSync)("script", ["--version"]).error) {
324641
+ if (!hasScript()) {
324608
324642
  return [shell, ["-i"]];
324609
324643
  }
324610
- return process.platform === "darwin" ? ["script", ["-q", "/dev/null", shell, "-i"]] : ["script", ["-qfec", `${shell} -i`, "/dev/null"]];
324644
+ const cols = dimension(size.cols, 80);
324645
+ const rows = dimension(size.rows, 24);
324646
+ const start3 = `stty cols ${cols} rows ${rows} 2>/dev/null; exec ${shell} -i`;
324647
+ return platform2 === "darwin" ? ["script", ["-q", "/dev/null", "/bin/sh", "-c", start3]] : ["script", ["-qfec", start3, "/dev/null"]];
324611
324648
  }
324612
324649
  function kill(child) {
324613
324650
  try {
@@ -324655,7 +324692,7 @@ var init_terminals = __esm({
324655
324692
  );
324656
324693
  }
324657
324694
  const sessionId = (0, import_crypto3.randomUUID)();
324658
- const [command, args] = shellCommand();
324695
+ const [command, args] = shellCommand(size);
324659
324696
  const child = (0, import_child_process8.spawn)(command, args, {
324660
324697
  cwd: this.root,
324661
324698
  env: {
@@ -324693,6 +324730,34 @@ ${e2.message}\r
324693
324730
  child.stdin?.write(data);
324694
324731
  return { written: data.length };
324695
324732
  }
324733
+ /**
324734
+ * The browser terminal changed size: the shell's PTY gets it (`stty -F
324735
+ * <pts>`), and the kernel sends its process group SIGWINCH - programs
324736
+ * redraw. Only with a PTY (`script`); on plain pipes there is nothing to
324737
+ * resize. Never throws: a resize is cosmetic.
324738
+ */
324739
+ resize(sessionId, size) {
324740
+ const child = this.sessions.get(sessionId);
324741
+ if (!child?.pid) {
324742
+ return { resized: false };
324743
+ }
324744
+ const tty = shellTty(child.pid);
324745
+ if (!tty) {
324746
+ return { resized: false };
324747
+ }
324748
+ const cols = dimension(size.cols, 0);
324749
+ const rows = dimension(size.rows, 0);
324750
+ if (!cols || !rows) {
324751
+ return { resized: false };
324752
+ }
324753
+ const flag = process.platform === "darwin" ? "-f" : "-F";
324754
+ const result = (0, import_child_process8.spawnSync)(
324755
+ "stty",
324756
+ [flag, tty, "cols", String(cols), "rows", String(rows)],
324757
+ { stdio: "ignore" }
324758
+ );
324759
+ return { resized: result.status === 0 };
324760
+ }
324696
324761
  close(sessionId) {
324697
324762
  const child = this.sessions.get(sessionId);
324698
324763
  if (child) {
@@ -324902,6 +324967,10 @@ var init_connection2 = __esm({
324902
324967
  return request.method === "POST" && WORKSPACE_OPS.includes(op) ? null : `${request.method} ${request.path} is not allowed by this workspace`;
324903
324968
  }
324904
324969
  onNotice(request) {
324970
+ if (request.type === "input" || request.type === "resize") {
324971
+ this.onTerminalNotice(request);
324972
+ return;
324973
+ }
324905
324974
  if (request.type !== "approval") return;
324906
324975
  try {
324907
324976
  const { decision } = JSON.parse(request.body ?? "{}");
@@ -324911,6 +324980,21 @@ var init_connection2 = __esm({
324911
324980
  } catch {
324912
324981
  }
324913
324982
  }
324983
+ /** One-way terminal frames: keystrokes and size. Only for a session the
324984
+ browser opened (which needs --allow-terminal); anything else is
324985
+ ignored - there is no one to answer. */
324986
+ onTerminalNotice(request) {
324987
+ try {
324988
+ const body = JSON.parse(request.body ?? "{}");
324989
+ if (!body.sessionId) return;
324990
+ if (request.type === "input" && typeof body.data === "string") {
324991
+ this.terminals.input(body.sessionId, body.data);
324992
+ } else if (request.type === "resize") {
324993
+ this.terminals.resize(body.sessionId, body);
324994
+ }
324995
+ } catch {
324996
+ }
324997
+ }
324914
324998
  async serve(request, sender, signal) {
324915
324999
  const op = request.path.slice(WORKSPACE_PATH_PREFIX.length);
324916
325000
  let args = {};
@@ -326172,7 +326256,7 @@ if (!isWebContainer) {
326172
326256
  } else {
326173
326257
  }
326174
326258
  }
326175
- var version2 = true ? "1.8.270" : "development";
326259
+ var version2 = true ? "1.8.272" : "development";
326176
326260
  var main = (argv) => {
326177
326261
  import_commander.program.name("gcli").version(version2);
326178
326262
  commands.map((command) => command(import_commander.program));