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.
- package/README.en.md +489 -473
- package/README.md +434 -424
- package/cordis.patch.yml +13 -5
- package/lib/client.js +946 -256
- package/lib/index.js +187 -15
- package/lib/p2-router-fs.js +6 -7
- package/lib/types/changes/recorder.d.ts +21 -0
- package/lib/types/changes/status.d.ts +41 -1
- package/lib/types/changes/text-diff.d.ts +18 -0
- package/lib/types/client/changes/ChangesDock.d.ts +9 -2
- package/lib/types/client/changes/model.d.ts +3 -1
- package/lib/types/client/changes/review-state.d.ts +67 -0
- package/lib/types/client/notices.d.ts +35 -0
- package/lib/types/client/store.d.ts +51 -0
- package/lib/types/client/vsc/change-marks.d.ts +17 -0
- package/lib/types/client/vsc/kit.d.ts +9 -0
- package/lib/types/deploy.d.ts +28 -2
- package/lib/types/notices.d.ts +22 -0
- package/lib/types/p2/router-fs.d.ts +4 -5
- package/lib/types/p2/worlds.d.ts +10 -0
- package/lib/types/protocol.d.ts +37 -1
- package/lib/{worlds-DSzyajOB.js → worlds-DXdP4SMn.js} +80 -4
- package/package.json +37 -37
- package/src/changes/recorder.ts +93 -28
- package/src/changes/status.ts +69 -2
- package/src/changes/text-diff.ts +42 -0
- package/src/client/DirectoryFlow.tsx +65 -5
- package/src/client/api.ts +5 -0
- package/src/client/changes/ChangesDock.tsx +241 -39
- package/src/client/changes/changes.css +122 -9
- package/src/client/changes/model.ts +106 -22
- package/src/client/changes/review-state.ts +133 -0
- package/src/client/i18n.ts +48 -8
- package/src/client/index.tsx +24 -5
- package/src/client/notices.ts +86 -0
- package/src/client/store.tsx +186 -2
- package/src/client/vsc/change-marks.ts +39 -6
- package/src/client/vsc/kit.tsx +16 -1
- package/src/client/vsc/vsc.css +23 -0
- package/src/deploy.ts +38 -2
- package/src/http.ts +12 -1
- package/src/notices.ts +37 -0
- package/src/p2/router-fs.ts +5 -6
- package/src/p2/worlds.ts +46 -2
- package/src/protocol.ts +37 -1
- package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.helper.json +19 -0
- package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.tar.gz +4 -0
- package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.tar.gz.sha256 +1 -0
- package/vendor/dsh-remote-helpers/ssh-helper-runtime-deps.patch +14 -0
- package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.1-alpha.2-linux-x64.helper.json +0 -16
- package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.1-alpha.2-linux-x64.tar.gz +0 -4
- package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.1-alpha.2-linux-x64.tar.gz.sha256 +0 -1
package/src/client/store.tsx
CHANGED
|
@@ -28,6 +28,7 @@ import { buildDiffModel } from './scm/diff-model.ts'
|
|
|
28
28
|
import type { ChangeMark, ChangeSet } from './vsc/change-marks.ts'
|
|
29
29
|
import { changeSetFromHunks } from './changes/model.ts'
|
|
30
30
|
import { undoContext, type UndoContext } from './changes/undo-context.ts'
|
|
31
|
+
import { changeOriginForTab, resolveUndoTarget } from './changes/undo-target.ts'
|
|
31
32
|
import { applyStageOverrides, bucketStatus, buildTreeMarks, insertStagedEntry, optimisticStageDetail, type ChangeEntry, type StageOverride, type StatusBuckets, type TreeMarks } from './scm/status-map.ts'
|
|
32
33
|
import { loadCommitFileDiff, findRepos, loadDiff, loadHead, loadStatusDetail, probeRepoRoot, probeStatusDir, probeStatusPaths, applyHunk, stagePaths, unstagePaths, type DiffPayload } from './scm/actions.ts'
|
|
33
34
|
import { StageCoordinator } from './scm/stage-queue.ts'
|
|
@@ -647,6 +648,12 @@ export interface ExplorerValue {
|
|
|
647
648
|
* `changeSet.marks`,`hunk` 是 `patches` 的下标)。
|
|
648
649
|
*/
|
|
649
650
|
undoChange: (tabId: string, mark: ChangeMark) => Promise<void>
|
|
651
|
+
/**
|
|
652
|
+
* 撤销本会话对某个文件的**全部**改动(改动面板那一行的动作)。
|
|
653
|
+
*
|
|
654
|
+
* @returns 远端是否真的写了(`false` = 被某道门拒了,文件未变)。
|
|
655
|
+
*/
|
|
656
|
+
revertFileChanges: (target: RevertFileTarget) => Promise<boolean>
|
|
650
657
|
/**
|
|
651
658
|
* Write one file tab back to the remote host.
|
|
652
659
|
* @returns true only when the write really succeeded — the caller uses it to
|
|
@@ -770,6 +777,7 @@ function build(): ExplorerValue {
|
|
|
770
777
|
gotoChange,
|
|
771
778
|
markChangeStale,
|
|
772
779
|
undoChange,
|
|
780
|
+
revertFileChanges,
|
|
773
781
|
saveTab,
|
|
774
782
|
dismissConflict,
|
|
775
783
|
reloadTab,
|
|
@@ -2616,7 +2624,31 @@ async function performSave(id: string, text: string, force: boolean): Promise<bo
|
|
|
2616
2624
|
})
|
|
2617
2625
|
markLiveEditorSaved(id, text)
|
|
2618
2626
|
toast(`${t('editor.saved')} · ${target.rel}`, false)
|
|
2619
|
-
|
|
2627
|
+
/**
|
|
2628
|
+
* The write is DONE, and the save result must not include a remote git read.
|
|
2629
|
+
*
|
|
2630
|
+
* `afterWrite()` re-reads `git status` and only then re-lists the tree. On a
|
|
2631
|
+
* monorepo that read is the expensive half (the SCM panel shows the same cost:
|
|
2632
|
+
* seconds, and minutes when the tree is cold), and awaiting it here made the
|
|
2633
|
+
* editor's "saving…" last exactly that long — which is what "saving is slow,
|
|
2634
|
+
* it refreshes git first" looks like from the outside. Nothing the save
|
|
2635
|
+
* REPORTS depends on it: the baseline advances from the write's own answer
|
|
2636
|
+
* above, and the dirty flag is re-derived synchronously.
|
|
2637
|
+
*
|
|
2638
|
+
* So it runs in the background. It still runs — the status marks and the tree
|
|
2639
|
+
* revision catch up when it lands — and the read queue collapses a burst of
|
|
2640
|
+
* saves into at most one follow-up walk (`ReadQueue.run(..., 'fresh')`).
|
|
2641
|
+
*/
|
|
2642
|
+
void afterWrite()
|
|
2643
|
+
/**
|
|
2644
|
+
* The save just changed what this file looks like against the session
|
|
2645
|
+
* baseline, so the marks painted from the PREVIOUS bytes are gone (typing
|
|
2646
|
+
* invalidates them by design) — and nothing used to bring them back until the
|
|
2647
|
+
* user clicked the row in the change panel again. Re-fetch them from the tab's
|
|
2648
|
+
* own recorded provenance, which needs no panel interaction. Also background:
|
|
2649
|
+
* it is one more remote read that must not stand between the user and "saved".
|
|
2650
|
+
*/
|
|
2651
|
+
refreshChangeSetForTab(id)
|
|
2620
2652
|
return true
|
|
2621
2653
|
} catch (error) {
|
|
2622
2654
|
/**
|
|
@@ -2915,7 +2947,7 @@ async function refreshChangeSet(tabId: string, context: UndoContext): Promise<vo
|
|
|
2915
2947
|
applyChangeSet(tabId, null)
|
|
2916
2948
|
return
|
|
2917
2949
|
}
|
|
2918
|
-
applyChangeSet(tabId, changeSetFromHunks(diff.hunks, `${tab.fullPath}@${Date.now()}
|
|
2950
|
+
applyChangeSet(tabId, changeSetFromHunks(diff.hunks, `${tab.fullPath}@${Date.now()}`, diff.patch))
|
|
2919
2951
|
} catch {
|
|
2920
2952
|
// A read that fails leaves no marks rather than wrong ones.
|
|
2921
2953
|
applyChangeSet(tabId, null)
|
|
@@ -3002,6 +3034,158 @@ export async function undoChange(tabId: string, mark: ChangeMark): Promise<void>
|
|
|
3002
3034
|
void api.changes.list(context.sessionId, true).catch(() => undefined)
|
|
3003
3035
|
}
|
|
3004
3036
|
|
|
3037
|
+
/**
|
|
3038
|
+
* Coordinates for "undo everything this session did to this file".
|
|
3039
|
+
*
|
|
3040
|
+
* Handed over by the change panel, which is the only surface that knows both the
|
|
3041
|
+
* file and the session it belongs to. `mode` comes from the HOST
|
|
3042
|
+
* (`RemoteChangedFile.revert`), never from the client: only git can say whether a
|
|
3043
|
+
* creation has a copy to fall back on.
|
|
3044
|
+
*/
|
|
3045
|
+
export interface RevertFileTarget {
|
|
3046
|
+
sessionId: string
|
|
3047
|
+
bindingId: string
|
|
3048
|
+
alias: string
|
|
3049
|
+
root: string
|
|
3050
|
+
path: string
|
|
3051
|
+
display: string
|
|
3052
|
+
mode: 'patch' | 'delete'
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
/**
|
|
3056
|
+
* Revert one file's WHOLE session change set (the panel row's action).
|
|
3057
|
+
*
|
|
3058
|
+
* Three things make this a separate path from `undoChange`, and each one is
|
|
3059
|
+
* load-bearing:
|
|
3060
|
+
*
|
|
3061
|
+
* 1. **It works without an open tab.** The panel lists files nobody opened, so
|
|
3062
|
+
* the coordinates cannot come from `undoContext()` (which describes the tab on
|
|
3063
|
+
* screen). They arrive with the call and are validated by the SAME rules
|
|
3064
|
+
* (`resolveUndoTarget`: session agreement, binding identity, path under the
|
|
3065
|
+
* ledger root) — a row from another conversation, or from a sibling binding
|
|
3066
|
+
* that happens to share the alias, is refused rather than guessed.
|
|
3067
|
+
* 2. **It is ONE remote write.** The host serves the file as a single patch, which
|
|
3068
|
+
* is exactly what `git apply -R` needs to restore the session baseline; a loop
|
|
3069
|
+
* of per-hunk applies would shift every later hunk and report a conflict
|
|
3070
|
+
* halfway through, leaving the file half reverted.
|
|
3071
|
+
* 3. **A creation is not a patch.** `mode: 'delete'` (a tracked addition, where
|
|
3072
|
+
* git still holds the bytes) deletes the file behind an explicit confirmation;
|
|
3073
|
+
* an untracked creation never reaches here, because the host offers no mode
|
|
3074
|
+
* for it.
|
|
3075
|
+
*
|
|
3076
|
+
* The order of the gates is the one `undoChange` established: an unsaved buffer
|
|
3077
|
+
* refuses first (a remote write must never overwrite what the user has not
|
|
3078
|
+
* saved), then the offline check, then the coordinates, then the patch.
|
|
3079
|
+
*
|
|
3080
|
+
* @returns whether the remote was actually written.
|
|
3081
|
+
*/
|
|
3082
|
+
export async function revertFileChanges(target: RevertFileTarget): Promise<boolean> {
|
|
3083
|
+
const tab = state.tabs.find(item => item.kind === 'file' && item.fullPath === target.path)
|
|
3084
|
+
if (tab?.dirty === true) {
|
|
3085
|
+
info(t('changes.undoDirty'))
|
|
3086
|
+
return false
|
|
3087
|
+
}
|
|
3088
|
+
if (connectionStateOf(target.alias) === 'error') {
|
|
3089
|
+
info(t('connection.actionFailed'))
|
|
3090
|
+
return false
|
|
3091
|
+
}
|
|
3092
|
+
const origin = {
|
|
3093
|
+
sessionId: target.sessionId,
|
|
3094
|
+
bindingId: target.bindingId,
|
|
3095
|
+
alias: target.alias,
|
|
3096
|
+
root: target.root,
|
|
3097
|
+
}
|
|
3098
|
+
/**
|
|
3099
|
+
* The session check inside `resolveUndoTarget` is trivially true here (the panel
|
|
3100
|
+
* passed both ids), and that is fine: the panel can only hand over a row from the
|
|
3101
|
+
* summary it fetched FOR this session (`data.id === sessionId`). What this call
|
|
3102
|
+
* really answers is the part the panel cannot know: is that binding still the
|
|
3103
|
+
* same one (id + alias), and does this path still sit under the ledger root the
|
|
3104
|
+
* patch was computed against?
|
|
3105
|
+
*/
|
|
3106
|
+
const resolved = resolveUndoTarget({
|
|
3107
|
+
origin,
|
|
3108
|
+
tabPath: target.path,
|
|
3109
|
+
panelSessionId: target.sessionId,
|
|
3110
|
+
bindings: remoteOpenBindings().bindings,
|
|
3111
|
+
})
|
|
3112
|
+
if (!resolved.ok) {
|
|
3113
|
+
info(t('changes.undoNoContext'))
|
|
3114
|
+
return false
|
|
3115
|
+
}
|
|
3116
|
+
try {
|
|
3117
|
+
if (target.mode === 'patch') {
|
|
3118
|
+
// Fresh from the host: the panel's numbers may be a poll old, and the patch
|
|
3119
|
+
// must describe the file as it is NOW.
|
|
3120
|
+
const diff = await api.changes.diff(target.sessionId, target.path)
|
|
3121
|
+
const patch = diff !== null && diff.kind === 'text' ? (diff.patch ?? '') : ''
|
|
3122
|
+
if (patch.trim() === '') {
|
|
3123
|
+
info(t('changes.undoMissing'))
|
|
3124
|
+
return false
|
|
3125
|
+
}
|
|
3126
|
+
await applyHunk(target.alias, target.root, patch, 'revert')
|
|
3127
|
+
} else {
|
|
3128
|
+
const ok = await confirmDialog({
|
|
3129
|
+
title: t('changes.revertCreationTitle'),
|
|
3130
|
+
text: t('changes.revertCreationText').replace('{path}', target.display),
|
|
3131
|
+
danger: true,
|
|
3132
|
+
okText: t('changes.revertCreationOk'),
|
|
3133
|
+
})
|
|
3134
|
+
if (!ok) return false
|
|
3135
|
+
await api.fileOp.rm(target.alias, target.path, false)
|
|
3136
|
+
}
|
|
3137
|
+
} catch (error) {
|
|
3138
|
+
if (isConnectionFailure(error)) {
|
|
3139
|
+
info(t('connection.actionFailed'))
|
|
3140
|
+
return false
|
|
3141
|
+
}
|
|
3142
|
+
const detail = error instanceof Error ? error.message.trim() : String(error).trim()
|
|
3143
|
+
// A refused reverse patch means "the surroundings moved" (that is the conflict
|
|
3144
|
+
// guard); a failed delete has no such reading, so it gets its own wording
|
|
3145
|
+
// instead of pretending the patch context drifted.
|
|
3146
|
+
const label = target.mode === 'delete' ? t('changes.revertFailed') : t('changes.undoConflict')
|
|
3147
|
+
info(detail === '' ? label : `${label} · ${detail}`)
|
|
3148
|
+
return false
|
|
3149
|
+
}
|
|
3150
|
+
/**
|
|
3151
|
+
* The write SUCCEEDED, so nothing below may be reported as a failure: the
|
|
3152
|
+
* remote file has already changed. Refreshing the tab and the list is best
|
|
3153
|
+
* effort — a read that fails here leaves a stale panel, not a lost revert.
|
|
3154
|
+
*/
|
|
3155
|
+
try {
|
|
3156
|
+
// Re-read the tab: the write took a round trip, and it may have been closed
|
|
3157
|
+
// (or replaced) meanwhile.
|
|
3158
|
+
const live = state.tabs.find(item => item.id === (tab?.id ?? ''))
|
|
3159
|
+
if (target.mode === 'delete') {
|
|
3160
|
+
// The file is gone; a tab showing it would keep a buffer that cannot be
|
|
3161
|
+
// saved anywhere sensible.
|
|
3162
|
+
if (live !== undefined) closeTab(live.id)
|
|
3163
|
+
} else if (live !== undefined) {
|
|
3164
|
+
await reloadTab(live.id)
|
|
3165
|
+
await refreshChangeSet(live.id, resolved.origin)
|
|
3166
|
+
}
|
|
3167
|
+
} catch {
|
|
3168
|
+
// Deliberately swallowed: see above.
|
|
3169
|
+
}
|
|
3170
|
+
void api.changes.list(target.sessionId, true).catch(() => undefined)
|
|
3171
|
+
info(target.mode === 'delete' ? t('changes.deletedCreation') : t('changes.revertedFile'))
|
|
3172
|
+
return true
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
/**
|
|
3176
|
+
* Re-read one tab's change marks from the provenance recorded for it.
|
|
3177
|
+
*
|
|
3178
|
+
* Used after a successful save: typing invalidates the painted marks by design
|
|
3179
|
+
* (see `change-marks.ts`), and without this the file would keep its "positions
|
|
3180
|
+
* stale" badge until the user clicked the row again. A tab nobody attached marks
|
|
3181
|
+
* to has no provenance, so this is a no-op for every file opened from the tree.
|
|
3182
|
+
*/
|
|
3183
|
+
function refreshChangeSetForTab(tabId: string): void {
|
|
3184
|
+
const origin = changeOriginForTab(tabId)
|
|
3185
|
+
if (origin === undefined) return
|
|
3186
|
+
void refreshChangeSet(tabId, origin)
|
|
3187
|
+
}
|
|
3188
|
+
|
|
3005
3189
|
/** Mount-time hook: boot the store for a given ctx. */
|
|
3006
3190
|
export function useBootstrap(ctx: Context): void {
|
|
3007
3191
|
useEffect(() => {
|
|
@@ -75,6 +75,14 @@ export interface RemovedChip {
|
|
|
75
75
|
truncated: boolean
|
|
76
76
|
/** 这个 chip 落在哪一行(1-based)。**省略 = 所属 mark 的 `from` 行**。 */
|
|
77
77
|
line?: number
|
|
78
|
+
/**
|
|
79
|
+
* 这个 chip 代表的**被删行数**(省略或 1 = 单行/行内片段)。
|
|
80
|
+
*
|
|
81
|
+
* 一个整块删除(例如删掉 10 行)不能画成 10 个 chip 叠在同一列上 —— 那既读不出
|
|
82
|
+
* "删了 10 行",也读不出内容。此时 `count > 1`,`text` 改为携带**预览**(前若干
|
|
83
|
+
* 行的原文,供 tooltip),渲染成一个 `−N 行已删除` 的可读胶囊。
|
|
84
|
+
*/
|
|
85
|
+
count?: number
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
/**
|
|
@@ -118,6 +126,15 @@ export interface ChangeSet {
|
|
|
118
126
|
* 护栏,比在浏览器里重算一遍替换区间可靠。
|
|
119
127
|
*/
|
|
120
128
|
patches?: string[]
|
|
129
|
+
/**
|
|
130
|
+
* 整文件的补丁(一个文件头 + 全部 hunk),用于"撤销该文件的全部改动"。
|
|
131
|
+
*
|
|
132
|
+
* 一次远端写而不是逐 hunk 循环:后者会让后面每个 hunk 的行号整体错位,撤到一半
|
|
133
|
+
* 报冲突,文件就停在半截状态。补丁由 Host 生成(浏览器一侧没有基线内容,自己拼
|
|
134
|
+
* 出来的补丁只会把别人的改动一起盖掉)。省略 = 这个文件没有可整体撤销的补丁
|
|
135
|
+
* (新建 / 二进制 / 字节被上限扣下)。
|
|
136
|
+
*/
|
|
137
|
+
filePatch?: string
|
|
121
138
|
}
|
|
122
139
|
|
|
123
140
|
/** 换一份改动标记;`null` = 清空(有改动数据,但没有任何要画的东西)。 */
|
|
@@ -170,6 +187,9 @@ const WORD_ADD = Decoration.mark({ class: 'rvs-change-word-add' })
|
|
|
170
187
|
/** 删除 chip 的悬浮说明。与 gutter 的 `LABEL` 一样,是编辑器侧的固定文案。 */
|
|
171
188
|
const CHIP_TITLE = '已删除的内容'
|
|
172
189
|
|
|
190
|
+
/** 整块删除那种胶囊的悬浮说明(后面跟行数)。 */
|
|
191
|
+
const BLOCK_CHIP_TITLE = '已删除的整块内容'
|
|
192
|
+
|
|
173
193
|
/**
|
|
174
194
|
* 被删内容的零宽 widget。
|
|
175
195
|
*
|
|
@@ -180,25 +200,37 @@ const CHIP_TITLE = '已删除的内容'
|
|
|
180
200
|
class RemovedChipWidget extends WidgetType {
|
|
181
201
|
private readonly text: string
|
|
182
202
|
private readonly truncated: boolean
|
|
203
|
+
private readonly count: number
|
|
183
204
|
|
|
184
|
-
constructor(text: string, truncated: boolean) {
|
|
205
|
+
constructor(text: string, truncated: boolean, count = 0) {
|
|
185
206
|
super()
|
|
186
207
|
this.text = text
|
|
187
208
|
this.truncated = truncated
|
|
209
|
+
this.count = count
|
|
188
210
|
}
|
|
189
211
|
|
|
190
212
|
eq(other: WidgetType): boolean {
|
|
191
213
|
return other instanceof RemovedChipWidget
|
|
192
214
|
&& other.text === this.text
|
|
193
215
|
&& other.truncated === this.truncated
|
|
216
|
+
&& other.count === this.count
|
|
194
217
|
}
|
|
195
218
|
|
|
196
219
|
toDOM(): HTMLElement {
|
|
197
220
|
const chip = document.createElement('span')
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
221
|
+
/**
|
|
222
|
+
* 整块删除(`count > 1`)读成一枚胶囊,不是一行删除线文字。
|
|
223
|
+
*
|
|
224
|
+
* 行内删短(`const a = 1 + 2` → `const a = 1`)仍然是划掉的原文 —— 那里被删的
|
|
225
|
+
* 是一个片段,位置和内容都能直接读。多行整块没有这个性质:原文是一个段落,
|
|
226
|
+
* 划线堆在行首只会糊成一片,所以这里只报**行数**,原文进 tooltip(已在数据层
|
|
227
|
+
* 限过长度,见 `model.ts` 的 `deletedRunChip`)。
|
|
228
|
+
*/
|
|
229
|
+
const block = this.count > 1
|
|
230
|
+
chip.className = block ? 'rvs-change-word-del rvs-change-block-del' : 'rvs-change-word-del'
|
|
231
|
+
chip.textContent = block ? `−${this.count} 行已删除` : (this.truncated ? `${this.text}…` : this.text)
|
|
232
|
+
chip.title = block ? `${BLOCK_CHIP_TITLE}(${this.count} 行)\n${this.text}` : CHIP_TITLE
|
|
233
|
+
chip.setAttribute('aria-label', chip.title)
|
|
202
234
|
return chip
|
|
203
235
|
}
|
|
204
236
|
}
|
|
@@ -209,7 +241,7 @@ class RemovedChipWidget extends WidgetType {
|
|
|
209
241
|
* `-2e8`、chip `-1e8`、字符区间 `-1`)。
|
|
210
242
|
*/
|
|
211
243
|
function chipDecoration(chip: RemovedChip): Decoration {
|
|
212
|
-
return Decoration.widget({ widget: new RemovedChipWidget(chip.text, chip.truncated), side: -1 })
|
|
244
|
+
return Decoration.widget({ widget: new RemovedChipWidget(chip.text, chip.truncated, chip.count ?? 0), side: -1 })
|
|
213
245
|
}
|
|
214
246
|
|
|
215
247
|
/** 一行的行内片段:新增字符区间 + 删除 chip。 */
|
|
@@ -251,6 +283,7 @@ function inlineIndexOf(set: ChangeSet | null, doc: Text): Map<number, LineInline
|
|
|
251
283
|
at: Math.max(0, Math.round(chip.at)),
|
|
252
284
|
text: chip.text,
|
|
253
285
|
truncated: chip.truncated === true,
|
|
286
|
+
...(chip.count === undefined ? {} : { count: chip.count }),
|
|
254
287
|
})
|
|
255
288
|
}
|
|
256
289
|
}
|
package/src/client/vsc/kit.tsx
CHANGED
|
@@ -783,6 +783,15 @@ export function ContextMenu(props: {
|
|
|
783
783
|
y: number
|
|
784
784
|
entries: MenuEntry[]
|
|
785
785
|
onClose: () => void
|
|
786
|
+
/**
|
|
787
|
+
* Extra class on the menu box, for a surface that lives OUTSIDE `.rvs-root`.
|
|
788
|
+
*
|
|
789
|
+
* The menu is portalled to `document.body`, so the `--rvs-*` variables defined
|
|
790
|
+
* on the root never reach it: an outside surface (the change panel above the
|
|
791
|
+
* composer) supplies its own palette through this hook instead of forking the
|
|
792
|
+
* component.
|
|
793
|
+
*/
|
|
794
|
+
className?: string
|
|
786
795
|
}): ReactNode {
|
|
787
796
|
const boxRef = useRef<HTMLDivElement>(null)
|
|
788
797
|
const [pos, setPos] = useState({ left: props.x, top: props.y })
|
|
@@ -896,7 +905,13 @@ export function ContextMenu(props: {
|
|
|
896
905
|
if (typeof document === 'undefined') return null
|
|
897
906
|
return createPortal(
|
|
898
907
|
<div className="rvs-portal">
|
|
899
|
-
<div
|
|
908
|
+
<div
|
|
909
|
+
ref={boxRef}
|
|
910
|
+
className={props.className === undefined ? 'rvs-menu' : `rvs-menu ${props.className}`}
|
|
911
|
+
role="menu"
|
|
912
|
+
style={{ left: pos.left, top: pos.top }}
|
|
913
|
+
onKeyDown={onMenuKeyDown}
|
|
914
|
+
>
|
|
900
915
|
{props.entries.map((entry, index) => (
|
|
901
916
|
<div key={`${entry.label}-${index}`}>
|
|
902
917
|
{entry.separated === true && index > 0 && <div className="rvs-menu-sep" />}
|
package/src/client/vsc/vsc.css
CHANGED
|
@@ -1836,6 +1836,29 @@ body:not([data-ds-dark-theme]) .rvs-edge .rvs-change-word-del {
|
|
|
1836
1836
|
background-color: rgba(207, 34, 46, .14);
|
|
1837
1837
|
}
|
|
1838
1838
|
|
|
1839
|
+
/**
|
|
1840
|
+
* 整块删除:一枚带行数的胶囊,不是一行划掉的文字。
|
|
1841
|
+
*
|
|
1842
|
+
* 多行删除的原文是一个段落,划线堆在锚点行首只会糊成一片(数据层因此把 `count > 1`
|
|
1843
|
+
* 的 chip 压成一枚,见 `change-marks.ts` 的 `RemovedChipWidget`)。这里只做外形:
|
|
1844
|
+
* 去掉继承来的删除线(胶囊不是"被划掉的字符串"),字号与计数对齐,别把行高撑开。
|
|
1845
|
+
*/
|
|
1846
|
+
.rvs-edge .rvs-change-block-del {
|
|
1847
|
+
padding: 0 4px;
|
|
1848
|
+
margin: 0 1px;
|
|
1849
|
+
border-radius: 3px;
|
|
1850
|
+
background-color: rgba(248, 81, 73, .18);
|
|
1851
|
+
font-size: 11px;
|
|
1852
|
+
font-variant-numeric: tabular-nums;
|
|
1853
|
+
text-decoration: none;
|
|
1854
|
+
opacity: 1;
|
|
1855
|
+
white-space: nowrap;
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
body:not([data-ds-dark-theme]) .rvs-edge .rvs-change-block-del {
|
|
1859
|
+
background-color: rgba(207, 34, 46, .14);
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1839
1862
|
/**
|
|
1840
1863
|
* 改动跳转按钮:浮在编辑器右上角。
|
|
1841
1864
|
*
|
package/src/deploy.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { createHash } from 'node:crypto'
|
|
|
12
12
|
import { copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, rmSync } from 'node:fs'
|
|
13
13
|
import { dirname, join, posix, resolve, sep } from 'node:path'
|
|
14
14
|
import { fileURLToPath } from 'node:url'
|
|
15
|
+
import { SSH_PROTOCOL_VERSION } from '@deepseek-ai/dsh-ssh/protocol'
|
|
15
16
|
import type { RemotePool } from './pool.ts'
|
|
16
17
|
import { RemoteFiles } from './sftp.ts'
|
|
17
18
|
import type { RemoteStore } from './store.ts'
|
|
@@ -123,8 +124,16 @@ const HELPER_VERSION_RE = /^[0-9A-Za-z][0-9A-Za-z._-]{0,63}$/
|
|
|
123
124
|
/** Platforms `mapPlatform()` can produce; a cache entry must name one of them. */
|
|
124
125
|
const HELPER_PLATFORMS = new Set(['linux-x64', 'linux-arm64', 'macos-x64', 'macos-arm64'])
|
|
125
126
|
|
|
126
|
-
/**
|
|
127
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Wire protocol this plugin's `dsh-ssh` generation speaks (see MAINTENANCE §2.7).
|
|
129
|
+
*
|
|
130
|
+
* Derived from the installed package instead of hardcoded: helper and client
|
|
131
|
+
* handshake on a strict literal, so a constant that drifts from the package
|
|
132
|
+
* silently selects a helper the handshake will reject. Before 0.23.0 this was a
|
|
133
|
+
* hand-maintained `2`; the protocol-3 move (MAINTENANCE §2.51) is why it can no
|
|
134
|
+
* longer be a second source of truth.
|
|
135
|
+
*/
|
|
136
|
+
export const EXPECTED_HELPER_PROTOCOL = SSH_PROTOCOL_VERSION
|
|
128
137
|
|
|
129
138
|
/** Resolve one cached tarball, or `undefined` when the name escapes the cache dir. */
|
|
130
139
|
function safeHelperTarball(dir: string, tarball: unknown): string | undefined {
|
|
@@ -247,6 +256,33 @@ export function pickCached(platform: string, version?: string, expectedProtocol:
|
|
|
247
256
|
return matches[0]
|
|
248
257
|
}
|
|
249
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Wire protocol of the helper build a deploy record points at, when this machine
|
|
261
|
+
* still has that build cached.
|
|
262
|
+
*
|
|
263
|
+
* Upgrade-day support for `createRpc`: it re-runs the deploy pipeline only when
|
|
264
|
+
* the record carries NO helper, so a host deployed by an older plugin keeps
|
|
265
|
+
* dialing a binary from another protocol generation — both sides pin a literal,
|
|
266
|
+
* so the handshake can only fail and nothing self-heals. The local cache is the
|
|
267
|
+
* one place that still knows that build's protocol, so the record is classified
|
|
268
|
+
* here:
|
|
269
|
+
* - unknown build (not cached here, e.g. deployed from another machine) →
|
|
270
|
+
* `undefined`: keep the record and let the handshake report the real error;
|
|
271
|
+
* - cached build of THIS protocol → returns the expected value, so a deliberate
|
|
272
|
+
* rollback pin (an older build of the same generation) stays pinned;
|
|
273
|
+
* - cached build of ANOTHER protocol → returns the foreign value; the caller
|
|
274
|
+
* re-deploys instead of dialing a doomed handshake.
|
|
275
|
+
*/
|
|
276
|
+
export function protocolOfStoredHelper(
|
|
277
|
+
binarySha256: string,
|
|
278
|
+
platform: string | undefined,
|
|
279
|
+
entries: HelperCacheEntry[] = listCachedHelpers(),
|
|
280
|
+
): number | undefined {
|
|
281
|
+
return entries
|
|
282
|
+
.find(entry => entry.binarySha256 === binarySha256 && (platform === undefined || entry.platform === platform))
|
|
283
|
+
?.protocol
|
|
284
|
+
}
|
|
285
|
+
|
|
250
286
|
/** Honest availability of the helper channels. */
|
|
251
287
|
export function helperAvailability(): HelperAvailability[] {
|
|
252
288
|
const cached = listCachedHelpers()
|
package/src/http.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Small JSON body/response helpers for the /api/dsh-remote route family.
|
|
3
3
|
*/
|
|
4
4
|
import type { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from 'node:http'
|
|
5
|
+
import { drainHostNotices } from './notices.ts'
|
|
5
6
|
import { DeadlineError } from './timeouts.ts'
|
|
6
7
|
|
|
7
8
|
const JSON_HEADERS = {
|
|
@@ -102,8 +103,18 @@ export function writeJson(
|
|
|
102
103
|
body: unknown,
|
|
103
104
|
headers: OutgoingHttpHeaders = {},
|
|
104
105
|
): void {
|
|
106
|
+
// Piggyback Host notices (an automatic helper push happened during this
|
|
107
|
+
// request) on any plain-object body: the browser's API wrapper renders them
|
|
108
|
+
// after parsing, so the user learns about the push without opening Settings.
|
|
109
|
+
// Arrays and scalars cannot carry extra keys — their notices stay queued for
|
|
110
|
+
// the next object response instead of being silently dropped.
|
|
111
|
+
const attachable = typeof body === 'object' && body !== null && !Array.isArray(body)
|
|
112
|
+
const notices = attachable ? drainHostNotices() : []
|
|
113
|
+
const payload = notices.length > 0
|
|
114
|
+
? { ...body as Record<string, unknown>, notices }
|
|
115
|
+
: body
|
|
105
116
|
res.writeHead(status, { ...JSON_HEADERS, ...headers })
|
|
106
|
-
res.end(JSON.stringify(
|
|
117
|
+
res.end(JSON.stringify(payload))
|
|
107
118
|
}
|
|
108
119
|
|
|
109
120
|
/**
|
package/src/notices.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot notices the Host hands to the browser on the next JSON response.
|
|
3
|
+
*
|
|
4
|
+
* Why a queue instead of a push channel: the Host half is request/response, and
|
|
5
|
+
* an event that matters (an automatic helper push) is produced *inside* a
|
|
6
|
+
* request the browser already made — the remote operation that needed a dial.
|
|
7
|
+
* Attaching the notice to that response reaches the surface that caused it with
|
|
8
|
+
* no extra connection, and a queue means a push during a streaming response or
|
|
9
|
+
* a failed request still arrives on the next successful one.
|
|
10
|
+
*/
|
|
11
|
+
export interface HostNotice {
|
|
12
|
+
/** What happened. Only kinds the client knows how to render belong here. */
|
|
13
|
+
kind: 'helper-pushed'
|
|
14
|
+
/** Host alias the helper was pushed to. */
|
|
15
|
+
alias: string
|
|
16
|
+
/** Helper version that was installed. */
|
|
17
|
+
version: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Bounded so an unreachable client cannot grow Host memory without limit. */
|
|
21
|
+
const MAX_PENDING = 8
|
|
22
|
+
|
|
23
|
+
let pending: HostNotice[] = []
|
|
24
|
+
|
|
25
|
+
/** Queue one notice for the next JSON response. */
|
|
26
|
+
export function pushHostNotice(notice: HostNotice): void {
|
|
27
|
+
if (pending.length >= MAX_PENDING) return
|
|
28
|
+
pending = [...pending, notice]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Take everything queued; the caller attaches it and the queue starts over. */
|
|
32
|
+
export function drainHostNotices(): HostNotice[] {
|
|
33
|
+
if (pending.length === 0) return []
|
|
34
|
+
const drained = pending
|
|
35
|
+
pending = []
|
|
36
|
+
return drained
|
|
37
|
+
}
|
package/src/p2/router-fs.ts
CHANGED
|
@@ -324,15 +324,14 @@ export default class TransparentFileSystem extends FileSystem {
|
|
|
324
324
|
|
|
325
325
|
/**
|
|
326
326
|
* alpha.3 added patch/delete/move to the FileSystem contract for the
|
|
327
|
-
* apply_patch tool.
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
* pin `applyPatch: false`), so this only matters when it is enabled.
|
|
327
|
+
* apply_patch tool. As of 0.23.0 every provider this plugin mounts implements
|
|
328
|
+
* all three — fs-ssh 0.2.2 talks the protocol-3 helper, which serves
|
|
329
|
+
* `fs.patch`/`fs.delete`/`fs.move` — so the guards below are defensive: they
|
|
330
|
+
* turn a thinner provider into a typed FsError instead of a TypeError.
|
|
332
331
|
*/
|
|
333
332
|
private unsupportedRemote(what: string): FsError {
|
|
334
333
|
return new FsError(
|
|
335
|
-
`${what} is not supported
|
|
334
|
+
`${what} is not supported by the remote fs provider mounted for this world; run it in a local workspace`,
|
|
336
335
|
'FS_IO_ERROR',
|
|
337
336
|
)
|
|
338
337
|
}
|
package/src/p2/worlds.ts
CHANGED
|
@@ -18,7 +18,8 @@ import type {} from '@deepseek-ai/dsh-working-directory'
|
|
|
18
18
|
import type {} from '@deepseek-ai/dsh-workspace'
|
|
19
19
|
import type { RemoteStore } from '../store.ts'
|
|
20
20
|
import type { RemotePool } from '../pool.ts'
|
|
21
|
-
import { deployFailure, probe, pushPipeline } from '../deploy.ts'
|
|
21
|
+
import { EXPECTED_HELPER_PROTOCOL, deployFailure, probe, protocolOfStoredHelper, pushPipeline, type PushReport } from '../deploy.ts'
|
|
22
|
+
import { pushHostNotice } from '../notices.ts'
|
|
22
23
|
import { aliasRoot } from '../paths.ts'
|
|
23
24
|
import type { RemoteHostEntry, RemoteWorkspaceBinding } from '../protocol.ts'
|
|
24
25
|
import { RpcConnection } from './helper-rpc.ts'
|
|
@@ -716,7 +717,7 @@ export class RemoteWorlds {
|
|
|
716
717
|
})
|
|
717
718
|
}
|
|
718
719
|
|
|
719
|
-
private async createRpc(alias: string): Promise<RpcConnection> {
|
|
720
|
+
private async createRpc(alias: string, allowRedeploy = true): Promise<RpcConnection> {
|
|
720
721
|
const entry: RemoteHostEntry = this.deps.store.require(alias)
|
|
721
722
|
let deploy = entry.deploy
|
|
722
723
|
if (deploy?.artifact === undefined || !deploy.artifact.startsWith('dsh-ssh-helper/') || deploy.helper === undefined) {
|
|
@@ -738,6 +739,7 @@ export class RemoteWorlds {
|
|
|
738
739
|
if (report.action === 'failed') {
|
|
739
740
|
throw new Error(`helper auto-deploy failed: ${report.detail}`)
|
|
740
741
|
}
|
|
742
|
+
if (report.action === 'pushed') this.notifyHelperPush(alias, report)
|
|
741
743
|
deploy = this.deps.store.require(alias).deploy
|
|
742
744
|
}
|
|
743
745
|
const helper = deploy?.helper
|
|
@@ -754,6 +756,33 @@ export class RemoteWorlds {
|
|
|
754
756
|
platform = platform && platform !== '' ? platform : probed.platform === 'unknown' ? undefined : probed.platform
|
|
755
757
|
if (platform === undefined) throw new Error(`cannot locate helper platform for ${alias}`)
|
|
756
758
|
}
|
|
759
|
+
// Upgrade-day self-heal: a record written by an older plugin names a helper
|
|
760
|
+
// of another wire protocol. Both sides pin the protocol as a literal, so
|
|
761
|
+
// dialing it can only fail — and the first-contact predicate above never
|
|
762
|
+
// re-runs the pipeline for a record that already has a helper. The local
|
|
763
|
+
// cache still knows that build's protocol, so a foreign generation is
|
|
764
|
+
// treated as stale and the cached build this plugin speaks is pushed. A pin
|
|
765
|
+
// to an older build of the SAME protocol is left alone (rollback stays
|
|
766
|
+
// intact); an uncached build is left for the handshake to explain.
|
|
767
|
+
const storedProtocol = protocolOfStoredHelper(helper.sha256, platform)
|
|
768
|
+
if (allowRedeploy && storedProtocol !== undefined && storedProtocol !== EXPECTED_HELPER_PROTOCOL) {
|
|
769
|
+
try {
|
|
770
|
+
this.ctx.logger.info(
|
|
771
|
+
`[remote-vs] helper on ${alias} speaks wire protocol ${storedProtocol}, this build speaks `
|
|
772
|
+
+ `${EXPECTED_HELPER_PROTOCOL}; re-deploying before dialing`,
|
|
773
|
+
)
|
|
774
|
+
} catch {
|
|
775
|
+
// Logging must never prevent the heal.
|
|
776
|
+
}
|
|
777
|
+
const report = await pushPipeline(this.deps.pool, this.deps.store, alias)
|
|
778
|
+
if (report.action === 'failed') {
|
|
779
|
+
throw new Error(`helper re-deploy after a wire-protocol change failed: ${report.detail}`)
|
|
780
|
+
}
|
|
781
|
+
if (report.action === 'pushed') this.notifyHelperPush(alias, report)
|
|
782
|
+
// Re-read the refreshed record; a second mismatch is handed to the
|
|
783
|
+
// handshake so its error explains what the pipeline could not fix.
|
|
784
|
+
return this.createRpc(alias, false)
|
|
785
|
+
}
|
|
757
786
|
const helperPath = `${home}/.dsh-helpers/dsh-ssh-helper-${helper.version}-${platform}/dsh-ssh-helper`
|
|
758
787
|
const conn = new RpcConnection({
|
|
759
788
|
entry: this.deps.store.require(alias),
|
|
@@ -770,4 +799,19 @@ export class RemoteWorlds {
|
|
|
770
799
|
}
|
|
771
800
|
return conn
|
|
772
801
|
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Queue a browser notice for an automatic helper push.
|
|
805
|
+
*
|
|
806
|
+
* Only a REAL push is announced: `skipped-same` means the host already runs
|
|
807
|
+
* this build (the self-heal case where an earlier push updated the remote),
|
|
808
|
+
* and announcing an upload that did not happen would be a lie. The notice
|
|
809
|
+
* rides the next JSON response (`src/notices.ts`), which is exactly the
|
|
810
|
+
* request whose dial needed the helper — the surface the user is looking at.
|
|
811
|
+
*/
|
|
812
|
+
private notifyHelperPush(alias: string, report: PushReport): void {
|
|
813
|
+
const version = report.installed?.helper?.version ?? this.deps.store.require(alias).deploy?.helper?.version
|
|
814
|
+
if (version === undefined || version === '') return
|
|
815
|
+
pushHostNotice({ kind: 'helper-pushed', alias, version })
|
|
816
|
+
}
|
|
773
817
|
}
|