@gapi/gcli 1.8.272 → 1.8.274

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,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.
@@ -0,0 +1,11 @@
1
+ ## 2026-11-18 - local-workspaces: Workspace protocol 2: announces one-way terminal frames
2
+
3
+ **Feature:** local-workspaces · **Type:** fix
4
+
5
+ - `WORKSPACE_VERSION` = `gcli-workspace/2` (`clientVersion` on every
6
+ heartbeat): the backend sends one-way `input` / `resize` frames only to
7
+ protocol 2+. It cannot tell from an npm version - gcli never reported one
8
+ (1.8.273 had the frames but still said /1, so it got request/response).
9
+ - **Test:** a workspace record's `clientVersion` after `gcli workspace:start`.
10
+ - **Debug:** `/1` = old gcli: keystrokes go request/response, no resize.
11
+ - **Verification:** tsc; the frames themselves: workspace-terminals spec (14).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gapi/gcli",
3
- "version": "1.8.272",
3
+ "version": "1.8.274",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Stradivario/gapi.git"
package/release/index.js CHANGED
@@ -324599,6 +324599,36 @@ ${this.text}` : this.text;
324599
324599
  });
324600
324600
 
324601
324601
  // src/commands/workspace/terminals.ts
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
+ }
324602
324632
  function dimension(value, fallback) {
324603
324633
  const n = Math.trunc(Number(value));
324604
324634
  return Number.isFinite(n) && n >= 10 && n <= 1e3 ? n : fallback;
@@ -324700,6 +324730,34 @@ ${e2.message}\r
324700
324730
  child.stdin?.write(data);
324701
324731
  return { written: data.length };
324702
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
+ }
324703
324761
  close(sessionId) {
324704
324762
  const child = this.sessions.get(sessionId);
324705
324763
  if (child) {
@@ -324909,6 +324967,10 @@ var init_connection2 = __esm({
324909
324967
  return request.method === "POST" && WORKSPACE_OPS.includes(op) ? null : `${request.method} ${request.path} is not allowed by this workspace`;
324910
324968
  }
324911
324969
  onNotice(request) {
324970
+ if (request.type === "input" || request.type === "resize") {
324971
+ this.onTerminalNotice(request);
324972
+ return;
324973
+ }
324912
324974
  if (request.type !== "approval") return;
324913
324975
  try {
324914
324976
  const { decision } = JSON.parse(request.body ?? "{}");
@@ -324918,6 +324980,21 @@ var init_connection2 = __esm({
324918
324980
  } catch {
324919
324981
  }
324920
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
+ }
324921
324998
  async serve(request, sender, signal) {
324922
324999
  const op = request.path.slice(WORKSPACE_PATH_PREFIX.length);
324923
325000
  let args = {};
@@ -325241,7 +325318,7 @@ var init_start4 = __esm({
325241
325318
  init_config2();
325242
325319
  init_connection2();
325243
325320
  init_policy();
325244
- WORKSPACE_VERSION = "gcli-workspace/1";
325321
+ WORKSPACE_VERSION = "gcli-workspace/2";
325245
325322
  csv = (value) => (value ?? "").split(",").map((v) => v.trim()).filter(Boolean);
325246
325323
  resolveWorkspace = async (root, cmd) => {
325247
325324
  if (cmd.token) {
@@ -326179,7 +326256,7 @@ if (!isWebContainer) {
326179
326256
  } else {
326180
326257
  }
326181
326258
  }
326182
- var version2 = true ? "1.8.271" : "development";
326259
+ var version2 = true ? "1.8.273" : "development";
326183
326260
  var main = (argv) => {
326184
326261
  import_commander.program.name("gcli").version(version2);
326185
326262
  commands.map((command) => command(import_commander.program));