dsh-remote-vs 0.20.1 → 0.21.1

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/README.en.md CHANGED
@@ -37,9 +37,9 @@ dsh plugin --profile web add dsh-remote-vs
37
37
  (From npm, recommended; installing straight from the repository also works:
38
38
  `dsh plugin --profile web add github:xiray-xia/dsh-remote-vs`.)
39
39
 
40
- **Requires DSH `0.2.2-alpha.3` or newer and below `0.3.0`** (`engines.dsh` enforces the range;
41
- **tested on `0.2.2-alpha.3` and `0.2.2-rc.1`**). On Host `0.2.2-alpha.2` use plugin `0.17.0` (or
42
- upgrade DSH first); the `0.2.1-rc.2` generation needs `0.9.3`. `--profile web` selects which profile to install into —
40
+ **Requires DSH `0.2.2-rc.2` or newer and below `0.3.0`** (`engines.dsh` enforces the range;
41
+ **adapted to and typechecked against `0.2.2-rc.2`**). On Host `0.2.2-alpha.3` / `0.2.2-rc.1` use plugin `0.20.1`; the
42
+ `0.2.2-alpha.2` generation needs `0.17.0` and the `0.2.1-rc.2` generation needs `0.9.3`. `--profile web` selects which profile to install into —
43
43
  this is a Web plugin, so it has to go into the profile your Web GUI runs from (`web` is
44
44
  the common name; use your own profile's name). Desktop uses the reserved `desktop`
45
45
  profile instead — see [Desktop](#desktop-dsh-desktop) below.
@@ -74,7 +74,7 @@ Install either way:
74
74
  `desktop` is reserved for the Electron application: an **npm-installed `dsh` cannot manage
75
75
  it** (it answers `profile "desktop" is managed exclusively by the Electron application`),
76
76
  so one of the two routes above is required. The Desktop release version equals the DSH
77
- runtime it bundles, and it must satisfy `engines.dsh` (`>=0.2.2-alpha.3`; check About);
77
+ runtime it bundles, and it must satisfy `engines.dsh` (`>=0.2.2-rc.2`; check About);
78
78
  older releases make the Plugins page refuse the install. Desktop opens no visible Web
79
79
  port, but the plugin's HTTP routes and terminal socket are forwarded through Desktop's
80
80
  Host (the terminal resolves its address from `__DSH_TRANSPORT__.streamBaseUrl`), so no
@@ -220,7 +220,7 @@ dsh_remote_vs/
220
220
  ├── vendor/dsh-remote-helpers/ # helper seeds (shipped, seeded into cache at startup, see below)
221
221
  ├── docs/ # local-only working docs (only docs/media/ screenshots ship)
222
222
  │ ├── MAINTENANCE.md # local-only (.gitignore), not shipped: upgrade impact, checklist, pitfalls, release
223
- │ ├── VERSION-HISTORY.md # local-only: per-release change log (0.7.1 → 0.20.0)
223
+ │ ├── VERSION-HISTORY.md # local-only: per-release change log (0.7.1 → 0.21.1)
224
224
  │ └── GATES.md # local-only: local gate inventory and measured assertion counts
225
225
  ├── locale/ # bilingual plugin metadata
226
226
  └── lib/ # build output (**must be committed**; only .map is ignored; restart after link install)
package/README.md CHANGED
@@ -34,8 +34,8 @@ dsh plugin --profile web add dsh-remote-vs
34
34
 
35
35
  (从 npm 装,推荐;也可以直接跟仓库装:`dsh plugin --profile web add github:xiray-xia/dsh-remote-vs`。)
36
36
 
37
- **需要 DSH `0.2.2-alpha.3` 及以上、`0.3.0` 以下**(`engines.dsh` 门到底;已在 `0.2.2-alpha.3` 与 `0.2.2-rc.1` 上验证)。
38
- Host 仍是 `0.2.2-alpha.2` 的请用插件 `0.17.0`(或先把 DSH 升到 `0.2.2-alpha.3`);`0.2.1-rc.2` 一代请用 `0.9.3`。
37
+ **需要 DSH `0.2.2-rc.2` 及以上、`0.3.0` 以下**(`engines.dsh` 门到底;已按 rc.2 适配并通过类型检查与本地全量门禁)。
38
+ Host 仍是 `0.2.2-alpha.3` / `0.2.2-rc.1` 的请用插件 `0.20.1`;`0.2.2-alpha.2` 一代请用 `0.17.0`;`0.2.1-rc.2` 一代请用 `0.9.3`。
39
39
  `--profile web` 指明装进哪个 profile —— 本插件是 Web 插件,
40
40
  要装进 Web GUI 所用的那个(`web` 是常见命名,以你自己的 profile 名为准);
41
41
  桌面端用的是保留 profile `desktop`,见下面「桌面端」。
@@ -63,7 +63,7 @@ Host 仍是 `0.2.2-alpha.2` 的请用插件 `0.17.0`(或先把 DSH 升到 `0.2
63
63
  注意:`desktop` 是桌面端独占的保留 profile,**npm 全局安装的 `dsh` 不能管理它**
64
64
  (会报 `profile "desktop" is managed exclusively by the Electron application`),
65
65
  只能走上面两条路径。桌面端的版本号等于它捆绑的 DSH 运行时版本,同样要满足
66
- `engines.dsh` 要求(`>=0.2.2-alpha.3`,关于面板可看);低于该版本时插件页会直接拒绝
66
+ `engines.dsh` 要求(`>=0.2.2-rc.2`,关于面板可看);低于该版本时插件页会直接拒绝
67
67
  安装。桌面端没有可见的 Web 端口,但本插件的 HTTP 路由与终端 socket 都经桌面端的
68
68
  Host 转发(终端按 `__DSH_TRANSPORT__.streamBaseUrl` 解析地址),无需额外设置。
69
69
 
@@ -205,7 +205,7 @@ dsh_remote_vs/
205
205
  ├── vendor/dsh-remote-helpers/ # helper 种子(随包发布,启动铺缓存,见下)
206
206
  ├── docs/ # 本地工作文档(不推送 GitHub;只有 docs/media/ 的截图随仓库公开)
207
207
  │ ├── MAINTENANCE.md # 本地私有(.gitignore,不入库):升级影响面/检查清单/踩坑/发布流程
208
- │ ├── VERSION-HISTORY.md # 本地私有:逐版本变更纪要(0.7.1 → 0.20.0)
208
+ │ ├── VERSION-HISTORY.md # 本地私有:逐版本变更纪要(0.7.1 → 0.21.1)
209
209
  │ └── GATES.md # 本地私有:本地门禁清单与实跑条数
210
210
  ├── locale/ # 插件元信息双语
211
211
  └── lib/ # 构建产物(**必须入库**,只有 .map 忽略;link 安装后重启即生效)
package/cordis.patch.yml CHANGED
@@ -54,6 +54,9 @@
54
54
  inject: [localFileReferences, remoteWorlds]
55
55
 
56
56
  # Remote agent preset, bound to this bundle's lifecycle.
57
+ # Mirrored from preset-standard @ dsh 0.2.2-rc.2. rc.2 deltas adopted:
58
+ # skill-filesystem customSkillDirs, tool-subagent-control interrupt:false,
59
+ # tool-office row.
57
60
  # Mirrored from preset-standard @ dsh 0.2.2-alpha.2 with these diffs:
58
61
  # 1. persona prefix reframed for remote SSH work (transparent routing);
59
62
  # 2. tool-bash moved into an isolated shell group with our routed bash
@@ -126,6 +129,9 @@
126
129
  name: '@deepseek-ai/dsh-tool-schedule'
127
130
  - id: skill-filesystem
128
131
  name: '@deepseek-ai/dsh-skill-filesystem'
132
+ config:
133
+ customSkillDirs:
134
+ - !!js process.getBuiltinModule('node:path').join(process.getBuiltinModule('node:path').dirname(process.getBuiltinModule('node:module').createRequire(baseUrl).resolve('@deepseek-ai/dsh-agent-preset/package.json')), 'skills')
129
135
  - id: tool-skill
130
136
  name: '@deepseek-ai/dsh-tool-skill'
131
137
  - id: command-goal
@@ -218,6 +224,8 @@
218
224
  config:
219
225
  - id: tool-subagent-control
220
226
  name: '@deepseek-ai/dsh-tool-subagent-control'
227
+ config:
228
+ interrupt: false
221
229
  - id: tool-subagent
222
230
  name: '@deepseek-ai/dsh-tool-subagent'
223
231
  config:
@@ -249,6 +257,8 @@
249
257
  searchTimeoutMs: 60000
250
258
  - id: present
251
259
  name: '@deepseek-ai/dsh-tool-present'
260
+ - id: tool-office
261
+ name: '@deepseek-ai/dsh-tool-office'
252
262
  - id: tool-plugin-manager
253
263
  name: '@deepseek-ai/dsh-plugin-manager/tools'
254
264
  disabled: !!js "!ctx.get('profileContext')"
package/lib/client.js CHANGED
@@ -489,6 +489,9 @@ window.__ModuleLoader__.load({
489
489
  "term.empty": "还没有终端 —— 选好主机后点右上角 + 新建一个。",
490
490
  "term.close": "关闭终端",
491
491
  "term.closeTitle": "关闭这个终端",
492
+ "term.copy": "复制",
493
+ "term.paste": "粘贴",
494
+ "term.selectAll": "全选",
492
495
  "term.noHosts": "还没有主机,请先去「设置 → 远程主机」配置。",
493
496
  "tab.git": "Git",
494
497
  "git.hint": "请选择远端路径为 git 仓库的工作区。",
@@ -1091,6 +1094,9 @@ window.__ModuleLoader__.load({
1091
1094
  "term.empty": "No terminal yet — pick a host, then press + to open one.",
1092
1095
  "term.close": "Close terminal",
1093
1096
  "term.closeTitle": "Close this terminal",
1097
+ "term.copy": "Copy",
1098
+ "term.paste": "Paste",
1099
+ "term.selectAll": "Select all",
1094
1100
  "term.noHosts": "No hosts yet. Configure one in Settings → Remote Hosts first.",
1095
1101
  "tab.git": "Git",
1096
1102
  "git.hint": "Pick a workspace whose remote path is a git repository.",
@@ -41584,7 +41590,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
41584
41590
  const primary = host.querySelectorAll("[class*=\"rvs-ck-\"]").length;
41585
41591
  const fallback = host.querySelectorAll("span[class^=\"rvs-t-\"]").length;
41586
41592
  const count = primary > 0 ? primary : fallback;
41587
- console.info(`[dsh-remote-vs] build 1110-1823 · ${source} · colored tokens: ${count} (${propsRef.current.path})`);
41593
+ console.info(`[dsh-remote-vs] build 1112-1650 · ${source} · colored tokens: ${count} (${propsRef.current.path})`);
41588
41594
  propsRef.current.onTokens?.(count);
41589
41595
  };
41590
41596
  const armFallback = () => {
@@ -48808,8 +48814,8 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
48808
48814
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConnectionStatusChip, { compact: true }),
48809
48815
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
48810
48816
  className: "rvs-build",
48811
- title: `dsh-remote-vs build 1110-1823`,
48812
- children: "1110-1823"
48817
+ title: `dsh-remote-vs build 1112-1650`,
48818
+ children: "1112-1650"
48813
48819
  }),
48814
48820
  tokenCount !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
48815
48821
  className: "rvs-build",
@@ -72989,9 +72995,96 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
72989
72995
  })()));
72990
72996
  }));
72991
72997
  //#endregion
72992
- //#region src/client/XTerm.tsx
72998
+ //#region src/client/vsc/terminal-clipboard.ts
72993
72999
  var import_xterm = require_xterm();
72994
73000
  var import_addon_fit = require_addon_fit();
73001
+ /** True when the key is the letter (layout-aware `code` is not required: xterm gives `key`). */
73002
+ function isLetter(input, letter) {
73003
+ return input.key.toLowerCase() === letter;
73004
+ }
73005
+ /**
73006
+ * Map one keydown to a clipboard chord.
73007
+ *
73008
+ * Conventions: Ctrl+Shift+C / Ctrl+Insert / Cmd+C copy, Ctrl+Shift+V / Cmd+V /
73009
+ * Shift+Insert paste. Plain Ctrl+V is left to the browser first (`paste-native`),
73010
+ * and plain Ctrl+C always stays SIGINT.
73011
+ */
73012
+ function clipboardChordFor(input) {
73013
+ const ctrl = input.ctrl, shift = input.shift, meta = input.meta;
73014
+ if (input.alt) return void 0;
73015
+ if (!meta && ctrl && shift && isLetter(input, "c")) return "copy";
73016
+ if (!meta && ctrl && !shift && input.key === "Insert") return "copy";
73017
+ if (meta && !ctrl && !shift && isLetter(input, "c")) return "copy";
73018
+ if (!meta && ctrl && shift && isLetter(input, "v")) return "paste";
73019
+ if (!meta && !ctrl && shift && input.key === "Insert") return "paste";
73020
+ if (meta && !ctrl && !shift && isLetter(input, "v")) return "paste";
73021
+ if (!meta && ctrl && !shift && isLetter(input, "v")) return "paste-native";
73022
+ if (!meta && ctrl && !shift && isLetter(input, "c")) return "copy-interrupt";
73023
+ }
73024
+ /**
73025
+ * Watches one Ctrl+V press: the browser's native paste wins when its event arrives,
73026
+ * otherwise the Clipboard API inserts the text after {@link PASTE_FALLBACK_MS}.
73027
+ *
73028
+ * The watcher is a single slot: arming again (a held/repeated key) replaces the
73029
+ * pending window instead of stacking pastes.
73030
+ */
73031
+ function createPasteFallback(deps) {
73032
+ const schedule = deps.schedule ?? ((run, ms) => {
73033
+ const timer = setTimeout(run, ms);
73034
+ timer.unref?.();
73035
+ return timer;
73036
+ });
73037
+ let pending;
73038
+ return {
73039
+ arm: () => {
73040
+ if (pending !== void 0) pending.cancelled = true;
73041
+ const token = { cancelled: false };
73042
+ pending = token;
73043
+ schedule(() => {
73044
+ if (token.cancelled) return;
73045
+ token.cancelled = true;
73046
+ if (pending === token) pending = void 0;
73047
+ deps.read().then((text) => {
73048
+ if (text === void 0) {
73049
+ deps.onDenied();
73050
+ return;
73051
+ }
73052
+ deps.paste(text);
73053
+ });
73054
+ }, 180);
73055
+ },
73056
+ observed: () => {
73057
+ if (pending !== void 0) pending.cancelled = true;
73058
+ pending = void 0;
73059
+ }
73060
+ };
73061
+ }
73062
+ /** Menu entry state for the right-click menu. */
73063
+ function terminalMenuState(input) {
73064
+ return { copyDisabled: !input.hasSelection };
73065
+ }
73066
+ /** Start/end markers a terminal wraps around a bracketed paste. */
73067
+ const PASTE_START = "\x1B[200~";
73068
+ const PASTE_END = "\x1B[201~";
73069
+ /**
73070
+ * Remove ONE bracketed-paste wrapper from an input chunk.
73071
+ *
73072
+ * xterm wraps `Terminal.paste()`/native pastes while the remote application has
73073
+ * bracketed paste enabled. When that mode is stale (an app that enabled it was
73074
+ * killed, or the shell never enabled it) the wrapper is displayed literally as
73075
+ * `^[[200~...^[[201~` and the text is not executed — a field screenshot showed
73076
+ * exactly that. The host-side input path strips one wrapper before forwarding,
73077
+ * so the PTY only ever receives the user's text. Apps that expect the wrapper
73078
+ * still accept raw text, like a classic terminal.
73079
+ */
73080
+ function stripBracketedPasteMarkers(data) {
73081
+ if (data.length < 6) return data;
73082
+ if (!data.startsWith(PASTE_START)) return data;
73083
+ if (!data.endsWith(PASTE_END)) return data;
73084
+ return data.slice(6, data.length - 6);
73085
+ }
73086
+ //#endregion
73087
+ //#region src/client/XTerm.tsx
72995
73088
  function send(ws, frame) {
72996
73089
  if (ws.readyState === WebSocket.OPEN) try {
72997
73090
  ws.send(JSON.stringify(frame));
@@ -73075,6 +73168,11 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
73075
73168
  const propsRef = (0, react.useRef)(props);
73076
73169
  propsRef.current = props;
73077
73170
  const liveRef = (0, react.useRef)(void 0);
73171
+ const menu = useContextMenu();
73172
+ const openMenuRef = (0, react.useRef)(menu.open);
73173
+ openMenuRef.current = menu.open;
73174
+ const tRef = (0, react.useRef)(props.t);
73175
+ tRef.current = props.t;
73078
73176
  (0, react.useEffect)(() => {
73079
73177
  if (props.visible === false) return;
73080
73178
  liveRef.current?.refit();
@@ -73134,7 +73232,9 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
73134
73232
  * characters — far under that cap either way, and far above a keystroke.
73135
73233
  */
73136
73234
  const INPUT_CHUNK_CHARS = 64 * 1024;
73137
- const sendInput = (data) => {
73235
+ const sendInput = (rawData) => {
73236
+ const data = stripBracketedPasteMarkers(rawData);
73237
+ if (data === "") return;
73138
73238
  if (data.length <= INPUT_CHUNK_CHARS) {
73139
73239
  send(ws, {
73140
73240
  t: "in",
@@ -73221,27 +73321,102 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
73221
73321
  term.paste(text);
73222
73322
  });
73223
73323
  };
73324
+ const pasteFallback = createPasteFallback({
73325
+ read: readClipboard,
73326
+ paste: (text) => {
73327
+ term.paste(text);
73328
+ },
73329
+ onDenied: () => {
73330
+ term.write("\r\n[dsh-remote] clipboard read denied by the browser\r\n");
73331
+ }
73332
+ });
73333
+ /**
73334
+ * All paste input converges here: one insertion per paste event.
73335
+ *
73336
+ * Capture phase + stopPropagation keeps xterm's own textarea handler from
73337
+ * inserting a second copy, and preventDefault stops the browser's remaining
73338
+ * default. The watcher is cancelled so the Clipboard-API fallback (for hosts
73339
+ * that never deliver this event) does not fire on top of it.
73340
+ */
73341
+ /**
73342
+ * Explicit paste chords (Ctrl+Shift+V / Cmd+V / Shift+Insert) insert through
73343
+ * the Clipboard API themselves. Some hosts still deliver the browser's native
73344
+ * paste afterwards even when the keydown was preventDefault-ed (observed with
73345
+ * Ctrl+Shift+V paste-as-plain-text), which pasted twice. This window swallows
73346
+ * that native delivery; plain Ctrl+V keeps the native path below.
73347
+ */
73348
+ let suppressNativePasteUntil = 0;
73349
+ const onPasteEvent = (e) => {
73350
+ e.preventDefault();
73351
+ e.stopPropagation();
73352
+ if (Date.now() < suppressNativePasteUntil) {
73353
+ suppressNativePasteUntil = 0;
73354
+ return;
73355
+ }
73356
+ const text = e.clipboardData?.getData("text/plain") ?? "";
73357
+ pasteFallback.observed();
73358
+ if (text !== "") term.paste(text);
73359
+ };
73360
+ host.addEventListener("paste", onPasteEvent, true);
73224
73361
  term.attachCustomKeyEventHandler((e) => {
73225
- const key = e.key.toLowerCase();
73226
- const copyKey = !e.metaKey && e.ctrlKey && (e.shiftKey && key === "c" || !e.shiftKey && e.key === "Insert") || e.metaKey && !e.ctrlKey && key === "c";
73227
- const pasteKey = !e.metaKey && e.ctrlKey && e.shiftKey && key === "v" || e.metaKey && !e.ctrlKey && key === "v" || !e.ctrlKey && !e.metaKey && e.shiftKey && e.key === "Insert";
73228
- if (copyKey) {
73229
- if (term.hasSelection()) {
73230
- doCopy(false);
73231
- return false;
73232
- }
73233
- return true;
73362
+ const chord = clipboardChordFor({
73363
+ key: e.key,
73364
+ ctrl: e.ctrlKey,
73365
+ shift: e.shiftKey,
73366
+ alt: e.altKey,
73367
+ meta: e.metaKey
73368
+ });
73369
+ if (chord === void 0) return true;
73370
+ if (chord === "copy-interrupt") {
73371
+ if (!term.hasSelection()) return true;
73372
+ e.preventDefault();
73373
+ doCopy(false);
73374
+ return false;
73234
73375
  }
73235
- if (pasteKey) {
73376
+ if (chord === "paste") {
73377
+ e.preventDefault();
73378
+ suppressNativePasteUntil = Date.now() + 600;
73236
73379
  doPaste();
73237
73380
  return false;
73238
73381
  }
73239
- return true;
73382
+ if (chord === "paste-native") {
73383
+ pasteFallback.arm();
73384
+ return true;
73385
+ }
73386
+ if (!term.hasSelection()) return true;
73387
+ e.preventDefault();
73388
+ doCopy(false);
73389
+ return false;
73240
73390
  });
73241
73391
  const onContextMenu = (e) => {
73242
73392
  e.preventDefault();
73243
- if (term.hasSelection()) doCopy(true);
73244
- else doPaste();
73393
+ const hasSelection = term.hasSelection();
73394
+ const entries = [
73395
+ {
73396
+ label: tRef.current("term.copy"),
73397
+ disabled: terminalMenuState({ hasSelection }).copyDisabled,
73398
+ onSelect: () => {
73399
+ doCopy(false);
73400
+ term.focus();
73401
+ }
73402
+ },
73403
+ {
73404
+ label: tRef.current("term.paste"),
73405
+ onSelect: () => {
73406
+ doPaste();
73407
+ term.focus();
73408
+ }
73409
+ },
73410
+ {
73411
+ label: tRef.current("term.selectAll"),
73412
+ separated: true,
73413
+ onSelect: () => {
73414
+ term.selectAll();
73415
+ term.focus();
73416
+ }
73417
+ }
73418
+ ];
73419
+ openMenuRef.current(e.clientX, e.clientY, entries);
73245
73420
  };
73246
73421
  host.addEventListener("contextmenu", onContextMenu);
73247
73422
  term.focus();
@@ -73250,6 +73425,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
73250
73425
  unflip();
73251
73426
  window.clearTimeout(timer);
73252
73427
  window.removeEventListener("resize", onWindowResize);
73428
+ host.removeEventListener("paste", onPasteEvent, true);
73253
73429
  host.removeEventListener("contextmenu", onContextMenu);
73254
73430
  resizeObserver.disconnect();
73255
73431
  try {
@@ -73258,13 +73434,18 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
73258
73434
  term.dispose();
73259
73435
  };
73260
73436
  }, []);
73261
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
73437
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
73262
73438
  ref: hostRef,
73263
73439
  style: {
73264
73440
  height: "100%",
73265
73441
  minHeight: 200
73266
73442
  }
73267
- });
73443
+ }), menu.menu !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextMenu, {
73444
+ x: menu.menu.x,
73445
+ y: menu.menu.y,
73446
+ entries: menu.menu.entries,
73447
+ onClose: menu.close
73448
+ })] });
73268
73449
  }
73269
73450
  //#endregion
73270
73451
  //#region src/client/TerminalView.tsx
@@ -73646,6 +73827,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
73646
73827
  rows: 24
73647
73828
  }),
73648
73829
  visible: props.visible && tab.id === active?.id,
73830
+ t,
73649
73831
  ...tab.initialCommand === void 0 ? {} : { initialInput: tab.initialCommand },
73650
73832
  onReady: (id) => patchTab(tab.id, {
73651
73833
  session: id,
@@ -18,4 +18,6 @@ export declare function XTerm(props: {
18
18
  * which correctly re-runs the line.
19
19
  */
20
20
  initialInput?: string;
21
+ /** Translator for the right-click menu (copy / paste / select all). */
22
+ t: (key: string) => string;
21
23
  }): ReactNode;
@@ -11,7 +11,7 @@
11
11
  * them here keeps the check meaningful in both directions: every entry must
12
12
  * exist in both dictionaries, and nothing else may be unreferenced.
13
13
  */
14
- export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff", "downloads.running", "downloads.indeterminate", "downloads.sizeUnknown", "downloads.handedOff", "term.disconnected", "term.closed", "connection.ok", "connection.error", "connection.idle", "connection.actionFailed", "doctor.state.ok", "doctor.state.missing", "doctor.state.unknown", "doctor.item.os", "doctor.item.libc", "doctor.item.git", "doctor.item.rg", "doctor.item.tar", "doctor.item.setsid", "doctor.item.disk", "doctor.item.nproc", "doctor.item.memory", "doctor.item.helpers", "doctor.item.sshd"];
14
+ export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff", "downloads.running", "downloads.indeterminate", "downloads.sizeUnknown", "downloads.handedOff", "term.disconnected", "term.closed", "term.copy", "term.paste", "term.selectAll", "connection.ok", "connection.error", "connection.idle", "connection.actionFailed", "doctor.state.ok", "doctor.state.missing", "doctor.state.unknown", "doctor.item.os", "doctor.item.libc", "doctor.item.git", "doctor.item.rg", "doctor.item.tar", "doctor.item.setsid", "doctor.item.disk", "doctor.item.nproc", "doctor.item.memory", "doctor.item.helpers", "doctor.item.sshd"];
15
15
  export type Lang = 'zh' | 'en';
16
16
  export declare function detectLang(): Lang;
17
17
  export declare function makeT(lang: Lang): (key: string) => string;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Terminal clipboard chords and the paste fallback, as testable logic.
3
+ *
4
+ * Why this module exists
5
+ * ----------------------
6
+ * The terminal's copy/paste handling used to be an inline `attachCustomKeyEventHandler`
7
+ * with three problems the UI tests could not see:
8
+ *
9
+ * 1. **Double paste on Ctrl+Shift+V.** The handler pasted through
10
+ * `navigator.clipboard.readText()` and returned `false`, but returning false only
11
+ * stops xterm's own handling — the browser still performed its default paste
12
+ * (Chrome maps Ctrl+Shift+V to "paste as plain text"), so both paths inserted the
13
+ * text. Handled chords must call `preventDefault()` themselves.
14
+ * 2. **Ctrl+V depended entirely on the browser's native paste.** When the host page
15
+ * or a wrapper swallows the paste event (desktop shells, non-standard clipboard
16
+ * permissions), the terminal silently received nothing. It now falls back to the
17
+ * Clipboard API only when no paste event arrived shortly after the key press.
18
+ * 3. **Right-click copied/pasted immediately with no visible affordance.** It is now
19
+ * a small menu (copy / paste / select all) so the action is discoverable and the
20
+ * copy item can be disabled when nothing is selected.
21
+ *
22
+ * The chord table and the fallback watcher are pure so a gate can pin all of it.
23
+ */
24
+ /** What one key press asks the terminal to do. */
25
+ export type TerminalClipboardChord =
26
+ /** Copy the current selection, then clear it (menu action). */
27
+ 'copy'
28
+ /** Paste immediately through the Clipboard API. */
29
+ | 'paste'
30
+ /** Let the browser's native paste run; fall back to the Clipboard API when no paste event arrives. */
31
+ | 'paste-native'
32
+ /** Plain Ctrl+C: copy when a selection exists, otherwise stay SIGINT. */
33
+ | 'copy-interrupt';
34
+ /** The keyboard state the chord table reads. */
35
+ export interface TerminalChordInput {
36
+ key: string;
37
+ ctrl: boolean;
38
+ shift: boolean;
39
+ alt: boolean;
40
+ meta: boolean;
41
+ }
42
+ /**
43
+ * Map one keydown to a clipboard chord.
44
+ *
45
+ * Conventions: Ctrl+Shift+C / Ctrl+Insert / Cmd+C copy, Ctrl+Shift+V / Cmd+V /
46
+ * Shift+Insert paste. Plain Ctrl+V is left to the browser first (`paste-native`),
47
+ * and plain Ctrl+C always stays SIGINT.
48
+ */
49
+ export declare function clipboardChordFor(input: TerminalChordInput): TerminalClipboardChord | undefined;
50
+ /** Copy and paste chords take the key over; the native-paste chord must not. */
51
+ export declare function chordTakesKey(chord: TerminalClipboardChord): boolean;
52
+ /** Dependencies of {@link createPasteFallback}. */
53
+ export interface PasteFallbackDeps {
54
+ /** Clipboard read; `undefined` when the browser denies it. */
55
+ read: () => Promise<string | undefined>;
56
+ /** Insert text into the terminal. */
57
+ paste: (text: string) => void;
58
+ /** Report a denied clipboard read (shown in the terminal). */
59
+ onDenied: () => void;
60
+ /** Timer injection (tests use a fake clock). */
61
+ schedule?: (run: () => void, ms: number) => unknown;
62
+ }
63
+ /** How long to wait for a native paste event before falling back to the API. */
64
+ export declare const PASTE_FALLBACK_MS = 180;
65
+ /**
66
+ * Watches one Ctrl+V press: the browser's native paste wins when its event arrives,
67
+ * otherwise the Clipboard API inserts the text after {@link PASTE_FALLBACK_MS}.
68
+ *
69
+ * The watcher is a single slot: arming again (a held/repeated key) replaces the
70
+ * pending window instead of stacking pastes.
71
+ */
72
+ export declare function createPasteFallback(deps: PasteFallbackDeps): {
73
+ arm: () => void;
74
+ /** The terminal saw a native paste for this window: cancel the fallback. */
75
+ observed: () => void;
76
+ };
77
+ /** Menu entry state for the right-click menu. */
78
+ export declare function terminalMenuState(input: {
79
+ hasSelection: boolean;
80
+ }): {
81
+ copyDisabled: boolean;
82
+ };
83
+ /**
84
+ * Remove ONE bracketed-paste wrapper from an input chunk.
85
+ *
86
+ * xterm wraps `Terminal.paste()`/native pastes while the remote application has
87
+ * bracketed paste enabled. When that mode is stale (an app that enabled it was
88
+ * killed, or the shell never enabled it) the wrapper is displayed literally as
89
+ * `^[[200~...^[[201~` and the text is not executed — a field screenshot showed
90
+ * exactly that. The host-side input path strips one wrapper before forwarding,
91
+ * so the PTY only ever receives the user's text. Apps that expect the wrapper
92
+ * still accept raw text, like a classic terminal.
93
+ */
94
+ export declare function stripBracketedPasteMarkers(data: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-remote-vs",
3
3
  "description": "VSCode-style remote development for DSH: SSH host manager (key/password), helper deploy pipeline with version check, remote file explorer + editor + terminal in dsh-better-sidebar.",
4
- "version": "0.20.1",
4
+ "version": "0.21.1",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
7
7
  "dsh",
@@ -59,7 +59,7 @@
59
59
  "./locale/*.json": "./locale/*.json"
60
60
  },
61
61
  "engines": {
62
- "dsh": ">=0.2.2-alpha.3 <0.3.0"
62
+ "dsh": ">=0.2.2-rc.2 <0.3.0"
63
63
  },
64
64
  "dsh": {
65
65
  "bundle": {
@@ -131,43 +131,43 @@
131
131
  },
132
132
  "peerDependencies": {
133
133
  "@deepseek-ai/cordis": "^4.1.0",
134
- "@deepseek-ai/dsh-agent-preset": "^0.2.2-rc.1",
135
- "@deepseek-ai/dsh-bash-local": "^0.2.2-rc.1",
136
- "@deepseek-ai/dsh-file-reference": "^0.2.2-rc.1",
137
- "@deepseek-ai/dsh-fs": "^0.2.2-rc.1",
138
- "@deepseek-ai/dsh-shell": "^0.2.2-rc.1",
139
- "@deepseek-ai/dsh-spill": "^0.2.2-rc.1",
140
- "@deepseek-ai/dsh-subprocess": "^0.2.2-rc.1",
141
- "@deepseek-ai/dsh-tools": "^0.2.2-rc.1",
134
+ "@deepseek-ai/dsh-agent-preset": "^0.2.2-rc.2",
135
+ "@deepseek-ai/dsh-bash-local": "^0.2.2-rc.2",
136
+ "@deepseek-ai/dsh-file-reference": "^0.2.2-rc.2",
137
+ "@deepseek-ai/dsh-fs": "^0.2.2-rc.2",
138
+ "@deepseek-ai/dsh-shell": "^0.2.2-rc.2",
139
+ "@deepseek-ai/dsh-spill": "^0.2.2-rc.2",
140
+ "@deepseek-ai/dsh-subprocess": "^0.2.2-rc.2",
141
+ "@deepseek-ai/dsh-tools": "^0.2.2-rc.2",
142
142
  "react": "^18.2.0",
143
143
  "react-dom": "^18.2.0"
144
144
  },
145
145
  "devDependencies": {
146
146
  "@deepseek-ai/cordis": "^4.1.0",
147
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
148
- "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.1",
149
- "@deepseek-ai/dsh-api-remotes": "0.2.2-rc.1",
150
- "@deepseek-ai/dsh-bash-local": "0.2.2-rc.1",
151
- "@deepseek-ai/dsh-client-locale": "0.2.2-rc.1",
152
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.1",
153
- "@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.1",
154
- "@deepseek-ai/dsh-client-ui-sidebar-right": "0.2.2-rc.1",
155
- "@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.1",
156
- "@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.1",
157
- "@deepseek-ai/dsh-file-reference": "0.2.2-rc.1",
158
- "@deepseek-ai/dsh-fs": "0.2.2-rc.1",
159
- "@deepseek-ai/dsh-host-directory-picker": "0.2.2-rc.1",
160
- "@deepseek-ai/dsh-host-webserver": "0.2.2-rc.1",
161
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
162
- "@deepseek-ai/dsh-sandbox": "0.2.2-rc.1",
163
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
164
- "@deepseek-ai/dsh-shell": "0.2.2-rc.1",
165
- "@deepseek-ai/dsh-spill": "0.2.2-rc.1",
166
- "@deepseek-ai/dsh-subprocess": "0.2.2-rc.1",
167
- "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
168
- "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
169
- "@deepseek-ai/dsh-working-directory": "0.2.2-rc.1",
170
- "@deepseek-ai/dsh-workspace": "0.2.2-rc.1",
147
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.2",
148
+ "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.2",
149
+ "@deepseek-ai/dsh-api-remotes": "0.2.2-rc.2",
150
+ "@deepseek-ai/dsh-bash-local": "0.2.2-rc.2",
151
+ "@deepseek-ai/dsh-client-locale": "0.2.2-rc.2",
152
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.2",
153
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.2",
154
+ "@deepseek-ai/dsh-client-ui-sidebar-right": "0.2.2-rc.2",
155
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.2",
156
+ "@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.2",
157
+ "@deepseek-ai/dsh-file-reference": "0.2.2-rc.2",
158
+ "@deepseek-ai/dsh-fs": "0.2.2-rc.2",
159
+ "@deepseek-ai/dsh-host-directory-picker": "0.2.2-rc.2",
160
+ "@deepseek-ai/dsh-host-webserver": "0.2.2-rc.2",
161
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.2",
162
+ "@deepseek-ai/dsh-sandbox": "0.2.2-rc.2",
163
+ "@deepseek-ai/dsh-session": "0.2.2-rc.2",
164
+ "@deepseek-ai/dsh-shell": "0.2.2-rc.2",
165
+ "@deepseek-ai/dsh-spill": "0.2.2-rc.2",
166
+ "@deepseek-ai/dsh-subprocess": "0.2.2-rc.2",
167
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.2",
168
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.2",
169
+ "@deepseek-ai/dsh-working-directory": "0.2.2-rc.2",
170
+ "@deepseek-ai/dsh-workspace": "0.2.2-rc.2",
171
171
  "@types/node": "^22.20.0",
172
172
  "@types/react": "~18.3.1",
173
173
  "@types/react-dom": "^18.3.5",
@@ -480,6 +480,7 @@ export function TerminalView(props: {
480
480
  rows: 24,
481
481
  })}
482
482
  visible={props.visible && tab.id === active?.id}
483
+ t={t}
483
484
  {...(tab.initialCommand === undefined ? {} : { initialInput: tab.initialCommand })}
484
485
  onReady={(id) => patchTab(tab.id, { session: id, connected: true, note: undefined })}
485
486
  onExit={(code, message) => {
@@ -10,6 +10,13 @@ import type { ITheme } from '@xterm/xterm'
10
10
  import { FitAddon } from '@xterm/addon-fit'
11
11
  import type { TerminalClientFrame, TerminalServerFrame } from '../protocol.ts'
12
12
  import { isDarkScheme, subscribeColorScheme } from './theme.ts'
13
+ import { ContextMenu, useContextMenu, type MenuEntry } from './vsc/kit.tsx'
14
+ import {
15
+ clipboardChordFor,
16
+ createPasteFallback,
17
+ stripBracketedPasteMarkers,
18
+ terminalMenuState,
19
+ } from './vsc/terminal-clipboard.ts'
13
20
 
14
21
  function send(ws: WebSocket, frame: TerminalClientFrame): void {
15
22
  if (ws.readyState === WebSocket.OPEN) {
@@ -112,11 +119,20 @@ export function XTerm(props: {
112
119
  * which correctly re-runs the line.
113
120
  */
114
121
  initialInput?: string
122
+ /** Translator for the right-click menu (copy / paste / select all). */
123
+ t: (key: string) => string
115
124
  }): ReactNode {
116
125
  const hostRef = useRef<HTMLDivElement>(null)
117
126
  const propsRef = useRef(props)
118
127
  propsRef.current = props
119
128
  const liveRef = useRef<{ refit: () => void } | undefined>(undefined)
129
+ // The context menu lives at component level (portal); the mount-once effect
130
+ // reaches it through refs, the same pattern the explorer row uses.
131
+ const menu = useContextMenu()
132
+ const openMenuRef = useRef(menu.open)
133
+ openMenuRef.current = menu.open
134
+ const tRef = useRef(props.t)
135
+ tRef.current = props.t
120
136
 
121
137
  // Shown again after being hidden: refit and push the size.
122
138
  useEffect(() => {
@@ -187,7 +203,9 @@ export function XTerm(props: {
187
203
  * characters — far under that cap either way, and far above a keystroke.
188
204
  */
189
205
  const INPUT_CHUNK_CHARS = 64 * 1024
190
- const sendInput = (data: string): void => {
206
+ const sendInput = (rawData: string): void => {
207
+ const data = stripBracketedPasteMarkers(rawData)
208
+ if (data === '') return
191
209
  if (data.length <= INPUT_CHUNK_CHARS) {
192
210
  send(ws, { t: 'in', d: data })
193
211
  return
@@ -253,9 +271,13 @@ export function XTerm(props: {
253
271
  // Late layout (tab switch): refit shortly after mount too.
254
272
  const timer = window.setTimeout(pushSize, 300)
255
273
 
256
- // Copy/paste (Windows Terminal conventions; plain Ctrl+C stays SIGINT):
257
- // Ctrl+Shift+C / Cmd+C / Ctrl+Insert = copy, Ctrl+Shift+V / Cmd+V /
258
- // Shift+Insert = paste, right-click = copy when selecting else paste.
274
+ // Clipboard (VS Code / Windows Terminal conventions; plain Ctrl+C stays SIGINT):
275
+ // copy = Ctrl+Shift+C / Cmd+C / Ctrl+Insert, paste = Ctrl+Shift+V / Cmd+V /
276
+ // Shift+Insert. Handled chords call preventDefault() THEMSELVES: returning
277
+ // false only stops xterm, and the browser would then run its own default
278
+ // (Chrome maps Ctrl+Shift+V to paste-as-plain-text, which double-pasted).
279
+ // Plain Ctrl+V is left to the browser first; when no paste event arrives the
280
+ // Clipboard API fallback fires (some shells swallow the native paste).
259
281
  const doCopy = (clear: boolean): void => {
260
282
  const selection = term.getSelection()
261
283
  if (selection === '') return
@@ -273,30 +295,91 @@ export function XTerm(props: {
273
295
  term.paste(text)
274
296
  })
275
297
  }
298
+ const pasteFallback = createPasteFallback({
299
+ read: readClipboard,
300
+ paste: (text) => { term.paste(text) },
301
+ onDenied: () => { term.write('\r\n[dsh-remote] clipboard read denied by the browser\r\n') },
302
+ })
303
+ /**
304
+ * All paste input converges here: one insertion per paste event.
305
+ *
306
+ * Capture phase + stopPropagation keeps xterm's own textarea handler from
307
+ * inserting a second copy, and preventDefault stops the browser's remaining
308
+ * default. The watcher is cancelled so the Clipboard-API fallback (for hosts
309
+ * that never deliver this event) does not fire on top of it.
310
+ */
311
+ /**
312
+ * Explicit paste chords (Ctrl+Shift+V / Cmd+V / Shift+Insert) insert through
313
+ * the Clipboard API themselves. Some hosts still deliver the browser's native
314
+ * paste afterwards even when the keydown was preventDefault-ed (observed with
315
+ * Ctrl+Shift+V paste-as-plain-text), which pasted twice. This window swallows
316
+ * that native delivery; plain Ctrl+V keeps the native path below.
317
+ */
318
+ let suppressNativePasteUntil = 0
319
+ const onPasteEvent = (e: ClipboardEvent): void => {
320
+ e.preventDefault()
321
+ e.stopPropagation()
322
+ if (Date.now() < suppressNativePasteUntil) {
323
+ // The explicit chord already inserted this paste through the API.
324
+ suppressNativePasteUntil = 0
325
+ return
326
+ }
327
+ const text = e.clipboardData?.getData('text/plain') ?? ''
328
+ pasteFallback.observed()
329
+ if (text !== '') term.paste(text)
330
+ }
331
+ host.addEventListener('paste', onPasteEvent, true)
276
332
  term.attachCustomKeyEventHandler((e) => {
277
- const key = e.key.toLowerCase()
278
- const copyKey = (!e.metaKey && e.ctrlKey && ((e.shiftKey && key === 'c') || (!e.shiftKey && e.key === 'Insert')))
279
- || (e.metaKey && !e.ctrlKey && key === 'c')
280
- const pasteKey = (!e.metaKey && e.ctrlKey && e.shiftKey && key === 'v')
281
- || (e.metaKey && !e.ctrlKey && key === 'v')
282
- || (!e.ctrlKey && !e.metaKey && e.shiftKey && e.key === 'Insert')
283
- if (copyKey) {
284
- if (term.hasSelection()) {
285
- doCopy(false)
286
- return false
287
- }
288
- return true
333
+ const chord = clipboardChordFor({
334
+ key: e.key,
335
+ ctrl: e.ctrlKey,
336
+ shift: e.shiftKey,
337
+ alt: e.altKey,
338
+ meta: e.metaKey,
339
+ })
340
+ if (chord === undefined) return true
341
+ if (chord === 'copy-interrupt') {
342
+ // Ctrl+C: with a selection the convention is COPY (never SIGINT); without
343
+ // one the key falls through so the remote shell interrupts as usual.
344
+ if (!term.hasSelection()) return true
345
+ e.preventDefault()
346
+ doCopy(false)
347
+ return false
289
348
  }
290
- if (pasteKey) {
349
+ if (chord === 'paste') {
350
+ // Explicit paste chord: insert ONCE through the Clipboard API and swallow
351
+ // the browser's native delivery for this gesture (some hosts ignore the
352
+ // keydown preventDefault and paste again).
353
+ e.preventDefault()
354
+ suppressNativePasteUntil = Date.now() + 600
291
355
  doPaste()
292
356
  return false
293
357
  }
294
- return true
358
+ if (chord === 'paste-native') {
359
+ // Plain Ctrl+V: the browser's native paste is the primary path; when the
360
+ // host swallows it, the watcher falls back to the Clipboard API.
361
+ pasteFallback.arm()
362
+ return true
363
+ }
364
+ // Copy: with nothing selected the key belongs to the terminal/browser.
365
+ if (!term.hasSelection()) return true
366
+ e.preventDefault()
367
+ doCopy(false)
368
+ return false
295
369
  })
296
370
  const onContextMenu = (e: MouseEvent): void => {
297
371
  e.preventDefault()
298
- if (term.hasSelection()) doCopy(true)
299
- else doPaste()
372
+ const hasSelection = term.hasSelection()
373
+ const entries: MenuEntry[] = [
374
+ {
375
+ label: tRef.current('term.copy'),
376
+ disabled: terminalMenuState({ hasSelection }).copyDisabled,
377
+ onSelect: () => { doCopy(false); term.focus() },
378
+ },
379
+ { label: tRef.current('term.paste'), onSelect: () => { doPaste(); term.focus() } },
380
+ { label: tRef.current('term.selectAll'), separated: true, onSelect: () => { term.selectAll(); term.focus() } },
381
+ ]
382
+ openMenuRef.current(e.clientX, e.clientY, entries)
300
383
  }
301
384
  host.addEventListener('contextmenu', onContextMenu)
302
385
 
@@ -306,6 +389,7 @@ export function XTerm(props: {
306
389
  unflip()
307
390
  window.clearTimeout(timer)
308
391
  window.removeEventListener('resize', onWindowResize)
392
+ host.removeEventListener('paste', onPasteEvent, true)
309
393
  host.removeEventListener('contextmenu', onContextMenu)
310
394
  resizeObserver.disconnect()
311
395
  try {
@@ -319,5 +403,12 @@ export function XTerm(props: {
319
403
  // eslint-disable-next-line react-hooks/exhaustive-deps
320
404
  }, [])
321
405
 
322
- return <div ref={hostRef} style={{ height: '100%', minHeight: 200 }} />
406
+ return (
407
+ <>
408
+ <div ref={hostRef} style={{ height: '100%', minHeight: 200 }} />
409
+ {menu.menu !== undefined && (
410
+ <ContextMenu x={menu.menu.x} y={menu.menu.y} entries={menu.menu.entries} onClose={menu.close} />
411
+ )}
412
+ </>
413
+ )
323
414
  }
@@ -40,6 +40,11 @@ export const DYNAMIC_KEYS = [
40
40
  // exit), which stores the key and renders it later.
41
41
  'term.disconnected',
42
42
  'term.closed',
43
+ // Reached through tRef.current(...) in the XTerm right-click menu (built
44
+ // inside a mount-once effect: literal keys, but not a t() call site).
45
+ 'term.copy',
46
+ 'term.paste',
47
+ 'term.selectAll',
43
48
  // Labels chosen through connectionLabelKey in connection.ts (a state → key
44
49
  // mapping, so the call site is (connectionLabelKey(state))).
45
50
  'connection.ok',
@@ -202,7 +207,10 @@ const zh: Record<string, string> = {
202
207
  'term.new': '新建终端',
203
208
  'term.empty': '还没有终端 —— 选好主机后点右上角 + 新建一个。',
204
209
  'term.close': '关闭终端',
205
- 'term.closeTitle': '关闭这个终端',
210
+ 'term.closeTitle': '关闭这个终端',
211
+ 'term.copy': '复制',
212
+ 'term.paste': '粘贴',
213
+ 'term.selectAll': '全选',
206
214
  'term.noHosts': '还没有主机,请先去「设置 → 远程主机」配置。',
207
215
  'tab.git': 'Git',
208
216
  'git.hint': '请选择远端路径为 git 仓库的工作区。',
@@ -817,7 +825,10 @@ const en: Record<string, string> = {
817
825
  'term.new': 'New terminal',
818
826
  'term.empty': 'No terminal yet — pick a host, then press + to open one.',
819
827
  'term.close': 'Close terminal',
820
- 'term.closeTitle': 'Close this terminal',
828
+ 'term.closeTitle': 'Close this terminal',
829
+ 'term.copy': 'Copy',
830
+ 'term.paste': 'Paste',
831
+ 'term.selectAll': 'Select all',
821
832
  'term.noHosts': 'No hosts yet. Configure one in Settings → Remote Hosts first.',
822
833
  'tab.git': 'Git',
823
834
  'git.hint': 'Pick a workspace whose remote path is a git repository.',
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Terminal clipboard chords and the paste fallback, as testable logic.
3
+ *
4
+ * Why this module exists
5
+ * ----------------------
6
+ * The terminal's copy/paste handling used to be an inline `attachCustomKeyEventHandler`
7
+ * with three problems the UI tests could not see:
8
+ *
9
+ * 1. **Double paste on Ctrl+Shift+V.** The handler pasted through
10
+ * `navigator.clipboard.readText()` and returned `false`, but returning false only
11
+ * stops xterm's own handling — the browser still performed its default paste
12
+ * (Chrome maps Ctrl+Shift+V to "paste as plain text"), so both paths inserted the
13
+ * text. Handled chords must call `preventDefault()` themselves.
14
+ * 2. **Ctrl+V depended entirely on the browser's native paste.** When the host page
15
+ * or a wrapper swallows the paste event (desktop shells, non-standard clipboard
16
+ * permissions), the terminal silently received nothing. It now falls back to the
17
+ * Clipboard API only when no paste event arrived shortly after the key press.
18
+ * 3. **Right-click copied/pasted immediately with no visible affordance.** It is now
19
+ * a small menu (copy / paste / select all) so the action is discoverable and the
20
+ * copy item can be disabled when nothing is selected.
21
+ *
22
+ * The chord table and the fallback watcher are pure so a gate can pin all of it.
23
+ */
24
+
25
+ /** What one key press asks the terminal to do. */
26
+ export type TerminalClipboardChord =
27
+ /** Copy the current selection, then clear it (menu action). */
28
+ | 'copy'
29
+ /** Paste immediately through the Clipboard API. */
30
+ | 'paste'
31
+ /** Let the browser's native paste run; fall back to the Clipboard API when no paste event arrives. */
32
+ | 'paste-native'
33
+ /** Plain Ctrl+C: copy when a selection exists, otherwise stay SIGINT. */
34
+ | 'copy-interrupt'
35
+
36
+ /** The keyboard state the chord table reads. */
37
+ export interface TerminalChordInput {
38
+ key: string
39
+ ctrl: boolean
40
+ shift: boolean
41
+ alt: boolean
42
+ meta: boolean
43
+ }
44
+
45
+ /** True when the key is the letter (layout-aware `code` is not required: xterm gives `key`). */
46
+ function isLetter(input: TerminalChordInput, letter: string): boolean {
47
+ return input.key.toLowerCase() === letter
48
+ }
49
+
50
+ /**
51
+ * Map one keydown to a clipboard chord.
52
+ *
53
+ * Conventions: Ctrl+Shift+C / Ctrl+Insert / Cmd+C copy, Ctrl+Shift+V / Cmd+V /
54
+ * Shift+Insert paste. Plain Ctrl+V is left to the browser first (`paste-native`),
55
+ * and plain Ctrl+C always stays SIGINT.
56
+ */
57
+ export function clipboardChordFor(input: TerminalChordInput): TerminalClipboardChord | undefined {
58
+ const ctrl = input.ctrl,
59
+ shift = input.shift,
60
+ meta = input.meta,
61
+ alt = input.alt
62
+ if (alt) return undefined
63
+ if (!meta && ctrl && shift && isLetter(input, 'c')) return 'copy'
64
+ if (!meta && ctrl && !shift && input.key === 'Insert') return 'copy'
65
+ if (meta && !ctrl && !shift && isLetter(input, 'c')) return 'copy'
66
+ if (!meta && ctrl && shift && isLetter(input, 'v')) return 'paste'
67
+ if (!meta && !ctrl && shift && input.key === 'Insert') return 'paste'
68
+ if (meta && !ctrl && !shift && isLetter(input, 'v')) return 'paste'
69
+ if (!meta && ctrl && !shift && isLetter(input, 'v')) return 'paste-native'
70
+ // Plain Ctrl+C only means COPY when there is a selection; without one it must
71
+ // stay SIGINT. The chord therefore only says "look at the selection".
72
+ if (!meta && ctrl && !shift && isLetter(input, 'c')) return 'copy-interrupt'
73
+ return undefined
74
+ }
75
+
76
+ /** Copy and paste chords take the key over; the native-paste chord must not. */
77
+ export function chordTakesKey(chord: TerminalClipboardChord): boolean {
78
+ return chord !== 'paste-native'
79
+ }
80
+
81
+ /** Dependencies of {@link createPasteFallback}. */
82
+ export interface PasteFallbackDeps {
83
+ /** Clipboard read; `undefined` when the browser denies it. */
84
+ read: () => Promise<string | undefined>
85
+ /** Insert text into the terminal. */
86
+ paste: (text: string) => void
87
+ /** Report a denied clipboard read (shown in the terminal). */
88
+ onDenied: () => void
89
+ /** Timer injection (tests use a fake clock). */
90
+ schedule?: (run: () => void, ms: number) => unknown
91
+ }
92
+
93
+ /** How long to wait for a native paste event before falling back to the API. */
94
+ export const PASTE_FALLBACK_MS = 180
95
+
96
+ /**
97
+ * Watches one Ctrl+V press: the browser's native paste wins when its event arrives,
98
+ * otherwise the Clipboard API inserts the text after {@link PASTE_FALLBACK_MS}.
99
+ *
100
+ * The watcher is a single slot: arming again (a held/repeated key) replaces the
101
+ * pending window instead of stacking pastes.
102
+ */
103
+ export function createPasteFallback(deps: PasteFallbackDeps): {
104
+ arm: () => void
105
+ /** The terminal saw a native paste for this window: cancel the fallback. */
106
+ observed: () => void
107
+ } {
108
+ const schedule = deps.schedule
109
+ ?? ((run, ms) => {
110
+ const timer = setTimeout(run, ms)
111
+ // Never keep a Host-alike or a page alive for a clipboard probe.
112
+ ;(timer as unknown as { unref?: () => void }).unref?.()
113
+ return timer
114
+ })
115
+ let pending: { cancelled: boolean } | undefined
116
+ return {
117
+ arm: () => {
118
+ if (pending !== undefined) pending.cancelled = true
119
+ const token = { cancelled: false }
120
+ pending = token
121
+ schedule(() => {
122
+ if (token.cancelled) return
123
+ token.cancelled = true
124
+ if (pending === token) pending = undefined
125
+ void deps.read().then((text) => {
126
+ if (text === undefined) {
127
+ deps.onDenied()
128
+ return
129
+ }
130
+ deps.paste(text)
131
+ })
132
+ }, PASTE_FALLBACK_MS)
133
+ },
134
+ observed: () => {
135
+ if (pending !== undefined) pending.cancelled = true
136
+ pending = undefined
137
+ },
138
+ }
139
+ }
140
+
141
+ /** Menu entry state for the right-click menu. */
142
+ export function terminalMenuState(input: { hasSelection: boolean }): {
143
+ copyDisabled: boolean
144
+ } {
145
+ return { copyDisabled: !input.hasSelection }
146
+ }
147
+
148
+ // ------------------------------------------------- bracketed-paste sanitising
149
+
150
+ /** Start/end markers a terminal wraps around a bracketed paste. */
151
+ const PASTE_START = '\u001b[200~'
152
+ const PASTE_END = '\u001b[201~'
153
+
154
+ /**
155
+ * Remove ONE bracketed-paste wrapper from an input chunk.
156
+ *
157
+ * xterm wraps `Terminal.paste()`/native pastes while the remote application has
158
+ * bracketed paste enabled. When that mode is stale (an app that enabled it was
159
+ * killed, or the shell never enabled it) the wrapper is displayed literally as
160
+ * `^[[200~...^[[201~` and the text is not executed — a field screenshot showed
161
+ * exactly that. The host-side input path strips one wrapper before forwarding,
162
+ * so the PTY only ever receives the user's text. Apps that expect the wrapper
163
+ * still accept raw text, like a classic terminal.
164
+ */
165
+ export function stripBracketedPasteMarkers(data: string): string {
166
+ if (data.length < PASTE_START.length) return data
167
+ if (!data.startsWith(PASTE_START)) return data
168
+ if (!data.endsWith(PASTE_END)) return data
169
+ return data.slice(PASTE_START.length, data.length - PASTE_END.length)
170
+ }