@linxin666/dsh-client-ui-task-board-ssh 0.0.0-stage → 0.4.20
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/LICENSE +202 -0
- package/README.i18n.yaml +6 -0
- package/README.md +85 -2
- package/README.zh.md +86 -0
- package/cordis.patch.yml +15 -0
- package/icon.svg +5 -0
- package/lib/client.js +4429 -0
- package/lib/index.js +6100 -0
- package/lib/types/client/PluginSettingsCard.d.ts +255 -0
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/index.d.ts +100 -0
- package/lib/types/client/locales.d.ts +125 -0
- package/lib/types/client/seat-props.d.ts +53 -0
- package/lib/types/client/settings-entry-form.d.ts +49 -0
- package/lib/types/client/settings-form.d.ts +237 -0
- package/lib/types/client/ssh/card-decoration.d.ts +23 -0
- package/lib/types/client/ssh/compose-section.d.ts +7 -0
- package/lib/types/client/ssh/detail-section.d.ts +7 -0
- package/lib/types/client/ssh/extension.d.ts +54 -0
- package/lib/types/client/ssh/log-buffer.d.ts +128 -0
- package/lib/types/client/ssh/log-view.d.ts +37 -0
- package/lib/types/client/ssh/model.d.ts +130 -0
- package/lib/types/client/ssh/settings-section.d.ts +134 -0
- package/lib/types/client/ssh/summary.d.ts +160 -0
- package/lib/types/client/ssh/target-form.d.ts +60 -0
- package/lib/types/core/action.d.ts +89 -0
- package/lib/types/core/adapters/claude.d.ts +15 -0
- package/lib/types/core/adapters/codex.d.ts +15 -0
- package/lib/types/core/adapters/custom.d.ts +29 -0
- package/lib/types/core/adapters/dsh.d.ts +21 -0
- package/lib/types/core/adapters/index.d.ts +25 -0
- package/lib/types/core/adapters/types.d.ts +76 -0
- package/lib/types/core/contract.d.ts +445 -0
- package/lib/types/core/launcher-script.d.ts +13 -0
- package/lib/types/core/launcher.d.ts +153 -0
- package/lib/types/core/ledger.d.ts +123 -0
- package/lib/types/core/shell.d.ts +61 -0
- package/lib/types/core/target.d.ts +143 -0
- package/lib/types/core/task-record.d.ts +63 -0
- package/lib/types/core/workspace.d.ts +74 -0
- package/lib/types/host/board.d.ts +71 -0
- package/lib/types/host/engine.d.ts +418 -0
- package/lib/types/host/extension.d.ts +59 -0
- package/lib/types/host/logs.d.ts +135 -0
- package/lib/types/host/payload.d.ts +75 -0
- package/lib/types/host/prompt.d.ts +44 -0
- package/lib/types/host/queue.d.ts +53 -0
- package/lib/types/host/remote.d.ts +120 -0
- package/lib/types/host/settings.d.ts +149 -0
- package/lib/types/host/timers.d.ts +20 -0
- package/lib/types/host/tools.d.ts +15 -0
- package/lib/types/host/workspace/errors.d.ts +29 -0
- package/lib/types/host/workspace/git.d.ts +108 -0
- package/lib/types/host/workspace/in-place.d.ts +36 -0
- package/lib/types/host/workspace/index.d.ts +28 -0
- package/lib/types/host/workspace/layout.d.ts +62 -0
- package/lib/types/host/workspace/local-git.d.ts +72 -0
- package/lib/types/host/workspace/remote-git.d.ts +111 -0
- package/lib/types/host/workspace/remote.d.ts +85 -0
- package/lib/types/host/workspace/types.d.ts +28 -0
- package/lib/types/host/workspace-seam.d.ts +100 -0
- package/lib/types/index.d.ts +97 -0
- package/lib/types/mount-once.d.ts +55 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +89 -3
- package/src/client/PluginSettingsCard.tsx +838 -0
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +195 -0
- package/src/client/locales.ts +257 -0
- package/src/client/seat-props.ts +58 -0
- package/src/client/settings-card.module.css +821 -0
- package/src/client/settings-entry-form.ts +141 -0
- package/src/client/settings-form.ts +529 -0
- package/src/client/ssh/card-decoration.tsx +55 -0
- package/src/client/ssh/compose-section.tsx +147 -0
- package/src/client/ssh/detail-section.tsx +345 -0
- package/src/client/ssh/extension.ts +271 -0
- package/src/client/ssh/log-buffer.ts +224 -0
- package/src/client/ssh/log-view.tsx +149 -0
- package/src/client/ssh/model.ts +299 -0
- package/src/client/ssh/settings-section.tsx +401 -0
- package/src/client/ssh/summary.ts +388 -0
- package/src/client/ssh/target-form.tsx +380 -0
- package/src/client/ssh.module.css +617 -0
- package/src/core/action.ts +270 -0
- package/src/core/adapters/claude.ts +64 -0
- package/src/core/adapters/codex.ts +83 -0
- package/src/core/adapters/custom.ts +88 -0
- package/src/core/adapters/dsh.ts +87 -0
- package/src/core/adapters/index.ts +74 -0
- package/src/core/adapters/types.ts +95 -0
- package/src/core/contract.ts +510 -0
- package/src/core/launcher-script.ts +313 -0
- package/src/core/launcher.ts +283 -0
- package/src/core/ledger.ts +372 -0
- package/src/core/shell.ts +77 -0
- package/src/core/target.ts +413 -0
- package/src/core/task-record.ts +65 -0
- package/src/core/workspace.ts +78 -0
- package/src/host/board.ts +103 -0
- package/src/host/engine.ts +1602 -0
- package/src/host/extension.ts +304 -0
- package/src/host/logs.ts +297 -0
- package/src/host/payload.ts +134 -0
- package/src/host/prompt.ts +89 -0
- package/src/host/queue.ts +73 -0
- package/src/host/remote.ts +328 -0
- package/src/host/settings.ts +294 -0
- package/src/host/timers.ts +33 -0
- package/src/host/tools.ts +259 -0
- package/src/host/workspace/errors.ts +43 -0
- package/src/host/workspace/git.ts +305 -0
- package/src/host/workspace/in-place.ts +58 -0
- package/src/host/workspace/index.ts +37 -0
- package/src/host/workspace/layout.ts +122 -0
- package/src/host/workspace/local-git.ts +164 -0
- package/src/host/workspace/remote-git.ts +244 -0
- package/src/host/workspace/remote.ts +181 -0
- package/src/host/workspace/types.ts +34 -0
- package/src/host/workspace-seam.ts +132 -0
- package/src/index.ts +243 -0
- package/src/mount-once.ts +142 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The summary this provider's host half publishes, and the store the browser
|
|
3
|
+
* half renders it from.
|
|
4
|
+
*
|
|
5
|
+
* The host half calls the board capability face's `publish(summary)`; the board
|
|
6
|
+
* carries that document in its snapshot and hands it to every bookmarking
|
|
7
|
+
* client inside the mirror's `extensions` map. It is therefore the browser
|
|
8
|
+
* half's only host-to-client data channel besides the ledger payload on each
|
|
9
|
+
* card — the action channel returns a boolean, not a reply — so everything the
|
|
10
|
+
* seats need that is not a card fact travels here: the host list behind the
|
|
11
|
+
* target form's picker, the provider's defaults, and the byte windows of the
|
|
12
|
+
* log being read.
|
|
13
|
+
*
|
|
14
|
+
* Nothing here is trusted: every field is read defensively and an unknown shape
|
|
15
|
+
* reads as absent, exactly like the GitHub provider's summary reader.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-task-board-ssh/client/ssh/summary
|
|
18
|
+
*/
|
|
19
|
+
import { useSyncExternalStore } from 'react'
|
|
20
|
+
import { SSH_EXTENSION_ID } from '../../core/action.ts'
|
|
21
|
+
import type { SshAgentKind, SshExecutionMode, SshRunPhase, SshWorkspaceKind } from '../../core/target.ts'
|
|
22
|
+
|
|
23
|
+
/** One host as the provider publishes it: no secret, no ProxyCommand text. */
|
|
24
|
+
export interface SshSummaryHost {
|
|
25
|
+
/** Alias every remote operation addresses. */
|
|
26
|
+
alias: string
|
|
27
|
+
/** Hostname or IP. */
|
|
28
|
+
host: string
|
|
29
|
+
/** Login user. */
|
|
30
|
+
user: string
|
|
31
|
+
/** SSH port. */
|
|
32
|
+
port: number
|
|
33
|
+
/** Deployment label, when the host carries one. */
|
|
34
|
+
environment?: string
|
|
35
|
+
/** Free-form note, when the host carries one. */
|
|
36
|
+
description?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* One run's log increment.
|
|
41
|
+
*
|
|
42
|
+
* The provider reads the run's remote stdout file by byte offset and publishes
|
|
43
|
+
* what it read since the previous window: `[baseOffset, endOffset)` with the
|
|
44
|
+
* bytes themselves as `text`. A window that starts at zero is a replay from the
|
|
45
|
+
* first byte — the provider publishes one whenever a card's detail is opened —
|
|
46
|
+
* and a window that starts where the previous one ended is the running tail.
|
|
47
|
+
*/
|
|
48
|
+
export interface SshSummaryLogWindow {
|
|
49
|
+
/** Run these bytes belong to. */
|
|
50
|
+
runId: string
|
|
51
|
+
/** Byte offset of `text`'s first byte in the remote file. */
|
|
52
|
+
baseOffset: number
|
|
53
|
+
/** Byte offset just past `text`'s last byte. */
|
|
54
|
+
endOffset: number
|
|
55
|
+
/** The bytes themselves, verbatim. */
|
|
56
|
+
text: string
|
|
57
|
+
/** Legacy flag: whether bytes were skipped before `baseOffset` (or trailing bytes remain when `hasMore` is also set). */
|
|
58
|
+
truncated?: boolean
|
|
59
|
+
/** Explicit flag: whether more trailing bytes exist after `endOffset` on the remote host. */
|
|
60
|
+
hasMore?: boolean
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One registered local workspace exposed by the board mirror. */
|
|
64
|
+
export interface SshBoardWorkspaceOption {
|
|
65
|
+
workspaceId: string
|
|
66
|
+
title: string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Defaults the provider prefills a new target from. */
|
|
70
|
+
export interface SshSummaryDefaults {
|
|
71
|
+
/** Host alias a new target opens with. */
|
|
72
|
+
host?: string
|
|
73
|
+
/** Execution mode. */
|
|
74
|
+
mode?: SshExecutionMode
|
|
75
|
+
/** Agent CLI. */
|
|
76
|
+
agent?: SshAgentKind
|
|
77
|
+
/** Filesystem mechanism. */
|
|
78
|
+
workspace?: SshWorkspaceKind
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** One card's run, as the provider publishes its progress. */
|
|
82
|
+
export interface SshSummaryRun {
|
|
83
|
+
/** Card the run belongs to. */
|
|
84
|
+
taskId: string
|
|
85
|
+
/** Run identifier. */
|
|
86
|
+
runId: string
|
|
87
|
+
/** Phase the provider last recorded. */
|
|
88
|
+
phase: SshRunPhase
|
|
89
|
+
/** Host the run addresses. */
|
|
90
|
+
host: string
|
|
91
|
+
/** Bytes of the remote log the provider has read. */
|
|
92
|
+
bytes?: number
|
|
93
|
+
/**
|
|
94
|
+
* Files the run left untracked in the workspace it came back from.
|
|
95
|
+
*
|
|
96
|
+
* Present only when the placement strategy reported any: an absent count
|
|
97
|
+
* means nothing was left behind, which reads the same as no notice at all.
|
|
98
|
+
*/
|
|
99
|
+
untrackedFiles?: number
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The provider's read-only summary; every field is optional on the wire. */
|
|
103
|
+
export interface SshSummary {
|
|
104
|
+
/** Whether the host half currently runs its extension. */
|
|
105
|
+
enabled?: boolean
|
|
106
|
+
/** Configured hosts, in `dsh-ssh` store order. */
|
|
107
|
+
hosts?: SshSummaryHost[]
|
|
108
|
+
/** Prefill values for a new target. */
|
|
109
|
+
defaults?: SshSummaryDefaults
|
|
110
|
+
/** Per-host running cap, keyed by host alias. */
|
|
111
|
+
caps?: Record<string, number>
|
|
112
|
+
/** Log increments, keyed by task id. */
|
|
113
|
+
logs?: Record<string, SshSummaryLogWindow>
|
|
114
|
+
/** Runs in flight, one entry per card the provider follows. */
|
|
115
|
+
runs?: SshSummaryRun[]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Whether a value is a plain object (not an array, not null). */
|
|
119
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
120
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Read one bounded string field. */
|
|
124
|
+
function readText(value: unknown): string | undefined {
|
|
125
|
+
return typeof value === 'string' ? value : undefined
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Read the host list, dropping entries a picker cannot use. */
|
|
129
|
+
function decodeHosts(value: unknown): SshSummaryHost[] | undefined {
|
|
130
|
+
if (!Array.isArray(value)) return undefined
|
|
131
|
+
const hosts: SshSummaryHost[] = []
|
|
132
|
+
for (const entry of value) {
|
|
133
|
+
if (!isPlainObject(entry)) continue
|
|
134
|
+
const alias = readText(entry.alias)
|
|
135
|
+
const host = readText(entry.host)
|
|
136
|
+
const user = readText(entry.user)
|
|
137
|
+
if (alias === undefined || host === undefined || user === undefined) continue
|
|
138
|
+
const decoded: SshSummaryHost = { alias, host, user, port: typeof entry.port === 'number' ? entry.port : 22 }
|
|
139
|
+
const environment = readText(entry.environment)
|
|
140
|
+
const description = readText(entry.description)
|
|
141
|
+
if (environment !== undefined) decoded.environment = environment
|
|
142
|
+
if (description !== undefined) decoded.description = description
|
|
143
|
+
hosts.push(decoded)
|
|
144
|
+
}
|
|
145
|
+
return hosts
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Read the prefill defaults. */
|
|
149
|
+
function decodeDefaults(value: unknown): SshSummaryDefaults | undefined {
|
|
150
|
+
if (!isPlainObject(value)) return undefined
|
|
151
|
+
const defaults: SshSummaryDefaults = {}
|
|
152
|
+
if (typeof value.host === 'string' && value.host !== '') defaults.host = value.host
|
|
153
|
+
if (value.mode === 'direct' || value.mode === 'proxy') defaults.mode = value.mode
|
|
154
|
+
if (value.agent === 'dsh' || value.agent === 'claude' || value.agent === 'codex' || value.agent === 'custom') defaults.agent = value.agent
|
|
155
|
+
if (value.workspace === 'in-place' || value.workspace === 'git') defaults.workspace = value.workspace
|
|
156
|
+
return Object.keys(defaults).length === 0 ? undefined : defaults
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Read the per-host caps, keeping only finite positive numbers. */
|
|
160
|
+
function decodeCaps(value: unknown): Record<string, number> | undefined {
|
|
161
|
+
if (!isPlainObject(value)) return undefined
|
|
162
|
+
const caps: Record<string, number> = {}
|
|
163
|
+
for (const [alias, cap] of Object.entries(value)) {
|
|
164
|
+
if (typeof cap === 'number' && Number.isFinite(cap) && cap > 0) caps[alias] = Math.floor(cap)
|
|
165
|
+
}
|
|
166
|
+
return Object.keys(caps).length === 0 ? undefined : caps
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Read the log windows, keyed by card id. */
|
|
170
|
+
function decodeLogs(value: unknown): Record<string, SshSummaryLogWindow> | undefined {
|
|
171
|
+
if (!isPlainObject(value)) return undefined
|
|
172
|
+
const logs: Record<string, SshSummaryLogWindow> = {}
|
|
173
|
+
for (const [taskId, entry] of Object.entries(value)) {
|
|
174
|
+
if (!isPlainObject(entry)) continue
|
|
175
|
+
const runId = readText(entry.runId)
|
|
176
|
+
if (runId === undefined || typeof entry.text !== 'string') continue
|
|
177
|
+
if (typeof entry.baseOffset !== 'number' || typeof entry.endOffset !== 'number') continue
|
|
178
|
+
const window: SshSummaryLogWindow = {
|
|
179
|
+
runId,
|
|
180
|
+
baseOffset: entry.baseOffset,
|
|
181
|
+
endOffset: entry.endOffset,
|
|
182
|
+
text: entry.text,
|
|
183
|
+
}
|
|
184
|
+
if (entry.truncated === true) window.truncated = true
|
|
185
|
+
if (entry.hasMore === true) window.hasMore = true
|
|
186
|
+
logs[taskId] = window
|
|
187
|
+
}
|
|
188
|
+
return Object.keys(logs).length === 0 ? undefined : logs
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Read the published runs, dropping entries a card cannot address. */
|
|
192
|
+
function decodeRuns(value: unknown): SshSummaryRun[] | undefined {
|
|
193
|
+
if (!Array.isArray(value)) return undefined
|
|
194
|
+
const runs: SshSummaryRun[] = []
|
|
195
|
+
for (const entry of value) {
|
|
196
|
+
if (!isPlainObject(entry)) continue
|
|
197
|
+
const taskId = readText(entry.taskId)
|
|
198
|
+
const runId = readText(entry.runId)
|
|
199
|
+
const host = readText(entry.host)
|
|
200
|
+
const phase = entry.phase
|
|
201
|
+
if (taskId === undefined || runId === undefined || host === undefined) continue
|
|
202
|
+
if (phase !== 'queued' && phase !== 'running' && phase !== 'succeeded' && phase !== 'failed' && phase !== 'cancelled' && phase !== 'lost') continue
|
|
203
|
+
const run: SshSummaryRun = { taskId, runId, phase, host }
|
|
204
|
+
if (typeof entry.bytes === 'number' && Number.isFinite(entry.bytes)) run.bytes = entry.bytes
|
|
205
|
+
if (typeof entry.untrackedFiles === 'number' && Number.isFinite(entry.untrackedFiles) && entry.untrackedFiles > 0) {
|
|
206
|
+
run.untrackedFiles = entry.untrackedFiles
|
|
207
|
+
}
|
|
208
|
+
runs.push(run)
|
|
209
|
+
}
|
|
210
|
+
return runs.length === 0 ? undefined : runs
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Normalize whatever the board hands back; a foreign payload reads as absent.
|
|
215
|
+
* @param value - the mirror's entry for this extension.
|
|
216
|
+
* @returns the summary, or undefined when nothing usable is published.
|
|
217
|
+
*/
|
|
218
|
+
export function decodeSummary(value: unknown): SshSummary | undefined {
|
|
219
|
+
if (!isPlainObject(value)) return undefined
|
|
220
|
+
const summary: SshSummary = {}
|
|
221
|
+
if (typeof value.enabled === 'boolean') summary.enabled = value.enabled
|
|
222
|
+
const hosts = decodeHosts(value.hosts)
|
|
223
|
+
if (hosts !== undefined) summary.hosts = hosts
|
|
224
|
+
const defaults = decodeDefaults(value.defaults)
|
|
225
|
+
if (defaults !== undefined) summary.defaults = defaults
|
|
226
|
+
const caps = decodeCaps(value.caps)
|
|
227
|
+
if (caps !== undefined) summary.caps = caps
|
|
228
|
+
const logs = decodeLogs(value.logs)
|
|
229
|
+
if (logs !== undefined) summary.logs = logs
|
|
230
|
+
const runs = decodeRuns(value.runs)
|
|
231
|
+
if (runs !== undefined) summary.runs = runs
|
|
232
|
+
return summary
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* What the browser can tell about the provider's host half.
|
|
237
|
+
*
|
|
238
|
+
* The board carries a published summary only while the extension's host half is
|
|
239
|
+
* registered and running: the ssh row mounts its extension behind one dependency
|
|
240
|
+
* scope that needs both `taskBoard` and `dshSsh`, and its `start()` publishes
|
|
241
|
+
* before that registration returns. So a mirror frame WITHOUT the `ssh` key is
|
|
242
|
+
* positive evidence that nothing is mounted — the case a deployment hits when
|
|
243
|
+
* `dsh-ssh` ships disabled and this row therefore never registers. What follows
|
|
244
|
+
* is the opposite mistake: no frame has arrived yet, so nothing is known and
|
|
245
|
+
* nothing is claimed.
|
|
246
|
+
*/
|
|
247
|
+
export type SshHostHalfStatus =
|
|
248
|
+
/** No mirror frame has been observed yet: nothing is known, nothing is claimed. */
|
|
249
|
+
| 'unknown'
|
|
250
|
+
/** A frame has carried this extension's summary, now or earlier in this page. */
|
|
251
|
+
| 'mounted'
|
|
252
|
+
/** Frames have arrived and never carried it: the host half is not mounted. */
|
|
253
|
+
| 'unmounted'
|
|
254
|
+
|
|
255
|
+
let current: SshSummary | undefined
|
|
256
|
+
/** How many mirror frames this page has observed. */
|
|
257
|
+
let framesSeen = 0
|
|
258
|
+
/** Whether any observed frame carried this extension's summary. */
|
|
259
|
+
let publishedEver = false
|
|
260
|
+
/** Registered local workspaces published by the board client mirror. */
|
|
261
|
+
let boardWorkspaces: readonly SshBoardWorkspaceOption[] = []
|
|
262
|
+
/** Most recent board transport error (e.g. Host refusal on an extension action). */
|
|
263
|
+
let lastBoardError: string | undefined
|
|
264
|
+
const listeners = new Set<() => void>()
|
|
265
|
+
|
|
266
|
+
/** Notify every subscriber, isolating each one. */
|
|
267
|
+
function notify(): void {
|
|
268
|
+
for (const listener of [...listeners]) {
|
|
269
|
+
try {
|
|
270
|
+
listener()
|
|
271
|
+
} catch {
|
|
272
|
+
// A subscriber must never break the extension's own bookkeeping.
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Replace the stored summary; an unchanged value notifies nobody. */
|
|
278
|
+
function setSummary(next: SshSummary | undefined): void {
|
|
279
|
+
if (current === next) return
|
|
280
|
+
current = next
|
|
281
|
+
notify()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Read one client mirror frame: store this extension's summary and record
|
|
286
|
+
* whether the frame carried it at all.
|
|
287
|
+
*
|
|
288
|
+
* The presence of the key is the evidence, not the shape of its value: a
|
|
289
|
+
* registered provider publishes a summary even before it has anything to report,
|
|
290
|
+
* and an unregistered one publishes nothing at all.
|
|
291
|
+
* @param published - the mirror's `extensions` map.
|
|
292
|
+
*/
|
|
293
|
+
export function acceptPublishedSummary(published: Readonly<Record<string, unknown>>): void {
|
|
294
|
+
const before = getHostHalfStatus()
|
|
295
|
+
framesSeen += 1
|
|
296
|
+
if (Object.hasOwn(published, SSH_EXTENSION_ID)) publishedEver = true
|
|
297
|
+
setSummary(decodeSummary(published[SSH_EXTENSION_ID]))
|
|
298
|
+
// A frame can settle the mount question without changing the summary at all.
|
|
299
|
+
if (getHostHalfStatus() !== before) notify()
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Drop the summary (the board reports the extension is not running). */
|
|
303
|
+
export function clearSummary(): void {
|
|
304
|
+
setSummary(undefined)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Whether the provider's host half is mounted, as far as this page can tell.
|
|
309
|
+
* @returns the status; `unknown` until the first mirror frame arrives.
|
|
310
|
+
*/
|
|
311
|
+
export function getHostHalfStatus(): SshHostHalfStatus {
|
|
312
|
+
if (publishedEver) return 'mounted'
|
|
313
|
+
return framesSeen === 0 ? 'unknown' : 'unmounted'
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Forget everything about this page's mirror history: for a fresh mount and for
|
|
318
|
+
* a spec that models one.
|
|
319
|
+
*/
|
|
320
|
+
export function resetSummaryStore(): void {
|
|
321
|
+
current = undefined
|
|
322
|
+
framesSeen = 0
|
|
323
|
+
publishedEver = false
|
|
324
|
+
boardWorkspaces = []
|
|
325
|
+
lastBoardError = undefined
|
|
326
|
+
notify()
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Update supplemental board mirror context (local workspaces + last Host refusal). */
|
|
330
|
+
export function acceptBoardContext(context: {
|
|
331
|
+
workspaces?: readonly SshBoardWorkspaceOption[]
|
|
332
|
+
lastError?: string
|
|
333
|
+
}): void {
|
|
334
|
+
let changed = false
|
|
335
|
+
if (context.workspaces !== undefined) {
|
|
336
|
+
const prev = boardWorkspaces
|
|
337
|
+
const next = context.workspaces
|
|
338
|
+
if (prev.length !== next.length || prev.some((item, index) => item.workspaceId !== next[index]?.workspaceId || item.title !== next[index]?.title)) {
|
|
339
|
+
boardWorkspaces = next
|
|
340
|
+
changed = true
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (lastBoardError !== context.lastError) {
|
|
344
|
+
lastBoardError = context.lastError
|
|
345
|
+
}
|
|
346
|
+
if (changed) notify()
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Most recent Host transport/action refusal reported by the board mirror. */
|
|
350
|
+
export function getLastBoardError(): string | undefined {
|
|
351
|
+
return lastBoardError
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Registered local workspaces observed from the board mirror. */
|
|
355
|
+
export function getBoardWorkspaces(): readonly SshBoardWorkspaceOption[] {
|
|
356
|
+
return boardWorkspaces
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** Observe the registered local workspaces from a React component. */
|
|
360
|
+
export function useBoardWorkspaces(): readonly SshBoardWorkspaceOption[] {
|
|
361
|
+
return useSyncExternalStore(subscribe, getBoardWorkspaces, getBoardWorkspaces)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The current summary, or undefined while none is published. */
|
|
365
|
+
export function getSummary(): SshSummary | undefined {
|
|
366
|
+
return current
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function subscribe(listener: () => void): () => void {
|
|
370
|
+
listeners.add(listener)
|
|
371
|
+
return () => { listeners.delete(listener) }
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Observe the published summary from a React component.
|
|
376
|
+
* @returns the current summary, or undefined while none is published.
|
|
377
|
+
*/
|
|
378
|
+
export function usePublishedSummary(): SshSummary | undefined {
|
|
379
|
+
return useSyncExternalStore(subscribe, getSummary, getSummary)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Observe whether the provider's host half is mounted.
|
|
384
|
+
* @returns the status, re-rendering when the first frame settles it.
|
|
385
|
+
*/
|
|
386
|
+
export function useHostHalfStatus(): SshHostHalfStatus {
|
|
387
|
+
return useSyncExternalStore(subscribe, getHostHalfStatus, getHostHalfStatus)
|
|
388
|
+
}
|