dsh-remote-vs 0.21.1 → 0.23.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.
Files changed (52) hide show
  1. package/README.en.md +489 -473
  2. package/README.md +434 -424
  3. package/cordis.patch.yml +13 -5
  4. package/lib/client.js +946 -256
  5. package/lib/index.js +187 -15
  6. package/lib/p2-router-fs.js +6 -7
  7. package/lib/types/changes/recorder.d.ts +21 -0
  8. package/lib/types/changes/status.d.ts +41 -1
  9. package/lib/types/changes/text-diff.d.ts +18 -0
  10. package/lib/types/client/changes/ChangesDock.d.ts +9 -2
  11. package/lib/types/client/changes/model.d.ts +3 -1
  12. package/lib/types/client/changes/review-state.d.ts +67 -0
  13. package/lib/types/client/notices.d.ts +35 -0
  14. package/lib/types/client/store.d.ts +51 -0
  15. package/lib/types/client/vsc/change-marks.d.ts +17 -0
  16. package/lib/types/client/vsc/kit.d.ts +9 -0
  17. package/lib/types/deploy.d.ts +28 -2
  18. package/lib/types/notices.d.ts +22 -0
  19. package/lib/types/p2/router-fs.d.ts +4 -5
  20. package/lib/types/p2/worlds.d.ts +10 -0
  21. package/lib/types/protocol.d.ts +37 -1
  22. package/lib/{worlds-DSzyajOB.js → worlds-DXdP4SMn.js} +80 -4
  23. package/package.json +37 -37
  24. package/src/changes/recorder.ts +93 -28
  25. package/src/changes/status.ts +69 -2
  26. package/src/changes/text-diff.ts +42 -0
  27. package/src/client/DirectoryFlow.tsx +65 -5
  28. package/src/client/api.ts +5 -0
  29. package/src/client/changes/ChangesDock.tsx +241 -39
  30. package/src/client/changes/changes.css +122 -9
  31. package/src/client/changes/model.ts +106 -22
  32. package/src/client/changes/review-state.ts +133 -0
  33. package/src/client/i18n.ts +48 -8
  34. package/src/client/index.tsx +24 -5
  35. package/src/client/notices.ts +86 -0
  36. package/src/client/store.tsx +186 -2
  37. package/src/client/vsc/change-marks.ts +39 -6
  38. package/src/client/vsc/kit.tsx +16 -1
  39. package/src/client/vsc/vsc.css +23 -0
  40. package/src/deploy.ts +38 -2
  41. package/src/http.ts +12 -1
  42. package/src/notices.ts +37 -0
  43. package/src/p2/router-fs.ts +5 -6
  44. package/src/p2/worlds.ts +46 -2
  45. package/src/protocol.ts +37 -1
  46. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.helper.json +19 -0
  47. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.tar.gz +4 -0
  48. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.tar.gz.sha256 +1 -0
  49. package/vendor/dsh-remote-helpers/ssh-helper-runtime-deps.patch +14 -0
  50. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.1-alpha.2-linux-x64.helper.json +0 -16
  51. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.1-alpha.2-linux-x64.tar.gz +0 -4
  52. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.1-alpha.2-linux-x64.tar.gz.sha256 +0 -1
@@ -165,6 +165,54 @@ function chipAt(at: number, text: string): RemovedChip | undefined {
165
165
  return { at, text: truncated ? text.slice(0, MAX_CHIP_CHARS) : text, truncated }
166
166
  }
167
167
 
168
+ /**
169
+ * How many lines of a collapsed deletion block travel as the tooltip preview.
170
+ *
171
+ * The pill only shows the COUNT, so the text is not on screen; it is still worth
172
+ * carrying a bounded prefix for the hover — enough to recognize the block, never
173
+ * enough to build a thousand-line title from a thousand-line removal.
174
+ */
175
+ const MAX_BLOCK_PREVIEW_LINES = 20
176
+
177
+ /**
178
+ * One chip for a run of deleted lines.
179
+ *
180
+ * A block deletion used to emit one chip PER line, every one of them at column 0
181
+ * of the same anchor line: a ten-line removal became ten struck-through
182
+ * fragments printed on top of each other, which says neither "ten lines" nor
183
+ * what they were. A run longer than a single line now collapses into one chip
184
+ * carrying the count (rendered as `−N 行已删除`) with a bounded preview in its
185
+ * title; a one-line removal keeps the exact text at the cut, which is the case
186
+ * where the struck-through words are genuinely readable.
187
+ *
188
+ * @param deleted - the run's deleted texts, in order.
189
+ * @param line - the line the run belongs to.
190
+ * @param anchor - the mark's anchor line (see {@link chipOnLine}).
191
+ */
192
+ function deletedRunChip(deleted: readonly string[], line: number, anchor: number): RemovedChip | undefined {
193
+ const [only] = deleted
194
+ if (only === undefined) return undefined
195
+ if (deleted.length === 1) {
196
+ const chip = chipAt(0, only)
197
+ return chip === undefined ? undefined : chipOnLine(chip, line, anchor)
198
+ }
199
+ const preview = deleted
200
+ .slice(0, MAX_BLOCK_PREVIEW_LINES)
201
+ .map(text => (text.length > MAX_CHIP_CHARS ? text.slice(0, MAX_CHIP_CHARS) : text))
202
+ .join('\n')
203
+ return chipOnLine(
204
+ {
205
+ at: 0,
206
+ text: preview,
207
+ // The preview was cut either by the line cap or by the line count.
208
+ truncated: deleted.length > MAX_BLOCK_PREVIEW_LINES || deleted.some(text => text.length > MAX_CHIP_CHARS),
209
+ count: deleted.length,
210
+ },
211
+ line,
212
+ anchor,
213
+ )
214
+ }
215
+
168
216
  /**
169
217
  * Attach `line` only when the fragment is NOT on the mark's anchor line.
170
218
  *
@@ -196,24 +244,57 @@ function shortEnough(deleted: readonly string[], added: readonly AddedLine[]): b
196
244
  /**
197
245
  * Fill in `mark.inline` / `mark.removed` for one modified block.
198
246
  *
199
- * Pairing is positional: the i-th deleted line of the block goes with the i-th
200
- * added line (git puts every deletion of a block before its additions, and a
201
- * block with unequal counts leaves the extras as pure additions/removals).
247
+ * Pairing happens in two phases, and the first one is what keeps the highlight
248
+ * honest:
249
+ *
250
+ * 1. **Exact matches are consumed first, at any index.** A block that was merely
251
+ * REORDERED (`a`,`b` → `b`,`a`) has no character-level change in it, but
252
+ * positional pairing compares `a` against `b` and paints "these characters
253
+ * changed" on two lines that did not change at all. The same phase fixes the
254
+ * common "one line inserted inside an edited run" shape, where every line
255
+ * after the insertion used to be paired with the wrong neighbour. Lookup goes
256
+ * through a text → indices map, so the phase stays linear in the block rather
257
+ * than quadratic in its lines.
258
+ * 2. **What is left pairs by position** — the i-th edited deletion with the i-th
259
+ * remaining addition. git puts every deletion of a block before its
260
+ * additions, and a block with unequal counts leaves the extras as pure
261
+ * additions/removals.
202
262
  *
203
263
  * @param mark - the block's mark (mutated).
204
264
  * @param deleted - the block's deleted texts, in order.
205
265
  * @param added - the block's added lines, in order.
206
266
  */
207
267
  function attachInline(mark: ChangeMark, deleted: readonly string[], added: readonly AddedLine[]): void {
208
- const pairs = Math.min(deleted.length, added.length)
268
+ // Phase 1 — consume lines that did not change, only moved.
269
+ const pending = new Map<string, number[]>()
270
+ added.forEach((item, index) => {
271
+ const list = pending.get(item.text)
272
+ if (list === undefined) pending.set(item.text, [index])
273
+ else list.push(index)
274
+ })
275
+ const edited: string[] = []
276
+ const used = new Array<boolean>(added.length).fill(false)
277
+ for (const text of deleted) {
278
+ const list = pending.get(text)
279
+ if (list === undefined || list.length === 0) {
280
+ edited.push(text)
281
+ continue
282
+ }
283
+ const index = list.shift()
284
+ if (index !== undefined) used[index] = true
285
+ }
286
+ const fresh = added.filter((_item, index) => !used[index])
287
+
288
+ // Phase 2 — positional pairing over the survivors.
289
+ const pairs = Math.min(edited.length, fresh.length)
209
290
  const inline: InlineRange[] = []
210
291
  const removed: RemovedChip[] = []
211
292
  for (let index = 0; index < pairs; index += 1) {
212
- const before = deleted[index]
213
- const after = added[index].text
214
- const line = added[index].line
215
- // A pair that came out identical (the block was reordered, not rewritten).
216
- if (before === after) continue
293
+ const before = edited[index]
294
+ const item = fresh[index]
295
+ if (before === undefined || item === undefined) continue
296
+ const after = item.text
297
+ const line = item.line
217
298
  const { head, oldMid, newMid } = splitCommon(before, after)
218
299
  if (newMid.length === 0) {
219
300
  // The line was only shortened: there is no new character to paint, so the
@@ -231,11 +312,10 @@ function attachInline(mark: ChangeMark, deleted: readonly string[], added: reado
231
312
  for (const range of refineRanges(oldMid, newMid, head)) inline.push(rangeOnLine(range, line, mark.from))
232
313
  }
233
314
  // Deleted lines with no added counterpart: their text no longer exists in the
234
- // new file, so it hangs on the anchor line's first column as a chip.
235
- for (let index = pairs; index < deleted.length; index += 1) {
236
- const chip = chipAt(0, deleted[index])
237
- if (chip !== undefined) removed.push(chip)
238
- }
315
+ // new file, so it hangs on the anchor line's first column — as one collapsed
316
+ // chip when the run is longer than a line (see `deletedRunChip`).
317
+ const tailChip = deletedRunChip(edited.slice(pairs), mark.from, mark.from)
318
+ if (tailChip !== undefined) removed.push(tailChip)
239
319
  if (inline.length > 0) mark.inline = inline
240
320
  if (removed.length > 0) mark.removed = removed
241
321
  }
@@ -280,13 +360,14 @@ function collectHunk(hunk: UnifiedHunk, marks: ChangeMark[], index: number): num
280
360
  } else if (deleted.length > 0) {
281
361
  const anchor = Math.max(1, line)
282
362
  const mark: ChangeMark = { from: anchor, to: anchor, kind: 'del', hunk: index }
283
- if (inlineAllowed && deleted.every(text => text.length <= MAX_INLINE_LINE)) {
284
- const chips: RemovedChip[] = []
285
- for (const text of deleted) {
286
- const chip = chipAt(0, text)
287
- if (chip !== undefined) chips.push(chip)
288
- }
289
- if (chips.length > 0) mark.removed = chips
363
+ // A collapsed block pill carries a bounded preview only, so the per-line
364
+ // length cap (which exists to keep character-level work bounded) does not
365
+ // apply to it; a single deleted line still has to fit before its text is
366
+ // put on screen.
367
+ const printable = deleted.length > 1 || deleted.every(text => text.length <= MAX_INLINE_LINE)
368
+ if (inlineAllowed && printable) {
369
+ const chip = deletedRunChip(deleted, anchor, anchor)
370
+ if (chip !== undefined) mark.removed = [chip]
290
371
  }
291
372
  marks.push(mark)
292
373
  first ??= anchor
@@ -319,9 +400,11 @@ function collectHunk(hunk: UnifiedHunk, marks: ChangeMark[], index: number): num
319
400
  *
320
401
  * @param hunks - served hunks for the whole session.
321
402
  * @param stamp - identity of the comparison (file + baseline + turn).
403
+ * @param filePatch - the host's whole-file reverse patch, when it served one
404
+ * (see `ChangeSet.filePatch`); '' / missing = nothing to revert as a whole.
322
405
  * @returns the mark set the editor paints, or {@link EMPTY_CHANGE_SET}.
323
406
  */
324
- export function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string): ChangeSet {
407
+ export function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string, filePatch?: string): ChangeSet {
325
408
  if (hunks.length === 0) return { marks: [], hunks: [], stamp, patches: [] }
326
409
  const marks: ChangeMark[] = []
327
410
  // `hunks[i]` / `patches[i]` must stay in step with the mark's `hunk` index, so
@@ -343,5 +426,6 @@ export function changeSetFromHunks(hunks: readonly UnifiedHunk[], stamp: string)
343
426
  hunks: [...new Set(order.map(anchor => anchor.line))],
344
427
  stamp,
345
428
  patches,
429
+ ...(filePatch === undefined || filePatch === '' ? {} : { filePatch }),
346
430
  }
347
431
  }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * 「这个文件我看过了」的本地标记。
3
+ *
4
+ * 会话改动面板原本只能看、不能收敛:一次三十个文件的重构,没有任何地方记得"这个我
5
+ * 已经审过",列表和游标每次都从头上开始。这里补的是**纯客户端**的审阅状态 —— 它不
6
+ * 写远端、不进账本、不影响任何一次 `git` 调用,因此是这条路线上唯一零风险的收敛手段
7
+ * ("接受改动"的另一半语义是真正的 `git apply --cached`,那要求基线等于索引,属于另一
8
+ * 个决定,**不在本模块**里)。
9
+ *
10
+ * ## 为什么键里带计数
11
+ *
12
+ * 键 = 路径 + 增删行数 + 状态。会话又改了同一批行(行数随之变化)时,旧标记自然失效,
13
+ * 文件重新变成"未审阅"——这正是想要的效果,而且不需要监听任何事件。行数完全没变的
14
+ * 二次编辑仍会被当成"已审阅",这是这套方案的已知盲点:它与"审阅的是哪一版"这个事实
15
+ * 相比,代价远小于为每个文件拉一次 diff 去算指纹。
16
+ *
17
+ * 纯函数 + 一个带上限的表,`scripts/check-review-state.mjs` 直接驱动真实的判定。
18
+ */
19
+
20
+ /** 面板能给的一行(`RemoteChangedFile` 的投影)。 */
21
+ export interface ReviewSubject {
22
+ /** 远端绝对路径(唯一标识)。 */
23
+ path: string
24
+ added: number
25
+ deleted: number
26
+ status?: string
27
+ }
28
+
29
+ /** 已审阅集合:键 → 1(用对象是为了能直接 JSON 往返)。 */
30
+ export type ReviewedMap = Readonly<Record<string, 1>>
31
+
32
+ /** 一个会话最多记住这么多条(长命页面不能无限长)。 */
33
+ export const REVIEW_CAP = 1000
34
+
35
+ /**
36
+ * 一行的审阅键。
37
+ *
38
+ * 计数进键里是刻意的:见文件头。`status` 也进键,因为"删掉了又加回来"和"一直在改"
39
+ * 是两件不同的事,标签变了就该重新看一遍。
40
+ *
41
+ * @param file - 面板的一行。
42
+ * @returns 稳定的键(路径里可能有任意字符,用 NUL 分隔不会与计数撞)。
43
+ */
44
+ export function reviewKeyOf(file: ReviewSubject): string {
45
+ return `${file.path}\u0000${file.added}\u0000${file.deleted}\u0000${file.status ?? ''}`
46
+ }
47
+
48
+ /** 这一行是否已被标为审阅。 */
49
+ export function isReviewed(file: ReviewSubject, reviewed: ReviewedMap): boolean {
50
+ return reviewed[reviewKeyOf(file)] === 1
51
+ }
52
+
53
+ /** 已审阅的行数(只数当前列表里的,所以它永远 ≤ 列表长度)。 */
54
+ export function reviewedCount(files: readonly ReviewSubject[], reviewed: ReviewedMap): number {
55
+ let count = 0
56
+ for (const file of files) if (isReviewed(file, reviewed)) count += 1
57
+ return count
58
+ }
59
+
60
+ /** 切换一行的标记,返回新表(输入不被修改)。 */
61
+ export function toggleReviewed(files: readonly ReviewSubject[], reviewed: ReviewedMap, file: ReviewSubject): Record<string, 1> {
62
+ const key = reviewKeyOf(file)
63
+ const next: Record<string, 1> = {}
64
+ for (const [candidate, value] of Object.entries(reviewed)) next[candidate] = value
65
+ if (next[key] === 1) delete next[key]
66
+ else next[key] = 1
67
+ return pruneReviewed(files, next)
68
+ }
69
+
70
+ /** 全标或全清。 */
71
+ export function setAllReviewed(files: readonly ReviewSubject[], on: boolean): Record<string, 1> {
72
+ if (!on) return {}
73
+ const next: Record<string, 1> = {}
74
+ for (const file of files) {
75
+ if (next[reviewKeyOf(file)] === 1) continue
76
+ next[reviewKeyOf(file)] = 1
77
+ if (Object.keys(next).length >= REVIEW_CAP) break
78
+ }
79
+ return next
80
+ }
81
+
82
+ /**
83
+ * 丢掉不属于当前列表的键。
84
+ *
85
+ * 列表每 3 秒重建一次,一条被删掉(或计数变了)的键如果留着,下次同一路径回到列表
86
+ * 时会被当成"已审阅"——那是凭空出现的勾。清理放在每次写入与每次加载后都做,代价是
87
+ * O(列表长度)。
88
+ */
89
+ export function pruneReviewed(files: readonly ReviewSubject[], reviewed: ReviewedMap): Record<string, 1> {
90
+ const live = new Set(files.map(file => reviewKeyOf(file)))
91
+ const next: Record<string, 1> = {}
92
+ let kept = 0
93
+ for (const [key, value] of Object.entries(reviewed)) {
94
+ if (value !== 1 || !live.has(key)) continue
95
+ next[key] = 1
96
+ kept += 1
97
+ if (kept >= REVIEW_CAP) break
98
+ }
99
+ return next
100
+ }
101
+
102
+ /**
103
+ * 解析持久化的一串 JSON。
104
+ *
105
+ * 任何畸形输入都给空表而不是抛错:这份状态是"看过没看过",读不出来最多重看一遍,
106
+ * 不值得让面板崩掉。键必须是字符串、值必须是 1,且受 {@link REVIEW_CAP} 限制。
107
+ *
108
+ * @param raw - `localStorage` 里存着的那串文本(可能为 null)。
109
+ */
110
+ export function parseReviewed(raw: string | null | undefined): Record<string, 1> {
111
+ if (typeof raw !== 'string' || raw === '') return {}
112
+ let parsed: unknown
113
+ try {
114
+ parsed = JSON.parse(raw)
115
+ } catch {
116
+ return {}
117
+ }
118
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {}
119
+ const next: Record<string, 1> = {}
120
+ let kept = 0
121
+ for (const [key, value] of Object.entries(parsed as Record<string, unknown>)) {
122
+ if (value !== 1 || key === '') continue
123
+ next[key] = 1
124
+ kept += 1
125
+ if (kept >= REVIEW_CAP) break
126
+ }
127
+ return next
128
+ }
129
+
130
+ /** 序列化(键数量已受上限约束,所以这串不会无限长)。 */
131
+ export function serializeReviewed(reviewed: ReviewedMap): string {
132
+ return JSON.stringify(reviewed)
133
+ }
@@ -100,6 +100,7 @@ const zh: Record<string, string> = {
100
100
  'hosts.unknownError': '未知错误',
101
101
  'hosts.deleted': '{alias}:已删除',
102
102
  'hosts.saved': '{alias}:已保存',
103
+ 'hosts.helperPushed': '{alias}:已自动推送远端 helper {version}',
103
104
  'hosts.imported': '已导入 {count} 个主机',
104
105
  'hosts.importedSkipped': ';跳过:{list}',
105
106
  'form.alias': '别名',
@@ -207,9 +208,9 @@ const zh: Record<string, string> = {
207
208
  'term.new': '新建终端',
208
209
  'term.empty': '还没有终端 —— 选好主机后点右上角 + 新建一个。',
209
210
  'term.close': '关闭终端',
210
- 'term.closeTitle': '关闭这个终端',
211
- 'term.copy': '复制',
212
- 'term.paste': '粘贴',
211
+ 'term.closeTitle': '关闭这个终端',
212
+ 'term.copy': '复制',
213
+ 'term.paste': '粘贴',
213
214
  'term.selectAll': '全选',
214
215
  'term.noHosts': '还没有主机,请先去「设置 → 远程主机」配置。',
215
216
  'tab.git': 'Git',
@@ -574,7 +575,26 @@ const zh: Record<string, string> = {
574
575
  'changes.statusDeleted': '删除',
575
576
  'changes.statusModified': '修改',
576
577
  'changes.statusRenamed': '重命名',
577
- 'changes.truncated': '文件过多,只列出前 500 个(统计数字仍为全部)。',
578
+ 'changes.truncated': '文件过多,只列出前 500 个(统计数字也只算这 500 个)。',
579
+ 'changes.excluded': '未统计构建产物目录:{dirs}',
580
+ 'changes.markReviewed': '标记为已审阅',
581
+ 'changes.unmarkReviewed': '取消审阅标记',
582
+ 'changes.reviewCount': '已审阅 {done}/{total}',
583
+ 'changes.reviewMenu': '审阅标记选项',
584
+ 'changes.reviewAll': '全部标为已审阅',
585
+ 'changes.reviewNone': '清除审阅标记',
586
+ 'changes.menuOpen': '打开',
587
+ 'changes.openInScm': '在 SCM 中查看',
588
+ 'changes.copyPath': '复制远端路径',
589
+ 'changes.revertFile': '撤销该文件的全部改动',
590
+ 'changes.revertNotPossible': '无法撤销(新建、二进制或过大)',
591
+ 'changes.revertCreation': '撤销新建(删除该文件)',
592
+ 'changes.revertCreationOk': '删除该文件',
593
+ 'changes.revertCreationTitle': '撤回这个新建文件?',
594
+ 'changes.revertCreationText': '会删除 {path}。git 索引里还留着内容,可以用 git checkout 恢复。',
595
+ 'changes.revertedFile': '已撤销该文件的改动',
596
+ 'changes.revertFailed': '撤销失败',
597
+ 'changes.deletedCreation': '已删除新建文件',
578
598
  'changes.prev': '上一个修改点',
579
599
  'changes.next': '下一个修改点',
580
600
  'changes.navLabel': '改动跳转',
@@ -718,6 +738,7 @@ const en: Record<string, string> = {
718
738
  'hosts.unknownError': 'unknown error',
719
739
  'hosts.deleted': '{alias}: deleted',
720
740
  'hosts.saved': '{alias}: saved',
741
+ 'hosts.helperPushed': '{alias}: pushed remote helper {version} automatically',
721
742
  'hosts.imported': 'Imported {count} host(s)',
722
743
  'hosts.importedSkipped': '; skipped: {list}',
723
744
  'form.alias': 'Alias',
@@ -825,9 +846,9 @@ const en: Record<string, string> = {
825
846
  'term.new': 'New terminal',
826
847
  'term.empty': 'No terminal yet — pick a host, then press + to open one.',
827
848
  'term.close': 'Close terminal',
828
- 'term.closeTitle': 'Close this terminal',
829
- 'term.copy': 'Copy',
830
- 'term.paste': 'Paste',
849
+ 'term.closeTitle': 'Close this terminal',
850
+ 'term.copy': 'Copy',
851
+ 'term.paste': 'Paste',
831
852
  'term.selectAll': 'Select all',
832
853
  'term.noHosts': 'No hosts yet. Configure one in Settings → Remote Hosts first.',
833
854
  'tab.git': 'Git',
@@ -1192,7 +1213,26 @@ const en: Record<string, string> = {
1192
1213
  'changes.statusDeleted': 'deleted',
1193
1214
  'changes.statusModified': 'modified',
1194
1215
  'changes.statusRenamed': 'renamed',
1195
- 'changes.truncated': 'Too many files: the first 500 are listed (totals cover all of them).',
1216
+ 'changes.truncated': 'Too many files: the first 500 are listed (the counts cover only those).',
1217
+ 'changes.excluded': 'Build output directories not counted: {dirs}',
1218
+ 'changes.markReviewed': 'Mark as reviewed',
1219
+ 'changes.unmarkReviewed': 'Clear the review mark',
1220
+ 'changes.reviewCount': '{done}/{total} reviewed',
1221
+ 'changes.reviewMenu': 'Review mark options',
1222
+ 'changes.reviewAll': 'Mark all as reviewed',
1223
+ 'changes.reviewNone': 'Clear all review marks',
1224
+ 'changes.menuOpen': 'Open',
1225
+ 'changes.openInScm': 'Show in Source Control',
1226
+ 'changes.copyPath': 'Copy remote path',
1227
+ 'changes.revertFile': 'Revert all changes in this file',
1228
+ 'changes.revertNotPossible': 'Cannot be reverted (new file, binary or too large)',
1229
+ 'changes.revertCreation': 'Undo the new file (delete it)',
1230
+ 'changes.revertCreationOk': 'Delete the file',
1231
+ 'changes.revertCreationTitle': 'Undo this new file?',
1232
+ 'changes.revertCreationText': 'It deletes {path}. git keeps the bytes in its index, so git checkout can bring it back.',
1233
+ 'changes.revertedFile': 'Reverted this file',
1234
+ 'changes.revertFailed': 'Revert failed',
1235
+ 'changes.deletedCreation': 'Deleted the new file',
1196
1236
  'changes.prev': 'Previous change',
1197
1237
  'changes.next': 'Next change',
1198
1238
  'changes.navLabel': 'Change navigation',
@@ -29,7 +29,8 @@ import { ChangesDock, type ChangesDockProps } from './changes/ChangesDock.tsx'
29
29
  import { SettingsHostsSection, SettingsWorkspacesSection } from './SettingsHosts.tsx'
30
30
  import { openFloatingEditor, setEditorSurface } from './store.tsx'
31
31
  import { detectLang, makeT } from './i18n.ts'
32
- import { setIconService, type IconServiceLike } from './vsc/kit.tsx'
32
+ import { DialogHost, setIconService, toast, type IconServiceLike } from './vsc/kit.tsx'
33
+ import { setHostNoticeEmitter } from './notices.ts'
33
34
 
34
35
  /** Services required before mounting (slots/uiWorkspace are core web services). */
35
36
  export const inject = ['slots', 'uiWorkspace']
@@ -310,6 +311,7 @@ export function apply(ctx: Context): void {
310
311
  // the menu entry can never point at a window that cannot paint.
311
312
  ctx.effect(() => {
312
313
  let dispose: (() => void) | undefined
314
+ let disposeNotices: (() => void) | undefined
313
315
  try {
314
316
  const slots = ctx.slots as unknown as {
315
317
  inject(slot: string, register: () => () => void): () => void
@@ -323,16 +325,33 @@ export function apply(ctx: Context): void {
323
325
  id: 'remote-vs:floating-editor',
324
326
  order: 40,
325
327
  }, () => <FloatingEditorWindow ctx={ctx} />))
328
+ // A frame-wide toast/confirm host. DialogHost arbitrates a single portal
329
+ // (the first mounted host renders), so this seat only guarantees one exists
330
+ // while the Web app runs: an automatic helper push is announced even when
331
+ // no remote-workspace surface — RemoteRoot, the editor view — is mounted.
332
+ disposeNotices = slots.inject('shell.overlay', () => slots.register({
333
+ name: 'shell.overlay',
334
+ id: 'remote-vs:toast-host',
335
+ order: 41,
336
+ }, () => <DialogHost />))
326
337
  } catch (error) {
327
338
  console.warn('[dsh-remote-vs] shell.overlay registration failed (floating editor unavailable):', error)
328
339
  return () => {}
329
340
  }
330
341
  return () => {
331
- try {
332
- dispose?.()
333
- } catch {
334
- // Ignore.
342
+ for (const teardown of [dispose, disposeNotices]) {
343
+ try {
344
+ teardown?.()
345
+ } catch {
346
+ // Ignore.
347
+ }
335
348
  }
336
349
  }
337
350
  }, 'dsh-remote-vs: floating editor window')
351
+ // Host notices (an automatic helper push) become the plugin's toast; the
352
+ // emitter lives here because the API layer must stay JSX-free.
353
+ ctx.effect(() => {
354
+ setHostNoticeEmitter(toast)
355
+ return () => setHostNoticeEmitter(undefined)
356
+ }, 'dsh-remote-vs: host notice toasts')
338
357
  }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Client side of the Host's one-shot notices (`src/notices.ts`).
3
+ *
4
+ * The Host attaches notices to a JSON response when an automatic helper push ran
5
+ * during that request; the API wrapper calls {@link dispatchHostNotices} after
6
+ * parsing, and the message goes through the plugin's toast layer (bottom-right,
7
+ * auto-dismiss) so the event is visible wherever the user is — including the
8
+ * conversation view, where no remote-workspace surface is mounted.
9
+ *
10
+ * The emitter is REGISTERED by the client entry instead of imported here: this
11
+ * module sits on the API path, which several offline gates load with a
12
+ * TypeScript-only loader. Importing the JSX widget kit from `api.ts` would drag
13
+ * React components into those loaders (they cannot transpile JSX) for a message
14
+ * that only needs a string.
15
+ */
16
+ import type { HostNotice } from '../notices.ts'
17
+ import { detectLang, makeT } from './i18n.ts'
18
+
19
+ /** How the toast layer receives one rendered message. */
20
+ export type HostNoticeEmitter = (text: string) => void
21
+
22
+ const MAX_QUEUED = 8
23
+ let emitter: HostNoticeEmitter | undefined
24
+ let queued: string[] = []
25
+
26
+ /**
27
+ * Install (or remove) the toast emitter; the client entry owns the lifetime.
28
+ *
29
+ * Messages that arrived before the entry registered are flushed, so a notice
30
+ * produced during the first remote operation of a page load cannot be lost.
31
+ */
32
+ export function setHostNoticeEmitter(next: HostNoticeEmitter | undefined): void {
33
+ emitter = next
34
+ if (next === undefined) return
35
+ const pending = queued
36
+ queued = []
37
+ for (const text of pending) next(text)
38
+ }
39
+
40
+ /** Render one notice in the page language. */
41
+ export function formatHostNotice(notice: HostNotice, lang = detectLang()): string {
42
+ const t = makeT(lang)
43
+ if (notice.kind === 'helper-pushed') {
44
+ return t('hosts.helperPushed')
45
+ .replace('{alias}', notice.alias)
46
+ .replace('{version}', notice.version)
47
+ }
48
+ // Unknown kinds are dropped by the dispatcher before reaching here.
49
+ return ''
50
+ }
51
+
52
+ /** Deliver one rendered message: to the emitter when present, else queue it. */
53
+ function deliver(text: string, emit?: HostNoticeEmitter): void {
54
+ const target = emit ?? emitter
55
+ if (target !== undefined) {
56
+ target(text)
57
+ return
58
+ }
59
+ if (queued.length < MAX_QUEUED) queued = [...queued, text]
60
+ }
61
+
62
+ /**
63
+ * Show every valid notice carried by one API response.
64
+ *
65
+ * `emit` is injectable so a gate can drive this without React or a DOM. A
66
+ * malformed payload is ignored: a newer/older peer must never turn a successful
67
+ * remote operation into a client exception.
68
+ */
69
+ export function dispatchHostNotices(payload: unknown, emit?: HostNoticeEmitter): number {
70
+ if (typeof payload !== 'object' || payload === null) return 0
71
+ const raw = (payload as { notices?: unknown }).notices
72
+ if (!Array.isArray(raw)) return 0
73
+ let shown = 0
74
+ for (const entry of raw) {
75
+ if (typeof entry !== 'object' || entry === null) continue
76
+ const notice = entry as Partial<HostNotice>
77
+ if (notice.kind !== 'helper-pushed') continue
78
+ if (typeof notice.alias !== 'string' || typeof notice.version !== 'string') continue
79
+ if (notice.alias === '' || notice.version === '') continue
80
+ const text = formatHostNotice({ kind: 'helper-pushed', alias: notice.alias, version: notice.version })
81
+ if (text === '') continue
82
+ deliver(text, emit)
83
+ shown += 1
84
+ }
85
+ return shown
86
+ }