dsh-ssh-workspace-companion 0.0.0-stage → 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/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,26 @@
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
+ Remote companion plugin for `dsh-ssh-workspace`.
4
+
5
+ Install it in each remote DSH web profile that should be embedded by the local Remote Desktop controller. It exposes only a transitional local health endpoint, runs only in `?dshRemoteDesktop=1` iframe mode, validates parent origin/token messages, forwards official Client Controller state and commands over a versioned `MessageChannel`, opens requested remote sessions, and hides the embedded remote left sidebar.
6
+
7
+ The companion does not expose Session/Workspace snapshot or RPC Host APIs. The authenticated remote DSH Gateway and its official `ctx.sessions` / `ctx.workspaces` services remain the only business-data path.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ dsh plugin --profile web add dsh-ssh-workspace-companion
13
+ ```
14
+
15
+ Before npm publication, install from a local checkout on the remote machine/profile:
16
+
17
+ ```sh
18
+ dsh plugin --profile web add /path/to/dsh-remote-desktop/packages/companion
19
+ ```
20
+
21
+ The iframe client source is `src/client.js`; `lib/client.js` is generated with
22
+ the repository-level `npm run build` command.
23
+
24
+ ## Architecture
25
+
26
+ See the repository [architecture reference](https://github.com/sincerity711/dsh-remote-desktop/blob/main/docs/architecture.md) for iframe bridge, token validation, and companion behavior.
@@ -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,63 @@
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.0",
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
+ ],
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/sincerity711/dsh-remote-desktop.git",
53
+ "directory": "packages/companion"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/sincerity711/dsh-remote-desktop/issues"
57
+ },
58
+ "homepage": "https://github.com/sincerity711/dsh-remote-desktop#readme",
59
+ "publishConfig": {
60
+ "access": "public",
61
+ "registry": "https://registry.npmjs.org/"
62
+ }
63
+ }