dsh-remote-go 0.1.0 → 0.2.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 +56 -95
- package/client.js +3121 -330
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +12 -11
- package/src/admission.js +43 -0
- package/src/api.js +219 -23
- package/src/atomic-json.js +19 -2
- package/src/bootstrap.js +14 -1
- package/src/connect-log.js +145 -8
- package/src/connect-pipeline.js +1545 -108
- package/src/connect-progress.js +28 -8
- package/src/constants.js +65 -3
- package/src/diagnostics.js +3 -0
- package/src/download-jobs.js +17 -0
- package/src/errors.js +98 -2
- package/src/host-lifecycle.js +434 -17
- package/src/host-registry.js +78 -6
- package/src/host-runtime.js +74 -0
- package/src/host-view.js +28 -4
- package/src/index.js +47 -3
- package/src/key-files.js +6 -1
- package/src/known-hosts.js +50 -11
- package/src/layout.js +28 -10
- package/src/local-download.js +232 -13
- package/src/probe.js +13 -1
- package/src/prompts.js +114 -17
- package/src/redact.js +17 -3
- package/src/remote-files.js +2 -2
- package/src/remote-path.js +64 -0
- package/src/remote-proc.js +135 -0
- package/src/remote-proxy.js +815 -0
- package/src/remote-web.js +479 -28
- package/src/request-trust.js +89 -0
- package/src/secrets.js +38 -8
- package/src/service.js +222 -13
- package/src/settings.js +30 -2
- package/src/ssh.js +108 -29
- package/src/store.js +58 -8
- package/src/tools.js +386 -0
- package/src/tunnel.js +60 -1
- package/src/webapp.js +15 -0
- package/vendor/THIRD_PARTY_NOTICES.md +27 -1
- package/vendor/ssh2-entry.mjs +0 -12
package/src/connect-log.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The connect log behind `HostView.logs`: the per-host ring, its bounded `/state` tail and which statuses print it
|
|
2
|
+
* The connect log behind `HostView.logs`: the per-host ring, the per-connection reset, the structured failure lines, its bounded `/state` tail and which statuses print it.
|
|
3
3
|
*/
|
|
4
|
+
import { redactText } from './redact.js'
|
|
5
|
+
import { headTail } from './util.js'
|
|
4
6
|
|
|
5
7
|
export const CONNECT_LOG_STATUSES = Object.freeze(['connecting', 'fingerprint-pending', 'error'])
|
|
6
8
|
|
|
@@ -8,19 +10,51 @@ export const LOG_RING_LIMIT = 200
|
|
|
8
10
|
|
|
9
11
|
export const LOG_TAIL_LIMIT = 120
|
|
10
12
|
|
|
13
|
+
/** How much of one technical detail (redacted) the log prints before `headTail` elides it. */
|
|
14
|
+
export const LOG_TECHNICAL_LIMIT = 1200
|
|
15
|
+
|
|
16
|
+
/** How long a single remote-log / technical line may get before it is elided. */
|
|
17
|
+
export const LOG_LINE_LIMIT = 400
|
|
18
|
+
|
|
19
|
+
/** Cap on the remote-log lines a failed start prints, so a chatty tail cannot eat the ring. */
|
|
20
|
+
export const LOG_TAIL_LINES = 60
|
|
21
|
+
|
|
11
22
|
export function connectLogVisible(status) {
|
|
12
23
|
return typeof status === 'string' && CONNECT_LOG_STATUSES.includes(status)
|
|
13
24
|
}
|
|
14
25
|
|
|
26
|
+
/** A bilingual line: zh and en side by side, the shape the Client already resolves. */
|
|
27
|
+
function pair(zh, en) {
|
|
28
|
+
return { zh, en }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Accept only a complete { zh, en } pair; a half-resolved object would render as an empty line. */
|
|
32
|
+
function normalizeText(value) {
|
|
33
|
+
if (!value || typeof value !== 'object') return null
|
|
34
|
+
const zh = typeof value.zh === 'string' ? value.zh : ''
|
|
35
|
+
const en = typeof value.en === 'string' ? value.en : ''
|
|
36
|
+
if (zh === '' || en === '') return null
|
|
37
|
+
return pair(zh, en)
|
|
38
|
+
}
|
|
39
|
+
|
|
15
40
|
export function appendConnectLog(runtime, input) {
|
|
16
|
-
const
|
|
41
|
+
const raw = typeof input.message === 'string' ? input.message : String(input.message ?? '')
|
|
42
|
+
// The remote's own stdout arrives here (`remote-web.js` hands every start line to `onLine`, and
|
|
43
|
+
// the first one is the launch URL with its session token). This ring is the second exit of that
|
|
44
|
+
// text — `HostView.logs`, the SSE state frames and the diagnostics export all read it — so it
|
|
45
|
+
// is redacted at write time, not only when the failure view is built.
|
|
46
|
+
const message = headTail(redactText(raw), LOG_TECHNICAL_LIMIT)
|
|
17
47
|
const entry = {
|
|
18
48
|
seq: (typeof runtime.logSeq === 'number' ? runtime.logSeq : 0) + 1,
|
|
19
49
|
at: typeof input.at === 'string' ? input.at : '',
|
|
20
50
|
level: typeof input.level === 'string' ? input.level : 'info',
|
|
51
|
+
phase: typeof input.phase === 'string' && input.phase !== '' ? input.phase : null,
|
|
21
52
|
message,
|
|
22
53
|
line: `[dsh-remote-go:${runtime.id}] ${message}`,
|
|
23
54
|
}
|
|
55
|
+
const text = normalizeText(input.text)
|
|
56
|
+
if (text !== null) entry.text = text
|
|
57
|
+
if (input.boundary === true) entry.boundary = true
|
|
24
58
|
if (!Array.isArray(runtime.logs)) runtime.logs = []
|
|
25
59
|
if (runtime.logs.length >= LOG_RING_LIMIT) runtime.logs.shift()
|
|
26
60
|
runtime.logSeq = entry.seq
|
|
@@ -28,12 +62,115 @@ export function appendConnectLog(runtime, input) {
|
|
|
28
62
|
return entry
|
|
29
63
|
}
|
|
30
64
|
|
|
65
|
+
/** Forget the previous connection's lines; the sequence restarts with this connection. */
|
|
66
|
+
export function resetConnectLog(runtime) {
|
|
67
|
+
runtime.logs = []
|
|
68
|
+
runtime.logSeq = 0
|
|
69
|
+
return runtime
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** `YYYY-MM-DD HH:MM:SS` in the Host's own timezone — the clock the user reads. */
|
|
73
|
+
function localClock(date) {
|
|
74
|
+
const pad = (value) => String(value).padStart(2, '0')
|
|
75
|
+
return (
|
|
76
|
+
`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
|
|
77
|
+
`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Start one connection's log: drop the previous attempt and write its boundary line, so the
|
|
83
|
+
* panel opens on this attempt only and a copied log says which attempt it belongs to.
|
|
84
|
+
*/
|
|
85
|
+
export function beginConnectLog(runtime, options = {}) {
|
|
86
|
+
const at = typeof options.at === 'string' && options.at !== '' ? options.at : new Date().toISOString()
|
|
87
|
+
const when = new Date(at)
|
|
88
|
+
const attempt = (typeof runtime.connectCount === 'number' ? runtime.connectCount : 0) + 1
|
|
89
|
+
runtime.connectCount = attempt
|
|
90
|
+
resetConnectLog(runtime)
|
|
91
|
+
const clock = Number.isNaN(when.getTime()) ? at : localClock(when)
|
|
92
|
+
const text = pair(`— 第 ${attempt} 次连接 · ${clock} —`, `— Connection ${attempt} · ${clock} —`)
|
|
93
|
+
return appendConnectLog(runtime, { at, level: 'info', message: text.en, text, boundary: true })
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** `{ zh, en }` from any bilingual value, filling a missing side from the other. */
|
|
97
|
+
function say(value) {
|
|
98
|
+
if (typeof value === 'string') return value === '' ? null : pair(value, value)
|
|
99
|
+
if (!value || typeof value !== 'object') return null
|
|
100
|
+
const zh = typeof value.zh === 'string' ? value.zh : ''
|
|
101
|
+
const en = typeof value.en === 'string' ? value.en : ''
|
|
102
|
+
if (zh === '' && en === '') return null
|
|
103
|
+
return { zh: zh === '' ? en : zh, en: en === '' ? zh : en }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Turn an `ErrorView` into the lines the connect log prints for a failed connection:
|
|
108
|
+
* the failed phase and code, the localized reason, every hint, then the redacted and
|
|
109
|
+
* head-tail-truncated technical detail — the remote log tail line by line for a failed start.
|
|
110
|
+
*
|
|
111
|
+
* `options.label` replaces the first line for a one-shot action that is not a connect (the
|
|
112
|
+
* explicit remote stop), so its failure is not announced as a connection failure.
|
|
113
|
+
*
|
|
114
|
+
* @param {{ code?: string, title?: unknown, detail?: unknown, nextSteps?: unknown[], technical?: string } | null} view
|
|
115
|
+
* @param {{ phase?: string | null, label?: { zh: string, en: string } | null }} [options] -
|
|
116
|
+
* the phase the pipeline was in when it failed, and the first line's wording.
|
|
117
|
+
* @returns {{ level: string, phase: string | null, message: string, text?: { zh: string, en: string } }[]}
|
|
118
|
+
*/
|
|
119
|
+
export function connectFailureLines(view, options = {}) {
|
|
120
|
+
const code = typeof view?.code === 'string' && view.code !== '' ? view.code : 'internal'
|
|
121
|
+
const phase = typeof options.phase === 'string' && options.phase !== '' ? options.phase : null
|
|
122
|
+
const lines = []
|
|
123
|
+
const push = (text) => lines.push({ level: 'error', phase, message: text.en, text })
|
|
124
|
+
const raw = (message) => lines.push({ level: 'error', phase, message })
|
|
125
|
+
|
|
126
|
+
const label = normalizeText(options.label)
|
|
127
|
+
push(
|
|
128
|
+
label ??
|
|
129
|
+
(phase === null
|
|
130
|
+
? pair(`连接失败:${code}`, `Connect failed: ${code}`)
|
|
131
|
+
: pair(`连接失败于 ${phase} 阶段:${code}`, `Connect failed in phase ${phase}: ${code}`)),
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
// The card explains the failure in one sentence; the log has to carry that sentence.
|
|
135
|
+
const reason = say(view?.detail) ?? say(view?.title)
|
|
136
|
+
if (reason !== null) push(pair(`原因:${reason.zh}`, `Reason: ${reason.en}`))
|
|
137
|
+
|
|
138
|
+
const hints = Array.isArray(view?.nextSteps) ? view.nextSteps : []
|
|
139
|
+
for (const hint of hints) {
|
|
140
|
+
const step = say(hint)
|
|
141
|
+
if (step !== null) push(pair(`建议:${step.zh}`, `Next: ${step.en}`))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const technical = typeof view?.technical === 'string' ? view.technical : ''
|
|
145
|
+
if (technical.trim() !== '') {
|
|
146
|
+
const tail = code === 'remote-dsh-start-failed'
|
|
147
|
+
push(tail ? pair('远端日志尾部:', 'Remote log tail:') : pair('技术细节:', 'Details:'))
|
|
148
|
+
// Redaction is the contract of anything copied out of the log; `headTail` keeps both the
|
|
149
|
+
// start of the message (what failed) and its end (the error itself) when it is too long.
|
|
150
|
+
let printed = 0
|
|
151
|
+
for (const line of headTail(redactText(technical), LOG_TECHNICAL_LIMIT).split(/\r?\n/)) {
|
|
152
|
+
if (printed >= LOG_TAIL_LINES) break
|
|
153
|
+
if (line.trim() === '') continue
|
|
154
|
+
raw(headTail(line, LOG_LINE_LIMIT))
|
|
155
|
+
printed += 1
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return lines
|
|
159
|
+
}
|
|
160
|
+
|
|
31
161
|
export function connectLogTail(runtime) {
|
|
32
162
|
const entries = runtime && Array.isArray(runtime.logs) ? runtime.logs : []
|
|
33
|
-
return entries.slice(-LOG_TAIL_LIMIT).map((entry) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
163
|
+
return entries.slice(-LOG_TAIL_LIMIT).map((entry) => {
|
|
164
|
+
const item = {
|
|
165
|
+
seq: typeof entry.seq === 'number' ? entry.seq : 0,
|
|
166
|
+
at: typeof entry.at === 'string' ? entry.at : '',
|
|
167
|
+
level: typeof entry.level === 'string' ? entry.level : 'info',
|
|
168
|
+
phase: typeof entry.phase === 'string' && entry.phase !== '' ? entry.phase : null,
|
|
169
|
+
message: typeof entry.message === 'string' ? entry.message : String(entry.line ?? ''),
|
|
170
|
+
}
|
|
171
|
+
const text = normalizeText(entry.text)
|
|
172
|
+
if (text !== null) item.text = text
|
|
173
|
+
if (entry.boundary === true) item.boundary = true
|
|
174
|
+
return item
|
|
175
|
+
})
|
|
39
176
|
}
|