@dsphere/dsphere-agent 0.0.0-stage → 2.0.7
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 +21 -0
- package/README.md +20 -2
- package/bin/dsphere-agent.mjs +4 -0
- package/lib/launcher.mjs +232 -0
- package/package.json +26 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsphere
|
|
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,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dsphere/dsphere-agent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Starts the [DSphere Agent](https://github.com/dsphere/dsphere-agent) MCP server over stdio. It is the launch command of the DSphere Agent connector in the WorkBuddy connector market, and works with any MCP client that can run a local stdio server:
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"mcpServers": {
|
|
8
|
+
"dsphere-agent": {
|
|
9
|
+
"command": "npx",
|
|
10
|
+
"args": ["-y", "@dsphere/dsphere-agent@2.0.7", "mcp", "serve", "--stdio"]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The package selects the Native Agent executable for this computer (Windows x64/x86/ARM64, macOS Intel/Apple Silicon) from its optional platform package, checks its SHA-256, copies it to a stable per-user directory and runs it with the given arguments:
|
|
17
|
+
|
|
18
|
+
- Windows: `%LOCALAPPDATA%\dsphere\dsphere-agent\workbuddy\2.0.7\dsphere-native-agent.exe`
|
|
19
|
+
- macOS: `~/Library/Application Support/dsphere/dsphere-agent/workbuddy/2.0.7/dsphere-native-agent`
|
|
20
|
+
|
|
21
|
+
The DSphere browser's Native Messaging host is bound to that same file during setup (see the DSphere Agent Skill), so the MCP connector and the browser runtime run one executable. `npx @dsphere/dsphere-agent@2.0.7 --print-executable` prints its path. The DSphere browser with the DSphere Agent extension is required.
|
package/lib/launcher.mjs
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// Starts the DSphere Native Agent for a WorkBuddy stdio MCP connector.
|
|
2
|
+
//
|
|
3
|
+
// WorkBuddy launches every stdio connector with one fixed command
|
|
4
|
+
// (`npx -y <launcher>@<version> mcp serve --stdio`). This launcher picks the
|
|
5
|
+
// executable for the current computer from the matching optional platform
|
|
6
|
+
// package, copies it to a stable per-user directory, and runs that copy with
|
|
7
|
+
// the caller's arguments. The stable copy is what the browser's Native
|
|
8
|
+
// Messaging host is bound to, so the MCP connector and the browser runtime run
|
|
9
|
+
// the same file, and the binding survives npm cache cleanup.
|
|
10
|
+
//
|
|
11
|
+
// stdout belongs to the child (MCP frames only). The launcher writes nothing to
|
|
12
|
+
// stdout except for `--print-executable`, and reports its own errors on stderr.
|
|
13
|
+
import { spawn } from 'node:child_process'
|
|
14
|
+
import { createHash, randomBytes } from 'node:crypto'
|
|
15
|
+
import {
|
|
16
|
+
chmodSync,
|
|
17
|
+
copyFileSync,
|
|
18
|
+
lstatSync,
|
|
19
|
+
mkdirSync,
|
|
20
|
+
readFileSync,
|
|
21
|
+
renameSync,
|
|
22
|
+
rmSync,
|
|
23
|
+
writeFileSync,
|
|
24
|
+
} from 'node:fs'
|
|
25
|
+
import { createRequire } from 'node:module'
|
|
26
|
+
import { homedir } from 'node:os'
|
|
27
|
+
import { posix, win32 } from 'node:path'
|
|
28
|
+
|
|
29
|
+
// One entry per optional platform package. `native` is the directory name the
|
|
30
|
+
// Skill package uses under assets/native. Windows on ARM64 runs the x64 build
|
|
31
|
+
// through emulation, the same choice the Skill's Windows setup makes.
|
|
32
|
+
export const PLATFORMS = Object.freeze([
|
|
33
|
+
{ id: 'win32-x64', os: 'win32', cpu: ['x64', 'arm64'], native: 'windows-x64', goos: 'windows', goarch: 'amd64', executable: 'dsphere-native-agent.exe' },
|
|
34
|
+
{ id: 'win32-ia32', os: 'win32', cpu: ['ia32'], native: 'windows-x86', goos: 'windows', goarch: '386', executable: 'dsphere-native-agent.exe' },
|
|
35
|
+
{ id: 'darwin-x64', os: 'darwin', cpu: ['x64'], native: 'macos-x64', goos: 'darwin', goarch: 'amd64', executable: 'dsphere-native-agent' },
|
|
36
|
+
{ id: 'darwin-arm64', os: 'darwin', cpu: ['arm64'], native: 'macos-arm64', goos: 'darwin', goarch: 'arm64', executable: 'dsphere-native-agent' },
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
// Overrides the stable install root. Intended for tests and diagnostics only.
|
|
40
|
+
export const HOME_ENV = 'DSPHERE_AGENT_WORKBUDDY_HOME'
|
|
41
|
+
export const DEFAULT_ARGS = Object.freeze(['mcp', 'serve', '--stdio'])
|
|
42
|
+
const SEMVER = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/
|
|
43
|
+
|
|
44
|
+
export class LauncherError extends Error {
|
|
45
|
+
constructor(code, message) {
|
|
46
|
+
super(message)
|
|
47
|
+
this.code = code
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function selectPlatform(platform = process.platform, arch = process.arch) {
|
|
52
|
+
const match = PLATFORMS.find(entry => entry.os === platform && entry.cpu.includes(arch))
|
|
53
|
+
if (!match) {
|
|
54
|
+
throw new LauncherError(
|
|
55
|
+
'UNSUPPORTED_PLATFORM',
|
|
56
|
+
`DSphere Agent runs on Windows (x64, x86, ARM64 through x64 emulation) and macOS (Intel, Apple Silicon); this computer is ${platform}-${arch}.`,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
return match
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const pathFor = platform => (platform === 'win32' ? win32 : posix)
|
|
63
|
+
|
|
64
|
+
// Windows: %LOCALAPPDATA%\dsphere\dsphere-agent\workbuddy
|
|
65
|
+
// macOS: ~/Library/Application Support/dsphere/dsphere-agent/workbuddy
|
|
66
|
+
export function installRoot({ env = process.env, platform = process.platform, home = homedir() } = {}) {
|
|
67
|
+
const path = pathFor(platform)
|
|
68
|
+
const override = env[HOME_ENV]
|
|
69
|
+
if (override) {
|
|
70
|
+
if (!path.isAbsolute(override)) throw new LauncherError('INVALID_HOME', `${HOME_ENV} must be an absolute path.`)
|
|
71
|
+
return override
|
|
72
|
+
}
|
|
73
|
+
if (platform === 'win32') {
|
|
74
|
+
const base = env.LOCALAPPDATA && path.isAbsolute(env.LOCALAPPDATA) ? env.LOCALAPPDATA : path.join(home, 'AppData', 'Local')
|
|
75
|
+
return path.join(base, 'dsphere', 'dsphere-agent', 'workbuddy')
|
|
76
|
+
}
|
|
77
|
+
if (platform === 'darwin') return path.join(home, 'Library', 'Application Support', 'dsphere', 'dsphere-agent', 'workbuddy')
|
|
78
|
+
throw new LauncherError('UNSUPPORTED_PLATFORM', `DSphere Agent has no stable install directory on ${platform}.`)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function stableExecutablePath({ root, version, target, platform = process.platform }) {
|
|
82
|
+
if (!SEMVER.test(version)) throw new LauncherError('INVALID_VERSION', `Invalid launcher version: ${version}`)
|
|
83
|
+
return pathFor(platform).join(root, version, target.executable)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const sha256File = file => createHash('sha256').update(readFileSync(file)).digest('hex')
|
|
87
|
+
|
|
88
|
+
function regularFileSize(file) {
|
|
89
|
+
try {
|
|
90
|
+
const stat = lstatSync(file)
|
|
91
|
+
return stat.isFile() ? stat.size : -1
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (error.code === 'ENOENT') return -1
|
|
94
|
+
throw error
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const matches = (file, native) => regularFileSize(file) === native.size && sha256File(file) === native.sha256
|
|
99
|
+
|
|
100
|
+
export function platformPackageName(launcherName, target) {
|
|
101
|
+
return `${launcherName}-${target.id}`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Reads the platform package's native.json and checks it describes the
|
|
105
|
+
// expected executable. `resolveFrom` is a file URL or path to resolve from.
|
|
106
|
+
export function resolvePlatformPackage(launcherName, target, resolveFrom = import.meta.url) {
|
|
107
|
+
const name = platformPackageName(launcherName, target)
|
|
108
|
+
let manifestPath
|
|
109
|
+
try {
|
|
110
|
+
manifestPath = createRequire(resolveFrom).resolve(`${name}/native.json`)
|
|
111
|
+
} catch {
|
|
112
|
+
throw new LauncherError(
|
|
113
|
+
'PLATFORM_PACKAGE_MISSING',
|
|
114
|
+
`${name} is not installed. It is an optional dependency of ${launcherName}; install without --omit=optional / --no-optional.`,
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
const path = pathFor(process.platform)
|
|
118
|
+
const dir = path.dirname(manifestPath)
|
|
119
|
+
let native
|
|
120
|
+
try {
|
|
121
|
+
native = JSON.parse(readFileSync(manifestPath, 'utf8'))
|
|
122
|
+
} catch {
|
|
123
|
+
throw new LauncherError('PLATFORM_PACKAGE_INVALID', `${name}/native.json is unreadable.`)
|
|
124
|
+
}
|
|
125
|
+
const expectedPath = `bin/${target.executable}`
|
|
126
|
+
if (
|
|
127
|
+
native?.schemaVersion !== 1 ||
|
|
128
|
+
native.platform !== target.native ||
|
|
129
|
+
native.goos !== target.goos ||
|
|
130
|
+
native.goarch !== target.goarch ||
|
|
131
|
+
native.path !== expectedPath ||
|
|
132
|
+
!Number.isSafeInteger(native.size) ||
|
|
133
|
+
native.size <= 0 ||
|
|
134
|
+
!/^[0-9a-f]{64}$/.test(native.sha256 ?? '') ||
|
|
135
|
+
!SEMVER.test(native.skillVersion ?? '') ||
|
|
136
|
+
!SEMVER.test(native.nativeVersion ?? '')
|
|
137
|
+
) {
|
|
138
|
+
throw new LauncherError('PLATFORM_PACKAGE_INVALID', `${name}/native.json does not describe ${target.native}/${target.executable}.`)
|
|
139
|
+
}
|
|
140
|
+
return { name, dir, native, binary: path.join(dir, ...expectedPath.split('/')) }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Ensures root/<version>/<executable> holds exactly the packaged executable and
|
|
144
|
+
// returns its path. An existing verified copy is reused untouched (it may be
|
|
145
|
+
// running as a browser runtime); a missing or damaged copy is replaced
|
|
146
|
+
// atomically. Concurrent launchers converge on the same verified file.
|
|
147
|
+
export function materialize({ pkg, root, version, target }) {
|
|
148
|
+
const path = pathFor(process.platform)
|
|
149
|
+
const destination = stableExecutablePath({ root, version, target })
|
|
150
|
+
if (matches(destination, pkg.native)) return destination
|
|
151
|
+
if (!matches(pkg.binary, pkg.native)) {
|
|
152
|
+
throw new LauncherError('PACKAGE_INTEGRITY', `${pkg.name} contains a damaged executable; clear the npm cache and reconnect.`)
|
|
153
|
+
}
|
|
154
|
+
const dir = path.dirname(destination)
|
|
155
|
+
mkdirSync(dir, { recursive: true })
|
|
156
|
+
const temporary = path.join(dir, `.${target.executable}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`)
|
|
157
|
+
try {
|
|
158
|
+
copyFileSync(pkg.binary, temporary)
|
|
159
|
+
chmodSync(temporary, 0o755)
|
|
160
|
+
if (!matches(temporary, pkg.native)) throw new LauncherError('COPY_INTEGRITY', `Copying ${target.executable} to ${dir} produced different bytes.`)
|
|
161
|
+
try {
|
|
162
|
+
renameSync(temporary, destination)
|
|
163
|
+
} catch (error) {
|
|
164
|
+
// Another launcher may have finished first, or Windows refuses to replace
|
|
165
|
+
// an executable that is running. Either way only a verified file is used.
|
|
166
|
+
if (!matches(destination, pkg.native)) {
|
|
167
|
+
throw new LauncherError('STABLE_COPY_LOCKED', `${destination} is in use and does not match ${pkg.name}; quit the DSphere browser and reconnect. (${error.code ?? error.message})`)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
} finally {
|
|
171
|
+
rmSync(temporary, { force: true })
|
|
172
|
+
}
|
|
173
|
+
const { size, sha256, skillVersion, nativeVersion, sourceCommit, builtAt, platform } = pkg.native
|
|
174
|
+
writeFileSync(
|
|
175
|
+
path.join(dir, 'install.json'),
|
|
176
|
+
JSON.stringify({ schemaVersion: 1, package: pkg.name, version, skillVersion, nativeVersion, sourceCommit, builtAt, platform, executable: target.executable, size, sha256 }, null, 2) + '\n',
|
|
177
|
+
)
|
|
178
|
+
return destination
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Runs the executable with inherited stdio and resolves with its exit status.
|
|
182
|
+
export function run(executable, args, { spawnImpl = spawn, signals = ['SIGINT', 'SIGTERM', 'SIGHUP'] } = {}) {
|
|
183
|
+
return new Promise(resolve => {
|
|
184
|
+
const child = spawnImpl(executable, args, { stdio: 'inherit', windowsHide: true })
|
|
185
|
+
const forward = signal => {
|
|
186
|
+
try {
|
|
187
|
+
child.kill(signal)
|
|
188
|
+
} catch {}
|
|
189
|
+
}
|
|
190
|
+
for (const signal of signals) process.on(signal, forward)
|
|
191
|
+
const done = result => {
|
|
192
|
+
for (const signal of signals) process.off(signal, forward)
|
|
193
|
+
resolve(result)
|
|
194
|
+
}
|
|
195
|
+
child.once('error', error => done({ code: 1, error }))
|
|
196
|
+
child.once('exit', (code, signal) => done({ code, signal }))
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function readLauncherPackage(url = new URL('../package.json', import.meta.url)) {
|
|
201
|
+
const pkg = JSON.parse(readFileSync(url, 'utf8'))
|
|
202
|
+
if (typeof pkg.name !== 'string' || !SEMVER.test(pkg.version ?? '')) throw new LauncherError('LAUNCHER_INVALID', 'The launcher package.json is invalid.')
|
|
203
|
+
return pkg
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function prepare({ launcher = readLauncherPackage(), resolveFrom = import.meta.url, env = process.env } = {}) {
|
|
207
|
+
const target = selectPlatform()
|
|
208
|
+
const pkg = resolvePlatformPackage(launcher.name, target, resolveFrom)
|
|
209
|
+
if (pkg.native.skillVersion !== launcher.version) {
|
|
210
|
+
throw new LauncherError('VERSION_MISMATCH', `${pkg.name} is ${pkg.native.skillVersion} but ${launcher.name} is ${launcher.version}; reinstall the connector.`)
|
|
211
|
+
}
|
|
212
|
+
const executable = materialize({ pkg, root: installRoot({ env }), version: launcher.version, target })
|
|
213
|
+
return { executable, target, pkg }
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
217
|
+
try {
|
|
218
|
+
const prepared = prepare()
|
|
219
|
+
if (argv.length === 1 && argv[0] === '--print-executable') {
|
|
220
|
+
const { nativeVersion, sourceCommit, builtAt } = prepared.pkg.native
|
|
221
|
+
process.stdout.write(JSON.stringify({ executable: prepared.executable, platform: prepared.target.native, nativeVersion, sourceCommit, builtAt }) + '\n')
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
const result = await run(prepared.executable, argv.length ? argv : [...DEFAULT_ARGS])
|
|
225
|
+
if (result.error) throw new LauncherError('SPAWN_FAILED', `Could not start ${prepared.executable}: ${result.error.message}`)
|
|
226
|
+
if (result.signal) process.kill(process.pid, result.signal)
|
|
227
|
+
else process.exitCode = result.code ?? 1
|
|
228
|
+
} catch (error) {
|
|
229
|
+
process.stderr.write(`dsphere-agent: ${error.code ?? 'LAUNCH_FAILED'}: ${error.message}\n`)
|
|
230
|
+
process.exitCode = 1
|
|
231
|
+
}
|
|
232
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsphere/dsphere-agent",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.7",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/dsphere/dsphere-agent.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/dsphere/dsphere-agent",
|
|
10
|
+
"description": "Starts the DSphere Agent MCP server (stdio) for WorkBuddy and other MCP clients.",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"bin": {
|
|
13
|
+
"dsphere-agent": "bin/dsphere-agent.mjs"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin",
|
|
17
|
+
"lib"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"optionalDependencies": {
|
|
23
|
+
"@dsphere/dsphere-agent-win32-x64": "2.0.7",
|
|
24
|
+
"@dsphere/dsphere-agent-win32-ia32": "2.0.7",
|
|
25
|
+
"@dsphere/dsphere-agent-darwin-x64": "2.0.7",
|
|
26
|
+
"@dsphere/dsphere-agent-darwin-arm64": "2.0.7"
|
|
27
|
+
}
|
|
28
|
+
}
|