@eum-agent/web-shell 1.1.0 → 1.2.0

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/dist/index.js CHANGED
@@ -1,16 +1,15 @@
1
1
  import { Changed, CloseParams, CloseTerminalsParams, CloseTerminalsResult, CreateParams, ListResult, OperationResult, OperationStatusesParams, OperationStatusesResult, RenameParams, RestartParams, RootsResult, TerminalInput, TerminalOpen, TerminalOutput, TerminalReady, TerminalSummary, WorkspaceId } from "./schema.js";
2
+ import nodePath, { dirname } from "node:path";
2
3
  import { existsSync } from "node:fs";
3
4
  import { userInfo } from "node:os";
4
5
  import { fileURLToPath } from "node:url";
5
6
  import { z } from "zod";
6
7
  import { randomUUID } from "node:crypto";
7
- import nodePath from "node:path";
8
8
  //#region src/output.ts
9
9
  const WINDOW = 4194304;
10
10
  const BLOCK = 8192;
11
11
  const HIGH = 524288;
12
12
  const LOW = 131072;
13
- /** Retains bounded UTF-8 replay and controls each independent consumer's output pressure. */
14
13
  function createTerminalOutput(handle, summary, attachments) {
15
14
  const chunks = [];
16
15
  const observers = /* @__PURE__ */ new Map();
@@ -135,7 +134,6 @@ function createTerminalOutput(handle, summary, attachments) {
135
134
  for (const observer of observers.values()) pump(observer);
136
135
  });
137
136
  return {
138
- /** Atomically snapshots replay and subscribes one observer, with explicit writer ownership. */
139
137
  open(params, context) {
140
138
  if (ended || summary.status === "ended") throw new TerminalError("terminal-ended");
141
139
  if (summary.status !== "running") throw new TerminalError("terminal-not-running");
@@ -213,20 +211,17 @@ function createTerminalOutput(handle, summary, attachments) {
213
211
  });
214
212
  }
215
213
  },
216
- /** Removes this observation only; the physical process remains owned by the directory. */
217
214
  async close() {
218
215
  detach(observer);
219
216
  }
220
217
  };
221
218
  },
222
- /** Publishes current status to attached consumers without adding replay history. */
223
219
  status() {
224
220
  for (const observer of observers.values()) send(observer, {
225
221
  kind: "status",
226
222
  terminal: structuredClone(summary)
227
223
  });
228
224
  },
229
- /** Releases replay bytes and attachments after physical process-group cleanup is confirmed. */
230
225
  end() {
231
226
  ended = true;
232
227
  unwatch();
@@ -245,8 +240,6 @@ function createTerminalOutput(handle, summary, attachments) {
245
240
  }
246
241
  //#endregion
247
242
  //#region src/path-semantics.ts
248
- /** Host path syntax only; resolved object identity remains the platform's responsibility. */
249
- /** Requires an independent absolute root, excluding Windows drive-relative and root-relative forms. */
250
243
  function isFullAbsolute(value, paths = nodePath) {
251
244
  if (value.includes("\0") || !paths.isAbsolute(value)) return false;
252
245
  if (paths.sep !== "\\") return true;
@@ -260,7 +253,6 @@ function isFullAbsolute(value, paths = nodePath) {
260
253
  "?"
261
254
  ].includes(server) && ![".", ".."].includes(share);
262
255
  }
263
- /** Compares canonical ancestor segments exactly; drive-letter syntax alone is case-insensitive. */
264
256
  function containsHostPath(root, value, paths = nodePath) {
265
257
  if (!isFullAbsolute(root, paths) || !isFullAbsolute(value, paths)) return false;
266
258
  const parts = (path) => {
@@ -277,13 +269,9 @@ function containsHostPath(root, value, paths = nodePath) {
277
269
  }
278
270
  //#endregion
279
271
  //#region src/provider.ts
280
- /** A bounded business failure without terminal output or raw environment details. */
281
272
  var TerminalError = class extends Error {
282
- /** Stable safe failure category exposed to the client. */
283
273
  code;
284
- /** Generic HTTP-like status used by the host client IO error mapping. */
285
274
  status;
286
- /** Defaults ordinary business conflicts to status 409. */
287
275
  constructor(code, status = 409) {
288
276
  super(code);
289
277
  this.name = "TerminalError";
@@ -291,7 +279,6 @@ var TerminalError = class extends Error {
291
279
  this.status = status;
292
280
  }
293
281
  };
294
- /** Constructs the owner-held terminal directory and bounded operation facts. */
295
282
  function createWebShell(options) {
296
283
  const identity = options.roots.availability();
297
284
  if (!identity.available) throw new TerminalError("unavailable", 503);
@@ -465,7 +452,6 @@ function createWebShell(options) {
465
452
  }));
466
453
  };
467
454
  return {
468
- /** Returns current independent workspace roots and physical availability. */
469
455
  async roots(workspaceId) {
470
456
  current();
471
457
  const snapshot = await options.roots.read(workspaceId);
@@ -479,7 +465,6 @@ function createWebShell(options) {
479
465
  ...!capability.available ? { reason: capability.reason } : !files.available ? { reason: files.reason } : {}
480
466
  };
481
467
  },
482
- /** Returns bounded summaries without creating or attaching a terminal. */
483
468
  list(workspaceId) {
484
469
  current();
485
470
  sweep();
@@ -489,7 +474,6 @@ function createWebShell(options) {
489
474
  terminals: [...terminals.values()].filter((value) => value.summary.workspaceId === workspaceId).map((value) => structuredClone(value.summary))
490
475
  };
491
476
  },
492
- /** Admits once per retained operation ID; connection cancellation does not cancel creation. */
493
477
  create(input) {
494
478
  const params = CreateParams.parse(input);
495
479
  return operation(params.operationId, JSON.stringify(["create", params]), async () => {
@@ -536,7 +520,6 @@ function createWebShell(options) {
536
520
  }
537
521
  });
538
522
  },
539
- /** Restarts once per operation ID after cleanup; preserves record/cursor and assigns a new runId. */
540
523
  restart(input) {
541
524
  const params = RestartParams.parse(input);
542
525
  return operation(params.operationId, JSON.stringify(["restart", params]), async () => {
@@ -612,7 +595,6 @@ function createWebShell(options) {
612
595
  }
613
596
  });
614
597
  },
615
- /** Trims one shared title without affecting its process, output or input ownership. */
616
598
  rename(input) {
617
599
  current();
618
600
  const params = RenameParams.parse(input);
@@ -625,7 +607,6 @@ function createWebShell(options) {
625
607
  notify(params.workspaceId);
626
608
  return structuredClone(terminal.summary);
627
609
  },
628
- /** Attaches one bounded observer; closing it leaves the terminal alive. */
629
610
  open(input, context) {
630
611
  current();
631
612
  if (input.instanceId !== identity.instanceId) throw new TerminalError("context-mismatch");
@@ -634,7 +615,6 @@ function createWebShell(options) {
634
615
  if (!terminal.flow) throw new TerminalError("terminal-ended");
635
616
  return terminal.flow.open(input, context);
636
617
  },
637
- /** Removes a terminal after confirmed PTY/group cleanup, retaining operation facts and failures. */
638
618
  closeTerminal(raw, changed = () => notify(raw.workspaceId)) {
639
619
  const input = CloseParams.parse(raw);
640
620
  return operation(input.operationId, JSON.stringify(["close", input]), async () => {
@@ -654,7 +634,6 @@ function createWebShell(options) {
654
634
  return terminal.summary;
655
635
  });
656
636
  },
657
- /** Queries retained execution facts; unknown never replays an operation. */
658
637
  operationStatus(input) {
659
638
  current();
660
639
  sweep();
@@ -668,7 +647,6 @@ function createWebShell(options) {
668
647
  status: "unknown"
669
648
  };
670
649
  },
671
- /** Stops admission and awaits all late creations and owned physical cleanup. */
672
650
  async close() {
673
651
  stopped = true;
674
652
  await Promise.allSettled([...operations.values()].map((value) => value.promise));
@@ -681,8 +659,6 @@ function createWebShell(options) {
681
659
  }
682
660
  //#endregion
683
661
  //#region src/collections.ts
684
- /** Bounded terminal collections preserve independent retained physical outcomes. */
685
- /** Runs owner-bound members in input order; actual oversize results fail only their member. */
686
662
  async function terminalCollection(targets, signal, work, maxItemBytes = Math.floor(8380416 / targets.length)) {
687
663
  const results = [];
688
664
  for (const [index, target] of targets.entries()) {
@@ -716,8 +692,6 @@ async function terminalCollection(targets, signal, work, maxItemBytes = Math.flo
716
692
  }
717
693
  //#endregion
718
694
  //#region src/index.ts
719
- /** Sessionless host-account terminals; registration exposes no Agent tools or approvals. */
720
- /** Registers one activation's terminal directory and awaited shutdown drain. */
721
695
  function registerWebShell(ctx) {
722
696
  let account;
723
697
  try {
@@ -833,7 +807,10 @@ function registerWebShell(ctx) {
833
807
  open: (params, pipe) => provider.open(params, pipe)
834
808
  });
835
809
  const module = fileURLToPath(new URL("../ui/ui.js", import.meta.url));
836
- if (existsSync(module)) ctx.client.registerUi({ module });
810
+ if (existsSync(module)) ctx.client.registerPackageFiles({
811
+ root: dirname(module),
812
+ entry: "ui.js"
813
+ });
837
814
  }
838
815
  const plugin = {
839
816
  name: "@eum-agent/web-shell",
package/dist/schema.js CHANGED
@@ -1,20 +1,13 @@
1
1
  import { z } from "zod";
2
2
  //#region src/schema.ts
3
- /** WebShell's browser-safe wire contract; the host owns authentication and stream envelopes. */
4
- /** Explicit workspace identity, independent of a selected chat. */
5
3
  const WorkspaceId = z.string().min(1).max(1024).refine((value) => !/[/\\]/u.test(value) && !Array.from(value).some((c) => c.charCodeAt(0) < 32));
6
- /** Full canonical-root digest. */
7
4
  const RootId = z.string().regex(/^[a-f0-9]{64}$/);
8
- /** Literal relative initial directory, with the empty path selecting its root. */
9
5
  const RelativePath = z.string().max(4096).refine((value) => value === "" || value.split("/").every((part) => part !== "" && part !== "." && part !== ".." && !/[\\]/u.test(part) && !Array.from(part).some((c) => c.charCodeAt(0) < 32 || c.charCodeAt(0) === 127)));
10
- /** Physical terminal dimensions. */
11
6
  const Dimension = z.number().int().min(1).max(1e3);
12
- /** A bounded public diagnostic; never contains output or exception details. */
13
7
  const AccessError = z.object({
14
8
  code: z.string().max(64),
15
9
  message: z.string().max(256)
16
10
  }).strict();
17
- /** State of a retained terminal; runId identifies its current physical PTY, cwd its initial directory. */
18
11
  const TerminalSummary = z.object({
19
12
  id: z.uuid(),
20
13
  runId: z.uuid(),
@@ -40,7 +33,6 @@ const TerminalSummary = z.object({
40
33
  cleanupWarnings: z.array(z.string().max(256)).max(32).optional(),
41
34
  truncated: z.boolean().optional()
42
35
  }).strict();
43
- /** Independent roots and current host capability. */
44
36
  const RootsResult = z.object({
45
37
  gatewayId: z.uuid(),
46
38
  instanceId: z.uuid(),
@@ -53,18 +45,15 @@ const RootsResult = z.object({
53
45
  path: z.string()
54
46
  }).strict())
55
47
  }).strict();
56
- /** Workspace terminal directory for this Gateway process. */
57
48
  const ListResult = z.object({
58
49
  gatewayId: z.uuid(),
59
50
  instanceId: z.uuid(),
60
51
  terminals: z.array(TerminalSummary).max(48)
61
52
  }).strict();
62
- /** A committed directory mutation; clients reread the matching workspace instead of replaying it. */
63
53
  const Changed = z.object({
64
54
  instanceId: z.uuid(),
65
55
  workspaceId: WorkspaceId
66
56
  }).strict();
67
- /** UUID operation facts retained only within the bounded query window. */
68
57
  const OperationResult = z.object({
69
58
  operationId: z.uuid(),
70
59
  instanceId: z.uuid(),
@@ -77,7 +66,6 @@ const OperationResult = z.object({
77
66
  terminal: TerminalSummary.optional(),
78
67
  error: AccessError.optional()
79
68
  }).strict();
80
- /** Defaults to workspace HOME; an explicit root/path selects another admitted initial directory. */
81
69
  const CreateParams = z.object({
82
70
  workspaceId: WorkspaceId,
83
71
  rootId: RootId.optional(),
@@ -86,7 +74,6 @@ const CreateParams = z.object({
86
74
  rows: Dimension,
87
75
  operationId: z.uuid()
88
76
  }).strict();
89
- /** Close selection; endedRunId limits automatic removal to that already ended run. */
90
77
  const CloseParams = z.object({
91
78
  instanceId: z.uuid(),
92
79
  workspaceId: WorkspaceId,
@@ -94,14 +81,12 @@ const CloseParams = z.object({
94
81
  operationId: z.uuid(),
95
82
  endedRunId: z.uuid().optional()
96
83
  }).strict();
97
- /** Metadata edit for the current Gateway/workspace; names are trimmed, nonblank and single-line. */
98
84
  const RenameParams = z.object({
99
85
  instanceId: z.uuid(),
100
86
  workspaceId: WorkspaceId,
101
87
  terminalId: z.uuid(),
102
88
  title: z.string().trim().min(1).max(80).refine((value) => !Array.from(value).some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127))
103
89
  }).strict();
104
- /** Restarts a cleaned ended record in its original directory; omitted dimensions retain its size. */
105
90
  const RestartParams = z.object({
106
91
  instanceId: z.uuid(),
107
92
  workspaceId: WorkspaceId,
@@ -110,12 +95,10 @@ const RestartParams = z.object({
110
95
  cols: Dimension.optional(),
111
96
  rows: Dimension.optional()
112
97
  }).strict();
113
- /** Read-only retained-operation query. */
114
98
  const OperationStatusParams = z.object({
115
99
  instanceId: z.uuid(),
116
100
  operationId: z.uuid()
117
101
  }).strict();
118
- /** One authenticated observation of an existing terminal. */
119
102
  const TerminalOpen = z.object({
120
103
  instanceId: z.uuid(),
121
104
  workspaceId: WorkspaceId,
@@ -123,7 +106,6 @@ const TerminalOpen = z.object({
123
106
  cursor: z.number().int().nonnegative().optional(),
124
107
  desiredInput: z.boolean()
125
108
  }).strict();
126
- /** Atomic ready metadata preceding any replay or live output. */
127
109
  const TerminalReady = z.object({
128
110
  terminal: TerminalSummary,
129
111
  subscriptionId: z.uuid(),
@@ -133,7 +115,6 @@ const TerminalReady = z.object({
133
115
  lastCursor: z.number().int().nonnegative(),
134
116
  truncated: z.boolean()
135
117
  }).strict();
136
- /** Control messages are independent of output consumption. */
137
118
  const TerminalInput = z.discriminatedUnion("kind", [
138
119
  z.object({
139
120
  kind: z.literal("write"),
@@ -152,7 +133,6 @@ const TerminalInput = z.discriminatedUnion("kind", [
152
133
  cursor: z.number().int().nonnegative()
153
134
  }).strict()
154
135
  ]);
155
- /** Output blocks and explicit history/control state. */
156
136
  const TerminalOutput = z.discriminatedUnion("kind", [
157
137
  z.object({
158
138
  kind: z.literal("output"),
@@ -183,7 +163,6 @@ const CloseMember = CloseParams.omit({
183
163
  instanceId: true,
184
164
  workspaceId: true
185
165
  });
186
- /** Independent close intents retain their UUID and normalized input regardless of array position. */
187
166
  const CloseTerminalsParams = z.object({
188
167
  instanceId: z.uuid(),
189
168
  workspaceId: WorkspaceId,
@@ -203,7 +182,6 @@ const CloseTerminalsParams = z.object({
203
182
  identities.set(member.operationId, value);
204
183
  }
205
184
  });
206
- /** Read-only status collections reject declared response costs before reading any retained fact. */
207
185
  const OperationStatusesParams = z.object({
208
186
  instanceId: z.uuid(),
209
187
  operationIds: z.array(z.uuid()).min(1).max(64),
@@ -228,9 +206,7 @@ function collectionResult(target) {
228
206
  error: AccessError
229
207
  }).strict()])).max(64) }).strict();
230
208
  }
231
- /** Ordered close outcomes preserve physical failure facts independently. */
232
209
  const CloseTerminalsResult = collectionResult(CloseMember);
233
- /** Ordered retained facts include unknown operations without replaying them. */
234
210
  const OperationStatusesResult = collectionResult(z.uuid());
235
211
  //#endregion
236
212
  export { AccessError, Changed, CloseParams, CloseTerminalsParams, CloseTerminalsResult, CreateParams, Dimension, ListResult, OperationResult, OperationStatusParams, OperationStatusesParams, OperationStatusesResult, RelativePath, RenameParams, RestartParams, RootId, RootsResult, TerminalInput, TerminalOpen, TerminalOutput, TerminalReady, TerminalSummary, WorkspaceId };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "en-US": "Terminal",
5
5
  "zh-CN": "终端"
6
6
  },
7
- "version": "1.1.0",
7
+ "version": "1.2.0",
8
8
  "type": "module",
9
9
  "description": "Sessionless host-account interactive terminals",
10
10
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  "lucide-react": "^1.40.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@eum-agent/plugin": "1.1.0",
31
+ "@eum-agent/plugin": "1.2.0",
32
32
  "@eum-agent/runtime": "1.0.0",
33
33
  "@eum-agent/protocol": "1.0.0",
34
34
  "@types/react": "^19.2.18",
@@ -37,7 +37,7 @@
37
37
  "react-dom": "^19.2.0",
38
38
  "vite": "^8.2.2",
39
39
  "@testing-library/react": "^16.3.3",
40
- "@eum-agent/infra-local": "1.0.1"
40
+ "@eum-agent/infra-local": "1.2.0"
41
41
  },
42
42
  "yaoguang": {
43
43
  "description": {
@@ -47,7 +47,7 @@
47
47
  "dependencies": {},
48
48
  "kind": "extension",
49
49
  "foundationDependencies": {
50
- "@eum-agent/infra-local": "1.0.1"
50
+ "@eum-agent/infra-local": "1.2.0"
51
51
  }
52
52
  },
53
53
  "scripts": {
package/ui/ui.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { SettingsPreview, useDeviceFonts, useViewRecord } from "@eum-agent/host/framework";
1
2
  import { createContext, createElement, forwardRef, useContext, useEffect, useRef, useState, useSyncExternalStore } from "react";
2
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { SettingsPreview, useDeviceFonts } from "@eum-agent/host/framework";
4
4
  //#region ../../../node_modules/.pnpm/@xterm+xterm@6.0.0/node_modules/@xterm/xterm/css/xterm.css?inline
5
5
  var xterm_default = "/**\n * Copyright (c) 2014 The xterm.js authors. All rights reserved.\n * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)\n * https://github.com/chjj/term.js\n * @license MIT\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n *\n * Originally forked from (with the author's permission):\n * Fabrice Bellard's javascript vt100 for jslinux:\n * http://bellard.org/jslinux/\n * Copyright (c) 2011 Fabrice Bellard\n * The original design remains. The terminal itself\n * has been extended to include xterm CSI codes, among\n * other features.\n */\n\n/**\n * Default styles for xterm.js\n */\n\n.xterm {\n cursor: text;\n position: relative;\n user-select: none;\n -ms-user-select: none;\n -webkit-user-select: none;\n}\n\n.xterm.focus,\n.xterm:focus {\n outline: none;\n}\n\n.xterm .xterm-helpers {\n position: absolute;\n top: 0;\n /**\n * The z-index of the helpers must be higher than the canvases in order for\n * IMEs to appear on top.\n */\n z-index: 5;\n}\n\n.xterm .xterm-helper-textarea {\n padding: 0;\n border: 0;\n margin: 0;\n /* Move textarea out of the screen to the far left, so that the cursor is not visible */\n position: absolute;\n opacity: 0;\n left: -9999em;\n top: 0;\n width: 0;\n height: 0;\n z-index: -5;\n /** Prevent wrapping so the IME appears against the textarea at the correct position */\n white-space: nowrap;\n overflow: hidden;\n resize: none;\n}\n\n.xterm .composition-view {\n /* TODO: Composition position got messed up somewhere */\n background: #000;\n color: #FFF;\n display: none;\n position: absolute;\n white-space: nowrap;\n z-index: 1;\n}\n\n.xterm .composition-view.active {\n display: block;\n}\n\n.xterm .xterm-viewport {\n /* On OS X this is required in order for the scroll bar to appear fully opaque */\n background-color: #000;\n overflow-y: scroll;\n cursor: default;\n position: absolute;\n right: 0;\n left: 0;\n top: 0;\n bottom: 0;\n}\n\n.xterm .xterm-screen {\n position: relative;\n}\n\n.xterm .xterm-screen canvas {\n position: absolute;\n left: 0;\n top: 0;\n}\n\n.xterm-char-measure-element {\n display: inline-block;\n visibility: hidden;\n position: absolute;\n top: 0;\n left: -9999em;\n line-height: normal;\n}\n\n.xterm.enable-mouse-events {\n /* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */\n cursor: default;\n}\n\n.xterm.xterm-cursor-pointer,\n.xterm .xterm-cursor-pointer {\n cursor: pointer;\n}\n\n.xterm.column-select.focus {\n /* Column selection mode */\n cursor: crosshair;\n}\n\n.xterm .xterm-accessibility:not(.debug),\n.xterm .xterm-message {\n position: absolute;\n left: 0;\n top: 0;\n bottom: 0;\n right: 0;\n z-index: 10;\n color: transparent;\n pointer-events: none;\n}\n\n.xterm .xterm-accessibility-tree:not(.debug) *::selection {\n color: transparent;\n}\n\n.xterm .xterm-accessibility-tree {\n font-family: monospace;\n user-select: text;\n white-space: pre;\n}\n\n.xterm .xterm-accessibility-tree > div {\n transform-origin: left;\n width: fit-content;\n}\n\n.xterm .live-region {\n position: absolute;\n left: -9999px;\n width: 1px;\n height: 1px;\n overflow: hidden;\n}\n\n.xterm-dim {\n /* Dim should not apply to background, so the opacity of the foreground color is applied\n * explicitly in the generated class and reset to 1 here */\n opacity: 1 !important;\n}\n\n.xterm-underline-1 { text-decoration: underline; }\n.xterm-underline-2 { text-decoration: double underline; }\n.xterm-underline-3 { text-decoration: wavy underline; }\n.xterm-underline-4 { text-decoration: dotted underline; }\n.xterm-underline-5 { text-decoration: dashed underline; }\n\n.xterm-overline {\n text-decoration: overline;\n}\n\n.xterm-overline.xterm-underline-1 { text-decoration: overline underline; }\n.xterm-overline.xterm-underline-2 { text-decoration: overline double underline; }\n.xterm-overline.xterm-underline-3 { text-decoration: overline wavy underline; }\n.xterm-overline.xterm-underline-4 { text-decoration: overline dotted underline; }\n.xterm-overline.xterm-underline-5 { text-decoration: overline dashed underline; }\n\n.xterm-strikethrough {\n text-decoration: line-through;\n}\n\n.xterm-screen .xterm-decoration-container .xterm-decoration {\n z-index: 6;\n position: absolute;\n}\n\n.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer {\n z-index: 7;\n}\n\n.xterm-decoration-overview-ruler {\n z-index: 8;\n position: absolute;\n top: 0;\n right: 0;\n pointer-events: none;\n}\n\n.xterm-decoration-top {\n z-index: 2;\n position: relative;\n}\n\n\n\n/* Derived from vs/base/browser/ui/scrollbar/media/scrollbar.css */\n\n/* xterm.js customization: Override xterm's cursor style */\n.xterm .xterm-scrollable-element > .scrollbar {\n cursor: default;\n}\n\n/* Arrows */\n.xterm .xterm-scrollable-element > .scrollbar > .scra {\n cursor: pointer;\n font-size: 11px !important;\n}\n\n.xterm .xterm-scrollable-element > .visible {\n opacity: 1;\n\n /* Background rule added for IE9 - to allow clicks on dom node */\n background:rgba(0,0,0,0);\n\n transition: opacity 100ms linear;\n /* In front of peek view */\n z-index: 11;\n}\n.xterm .xterm-scrollable-element > .invisible {\n opacity: 0;\n pointer-events: none;\n}\n.xterm .xterm-scrollable-element > .invisible.fade {\n transition: opacity 800ms linear;\n}\n\n/* Scrollable Content Inset Shadow */\n.xterm .xterm-scrollable-element > .shadow {\n position: absolute;\n display: none;\n}\n.xterm .xterm-scrollable-element > .shadow.top {\n display: block;\n top: 0;\n left: 3px;\n height: 3px;\n width: 100%;\n box-shadow: var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset;\n}\n.xterm .xterm-scrollable-element > .shadow.left {\n display: block;\n top: 3px;\n left: 0;\n height: 100%;\n width: 3px;\n box-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;\n}\n.xterm .xterm-scrollable-element > .shadow.top-left-corner {\n display: block;\n top: 0;\n left: 0;\n height: 3px;\n width: 3px;\n}\n.xterm .xterm-scrollable-element > .shadow.top.left {\n box-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;\n}\n";
6
6
  //#endregion
@@ -17443,6 +17443,7 @@ function TerminalScreen({ ctx, store, preferences, terminal, visible, renaming,
17443
17443
  latestTerminal.current = terminal;
17444
17444
  const ended = terminal.status === "ended";
17445
17445
  const cursor = useRef(0);
17446
+ const restoreReading = useRef(() => {});
17446
17447
  const [dimensions, setDimensions] = useState({
17447
17448
  cols: terminal.cols,
17448
17449
  rows: terminal.rows
@@ -17521,6 +17522,67 @@ function TerminalScreen({ ctx, store, preferences, terminal, visible, renaming,
17521
17522
  search.current = void 0;
17522
17523
  };
17523
17524
  }, [ctx, terminal.id]);
17525
+ useEffect(() => {
17526
+ const xterm = display.current;
17527
+ const container = element.current;
17528
+ if (!xterm || !container) return;
17529
+ const identity = store.get().identity;
17530
+ const scope = identity ? [
17531
+ identity.gatewayId,
17532
+ terminal.workspaceId,
17533
+ terminal.id,
17534
+ terminal.runId,
17535
+ "reading"
17536
+ ] : null;
17537
+ const raw = scope ? ctx.viewState.read(scope) : void 0;
17538
+ const saved = raw && typeof raw === "object" ? raw : {};
17539
+ let restoring = saved.following === false && typeof saved.cursor === "number" && typeof saved.distance === "number" && Number.isFinite(saved.distance);
17540
+ let parsed = false;
17541
+ let lastReading;
17542
+ const saveReading = () => {
17543
+ if (!scope || restoring || !parsed) return;
17544
+ if (display.current !== xterm) {
17545
+ if (lastReading) ctx.viewState.write(scope, lastReading);
17546
+ return;
17547
+ }
17548
+ const buffer = xterm.buffer.active;
17549
+ lastReading = {
17550
+ following: buffer.viewportY >= buffer.baseY,
17551
+ distance: Math.max(0, buffer.baseY - buffer.viewportY),
17552
+ cursor: cursor.current
17553
+ };
17554
+ ctx.viewState.write(scope, lastReading);
17555
+ };
17556
+ restoreReading.current = (consumed) => {
17557
+ parsed = true;
17558
+ if (restoring && consumed >= saved.cursor) {
17559
+ xterm.scrollToLine(Math.max(0, xterm.buffer.active.baseY - saved.distance));
17560
+ restoring = false;
17561
+ }
17562
+ saveReading();
17563
+ };
17564
+ const intent = () => {
17565
+ restoring = false;
17566
+ };
17567
+ container.addEventListener("wheel", intent, { passive: true });
17568
+ container.addEventListener("pointerdown", intent);
17569
+ container.addEventListener("keydown", intent);
17570
+ const scrolling = xterm.onScroll(saveReading);
17571
+ return () => {
17572
+ saveReading();
17573
+ restoreReading.current = () => {};
17574
+ scrolling.dispose();
17575
+ container.removeEventListener("wheel", intent);
17576
+ container.removeEventListener("pointerdown", intent);
17577
+ container.removeEventListener("keydown", intent);
17578
+ };
17579
+ }, [
17580
+ ctx,
17581
+ store,
17582
+ terminal.id,
17583
+ terminal.runId,
17584
+ terminal.workspaceId
17585
+ ]);
17524
17586
  useEffect(() => {
17525
17587
  const xterm = display.current;
17526
17588
  if (!xterm) return;
@@ -17617,7 +17679,10 @@ function TerminalScreen({ ctx, store, preferences, terminal, visible, renaming,
17617
17679
  cursor: cursor.current,
17618
17680
  consumed: (value) => {
17619
17681
  const current = store.get();
17620
- if (display.current === xterm && !ctx.signal.aborted && current.workspaceId === observing.workspaceId && current.identity?.instanceId === observing.instanceId && current.terminals.some((terminal) => terminal.id === observing.id)) cursor.current = Math.max(cursor.current, value);
17682
+ if (display.current === xterm && !ctx.signal.aborted && current.workspaceId === observing.workspaceId && current.identity?.instanceId === observing.instanceId && current.terminals.some((terminal) => terminal.id === observing.id)) {
17683
+ cursor.current = Math.max(cursor.current, value);
17684
+ restoreReading.current(value);
17685
+ }
17621
17686
  },
17622
17687
  changed: (value) => {
17623
17688
  if (applies()) {
@@ -17884,23 +17949,28 @@ function TerminalScreen({ ctx, store, preferences, terminal, visible, renaming,
17884
17949
  /** Session navigation and terminal observations share the Logo workspace context. */
17885
17950
  function ShellPage({ ctx, store, preferences = store.preferences }) {
17886
17951
  const state = useSyncExternalStore(store.subscribe, store.get);
17887
- const [active, setActive] = useState("");
17952
+ const scope = state.identity && state.workspaceId ? [state.identity.gatewayId, state.workspaceId] : null;
17953
+ const [active, setActive] = useViewRecord(ctx.viewState, scope && [...scope, "active"], "", (value) => typeof value === "string" ? value : "");
17888
17954
  const previous = useRef([]);
17889
- const [query, setQuery] = useState("");
17955
+ const [query, setQuery] = useViewRecord(ctx.viewState, scope && [...scope, "filter"], "", (value) => typeof value === "string" ? value : "");
17890
17956
  const [drawer, setDrawer] = useState(false);
17891
17957
  const [editing, setEditing] = useState([]);
17892
17958
  useEffect(() => {
17893
17959
  store.reload();
17894
17960
  }, [store]);
17895
17961
  useEffect(() => {
17962
+ if (!state.roots && state.terminals.length === 0) return;
17896
17963
  if (!state.terminals.some((terminal) => terminal.id === active)) {
17897
17964
  const index = Math.max(0, previous.current.indexOf(active));
17898
17965
  setActive(state.terminals[Math.min(index, state.terminals.length - 1)]?.id ?? "");
17899
17966
  }
17900
17967
  previous.current = state.terminals.map((terminal) => terminal.id);
17901
- }, [active, state.terminals]);
17968
+ }, [
17969
+ active,
17970
+ state.terminals,
17971
+ state.roots
17972
+ ]);
17902
17973
  useEffect(() => {
17903
- setQuery("");
17904
17974
  setDrawer(false);
17905
17975
  setEditing([]);
17906
17976
  }, [state.workspaceId]);
@@ -17909,8 +17979,9 @@ function ShellPage({ ctx, store, preferences = store.preferences }) {
17909
17979
  setActive(state.createdTerminalId);
17910
17980
  setQuery("");
17911
17981
  setDrawer(false);
17982
+ store.acknowledgeCreatedTerminal(state.createdTerminalId);
17912
17983
  }
17913
- }, [state.createdTerminalId]);
17984
+ }, [state.createdTerminalId, store]);
17914
17985
  const { Button, EmptyState, Icon, Input, StatusBarArea } = ctx.ui;
17915
17986
  const t = ctx.i18n.t;
17916
17987
  const create = () => {
@@ -18822,6 +18893,10 @@ function createShellStore(ctx, suppliedPreferences) {
18822
18893
  },
18823
18894
  reload,
18824
18895
  reloadWorkspace,
18896
+ /** Consumes a creation focus request once, so remounts restore the saved selection. */
18897
+ acknowledgeCreatedTerminal(id) {
18898
+ if (state.createdTerminalId === id) patch({ createdTerminalId: void 0 });
18899
+ },
18825
18900
  recoverRestart,
18826
18901
  launcher,
18827
18902
  dispose,