dsh-remote 0.8.79 → 0.8.80
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/lib/tui/format.js +48 -0
- package/lib/tui/i18n.js +6 -0
- package/lib/tui/index.js +218 -9
- package/lib/tui/provider.js +36 -19
- package/package.json +1 -1
package/lib/tui/format.js
CHANGED
|
@@ -330,3 +330,51 @@ export function formatBytes(value) {
|
|
|
330
330
|
}
|
|
331
331
|
return `${size >= 10 ? size.toFixed(0) : size.toFixed(1)} ${units[index]}`
|
|
332
332
|
}
|
|
333
|
+
|
|
334
|
+
/** 东亚宽字符 / emoji 占两个终端单元格,其余一个(粗略但够用的 wcwidth 子集)。 */
|
|
335
|
+
function charCells(codePoint) {
|
|
336
|
+
if (codePoint === 0) return 0
|
|
337
|
+
if (
|
|
338
|
+
(codePoint >= 0x1100 && codePoint <= 0x115f)
|
|
339
|
+
|| codePoint === 0x2329 || codePoint === 0x232a
|
|
340
|
+
|| (codePoint >= 0x2e80 && codePoint <= 0xa4cf && codePoint !== 0x303f)
|
|
341
|
+
|| (codePoint >= 0xac00 && codePoint <= 0xd7a3)
|
|
342
|
+
|| (codePoint >= 0xf900 && codePoint <= 0xfaff)
|
|
343
|
+
|| (codePoint >= 0xfe10 && codePoint <= 0xfe19)
|
|
344
|
+
|| (codePoint >= 0xfe30 && codePoint <= 0xfe6f)
|
|
345
|
+
|| (codePoint >= 0xff00 && codePoint <= 0xff60)
|
|
346
|
+
|| (codePoint >= 0xffe0 && codePoint <= 0xffe6)
|
|
347
|
+
|| (codePoint >= 0x231a && codePoint <= 0x231b)
|
|
348
|
+
|| (codePoint >= 0x23e9 && codePoint <= 0x23f3)
|
|
349
|
+
|| (codePoint >= 0x25fd && codePoint <= 0x25fe)
|
|
350
|
+
|| (codePoint >= 0x2600 && codePoint <= 0x27bf)
|
|
351
|
+
|| (codePoint >= 0x2b00 && codePoint <= 0x2bff)
|
|
352
|
+
|| (codePoint >= 0x1f000 && codePoint <= 0x1f2ff)
|
|
353
|
+
|| (codePoint >= 0x1f300 && codePoint <= 0x1faff)
|
|
354
|
+
|| (codePoint >= 0x20000 && codePoint <= 0x3fffd)
|
|
355
|
+
) return 2
|
|
356
|
+
return 1
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** 字符串在终端里占用的单元格数(CJK / emoji 记 2)。 */
|
|
360
|
+
export function displayWidth(text) {
|
|
361
|
+
let cells = 0
|
|
362
|
+
for (const char of String(text == null ? '' : text)) cells += charCells(char.codePointAt(0))
|
|
363
|
+
return cells
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** 按终端单元格截断,超宽时以 `…` 结尾(不再额外超宽)。 */
|
|
367
|
+
export function clipCells(text, maxCells) {
|
|
368
|
+
const value = String(text == null ? '' : text)
|
|
369
|
+
const limit = Math.max(1, Math.floor(Number(maxCells) || 0))
|
|
370
|
+
if (displayWidth(value) <= limit) return value
|
|
371
|
+
let out = ''
|
|
372
|
+
let used = 0
|
|
373
|
+
for (const char of value) {
|
|
374
|
+
const cells = charCells(char.codePointAt(0))
|
|
375
|
+
if (used + cells > limit - 1) break
|
|
376
|
+
out += char
|
|
377
|
+
used += cells
|
|
378
|
+
}
|
|
379
|
+
return `${out}…`
|
|
380
|
+
}
|
package/lib/tui/i18n.js
CHANGED
|
@@ -18,6 +18,9 @@ const DICT = {
|
|
|
18
18
|
'status.none': '未连接远程机',
|
|
19
19
|
'status.connected': '已连接 {target}',
|
|
20
20
|
'status.disconnected': '未连接 · {target}',
|
|
21
|
+
'status.detailMachine': '远程机 {name}',
|
|
22
|
+
'status.detailTarget': '{user}@{host}:{port}',
|
|
23
|
+
'status.detailRemote': '远端 {path}',
|
|
21
24
|
|
|
22
25
|
// ── 机器列表 ──────────────────────────────────────────────────────────
|
|
23
26
|
'list.hints': '↑↓ 选择 · →/Enter 动作菜单 · a 新增 · c 连接 · t 探测 · b 浏览 · e 编辑 · d 删除 · ←/Esc 关闭',
|
|
@@ -168,6 +171,9 @@ const DICT = {
|
|
|
168
171
|
'status.none': 'no remote machine',
|
|
169
172
|
'status.connected': 'connected · {target}',
|
|
170
173
|
'status.disconnected': 'disconnected · {target}',
|
|
174
|
+
'status.detailMachine': 'machine {name}',
|
|
175
|
+
'status.detailTarget': '{user}@{host}:{port}',
|
|
176
|
+
'status.detailRemote': 'remote {path}',
|
|
171
177
|
|
|
172
178
|
'list.hints': '↑↓ select · →/Enter actions · a add · c connect · t probe · b browse · e edit · d delete · ←/Esc close',
|
|
173
179
|
'list.empty': 'no saved machines yet — press a to add one',
|
package/lib/tui/index.js
CHANGED
|
@@ -9,8 +9,12 @@
|
|
|
9
9
|
// · `installTui` 同步返回、不 await、绝不抛错:内部 try/catch + logger.warn。
|
|
10
10
|
// · 每个注册返回的 disposer 都用 `ctx.effect(() => () => dispose())` 绑定生命周期。
|
|
11
11
|
|
|
12
|
+
import os from 'node:os'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
import { resolveMirror } from '../binding.js'
|
|
12
15
|
import { createI18n } from './i18n.js'
|
|
13
|
-
import {
|
|
16
|
+
import { clipCells } from './format.js'
|
|
17
|
+
import { createWorkspaceProvider, matchMachineForMirror } from './provider.js'
|
|
14
18
|
import { createSceneComponent } from './scene.js'
|
|
15
19
|
import { runDialogFlow } from './flow.js'
|
|
16
20
|
|
|
@@ -139,9 +143,27 @@ export function installTui(ctx, api, config) {
|
|
|
139
143
|
let statusService = null
|
|
140
144
|
let statusFieldDispose = null
|
|
141
145
|
let statusRefreshToken = 0
|
|
146
|
+
/** 最近进入 store 的会话 / 最近收到用户输入的会话(见 activeSessionCwd)。 */
|
|
147
|
+
let activeSessionId = null
|
|
148
|
+
let lastUserSessionId = null
|
|
149
|
+
/** 宿主每次会话切换都会用新 cwd 调 provider.describe():那是“当前会话”的
|
|
150
|
+
* 可靠提示(sessions 事件覆盖不到 live 会话切换)。见 noteHostSessionCwd。 */
|
|
151
|
+
let hostSessionCwd = ''
|
|
152
|
+
/** 插件卸载后,仍在 await 的刷新不得再写底栏。 */
|
|
153
|
+
let disposed = false
|
|
154
|
+
/** 上一次写入的 text/detail:相同值不重复 setField(宿主会无条件 emit 并记账)。 */
|
|
155
|
+
let lastStatusWrite = null
|
|
156
|
+
bindEffect(ctx, () => { disposed = true })
|
|
142
157
|
|
|
143
158
|
const ensureProvider = () => {
|
|
144
|
-
if (!provider)
|
|
159
|
+
if (!provider) {
|
|
160
|
+
provider = createWorkspaceProvider({
|
|
161
|
+
api,
|
|
162
|
+
config: config || {},
|
|
163
|
+
logger: getService(ctx, 'logger'),
|
|
164
|
+
onDescribe: noteHostSessionCwd,
|
|
165
|
+
})
|
|
166
|
+
}
|
|
145
167
|
return provider
|
|
146
168
|
}
|
|
147
169
|
|
|
@@ -195,12 +217,27 @@ export function installTui(ctx, api, config) {
|
|
|
195
217
|
if (commandsSeen) registerCommand(commandsSeen)
|
|
196
218
|
}
|
|
197
219
|
|
|
198
|
-
/** 状态行字段:只在服务形状符合契约时写入,否则整段跳过(不猜 API)。
|
|
199
|
-
|
|
220
|
+
/** 状态行字段:只在服务形状符合契约时写入,否则整段跳过(不猜 API)。
|
|
221
|
+
* `detail` 是鼠标悬停时补在空闲提示行上的说明(宿主按 `inactiveShimmer`
|
|
222
|
+
* 渲染,单行、上限 160 cells,与其它底栏字段的 hover 效果一致)。
|
|
223
|
+
* 宿主对 detail 只按 160 cells 截断、不做“适配当前宽度”的 truncate,超宽会
|
|
224
|
+
* wrap 进看不见的第二行;所以按终端宽度自己裁:状态行内宽是 columns-2
|
|
225
|
+
* (宿主 paddingX=1),再给右侧 MiniWake/activity 预留 16 格,下限 8。 */
|
|
226
|
+
const applyStatusField = (text, detail) => {
|
|
227
|
+
if (disposed) return
|
|
200
228
|
if (!statusService || typeof statusService.setField !== 'function') return
|
|
201
229
|
try {
|
|
230
|
+
const columns = Number(process.stdout && process.stdout.columns) || 80
|
|
231
|
+
const clipped = detail ? clipCells(detail, Math.max(8, columns - 18)) : ''
|
|
232
|
+
// 相同值不重复写:宿主 store 会对同 text 的 setField 也 emit,并往
|
|
233
|
+
// append-only 的 effect-ledger 记一笔。从未写过时也不要发“空清除”。
|
|
234
|
+
const previous = lastStatusWrite
|
|
235
|
+
if (previous && previous.text === text && previous.detail === clipped) return
|
|
236
|
+
if (!previous && text === undefined && !clipped) return
|
|
237
|
+
lastStatusWrite = { text, detail: clipped }
|
|
238
|
+
const options = clipped ? { ...STATUS_OPTIONS, detail: clipped } : STATUS_OPTIONS
|
|
202
239
|
// 第 4 个参数是插件自己的 ctx(只用于 effect ledger 归属,可省略)。
|
|
203
|
-
const next = statusService.setField(STATUS_KEY, text,
|
|
240
|
+
const next = statusService.setField(STATUS_KEY, text, options, ctx)
|
|
204
241
|
if (statusFieldDispose) {
|
|
205
242
|
const previous = statusFieldDispose
|
|
206
243
|
statusFieldDispose = null
|
|
@@ -212,7 +249,108 @@ export function installTui(ctx, api, config) {
|
|
|
212
249
|
}
|
|
213
250
|
}
|
|
214
251
|
|
|
215
|
-
/**
|
|
252
|
+
/** 子代理会话也会进 store、也会发 `user/message`,但它不是用户在看的会话。 */
|
|
253
|
+
const isSubagentSession = (session) => {
|
|
254
|
+
const origin = session && session.header && session.header.origin
|
|
255
|
+
return origin === 'subagent'
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** 本进程的 live 会话(不含子代理)。`null` = 宿主没有 sessions 服务(旧组合),
|
|
259
|
+
* `[]` = 服务在但读不到/读抛错 → 调用方按“没有远程会话”处理。 */
|
|
260
|
+
const liveSessions = () => {
|
|
261
|
+
const sessions = getService(ctx, 'sessions')
|
|
262
|
+
if (!sessions || typeof sessions.list !== 'function') return null
|
|
263
|
+
try {
|
|
264
|
+
const list = sessions.list()
|
|
265
|
+
if (!Array.isArray(list)) return []
|
|
266
|
+
return list.filter((one) => one && one.header && one.header.cwd && !isSubagentSession(one))
|
|
267
|
+
} catch (error) {
|
|
268
|
+
warn(ctx, '会话列表读取失败', error)
|
|
269
|
+
return []
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** 当前 TUI 会话的 cwd。
|
|
274
|
+
*
|
|
275
|
+
* TUI 进程里可以同时有多个 live session(挂载中的会话 + parked 后台会话),
|
|
276
|
+
* 而“切到已挂载会话”不会发 session/* 事件。插件拿不到宿主 channel,按可靠性
|
|
277
|
+
* 依次采信:① 宿主切换会话时传入 provider.describe() 的 cwd(只在这种情况下
|
|
278
|
+
* 才算数,并交叉校验它确实属于某个 live 会话);② 最近进入/用户说过话的
|
|
279
|
+
* 会话;③ store 里最后进入的会话。 */
|
|
280
|
+
const activeSessionCwd = () => {
|
|
281
|
+
const list = liveSessions()
|
|
282
|
+
if (list === null) return { supported: false, cwd: '' }
|
|
283
|
+
const cwds = new Set(list.map((one) => String(one.header.cwd)))
|
|
284
|
+
if (hostSessionCwd && cwds.has(hostSessionCwd)) return { supported: true, cwd: hostSessionCwd }
|
|
285
|
+
const cwdOf = (id) => {
|
|
286
|
+
if (!id) return ''
|
|
287
|
+
const one = list.find((candidate) => String(candidate.id) === String(id))
|
|
288
|
+
return one ? String(one.header.cwd) : ''
|
|
289
|
+
}
|
|
290
|
+
let cwd = cwdOf(activeSessionId) || cwdOf(lastUserSessionId)
|
|
291
|
+
if (!cwd && list.length > 0) cwd = String(list[list.length - 1].header.cwd)
|
|
292
|
+
return { supported: true, cwd }
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** 宿主在会话切换/工作区描述时把当前 cwd 交给 provider.describe();记下来,
|
|
296
|
+
* 由 activeSessionCwd 交叉校验后使用。 */
|
|
297
|
+
const noteHostSessionCwd = (cwd) => {
|
|
298
|
+
const value = String(cwd || '')
|
|
299
|
+
if (!value || value === hostSessionCwd) return
|
|
300
|
+
hostSessionCwd = value
|
|
301
|
+
void refreshStatusField()
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** `$DSH_HOME`:宿主的 `dshHomePath` 服务是**函数**(`(...segments) => path`),
|
|
305
|
+
* 老版本/测试里也可能是字符串或 `{path}`;都没有时退回环境变量/`~/.dsh`。 */
|
|
306
|
+
const dshHomePath = () => {
|
|
307
|
+
const service = getService(ctx, 'dshHomePath')
|
|
308
|
+
if (typeof service === 'function') {
|
|
309
|
+
try {
|
|
310
|
+
const home = service()
|
|
311
|
+
if (typeof home === 'string' && home) return home
|
|
312
|
+
} catch { /* fall through to the string forms */ }
|
|
313
|
+
}
|
|
314
|
+
if (typeof service === 'string' && service) return service
|
|
315
|
+
if (service && typeof service.path === 'string' && service.path) return service.path
|
|
316
|
+
return process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** 会话在远程镜像里 → `{label, detail}`;本地会话 / 无会话 → ''。
|
|
320
|
+
* `detail` 供底栏 hover 使用:完整机器名 + `user@host:port` + 远端路径。
|
|
321
|
+
* `null` 表示宿主没有 sessions 服务(旧组合),调用方退回旧行为。 */
|
|
322
|
+
const remoteSessionLabel = (machines) => {
|
|
323
|
+
const { supported, cwd } = activeSessionCwd()
|
|
324
|
+
if (!supported) return null
|
|
325
|
+
if (!cwd) return ''
|
|
326
|
+
let resolved
|
|
327
|
+
try {
|
|
328
|
+
resolved = resolveMirror(cwd, path.join(dshHomePath(), 'remote-workspaces'))
|
|
329
|
+
} catch {
|
|
330
|
+
return ''
|
|
331
|
+
}
|
|
332
|
+
const machine = resolved && resolved.machine
|
|
333
|
+
if (!machine || !resolved.remotePath) return ''
|
|
334
|
+
// 与 provider 的机器匹配共用一套规则:ssh-config 别名机按 alias 命中,
|
|
335
|
+
// 字面机按 host/port/username 命中。
|
|
336
|
+
const match = matchMachineForMirror(machines, machine)
|
|
337
|
+
const label = String(((match && (match.name || match.host)) || machine.alias || machine.host || '')).trim()
|
|
338
|
+
const parts = []
|
|
339
|
+
if (label) parts.push(i18n.t('status.detailMachine', { name: label }))
|
|
340
|
+
parts.push(i18n.t('status.detailTarget', {
|
|
341
|
+
user: machine.username || '',
|
|
342
|
+
host: machine.host || '',
|
|
343
|
+
port: Number(machine.port) || 22,
|
|
344
|
+
}))
|
|
345
|
+
parts.push(i18n.t('status.detailRemote', { path: resolved.remotePath }))
|
|
346
|
+
return { label, detail: parts.filter(Boolean).join(' · ') }
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** 读当前机器名并写状态行;旧结果(token 过期)直接丢弃。
|
|
350
|
+
*
|
|
351
|
+
* 只在**当前会话的 cwd 落在远程镜像里**时显示(用户报告的“本地目录也显示
|
|
352
|
+
* 服务器名”就是待机机器被无条件写进底栏)。没有 sessions 服务的旧组合
|
|
353
|
+
* 退回旧行为,不猜。 */
|
|
216
354
|
const refreshStatusField = async () => {
|
|
217
355
|
if (!statusService || typeof statusService.setField !== 'function') return
|
|
218
356
|
if (typeof api.listMachines !== 'function') return
|
|
@@ -225,12 +363,30 @@ export function installTui(ctx, api, config) {
|
|
|
225
363
|
currentId = result && result.currentId !== undefined ? result.currentId : null
|
|
226
364
|
} catch (error) {
|
|
227
365
|
warn(ctx, '状态行读取机器列表失败', error)
|
|
366
|
+
// 读不到机器列表时不要留下旧机器名(那正是“待机机器占底栏”的观感来源)。
|
|
367
|
+
applyStatusField(undefined)
|
|
228
368
|
return
|
|
229
369
|
}
|
|
230
|
-
if (token !== statusRefreshToken) return
|
|
370
|
+
if (token !== statusRefreshToken || disposed) return
|
|
231
371
|
const current = machines.find((machine) => machine && machine.id === currentId)
|
|
232
|
-
const
|
|
233
|
-
|
|
372
|
+
const remote = remoteSessionLabel(machines)
|
|
373
|
+
const label = remote === null
|
|
374
|
+
? (current ? String(current.name || current.host || '').trim() : '')
|
|
375
|
+
: remote.label
|
|
376
|
+
applyStatusField(label || undefined, remote && remote.detail)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** 会话事件合并刷新:会话进入/结束、用户在哪说话都会改变“当前会话”。
|
|
380
|
+
* 500ms 合并避免连续事件重复跑 listMachines。 */
|
|
381
|
+
const SESSION_REFRESH_MS = 500
|
|
382
|
+
let sessionRefreshTimer = null
|
|
383
|
+
const scheduleStatusRefresh = () => {
|
|
384
|
+
if (sessionRefreshTimer) return
|
|
385
|
+
sessionRefreshTimer = setTimeout(() => {
|
|
386
|
+
sessionRefreshTimer = null
|
|
387
|
+
void refreshStatusField()
|
|
388
|
+
}, SESSION_REFRESH_MS)
|
|
389
|
+
if (typeof sessionRefreshTimer.unref === 'function') sessionRefreshTimer.unref()
|
|
234
390
|
}
|
|
235
391
|
|
|
236
392
|
/** 任意 TUI 接缝出现后:订阅宿主变更(刷新 provider 缓存 + 状态行)。 */
|
|
@@ -251,6 +407,59 @@ export function installTui(ctx, api, config) {
|
|
|
251
407
|
}
|
|
252
408
|
bindEffect(ctx, dispose)
|
|
253
409
|
}
|
|
410
|
+
// 会话进入/结束、用户发消息都会改变“当前会话”,据此刷新底栏字段。
|
|
411
|
+
if (typeof ctx.on === 'function') {
|
|
412
|
+
const disposers = []
|
|
413
|
+
const subscribe = (event, listener) => {
|
|
414
|
+
try {
|
|
415
|
+
const dispose = ctx.on(event, listener)
|
|
416
|
+
if (typeof dispose === 'function') disposers.push(dispose)
|
|
417
|
+
} catch (error) {
|
|
418
|
+
warn(ctx, `会话事件订阅失败(${event})`, error)
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
subscribe('session/created', (session) => {
|
|
422
|
+
if (!session || session.id == null || isSubagentSession(session)) return
|
|
423
|
+
activeSessionId = String(session.id)
|
|
424
|
+
scheduleStatusRefresh()
|
|
425
|
+
})
|
|
426
|
+
subscribe('session/disposed', (session) => {
|
|
427
|
+
if (!session || session.id == null || isSubagentSession(session)) return
|
|
428
|
+
const id = String(session.id)
|
|
429
|
+
if (id === activeSessionId) {
|
|
430
|
+
activeSessionId = lastUserSessionId && lastUserSessionId !== id ? lastUserSessionId : null
|
|
431
|
+
}
|
|
432
|
+
if (id === lastUserSessionId) lastUserSessionId = null
|
|
433
|
+
if (hostSessionCwd && !activeSessionId) hostSessionCwd = ''
|
|
434
|
+
scheduleStatusRefresh()
|
|
435
|
+
})
|
|
436
|
+
subscribe('session/event', (session, event) => {
|
|
437
|
+
if (!event || event.type !== 'user/message' || isSubagentSession(session)) return
|
|
438
|
+
if (!session || session.id == null) return
|
|
439
|
+
lastUserSessionId = String(session.id)
|
|
440
|
+
activeSessionId = String(session.id)
|
|
441
|
+
scheduleStatusRefresh()
|
|
442
|
+
})
|
|
443
|
+
bindEffect(ctx, () => {
|
|
444
|
+
if (sessionRefreshTimer) {
|
|
445
|
+
clearTimeout(sessionRefreshTimer)
|
|
446
|
+
sessionRefreshTimer = null
|
|
447
|
+
}
|
|
448
|
+
for (const dispose of disposers) {
|
|
449
|
+
try { dispose() } catch { /* teardown is best-effort */ }
|
|
450
|
+
}
|
|
451
|
+
})
|
|
452
|
+
}
|
|
453
|
+
// 终端变窄/变宽后详情要重新裁:否则旧字符串会 wrap 进看不见的第二行。
|
|
454
|
+
if (process.stdout && typeof process.stdout.on === 'function') {
|
|
455
|
+
const onResize = () => scheduleStatusRefresh()
|
|
456
|
+
try {
|
|
457
|
+
process.stdout.on('resize', onResize)
|
|
458
|
+
bindEffect(ctx, () => process.stdout.removeListener('resize', onResize))
|
|
459
|
+
} catch (error) {
|
|
460
|
+
warn(ctx, '终端 resize 订阅失败', error)
|
|
461
|
+
}
|
|
462
|
+
}
|
|
254
463
|
void refreshStatusField()
|
|
255
464
|
}
|
|
256
465
|
|
package/lib/tui/provider.js
CHANGED
|
@@ -53,9 +53,39 @@ function rootFromCwd(cwd) {
|
|
|
53
53
|
* @param {object} [deps.config] - 行 config(tuiProviderListRecent / tuiProviderRecentLimit)。
|
|
54
54
|
* @param {object} [deps.logger] - cordis logger(只用于 warn,失败一律降级)。
|
|
55
55
|
* @param {string} [deps.root] - 镜像 registry 根;省略时从 listRemoteProjects 结果推导。
|
|
56
|
+
* @param {(cwd: string) => void} [deps.onDescribe] - 宿主每次用会话 cwd 调
|
|
57
|
+
* `describe()` 时的只读提示(installTui 用它跟踪“当前会话”,见 lib/tui/index.js)。
|
|
56
58
|
* @returns {object} TuiWorkspaceProvider(附加 `refresh()`,供 installTui 预热/订阅刷新)。
|
|
57
59
|
*/
|
|
58
|
-
|
|
60
|
+
/**
|
|
61
|
+
* 把镜像 meta 里的 `{host, port, username, alias}` 对到保存的机器记录:
|
|
62
|
+
* ssh-config 别名机按 alias 命中(meta 记的是解析后地址 + alias),字面机按
|
|
63
|
+
* host/port/username 命中。installTui 的底栏与 provider 共用这一套规则。
|
|
64
|
+
*
|
|
65
|
+
* @param {Array<object>} machines - `api.listMachines()` 的 MachineView 列表。
|
|
66
|
+
* @param {{host: string, port: number, username: string, alias?: string}} mirrorMachine
|
|
67
|
+
* @returns {object|undefined} 命中的机器记录。
|
|
68
|
+
*/
|
|
69
|
+
export function matchMachineForMirror(machines, mirrorMachine) {
|
|
70
|
+
const list = Array.isArray(machines) ? machines : []
|
|
71
|
+
if (!mirrorMachine) return undefined
|
|
72
|
+
const alias = String(mirrorMachine.alias || '')
|
|
73
|
+
if (alias) {
|
|
74
|
+
const byAlias = list.find((m) => m && m.useSshConfig && String(m.host || '') === alias)
|
|
75
|
+
if (byAlias) return byAlias
|
|
76
|
+
}
|
|
77
|
+
const host = String(mirrorMachine.host || '')
|
|
78
|
+
const port = Number(mirrorMachine.port) || 22
|
|
79
|
+
const user = String(mirrorMachine.username || '')
|
|
80
|
+
return list.find((m) => {
|
|
81
|
+
if (!m || m.useSshConfig) return false
|
|
82
|
+
if (String(m.host || '') !== host) return false
|
|
83
|
+
if ((Number(m.port) || 22) !== port) return false
|
|
84
|
+
return !user || String(m.username || '') === user
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function createWorkspaceProvider({ api, config, logger, root, onDescribe } = {}) {
|
|
59
89
|
const state = {
|
|
60
90
|
targets: [],
|
|
61
91
|
machines: [],
|
|
@@ -123,23 +153,7 @@ export function createWorkspaceProvider({ api, config, logger, root } = {}) {
|
|
|
123
153
|
}
|
|
124
154
|
|
|
125
155
|
/** resolveMirror 的 machine 段(meta)→ 保存的机器。 */
|
|
126
|
-
const machineForMirror = (mirrorMachine) =>
|
|
127
|
-
if (!mirrorMachine) return undefined
|
|
128
|
-
const alias = String(mirrorMachine.alias || '')
|
|
129
|
-
if (alias) {
|
|
130
|
-
const byAlias = state.machines.find((m) => m.useSshConfig && String(m.host || '') === alias)
|
|
131
|
-
if (byAlias) return byAlias
|
|
132
|
-
}
|
|
133
|
-
const host = String(mirrorMachine.host || '')
|
|
134
|
-
const port = Number(mirrorMachine.port) || 22
|
|
135
|
-
const user = String(mirrorMachine.username || '')
|
|
136
|
-
return state.machines.find((m) => {
|
|
137
|
-
if (m.useSshConfig) return false
|
|
138
|
-
if (String(m.host || '') !== host) return false
|
|
139
|
-
if ((Number(m.port) || 22) !== port) return false
|
|
140
|
-
return !user || String(m.username || '') === user
|
|
141
|
-
})
|
|
142
|
-
}
|
|
156
|
+
const machineForMirror = (mirrorMachine) => matchMachineForMirror(state.machines, mirrorMachine)
|
|
143
157
|
|
|
144
158
|
/** 把一个 target 放进缓存(uri 去重,先到先得)。 */
|
|
145
159
|
const remember = (map, target) => {
|
|
@@ -270,8 +284,11 @@ export function createWorkspaceProvider({ api, config, logger, root } = {}) {
|
|
|
270
284
|
return target
|
|
271
285
|
}
|
|
272
286
|
|
|
273
|
-
/** 只读同步的镜像解析:cwd 属于某个镜像 → target;否则 undefined。
|
|
287
|
+
/** 只读同步的镜像解析:cwd 属于某个镜像 → target;否则 undefined。
|
|
288
|
+
* 宿主在每次会话切换后都会带着新 cwd 调这里(见 dsh-tui live adoption),
|
|
289
|
+
* 所以顺手把 cwd 作为“当前会话”提示交给 installTui。 */
|
|
274
290
|
const describe = (cwd) => {
|
|
291
|
+
try { if (typeof onDescribe === 'function') onDescribe(cwd) } catch { /* hint is best-effort */ }
|
|
275
292
|
if (!cwd) return undefined
|
|
276
293
|
const root = mirrorRoot(String(cwd))
|
|
277
294
|
if (!root) return undefined
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.80",
|
|
4
4
|
"description": "Remote-work assistant for DeepSeek Harness: connect SSH (password/key/agent/keyboard-interactive, multi-hop ProxyJump), list hosts from ~/.ssh/config, pick a remote workspace, operate on it with 21 rw_* tools, conflict-aware mirror sync, an embedded PTY terminal, remote DSH web UI attach, port forwarding, host grouping, remote sandbox fencing, audit log, keychain passwords.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "flymysql <flyphp@outlook.com>",
|