dsh-go-plugin-sync 0.3.4 → 0.3.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.7 — 2026-12-04
4
+
5
+ ### 同步通道
6
+ - SSH 拉远端清单现在同时扫描 Cordis bundle 和手机原生插件,并带上类型
7
+ - SSH 拉取按来源处理:有文件目录的走文件,npm 安装的走 npm,不再一概 tar
8
+ - SSH 推送:本机从 npm 安装的插件,改为远端直接从 npm 安装
9
+ - 设置页新增“同步通道”:拉取中转、推送中转、测试 SSH、拉远端清单
10
+ - 打开设置页或拉取完成后会刷新中转/SSH 清单
11
+ - 设置页按钮改为“执行选中”,覆盖安装、推送和拉取
12
+
13
+ ## 0.3.6 — 2026-12-04
14
+
15
+ ### 双向兼容判断
16
+ - 同步码和清单记录插件类型:`native`(只有 dshGo)、`bundle`(Cordis/网页)、`both`
17
+ - 电脑端导入:手机原生插件标为不支持,不安装
18
+ - 手机端导入:电脑/网页插件标为“无原生界面”,默认不选中,仍可手动勾选安装
19
+ - 导入时只预选“可执行且兼容当前宿主”的项,不再把不兼容项一起选中
20
+ - 插件列表显示类型标签:手机原生 / 两端可用 / 电脑网页
21
+
22
+ ### 说明
23
+ - 旧同步码没有类型字段,按可尝试安装处理;新生成的同步码都带类型
24
+
25
+ ## 0.3.5 — 2026-12-04
26
+
27
+ ### 安装
28
+ - 安装改用 DSH 自带的 `pluginManager`(插件市场使用的同一套安装器),不再 shell 调用 `dsh plugin add`
29
+ - 自动使用当前 profile,避免装到错误的 profile
30
+ - 由插件管理器负责注册表、校验、激活和失败回滚
31
+ - 设置页显示每一项的失败原因,不只是“失败 N 项”
32
+
33
+ ### 说明
34
+ - 只有安装任务走插件管理器;Git 中转和 SSH 推/拉仍走原来的通道
35
+ - 没有 `pluginManager` 的旧宿主会自动回退到原来的安装方式
36
+
3
37
  ## 0.3.4 — 2026-12-04
4
38
 
5
39
  ### 电脑端
package/README.md CHANGED
@@ -57,6 +57,22 @@ Windows 上支持同步码导入和安装;安装任务由 Node 直接执行,
57
57
 
58
58
  注意:电脑上装完插件后同样要重启一次 DSH。
59
59
 
60
+ ## 插件类型与方向
61
+
62
+ 同步时会标出插件的运行环境:
63
+
64
+ - **手机原生**:只有 `dshGo`,只能在手机端用
65
+ - **两端可用**:同时有 `dshGo` 和 `dsh.bundle`
66
+ - **电脑/网页**:只有 Cordis/网页半侧,手机能装但没有原生界面
67
+
68
+ 导入时按方向判断:
69
+
70
+ - 手机的同步码给电脑:手机原生插件标为不支持,不安装
71
+ - 电脑的同步码给手机:电脑/网页插件标为“无原生界面”,默认不选中,可手动勾选
72
+ - 两端可用的插件正常预选和安装
73
+
74
+ 同步码、文件清单、Git 中转、SSH 都使用同一套类型判断;SSH 拉远端清单会同时看手机原生目录和 profile 里的 Cordis bundle。
75
+
60
76
  ## 只增不删
61
77
 
62
78
  - 只安装本机缺少的插件
package/lib/client.js CHANGED
@@ -29,6 +29,14 @@ window.__ModuleLoader__.load({
29
29
  cursor: 'pointer',
30
30
  }
31
31
  const PRIMARY = { ...BUTTON, background: '#3D6FD6', borderColor: '#3D6FD6', color: '#fff' }
32
+ const BADGE = {
33
+ fontSize: '11px',
34
+ lineHeight: '16px',
35
+ padding: '0 6px',
36
+ borderRadius: '8px',
37
+ border: '1px solid rgba(128,128,128,.3)',
38
+ opacity: 0.75,
39
+ }
32
40
 
33
41
  function api(path, body) {
34
42
  const options = body === undefined
@@ -50,6 +58,7 @@ window.__ModuleLoader__.load({
50
58
 
51
59
  function SyncSettings() {
52
60
  const [rows, setRows] = React.useState([])
61
+ const [results, setResults] = React.useState([])
53
62
  const [picked, setPicked] = React.useState({})
54
63
  const [code, setCode] = React.useState('')
55
64
  const [config, setConfig] = React.useState(null)
@@ -64,6 +73,7 @@ window.__ModuleLoader__.load({
64
73
  const load = () => api('state').then((snapshot) => {
65
74
  if (snapshot.error) { note(snapshot.error, 'bad'); return }
66
75
  setRows(snapshot.rows || [])
76
+ setResults(snapshot.results || [])
67
77
  setConfig(snapshot.config || null)
68
78
  setConfigPath(snapshot.configPath || '')
69
79
  const next = {}
@@ -75,6 +85,7 @@ window.__ModuleLoader__.load({
75
85
  React.useEffect(() => {
76
86
  const timer = setInterval(() => {
77
87
  api('status').then((snapshot) => {
88
+ if (snapshot.results) setResults(snapshot.results)
78
89
  if (!snapshot.task) return
79
90
  if (snapshot.task.running) note(T('正在执行…', 'Running…'))
80
91
  else if (snapshot.task.ok === false) note(T(`上次失败 ${snapshot.task.failed} 项`, `Last run failed: ${snapshot.task.failed}`), 'bad')
@@ -86,6 +97,13 @@ window.__ModuleLoader__.load({
86
97
  return () => clearInterval(timer)
87
98
  }, [])
88
99
 
100
+ const kindLabel = (kind) => kind === 'native'
101
+ ? T('手机原生', 'Phone native')
102
+ : kind === 'both'
103
+ ? T('两端可用', 'Both')
104
+ : kind === 'bundle'
105
+ ? T('电脑/网页', 'Desktop/web')
106
+ : ''
89
107
  const toggle = (name, checked) => setPicked((previous) => ({ ...previous, [name]: checked }))
90
108
  const all = (checked) => {
91
109
  const next = {}
@@ -110,7 +128,7 @@ window.__ModuleLoader__.load({
110
128
  api('apply', { names }).then((result) => {
111
129
  setBusy(false)
112
130
  if (result.error) { note(result.error, 'bad'); return }
113
- note(T(`已开始安装 ${result.count} 项`, `Installing ${result.count}`), 'good')
131
+ note(T(`已开始执行 ${result.count} 项`, `Running ${result.count}`), 'good')
114
132
  }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
115
133
  }
116
134
  const setPath = (path, value) => setConfig((previous) => {
@@ -124,6 +142,14 @@ window.__ModuleLoader__.load({
124
142
  cursor[keys[keys.length - 1]] = value
125
143
  return next
126
144
  })
145
+ const runAction = (action, message) => {
146
+ setBusy(true)
147
+ api('action', { action }).then((result) => {
148
+ setBusy(false)
149
+ if (result.error) { note(result.error, 'bad'); return }
150
+ note(message, 'good')
151
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
152
+ }
127
153
  const saveConfig = () => {
128
154
  if (!config) { note(T('配置还没加载完,稍后再试', 'Configuration is not loaded yet'), 'bad'); return }
129
155
  setBusy(true)
@@ -169,13 +195,19 @@ window.__ModuleLoader__.load({
169
195
  onChange: (event) => toggle(row.name, event.target.checked),
170
196
  }),
171
197
  h('span', { style: { fontWeight: 500 } }, row.name),
198
+ row.kind && h('span', { style: BADGE }, kindLabel(row.kind)),
172
199
  h('span', { style: { marginLeft: 'auto', fontSize: '12px', opacity: 0.65 } }, row.subtitle || row.status))),
173
200
  h('div', { style: { display: 'flex', gap: '8px', marginTop: '4px' } },
174
201
  h('button', { type: 'button', style: BUTTON, onClick: () => all(true) }, T('全选', 'Select all')),
175
202
  h('button', { type: 'button', style: BUTTON, onClick: () => all(false) }, T('清空', 'Clear')),
176
- h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: applySelected }, T('安装选中', 'Install selected')))),
203
+ h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: applySelected }, T('执行选中', 'Run selected')))),
177
204
 
178
205
  status && h('div', { style: { fontSize: '13px', color: tone === 'bad' ? '#c62828' : tone === 'good' ? '#2e7d32' : 'inherit' } }, status),
206
+ results.length > 0 && h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
207
+ ...results.map((item) => h('div', {
208
+ key: `${item.action || ''}:${item.name}`,
209
+ style: { fontSize: '12px', color: item.ok ? '#2e7d32' : '#c62828', wordBreak: 'break-word' },
210
+ }, `${item.ok ? '✓' : '✗'} ${item.name}${item.message ? ` — ${item.message}` : ''}`))),
179
211
 
180
212
  h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
181
213
  h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('Git 中转(可选)', 'Git relay (optional)')),
@@ -198,8 +230,15 @@ window.__ModuleLoader__.load({
198
230
  h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: saveConfig }, T('保存配置', 'Save configuration')),
199
231
  configPath && h('span', { style: { fontSize: '12px', opacity: 0.6, wordBreak: 'break-all' } }, configPath)),
200
232
 
201
- h('div', { style: { fontSize: '12px', opacity: 0.6 } },
202
- T('SSH 只支持密钥或 agent,不保存密码;Git 使用系统凭据。', 'SSH uses a key or agent (no passwords). Git uses system credentials.')))
233
+ h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
234
+ h('div', { style: { fontWeight: 600, marginBottom: '6px' } }, T('同步通道', 'Channels')),
235
+ h('div', { style: { display: 'flex', gap: '8px', flexWrap: 'wrap' } },
236
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('relay-pull', T('正在拉取中转…', 'Pulling relay…')) }, T('拉取中转', 'Pull relay')),
237
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('relay-push', T('正在推送中转…', 'Pushing relay…')) }, T('推送中转', 'Push relay')),
238
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('ssh-test', T('正在测试 SSH…', 'Testing SSH…')) }, T('测试 SSH', 'Test SSH')),
239
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('ssh-scan', T('正在拉远端清单…', 'Scanning remote…')) }, T('拉远端清单', 'Scan remote'))),
240
+ h('div', { style: { fontSize: '12px', opacity: 0.6, marginTop: '6px' } },
241
+ T('先保存配置再执行;SSH 只支持密钥或 agent,Git 使用系统凭据。', 'Save the configuration first. SSH uses a key or agent; Git uses system credentials.'))))
203
242
  }
204
243
 
205
244
  return {
package/lib/index.js CHANGED
@@ -133,6 +133,7 @@ function buildSyncCode(plugins) {
133
133
  hash: plugin.hash,
134
134
  relDir: plugin.relDir,
135
135
  depSpec: plugin.depSpec,
136
+ kind: plugin.kind || null,
136
137
  files: safeDirName(plugin.relDir) && existsSync(plugin.dir)
137
138
  ? readPluginTextFiles(plugin.dir)
138
139
  : {},
@@ -182,6 +183,7 @@ function decodeSyncCode(text) {
182
183
  hash: typeof raw.hash === 'string' ? raw.hash : null,
183
184
  relDir,
184
185
  depSpec: typeof raw.depSpec === 'string' ? raw.depSpec.slice(0, 200) : null,
186
+ kind: raw.kind === 'native' || raw.kind === 'bundle' || raw.kind === 'both' ? raw.kind : null,
185
187
  files,
186
188
  })
187
189
  }
@@ -233,7 +235,7 @@ function codeFromSubmit(value) {
233
235
  }
234
236
 
235
237
  /** Decode a sync code, materialize files, and preselect every row (all by default). */
236
- function applySyncCode(scope, text, sourceName) {
238
+ function applySyncCode(scope, text, sourceName, host = {}) {
237
239
  const decoded = decodeSyncCode(text)
238
240
  if (decoded.error) return { error: decoded.error }
239
241
  const state = stateFor(scope)
@@ -243,12 +245,14 @@ function applySyncCode(scope, text, sourceName) {
243
245
  state.sourceName = sourceName
244
246
  persistImported(state)
245
247
  writeCodeFiles(decoded)
246
- const rows = diffRows(localPlugins(), state.manifest, state.manifestSource)
248
+ const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, host)
247
249
  const manifestNames = new Set(decoded.manifest.plugins.map((plugin) => plugin.name))
248
250
  state.selected.clear()
249
251
  let selected = 0
250
252
  for (const row of rows) {
251
253
  if (!manifestNames.has(row.name)) continue
254
+ if (!row.action) continue
255
+ if (host.dshGo === true && row.kind === 'bundle') continue
252
256
  state.selected.add(row.name)
253
257
  selected++
254
258
  }
@@ -362,6 +366,15 @@ function titleOf(pkg) {
362
366
  return typeof pkg?.displayName === 'string' ? pkg.displayName : ''
363
367
  }
364
368
 
369
+ function pluginKind(pkg) {
370
+ const native = Boolean(pkg?.dshGo && typeof pkg.dshGo === 'object')
371
+ const bundle = Boolean(pkg?.dsh && typeof pkg.dsh === 'object' && pkg.dsh.bundle)
372
+ if (native && bundle) return 'both'
373
+ if (native) return 'native'
374
+ if (bundle) return 'bundle'
375
+ return null
376
+ }
377
+
365
378
  function makeEntry(pkg, dir, relDir, depSpec) {
366
379
  return {
367
380
  name: pkg.name,
@@ -370,6 +383,7 @@ function makeEntry(pkg, dir, relDir, depSpec) {
370
383
  hash: shortHash(dir),
371
384
  relDir: relDir || null,
372
385
  depSpec: depSpec || null,
386
+ kind: pluginKind(pkg),
373
387
  dir,
374
388
  installed: false,
375
389
  }
@@ -451,6 +465,7 @@ function buildManifest(plugins) {
451
465
  hash: plugin.hash,
452
466
  relDir: plugin.relDir,
453
467
  depSpec: plugin.depSpec,
468
+ kind: plugin.kind || null,
454
469
  installed: plugin.installed === true,
455
470
  })),
456
471
  }
@@ -468,6 +483,7 @@ function validManifest(doc) {
468
483
  title: typeof raw.title === 'string' ? raw.title.slice(0, 40) : '',
469
484
  hash: typeof raw.hash === 'string' ? raw.hash.slice(0, 64) : null,
470
485
  relDir: safeDirName(raw.relDir) ? raw.relDir : null,
486
+ kind: raw.kind === 'native' || raw.kind === 'bundle' || raw.kind === 'both' ? raw.kind : null,
471
487
  depSpec: typeof raw.depSpec === 'string' ? raw.depSpec.slice(0, 200) : null,
472
488
  installed: raw.installed === true,
473
489
  })
@@ -492,19 +508,30 @@ function registrySpecOf(remote) {
492
508
  return `${remote.name}@${version}`
493
509
  }
494
510
 
495
- function diffRows(local, manifest, source) {
511
+ function diffRows(local, manifest, source, host = {}) {
512
+ const nativeHost = host.dshGo === true
496
513
  const localByName = new Map(local.map((plugin) => [plugin.name, plugin]))
497
514
  const manifestByName = new Map((manifest?.plugins ?? []).map((plugin) => [plugin.name, plugin]))
498
515
  const rows = []
499
516
  for (const remote of manifest?.plugins ?? []) {
500
517
  const here = localByName.get(remote.name)
501
518
  const remoteDir = remote.relDir || remote.name
519
+ const kind = remote.kind || here?.kind || null
520
+ if (!nativeHost && kind === 'native') {
521
+ rows.push({ name: remote.name, version: remote.version, remoteVersion: remote.version, status: 'native-only', action: null, kind })
522
+ continue
523
+ }
502
524
  if (!here) {
503
525
  let action = null
504
526
  let localDir = null
505
527
  let registrySpec = null
506
528
  if (source?.kind === 'ssh') {
507
- action = 'pull'
529
+ if (safeDirName(remote.relDir)) {
530
+ action = 'pull'
531
+ } else {
532
+ registrySpec = registrySpecOf(remote)
533
+ if (registrySpec) action = 'install'
534
+ }
508
535
  } else {
509
536
  if (source?.kind === 'relay') localDir = join(source.pluginsDir, remoteDir)
510
537
  else if (remote.relDir) localDir = join(pluginsRoot(), remote.relDir)
@@ -520,8 +547,9 @@ function diffRows(local, manifest, source) {
520
547
  name: remote.name,
521
548
  version: remote.version,
522
549
  remoteVersion: remote.version,
523
- status: action ? 'installable' : 'missing',
550
+ status: action ? (nativeHost && kind === 'bundle' ? 'web-only' : 'installable') : 'missing',
524
551
  action,
552
+ kind,
525
553
  localDir,
526
554
  registrySpec,
527
555
  dirName: remoteDir,
@@ -530,22 +558,29 @@ function diffRows(local, manifest, source) {
530
558
  }
531
559
  const same = (!remote.hash || !here.hash || remote.hash === here.hash) && remote.version === here.version
532
560
  if (!same) {
533
- rows.push({ name: here.name, version: here.version, remoteVersion: remote.version, status: 'conflict', action: null })
561
+ rows.push({ name: here.name, version: here.version, remoteVersion: remote.version, status: 'conflict', action: null, kind })
534
562
  } else if (!here.installed) {
535
- rows.push({ name: here.name, version: here.version, status: 'install', action: 'install', localDir: here.dir })
563
+ rows.push({ name: here.name, version: here.version, status: nativeHost && kind === 'bundle' ? 'web-only' : 'install', action: 'install', kind, localDir: here.dir })
536
564
  } else {
537
- rows.push({ name: here.name, version: here.version, status: 'same', action: null })
565
+ rows.push({ name: here.name, version: here.version, status: 'same', action: null, kind })
538
566
  }
539
567
  }
540
568
  for (const here of local) {
541
569
  if (manifestByName.has(here.name)) continue
542
570
  if (source?.kind === 'ssh') {
543
- rows.push({ name: here.name, version: here.version, status: 'push', action: 'push', dirName: here.relDir || here.name })
571
+ if (safeDirName(here.relDir)) {
572
+ rows.push({ name: here.name, version: here.version, status: 'push', action: 'push', kind: here.kind || null, dirName: here.relDir })
573
+ } else {
574
+ const registrySpec = registrySpecOf({ name: here.name, version: here.version })
575
+ rows.push(registrySpec
576
+ ? { name: here.name, version: here.version, status: 'push', action: 'push-npm', kind: here.kind || null, registrySpec }
577
+ : { name: here.name, version: here.version, status: 'extra', action: null, kind: here.kind || null })
578
+ }
544
579
  } else {
545
- rows.push({ name: here.name, version: here.version, status: 'extra', action: null })
580
+ rows.push({ name: here.name, version: here.version, status: 'extra', action: null, kind: here.kind || null })
546
581
  }
547
582
  }
548
- const order = { conflict: 0, installable: 1, install: 2, push: 3, extra: 4, missing: 5, same: 6 }
583
+ const order = { conflict: 0, installable: 1, install: 2, push: 3, extra: 4, missing: 5, same: 6, 'native-only': 7, 'web-only': 8 }
549
584
  rows.sort((a, b) => (order[a.status] ?? 9) - (order[b.status] ?? 9) || a.name.localeCompare(b.name))
550
585
  return rows
551
586
  }
@@ -806,6 +841,59 @@ function localAddCommand(dir) {
806
841
  return `"$DSH_BIN" plugin --profile "$PROFILE" add ${shQuote(dir)}`
807
842
  }
808
843
 
844
+ /** Install jobs through the host's own plugin manager (same path as the plugin market). */
845
+ function startInstallTask(ctx, jobs) {
846
+ const manager = ctx.get?.('pluginManager')
847
+ if (!manager || typeof manager.installBundle !== 'function') return null
848
+ if (taskRunning()) return { ok: false, error: '已有任务在运行,等它结束再试' }
849
+ ensureStore()
850
+ writeFileSync(taskLogPath(), '')
851
+ writeFileSync(taskStatusPath(), `running ${Math.floor(Date.now() / 1000)} apply\n`)
852
+ const installs = jobs.filter((job) => job.action === 'install')
853
+ const say = (line) => { try { writeFileSync(taskLogPath(), `${line}\n`, { flag: 'a' }) } catch {} }
854
+ ;(async () => {
855
+ let failed = 0
856
+ for (const job of installs) {
857
+ const name = markerName(job.name)
858
+ const target = job.localDir || job.registrySpec
859
+ say(`@@ install ${name} start`)
860
+ if (!target) {
861
+ failed += 1
862
+ say(`@@ install ${name} fail`)
863
+ say('no install source')
864
+ continue
865
+ }
866
+ try {
867
+ const result = await manager.installBundle(target, { enabled: true })
868
+ if (result && result.ok === false) {
869
+ failed += 1
870
+ say(String(result.error?.message || result.error || 'install failed').slice(0, 2000))
871
+ say(`@@ install ${name} fail`)
872
+ } else {
873
+ say(`@@ install ${name} ok`)
874
+ const value = result && result.value !== undefined ? result.value : result
875
+ try { say(JSON.stringify(value).slice(0, 2000)) } catch {}
876
+ }
877
+ } catch (error) {
878
+ failed += 1
879
+ say(String(error && (error.stack || error.message) || error).slice(0, 2000))
880
+ say(`@@ install ${name} fail`)
881
+ }
882
+ }
883
+ try { writeFileSync(taskStatusPath(), `done ${Math.floor(Date.now() / 1000)} ${failed} apply\n`) } catch {}
884
+ })()
885
+ return { ok: true }
886
+ }
887
+
888
+ /** Prefer the plugin manager for pure installs; keep the shell path for SSH push/pull. */
889
+ function startApplyTask(ctx, cfg, jobs) {
890
+ if (jobs.every((job) => job.action === 'install')) {
891
+ const started = startInstallTask(ctx, jobs)
892
+ if (started) return started
893
+ }
894
+ return startTask('apply', buildApply(cfg, jobs), winTask(jobs))
895
+ }
896
+
809
897
  /** One result-reporting item: start marker, commands, ok/fail marker. */
810
898
  function itemLines(action, name, commands) {
811
899
  const tag = `${action} ${markerName(name)}`
@@ -898,11 +986,12 @@ function buildSshTest(cfg) {
898
986
 
899
987
  function buildSshScan(cfg) {
900
988
  const { home } = remotePaths(cfg)
989
+ const profileDir = `${home}/profiles/${cfg.ssh.profile}`
901
990
  const scanner = remoteScannerFile()
902
991
  writeFileSync(scanner, remoteScannerSource())
903
992
  return [
904
993
  ...sshPrelude(cfg),
905
- `ssh_run "$SSH_TARGET" "${cfg.ssh.nodePath} - ${home}" < ${shQuote(scanner)} > ${shQuote(sshManifestFile())} 2>> "$LOG" || failed=$((failed + 1))`,
994
+ `ssh_run "$SSH_TARGET" "${cfg.ssh.nodePath} - ${home} ${profileDir}" < ${shQuote(scanner)} > ${shQuote(sshManifestFile())} 2>> "$LOG" || failed=$((failed + 1))`,
906
995
  ]
907
996
  }
908
997
 
@@ -911,12 +1000,17 @@ function buildSshPush(cfg, jobs) {
911
1000
  const dsh = cfg.ssh.dshPath
912
1001
  const profile = cfg.ssh.profile
913
1002
  const lines = [...sshPrelude(cfg)]
914
- for (const job of jobs.filter((item) => safeName(item.dirName))) {
1003
+ for (const job of jobs.filter((item) => item.action === 'push' && safeName(item.dirName))) {
915
1004
  lines.push(...itemLines('push', job.name, [
916
1005
  `tar -C ${shQuote(pluginsRoot())} -czf - --exclude=node_modules --exclude=.git ${shQuote(job.dirName)} | ssh_run "$SSH_TARGET" "mkdir -p ${plugins} && tar -C ${plugins} -xzf -"`,
917
1006
  `ssh_run "$SSH_TARGET" "cd ${home} && ${dsh} plugin --profile ${profile} add ${plugins}/${job.dirName}"`,
918
1007
  ]))
919
1008
  }
1009
+ for (const job of jobs.filter((item) => item.action === 'push-npm' && item.registrySpec)) {
1010
+ lines.push(...itemLines('push', job.name, [
1011
+ `ssh_run "$SSH_TARGET" "cd ${home} && ${dsh} plugin --profile ${profile} add ${shQuote(job.registrySpec)}"`,
1012
+ ]))
1013
+ }
920
1014
  return lines
921
1015
  }
922
1016
 
@@ -947,7 +1041,7 @@ function winTask(jobs) {
947
1041
  function buildApply(cfg, jobs) {
948
1042
  const lines = []
949
1043
  const installs = jobs.filter((job) => job.action === 'install')
950
- const pushes = jobs.filter((job) => job.action === 'push')
1044
+ const pushes = jobs.filter((job) => job.action === 'push' || job.action === 'push-npm')
951
1045
  const pulls = jobs.filter((job) => job.action === 'pull')
952
1046
  for (const job of installs) {
953
1047
  const target = job.localDir || job.registrySpec
@@ -961,51 +1055,91 @@ function buildApply(cfg, jobs) {
961
1055
  let SCANNER_CACHE
962
1056
  function remoteScannerSource() {
963
1057
  if (SCANNER_CACHE) return SCANNER_CACHE
964
- SCANNER_CACHE = [
965
- "const fs = require('fs')",
966
- "const path = require('path')",
967
- "const crypto = require('crypto')",
968
- "const root = path.join(process.argv[2], 'dsh-go', 'plugins')",
969
- 'const out = []',
970
- 'function walk(dir, acc, depth) {',
971
- ' if (depth > 6 || acc.length >= 300) return',
972
- ' let entries',
973
- ' try { entries = fs.readdirSync(dir, { withFileTypes: true }) } catch { return }',
974
- ' for (const e of entries) {',
975
- ' if (acc.length >= 300) return',
976
- " const full = path.join(dir, e.name)",
977
- ' if (e.isDirectory()) walk(full, acc, depth + 1)',
978
- ' else if (e.isFile()) acc.push(full)',
979
- ' }',
980
- '}',
981
- 'function hash(dir) {',
982
- " const h = crypto.createHash('sha256')",
983
- " try { h.update(fs.readFileSync(path.join(dir, 'package.json'))) } catch { return null }",
984
- ' const files = []',
985
- " walk(path.join(dir, 'lib'), files, 0)",
986
- ' files.sort()',
987
- ' for (const f of files) {',
988
- ' let b',
989
- ' try { b = fs.readFileSync(f) } catch { continue }',
990
- ' if (b.length > 2097152) continue',
991
- " h.update(path.relative(dir, f))",
992
- " h.update('\\0')",
993
- ' h.update(b)',
994
- ' }',
995
- " return h.digest('hex').slice(0, 16)",
996
- '}',
997
- "try {",
998
- ' for (const e of fs.readdirSync(root, { withFileTypes: true })) {',
999
- " if (!e.isDirectory() || e.name.startsWith('.')) continue",
1000
- ' const dir = path.join(root, e.name)',
1001
- ' let pkg',
1002
- " try { pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')) } catch { continue }",
1003
- " if (!pkg || typeof pkg.name !== 'string' || !pkg.dshGo) continue",
1004
- ' out.push({ name: pkg.name, version: String(pkg.version || \'0.0.0\'), hash: hash(dir), relDir: e.name, depSpec: null, installed: false })',
1005
- ' }',
1006
- '} catch {}',
1007
- "process.stdout.write(JSON.stringify({ v: 1, exportedAt: new Date().toISOString(), host: { profile: 'remote' }, plugins: out }))",
1008
- ].join('\n') + '\n'
1058
+ SCANNER_CACHE = `const fs = require('fs')
1059
+ const path = require('path')
1060
+ const crypto = require('crypto')
1061
+ const home = process.argv[2]
1062
+ const profileDir = process.argv[3] || path.join(home, 'profiles', 'web')
1063
+ const root = path.join(home, 'dsh-go', 'plugins')
1064
+ const out = new Map()
1065
+ function kind(pkg) {
1066
+ const native = Boolean(pkg.dshGo && typeof pkg.dshGo === 'object')
1067
+ const bundle = Boolean(pkg.dsh && typeof pkg.dsh === 'object' && pkg.dsh.bundle)
1068
+ if (native && bundle) return 'both'
1069
+ if (native) return 'native'
1070
+ if (bundle) return 'bundle'
1071
+ return null
1072
+ }
1073
+ function usable(pkg) {
1074
+ if (!pkg || typeof pkg.name !== 'string') return false
1075
+ if (pkg.name.startsWith('@deepseek-ai/') || pkg.name === 'dsh-go-plugin-sync') return false
1076
+ return kind(pkg) !== null
1077
+ }
1078
+ function walk(dir, acc, depth) {
1079
+ if (depth > 6 || acc.length >= 300) return
1080
+ let entries
1081
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }) } catch { return }
1082
+ for (const e of entries) {
1083
+ if (acc.length >= 300) return
1084
+ const full = path.join(dir, e.name)
1085
+ if (e.isDirectory()) walk(full, acc, depth + 1)
1086
+ else if (e.isFile()) acc.push(full)
1087
+ }
1088
+ }
1089
+ function hash(dir) {
1090
+ const h = crypto.createHash('sha256')
1091
+ try { h.update(fs.readFileSync(path.join(dir, 'package.json'))) } catch { return null }
1092
+ const files = []
1093
+ walk(path.join(dir, 'lib'), files, 0)
1094
+ files.sort()
1095
+ for (const f of files) {
1096
+ let b
1097
+ try { b = fs.readFileSync(f) } catch { continue }
1098
+ if (b.length > 2097152) continue
1099
+ h.update(path.relative(dir, f).split(path.sep).join('/'))
1100
+ h.update(String.fromCharCode(0))
1101
+ h.update(b)
1102
+ }
1103
+ return h.digest('hex').slice(0, 16)
1104
+ }
1105
+ try {
1106
+ for (const e of fs.readdirSync(root, { withFileTypes: true })) {
1107
+ if (!e.isDirectory() || e.name.startsWith('.')) continue
1108
+ const dir = path.join(root, e.name)
1109
+ let pkg
1110
+ try { pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')) } catch { continue }
1111
+ if (!usable(pkg)) continue
1112
+ out.set(pkg.name, { name: pkg.name, version: String(pkg.version || '0.0.0'), hash: hash(dir), relDir: e.name, depSpec: null, kind: kind(pkg), installed: false })
1113
+ }
1114
+ } catch {}
1115
+ try {
1116
+ const profile = JSON.parse(fs.readFileSync(path.join(profileDir, 'package.json'), 'utf8'))
1117
+ const deps = profile.dependencies || {}
1118
+ for (const [dep, spec] of Object.entries(deps)) {
1119
+ let pkg
1120
+ try { pkg = JSON.parse(fs.readFileSync(path.join(profileDir, 'node_modules', dep, 'package.json'), 'utf8')) } catch { continue }
1121
+ if (!usable(pkg)) continue
1122
+ let relDir = null
1123
+ if (typeof spec === 'string' && (spec.startsWith('link:') || spec.startsWith('file:'))) {
1124
+ const raw = spec.slice(spec.indexOf(':') + 1)
1125
+ const rel = path.relative(root, path.resolve(profileDir, raw))
1126
+ if (rel && !rel.startsWith('..') && !path.isAbsolute(rel)) relDir = rel.split(path.sep).join('/')
1127
+ }
1128
+ const entry = { name: pkg.name, version: String(pkg.version || '0.0.0'), hash: hash(path.join(profileDir, 'node_modules', dep)), relDir, depSpec: typeof spec === 'string' ? spec : null, kind: kind(pkg), installed: true }
1129
+ const existing = out.get(pkg.name)
1130
+ if (existing) {
1131
+ existing.installed = true
1132
+ existing.depSpec = entry.depSpec
1133
+ if (!existing.relDir) existing.relDir = entry.relDir
1134
+ if (!existing.hash) existing.hash = entry.hash
1135
+ if (!existing.kind) existing.kind = entry.kind
1136
+ } else {
1137
+ out.set(pkg.name, entry)
1138
+ }
1139
+ }
1140
+ } catch {}
1141
+ process.stdout.write(JSON.stringify({ v: 1, exportedAt: new Date().toISOString(), host: { profile: path.basename(profileDir) }, plugins: [...out.values()] }))
1142
+ `
1009
1143
  return SCANNER_CACHE
1010
1144
  }
1011
1145
 
@@ -1059,10 +1193,15 @@ function statusLine(row, en) {
1059
1193
  missing: en ? 'files not on this host' : '本机缺少文件,需手动拷贝',
1060
1194
  extra: en ? 'not in manifest' : '清单里没有',
1061
1195
  push: en ? 'remote lacks it; can push' : '远端没有,可推送',
1196
+ 'native-only': en ? 'phone-only native plugin; not supported here' : '手机端原生插件,电脑端不支持',
1197
+ 'web-only': en ? 'desktop/web plugin; no native UI on the phone' : '电脑/网页端插件,手机无原生界面',
1062
1198
  }[row.status] || row.status
1063
- if (row.action === 'install' && row.registrySpec) text = en ? 'install from npm' : '可从 npm 安装'
1064
- else if (row.action === 'install' && row.localDir) text = en ? 'install from files' : '可从文件安装'
1065
- else if (row.action === 'pull') text = en ? 'pull from remote' : '可从远端拉取'
1199
+ if (row.status !== 'web-only' && row.status !== 'native-only') {
1200
+ if (row.action === 'install' && row.registrySpec) text = en ? 'install from npm' : '可从 npm 安装'
1201
+ else if (row.action === 'install' && row.localDir) text = en ? 'install from files' : '可从文件安装'
1202
+ else if (row.action === 'pull') text = en ? 'pull from remote' : '可从远端拉取'
1203
+ else if (row.action === 'push-npm') text = en ? 'remote installs it from npm' : '远端从 npm 安装'
1204
+ }
1066
1205
  const version = row.status === 'conflict' && row.remoteVersion && row.remoteVersion !== row.version
1067
1206
  ? `${row.version} → ${row.remoteVersion}`
1068
1207
  : row.version
@@ -1094,7 +1233,7 @@ function buildView(scope, caps, ctx) {
1094
1233
  const state = stateFor(scope)
1095
1234
  refreshManifests(state, cfg)
1096
1235
  const local = localPluginsCached()
1097
- const rows = diffRows(local, state.manifest, state.manifestSource)
1236
+ const rows = diffRows(local, state.manifest, state.manifestSource, { dshGo: true })
1098
1237
  const components = Array.isArray(caps?.components) ? caps.components : []
1099
1238
  const canForm = components.includes('form') && components.includes('textField')
1100
1239
  const children = []
@@ -1315,7 +1454,7 @@ function stripValue(scope, en) {
1315
1454
  if (task && task.ok === false) return { text: en ? `Sync failed: ${task.failed}` : `同步失败 ${task.failed} 项`, icon: 'warning', tone: 'bad' }
1316
1455
  const state = stateFor(scope)
1317
1456
  if (state.manifest) {
1318
- const rows = diffRows(localPluginsCached(), state.manifest, state.manifestSource)
1457
+ const rows = diffRows(localPluginsCached(), state.manifest, state.manifestSource, { dshGo: true })
1319
1458
  const pending = rows.filter((row) => row.action).length
1320
1459
  if (pending > 0) return { text: en ? `Sync ${pending} left` : `待同步 ${pending} 项`, icon: 'refresh', tone: 'warn' }
1321
1460
  return { text: en ? 'Plugins in sync' : '插件已同步', icon: 'check', tone: 'good' }
@@ -1352,8 +1491,9 @@ function webSnapshot(ctx) {
1352
1491
  const scope = { sessionId: 'web-ui' }
1353
1492
  const state = stateFor(scope)
1354
1493
  const cfg = loadConfig(ctx, scope)
1494
+ refreshManifests(state, cfg)
1355
1495
  const local = localPlugins()
1356
- const rows = diffRows(local, state.manifest, state.manifestSource)
1496
+ const rows = diffRows(local, state.manifest, state.manifestSource, { dshGo: Boolean(ctx.get?.('dshGo')) })
1357
1497
  return {
1358
1498
  plugins: local.map((plugin) => ({
1359
1499
  name: plugin.name,
@@ -1369,6 +1509,7 @@ function webSnapshot(ctx) {
1369
1509
  version: row.version,
1370
1510
  status: row.status,
1371
1511
  action: row.action || null,
1512
+ kind: row.kind || null,
1372
1513
  subtitle: statusLine(row, false),
1373
1514
  })),
1374
1515
  task: readTaskStatus(),
@@ -1470,13 +1611,13 @@ export function apply(ctx) {
1470
1611
  const failed = readTaskResults().filter((result) => !result.ok)
1471
1612
  if (failed.length === 0) return { toast: '没有失败项' }
1472
1613
  const names = new Set(failed.map((result) => result.name))
1473
- const rows = diffRows(localPlugins(), state.manifest, state.manifestSource)
1614
+ const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, { dshGo: true })
1474
1615
  const jobs = rows.filter((row) => names.has(row.name) && row.action)
1475
1616
  if (jobs.length === 0) return { toast: '失败项已不在列表' }
1476
- if (jobs.some((row) => row.action === 'push' || row.action === 'pull') && !cfg.ssh.host) {
1617
+ if (jobs.some((row) => row.action === 'push' || row.action === 'push-npm' || row.action === 'pull') && !cfg.ssh.host) {
1477
1618
  return { toast: '先配置 ssh.host' }
1478
1619
  }
1479
- const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1620
+ const started = startApplyTask(ctx, cfg, jobs)
1480
1621
  if (!started.ok) return { toast: started.error }
1481
1622
  return [{ toast: `重试 ${jobs.length} 项` }, { refresh: true }]
1482
1623
  }
@@ -1505,7 +1646,7 @@ export function apply(ctx) {
1505
1646
  'import-code'(scope, event) {
1506
1647
  const text = codeFromSubmit(event?.value)
1507
1648
  if (text === '') return { toast: '先粘贴同步码' }
1508
- const result = applySyncCode(scope, text, '面板粘贴')
1649
+ const result = applySyncCode(scope, text, '面板粘贴', { dshGo: true })
1509
1650
  if (result.error) return { toast: result.error }
1510
1651
  const toast = result.count === 0
1511
1652
  ? '已导入,没有插件'
@@ -1559,7 +1700,7 @@ export function apply(ctx) {
1559
1700
  for (const plugin of localPlugins()) state.selected.add(plugin.name)
1560
1701
  return { refresh: true }
1561
1702
  }
1562
- const rows = diffRows(localPlugins(), state.manifest, state.manifestSource)
1703
+ const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, { dshGo: true })
1563
1704
  for (const row of rows) state.selected.add(row.name)
1564
1705
  return { refresh: true }
1565
1706
  },
@@ -1591,7 +1732,7 @@ export function apply(ctx) {
1591
1732
  if (event?.value?.confirmed !== true) return { toast: '已取消' }
1592
1733
  const cfg = loadConfig(ctx, scope)
1593
1734
  const state = stateFor(scope)
1594
- const rows = diffRows(localPlugins(), state.manifest, state.manifestSource)
1735
+ const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, { dshGo: true })
1595
1736
  const jobs = rows.filter((row) => state.selected.has(row.name) && row.action)
1596
1737
  if (jobs.length === 0) {
1597
1738
  return { toast: state.selected.size > 0 ? '选中的都已安装' : '没有可执行的项' }
@@ -1599,10 +1740,10 @@ export function apply(ctx) {
1599
1740
  if (jobs.some((job) => job.action === 'install' && !job.localDir && !job.registrySpec)) {
1600
1741
  return { toast: '有项找不到安装来源' }
1601
1742
  }
1602
- if (jobs.some((job) => job.action === 'push' || job.action === 'pull') && !cfg.ssh.host) {
1743
+ if (jobs.some((job) => job.action === 'push' || job.action === 'push-npm' || job.action === 'pull') && !cfg.ssh.host) {
1603
1744
  return { toast: '推/拉远端要先配置 ssh.host' }
1604
1745
  }
1605
- const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1746
+ const started = startApplyTask(ctx, cfg, jobs)
1606
1747
  if (!started.ok) return { toast: started.error }
1607
1748
  state.selected.clear()
1608
1749
  return [{ toast: `已开始处理 ${jobs.length} 项` }, { refresh: true }]
@@ -1681,6 +1822,51 @@ export function apply(ctx) {
1681
1822
  webJson(res, 200, { task: readTaskStatus(), results: readTaskResults() })
1682
1823
  return
1683
1824
  }
1825
+ if (req.method === 'POST' && path === '/dsh-go-plugin-sync/api/action') {
1826
+ const body = JSON.parse((await webReadBody(req)) || '{}')
1827
+ const action = typeof body.action === 'string' ? body.action : ''
1828
+ const scope = { sessionId: 'web-ui' }
1829
+ const cfg = loadConfig(ctx, scope)
1830
+ const state = stateFor(scope)
1831
+ if (action === 'relay-pull') {
1832
+ if (!cfg.relay.repo) { webJson(res, 200, { error: '先配置中转仓' }); return }
1833
+ state.relayLoadedAt = 0
1834
+ const started = startTask('relay-pull', buildRelayPull(cfg))
1835
+ webJson(res, 200, started.ok ? { ok: true } : { error: started.error })
1836
+ return
1837
+ }
1838
+ if (action === 'relay-push') {
1839
+ if (!cfg.relay.repo) { webJson(res, 200, { error: '先配置中转仓' }); return }
1840
+ const local = localPlugins()
1841
+ const pushable = local.filter((plugin) => safeDirName(plugin.relDir))
1842
+ if (pushable.length === 0) { webJson(res, 200, { error: '本机没有可推送的插件' }); return }
1843
+ try {
1844
+ ensureStore()
1845
+ writeFileSync(pushManifestFile(), JSON.stringify(buildManifest(local), null, 2) + '\n')
1846
+ } catch {
1847
+ webJson(res, 200, { error: '写清单失败' })
1848
+ return
1849
+ }
1850
+ const started = startTask('relay-push', buildRelayPush(cfg, pushable, pushManifestFile()))
1851
+ webJson(res, 200, started.ok ? { ok: true, count: pushable.length } : { error: started.error })
1852
+ return
1853
+ }
1854
+ if (action === 'ssh-test') {
1855
+ if (!cfg.ssh.host) { webJson(res, 200, { error: '先配置 ssh.host' }); return }
1856
+ const started = startTask('ssh-test', buildSshTest(cfg))
1857
+ webJson(res, 200, started.ok ? { ok: true } : { error: started.error })
1858
+ return
1859
+ }
1860
+ if (action === 'ssh-scan') {
1861
+ if (!cfg.ssh.host) { webJson(res, 200, { error: '先配置 ssh.host' }); return }
1862
+ state.sshLoadedAt = 0
1863
+ const started = startTask('ssh-scan', buildSshScan(cfg))
1864
+ webJson(res, 200, started.ok ? { ok: true } : { error: started.error })
1865
+ return
1866
+ }
1867
+ webJson(res, 200, { error: '未知操作' })
1868
+ return
1869
+ }
1684
1870
  if (req.method === 'POST' && path === '/dsh-go-plugin-sync/api/config') {
1685
1871
  const body = JSON.parse((await webReadBody(req)) || '{}')
1686
1872
  const next = normalizeConfig(body.config || {})
@@ -1711,7 +1897,7 @@ export function apply(ctx) {
1711
1897
  if (req.method === 'POST' && path === '/dsh-go-plugin-sync/api/import') {
1712
1898
  const body = JSON.parse((await webReadBody(req)) || '{}')
1713
1899
  const code = typeof body.code === 'string' ? body.code : ''
1714
- const result = applySyncCode({ sessionId: 'web-ui' }, code, '网页版')
1900
+ const result = applySyncCode({ sessionId: 'web-ui' }, code, '网页版', { dshGo: Boolean(ctx.get?.('dshGo')) })
1715
1901
  if (result.error) { webJson(res, 200, { error: result.error }); return }
1716
1902
  webJson(res, 200, { ok: true, count: result.count, selected: result.selected })
1717
1903
  return
@@ -1722,13 +1908,13 @@ export function apply(ctx) {
1722
1908
  const scope = { sessionId: 'web-ui' }
1723
1909
  const cfg = loadConfig(ctx, scope)
1724
1910
  const state = stateFor(scope)
1725
- const rows = diffRows(localPlugins(), state.manifest, state.manifestSource)
1911
+ const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, { dshGo: Boolean(ctx.get?.('dshGo')) })
1726
1912
  const jobs = rows.filter((row) => names.includes(row.name) && row.action)
1727
1913
  if (jobs.length === 0) { webJson(res, 200, { error: '没有可安装的项' }); return }
1728
- if (jobs.some((job) => job.action === 'push' || job.action === 'pull') && !cfg.ssh.host) {
1914
+ if (jobs.some((job) => job.action === 'push' || job.action === 'push-npm' || job.action === 'pull') && !cfg.ssh.host) {
1729
1915
  webJson(res, 200, { error: '先配置 ssh.host' }); return
1730
1916
  }
1731
- const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1917
+ const started = startApplyTask(ctx, cfg, jobs)
1732
1918
  if (!started.ok) { webJson(res, 200, { error: started.error }); return }
1733
1919
  state.selected.clear()
1734
1920
  webJson(res, 200, { ok: true, count: jobs.length })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-go-plugin-sync",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "dsh": {