dsh-coexist-cli 0.0.0-stage → 0.1.1

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 唐宋元明清
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.
@@ -0,0 +1,319 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ runCheck,
4
+ runPlan,
5
+ runApply,
6
+ runRollback,
7
+ runReport,
8
+ runList,
9
+ runAudit,
10
+ runBackups,
11
+ runPrefer,
12
+ } from '../src/commands.js'
13
+ import {
14
+ renderGraph,
15
+ renderPlan,
16
+ renderApply,
17
+ renderRollback,
18
+ renderReport,
19
+ renderList,
20
+ renderAudit,
21
+ renderBackups,
22
+ renderInstall,
23
+ renderUninstall,
24
+ renderMatrix,
25
+ renderDesktopPlan,
26
+ renderDesktopInstall,
27
+ renderDesktopRestore,
28
+ renderDesktopStatus,
29
+ renderDesktopLog,
30
+ } from '../src/report.js'
31
+ import { installPlugin, uninstallPlugin, buildMatrix } from '../src/installer.js'
32
+ import { freePort } from '../src/ports.js'
33
+ import { fileURLToPath } from 'node:url'
34
+ import { parseRunArgs, runDsh, RUN_HELP } from '../src/launcher.js'
35
+ import {
36
+ parseDesktopArgs,
37
+ installDesktop,
38
+ restoreDesktop,
39
+ desktopStatus,
40
+ desktopLog,
41
+ DESKTOP_HELP,
42
+ } from '../src/desktop.js'
43
+
44
+ const HELP = `dsh-coexist <check|plan|apply|rollback|report|list|audit|backups|prefer|free-port|run|desktop|install|uninstall|matrix> [options]
45
+
46
+ check scan the profile and report coexistence conflicts (default)
47
+ plan print the repair plan without writing anything
48
+ apply apply the plan (requires --yes)
49
+ rollback restore the latest backup, or one selected with --id
50
+ report read the runtime report written by the plugin
51
+ list list installed bundles and detected resources
52
+ audit read the local audit log
53
+ backups list backup ids
54
+ prefer move a bundle to the front so it keeps the original name on conflicts
55
+ free-port show or kill the process listening on a port (--yes to kill)
56
+ run boot DSH with the coexist preload (see: dsh-coexist run --help)
57
+ desktop install/restore the DSH desktop shortcut wrapper
58
+ install install a plugin into the profile (auto version check + rollback)
59
+ uninstall remove a plugin from the profile
60
+ matrix show host/plugin version compatibility for every installed plugin
61
+
62
+ Options:
63
+ --home <dir> DSH_HOME (default: $DSH_HOME or ~/.dsh)
64
+ --profile <name> profile name (default: desktop when it exists, otherwise web)
65
+ --json print JSON
66
+ --yes apply without the dry-run confirmation
67
+ --no-port-scan skip probing declared ports
68
+ --no-log-scan skip scanning DSH logs for historical errors
69
+ --no-source-scan skip scanning plugin sources for command/provider/slot/lock conflicts
70
+ --log <file> scan a specific log file
71
+ --allow-peer-override write controlled peer overrides (requires reinstall)
72
+ --app <file> path to the DSH desktop executable (auto-detected by default)
73
+ --dsh-version <v> override the detected DSH version
74
+ --self install the bundled dsh-coexist-plugin
75
+ --force install even if the version check fails
76
+ --dry-run for install: check only, write nothing
77
+ --plan <id> apply a saved plan (default: latest)
78
+ --id <id> rollback a specific backup id
79
+ --limit <n> audit entries to show (default 20)
80
+ --dump-config also run DSH --dump-config as a preflight
81
+ --reinstall after rollback, reinstall dependencies from the restored lockfile
82
+ --purge for uninstall: also remove ~/.dsh/coexist (backups, reports, config)
83
+ --no-diff skip the plan file preview
84
+ -h, --help show this help
85
+ `
86
+
87
+ function parseArgs(argv) {
88
+ const options = { command: 'check', positional: [] }
89
+ let commandSet = false
90
+
91
+ for (let index = 0; index < argv.length; index += 1) {
92
+ const arg = argv[index]
93
+ if (arg === '--home') options.home = argv[++index]
94
+ else if (arg === '--profile') options.profile = argv[++index]
95
+ else if (arg === '--json') options.json = true
96
+ else if (arg === '--yes') options.yes = true
97
+ else if (arg === '--no-port-scan') options.scanPorts = false
98
+ else if (arg === '--no-log-scan') options.scanLogs = false
99
+ else if (arg === '--no-source-scan') options.scanSources = false
100
+ else if (arg === '--log') options.logFile = argv[++index]
101
+ else if (arg === '--allow-peer-override') options.allowPeerOverride = true
102
+ else if (arg === '--app') options.app = argv[++index]
103
+ else if (arg === '--dsh-version') options.dshVersion = argv[++index]
104
+ else if (arg === '--self') options.self = true
105
+ else if (arg === '--force') options.force = true
106
+ else if (arg === '--dry-run') options.dryRun = true
107
+ else if (arg === '--plan') options.planId = argv[++index]
108
+ else if (arg === '--id') options.id = argv[++index]
109
+ else if (arg === '--limit') options.limit = Number(argv[++index])
110
+ else if (arg === '--dump-config') options.dumpConfig = true
111
+ else if (arg === '--reinstall') options.reinstall = true
112
+ else if (arg === '--purge') options.purge = true
113
+ else if (arg === '--no-diff') options.diff = false
114
+ else if (arg === '--help' || arg === '-h') options.help = true
115
+ else if (!arg.startsWith('-') && !commandSet) {
116
+ options.command = arg
117
+ commandSet = true
118
+ } else if (!arg.startsWith('-')) options.positional.push(arg)
119
+ }
120
+
121
+ return options
122
+ }
123
+
124
+ async function main() {
125
+ if (process.argv[2] === 'run') {
126
+ const runOptions = parseRunArgs(process.argv.slice(3))
127
+ if (runOptions.help) {
128
+ console.log(RUN_HELP)
129
+ return
130
+ }
131
+ const code = await runDsh(runOptions)
132
+ if (typeof code === 'number' && code !== 0) process.exitCode = code
133
+ return
134
+ }
135
+
136
+ if (process.argv[2] === 'desktop') {
137
+ const desktopOptions = parseDesktopArgs(process.argv.slice(3))
138
+ if (desktopOptions.help) {
139
+ console.log(DESKTOP_HELP)
140
+ return
141
+ }
142
+
143
+ if (desktopOptions.action === 'install') {
144
+ const result = await installDesktop(desktopOptions)
145
+ if (!result.applied) {
146
+ console.log(renderDesktopPlan(result))
147
+ if (result.needsConfirm) {
148
+ console.log('')
149
+ console.log('Dry run only. Re-run with --yes to apply.')
150
+ }
151
+ return
152
+ }
153
+ console.log(renderDesktopInstall(result))
154
+ return
155
+ }
156
+
157
+ if (desktopOptions.action === 'restore') {
158
+ console.log(renderDesktopRestore(await restoreDesktop(desktopOptions)))
159
+ return
160
+ }
161
+
162
+ if (desktopOptions.action === 'status') {
163
+ console.log(renderDesktopStatus(await desktopStatus(desktopOptions)))
164
+ return
165
+ }
166
+
167
+ if (desktopOptions.action === 'log') {
168
+ console.log(renderDesktopLog(await desktopLog(desktopOptions)))
169
+ return
170
+ }
171
+
172
+ console.error(`Unknown desktop action: ${desktopOptions.action}`)
173
+ console.log(DESKTOP_HELP)
174
+ process.exitCode = 1
175
+ return
176
+ }
177
+
178
+ const options = parseArgs(process.argv.slice(2))
179
+
180
+ if (options.help) {
181
+ console.log(HELP)
182
+ return
183
+ }
184
+
185
+ if (options.command === 'check') {
186
+ const { graph } = await runCheck(options)
187
+ console.log(options.json ? JSON.stringify(graph, null, 2) : renderGraph(graph))
188
+ return
189
+ }
190
+
191
+ if (options.command === 'plan') {
192
+ const { plan } = await runPlan(options)
193
+ console.log(options.json ? JSON.stringify(plan, null, 2) : renderPlan(plan))
194
+ return
195
+ }
196
+
197
+ if (options.command === 'apply') {
198
+ const result = await runApply(options)
199
+ if (result.needsConfirm) {
200
+ console.log(renderPlan(result.plan))
201
+ console.log('')
202
+ console.log('Dry run only. Re-run with --yes to apply.')
203
+ return
204
+ }
205
+ console.log(options.json ? JSON.stringify(result, null, 2) : renderApply(result))
206
+ return
207
+ }
208
+
209
+ if (options.command === 'rollback') {
210
+ const result = await runRollback(options)
211
+ console.log(options.json ? JSON.stringify(result, null, 2) : renderRollback(result))
212
+ return
213
+ }
214
+
215
+ if (options.command === 'report') {
216
+ const result = await runReport(options)
217
+ console.log(options.json ? JSON.stringify(result, null, 2) : renderReport(result))
218
+ return
219
+ }
220
+
221
+ if (options.command === 'list') {
222
+ const result = await runList(options)
223
+ console.log(options.json ? JSON.stringify(result, null, 2) : renderList(result))
224
+ return
225
+ }
226
+
227
+ if (options.command === 'audit') {
228
+ const result = await runAudit(options)
229
+ console.log(options.json ? JSON.stringify(result, null, 2) : renderAudit(result))
230
+ return
231
+ }
232
+
233
+ if (options.command === 'backups') {
234
+ const result = await runBackups(options)
235
+ console.log(options.json ? JSON.stringify(result, null, 2) : renderBackups(result))
236
+ return
237
+ }
238
+
239
+ if (options.command === 'prefer') {
240
+ const result = await runPrefer({ ...options, plugin: options.positional[0] })
241
+ if (options.json) {
242
+ console.log(JSON.stringify(result, null, 2))
243
+ } else if (!result.ok) {
244
+ console.log(`Prefer failed: ${result.error}`)
245
+ } else if (!result.changed) {
246
+ console.log(`${result.plugin} is already first.`)
247
+ } else {
248
+ console.log(`Moved ${result.plugin} to the front. Restart DSH to apply.`)
249
+ console.log(`Backup: ${result.backup}`)
250
+ }
251
+ if (!result.ok) process.exitCode = 1
252
+ return
253
+ }
254
+
255
+ if (options.command === 'free-port') {
256
+ const port = Number(options.positional[0])
257
+ if (!Number.isInteger(port) || port <= 0 || port > 65535) {
258
+ console.error('Usage: dsh-coexist free-port <port> [--yes]')
259
+ process.exitCode = 1
260
+ return
261
+ }
262
+ const result = await freePort(port, { yes: options.yes })
263
+ if (options.json) {
264
+ console.log(JSON.stringify(result, null, 2))
265
+ } else if (!result.ok) {
266
+ console.log(`Cannot inspect port ${port}: ${result.error}`)
267
+ } else if (result.pids.length === 0) {
268
+ console.log(`Port ${port} is free.`)
269
+ } else if (result.killed.length > 0) {
270
+ console.log(`Killed ${result.killed.length} process(es) on port ${port}: ${result.killed.join(', ')}`)
271
+ } else {
272
+ console.log(`Port ${port} is held by PID(s): ${result.pids.join(', ')}`)
273
+ console.log('Re-run with --yes to kill them.')
274
+ }
275
+ return
276
+ }
277
+
278
+ if (options.command === 'install') {
279
+ const spec = options.self
280
+ ? fileURLToPath(new URL('../../plugin', import.meta.url))
281
+ : options.positional[0]
282
+ if (!spec) {
283
+ console.error('Usage: dsh-coexist install <package|path> [--self]')
284
+ process.exitCode = 1
285
+ return
286
+ }
287
+ const result = await installPlugin({ ...options, spec })
288
+ console.log(options.json ? JSON.stringify(result, null, 2) : renderInstall(result))
289
+ if (!result.ok && !result.dryRun) process.exitCode = 1
290
+ return
291
+ }
292
+
293
+ if (options.command === 'uninstall') {
294
+ const spec = options.positional[0]
295
+ if (!spec) {
296
+ console.error('Usage: dsh-coexist uninstall <package>')
297
+ process.exitCode = 1
298
+ return
299
+ }
300
+ const result = await uninstallPlugin({ ...options, spec })
301
+ console.log(options.json ? JSON.stringify(result, null, 2) : renderUninstall(result))
302
+ return
303
+ }
304
+
305
+ if (options.command === 'matrix') {
306
+ const result = await buildMatrix(options)
307
+ console.log(options.json ? JSON.stringify(result, null, 2) : renderMatrix(result))
308
+ return
309
+ }
310
+
311
+ console.error(`Unknown command: ${options.command}`)
312
+ console.log(HELP)
313
+ process.exitCode = 1
314
+ }
315
+
316
+ main().catch((err) => {
317
+ console.error(err.stack ?? err.message)
318
+ process.exitCode = 1
319
+ })
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "dsh-coexist-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Pre-boot conflict scanner and repair planner for DeepSeek Harness profiles.",
5
+ "type": "module",
6
+ "bin": {
7
+ "dsh-coexist": "bin/dsh-coexist.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "preload.mjs"
13
+ ],
14
+ "keywords": [
15
+ "dsh-plugin",
16
+ "deepseek-harness",
17
+ "compatibility",
18
+ "coexistence"
19
+ ],
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Qymzz/dsh-coexist.git",
24
+ "directory": "packages/cli"
25
+ },
26
+ "homepage": "https://github.com/Qymzz/dsh-coexist#readme",
27
+ "dependencies": {
28
+ "yaml": "^2.8.0"
29
+ },
30
+ "engines": {
31
+ "node": "^22.19.0 || >=24.0.0"
32
+ }
33
+ }
package/preload.mjs ADDED
@@ -0,0 +1,74 @@
1
+ import { appendFileSync, mkdirSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import os from 'node:os'
4
+ import path from 'node:path'
5
+ import { pathToFileURL } from 'node:url'
6
+ import { installPrototypePatch } from './src/preload/patch.js'
7
+
8
+ const logFile =
9
+ process.env.DSH_COEXIST_LOG ??
10
+ path.join(os.homedir(), '.dsh', 'coexist', 'desktop', 'preload.log')
11
+
12
+ function logLine(message) {
13
+ try {
14
+ mkdirSync(path.dirname(logFile), { recursive: true })
15
+ appendFileSync(logFile, `[${new Date().toISOString()}] ${message}\n`)
16
+ } catch {
17
+ // Logging must never break the host.
18
+ }
19
+ }
20
+
21
+ logLine(
22
+ `preload start argv=${JSON.stringify(process.argv)} ` +
23
+ `electronRunAsNode=${process.env.ELECTRON_RUN_AS_NODE ?? ''} ` +
24
+ `nodeOptions=${process.env.NODE_OPTIONS ? 'yes' : 'no'}`,
25
+ )
26
+
27
+ const watch = (process.env.DSH_COEXIST_WATCH ?? '')
28
+ .split(',')
29
+ .map((name) => name.trim())
30
+ .filter(Boolean)
31
+
32
+ let toolsPath = process.env.DSH_COEXIST_TOOLS_PATH
33
+ if (!toolsPath) {
34
+ try {
35
+ toolsPath = createRequire(process.argv[1] ?? process.cwd()).resolve('@deepseek-ai/dsh-tools')
36
+ } catch {
37
+ // Keep looking below; the caller may set DSH_COEXIST_TOOLS_PATH.
38
+ }
39
+ }
40
+
41
+ if (!toolsPath) {
42
+ logLine('preload failed: cannot resolve @deepseek-ai/dsh-tools')
43
+ console.warn('[coexist] cannot resolve @deepseek-ai/dsh-tools; preload skipped')
44
+ } else {
45
+ try {
46
+ logLine(`preload tools=${toolsPath}`)
47
+ const requireFromDsh = createRequire(toolsPath)
48
+ const mod = await import(pathToFileURL(toolsPath).href)
49
+ const ToolsService = [mod.ToolsService, mod.ToolRuntime, mod.default].find(
50
+ (candidate) => typeof candidate?.prototype?.register === 'function',
51
+ )
52
+ if (!ToolsService) {
53
+ throw new Error('no tool registry class with register() found')
54
+ }
55
+
56
+ let scopeOf
57
+ try {
58
+ const scopePath = requireFromDsh.resolve('@deepseek-ai/dsh-scope')
59
+ ;({ scopeOf } = await import(pathToFileURL(scopePath).href))
60
+ } catch {
61
+ // Scope isolation falls back to a single global bucket.
62
+ }
63
+
64
+ installPrototypePatch(ToolsService, {
65
+ watch,
66
+ auto: watch.length === 0,
67
+ scopeOf,
68
+ logFile,
69
+ })
70
+ } catch (err) {
71
+ logLine(`preload failed: ${err.stack ?? err.message}`)
72
+ console.warn(`[coexist] preload failed: ${err.message}`)
73
+ }
74
+ }