dsh-remote-go 0.1.0 → 0.3.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.md +64 -95
- package/{client.js → dist/client.js} +7805 -5486
- package/dist/index.js +4 -0
- package/dist/src/admission.js +46 -0
- package/dist/src/api.js +442 -0
- package/dist/src/atomic-json.js +235 -0
- package/dist/src/bootstrap.js +106 -0
- package/dist/src/connect/attach.js +43 -0
- package/dist/src/connect/bootstrap.js +14 -0
- package/dist/src/connect/failures.js +44 -0
- package/dist/src/connect/guards.js +31 -0
- package/dist/src/connect/launch.js +80 -0
- package/dist/src/connect/links.js +70 -0
- package/dist/src/connect/ownership.js +220 -0
- package/dist/src/connect/pipeline.js +473 -0
- package/dist/src/connect/reattach.js +215 -0
- package/dist/src/connect/registry.js +11 -0
- package/dist/src/connect/repair.js +126 -0
- package/dist/src/connect/restart.js +316 -0
- package/dist/src/connect/stop.js +198 -0
- package/dist/src/connect/transport.js +109 -0
- package/dist/src/connect/verify.js +39 -0
- package/dist/src/connect/watchdog.js +76 -0
- package/dist/src/connect-log.js +162 -0
- package/dist/src/connect-progress.js +142 -0
- package/dist/src/constants.js +67 -0
- package/dist/src/context.js +117 -0
- package/dist/src/diagnostics.js +102 -0
- package/dist/src/download-jobs.js +230 -0
- package/dist/src/errors.js +243 -0
- package/dist/src/events.js +390 -0
- package/dist/src/host-lifecycle.js +504 -0
- package/dist/src/host-registry.js +232 -0
- package/dist/src/host-runtime.js +86 -0
- package/dist/src/host-view.js +75 -0
- package/dist/src/index.js +216 -0
- package/dist/src/kernel-adapter.js +434 -0
- package/dist/src/key-files.js +52 -0
- package/dist/src/known-hosts.js +125 -0
- package/dist/src/layout.js +43 -0
- package/dist/src/local-download.js +380 -0
- package/dist/src/local-ssh.js +30 -0
- package/dist/src/local-version.js +101 -0
- package/dist/src/node/download.js +160 -0
- package/dist/src/node-runtime.js +346 -0
- package/dist/src/probe.js +96 -0
- package/dist/src/prompts.js +270 -0
- package/dist/src/proxy/cookies.js +136 -0
- package/dist/src/proxy/headers.js +262 -0
- package/dist/src/proxy/http.js +142 -0
- package/dist/src/proxy/index.js +135 -0
- package/dist/src/proxy/limits.js +8 -0
- package/dist/src/proxy/routes.js +39 -0
- package/dist/src/proxy/upgrade.js +175 -0
- package/dist/src/redact.js +104 -0
- package/dist/src/remote-files.js +72 -0
- package/dist/src/remote-path.js +123 -0
- package/dist/src/remote-proc.js +339 -0
- package/dist/src/remote-web/registry.js +147 -0
- package/dist/src/remote-web/resolve.js +310 -0
- package/dist/src/remote-web/start.js +227 -0
- package/dist/src/remote-web/stop.js +93 -0
- package/dist/src/request-trust.js +87 -0
- package/dist/src/runtime/dispatch.js +310 -0
- package/dist/src/runtime/effects.js +91 -0
- package/dist/src/runtime/events.js +35 -0
- package/dist/src/runtime/fsm.js +120 -0
- package/dist/src/runtime/rules.js +565 -0
- package/dist/src/secrets.js +142 -0
- package/dist/src/service.js +406 -0
- package/dist/src/settings.js +144 -0
- package/dist/src/ssh-config.js +276 -0
- package/dist/src/ssh-failures.js +122 -0
- package/dist/src/ssh-port.js +4 -0
- package/dist/src/ssh-sftp.js +297 -0
- package/dist/src/ssh.js +477 -0
- package/dist/src/store.js +191 -0
- package/dist/src/tool-shared.js +181 -0
- package/dist/src/tools-exec-policy.js +167 -0
- package/dist/src/tools-exec.js +371 -0
- package/dist/src/tools-report.js +424 -0
- package/dist/src/tools.js +411 -0
- package/dist/src/tunnel.js +129 -0
- package/dist/src/util.js +149 -0
- package/dist/src/version.js +114 -0
- package/dist/src/watchdog-bus.js +29 -0
- package/dist/src/watchdog.js +156 -0
- package/index.js +5 -4
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +40 -21
- package/vendor/THIRD_PARTY_NOTICES.md +27 -1
- package/src/api.js +0 -340
- package/src/atomic-json.js +0 -208
- package/src/bootstrap.js +0 -100
- package/src/connect-log.js +0 -39
- package/src/connect-pipeline.js +0 -463
- package/src/connect-progress.js +0 -135
- package/src/constants.js +0 -31
- package/src/diagnostics.js +0 -157
- package/src/download-jobs.js +0 -217
- package/src/errors.js +0 -316
- package/src/host-lifecycle.js +0 -187
- package/src/host-registry.js +0 -145
- package/src/host-runtime.js +0 -53
- package/src/host-view.js +0 -51
- package/src/index.js +0 -162
- package/src/key-files.js +0 -49
- package/src/known-hosts.js +0 -94
- package/src/layout.js +0 -35
- package/src/local-download.js +0 -162
- package/src/local-ssh.js +0 -27
- package/src/local-version.js +0 -88
- package/src/node-runtime.js +0 -521
- package/src/probe.js +0 -89
- package/src/prompts.js +0 -132
- package/src/redact.js +0 -54
- package/src/remote-files.js +0 -71
- package/src/remote-path.js +0 -73
- package/src/remote-proc.js +0 -208
- package/src/remote-web.js +0 -300
- package/src/secrets.js +0 -79
- package/src/service.js +0 -250
- package/src/settings.js +0 -135
- package/src/ssh-config.js +0 -271
- package/src/ssh.js +0 -652
- package/src/store.js +0 -143
- package/src/tunnel.js +0 -73
- package/src/util.js +0 -153
- package/src/version.js +0 -103
- package/src/webapp.js +0 -28
- package/vendor/ssh2-entry.mjs +0 -12
- /package/{vendor → dist/vendor}/ssh2.bundle.cjs +0 -0
package/src/known-hosts.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read-only `~/.ssh/known_hosts` parsing and OpenSSH SHA256 fingerprints; hashed entries are counted, never guessed at.
|
|
3
|
-
*/
|
|
4
|
-
import { createHash } from 'node:crypto'
|
|
5
|
-
|
|
6
|
-
export function fingerprintFromBase64(keyBase64) {
|
|
7
|
-
const digest = createHash('sha256').update(Buffer.from(keyBase64, 'base64')).digest('base64')
|
|
8
|
-
return `SHA256:${digest.replace(/=+$/g, '')}`
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function fingerprintFromBlob(keyBlob) {
|
|
12
|
-
const digest = createHash('sha256').update(keyBlob).digest('base64')
|
|
13
|
-
return `SHA256:${digest.replace(/=+$/g, '')}`
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function parseKnownHosts(text) {
|
|
17
|
-
const entries = []
|
|
18
|
-
const malformed = []
|
|
19
|
-
let hashedCount = 0
|
|
20
|
-
let revoked = 0
|
|
21
|
-
let certAuthority = 0
|
|
22
|
-
|
|
23
|
-
const lines = String(text ?? '').split(/\r?\n/)
|
|
24
|
-
for (let index = 0; index < lines.length; index += 1) {
|
|
25
|
-
const lineNo = index + 1
|
|
26
|
-
const raw = lines[index].trim()
|
|
27
|
-
if (raw === '' || raw.startsWith('#')) continue
|
|
28
|
-
const parts = raw.split(/\s+/)
|
|
29
|
-
let marker = null
|
|
30
|
-
if (parts[0].startsWith('@')) marker = parts.shift() ?? null
|
|
31
|
-
if (parts.length < 3) {
|
|
32
|
-
malformed.push({ line: lineNo, text: raw })
|
|
33
|
-
continue
|
|
34
|
-
}
|
|
35
|
-
const [hostField, keyType, keyBase64] = parts
|
|
36
|
-
if (marker === '@revoked') {
|
|
37
|
-
revoked += 1
|
|
38
|
-
continue
|
|
39
|
-
}
|
|
40
|
-
if (marker === '@cert-authority') {
|
|
41
|
-
certAuthority += 1
|
|
42
|
-
continue
|
|
43
|
-
}
|
|
44
|
-
if (hostField.startsWith('|1|')) {
|
|
45
|
-
hashedCount += 1
|
|
46
|
-
continue
|
|
47
|
-
}
|
|
48
|
-
if (!/^[A-Za-z0-9+/=]+$/.test(keyBase64 ?? '')) {
|
|
49
|
-
malformed.push({ line: lineNo, text: raw })
|
|
50
|
-
continue
|
|
51
|
-
}
|
|
52
|
-
entries.push({
|
|
53
|
-
hosts: hostField.split(',').filter(Boolean),
|
|
54
|
-
keyType,
|
|
55
|
-
keyBase64,
|
|
56
|
-
fingerprint: fingerprintFromBase64(keyBase64),
|
|
57
|
-
marker,
|
|
58
|
-
line: lineNo,
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
return { entries, hashedCount, malformed, revoked, certAuthority }
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function knownHostFieldMatches(pattern, host, port) {
|
|
65
|
-
const portSuffix = port && port !== 22 ? `:${port}` : null
|
|
66
|
-
const candidates = portSuffix ? [`[${host}]${portSuffix}`] : []
|
|
67
|
-
// A plain `host` line also matches a non-default port only for SSH's default
|
|
68
|
-
// behavior; be conservative and require the bracketed form for non-22.
|
|
69
|
-
candidates.push(host, `[${host}]`)
|
|
70
|
-
const escaped = String(pattern)
|
|
71
|
-
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
72
|
-
.replace(/\*/g, '.*')
|
|
73
|
-
.replace(/\?/g, '.')
|
|
74
|
-
const matcher = new RegExp(`^${escaped}$`, 'i')
|
|
75
|
-
return candidates.some((candidate) => matcher.test(candidate))
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function findKnownHostEntries(parsed, host, port) {
|
|
79
|
-
return parsed.entries.filter((entry) => entry.hosts.some((pattern) => knownHostFieldMatches(pattern, host, port)))
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function summarizeKnownHosts(parsed) {
|
|
83
|
-
const hosts = new Set()
|
|
84
|
-
for (const entry of parsed.entries) {
|
|
85
|
-
for (const host of entry.hosts) {
|
|
86
|
-
if (!host.startsWith('|1|')) hosts.add(host)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
entries: parsed.entries.length,
|
|
91
|
-
hashed: parsed.hashedCount,
|
|
92
|
-
hosts: [...hosts].sort().slice(0, 200),
|
|
93
|
-
}
|
|
94
|
-
}
|
package/src/layout.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remote directory layout: everything the plugin writes lives under `$DSH_HOME/remote-go`, so a host only gets `~/.dsh` plus that one subdirectory.
|
|
3
|
-
*/
|
|
4
|
-
import { REMOTE_DSH_DIR, REMOTE_STATE_DIR } from './constants.js'
|
|
5
|
-
|
|
6
|
-
export function remoteLayout(home = null) {
|
|
7
|
-
const dshHome = expandRemoteTilde(`~/${REMOTE_DSH_DIR}`, home).replace(/\/+$/, '')
|
|
8
|
-
const root = `${dshHome}/${REMOTE_STATE_DIR}`
|
|
9
|
-
return {
|
|
10
|
-
root,
|
|
11
|
-
// Kept for callers that resolve the remote DSH home separately from the
|
|
12
|
-
// plugin's own state directory.
|
|
13
|
-
stateHome: dshHome,
|
|
14
|
-
// The remote DSH runs with its real home, so its data is the user's own.
|
|
15
|
-
dshHome,
|
|
16
|
-
nodeDir: `${root}/node`,
|
|
17
|
-
downloadDir: `${root}/downloads`,
|
|
18
|
-
logsDir: `${root}/logs`,
|
|
19
|
-
logFile: `${root}/logs/web.log`,
|
|
20
|
-
runDir: `${root}/run`,
|
|
21
|
-
runFile: `${root}/run/web.json`,
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Expand a leading `~` (or `~/`) with a known remote home. When `home` is not
|
|
27
|
-
* known yet the tilde is preserved; callers must expand before shell use.
|
|
28
|
-
*/
|
|
29
|
-
function expandRemoteTilde(value, home) {
|
|
30
|
-
const text = String(value ?? '')
|
|
31
|
-
if (!home) return text
|
|
32
|
-
if (text === '~') return home
|
|
33
|
-
if (text.startsWith('~/')) return `${home.replace(/\/+$/, '')}/${text.slice(2)}`
|
|
34
|
-
return text
|
|
35
|
-
}
|
package/src/local-download.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local download writer. Every download (single file or folder) is streamed from
|
|
3
|
-
* SFTP directly to a user-selected local directory. Nothing is archived or held in
|
|
4
|
-
* memory, and there is no byte or entry cap. Existing target names are renamed with
|
|
5
|
-
* a ` (2)`, ` (3)` suffix so a download never overwrites local data.
|
|
6
|
-
*/
|
|
7
|
-
import path from 'node:path'
|
|
8
|
-
import { mkdir, open, rm, stat } from 'node:fs/promises'
|
|
9
|
-
import { errors, isRemoteGoError } from './errors.js'
|
|
10
|
-
import { remoteFileName, safeLocalSegment } from './remote-path.js'
|
|
11
|
-
|
|
12
|
-
async function requireDestination(destination) {
|
|
13
|
-
if (typeof destination !== 'string' || destination.trim() === '' || destination.includes('\0')) {
|
|
14
|
-
throw errors.invalidInput('destination', {
|
|
15
|
-
zh: '请选择本机的保存文件夹。',
|
|
16
|
-
en: 'Choose a destination folder on this machine.',
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
const base = path.resolve(destination)
|
|
20
|
-
try {
|
|
21
|
-
const info = await stat(base)
|
|
22
|
-
if (!info.isDirectory()) {
|
|
23
|
-
throw errors.invalidInput('destination', {
|
|
24
|
-
zh: '选择的保存位置不是文件夹。',
|
|
25
|
-
en: 'The selected destination is not a folder.',
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
} catch (error) {
|
|
29
|
-
if (isRemoteGoError(error)) throw error
|
|
30
|
-
throw errors.invalidInput('destination', {
|
|
31
|
-
zh: '选择的保存文件夹不存在或不可写。',
|
|
32
|
-
en: 'The selected destination folder does not exist or cannot be written.',
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
return base
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function createUniqueFolder(base, name) {
|
|
39
|
-
const safeName = safeLocalSegment(name) || 'download'
|
|
40
|
-
for (let index = 1; index <= 999; index += 1) {
|
|
41
|
-
const candidate = path.join(base, index === 1 ? safeName : `${safeName} (${index})`)
|
|
42
|
-
try {
|
|
43
|
-
await mkdir(candidate)
|
|
44
|
-
return candidate
|
|
45
|
-
} catch (error) {
|
|
46
|
-
if (/** @type {any} */ (error)?.code !== 'EEXIST') throw error
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
throw errors.invalidInput('destination', {
|
|
50
|
-
zh: '目标目录里已经有太多同名文件夹,请换一个目录。',
|
|
51
|
-
en: 'The destination already contains too many folders with this name; choose another directory.',
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function createUniqueFile(base, name) {
|
|
56
|
-
const safeName = safeLocalSegment(name) || 'download'
|
|
57
|
-
const extension = path.extname(safeName)
|
|
58
|
-
const stem = path.basename(safeName, extension) || 'download'
|
|
59
|
-
for (let index = 1; index <= 999; index += 1) {
|
|
60
|
-
const fileName = index === 1 ? safeName : `${stem} (${index})${extension}`
|
|
61
|
-
const candidate = path.join(base, fileName)
|
|
62
|
-
try {
|
|
63
|
-
const handle = await open(candidate, 'wx', 0o600)
|
|
64
|
-
await handle.close()
|
|
65
|
-
return candidate
|
|
66
|
-
} catch (error) {
|
|
67
|
-
if (/** @type {any} */ (error)?.code !== 'EEXIST') throw error
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
throw errors.invalidInput('destination', {
|
|
71
|
-
zh: '目标目录里已经有太多同名文件,请换一个目录。',
|
|
72
|
-
en: 'The destination already contains too many files with this name; choose another directory.',
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function toDownloadError(error) {
|
|
77
|
-
if (isRemoteGoError(error)) return error
|
|
78
|
-
return errors.remoteFileUnavailable(undefined, {
|
|
79
|
-
technical: String(/** @type {any} */ (error?.message ?? error ?? '')).slice(0, 300),
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Stream one remote file into `destination`, creating an auto-renamed local file.
|
|
85
|
-
* @param {object} runtime - connected host runtime.
|
|
86
|
-
* @param {string} remotePath - normalized absolute remote path.
|
|
87
|
-
* @param {unknown} destination - absolute local directory.
|
|
88
|
-
* @param {{ onProgress?: Function, isCancelled?: () => boolean }} [options]
|
|
89
|
-
* @returns {Promise<{ path: string, kind: 'file', name: string, destination: string,
|
|
90
|
-
* totalBytes: number, files: number }>}
|
|
91
|
-
*/
|
|
92
|
-
export async function saveHostFile(runtime, remotePath, destination, options = {}) {
|
|
93
|
-
if (!runtime || runtime.status !== 'connected' || !runtime.ssh) {
|
|
94
|
-
throw errors.remoteFileUnavailable({
|
|
95
|
-
zh: '这台主机还没有连接,无法读取远端文件。',
|
|
96
|
-
en: 'This host is not connected, so the remote file cannot be read.',
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
if (typeof runtime.ssh.saveRemoteFile !== 'function') {
|
|
100
|
-
throw errors.internal('the SSH transport does not support file saves')
|
|
101
|
-
}
|
|
102
|
-
const base = await requireDestination(destination)
|
|
103
|
-
const name = remoteFileName(remotePath)
|
|
104
|
-
let localPath = null
|
|
105
|
-
try {
|
|
106
|
-
localPath = await createUniqueFile(base, name)
|
|
107
|
-
const result = await runtime.ssh.saveRemoteFile(remotePath, localPath, options)
|
|
108
|
-
return {
|
|
109
|
-
path: remotePath,
|
|
110
|
-
kind: 'file',
|
|
111
|
-
name: path.basename(localPath),
|
|
112
|
-
destination: localPath,
|
|
113
|
-
totalBytes: Number(result?.size ?? 0),
|
|
114
|
-
files: 1,
|
|
115
|
-
}
|
|
116
|
-
} catch (error) {
|
|
117
|
-
if (localPath) await rm(localPath, { force: true }).catch(() => {})
|
|
118
|
-
throw toDownloadError(error)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Copy one remote folder into `destination` as individual local files.
|
|
124
|
-
* @param {object} runtime - connected host runtime.
|
|
125
|
-
* @param {string} remotePath - normalized absolute remote folder path.
|
|
126
|
-
* @param {unknown} destination - absolute local directory.
|
|
127
|
-
* @param {{ onInventory?: Function, onProgress?: Function, isCancelled?: () => boolean }} [options]
|
|
128
|
-
* @returns {Promise<{ path: string, kind: 'folder', name: string, destination: string,
|
|
129
|
-
* totalBytes: number, files: number, cancelled?: boolean }>}
|
|
130
|
-
*/
|
|
131
|
-
export async function saveHostFolder(runtime, remotePath, destination, options = {}) {
|
|
132
|
-
if (!runtime || runtime.status !== 'connected' || !runtime.ssh) {
|
|
133
|
-
throw errors.remoteFileUnavailable({
|
|
134
|
-
zh: '这台主机还没有连接,无法读取远端文件夹。',
|
|
135
|
-
en: 'This host is not connected, so the remote folder cannot be read.',
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
if (typeof runtime.ssh.saveRemoteTree !== 'function') {
|
|
139
|
-
throw errors.internal('the SSH transport does not support folder saves')
|
|
140
|
-
}
|
|
141
|
-
const base = await requireDestination(destination)
|
|
142
|
-
const name = remoteFileName(remotePath)
|
|
143
|
-
let root = null
|
|
144
|
-
try {
|
|
145
|
-
root = await createUniqueFolder(base, name)
|
|
146
|
-
const result = await runtime.ssh.saveRemoteTree(remotePath, root, options)
|
|
147
|
-
return {
|
|
148
|
-
path: remotePath,
|
|
149
|
-
kind: 'folder',
|
|
150
|
-
name,
|
|
151
|
-
destination: result?.destination ?? root,
|
|
152
|
-
totalBytes: Number(result?.totalBytes ?? 0),
|
|
153
|
-
files: Number(result?.totalFiles ?? 0),
|
|
154
|
-
...(result?.cancelled === true ? { cancelled: true } : {}),
|
|
155
|
-
}
|
|
156
|
-
} catch (error) {
|
|
157
|
-
if (root) await rm(root, { recursive: true, force: true }).catch(() => {})
|
|
158
|
-
throw toDownloadError(error)
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export { requireDestination }
|
package/src/local-ssh.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local SSH material (read-only): `~/.ssh/config` and `~/.ssh/known_hosts`; never writes, never prompts.
|
|
3
|
-
*/
|
|
4
|
-
import { existsSync } from 'node:fs'
|
|
5
|
-
import { readFile } from 'node:fs/promises'
|
|
6
|
-
import path from 'node:path'
|
|
7
|
-
|
|
8
|
-
export async function loadLocalSshMaterial(input) {
|
|
9
|
-
const sshDir = path.join(input.home, '.ssh')
|
|
10
|
-
const configPath = path.join(sshDir, 'config')
|
|
11
|
-
const knownHostsPath = path.join(sshDir, 'known_hosts')
|
|
12
|
-
const exists = input.exists ?? existsSync
|
|
13
|
-
const read = input.readFileImpl ?? readFile
|
|
14
|
-
let configText = ''
|
|
15
|
-
let knownHostsText = ''
|
|
16
|
-
try {
|
|
17
|
-
if (exists(configPath)) configText = await read(configPath, 'utf8')
|
|
18
|
-
} catch {
|
|
19
|
-
configText = ''
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
if (exists(knownHostsPath)) knownHostsText = await read(knownHostsPath, 'utf8')
|
|
23
|
-
} catch {
|
|
24
|
-
knownHostsText = ''
|
|
25
|
-
}
|
|
26
|
-
return { sshDir, configText, knownHostsText, configPath, knownHostsPath }
|
|
27
|
-
}
|
package/src/local-version.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detect the DSH version of the local installation; the remote runtime is pinned to this exact version, never to npm `latest`.
|
|
3
|
-
*/
|
|
4
|
-
import { existsSync } from 'node:fs'
|
|
5
|
-
import { readFile } from 'node:fs/promises'
|
|
6
|
-
import path from 'node:path'
|
|
7
|
-
import { normalizeVersion, parseVersion } from './version.js'
|
|
8
|
-
|
|
9
|
-
export async function detectLocalVersion(input = {}) {
|
|
10
|
-
const env = input.env ?? process.env
|
|
11
|
-
const explicit = env.DSH_VERSION || env.DSH_RUNTIME_VERSION
|
|
12
|
-
if (explicit && parseVersion(normalizeVersion(explicit))) {
|
|
13
|
-
return { version: normalizeVersion(explicit), source: 'env' }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// The web client-module registry publishes the Host release identity, which
|
|
17
|
-
// releases share with the CLI package version.
|
|
18
|
-
try {
|
|
19
|
-
const clientModules = input.ctx?.get?.('clientModules')
|
|
20
|
-
const release = clientModules?.graph?.()?.release
|
|
21
|
-
if (release?.version && parseVersion(normalizeVersion(release.version))) {
|
|
22
|
-
return { version: normalizeVersion(release.version), source: 'client-modules' }
|
|
23
|
-
}
|
|
24
|
-
} catch {
|
|
25
|
-
/* service not present in this composition */
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (const candidate of candidatePackageJsons(input)) {
|
|
29
|
-
try {
|
|
30
|
-
if (!existsSync(candidate)) continue
|
|
31
|
-
const text = await readFile(candidate, 'utf8')
|
|
32
|
-
const parsed = JSON.parse(text)
|
|
33
|
-
if (parsed?.name === '@deepseek-ai/dsh' && parsed?.version && parseVersion(normalizeVersion(parsed.version))) {
|
|
34
|
-
return { version: normalizeVersion(parsed.version), source: `package.json:${candidate}` }
|
|
35
|
-
}
|
|
36
|
-
} catch {}
|
|
37
|
-
}
|
|
38
|
-
return { version: null, source: 'unknown' }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The local DSH build's Node engine range (`engines.node`). It is the source of
|
|
43
|
-
* truth for the managed Node version the plugin installs on the remote: the
|
|
44
|
-
* remote runs this exact DSH version, so it must satisfy this declaration.
|
|
45
|
-
*
|
|
46
|
-
* Best-effort like the version probe: an unreadable or missing package yields
|
|
47
|
-
* `range: null` and the caller falls back to the plugin's own floor.
|
|
48
|
-
*/
|
|
49
|
-
export async function detectLocalEnginesNode(input = {}) {
|
|
50
|
-
for (const candidate of candidatePackageJsons(input)) {
|
|
51
|
-
try {
|
|
52
|
-
if (!existsSync(candidate)) continue
|
|
53
|
-
const parsed = JSON.parse(await readFile(candidate, 'utf8'))
|
|
54
|
-
const range = parsed?.engines?.node
|
|
55
|
-
if (typeof range === 'string' && range.trim() !== '') {
|
|
56
|
-
return { range: range.trim(), source: `package.json:${candidate}` }
|
|
57
|
-
}
|
|
58
|
-
} catch {}
|
|
59
|
-
}
|
|
60
|
-
return { range: null, source: 'unknown' }
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function candidatePackageJsons(input = {}) {
|
|
64
|
-
const out = []
|
|
65
|
-
const argv1 = input.argv1 ?? process.argv[1] ?? ''
|
|
66
|
-
const marker = `${path.sep}@deepseek-ai${path.sep}dsh${path.sep}`
|
|
67
|
-
const markerIndex = argv1.indexOf(marker)
|
|
68
|
-
if (markerIndex >= 0) {
|
|
69
|
-
out.push(path.join(argv1.slice(0, markerIndex + marker.length), 'package.json'))
|
|
70
|
-
}
|
|
71
|
-
const resourcesPath = input.resourcesPath ?? /** @type {any} */ (process).resourcesPath
|
|
72
|
-
if (typeof resourcesPath === 'string' && resourcesPath !== '') {
|
|
73
|
-
out.push(path.join(resourcesPath, 'app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'package.json'))
|
|
74
|
-
out.push(
|
|
75
|
-
path.join(resourcesPath, 'app.asar.unpacked', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'package.json'),
|
|
76
|
-
)
|
|
77
|
-
out.push(path.join(resourcesPath, 'app', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'package.json'))
|
|
78
|
-
}
|
|
79
|
-
// Walk up from the CLI entry looking for a nested package.
|
|
80
|
-
let dir = argv1 ? path.dirname(argv1) : (input.cwd ?? process.cwd())
|
|
81
|
-
for (let i = 0; i < 8; i += 1) {
|
|
82
|
-
out.push(path.join(dir, 'node_modules', '@deepseek-ai', 'dsh', 'package.json'))
|
|
83
|
-
const parent = path.dirname(dir)
|
|
84
|
-
if (parent === dir) break
|
|
85
|
-
dir = parent
|
|
86
|
-
}
|
|
87
|
-
return [...new Set(out)]
|
|
88
|
-
}
|