dsh-ssh-workspace-companion 0.0.0-stage → 0.2.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 i060912
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,46 @@
1
- # Temporary Holding Version
1
+ # dsh-ssh-workspace-companion
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [dsh-ssh-workspace](https://www.npmjs.com/package/dsh-ssh-workspace) 的远程配套插件。安装在每台远程机器的 DeepSeek Harness(DSH)Web profile 中,让本地插件可以打开和操作该机器的工作区与会话。
4
+
5
+ ## 安装位置
6
+
7
+ - 本地机器安装 `dsh-ssh-workspace`。
8
+ - 每台远程机器安装本包 `dsh-ssh-workspace-companion`。
9
+
10
+ 本包需要配合本地插件使用。
11
+
12
+ ## 兼容性
13
+
14
+ 插件 0.2.x 面向 **DSH 0.2.0-rc.2**,不支持 DSH 0.1.x。本地插件与所有远程 companion 应使用相同版本,更新后重启 DSH。
15
+
16
+ ## 远程机器安装
17
+
18
+ ```sh
19
+ dsh plugin --profile web add dsh-ssh-workspace-companion
20
+ ```
21
+
22
+ 远程 Web 服务应绑定 loopback:
23
+
24
+ ```sh
25
+ dsh --profile web --host 127.0.0.1 --port 30800 --trusted-host 127.0.0.1:30800
26
+ ```
27
+
28
+ 本地插件通过 SSH 隧道连接该服务。如果使用自定义 `DSH_HOME`,安装、启动和本地 Remote Desktop 设置中的远程 profile 路径必须对应同一个目录。
29
+
30
+ 随后在本地机器安装主插件,并在 **Settings → Remote Desktop** 中连接 SSH 主机:
31
+
32
+ ```sh
33
+ dsh plugin --profile web add dsh-ssh-workspace
34
+ ```
35
+
36
+ ## 工作方式
37
+
38
+ companion 在本地插件打开的远程 iframe 中验证父页面来源和连接 token,通过专用 MessageChannel 转发 DSH 官方 Controller 状态与操作,并隐藏 iframe 中的远程侧栏。远程业务数据继续由远程 DSH 的认证服务处理。
39
+
40
+ ## 文档与反馈
41
+
42
+ - [项目与完整使用说明](https://github.com/sincerity711/dsh-ssh-workspace)
43
+ - [远程服务器配置](https://github.com/sincerity711/dsh-ssh-workspace/blob/main/docs/remote-server-setup.md)
44
+ - [问题反馈](https://github.com/sincerity711/dsh-ssh-workspace/issues)
45
+
46
+ 开发时修改 `packages/companion/src/client.js`,再在仓库根目录执行 `npm run build` 和 `npm run check`。
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: remote-desktop-companion
3
+ name: dsh-ssh-workspace-companion
package/lib/client.js ADDED
@@ -0,0 +1,230 @@
1
+ // Generated by scripts/build-clients.mjs. Edit packages/companion/src/client.js instead.
2
+ window.__ModuleLoader__.load({
3
+ id: 'dsh-remote-desktop-companion',
4
+ factory: (require) => {
5
+ const module = { exports: {} }
6
+ const exports = module.exports
7
+ exports.inject = ['sessions', 'workspaces', 'uiWorkspace']
8
+
9
+ const BRIDGE_PROTOCOL_VERSION = 1
10
+ const BRIDGE_CAPABILITIES = Object.freeze([
11
+ 'session/open',
12
+ 'session/create',
13
+ 'session/search',
14
+ 'session/rename',
15
+ 'session/fork',
16
+ 'workspace/create',
17
+ 'workspace/rename',
18
+ 'workspace/delete',
19
+ 'workspace/insertBefore',
20
+ 'workspace/archiveSession',
21
+ 'workspace/insertSessionBefore',
22
+ ])
23
+ const BRIDGE_METHODS = new Set(BRIDGE_CAPABILITIES)
24
+
25
+ function parseHash() {
26
+ const params = new URLSearchParams(window.location.hash.replace(/^#/, ''))
27
+ return { token: params.get('token') || '', parent: params.get('parent') || '' }
28
+ }
29
+
30
+ function installEmbeddedCss() {
31
+ document.body.setAttribute('data-dsh-remote-desktop-child', 'true')
32
+ const style = document.createElement('style')
33
+ style.setAttribute('data-dsh-remote-desktop-companion', '')
34
+ style.textContent = `
35
+ body[data-dsh-remote-desktop-child="true"] #root [class*="frame"]:has(> [class*="sidebarCol"]) > [class*="sidebarCol"] { visibility: hidden !important; pointer-events: none !important; overflow: hidden !important; }
36
+ body[data-dsh-remote-desktop-child="true"] [class*="handle"][data-side="sidebar"] { display: none !important; }
37
+ body[data-dsh-remote-desktop-child="true"] #root [class*="frame"]:has(> [class*="sidebarCol"]) { grid-template-columns: 0 minmax(0, 1fr) 0 !important; }
38
+ `
39
+ document.head.appendChild(style)
40
+ return () => { style.remove(); document.body.removeAttribute('data-dsh-remote-desktop-child') }
41
+ }
42
+
43
+ function controllerSnapshot(ctx) {
44
+ const sessions = ctx.sessions.list.getSnapshot()
45
+ const workspaces = ctx.workspaces.list.getSnapshot()
46
+ return {
47
+ sessions: {
48
+ ...sessions,
49
+ items: (sessions.ids || Object.keys(sessions.byId || {}))
50
+ .map(id => sessions.byId?.[id])
51
+ .filter(Boolean),
52
+ },
53
+ workspaces: {
54
+ ...workspaces,
55
+ items: [...(workspaces.items || [])],
56
+ archivedSessionIds: [...(workspaces.archivedSessionIds || [])],
57
+ },
58
+ }
59
+ }
60
+
61
+ function structuredError(error) {
62
+ const code = typeof error?.code === 'string' ? error.code : 'remote_desktop_bridge_failed'
63
+ const message = error instanceof Error ? error.message : String(error)
64
+ return { code, message }
65
+ }
66
+
67
+ async function waitUntilCurrent(ctx, sessionId, signal) {
68
+ signal.throwIfAborted()
69
+ ctx.uiWorkspace.openSession(sessionId)
70
+ await ctx.sessions.using(sessionId, { source: 'controllerOperation', signal }, async reference => {
71
+ await reference.ready
72
+ signal.throwIfAborted()
73
+ const owners = ctx.sessions.retainInfo(sessionId).getSnapshot().retainedBy
74
+ if ((owners.mainView || 0) === 0) throw new Error('session open superseded')
75
+ })
76
+ }
77
+
78
+ async function invoke(ctx, method, payload, signal) {
79
+ if (!BRIDGE_METHODS.has(method)) throw new Error(`unsupported remote desktop bridge method ${String(method)}`)
80
+ switch (method) {
81
+ case 'session/open': await waitUntilCurrent(ctx, payload.sessionId, signal); return { sessionId: payload.sessionId }
82
+ case 'session/create': return { sessionId: await ctx.sessions.create({ workspaceId: payload.workspaceId }) }
83
+ case 'session/search': {
84
+ const result = await ctx.sessions.search(String(payload.query || ''), signal)
85
+ if (!result.ok) throw new Error(result.error.message)
86
+ return result.value
87
+ }
88
+ case 'session/rename': {
89
+ return ctx.sessions.using(payload.sessionId, { source: 'controllerOperation', signal }, async reference => {
90
+ const binding = await reference.ready
91
+ const result = await binding.session.rename(payload.title)
92
+ if (!result.ok) throw new Error(result.error.message)
93
+ return result.value
94
+ })
95
+ }
96
+ case 'session/fork': {
97
+ const sessionId = await ctx.sessions.fork({ sessionId: payload.sessionId, increaseTitle: true })
98
+ return { sessionId }
99
+ }
100
+ case 'workspace/create': return { workspace: await ctx.workspaces.create({ path: payload.path }) }
101
+ case 'workspace/rename': return { workspace: await ctx.workspaces.rename(payload.workspaceId, payload.title) }
102
+ case 'workspace/delete': await ctx.workspaces.delete(payload.workspaceId); return {}
103
+ case 'workspace/insertBefore': await ctx.workspaces.insertBefore(payload.workspaceId, payload.beforeWorkspaceId); return {}
104
+ case 'workspace/archiveSession': await ctx.workspaces.archiveSession(payload.sessionId); return {}
105
+ case 'workspace/insertSessionBefore':
106
+ return { workspace: await ctx.workspaces.insertSessionBefore(payload.workspaceId, payload.sessionId, payload.beforeSessionId) }
107
+ default: throw new Error(`unsupported remote desktop bridge method ${String(method)}`)
108
+ }
109
+ }
110
+
111
+ exports.apply = function apply(ctx) {
112
+ const marker = new URLSearchParams(window.location.search).get('dshRemoteDesktop')
113
+ const { token, parent } = parseHash()
114
+ if (marker !== '1' || token === '' || parent === '') return
115
+ ctx.effect(() => {
116
+ const disposeCss = installEmbeddedCss()
117
+ let channel
118
+ let channelCleanup = () => {}
119
+ let openController
120
+ let announceTimer
121
+
122
+ const announceListening = () => {
123
+ window.parent.postMessage({
124
+ type: 'dsh-remote-desktop/bridge-listening',
125
+ protocolVersion: BRIDGE_PROTOCOL_VERSION,
126
+ sourceToken: token,
127
+ }, parent)
128
+ }
129
+
130
+ const attach = (port) => {
131
+ window.clearInterval(announceTimer)
132
+ channelCleanup()
133
+ channel = port
134
+ const generation = globalThis.crypto?.randomUUID?.() || `${Date.now()}-${Math.random()}`
135
+ let revision = 0
136
+ let queued = false
137
+ const publishBaseline = () => {
138
+ if (queued) return
139
+ queued = true
140
+ queueMicrotask(() => {
141
+ queued = false
142
+ if (channel !== port) return
143
+ revision += 1
144
+ port.postMessage({
145
+ type: 'dsh-remote-desktop/state-baseline',
146
+ protocolVersion: BRIDGE_PROTOCOL_VERSION,
147
+ sourceToken: token,
148
+ generation,
149
+ revision,
150
+ snapshot: controllerSnapshot(ctx),
151
+ })
152
+ })
153
+ }
154
+ const disposeSessions = ctx.sessions.list.subscribe(publishBaseline)
155
+ const disposeWorkspaces = ctx.workspaces.list.subscribe(publishBaseline)
156
+ port.onmessage = (event) => {
157
+ const data = event.data
158
+ if (data?.sourceToken !== token || data.protocolVersion !== BRIDGE_PROTOCOL_VERSION) return
159
+ if (data.type === 'dsh-remote-desktop/state-resync') {
160
+ publishBaseline()
161
+ return
162
+ }
163
+ if (data.type !== 'dsh-remote-desktop/request') return
164
+ if (typeof data.requestId !== 'string' || typeof data.method !== 'string') return
165
+ if (!BRIDGE_METHODS.has(data.method)) {
166
+ port.postMessage({
167
+ type: 'dsh-remote-desktop/result', protocolVersion: BRIDGE_PROTOCOL_VERSION,
168
+ sourceToken: token, requestId: data.requestId, ok: false,
169
+ error: { code: 'unsupported_method', message: `unsupported remote desktop bridge method ${data.method}` },
170
+ })
171
+ return
172
+ }
173
+ if (data.method === 'session/open') {
174
+ openController?.abort(new Error('session open superseded'))
175
+ openController = new AbortController()
176
+ }
177
+ const signal = data.method === 'session/open' ? openController.signal : AbortSignal.timeout(30_000)
178
+ void invoke(ctx, data.method, data.payload || {}, signal).then((value) => {
179
+ port.postMessage({
180
+ type: 'dsh-remote-desktop/result', protocolVersion: BRIDGE_PROTOCOL_VERSION,
181
+ sourceToken: token, requestId: data.requestId, ok: true, value,
182
+ })
183
+ }).catch((error) => {
184
+ port.postMessage({
185
+ type: 'dsh-remote-desktop/result', protocolVersion: BRIDGE_PROTOCOL_VERSION,
186
+ sourceToken: token, requestId: data.requestId, ok: false, error: structuredError(error),
187
+ })
188
+ })
189
+ }
190
+ port.start?.()
191
+ port.postMessage({
192
+ type: 'dsh-remote-desktop/ready',
193
+ protocolVersion: BRIDGE_PROTOCOL_VERSION,
194
+ sourceToken: token,
195
+ generation,
196
+ capabilities: BRIDGE_CAPABILITIES,
197
+ })
198
+ publishBaseline()
199
+ channelCleanup = () => {
200
+ disposeWorkspaces()
201
+ disposeSessions()
202
+ port.close()
203
+ }
204
+ }
205
+
206
+ const onMessage = (event) => {
207
+ if (event.origin !== parent || event.source !== window.parent) return
208
+ const data = event.data
209
+ if (data?.type !== 'dsh-remote-desktop/connect'
210
+ || data.protocolVersion !== BRIDGE_PROTOCOL_VERSION
211
+ || data.sourceToken !== token) return
212
+ const port = event.ports?.[0]
213
+ if (port === undefined) return
214
+ attach(port)
215
+ }
216
+ window.addEventListener('message', onMessage)
217
+ announceListening()
218
+ announceTimer = window.setInterval(announceListening, 500)
219
+ return () => {
220
+ window.clearInterval(announceTimer)
221
+ openController?.abort(new Error('remote desktop companion disposed'))
222
+ channelCleanup()
223
+ window.removeEventListener('message', onMessage)
224
+ disposeCss()
225
+ }
226
+ }, 'dsh-remote-desktop-companion: iframe bridge')
227
+ }
228
+ return module.exports
229
+ },
230
+ })
package/lib/index.js ADDED
@@ -0,0 +1,23 @@
1
+ export const name = 'dsh-remote-desktop-companion'
2
+ export const inject = ['webServer']
3
+
4
+ const HEALTH_PATH = '/remote-desktop-companion/api/health'
5
+
6
+ /**
7
+ * Transitional package-readiness probe. Session and Workspace data always use
8
+ * the authenticated DSH Client Controller running inside the remote iframe.
9
+ */
10
+ export function apply(ctx) {
11
+ const disposeHealth = ctx.webServer.register({
12
+ kind: 'exact',
13
+ path: HEALTH_PATH,
14
+ handler: (_req, res) => {
15
+ res.writeHead(200, {
16
+ 'content-type': 'application/json; charset=utf-8',
17
+ 'cache-control': 'no-store',
18
+ })
19
+ res.end(JSON.stringify({ ok: true, name }))
20
+ },
21
+ })
22
+ ctx.effect(() => disposeHealth, 'dsh-remote-desktop-companion: readiness route')
23
+ }
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "dsh-ssh-workspace-companion",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.2",
4
+ "description": "Remote companion for dsh-remote-desktop iframe control.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./client": "./lib/client.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "dsh": {
13
+ "bundle": {
14
+ "patch": "./cordis.patch.yml"
15
+ },
16
+ "client": {
17
+ "inject": [
18
+ "@deepseek-ai/dsh-api-session-controller",
19
+ "@deepseek-ai/dsh-api-workspace-controller",
20
+ "@deepseek-ai/dsh-client-ui-workspace"
21
+ ],
22
+ "platform": "web"
23
+ }
24
+ },
25
+ "peerDependencies": {
26
+ "@deepseek-ai/cordis": "^4.0.1",
27
+ "@deepseek-ai/dsh-api-session-controller": "0.2.0-rc.2",
28
+ "@deepseek-ai/dsh-api-workspace-controller": "0.2.0-rc.2",
29
+ "@deepseek-ai/dsh-host-webserver": "0.2.0-rc.2",
30
+ "@deepseek-ai/dsh-workspace": "0.2.0-rc.2"
31
+ },
32
+ "files": [
33
+ "lib",
34
+ "cordis.patch.yml",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "license": "MIT",
39
+ "keywords": [
40
+ "dsh-plugin",
41
+ "deepseek-harness",
42
+ "dsh",
43
+ "deepseek",
44
+ "cordis",
45
+ "remote-desktop",
46
+ "iframe",
47
+ "companion",
48
+ "remote-workspace",
49
+ "ssh-workspace",
50
+ "dsh-ssh-workspace"
51
+ ],
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/sincerity711/dsh-ssh-workspace.git",
55
+ "directory": "packages/companion"
56
+ },
57
+ "bugs": {
58
+ "url": "https://github.com/sincerity711/dsh-ssh-workspace/issues"
59
+ },
60
+ "homepage": "https://github.com/sincerity711/dsh-ssh-workspace#readme",
61
+ "publishConfig": {
62
+ "access": "public",
63
+ "registry": "https://registry.npmjs.org/"
64
+ }
65
+ }