@linxin666/dsh-ssh 0.4.22 → 0.4.23

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.
@@ -21,13 +21,19 @@
21
21
  * @module @linxin666/dsh-client-ssh/client
22
22
  */
23
23
  import type { Context as ClientContext } from '@deepseek-ai/cordis'
24
- import type {} from '@deepseek-ai/dsh-client-ui-slots'
24
+ import type {} from '@deepseek-ai/dsh-client-ui-slots/client'
25
25
  import type {} from '@deepseek-ai/dsh-client-ui-layout/client'
26
26
  import type {} from '@deepseek-ai/dsh-client-ui-sidebar/client'
27
27
  import type { SshApi } from './api.ts'
28
28
  import { SSH_PANEL_ID, type PanelController } from './panel/controller.ts'
29
29
  import { tt, type TerminalFontSource } from './panel/helpers.ts'
30
30
  import { SshPanel } from './panel/SshPanel.tsx'
31
+ import {
32
+ DIRECTORY_BROWSER_DIALOG_FACTORY,
33
+ hasDirectoryBrowserFactory,
34
+ type DirectoryDialogRenderProps,
35
+ type RenderFactorySlotFn,
36
+ } from './panel/directory-dialog.ts'
31
37
  import css from './panel/panel.module.css'
32
38
 
33
39
  /** The panel id shared by the sidebar row and the main-slot occupant. */
@@ -76,14 +82,35 @@ export function SshPanelIcon({ size }: { size: number; active: boolean }): React
76
82
  * @param props - the framework main-slot share plus this entry's injected face.
77
83
  * @returns the SSH panel page.
78
84
  */
79
- export function SshPanelPage({ controller, api, terminalFont }: {
85
+ export function SshPanelPage({ controller, api, terminalFont, renderFactorySlot, hasDirectoryDialog }: {
80
86
  controller: PanelController
81
87
  api: SshApi
82
88
  terminalFont?: TerminalFontSource
89
+ renderFactorySlot?: RenderFactorySlotFn
90
+ hasDirectoryDialog?: () => boolean
83
91
  }): React.ReactElement {
92
+ const canRenderDialog = renderFactorySlot !== undefined && (hasDirectoryDialog === undefined || hasDirectoryDialog())
93
+ const renderDirectoryDialog = canRenderDialog
94
+ ? (dialogProps: DirectoryDialogRenderProps) => renderFactorySlot!(
95
+ DIRECTORY_BROWSER_DIALOG_FACTORY,
96
+ {
97
+ open: dialogProps.open,
98
+ busy: dialogProps.busy,
99
+ listDirectory: dialogProps.listDirectory,
100
+ onOpen: dialogProps.onOpen,
101
+ onClose: dialogProps.onClose,
102
+ },
103
+ { fallback: null },
104
+ )
105
+ : undefined
84
106
  return (
85
107
  <div className={css.view} data-dsh-ssh-view="" data-dsh-plugin="ssh">
86
- <SshPanel controller={controller} api={api} terminalFont={terminalFont} />
108
+ <SshPanel
109
+ controller={controller}
110
+ api={api}
111
+ terminalFont={terminalFont}
112
+ renderDirectoryDialog={renderDirectoryDialog}
113
+ />
87
114
  </div>
88
115
  )
89
116
  }
@@ -93,6 +120,7 @@ interface PanelFace {
93
120
  controller: PanelController
94
121
  api: SshApi
95
122
  terminalFont?: TerminalFontSource
123
+ hasDirectoryDialog: () => boolean
96
124
  }
97
125
 
98
126
  /**
@@ -132,7 +160,12 @@ export function registerSshPanel(
132
160
  disposers.push(slots.inject('main', () => slots.register({
133
161
  name: 'main',
134
162
  key: SSH_PANEL_ID,
135
- inject: (): PanelFace => ({ controller, api, terminalFont }),
163
+ inject: (): PanelFace => ({
164
+ controller,
165
+ api,
166
+ terminalFont,
167
+ hasDirectoryDialog: () => hasDirectoryBrowserFactory(slots),
168
+ }),
136
169
  }, SshPanelPage as never)))
137
170
 
138
171
  return () => {
@@ -18,6 +18,7 @@ import { KeysTab } from './KeysTab.tsx'
18
18
  import { TerminalTab } from './TerminalTab.tsx'
19
19
  import { TransferTab } from './TransferTab.tsx'
20
20
  import { TunnelsTab } from './TunnelsTab.tsx'
21
+ import type { RenderDirectoryDialog } from './directory-dialog.ts'
21
22
  import css from './panel.module.css'
22
23
 
23
24
  /** Panel shell props. */
@@ -28,6 +29,8 @@ export interface SshPanelProps {
28
29
  api: SshApi
29
30
  /** Live terminal-font setting source handed to the terminal tab (issue #577). */
30
31
  terminalFont?: TerminalFontSource
32
+ /** Optional shell `directory.browser.dialog` factory renderer for remote folder picks. */
33
+ renderDirectoryDialog?: RenderDirectoryDialog
31
34
  }
32
35
 
33
36
  /** The tab bar definition (labels resolved at render time). */
@@ -41,7 +44,7 @@ const TABS: ReadonlyArray<{ id: SshTab; label: () => string }> = [
41
44
  ]
42
45
 
43
46
  /** The tabbed SSH panel. */
44
- export function SshPanel({ controller, api, terminalFont }: SshPanelProps) {
47
+ export function SshPanel({ controller, api, terminalFont, renderDirectoryDialog }: SshPanelProps) {
45
48
  const { panelOpen, activeTab } = useSyncExternalStore(
46
49
  useCallback(listener => controller.subscribe(listener), [controller]),
47
50
  useCallback(() => controller.getSnapshot(), [controller]),
@@ -76,8 +79,10 @@ export function SshPanel({ controller, api, terminalFont }: SshPanelProps) {
76
79
  {activeTab === 'terminal' && (
77
80
  <TerminalTab api={api} controller={controller} terminalFont={terminalFont} />
78
81
  )}
79
- {activeTab === 'transfer' && <TransferTab api={api} />}
80
- {activeTab === 'tunnels' && <TunnelsTab api={api} active={panelOpen} />}
82
+ {activeTab === 'transfer' && <TransferTab api={api} renderDirectoryDialog={renderDirectoryDialog} />}
83
+ {activeTab === 'tunnels' && (
84
+ <TunnelsTab api={api} active={panelOpen} onTunnelsChange={list => { controller.setActiveTunnels(list) }} />
85
+ )}
81
86
  {activeTab === 'cluster' && <ClusterTab api={api} />}
82
87
  </div>
83
88
  </div>
@@ -7,11 +7,19 @@ import { useEffect, useRef, useState, type ChangeEvent } from 'react'
7
7
  import type { SshApi } from '../api.ts'
8
8
  import type { RemoteDirEntry, SshHostSummary, TransferProgress } from '../../protocol.ts'
9
9
  import { errorMessage, tt } from './helpers.ts'
10
+ import {
11
+ formatRemoteDirectoryPath,
12
+ normalizeRemoteDirPath,
13
+ remoteEntriesToDirectoryListing,
14
+ type RenderDirectoryDialog,
15
+ } from './directory-dialog.ts'
10
16
  import css from './panel.module.css'
11
17
 
12
18
  /** Transfer tab props. */
13
19
  export interface TransferTabProps {
14
20
  api: SshApi
21
+ /** Optional shell `directory.browser.dialog` factory renderer for remote folder picks. */
22
+ renderDirectoryDialog?: RenderDirectoryDialog
15
23
  }
16
24
 
17
25
  /** One in-flight transfer (drives the progress bar). */
@@ -49,12 +57,13 @@ function formatBytes(bytes: number): string {
49
57
  }
50
58
 
51
59
  /** The upload/download tab. */
52
- export function TransferTab({ api }: TransferTabProps) {
60
+ export function TransferTab({ api, renderDirectoryDialog }: TransferTabProps) {
53
61
  const [hosts, setHosts] = useState<SshHostSummary[]>([])
54
62
  const [listError, setListError] = useState<string | null>(null)
55
63
  const [alias, setAlias] = useState('')
56
64
  const [remotePath, setRemotePath] = useState('')
57
65
  const [browseOpen, setBrowseOpen] = useState(false)
66
+ const [dialogOpen, setDialogOpen] = useState(false)
58
67
  const [browseDir, setBrowseDir] = useState('/')
59
68
  const [entries, setEntries] = useState<RemoteDirEntry[]>([])
60
69
  const [browsing, setBrowsing] = useState(false)
@@ -174,6 +183,9 @@ export function TransferTab({ api }: TransferTabProps) {
174
183
  </select>
175
184
  <input className={css.input} placeholder={tt('transfer.remotePathHint')} value={remotePath} onChange={event => { setRemotePath(event.target.value) }} />
176
185
  <button type="button" className={css.ghostButton} disabled={alias === ''} onClick={openBrowse}>{tt('transfer.browseRemote')}</button>
186
+ {renderDirectoryDialog !== undefined && (
187
+ <button type="button" className={css.ghostButton} disabled={alias === ''} onClick={() => { setDialogOpen(true) }}>{tt('transfer.pickDirectory')}</button>
188
+ )}
177
189
  <div className={css.toolbarSpacer} />
178
190
  <button type="button" className={css.primaryButton} disabled={!ready} onClick={() => { fileRef.current?.click() }}>{tt('transfer.upload')}</button>
179
191
  <button type="button" className={css.ghostButton} disabled={!ready} onClick={() => { void handleDownload() }}>{tt('transfer.download')}</button>
@@ -222,6 +234,20 @@ export function TransferTab({ api }: TransferTabProps) {
222
234
  </div>
223
235
  </div>
224
236
  )}
237
+ {dialogOpen && alias !== '' && renderDirectoryDialog !== undefined && renderDirectoryDialog({
238
+ open: true,
239
+ busy: transfer !== null,
240
+ listDirectory: async (path) => {
241
+ const target = path === undefined ? normalizeRemoteDirPath(remotePath) : normalizeRemoteDirPath(path)
242
+ const list = await api.ls(alias, target)
243
+ return remoteEntriesToDirectoryListing(target, list)
244
+ },
245
+ onOpen: (picked) => {
246
+ setRemotePath(formatRemoteDirectoryPath(picked))
247
+ setDialogOpen(false)
248
+ },
249
+ onClose: () => { setDialogOpen(false) },
250
+ })}
225
251
  {status !== null && (
226
252
  <div className={css.banner} data-kind={status.kind}>
227
253
  {status.kind === 'ok' ? tt('transfer.done', { bytes: status.bytes }) : tt('transfer.failed', { error: status.error })}
@@ -39,10 +39,12 @@ export interface TunnelsTabProps {
39
39
  api: SshApi
40
40
  /** Pause automatic reads while the owning panel is closed, preserving form state. */
41
41
  active?: boolean
42
+ /** Optional listener mirroring refreshed tunnel state back to PanelController. */
43
+ onTunnelsChange?: (tunnels: readonly TunnelInfo[]) => void
42
44
  }
43
45
 
44
46
  /** The tunnels tab. */
45
- export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
47
+ export function TunnelsTab({ api, active = true, onTunnelsChange }: TunnelsTabProps) {
46
48
  const [hosts, setHosts] = useState<SshHostSummary[]>([])
47
49
  const [tunnels, setTunnels] = useState<TunnelInfo[] | null>(null)
48
50
  const [error, setError] = useState<string | null>(null)
@@ -73,6 +75,8 @@ export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
73
75
  // previous state reference (no wasted re-render).
74
76
  const seqRef = useRef(0)
75
77
  const mountedRef = useRef(true)
78
+ const onTunnelsChangeRef = useRef(onTunnelsChange)
79
+ onTunnelsChangeRef.current = onTunnelsChange
76
80
  useEffect(() => {
77
81
  mountedRef.current = true
78
82
  return () => { mountedRef.current = false }
@@ -91,6 +95,7 @@ export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
91
95
  const list = await api.listTunnels()
92
96
  if (disposed || seq !== seqRef.current) return
93
97
  setTunnels(prev => diffTunnels(prev, list) ?? prev)
98
+ onTunnelsChangeRef.current?.(list)
94
99
  setError(null)
95
100
  } catch (cause) {
96
101
  if (disposed || seq !== seqRef.current) return
@@ -139,6 +144,7 @@ export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
139
144
  const list = await api.listTunnels()
140
145
  if (!mountedRef.current || seq !== seqRef.current) return
141
146
  setTunnels(list)
147
+ onTunnelsChangeRef.current?.(list)
142
148
  if (!preserveError) setError(null)
143
149
  } catch (cause) {
144
150
  if (!mountedRef.current || seq !== seqRef.current) return
@@ -21,6 +21,7 @@
21
21
  */
22
22
 
23
23
  import type { TerminalConnection } from '../api.ts'
24
+ import type { TunnelInfo } from '../../protocol.ts'
24
25
 
25
26
  /** The panel's tab identifiers. */
26
27
  export type SshTab = 'hosts' | 'keys' | 'terminal' | 'transfer' | 'tunnels' | 'cluster'
@@ -173,6 +174,7 @@ export class PanelController {
173
174
  private terminalTabs: readonly TerminalTabRecord[] = []
174
175
  private activeTerminalTabId: string | undefined
175
176
  private draftAlias = ''
177
+ private activeTunnels: readonly TunnelInfo[] = []
176
178
  private nextTerminalTabSeq = 0
177
179
  private listeners = new Set<() => void>()
178
180
  /**
@@ -202,6 +204,25 @@ export class PanelController {
202
204
  return this.snapshot
203
205
  }
204
206
 
207
+ /** Latest host tunnel list mirrored by the Tunnels tab (kept outside PanelControllerSnapshot). */
208
+ getActiveTunnels(): readonly TunnelInfo[] {
209
+ return this.activeTunnels
210
+ }
211
+
212
+ /** Mirror the latest host tunnel list so subscribers such as sessionActivities stay current. */
213
+ setActiveTunnels(tunnels: readonly TunnelInfo[]): void {
214
+ if (
215
+ this.activeTunnels.length === tunnels.length
216
+ && this.activeTunnels.every((item, index) =>
217
+ item.id === tunnels[index]?.id && item.state === tunnels[index]?.state,
218
+ )
219
+ ) {
220
+ return
221
+ }
222
+ this.activeTunnels = [...tunnels]
223
+ for (const fn of [...this.listeners]) fn()
224
+ }
225
+
205
226
  subscribe(fn: () => void): () => void {
206
227
  this.listeners.add(fn)
207
228
  return () => { this.listeners.delete(fn) }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Adapter bridging `dsh-ssh` remote SFTP directory listings (`api.ls`) onto the
3
+ * official reusable `directory.browser.dialog` Component Factory (DSH 0.2.3-alpha.4+).
4
+ */
5
+ import type { ReactNode } from 'react'
6
+ import type { RemoteDirEntry } from '../../protocol.ts'
7
+
8
+ /** Slot factory name owned by `@deepseek-ai/dsh-client-ui-directory-picker-browse`. */
9
+ export const DIRECTORY_BROWSER_DIALOG_FACTORY = 'directory.browser.dialog'
10
+
11
+ /** One directory row matching `DirectoryBrowserEntry`. */
12
+ export interface DirectoryDialogEntry {
13
+ readonly name: string
14
+ readonly path: string
15
+ readonly hidden: boolean
16
+ }
17
+
18
+ /** One listed level matching `DirectoryBrowserListing`. */
19
+ export interface DirectoryDialogListing {
20
+ readonly path: string
21
+ readonly home?: string
22
+ readonly crumbs: readonly DirectoryDialogEntry[]
23
+ readonly entries: readonly DirectoryDialogEntry[]
24
+ readonly truncated: boolean
25
+ }
26
+
27
+ /** Input props passed to `renderFactorySlot('directory.browser.dialog', ...)`. */
28
+ export interface DirectoryDialogRenderProps {
29
+ readonly open: boolean
30
+ readonly busy: boolean
31
+ readonly listDirectory: (path?: string, signal?: AbortSignal) => Promise<DirectoryDialogListing>
32
+ readonly onOpen: (path: string) => void
33
+ readonly onClose: () => void
34
+ }
35
+
36
+ /** Bound renderer for the optional `directory.browser.dialog` factory. */
37
+ export type RenderDirectoryDialog = (props: DirectoryDialogRenderProps) => ReactNode
38
+
39
+ /** Structural slice of the slot renderer's `renderFactorySlot` helper. */
40
+ export type RenderFactorySlotFn = (
41
+ name: string,
42
+ props: Record<string, unknown>,
43
+ options?: { readonly fallback?: ReactNode },
44
+ ) => ReactNode
45
+
46
+ /** Check whether the slot registry currently carries the `directory.browser.dialog` factory. */
47
+ export function hasDirectoryBrowserFactory(slots: unknown): boolean {
48
+ if (typeof slots !== 'object' || slots === null) return false
49
+ const snapshot = (slots as { snapshot?: (root?: string) => unknown }).snapshot
50
+ if (typeof snapshot !== 'function') return false
51
+ try {
52
+ const nodes = snapshot.call(slots, `factory:${DIRECTORY_BROWSER_DIALOG_FACTORY}`)
53
+ return Array.isArray(nodes) && nodes.length > 0
54
+ } catch {
55
+ return false
56
+ }
57
+ }
58
+
59
+ /** Normalize a POSIX remote path for directory listing (`''` / `'/'` -> `'/'`, no trailing slash otherwise). */
60
+ export function normalizeRemoteDirPath(raw: string | undefined): string {
61
+ const trimmed = raw?.trim() ?? ''
62
+ if (trimmed === '' || trimmed === '/') return '/'
63
+ const prefixed = trimmed.startsWith('/') ? trimmed : `/${trimmed}`
64
+ const collapsed = prefixed.replace(/\/+/g, '/').replace(/\/+$/, '')
65
+ return collapsed === '' ? '/' : collapsed
66
+ }
67
+
68
+ /** Format a confirmed remote directory path for the transfer path input (always ends with `/`). */
69
+ export function formatRemoteDirectoryPath(raw: string): string {
70
+ const norm = normalizeRemoteDirPath(raw)
71
+ return norm === '/' ? '/' : `${norm}/`
72
+ }
73
+
74
+ /** Build breadcrumb ancestry from `/` through `normalizedDir` inclusive. */
75
+ function buildPosixCrumbs(normalizedDir: string): DirectoryDialogEntry[] {
76
+ const crumbs: DirectoryDialogEntry[] = [{ name: '/', path: '/', hidden: false }]
77
+ if (normalizedDir === '/') return crumbs
78
+ let current = ''
79
+ for (const segment of normalizedDir.slice(1).split('/')) {
80
+ if (segment === '') continue
81
+ current += `/${segment}`
82
+ crumbs.push({ name: segment, path: current, hidden: segment.startsWith('.') })
83
+ }
84
+ return crumbs
85
+ }
86
+
87
+ /** Convert `api.ls` entries into a `DirectoryBrowserListing` (directories only, sorted by name). */
88
+ export function remoteEntriesToDirectoryListing(
89
+ dir: string | undefined,
90
+ entries: readonly RemoteDirEntry[],
91
+ ): DirectoryDialogListing {
92
+ const path = normalizeRemoteDirPath(dir)
93
+ const dirs = entries
94
+ .filter(entry => entry.type === 'dir' && entry.name !== '.' && entry.name !== '..')
95
+ .sort((a, b) => a.name.localeCompare(b.name))
96
+ .map(entry => ({
97
+ name: entry.name,
98
+ path: path === '/' ? `/${entry.name}` : `${path}/${entry.name}`,
99
+ hidden: entry.name.startsWith('.'),
100
+ }))
101
+ return {
102
+ path,
103
+ crumbs: buildPosixCrumbs(path),
104
+ entries: dirs,
105
+ truncated: false,
106
+ }
107
+ }
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Session island activity source for `dsh-ssh`.
3
+ *
4
+ * Reports live SSH terminal connections (`connecting` / `connected`) and active
5
+ * local port-forward tunnels (`connecting` / `forwarding`) held by
6
+ * {@link PanelController} to the official `sessionActivities` service, with a
7
+ * matching 16px glyph registered into `conversation.session.panel.activity.icon`.
8
+ * Reads solely from the controller store so observing a Session triggers zero
9
+ * background polling.
10
+ */
11
+ import { createElement, type ReactNode } from 'react'
12
+ import type { Context as ClientContext } from '@deepseek-ai/cordis'
13
+ import type { TunnelInfo } from '../protocol.ts'
14
+ import type { PanelController, TerminalTabRecord } from './panel/controller.ts'
15
+ import { tt } from './panel/helpers.ts'
16
+
17
+ /** Stable source id shared with `conversation.session.panel.activity.icon`. */
18
+ export const SSH_ACTIVITY_ID = 'dsh-ssh'
19
+
20
+ /** Official `SessionActivityStatus` subset reported to `sessionActivities`. */
21
+ export type SshActivityStatus = 'queued' | 'running' | 'stopping' | 'done' | 'failed' | 'inactive'
22
+
23
+ /** One reported activity unit matching `@deepseek-ai/dsh-client-ui-session-panel`. */
24
+ export interface SshSessionActivity {
25
+ readonly id: string
26
+ readonly status: SshActivityStatus
27
+ }
28
+
29
+ interface ObservableActivities {
30
+ getSnapshot(): readonly SshSessionActivity[]
31
+ subscribe(listener: () => void): () => void
32
+ }
33
+
34
+ interface SessionActivitiesFace {
35
+ registerSource(source: {
36
+ readonly id: string
37
+ readonly title: () => string
38
+ readonly observe: (sessionId: unknown) => ObservableActivities
39
+ }): () => void
40
+ }
41
+
42
+ interface ActivitySlotsFace {
43
+ inject(name: string, register: () => () => void): () => void
44
+ register(options: { name: string; key: string }, component: () => ReactNode): () => void
45
+ }
46
+
47
+ const EMPTY_ACTIVITIES: readonly SshSessionActivity[] = []
48
+
49
+ function sameActivities(
50
+ left: readonly SshSessionActivity[],
51
+ right: readonly SshSessionActivity[],
52
+ ): boolean {
53
+ return left.length === right.length
54
+ && left.every((item, index) => item.id === right[index]?.id && item.status === right[index]?.status)
55
+ }
56
+
57
+ /**
58
+ * Derive active SSH connection activities from live terminal tabs and tunnels.
59
+ */
60
+ export function sshActivitiesFrom(
61
+ tabs: readonly TerminalTabRecord[],
62
+ tunnels: readonly TunnelInfo[],
63
+ ): readonly SshSessionActivity[] {
64
+ const activities: SshSessionActivity[] = []
65
+ for (const tab of tabs) {
66
+ if (tab.status === 'connecting' || tab.status === 'connected') {
67
+ activities.push({ id: `terminal:${tab.id}`, status: 'running' })
68
+ }
69
+ }
70
+ for (const tunnel of tunnels) {
71
+ if (tunnel.state === 'connecting' || tunnel.state === 'forwarding') {
72
+ activities.push({ id: `tunnel:${tunnel.id}`, status: 'running' })
73
+ }
74
+ }
75
+ return activities.length === 0 ? EMPTY_ACTIVITIES : activities
76
+ }
77
+
78
+ /** 16px SSH terminal glyph rendered in the Session island header toggle. */
79
+ export function SshActivityIcon(): ReactNode {
80
+ return createElement(
81
+ 'svg',
82
+ {
83
+ viewBox: '0 0 16 16',
84
+ width: 16,
85
+ height: 16,
86
+ fill: 'none',
87
+ stroke: 'currentColor',
88
+ strokeWidth: '1.5',
89
+ strokeLinecap: 'round',
90
+ strokeLinejoin: 'round',
91
+ 'aria-hidden': 'true',
92
+ },
93
+ createElement('rect', { x: 1.75, y: 2.25, width: 12.5, height: 11.5, rx: 1.75 }),
94
+ createElement('path', { d: 'M4.25 5.25l2.75 2.75-2.75 2.75' }),
95
+ createElement('path', { d: 'M8.5 10.75h3.25' }),
96
+ )
97
+ }
98
+
99
+ /**
100
+ * Register the optional `sessionActivities` source and matching island icon.
101
+ * Returns a disposer releasing both registrations.
102
+ */
103
+ export function registerSshSessionActivity(
104
+ ctx: ClientContext,
105
+ controller: Pick<PanelController, 'getSnapshot' | 'getActiveTunnels' | 'subscribe'>,
106
+ ): () => void {
107
+ const disposers: Array<() => void> = []
108
+
109
+ const injectFn = (ctx as unknown as { inject?: (deps: readonly string[], cb: (scope: ClientContext) => void) => { dispose(): unknown } }).inject
110
+ if (typeof injectFn === 'function') {
111
+ let stopSource: (() => void) | undefined
112
+ const releaseSource = (): void => {
113
+ const stop = stopSource
114
+ stopSource = undefined
115
+ stop?.()
116
+ }
117
+ const fork = injectFn.call(ctx, ['sessionActivities'], (scope) => {
118
+ const service = (scope as unknown as { get?(name: string): unknown }).get?.('sessionActivities') as SessionActivitiesFace | undefined
119
+ if (typeof service?.registerSource !== 'function') return
120
+ scope.effect(() => {
121
+ releaseSource()
122
+ stopSource = service.registerSource({
123
+ id: SSH_ACTIVITY_ID,
124
+ title: () => tt('activity.title'),
125
+ observe: () => {
126
+ let cachedTabs: readonly TerminalTabRecord[] | undefined
127
+ let cachedTunnels: readonly TunnelInfo[] | undefined
128
+ let cached: readonly SshSessionActivity[] = EMPTY_ACTIVITIES
129
+ return {
130
+ getSnapshot: () => {
131
+ const tabs = controller.getSnapshot().terminalTabs
132
+ const tunnels = controller.getActiveTunnels()
133
+ if (tabs !== cachedTabs || tunnels !== cachedTunnels) {
134
+ cachedTabs = tabs
135
+ cachedTunnels = tunnels
136
+ const next = sshActivitiesFrom(tabs, tunnels)
137
+ if (!sameActivities(cached, next)) cached = next
138
+ }
139
+ return cached
140
+ },
141
+ subscribe: listener => controller.subscribe(listener),
142
+ }
143
+ },
144
+ })
145
+ return releaseSource
146
+ }, 'dsh-ssh: session activity source')
147
+ })
148
+ disposers.push(() => {
149
+ releaseSource()
150
+ void fork?.dispose?.()
151
+ })
152
+ }
153
+
154
+ const slots = (ctx as unknown as { slots?: ActivitySlotsFace }).slots
155
+ if (typeof slots?.inject === 'function' && typeof slots?.register === 'function') {
156
+ disposers.push(slots.inject(
157
+ 'conversation.session.panel.activity.icon',
158
+ () => slots.register({
159
+ name: 'conversation.session.panel.activity.icon',
160
+ key: SSH_ACTIVITY_ID,
161
+ }, SshActivityIcon),
162
+ ))
163
+ }
164
+
165
+ return () => {
166
+ for (const dispose of disposers.splice(0)) dispose()
167
+ }
168
+ }
@@ -1,7 +1,6 @@
1
1
  // Generated by scripts/sync-shared.mjs from shared/host/connection-trust.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
2
  /**
3
- * Optional bridge to the Host connection trust decision. Newer hosts expose
4
- * admit(request); the rc.3 SDK cohort exposes requestRejection(request). A
3
+ * Optional bridge to the Host connection trust decision (`admit(request)`). A
5
4
  * missing or throwing bridge is not an admission: callers must retain their
6
5
  * existing loopback or pairing fence.
7
6
  */
@@ -9,9 +8,8 @@
9
8
  import type { IncomingMessage } from 'node:http'
10
9
  import type { Context } from '@deepseek-ai/cordis'
11
10
 
12
- /** Structural host connection face across supported SDK cohorts. */
11
+ /** Structural host connection face (`admit(request)` on DSH 0.2.3-alpha.2+). */
13
12
  export interface HostConnectionService {
14
- requestRejection?: (request: IncomingMessage) => unknown
15
13
  admit?: (request: IncomingMessage) => { readonly peer?: unknown; readonly rejection?: unknown }
16
14
  }
17
15
 
@@ -23,9 +21,7 @@ function resolveConnection(ctx: Context): HostConnectionService | undefined {
23
21
  const candidate = typeof ctx.get === 'function'
24
22
  ? (ctx.get('connection', false) ?? ctx.get('connection'))
25
23
  : (ctx as { connection?: HostConnectionService }).connection
26
- return candidate !== undefined && candidate !== null && (
27
- typeof candidate.admit === 'function' || typeof candidate.requestRejection === 'function'
28
- )
24
+ return candidate !== undefined && candidate !== null && typeof candidate.admit === 'function'
29
25
  ? candidate
30
26
  : undefined
31
27
  } catch {
@@ -35,14 +31,10 @@ function resolveConnection(ctx: Context): HostConnectionService | undefined {
35
31
 
36
32
  /** Whether the Host's own authenticated/trusted-host decision admits a request. */
37
33
  export function connectionAdmits(connection: HostConnectionService | undefined, request: IncomingMessage): boolean {
38
- if (connection === undefined) return false
34
+ if (connection === undefined || typeof connection.admit !== 'function') return false
39
35
  try {
40
- if (typeof connection.admit === 'function') {
41
- const admission = connection.admit(request)
42
- return admission.rejection === undefined && 'peer' in admission && admission.peer !== undefined
43
- }
44
- if (typeof connection.requestRejection === 'function') return connection.requestRejection(request) === undefined
45
- return false
36
+ const admission = connection.admit(request)
37
+ return admission.rejection === undefined && 'peer' in admission && admission.peer !== undefined
46
38
  } catch {
47
39
  return false
48
40
  }
package/src/dsh-home.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  // Generated by scripts/sync-shared.mjs from shared/host/dsh-home.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
2
  /**
3
- * DSH_HOME resolution shared by the plugin family's Host halves: the
4
- * environment override wins, the platform home fallback follows. Mirrors
5
- * what dsh-pet and dsh-liangshen each used to implement locally.
3
+ * DSH_HOME and DSH_AGENTS_HOME resolution shared by the plugin family's Host
4
+ * halves: environment overrides win (blank values treated as unset), then the
5
+ * platform home fallbacks follow — mirroring `@deepseek-ai/dsh-home-paths`.
6
6
  */
7
7
 
8
8
  import { homedir } from 'node:os'
@@ -18,6 +18,21 @@ export function expandHome(path: string, home: string = homedir()): string {
18
18
  return path
19
19
  }
20
20
 
21
+ function resolveUserRoot(
22
+ envValue: string | undefined,
23
+ defaultDirName: string,
24
+ home: string,
25
+ ): string {
26
+ const isPosix = home.startsWith('/')
27
+ const j = isPosix ? posixJoin : join
28
+ const isAbs = isPosix ? posixIsAbsolute : isAbsolute
29
+ if (envValue !== undefined && envValue.trim() !== '') {
30
+ const expanded = expandHome(envValue.trim(), home)
31
+ return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
32
+ }
33
+ return j(home, defaultDirName)
34
+ }
35
+
21
36
  /**
22
37
  * Resolve the DSH home directory.
23
38
  * @param env - process environment to read DSH_HOME from.
@@ -25,18 +40,26 @@ export function expandHome(path: string, home: string = homedir()): string {
25
40
  * @returns the absolute DSH home path.
26
41
  */
27
42
  export function resolveDshHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
28
- const isPosix = home.startsWith('/')
29
- const j = isPosix ? posixJoin : join
30
- const isAbs = isPosix ? posixIsAbsolute : isAbsolute
31
- const raw = env.DSH_HOME
32
- if (raw !== undefined && raw.trim() !== '') {
33
- const expanded = expandHome(raw.trim(), home)
34
- return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
35
- }
36
- return j(home, '.dsh')
43
+ return resolveUserRoot(env.DSH_HOME, '.dsh', home)
37
44
  }
38
45
 
39
46
  /** Resolve the DSH home directory from the live environment. */
40
47
  export function dshHome(): string {
41
48
  return resolveDshHome()
42
49
  }
50
+
51
+ /**
52
+ * Resolve the shared agent configuration root (`$DSH_AGENTS_HOME`, defaulting
53
+ * to `<home>/.agents`), matching `@deepseek-ai/dsh-home-paths`'s `resolveAgentsHome`.
54
+ * @param env - process environment to read DSH_AGENTS_HOME from.
55
+ * @param home - platform home directory fallback (test seam).
56
+ * @returns the absolute shared agents home path.
57
+ */
58
+ export function resolveAgentsHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
59
+ return resolveUserRoot(env.DSH_AGENTS_HOME, '.agents', home)
60
+ }
61
+
62
+ /** Resolve the shared agent configuration root from the live environment. */
63
+ export function agentsHome(): string {
64
+ return resolveAgentsHome()
65
+ }