dsh-linked-workspace 0.24.0 → 0.25.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/CHANGELOG.md +33 -0
- package/README.en.md +13 -7
- package/README.md +13 -7
- package/docs/API.md +3 -2
- package/docs/VERIFY.md +39 -1
- package/lib/client.js +635 -81
- package/lib/index.js +141 -32
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -39,7 +39,7 @@ export const inject = ['webServer', 'tools', 'systemPrompt', 'workingDirectory']
|
|
|
39
39
|
* is still running an older copy of the Host — refreshing the page only swaps
|
|
40
40
|
* the browser bundle, so the two halves can drift by one restart.
|
|
41
41
|
*/
|
|
42
|
-
const API_REVISION =
|
|
42
|
+
const API_REVISION = 10
|
|
43
43
|
|
|
44
44
|
/** When this copy of the Host was loaded; shown by `meta.info`. */
|
|
45
45
|
const STARTED_AT = new Date().toISOString()
|
|
@@ -65,7 +65,7 @@ const HOST_KEY_POLICIES = new Set(['tofu', 'strict'])
|
|
|
65
65
|
const OUTPUT_ENCODINGS = new Set(['utf8', 'gbk'])
|
|
66
66
|
/** Exec allow-lists travel as arrays, so they are not part of the frozen defaults. */
|
|
67
67
|
const EMPTY_ID_LIST = Object.freeze([])
|
|
68
|
-
const EDITOR_THEME_FAMILIES = new Set(['github', 'solarized', 'one', 'dracula', 'monokai', 'nord', 'vscode', 'xcode', 'catppuccin'])
|
|
68
|
+
const EDITOR_THEME_FAMILIES = new Set(['github', 'solarized', 'one', 'dracula', 'monokai', 'nord', 'vscode', 'xcode', 'catppuccin', 'tokyo', 'gruvbox', 'ayu'])
|
|
69
69
|
const THEME_FAMILY_OF = (id) => {
|
|
70
70
|
const value = String(id || '')
|
|
71
71
|
if (value.startsWith('solarized')) return 'solarized'
|
|
@@ -76,10 +76,13 @@ const THEME_FAMILY_OF = (id) => {
|
|
|
76
76
|
if (value.startsWith('vs-')) return 'vscode'
|
|
77
77
|
if (value.startsWith('xcode')) return 'xcode'
|
|
78
78
|
if (value.startsWith('catppuccin')) return 'catppuccin'
|
|
79
|
+
if (value.startsWith('tokyo')) return 'tokyo'
|
|
80
|
+
if (value.startsWith('gruvbox')) return 'gruvbox'
|
|
81
|
+
if (value.startsWith('ayu')) return 'ayu'
|
|
79
82
|
return 'github'
|
|
80
83
|
}
|
|
81
84
|
const EDITOR_THEME_MODES = new Set(['system', 'light', 'dark'])
|
|
82
|
-
const LIGHT_EDITOR_THEMES = new Set(['github-light', 'solarized-light', 'xcode-light'])
|
|
85
|
+
const LIGHT_EDITOR_THEMES = new Set(['github-light', 'solarized-light', 'xcode-light', 'tokyo-night-light', 'gruvbox-light', 'ayu-light'])
|
|
83
86
|
const LEGACY_THEME_MIGRATION = 'github-dark'
|
|
84
87
|
const FILE_OPEN_MODES = new Set(['editor', 'system', 'copy'])
|
|
85
88
|
const WORKSPACE_TITLE_PREFIX = '⇄ '
|
|
@@ -1085,6 +1088,9 @@ export function apply(ctx) {
|
|
|
1085
1088
|
const settingsStore = new SettingsStore(join(dir, 'settings.json'))
|
|
1086
1089
|
/** localhost TCP tunnels opened by hosts.forward (id -> { server, ... }) */
|
|
1087
1090
|
const forwardServers = new Map()
|
|
1091
|
+
/** Tunnels that are still listed but have no listener right now (port taken, ...). */
|
|
1092
|
+
const forwardPending = new Map()
|
|
1093
|
+
const forwardFile = join(dir, 'forwards.json')
|
|
1088
1094
|
const forwardView = (record) => ({
|
|
1089
1095
|
id: record.id,
|
|
1090
1096
|
hostId: record.hostId,
|
|
@@ -1095,6 +1101,84 @@ export function apply(ctx) {
|
|
|
1095
1101
|
startedAt: record.startedAt,
|
|
1096
1102
|
url: `http://127.0.0.1:${record.localPort}/`,
|
|
1097
1103
|
})
|
|
1104
|
+
// 0.25.0: a tunnel is a standing arrangement, not a side effect of one page
|
|
1105
|
+
// session. Definitions live in forwards.json and the listeners are re-bound
|
|
1106
|
+
// on start, so a TensorBoard URL survives a Host restart; only
|
|
1107
|
+
// hosts.unforward (the Stop button) takes an entry away.
|
|
1108
|
+
const readForwardDefs = () => {
|
|
1109
|
+
const data = readJsonFile(forwardFile, null)
|
|
1110
|
+
const list = data && Array.isArray(data.forwards) ? data.forwards : []
|
|
1111
|
+
return list
|
|
1112
|
+
.filter((item) => item && typeof item.id === 'string' && typeof item.hostId === 'string')
|
|
1113
|
+
.map((item) => ({
|
|
1114
|
+
id: item.id,
|
|
1115
|
+
hostId: item.hostId,
|
|
1116
|
+
hostName: typeof item.hostName === 'string' && item.hostName !== '' ? item.hostName : item.hostId,
|
|
1117
|
+
remoteHost: typeof item.remoteHost === 'string' && item.remoteHost !== '' ? item.remoteHost : '127.0.0.1',
|
|
1118
|
+
remotePort: clampInt(item.remotePort, 1, 65535, 0),
|
|
1119
|
+
localPort: clampInt(item.localPort, 0, 65535, 0),
|
|
1120
|
+
startedAt: clampInt(item.startedAt, 0, Number.MAX_SAFE_INTEGER, Date.now()),
|
|
1121
|
+
}))
|
|
1122
|
+
.filter((item) => item.remotePort > 0)
|
|
1123
|
+
}
|
|
1124
|
+
const forwardDefOf = (record) => ({
|
|
1125
|
+
id: record.id,
|
|
1126
|
+
hostId: record.hostId,
|
|
1127
|
+
hostName: record.hostName,
|
|
1128
|
+
remoteHost: record.remoteHost,
|
|
1129
|
+
remotePort: record.remotePort,
|
|
1130
|
+
localPort: record.localPort,
|
|
1131
|
+
startedAt: record.startedAt,
|
|
1132
|
+
})
|
|
1133
|
+
const saveForwardDefs = () => {
|
|
1134
|
+
const forwards = [
|
|
1135
|
+
...[...forwardServers.values()].map(forwardDefOf),
|
|
1136
|
+
...[...forwardPending.values()].map((item) => item.def),
|
|
1137
|
+
]
|
|
1138
|
+
try {
|
|
1139
|
+
writeJsonAtomic(forwardFile, { version: 1, forwards })
|
|
1140
|
+
} catch (error) {
|
|
1141
|
+
log('warn', `could not save the tunnel list: ${error && error.message ? error.message : error}`)
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Bind one tunnel's local listener. `eager` dials the SSH connection first so
|
|
1146
|
+
* the caller sees credential/host-key problems immediately; restored tunnels
|
|
1147
|
+
* dial on the first connection instead, so a machine that is unreachable at
|
|
1148
|
+
* start-up still gets its listener back.
|
|
1149
|
+
*/
|
|
1150
|
+
const openForward = async (def, eager) => {
|
|
1151
|
+
const record = { ...def, server: null, remote: null }
|
|
1152
|
+
const remoteFor = async () => {
|
|
1153
|
+
if (record.remote) return record.remote
|
|
1154
|
+
const host = await findHost(record.hostId)
|
|
1155
|
+
record.remote = await pool.remote(host)
|
|
1156
|
+
return record.remote
|
|
1157
|
+
}
|
|
1158
|
+
if (eager) await remoteFor()
|
|
1159
|
+
const server = net.createServer((socket) => {
|
|
1160
|
+
remoteFor()
|
|
1161
|
+
.then((remote) => remote.forwardOut(record.remoteHost, record.remotePort))
|
|
1162
|
+
.then((channel) => {
|
|
1163
|
+
socket.pipe(channel).pipe(socket)
|
|
1164
|
+
channel.on('error', () => socket.destroy())
|
|
1165
|
+
socket.on('error', () => channel.destroy())
|
|
1166
|
+
})
|
|
1167
|
+
.catch((error) => {
|
|
1168
|
+
log('warn', `forward ${record.id} failed: ${error && error.message ? error.message : error}`)
|
|
1169
|
+
socket.destroy()
|
|
1170
|
+
})
|
|
1171
|
+
})
|
|
1172
|
+
await new Promise((resolvePromise, rejectPromise) => {
|
|
1173
|
+
server.once('error', rejectPromise)
|
|
1174
|
+
server.listen(def.localPort, '127.0.0.1', () => resolvePromise())
|
|
1175
|
+
}).catch((error) => {
|
|
1176
|
+
throw new ApiError('FORWARD_FAILED', `无法监听本地端口:${error && error.message ? error.message : error}`)
|
|
1177
|
+
})
|
|
1178
|
+
record.server = server
|
|
1179
|
+
record.localPort = server.address().port
|
|
1180
|
+
return record
|
|
1181
|
+
}
|
|
1098
1182
|
const linkedStore = new linkedFs.LinkedStore(join(dir, 'linked.json'))
|
|
1099
1183
|
const remoteStore = new RemoteWorkspaceStore(join(dir, 'remote-workspaces.json'))
|
|
1100
1184
|
// Old "open in notepad" copies are dead weight; clear them once per start.
|
|
@@ -3249,49 +3333,44 @@ export function apply(ctx) {
|
|
|
3249
3333
|
const existing = [...forwardServers.values()].find((item) => item.hostId === host.id
|
|
3250
3334
|
&& item.remotePort === remotePort && item.remoteHost === remoteHost)
|
|
3251
3335
|
if (existing) return { forward: forwardView(existing) }
|
|
3252
|
-
const
|
|
3253
|
-
|
|
3254
|
-
const server = net.createServer((socket) => {
|
|
3255
|
-
remote.forwardOut(remoteHost, remotePort).then((channel) => {
|
|
3256
|
-
socket.pipe(channel).pipe(socket)
|
|
3257
|
-
channel.on('error', () => socket.destroy())
|
|
3258
|
-
socket.on('error', () => channel.destroy())
|
|
3259
|
-
}).catch((error) => {
|
|
3260
|
-
log('warn', `forward ${id} failed: ${error && error.message ? error.message : error}`)
|
|
3261
|
-
socket.destroy()
|
|
3262
|
-
})
|
|
3263
|
-
})
|
|
3264
|
-
await new Promise((resolvePromise, rejectPromise) => {
|
|
3265
|
-
server.once('error', rejectPromise)
|
|
3266
|
-
server.listen(wantedPort, '127.0.0.1', () => resolvePromise())
|
|
3267
|
-
}).catch((error) => {
|
|
3268
|
-
throw new ApiError('FORWARD_FAILED', `无法监听本地端口:${error && error.message ? error.message : error}`)
|
|
3269
|
-
})
|
|
3270
|
-
const record = {
|
|
3271
|
-
id,
|
|
3336
|
+
const record = await openForward({
|
|
3337
|
+
id: randomUUID(),
|
|
3272
3338
|
hostId: host.id,
|
|
3273
3339
|
hostName: host.name || host.id,
|
|
3274
3340
|
remoteHost,
|
|
3275
3341
|
remotePort,
|
|
3276
|
-
localPort:
|
|
3342
|
+
localPort: wantedPort,
|
|
3277
3343
|
startedAt: Date.now(),
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3344
|
+
}, true)
|
|
3345
|
+
forwardServers.set(record.id, record)
|
|
3346
|
+
forwardPending.delete(record.id)
|
|
3347
|
+
saveForwardDefs()
|
|
3282
3348
|
return { forward: forwardView(record) }
|
|
3283
3349
|
},
|
|
3284
3350
|
|
|
3285
3351
|
async 'hosts.forwards'() {
|
|
3286
|
-
|
|
3352
|
+
const live = [...forwardServers.values()].map(forwardView)
|
|
3353
|
+
// A tunnel whose port was taken on restart is still a definition the user
|
|
3354
|
+
// owns: list it with the reason instead of hiding it.
|
|
3355
|
+
const stuck = [...forwardPending.values()].map((item) => ({
|
|
3356
|
+
...forwardView({ ...item.def, localPort: 0 }),
|
|
3357
|
+
url: '',
|
|
3358
|
+
error: item.error,
|
|
3359
|
+
}))
|
|
3360
|
+
return { forwards: [...live, ...stuck] }
|
|
3287
3361
|
},
|
|
3288
3362
|
|
|
3289
3363
|
async 'hosts.unforward'(params = {}) {
|
|
3290
3364
|
const id = typeof params.id === 'string' ? params.id.trim() : ''
|
|
3291
3365
|
const record = forwardServers.get(id)
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3366
|
+
const stuck = forwardPending.get(id)
|
|
3367
|
+
if (!record && !stuck) return { removed: false }
|
|
3368
|
+
if (record) {
|
|
3369
|
+
try { record.server.close() } catch { /* already closed */ }
|
|
3370
|
+
forwardServers.delete(id)
|
|
3371
|
+
}
|
|
3372
|
+
forwardPending.delete(id)
|
|
3373
|
+
saveForwardDefs()
|
|
3295
3374
|
return { removed: true }
|
|
3296
3375
|
},
|
|
3297
3376
|
|
|
@@ -5889,6 +5968,36 @@ export function apply(ctx) {
|
|
|
5889
5968
|
ctx.effect(() => () => {
|
|
5890
5969
|
for (const id of [...autoPushWatchers.keys()]) stopAutoPush(id)
|
|
5891
5970
|
}, 'dsh-linked-workspace: auto push watchers')
|
|
5971
|
+
// Re-bind the tunnels that were open when this Host last stopped. Deferred so
|
|
5972
|
+
// the whole apply() body (pool, findHost) is initialised first.
|
|
5973
|
+
setTimeout(() => {
|
|
5974
|
+
const defs = readForwardDefs()
|
|
5975
|
+
if (defs.length === 0) return
|
|
5976
|
+
void (async () => {
|
|
5977
|
+
for (const def of defs) {
|
|
5978
|
+
if (forwardServers.has(def.id) || forwardPending.has(def.id)) continue
|
|
5979
|
+
try {
|
|
5980
|
+
const record = await openForward(def, false)
|
|
5981
|
+
forwardServers.set(record.id, record)
|
|
5982
|
+
} catch (error) {
|
|
5983
|
+
const message = error && error.message ? error.message : String(error)
|
|
5984
|
+
if (def.localPort !== 0) {
|
|
5985
|
+
try {
|
|
5986
|
+
const retry = await openForward({ ...def, localPort: 0 }, false)
|
|
5987
|
+
forwardServers.set(retry.id, retry)
|
|
5988
|
+
continue
|
|
5989
|
+
} catch { /* keep the definition, report it as stuck */ }
|
|
5990
|
+
}
|
|
5991
|
+
forwardPending.set(def.id, { def, error: message })
|
|
5992
|
+
log('warn', `could not restore tunnel ${def.id}: ${message}`)
|
|
5993
|
+
}
|
|
5994
|
+
}
|
|
5995
|
+
saveForwardDefs()
|
|
5996
|
+
if (forwardServers.size > 0 || forwardPending.size > 0) {
|
|
5997
|
+
log('info', `tunnels: ${forwardServers.size} re-bound, ${forwardPending.size} waiting`)
|
|
5998
|
+
}
|
|
5999
|
+
})()
|
|
6000
|
+
}, 0)
|
|
5892
6001
|
ctx.effect(() => () => {
|
|
5893
6002
|
for (const record of forwardServers.values()) {
|
|
5894
6003
|
try { record.server.close() } catch { /* already closed */ }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-linked-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Linked local ⇄ remote workspaces and remote workspaces for DeepSeek Harness: theme-aware split editor, file-type icons, and agent tools that edit remote files directly.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|