dsh-go-plugin-sync 0.3.3 → 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,49 @@
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
+
37
+ ## 0.3.4 — 2026-12-04
38
+
39
+ ### 电脑端
40
+ - 新增 **设置 → 插件同步** 页面:同步码导入、插件勾选安装、任务状态、Git 中转和 SSH 配置都在设置页完成
41
+ - 移除插件详情页的「打开插件同步网页」按钮和网页版页面,不再依赖浏览器新标签页、DSH 地址或端口
42
+ - 配置保存到 `plugin-sync-config.json`,设置页会显示当前路径
43
+
44
+ ### 说明
45
+ - 手机端原生面板不变;电脑端改用设置页,Windows 同样适用
46
+
3
47
  ## 0.3.3 — 2026-12-04
4
48
 
5
49
  ### 修复
package/README.md CHANGED
@@ -13,6 +13,7 @@
13
13
  - **状态条**:输入框上方显示「待同步 N 项 / 同步失败 N 项 / 插件已同步」
14
14
  - **高级通道**:Git 私有仓中转、SSH 直连(推送 / 拉取 / 拉远端清单)
15
15
  - **使用引导**:面板里的「使用引导」有完整步骤
16
+ - **电脑端设置页**:设置 → 插件同步,导入同步码、勾选安装、配置 Git 中转和 SSH
16
17
 
17
18
  ## 安装
18
19
 
@@ -43,28 +44,34 @@ dsh plugin --profile web add ./dshgochajiantongbucha
43
44
 
44
45
  两端第一次都要手动装一次本插件,之后就能复制粘贴。
45
46
 
46
- ## 网页版(电脑)
47
+ ## 电脑端(设置页)
47
48
 
48
- 电脑上的 DSH Web 可以直接打开内置同步页面,不需要 dsh-go 桥接。装好插件并重启 DSH 后,打开**插件**页,进入「插件同步」详情,点标题旁的**打开插件同步网页**,会在浏览器新标签页打开:
49
+ 电脑上的 DSH 不需要 dsh-go 桥接,也不需要打开网页。装好插件并重启 DSH 后,打开 **设置 → 插件同步**,直接在里面完成:
49
50
 
50
- ```text
51
- http://<DSH 地址>:<端口>/dsh-go-plugin-sync/
52
- ```
51
+ 1. 粘贴同步码,点**导入同步码**
52
+ 2. 在插件列表里勾选要安装的项(默认选中同步码里的插件)
53
+ 3. 点**安装选中**,下方显示任务状态
54
+ 4. 在同一页填写 **Git 中转**(仓库地址 / 分支 / 目录)和 **SSH**(主机 / 端口 / 用户 / 私钥 / profile),点**保存配置**
53
55
 
54
- 地址就是当前 DSH Web 的地址和端口(例如 `http://127.0.0.1:3080/dsh-go-plugin-sync/`)。旧地址 `/local-plugin-sync/` 会自动跳转过来。
56
+ Windows 上支持同步码导入和安装;安装任务由 Node 直接执行,不依赖 `/bin/sh`。Git 中转和 SSH 推/拉暂不支持 Windows。
55
57
 
56
- 页面提供和手机端一样的发送/接收:
58
+ 注意:电脑上装完插件后同样要重启一次 DSH。
57
59
 
58
- 1. 勾选要同步的插件,点**复制同步码**
59
- 2. 在另一台打开同一页面,把同步码粘进输入框,点**导入同步码**
60
- 3. 默认选中同步码里的插件,可以取消;点**安装选中**
61
- 4. 页面下方显示任务状态和逐项结果
60
+ ## 插件类型与方向
62
61
 
63
- 如果页面返回 401:用已经登录 DSH 的同一个浏览器打开;如果返回 404:确认插件已启用并重启过 DSH。
62
+ 同步时会标出插件的运行环境:
64
63
 
65
- Windows 上网页版的同步码发送、导入和「安装选中」都可用;安装任务由 Node 直接执行,不依赖 `/bin/sh`。Git 中转和 SSH 推/拉暂不支持 Windows。
64
+ - **手机原生**:只有 `dshGo`,只能在手机端用
65
+ - **两端可用**:同时有 `dshGo` 和 `dsh.bundle`
66
+ - **电脑/网页**:只有 Cordis/网页半侧,手机能装但没有原生界面
66
67
 
67
- 注意:电脑上装完插件后同样要重启一次 DSH。
68
+ 导入时按方向判断:
69
+
70
+ - 手机的同步码给电脑:手机原生插件标为不支持,不安装
71
+ - 电脑的同步码给手机:电脑/网页插件标为“无原生界面”,默认不选中,可手动勾选
72
+ - 两端可用的插件正常预选和安装
73
+
74
+ 同步码、文件清单、Git 中转、SSH 都使用同一套类型判断;SSH 拉远端清单会同时看手机原生目录和 profile 里的 Cordis bundle。
68
75
 
69
76
  ## 只增不删
70
77
 
package/lib/client.js CHANGED
@@ -3,9 +3,23 @@ window.__ModuleLoader__.load({
3
3
  factory(require) {
4
4
  const React = require('react')
5
5
  const h = React.createElement
6
- const PKG = 'dsh-go-plugin-sync'
6
+ const API = '/dsh-go-plugin-sync/api'
7
+ const zh = (navigator.language || '').toLowerCase().indexOf('zh') === 0
8
+ const T = (cn, en) => (zh ? cn : en)
9
+ const INPUT = {
10
+ width: '100%',
11
+ boxSizing: 'border-box',
12
+ padding: '6px 8px',
13
+ borderRadius: '6px',
14
+ border: '1px solid rgba(128,128,128,.35)',
15
+ background: 'transparent',
16
+ color: 'inherit',
17
+ font: 'inherit',
18
+ fontSize: '13px',
19
+ }
20
+ const LABEL = { display: 'block', margin: '8px 0 0', fontSize: '12px', opacity: 0.7 }
7
21
  const BUTTON = {
8
- padding: '5px 12px',
22
+ padding: '6px 12px',
9
23
  borderRadius: '6px',
10
24
  border: '1px solid rgba(128,128,128,.35)',
11
25
  background: 'transparent',
@@ -14,42 +28,228 @@ window.__ModuleLoader__.load({
14
28
  fontSize: '13px',
15
29
  cursor: 'pointer',
16
30
  }
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
+ }
40
+
41
+ function api(path, body) {
42
+ const options = body === undefined
43
+ ? {}
44
+ : { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }
45
+ return fetch(`${API}/${path}`, options).then((response) => response.json())
46
+ }
17
47
 
18
- const isOurs = (subject) => Boolean(
19
- subject
20
- && (subject.kind === 'bundle' || subject.kind === 'row')
21
- && subject.pkg
22
- && subject.pkg.name === PKG,
23
- )
24
-
25
- function syncUrl() {
26
- const url = new URL('/dsh-go-plugin-sync/', window.location.href)
27
- url.search = window.location.search || ''
28
- url.hash = window.location.hash || ''
29
- return url.href
48
+ function Field({ label, value, onChange, placeholder, type }) {
49
+ return h('label', { style: LABEL }, label,
50
+ h('input', {
51
+ type: type || 'text',
52
+ value: value == null ? '' : String(value),
53
+ placeholder: placeholder || '',
54
+ onChange: (event) => onChange(event.target.value),
55
+ style: { ...INPUT, marginTop: '4px' },
56
+ }))
30
57
  }
31
58
 
32
- function OpenSync(props) {
33
- if (!isOurs(props && props.subject)) return null
34
- const zh = (navigator.language || '').toLowerCase().indexOf('zh') === 0
35
- return h('button', {
36
- type: 'button',
37
- title: syncUrl(),
38
- style: BUTTON,
39
- onClick() {
40
- window.open(syncUrl(), '_blank', 'noopener')
41
- },
42
- }, zh ? '打开插件同步网页' : 'Open plugin sync page')
59
+ function SyncSettings() {
60
+ const [rows, setRows] = React.useState([])
61
+ const [results, setResults] = React.useState([])
62
+ const [picked, setPicked] = React.useState({})
63
+ const [code, setCode] = React.useState('')
64
+ const [config, setConfig] = React.useState(null)
65
+ const [status, setStatus] = React.useState('')
66
+ const [tone, setTone] = React.useState('')
67
+ const [busy, setBusy] = React.useState(false)
68
+ const [configPath, setConfigPath] = React.useState('')
69
+ const wasRunning = React.useRef(false)
70
+
71
+ const note = (text, kind) => { setStatus(text); setTone(kind || '') }
72
+
73
+ const load = () => api('state').then((snapshot) => {
74
+ if (snapshot.error) { note(snapshot.error, 'bad'); return }
75
+ setRows(snapshot.rows || [])
76
+ setResults(snapshot.results || [])
77
+ setConfig(snapshot.config || null)
78
+ setConfigPath(snapshot.configPath || '')
79
+ const next = {}
80
+ for (const name of snapshot.selected || []) next[name] = true
81
+ setPicked(next)
82
+ }).catch((error) => note(String(error && error.message || error), 'bad'))
83
+
84
+ React.useEffect(() => { load() }, [])
85
+ React.useEffect(() => {
86
+ const timer = setInterval(() => {
87
+ api('status').then((snapshot) => {
88
+ if (snapshot.results) setResults(snapshot.results)
89
+ if (!snapshot.task) return
90
+ if (snapshot.task.running) note(T('正在执行…', 'Running…'))
91
+ else if (snapshot.task.ok === false) note(T(`上次失败 ${snapshot.task.failed} 项`, `Last run failed: ${snapshot.task.failed}`), 'bad')
92
+ else note(T('上次完成', 'Last run finished'), 'good')
93
+ if (wasRunning.current && !snapshot.task.running) load()
94
+ wasRunning.current = snapshot.task.running
95
+ }).catch(() => {})
96
+ }, 3000)
97
+ return () => clearInterval(timer)
98
+ }, [])
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
+ : ''
107
+ const toggle = (name, checked) => setPicked((previous) => ({ ...previous, [name]: checked }))
108
+ const all = (checked) => {
109
+ const next = {}
110
+ for (const row of rows) next[row.name] = checked
111
+ setPicked(next)
112
+ }
113
+ const importCode = () => {
114
+ if (!code.trim()) { note(T('先粘贴同步码', 'Paste a sync code first'), 'bad'); return }
115
+ setBusy(true)
116
+ api('import', { code }).then((result) => {
117
+ setBusy(false)
118
+ if (result.error) { note(result.error, 'bad'); return }
119
+ setCode('')
120
+ note(T(`已导入 ${result.count} 个插件,选中 ${result.selected} 个`, `Imported ${result.count}, selected ${result.selected}`), 'good')
121
+ load()
122
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
123
+ }
124
+ const applySelected = () => {
125
+ const names = rows.filter((row) => row.action && picked[row.name]).map((row) => row.name)
126
+ if (names.length === 0) { note(T('先选择要安装的插件', 'Select plugins to install'), 'bad'); return }
127
+ setBusy(true)
128
+ api('apply', { names }).then((result) => {
129
+ setBusy(false)
130
+ if (result.error) { note(result.error, 'bad'); return }
131
+ note(T(`已开始执行 ${result.count} 项`, `Running ${result.count}`), 'good')
132
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
133
+ }
134
+ const setPath = (path, value) => setConfig((previous) => {
135
+ const next = { ...previous }
136
+ const keys = path.split('.')
137
+ let cursor = next
138
+ for (let index = 0; index < keys.length - 1; index += 1) {
139
+ cursor[keys[index]] = { ...(cursor[keys[index]] || {}) }
140
+ cursor = cursor[keys[index]]
141
+ }
142
+ cursor[keys[keys.length - 1]] = value
143
+ return next
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
+ }
153
+ const saveConfig = () => {
154
+ if (!config) { note(T('配置还没加载完,稍后再试', 'Configuration is not loaded yet'), 'bad'); return }
155
+ setBusy(true)
156
+ api('config', { config }).then((result) => {
157
+ setBusy(false)
158
+ if (result.error) { note(result.error, 'bad'); return }
159
+ setConfig(result.config)
160
+ setConfigPath(result.path || configPath)
161
+ note(T('配置已保存', 'Configuration saved'), 'good')
162
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
163
+ }
164
+
165
+ const relay = config && config.relay ? config.relay : { repo: '', branch: 'main', dir: 'dsh-go-plugins' }
166
+ const ssh = config && config.ssh ? config.ssh : { host: '', port: 22, user: '', identity: '', remoteHome: '~/.dsh', dshPath: 'dsh', nodePath: 'node', profile: 'web' }
167
+
168
+ return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '14px', maxWidth: '760px' } },
169
+ h('div', { style: { fontSize: '13px', opacity: 0.7 } },
170
+ T('从同步码安装缺少的插件;只增不删,冲突只提示。', 'Install missing plugins from a sync code. Add-only: conflicts are warnings.')),
171
+
172
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
173
+ h('div', { style: { fontWeight: 600 } }, T('同步码', 'Sync code')),
174
+ h('textarea', {
175
+ value: code,
176
+ rows: 4,
177
+ placeholder: 'DSHSYNC1:…',
178
+ onChange: (event) => setCode(event.target.value),
179
+ style: { ...INPUT, fontFamily: 'ui-monospace, monospace', minHeight: '80px', resize: 'vertical' },
180
+ }),
181
+ h('div', { style: { display: 'flex', gap: '8px' } },
182
+ h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: importCode }, T('导入同步码', 'Import code')),
183
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: load }, T('刷新', 'Refresh')))),
184
+
185
+ rows.length > 0 && h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
186
+ h('div', { style: { fontWeight: 600 } }, T('待处理插件', 'Plugins')),
187
+ ...rows.map((row) => h('label', {
188
+ key: row.name,
189
+ style: { display: 'flex', alignItems: 'center', gap: '8px', padding: '4px 0', opacity: row.action ? 1 : 0.55 },
190
+ },
191
+ h('input', {
192
+ type: 'checkbox',
193
+ checked: Boolean(picked[row.name]),
194
+ disabled: !row.action,
195
+ onChange: (event) => toggle(row.name, event.target.checked),
196
+ }),
197
+ h('span', { style: { fontWeight: 500 } }, row.name),
198
+ row.kind && h('span', { style: BADGE }, kindLabel(row.kind)),
199
+ h('span', { style: { marginLeft: 'auto', fontSize: '12px', opacity: 0.65 } }, row.subtitle || row.status))),
200
+ h('div', { style: { display: 'flex', gap: '8px', marginTop: '4px' } },
201
+ h('button', { type: 'button', style: BUTTON, onClick: () => all(true) }, T('全选', 'Select all')),
202
+ h('button', { type: 'button', style: BUTTON, onClick: () => all(false) }, T('清空', 'Clear')),
203
+ h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: applySelected }, T('执行选中', 'Run selected')))),
204
+
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}` : ''}`))),
211
+
212
+ h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
213
+ h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('Git 中转(可选)', 'Git relay (optional)')),
214
+ h(Field, { label: T('仓库地址', 'Repository'), value: relay.repo, onChange: (value) => setPath('relay.repo', value), placeholder: 'https://gitee.com/you/dsh-plugins.git' }),
215
+ h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' } },
216
+ h(Field, { label: T('分支', 'Branch'), value: relay.branch, onChange: (value) => setPath('relay.branch', value) }),
217
+ h(Field, { label: T('目录', 'Directory'), value: relay.dir, onChange: (value) => setPath('relay.dir', value) }))),
218
+
219
+ h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
220
+ h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('SSH(可选)', 'SSH (optional)')),
221
+ h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' } },
222
+ h(Field, { label: T('主机', 'Host'), value: ssh.host, onChange: (value) => setPath('ssh.host', value), placeholder: '192.168.1.10' }),
223
+ h(Field, { label: T('端口', 'Port'), value: ssh.port, onChange: (value) => setPath('ssh.port', Number(value) || 22), type: 'number' }),
224
+ h(Field, { label: T('用户', 'User'), value: ssh.user, onChange: (value) => setPath('ssh.user', value) }),
225
+ h(Field, { label: T('私钥路径', 'Identity file'), value: ssh.identity, onChange: (value) => setPath('ssh.identity', value), placeholder: '~/.ssh/id_ed25519' }),
226
+ h(Field, { label: T('远端 HOME', 'Remote home'), value: ssh.remoteHome, onChange: (value) => setPath('ssh.remoteHome', value) }),
227
+ h(Field, { label: T('profile', 'Profile'), value: ssh.profile, onChange: (value) => setPath('ssh.profile', value) }))),
228
+
229
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: '10px', flexWrap: 'wrap' } },
230
+ h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: saveConfig }, T('保存配置', 'Save configuration')),
231
+ configPath && h('span', { style: { fontSize: '12px', opacity: 0.6, wordBreak: 'break-all' } }, configPath)),
232
+
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.'))))
43
242
  }
44
243
 
45
244
  return {
46
245
  inject: ['slots'],
47
246
  apply(ctx) {
48
- ctx.slots.inject('plugins.detail.actions', () => ctx.slots.register({
49
- name: 'plugins.detail.actions',
50
- id: 'dsh-go-plugin-sync-open',
51
- order: 100,
52
- }, OpenSync))
247
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
248
+ name: 'settings.section',
249
+ id: 'dsh-go-plugin-sync',
250
+ order: 50,
251
+ label: () => T('插件同步', 'Plugin sync'),
252
+ }, SyncSettings))
53
253
  },
54
254
  }
55
255
  },
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,84 +1509,24 @@ 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(),
1375
1516
  results: readTaskResults(),
1376
- config: { relay: Boolean(cfg.relay.repo), ssh: Boolean(cfg.ssh.host) },
1517
+ config: cfg,
1518
+ configPath: configPathFor(ctx, scope),
1377
1519
  }
1378
1520
  }
1379
1521
 
1380
- function webPageHtml() {
1381
- return `<!doctype html>
1382
- <html lang="zh-CN">
1383
- <head>
1384
- <meta charset="utf-8">
1385
- <meta name="viewport" content="width=device-width, initial-scale=1">
1386
- <title>插件同步</title>
1387
- <style>
1388
- :root{color-scheme:light dark}
1389
- body{font:14px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:0;padding:16px;max-width:820px;margin-inline:auto}
1390
- h1{font-size:20px;margin:0 0 4px}h2{font-size:15px;margin:20px 0 8px}
1391
- .muted{opacity:.65}.row{display:flex;gap:8px;flex-wrap:wrap;margin:8px 0}
1392
- button{font:inherit;padding:7px 12px;border-radius:8px;border:1px solid #8884;background:#8881;cursor:pointer}
1393
- button.primary{background:#3D6FD6;border-color:#3D6FD6;color:#fff}
1394
- button:disabled{opacity:.5;cursor:default}
1395
- textarea{width:100%;box-sizing:border-box;min-height:88px;font:12px/1.4 ui-monospace,monospace;padding:8px;border-radius:8px;border:1px solid #8884;background:#8881}
1396
- ul{list-style:none;padding:0;margin:0}
1397
- li.item{display:flex;align-items:center;gap:8px;padding:6px 4px;border-bottom:1px solid #8882}
1398
- li.item .name{font-weight:600}li.item .meta{margin-left:auto;font-size:12px;opacity:.7}
1399
- .status{font-size:12px;opacity:.8}.bad{color:#c62828}.good{color:#2e7d32}
1400
- </style>
1401
- </head>
1402
- <body>
1403
- <h1>插件同步</h1>
1404
- <div id="addr" class="muted"></div>
1405
- <div class="muted">复制同步码到另一台主机导入;只安装缺少的插件,不卸载、不覆盖。</div>
1406
- <div id="config" class="muted"></div>
1407
-
1408
- <h2>发送(本机 → 同步码)</h2>
1409
- <ul id="plugins"></ul>
1410
- <div class="row">
1411
- <button id="all">全选</button>
1412
- <button id="none">清空</button>
1413
- <button id="copy" class="primary">复制同步码</button>
1414
- </div>
1415
- <textarea id="code" placeholder="生成的同步码会显示在这里" readonly></textarea>
1416
-
1417
- <h2>接收(同步码 → 本机)</h2>
1418
- <textarea id="importCode" placeholder="粘贴 DSHSYNC1: 开头的同步码"></textarea>
1419
- <div class="row"><button id="import" class="primary">导入同步码</button></div>
1420
- <ul id="diff"></ul>
1421
- <div class="row"><button id="apply" class="primary">安装选中</button></div>
1422
-
1423
- <h2>状态</h2>
1424
- <div id="status" class="status"></div>
1425
- <div id="results"></div>
1426
- <script>
1427
- (function(){
1428
- var localSelected=new Set(), diffSelected=new Set(), current={}, lastKey=null, wasRunning=false;
1429
- function el(t,c,x){var n=document.createElement(t);if(c)n.className=c;if(x!=null)n.textContent=x;return n}
1430
- (function(){var a=document.getElementById('addr');if(a)a.textContent='地址:'+location.origin+'/dsh-go-plugin-sync/'})();
1431
- function api(p,b){var o=b===undefined?{}:{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(b)};return fetch('api/'+p,o).then(function(r){return r.json()})}
1432
- function setStatus(t,c){var n=document.getElementById('status');n.textContent=t;n.className='status'+(c?' '+c:'')}
1433
- function renderPlugins(list){var ul=document.getElementById('plugins');ul.textContent='';(list||[]).forEach(function(p){var li=el('li','item');var cb=el('input');cb.type='checkbox';cb.checked=localSelected.has(p.name);cb.onchange=function(){if(cb.checked)localSelected.add(p.name);else localSelected.delete(p.name)};li.appendChild(cb);li.appendChild(el('span','name',p.name));li.appendChild(el('span','meta','v'+p.version+(p.installed?' · 已安装':' · 未安装')));ul.appendChild(li)})}
1434
- function renderDiff(rows){var ul=document.getElementById('diff');ul.textContent='';if(!rows||!rows.length){ul.appendChild(el('li','muted','导入后在这里选择要安装的插件'));return}rows.forEach(function(r){var li=el('li','item');var cb=el('input');cb.type='checkbox';cb.disabled=!r.action;cb.checked=diffSelected.has(r.name);cb.onchange=function(){if(cb.checked)diffSelected.add(r.name);else diffSelected.delete(r.name)};li.appendChild(cb);li.appendChild(el('span','name',r.name));li.appendChild(el('span','meta',r.subtitle));ul.appendChild(li)})}
1435
- function renderResults(list){var box=document.getElementById('results');box.textContent='';(list||[]).forEach(function(r){box.appendChild(el('div',r.ok?'good':'bad',(r.ok?'✓ ':'✗ ')+r.name+(r.message?' — '+r.message:'')))})}
1436
- function renderTask(t){if(!t){setStatus('就绪');return}if(t.running){setStatus('正在执行…');return}setStatus(t.ok===false?('上次失败 '+t.failed+' 项'):'上次完成',t.ok===false?'bad':'good')}
1437
- function manifestKey(s){var m=s&&s.manifest;return (m&&m.exportedAt||'')+'|'+((m&&m.plugins)||[]).map(function(p){return p.name}).join(',')}
1438
- function refresh(){return api('state').then(function(s){if(s.error){setStatus(s.error,'bad');return}current=s;var key=manifestKey(s);if(key!==lastKey){lastKey=key;localSelected=new Set(s.selected||[]);diffSelected=new Set(s.selected||[])}renderPlugins(s.plugins);renderDiff(s.rows);renderResults(s.results);renderTask(s.task);var c=s.config||{};document.getElementById('config').textContent='中转:'+(c.relay?'已配置':'未配置')+' · SSH:'+(c.ssh?'已配置':'未配置')})}
1439
- function poll(){api('status').then(function(s){if(s.task){renderTask(s.task);if(wasRunning&&!s.task.running)refresh();wasRunning=s.task.running}else{wasRunning=false}if(s.results)renderResults(s.results)}).catch(function(){})}
1440
- document.getElementById('all').onclick=function(){(current.plugins||[]).forEach(function(p){localSelected.add(p.name)});renderPlugins(current.plugins)};
1441
- document.getElementById('none').onclick=function(){localSelected.clear();renderPlugins(current.plugins)};
1442
- document.getElementById('copy').onclick=function(){api('export',{names:Array.from(localSelected)}).then(function(r){if(r.error){setStatus(r.error,'bad');return}document.getElementById('code').value=r.code;if(navigator.clipboard)navigator.clipboard.writeText(r.code).catch(function(){});setStatus('已生成 '+r.count+' 个插件的同步码','good')})};
1443
- document.getElementById('import').onclick=function(){var code=document.getElementById('importCode').value.trim();if(!code){setStatus('先粘贴同步码','bad');return}api('import',{code:code}).then(function(r){if(r.error){setStatus(r.error,'bad');return}lastKey=null;setStatus('已导入 '+r.count+' 个插件,选中 '+r.selected+' 个','good');refresh()})};
1444
- document.getElementById('apply').onclick=function(){var names=Array.from(diffSelected);if(!names.length){setStatus('先选择要安装的插件','bad');return}api('apply',{names:names}).then(function(r){if(r.error){setStatus(r.error,'bad');return}names.forEach(function(n){diffSelected.delete(n)});setStatus('已开始安装 '+r.count+' 项','good');refresh()})};
1445
- refresh();setInterval(poll,3000);
1446
- })();
1447
- </script>
1448
- </body>
1449
- </html>`
1522
+ /** Where the next saved config will live: an existing workspace file, else the store. */
1523
+ function configPathFor(ctx, scope) {
1524
+ const ws = writableDir(ctx, scope)
1525
+ if (ws) {
1526
+ const path = join(ws, CONFIG_FILE)
1527
+ if (existsSync(path)) return path
1528
+ }
1529
+ return join(storeDir(), CONFIG_FILE)
1450
1530
  }
1451
1531
 
1452
1532
  // ---------------------------------------------------------------- plugin
@@ -1531,13 +1611,13 @@ export function apply(ctx) {
1531
1611
  const failed = readTaskResults().filter((result) => !result.ok)
1532
1612
  if (failed.length === 0) return { toast: '没有失败项' }
1533
1613
  const names = new Set(failed.map((result) => result.name))
1534
- const rows = diffRows(localPlugins(), state.manifest, state.manifestSource)
1614
+ const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, { dshGo: true })
1535
1615
  const jobs = rows.filter((row) => names.has(row.name) && row.action)
1536
1616
  if (jobs.length === 0) return { toast: '失败项已不在列表' }
1537
- 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) {
1538
1618
  return { toast: '先配置 ssh.host' }
1539
1619
  }
1540
- const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1620
+ const started = startApplyTask(ctx, cfg, jobs)
1541
1621
  if (!started.ok) return { toast: started.error }
1542
1622
  return [{ toast: `重试 ${jobs.length} 项` }, { refresh: true }]
1543
1623
  }
@@ -1566,7 +1646,7 @@ export function apply(ctx) {
1566
1646
  'import-code'(scope, event) {
1567
1647
  const text = codeFromSubmit(event?.value)
1568
1648
  if (text === '') return { toast: '先粘贴同步码' }
1569
- const result = applySyncCode(scope, text, '面板粘贴')
1649
+ const result = applySyncCode(scope, text, '面板粘贴', { dshGo: true })
1570
1650
  if (result.error) return { toast: result.error }
1571
1651
  const toast = result.count === 0
1572
1652
  ? '已导入,没有插件'
@@ -1620,7 +1700,7 @@ export function apply(ctx) {
1620
1700
  for (const plugin of localPlugins()) state.selected.add(plugin.name)
1621
1701
  return { refresh: true }
1622
1702
  }
1623
- const rows = diffRows(localPlugins(), state.manifest, state.manifestSource)
1703
+ const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, { dshGo: true })
1624
1704
  for (const row of rows) state.selected.add(row.name)
1625
1705
  return { refresh: true }
1626
1706
  },
@@ -1652,7 +1732,7 @@ export function apply(ctx) {
1652
1732
  if (event?.value?.confirmed !== true) return { toast: '已取消' }
1653
1733
  const cfg = loadConfig(ctx, scope)
1654
1734
  const state = stateFor(scope)
1655
- const rows = diffRows(localPlugins(), state.manifest, state.manifestSource)
1735
+ const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, { dshGo: true })
1656
1736
  const jobs = rows.filter((row) => state.selected.has(row.name) && row.action)
1657
1737
  if (jobs.length === 0) {
1658
1738
  return { toast: state.selected.size > 0 ? '选中的都已安装' : '没有可执行的项' }
@@ -1660,10 +1740,10 @@ export function apply(ctx) {
1660
1740
  if (jobs.some((job) => job.action === 'install' && !job.localDir && !job.registrySpec)) {
1661
1741
  return { toast: '有项找不到安装来源' }
1662
1742
  }
1663
- 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) {
1664
1744
  return { toast: '推/拉远端要先配置 ssh.host' }
1665
1745
  }
1666
- const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1746
+ const started = startApplyTask(ctx, cfg, jobs)
1667
1747
  if (!started.ok) return { toast: started.error }
1668
1748
  state.selected.clear()
1669
1749
  return [{ toast: `已开始处理 ${jobs.length} 项` }, { refresh: true }]
@@ -1734,16 +1814,6 @@ export function apply(ctx) {
1734
1814
  if (rejection !== undefined) { res.writeHead(rejection); res.end(); return }
1735
1815
  const url = new URL(req.url || '/', 'http://dsh.local')
1736
1816
  const path = url.pathname.replace(/\/+$/, '') || '/'
1737
- if (url.pathname === '/local-plugin-sync' || url.pathname.startsWith('/local-plugin-sync/')) {
1738
- res.writeHead(302, { location: `/dsh-go-plugin-sync${url.pathname.slice('/local-plugin-sync'.length)}${url.search || ''}` })
1739
- res.end()
1740
- return
1741
- }
1742
- if (req.method === 'GET' && (path === '/dsh-go-plugin-sync' || url.pathname === '/dsh-go-plugin-sync/')) {
1743
- res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
1744
- res.end(webPageHtml())
1745
- return
1746
- }
1747
1817
  if (req.method === 'GET' && path === '/dsh-go-plugin-sync/api/state') {
1748
1818
  webJson(res, 200, webSnapshot(ctx))
1749
1819
  return
@@ -1752,6 +1822,67 @@ export function apply(ctx) {
1752
1822
  webJson(res, 200, { task: readTaskStatus(), results: readTaskResults() })
1753
1823
  return
1754
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
+ }
1870
+ if (req.method === 'POST' && path === '/dsh-go-plugin-sync/api/config') {
1871
+ const body = JSON.parse((await webReadBody(req)) || '{}')
1872
+ const next = normalizeConfig(body.config || {})
1873
+ const scope = { sessionId: 'web-ui' }
1874
+ const target = configPathFor(ctx, scope)
1875
+ try {
1876
+ ensureStore()
1877
+ mkdirSync(dirname(target), { recursive: true })
1878
+ writeFileSync(target, JSON.stringify(next, null, 2) + '\n')
1879
+ } catch {
1880
+ webJson(res, 200, { error: '保存配置失败' })
1881
+ return
1882
+ }
1883
+ webJson(res, 200, { ok: true, config: next, path: target })
1884
+ return
1885
+ }
1755
1886
  if (req.method === 'POST' && path === '/dsh-go-plugin-sync/api/export') {
1756
1887
  const body = JSON.parse((await webReadBody(req)) || '{}')
1757
1888
  const names = Array.isArray(body.names) ? body.names.filter((n) => typeof n === 'string') : []
@@ -1766,7 +1897,7 @@ export function apply(ctx) {
1766
1897
  if (req.method === 'POST' && path === '/dsh-go-plugin-sync/api/import') {
1767
1898
  const body = JSON.parse((await webReadBody(req)) || '{}')
1768
1899
  const code = typeof body.code === 'string' ? body.code : ''
1769
- const result = applySyncCode({ sessionId: 'web-ui' }, code, '网页版')
1900
+ const result = applySyncCode({ sessionId: 'web-ui' }, code, '网页版', { dshGo: Boolean(ctx.get?.('dshGo')) })
1770
1901
  if (result.error) { webJson(res, 200, { error: result.error }); return }
1771
1902
  webJson(res, 200, { ok: true, count: result.count, selected: result.selected })
1772
1903
  return
@@ -1777,13 +1908,13 @@ export function apply(ctx) {
1777
1908
  const scope = { sessionId: 'web-ui' }
1778
1909
  const cfg = loadConfig(ctx, scope)
1779
1910
  const state = stateFor(scope)
1780
- const rows = diffRows(localPlugins(), state.manifest, state.manifestSource)
1911
+ const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, { dshGo: Boolean(ctx.get?.('dshGo')) })
1781
1912
  const jobs = rows.filter((row) => names.includes(row.name) && row.action)
1782
1913
  if (jobs.length === 0) { webJson(res, 200, { error: '没有可安装的项' }); return }
1783
- 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) {
1784
1915
  webJson(res, 200, { error: '先配置 ssh.host' }); return
1785
1916
  }
1786
- const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1917
+ const started = startApplyTask(ctx, cfg, jobs)
1787
1918
  if (!started.ok) { webJson(res, 200, { error: started.error }); return }
1788
1919
  state.selected.clear()
1789
1920
  webJson(res, 200, { ok: true, count: jobs.length })
@@ -1801,7 +1932,7 @@ export function apply(ctx) {
1801
1932
  const host = String(ws.host || '127.0.0.1')
1802
1933
  const shown = host === '0.0.0.0' || host === '::' ? '127.0.0.1' : host
1803
1934
  const bracketed = shown.includes(':') ? `[${shown}]` : shown
1804
- console.log(`[dsh-go-plugin-sync] 插件同步网页:${ws.protocol || 'http:'}//${bracketed}:${ws.port}/dsh-go-plugin-sync/`)
1935
+ console.log(`[dsh-go-plugin-sync] 设置页 API:${ws.protocol || 'http:'}//${bracketed}:${ws.port}/dsh-go-plugin-sync/api/`)
1805
1936
  } catch {}
1806
1937
  })
1807
1938
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-go-plugin-sync",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "dsh": {
@@ -11,7 +11,7 @@
11
11
  "platform": "web",
12
12
  "immediately": true,
13
13
  "inject": [
14
- "@deepseek-ai/dsh-client-ui-plugin-manager"
14
+ "@deepseek-ai/dsh-client-ui-settings"
15
15
  ]
16
16
  }
17
17
  },