Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat(ssh): 远端会话只读提示——SSH 中的实例引导回发起端配置

Menghuan19182a4062fabeca
diff --git a/packages/dsh-tauri-ssh-ui/src/client/components/machines-section.test.tsx b/packages/dsh-tauri-ssh-ui/src/client/components/machines-section.test.tsx
index a22cbdb7..48daa9df 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/components/machines-section.test.tsx
+++ b/packages/dsh-tauri-ssh-ui/src/client/components/machines-section.test.tsx
@@ -62,6 +62,21 @@ function mount(overrides: { envelope?: SshApiResponse, bridge?: RemoteBridge } =
}
describe('machinesSection', () => {
+ it('renders the read-only SSH-in-progress banner on a remote target and hides management', async () => {
+ const fetchFn = vi.fn<FetchFn>(async (_url, init) => {
+ const body = JSON.parse(String(init.body)) as { method: string }
+ if (body.method === 'session.role')
+ return { json: async () => ({ ok: true, value: { remote: true, origin: 'ops' } }) } as unknown as Response
+ return { json: async () => ({ ok: true, value: { items: [{ ...machineA, state: 'disconnected' }] } }) } as unknown as Response
+ })
+ render(<MachinesSection store={new MachinesStore(fetchFn)} t={t} />)
+ await waitFor(() => expect(screen.getByTestId('remote-session-banner')).toBeTruthy())
+ expect(screen.getByText('Currently in an SSH session')).toBeTruthy()
+ expect(screen.getByText(/over SSH from ops/)).toBeTruthy()
+ expect(screen.queryByText('Add machine')).toBeNull()
+ expect(screen.queryByTestId('machine-a')).toBeNull()
+ })
+
it('renders the loaded machine cards with statuses', async () => {
const { fetchFn } = mount({
envelope: { ok: true, value: { items: [{ ...machineA, state: 'connected', tunnelBaseUrl: 'http://127.0.0.1:49152' }] } },
diff --git a/packages/dsh-tauri-ssh-ui/src/client/components/machines-section.tsx b/packages/dsh-tauri-ssh-ui/src/client/components/machines-section.tsx
index 2433fb80..5f1af11a 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/components/machines-section.tsx
+++ b/packages/dsh-tauri-ssh-ui/src/client/components/machines-section.tsx
@@ -850,9 +850,13 @@ export function MachinesSection({ t, store, bridge }: MachinesSectionProps): Rea
<Button variant="outline" size="sm" disabled={state.status === 'loading'} onClick={() => void store.load()}>
{t('refresh')}
</Button>
- <Button variant="primary" size="sm" disabled={state.status === 'loading'} onClick={() => setAddOpen(true)}>
- {t('addMachine')}
- </Button>
+ {state.role?.remote === true
+ ? null
+ : (
+ <Button variant="primary" size="sm" disabled={state.status === 'loading'} onClick={() => setAddOpen(true)}>
+ {t('addMachine')}
+ </Button>
+ )}
</div>
</div>
{state.notice !== null ? <p className={cls.notice} data-testid="notice">{noticeTextOf(state.notice, t)}</p> : null}
@@ -876,127 +880,142 @@ export function MachinesSection({ t, store, bridge }: MachinesSectionProps): Rea
{state.status === 'ready' && state.machines.length === 0 && state.discovered.length === 0
? <p className={cls.empty}>{t('empty')}</p>
: null}
- <ul className={cls.rows}>
- {state.machines.map((row) => {
- const draft = drafts[row.id] ?? { key: row.id, row }
- return (
- <RowShell
- key={row.id}
- id={row.id}
- name={row.name === '' ? row.id : row.name}
- tag={row.host}
- tintColor={colorOf(row)}
- tintBorder={row.tintBorder === true}
- status={state.statuses[row.id]}
- trail={state.trails[row.id] ?? []}
- t={t}
- actions={(
- <RowActions
- id={row.id}
- t={t}
- status={state.statuses[row.id]}
- busy={state.busy[row.id]}
- bridgeOpen={bridgeOpen}
- bridgePending={bridgePending}
- opening={openingId === row.id}
- onTest={id => void store.test(id)}
- onConnect={id => void store.connect(id)}
- onDisconnect={id => void store.disconnect(id)}
- onOpen={openRemoteWindow}
- extras={(
- <>
- <Button variant="outline" size="sm" disabled={editingId !== null && editingId !== row.id} onClick={() => editingId === row.id ? closeEditor(row.id) : openEditor(row)}>
- {t('edit')}
- </Button>
- <Button variant="ghost" size="sm" className={cls.dangerAction} disabled={state.busy[row.id] !== undefined} onClick={() => setRemoveTarget({ key: row.id, id: row.id, name: row.name === '' ? row.id : row.name })}>
- {t('remove')}
- </Button>
- </>
- )}
- />
- )}
- >
- {editingId === row.id
- ? (
- <EditPanel
- draft={draft}
- t={t}
- secretSet={secretFlagsOf(row)}
- dirty={dirty[row.id] ?? {}}
- saving={savingId === row.id}
- onChange={patchDraft}
- onSecret={patchDirty}
- onSave={key => void saveRow(key)}
- onCancel={closeEditor}
- />
- )
- : null}
- <RowDetails
- id={row.id}
- status={state.statuses[row.id]}
- busy={state.busy[row.id]}
- logLines={state.logs[row.id] ?? []}
- bridgeError={bridgeErrors[row.id]}
- installResult={state.installResults[row.id]}
- t={t}
- onInstall={id => void store.install(id)}
- />
- </RowShell>
- )
- })}
- </ul>
- {state.discovered.length > 0
+ {state.role?.remote === true
? (
+ <div className={cls.emptyBlock} data-testid="remote-session-banner">
+ <p className={cls.empty}>{t('session.remoteTitle')}</p>
+ <p className={cls.hint}>
+ {state.role.origin !== undefined && state.role.origin !== ''
+ ? t('session.remoteHintNamed').replace('{name}', state.role.origin)
+ : t('session.remoteHint')}
+ </p>
+ </div>
+ )
+ : (
<>
- <div className={cls.group}>
- <h3 className={cls.groupTitle}>{t('configHosts')}</h3>
- <p className={cls.groupHint}>{t('configHostsHint')}</p>
- </div>
<ul className={cls.rows}>
- {state.discovered.map(row => (
- <RowShell
- key={row.id}
- id={row.id}
- name={row.name}
- tag={t('configTag')}
- tintColor={undefined}
- tintBorder={false}
- status={state.statuses[row.id]}
- trail={state.trails[row.id] ?? []}
- t={t}
- actions={(
- <RowActions
+ {state.machines.map((row) => {
+ const draft = drafts[row.id] ?? { key: row.id, row }
+ return (
+ <RowShell
+ key={row.id}
+ id={row.id}
+ name={row.name === '' ? row.id : row.name}
+ tag={row.host}
+ tintColor={colorOf(row)}
+ tintBorder={row.tintBorder === true}
+ status={state.statuses[row.id]}
+ trail={state.trails[row.id] ?? []}
+ t={t}
+ actions={(
+ <RowActions
+ id={row.id}
+ t={t}
+ status={state.statuses[row.id]}
+ busy={state.busy[row.id]}
+ bridgeOpen={bridgeOpen}
+ bridgePending={bridgePending}
+ opening={openingId === row.id}
+ onTest={id => void store.test(id)}
+ onConnect={id => void store.connect(id)}
+ onDisconnect={id => void store.disconnect(id)}
+ onOpen={openRemoteWindow}
+ extras={(
+ <>
+ <Button variant="outline" size="sm" disabled={editingId !== null && editingId !== row.id} onClick={() => editingId === row.id ? closeEditor(row.id) : openEditor(row)}>
+ {t('edit')}
+ </Button>
+ <Button variant="ghost" size="sm" className={cls.dangerAction} disabled={state.busy[row.id] !== undefined} onClick={() => setRemoveTarget({ key: row.id, id: row.id, name: row.name === '' ? row.id : row.name })}>
+ {t('remove')}
+ </Button>
+ </>
+ )}
+ />
+ )}
+ >
+ {editingId === row.id
+ ? (
+ <EditPanel
+ draft={draft}
+ t={t}
+ secretSet={secretFlagsOf(row)}
+ dirty={dirty[row.id] ?? {}}
+ saving={savingId === row.id}
+ onChange={patchDraft}
+ onSecret={patchDirty}
+ onSave={key => void saveRow(key)}
+ onCancel={closeEditor}
+ />
+ )
+ : null}
+ <RowDetails
id={row.id}
- t={t}
status={state.statuses[row.id]}
busy={state.busy[row.id]}
- bridgeOpen={bridgeOpen}
- bridgePending={bridgePending}
- opening={openingId === row.id}
- onTest={id => void store.test(id)}
- onConnect={id => void store.connect(id)}
- onDisconnect={id => void store.disconnect(id)}
- onOpen={openRemoteWindow}
+ logLines={state.logs[row.id] ?? []}
+ bridgeError={bridgeErrors[row.id]}
+ installResult={state.installResults[row.id]}
+ t={t}
+ onInstall={id => void store.install(id)}
/>
- )}
- >
- <RowDetails
- id={row.id}
- status={state.statuses[row.id]}
- busy={state.busy[row.id]}
- logLines={state.logs[row.id] ?? []}
- bridgeError={bridgeErrors[row.id]}
- installResult={state.installResults[row.id]}
- t={t}
- onInstall={id => void store.install(id)}
- />
- </RowShell>
- ))}
+ </RowShell>
+ )
+ })}
</ul>
+ {state.discovered.length > 0
+ ? (
+ <>
+ <div className={cls.group}>
+ <h3 className={cls.groupTitle}>{t('configHosts')}</h3>
+ <p className={cls.groupHint}>{t('configHostsHint')}</p>
+ </div>
+ <ul className={cls.rows}>
+ {state.discovered.map(row => (
+ <RowShell
+ key={row.id}
+ id={row.id}
+ name={row.name}
+ tag={t('configTag')}
+ tintColor={undefined}
+ tintBorder={false}
+ status={state.statuses[row.id]}
+ trail={state.trails[row.id] ?? []}
+ t={t}
+ actions={(
+ <RowActions
+ id={row.id}
+ t={t}
+ status={state.statuses[row.id]}
+ busy={state.busy[row.id]}
+ bridgeOpen={bridgeOpen}
+ bridgePending={bridgePending}
+ opening={openingId === row.id}
+ onTest={id => void store.test(id)}
+ onConnect={id => void store.connect(id)}
+ onDisconnect={id => void store.disconnect(id)}
+ onOpen={openRemoteWindow}
+ />
+ )}
+ >
+ <RowDetails
+ id={row.id}
+ status={state.statuses[row.id]}
+ busy={state.busy[row.id]}
+ logLines={state.logs[row.id] ?? []}
+ bridgeError={bridgeErrors[row.id]}
+ installResult={state.installResults[row.id]}
+ t={t}
+ onInstall={id => void store.install(id)}
+ />
+ </RowShell>
+ ))}
+ </ul>
+ </>
+ )
+ : null}
+ <SyncPanel store={store} t={t} />
</>
- )
- : null}
- <SyncPanel store={store} t={t} />
+ )}
{addOpen
? (
<AddMachineDialog
diff --git a/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts b/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts
index 57107504..2812407c 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts
+++ b/packages/dsh-tauri-ssh-ui/src/client/locales/index.ts
@@ -31,6 +31,9 @@ export const zh = {
'field.host': '主机(或 config 别名)',
'field.port': '端口',
'field.user': '用户(可选)',
+ 'session.remoteTitle': '目前正在 SSH 中',
+ 'session.remoteHintNamed': '此实例正通过 SSH 来自 {name} 的连接使用——机器管理请在发起 SSH 连接的机器上配置。',
+ 'session.remoteHint': '此实例正通过 SSH 远程连接使用——机器管理请在发起 SSH 连接的机器上配置。',
'field.remotePort': '远端端口',
'field.profileName': '远端档案(默认 remote)',
'field.startCommand': '启动命令(可选)',
@@ -131,6 +134,9 @@ export const en = {
'field.host': 'Host or config alias',
'field.port': 'Port',
'field.user': 'User (optional)',
+ 'session.remoteTitle': 'Currently in an SSH session',
+ 'session.remoteHintNamed': 'This instance is in use over SSH from {name} — manage machines on the machine that initiated the SSH connection.',
+ 'session.remoteHint': 'This instance is in use over SSH — manage machines on the machine that initiated the SSH connection.',
'field.remotePort': 'Remote port',
'field.profileName': 'Remote profile (default remote)',
'field.startCommand': 'Start command (optional)',
diff --git a/packages/dsh-tauri-ssh-ui/src/client/store/index.test.ts b/packages/dsh-tauri-ssh-ui/src/client/store/index.test.ts
index 5b984596..496937b9 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/store/index.test.ts
+++ b/packages/dsh-tauri-ssh-ui/src/client/store/index.test.ts
@@ -214,7 +214,7 @@ describe('machinesStore', () => {
)
const calls = fetchFn.mock.calls
.map(call => JSON.parse(String(call[1]?.body)) as { method: string, payload: Record<string, unknown> })
- .filter(call => call.method !== 'machine.list')
+ .filter(call => call.method !== 'machine.list' && call.method !== 'session.role')
expect(calls).toHaveLength(2)
expect(calls[0]).toMatchObject({
method: 'machine.save',
@@ -241,7 +241,7 @@ describe('machinesStore', () => {
await store.persist([machineA], {})
const calls = fetchFn.mock.calls
.map(call => JSON.parse(String(call[1]?.body)) as { method: string, payload: Record<string, unknown> })
- .filter(call => call.method !== 'machine.list')
+ .filter(call => call.method !== 'machine.list' && call.method !== 'session.role')
expect(calls).toHaveLength(1)
expect(calls[0]).toMatchObject({ method: 'machine.save', payload: { machineId: 'a' } })
})
@@ -263,8 +263,10 @@ describe('machinesStore', () => {
const state = store.getSnapshot()
expect(state.notice).toEqual({ kind: 'text', text: 'Linux alpha' })
expect(state.busy).toEqual({})
- const [, init] = fetchFn.mock.calls[1] as [string, RequestInit]
- expect(JSON.parse(String(init.body))).toEqual({ method: 'machine.test', payload: { machineId: 'a' } })
+ const testCall = fetchFn.mock.calls
+ .map(call => JSON.parse(String(call[1]?.body)) as { method: string, payload?: Record<string, unknown> })
+ .find(call => call.method === 'machine.test')
+ expect(testCall).toEqual({ method: 'machine.test', payload: { machineId: 'a' } })
})
it('falls back to defaults when a probe omits banner or message', async () => {
diff --git a/packages/dsh-tauri-ssh-ui/src/client/store/index.ts b/packages/dsh-tauri-ssh-ui/src/client/store/index.ts
index 974e8f6a..0302dd7c 100644
--- a/packages/dsh-tauri-ssh-ui/src/client/store/index.ts
+++ b/packages/dsh-tauri-ssh-ui/src/client/store/index.ts
@@ -115,6 +115,8 @@ export interface MachinesPageState {
installResults: Record<string, InstallResult>
/** The sync-to-remote panel state. */
sync: SyncPanelState
+ /** This instance's session role (a remote target renders the read-only banner). */
+ role: { remote: boolean, origin?: string } | null
}
/** The fetch seam (window.fetch in the browser, fakes in tests). */
@@ -375,6 +377,7 @@ export class MachinesStore {
notice: null,
installResults: {},
sync: { status: 'idle', error: null, preview: null, applying: false, results: null },
+ role: null,
})
}
@@ -452,6 +455,8 @@ export class MachinesStore {
state.error = null
})
try {
+ if (this.store.getSnapshot().role === null)
+ void this.loadRole()
this.applyList(await this.callApi<{ items?: MachineListItem[], discovered?: MachineListItem[] }>('machine.list', {}))
}
catch (error) {
@@ -462,6 +467,19 @@ export class MachinesStore {
}
}
+ /** Load this instance's session role once (old hosts without the method keep null). */
+ async loadRole(): Promise<void> {
+ try {
+ const role = await this.callApi<{ remote: boolean, origin?: string }>('session.role', {})
+ this.store.update((state) => {
+ state.role = role.remote === true ? { remote: true, ...role.origin === undefined || role.origin === '' ? {} : { origin: role.origin } } : { remote: false }
+ })
+ }
+ catch {
+ // Older hosts lack session.role; the banner simply stays hidden.
+ }
+ }
+
/** Silent refresh: same payload as load(), but never flips the loading banner. */
async poll(): Promise<void> {
try {
diff --git a/packages/dsh-tauri-ssh/src/host/apply.ts b/packages/dsh-tauri-ssh/src/host/apply.ts
index 3821b8d3..f0ff98c1 100644
--- a/packages/dsh-tauri-ssh/src/host/apply.ts
+++ b/packages/dsh-tauri-ssh/src/host/apply.ts
@@ -184,6 +184,14 @@ export class SshRemoteService implements SshApiHost {
return [...this.manualProfiles().values()].map(profileView)
}
+ /** This instance's session role: a remote target (with its origin name) or a local host. */
+ sessionRole(): { remote: boolean, origin?: string } {
+ const origin = process.env.DSH_REMOTE_SESSION_ORIGIN
+ return origin === undefined || origin === ''
+ ? { remote: false }
+ : { remote: true, origin }
+ }
+
/** Redacted views of the discovered `~/.ssh/config` aliases (read-only). */
async discoveredViews(): Promise<MachineView[]> {
const manual = this.manualProfiles()
diff --git a/packages/dsh-tauri-ssh/src/host/routes/index.test.ts b/packages/dsh-tauri-ssh/src/host/routes/index.test.ts
index 0f492e37..a8fed0c2 100644
--- a/packages/dsh-tauri-ssh/src/host/routes/index.test.ts
+++ b/packages/dsh-tauri-ssh/src/host/routes/index.test.ts
@@ -27,6 +27,7 @@ log.append(MachineId('m1'), 'ready', '远端实例已就绪', { terminal: 'succe
function fakeHost(overrides: Partial<SshApiHost> = {}): SshApiHost {
return {
+ sessionRole: () => ({ remote: false }),
profileViews: () => [view],
discoveredViews: async () => [],
status: () => ({ machineId: MachineId('m1'), state: 'disconnected' }),
@@ -139,6 +140,13 @@ describe('/api-ssh handler', () => {
expect(missing.body).toMatchObject({ ok: false, error: { code: 'bad-request' } })
})
+ it('answers session.role from the host', async () => {
+ const plain = await call(fakeHost(), JSON.stringify({ method: 'session.role' }))
+ expect(plain.body).toEqual({ ok: true, value: { remote: false } })
+ const remote = await call(fakeHost({ sessionRole: () => ({ remote: true, origin: 'ops' }) }), JSON.stringify({ method: 'session.role' }))
+ expect(remote.body).toEqual({ ok: true, value: { remote: true, origin: 'ops' } })
+ })
+
it('lists machines with live status', async () => {
const host = fakeHost({
status: () => ({ machineId: MachineId('m1'), state: 'connected', tunnelBaseUrl: 'http://127.0.0.1:1', lastError: 'boom' }),
diff --git a/packages/dsh-tauri-ssh/src/host/routes/index.ts b/packages/dsh-tauri-ssh/src/host/routes/index.ts
index 1476861a..7a30f146 100644
--- a/packages/dsh-tauri-ssh/src/host/routes/index.ts
+++ b/packages/dsh-tauri-ssh/src/host/routes/index.ts
@@ -46,6 +46,7 @@ export type SshApiMethod
| 'machine.events'
| 'machine.save'
| 'machine.remove'
+ | 'session.role'
| 'sync.preview'
| 'sync.apply'
@@ -63,6 +64,8 @@ export interface SshMachineListItem extends MachineView {
/** The manager face this API needs (the plugin's service). */
export interface SshApiHost {
+ /** Whether this host instance is itself a remote target of an SSH session. */
+ sessionRole: () => { remote: boolean, origin?: string }
profileViews: () => MachineView[]
/** The read-only `~/.ssh/config` alias machines (awaits the config read). */
discoveredViews: () => Promise<MachineView[]>
@@ -182,6 +185,10 @@ export function createSshApiHandler(host: SshApiHost): (req: IncomingMessage, re
const payload = (request.payload ?? {}) as Record<string, unknown>
try {
switch (request.method as SshApiMethod) {
+ case 'session.role': {
+ respond(200, { ok: true, value: host.sessionRole() })
+ return
+ }
case 'machine.list': {
const items: SshMachineListItem[] = host.profileViews().map(view => listItemOf(host, view))
const discovered: SshMachineListItem[] = (await host.discoveredViews()).map(view => listItemOf(host, view))
diff --git a/packages/dsh-tauri-ssh/src/host/service/bootstrap.ts b/packages/dsh-tauri-ssh/src/host/service/bootstrap.ts
index cbf283b2..03aca232 100644
--- a/packages/dsh-tauri-ssh/src/host/service/bootstrap.ts
+++ b/packages/dsh-tauri-ssh/src/host/service/bootstrap.ts
@@ -566,6 +566,7 @@ export function startCommandFor(profile: MachineProfile, plan?: RemoteInstallPla
`mkdir -p "$LOG_DIR"`,
`export PATH="$ROOT/runtime/bin:$PATH"`,
`export DSH_TELEMETRY_DISABLED=1 NO_COLOR=1 DSH_WEB_PORT=${profile.remotePort}`,
+ `export DSH_REMOTE_SESSION_ORIGIN=${shQuote(profile.name)}`,
`( sh -c 'echo $$ > "$1/.dsh-remote.pid"; exec "$2" "$3" --profile "$5" web --host 127.0.0.1 --port "$4" --no-open' dsh-remote "$LOG_DIR" "$NODE" "$DSH_BIN" ${profile.remotePort} ${profileName} </dev/null >>"$LOG" 2>&1 & )`,
`echo "远端实例已拉起(档案: ${profileName}, 日志: $LOG)"`,
].join('\n')