dsh-go-plugin-sync 0.4.1 → 0.4.3

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,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.3 — 2026-12-04
4
+
5
+ ### 改进
6
+ - dsh-go 面板按钮精简:「全选/取消全选」合并成一个切换;去掉「导出清单」「工作区导入」;「清空清单」改名「重置清单」;「重试失败」只在有失败项时出现并带数量;「使用引导」保留
7
+ - 「使用引导」改成纯文字说明,不再带操作按钮;安装失败日志补充 target(装的是哪个目录或哪个包)
8
+ - 安装失败会自动补一行「原因:」白话结论(超时、断网、权限、缺文件、包不存在、依赖冲突、该端不支持),电脑端和 dsh-go 面板都能看到;日志尾部展示行数增加(dsh-go 8 行、电脑端 12 行);修复「没有可安装来源」时原因写在失败标记之后导致读不到的顺序问题
9
+ - 失败归因更准:404 与版本不兼容不再误判成缺文件;pnpm 原文只在 packageResult.output 里时也能归因;结果行优先显示「target + 原因」,超长时保留尾部
10
+ - 取消任务改为按轮次隔离(run token):取消后旧循环不能再写日志/状态,也不会把剩余项装进新任务;取消结果行显示「任务被用户取消」而不是 stop 时间戳
11
+ - pnpm 原文与安装器 logPath 会写进任务日志(原因行之前),日志尾部能看到原始错误
12
+ - dsh-go 面板只列清单里的待处理插件:新增「待处理插件(N)」标题,去掉本机插件列表,清单外(仅本机有)的插件也不再显示;复制同步码在没选插件时默认带上全部本机插件
13
+ - dsh-go 面板的清单列表按电脑端风格精简:每行只显示名称和一句短状态,不再重复版本号与动作后缀;状态文案改为「可安装」「本地已有」「本地已有,版本不同」「仅dshgo」「仅电脑/网页」「缺文件」等;未选中项不再显示圆圈,选中后才出现 ✓
14
+ - 本地插件列表同样只保留名称 + 版本,可安装项排在前面
15
+
16
+ ## 0.4.2 — 2026-12-04
17
+
18
+ ### 修复
19
+ - 任务卡死可处理:任务状态里记录进程号,电脑端与 dsh-go 面板的进行中任务旁新增「取消任务」,会终止任务进程并把状态标记为已取消
20
+ - 单个安装命令超过 600 秒自动终止并记为失败(此前 pnpm 卡住时任务会一直显示运行中),POSIX 上使用 `timeout`,Windows 的 Node 任务器内置同样的超时
21
+ - 待处理列表把可安装项排在前面,不能安装的项在电脑端保持浅色弱化,dsh-go 面板同样按可安装优先排序
22
+
3
23
  ## 0.4.1 — 2026-12-04
4
24
 
5
25
  ### 改进
package/lib/client.js CHANGED
@@ -120,6 +120,7 @@ window.__ModuleLoader__.load({
120
120
  const toggle = (name, checked) => setPicked((previous) => ({ ...previous, [name]: checked }))
121
121
  const installedRows = rows.filter((row) => row.status === 'same')
122
122
  const pendingRows = rows.filter((row) => row.status !== 'same')
123
+ .slice().sort((a, b) => Number(Boolean(b.action)) - Number(Boolean(a.action)))
123
124
  const all = (checked) => {
124
125
  const next = {}
125
126
  for (const row of pendingRows) next[row.name] = checked
@@ -193,6 +194,16 @@ window.__ModuleLoader__.load({
193
194
  load()
194
195
  }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
195
196
  }
197
+ const stopRun = () => {
198
+ if (!window.confirm(T('取消当前任务?已完成的项不会回滚。', 'Stop the running task? Finished items are not rolled back.'))) return
199
+ setBusy(true)
200
+ api('action', { action: 'stop' }).then((result) => {
201
+ setBusy(false)
202
+ if (result.error) { note(result.error, 'bad'); return }
203
+ note(T('已取消任务', 'Task cancelled'), 'good')
204
+ load()
205
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
206
+ }
196
207
  const setPath = (path, value) => setConfig((previous) => {
197
208
  const next = { ...previous }
198
209
  const keys = path.split('.')
@@ -242,7 +253,12 @@ window.__ModuleLoader__.load({
242
253
  running
243
254
  ? T(`${actionLabel(task.kind)}中${current ? `:${current.name}` : '(准备中)'}`, `${actionLabel(task.kind)}${current ? `: ${current.name}` : ' (preparing)'}`)
244
255
  : T(`上次${actionLabel(task.kind)}结束`, `Last ${actionLabel(task.kind)} ended`),
245
- running && h('span', { style: { marginLeft: 'auto', fontSize: '12px', fontWeight: 400, opacity: 0.7 } }, `${elapsed}s`)),
256
+ running && h('button', {
257
+ type: 'button',
258
+ style: { ...BUTTON, marginLeft: 'auto', padding: '1px 8px', fontSize: '12px' },
259
+ onClick: stopRun,
260
+ }, T('取消任务', 'Stop')),
261
+ running && h('span', { style: { fontSize: '12px', fontWeight: 400, opacity: 0.7 } }, `${elapsed}s`)),
246
262
  running && h('div', { style: { height: '4px', borderRadius: '2px', background: 'rgba(128,128,128,.25)', overflow: 'hidden' } },
247
263
  h('div', {
248
264
  style: {
package/lib/index.js CHANGED
@@ -15,7 +15,7 @@
15
15
  import { spawn } from 'node:child_process'
16
16
  import { createHash } from 'node:crypto'
17
17
  import {
18
- accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync,
18
+ accessSync, appendFileSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync,
19
19
  } from 'node:fs'
20
20
  import { homedir } from 'node:os'
21
21
  import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path'
@@ -710,7 +710,7 @@ function readTaskStatus() {
710
710
  try {
711
711
  const parts = readFileSync(taskStatusPath(), 'utf8').trim().split(/\s+/)
712
712
  const started = Number(parts[1]) || 0
713
- if (parts[0] === 'running') return { running: true, startedAt: started * 1000, kind: parts[2] || '' }
713
+ if (parts[0] === 'running') return { running: true, startedAt: started * 1000, kind: parts[2] || '', pid: Number(parts[3]) || 0 }
714
714
  if (parts[0] === 'done') {
715
715
  const failed = Number(parts[2]) || 0
716
716
  return { running: false, finishedAt: started * 1000, failed, kind: parts[3] || '', ok: failed === 0 }
@@ -758,11 +758,18 @@ function readTaskResults() {
758
758
  continue
759
759
  }
760
760
  if (current && current.action === action && current.name === name) {
761
+ const targetLine = current.lines.find((line) => line.startsWith('target '))
762
+ const hintLine = current.lines.find((line) => line.startsWith('原因:'))
763
+ const others = current.lines.filter((line) => line.trim() !== '' && !line.startsWith('target ') && !line.startsWith('原因:') && !line.startsWith('stop '))
764
+ const parts = [targetLine, hintLine]
765
+ if (!hintLine && others.length > 0) parts.push(others[others.length - 1])
761
766
  results.push({
762
767
  action,
763
768
  name,
764
769
  ok: phase === 'ok',
765
- message: phase === 'fail' ? current.lines.slice(-2).join(' ').slice(0, 140) : '',
770
+ message: phase === 'fail'
771
+ ? (parts.filter(Boolean).join(' ').slice(-200) || current.lines.slice(-3).join(' ').slice(-200))
772
+ : '',
766
773
  })
767
774
  current = undefined
768
775
  }
@@ -798,6 +805,40 @@ function taskRunning() {
798
805
  return Boolean(status?.running && Date.now() - status.startedAt < 15 * 60 * 1000)
799
806
  }
800
807
 
808
+ /** Per-run token: cancelling marks the current run so it can never write into the next task. */
809
+ let installRun = 0
810
+ let cancelledRun = -1
811
+
812
+ /** Kill the running task (its status line carries the pid) and mark it cancelled. */
813
+ function stopTask() {
814
+ const status = readTaskStatus()
815
+ if (!status?.running) return { ok: false, error: '没有在运行的任务' }
816
+ const pid = Number(status.pid) || 0
817
+ if (pid > 0) {
818
+ try {
819
+ if (process.platform === 'win32') {
820
+ spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { stdio: 'ignore' })
821
+ } else {
822
+ try { process.kill(-pid, 'SIGTERM') } catch { try { process.kill(pid, 'SIGTERM') } catch {} }
823
+ }
824
+ } catch {}
825
+ }
826
+ cancelledRun = installRun
827
+ const current = readTaskCurrent()
828
+ try {
829
+ let note = '任务被用户取消\n'
830
+ note += `stop ${Math.floor(Date.now() / 1000)}\n`
831
+ if (current) note += `@@ ${current.action} ${current.name} fail\n`
832
+ appendFileSync(taskLogPath(), note)
833
+ } catch {}
834
+ const failed = readTaskResults().filter((result) => !result.ok).length
835
+ const stoppedFailed = status.kind === 'install' ? Math.max(1, failed) : failed
836
+ try {
837
+ writeFileSync(taskStatusPath(), `done ${Math.floor(Date.now() / 1000)} ${stoppedFailed} ${status.kind || 'apply'}\n`)
838
+ } catch {}
839
+ return { ok: true, pid }
840
+ }
841
+
801
842
  /** Start one background task; returns `{ ok }` or an explanation of why it did not start. */
802
843
  function startTask(kind, lines, win) {
803
844
  if (taskRunning()) return { ok: false, error: '已有任务在运行,等它结束再试' }
@@ -810,7 +851,9 @@ function startTask(kind, lines, win) {
810
851
  `STATUS=${shQuote(taskStatusPath())}`,
811
852
  `PROFILE=${shQuote(profileName())}`,
812
853
  'DSH_BIN="${DSH_BIN:-$(command -v dsh || echo /usr/local/bin/dsh)}"',
854
+ 'TIMEOUT=""; if command -v timeout >/dev/null 2>&1; then TIMEOUT="timeout 600"; fi',
813
855
  ': > "$LOG"',
856
+ `echo "running $(date +%s) ${kind} $$" > "$STATUS"`,
814
857
  'failed=0',
815
858
  'say() { echo "$@" >> "$LOG"; }',
816
859
  ...lines,
@@ -877,10 +920,15 @@ const spec = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'))
877
920
  const log = fs.openSync(spec.log, 'w')
878
921
  const say = (line) => fs.writeSync(log, line + '\\n')
879
922
  const status = (line) => fs.writeFileSync(spec.status, line + '\\n')
880
- status('running ' + Math.floor(Date.now() / 1000) + ' ' + spec.kind)
923
+ status('running ' + Math.floor(Date.now() / 1000) + ' ' + spec.kind + ' ' + process.pid)
881
924
  function run(command, args) {
882
925
  return new Promise((resolve) => {
883
926
  let child
927
+ let timer = null
928
+ const finish = (code) => {
929
+ if (timer) { clearTimeout(timer); timer = null }
930
+ resolve(code)
931
+ }
884
932
  try {
885
933
  child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], env: process.env })
886
934
  } catch (error) {
@@ -888,10 +936,15 @@ function run(command, args) {
888
936
  resolve(1)
889
937
  return
890
938
  }
939
+ timer = setTimeout(() => {
940
+ say('超过 600 秒没有结束,终止:' + command + ' ' + args.join(' '))
941
+ try { child.kill() } catch {}
942
+ finish(1)
943
+ }, 600000)
891
944
  child.stdout.on('data', (chunk) => fs.writeSync(log, chunk))
892
945
  child.stderr.on('data', (chunk) => fs.writeSync(log, chunk))
893
- child.on('error', (error) => { say(String(error && error.message ? error.message : error)); resolve(1) })
894
- child.on('exit', (code) => resolve(code === 0 ? 0 : 1))
946
+ child.on('error', (error) => { say(String(error && error.message ? error.message : error)); finish(1) })
947
+ child.on('exit', (code) => finish(code === 0 ? 0 : 1))
895
948
  })
896
949
  }
897
950
  ;(async () => {
@@ -916,7 +969,7 @@ function run(command, args) {
916
969
  }
917
970
 
918
971
  function localAddCommand(dir) {
919
- return `"$DSH_BIN" plugin --profile "$PROFILE" add ${shQuote(dir)}`
972
+ return `\${TIMEOUT} "$DSH_BIN" plugin --profile "$PROFILE" add ${shQuote(dir)}`
920
973
  }
921
974
 
922
975
  /** The plugin manager reports a failed operation as `error` + `application:"failed"`, not `ok:false`. */
@@ -933,6 +986,22 @@ function installTimedOut(result) {
933
986
  return kind.toLowerCase().includes('timeout')
934
987
  }
935
988
 
989
+ /** Turn noisy pnpm / installer output into one plain-language cause (empty when nothing matches). */
990
+ function explainFailure(text) {
991
+ const raw = String(text || '')
992
+ if (!raw) return ''
993
+ if (/ENOTFOUND|EAI_AGAIN|getaddrinfo/i.test(raw)) return '域名解析失败,检查网络或 registry 地址'
994
+ if (/ERR_PNPM_FETCH_404|E404|404 Not Found|does not exist on the registry/i.test(raw)) return '包或版本在 registry 上不存在(404)'
995
+ if (/ECONNRESET|ECONNREFUSED|socket hang up|ERR_SOCKET|network error/i.test(raw)) return '网络连接被重置或拒绝,多为 registry 不可达'
996
+ if (/ETIMEDOUT|ESOCKETTIMEDOUT|timed out|timeout|600000ms/i.test(raw)) return '安装超时(安装器长时间没有输出,原因为网络或 registry 卡住)'
997
+ if (/EPERM|EACCES|permission denied/i.test(raw)) return '权限不足,无法写入安装目录'
998
+ if (/ENOENT|no such file/i.test(raw)) return '缺文件:同步码里的文件或包内容不完整'
999
+ if (/ERESOLVE|peer dep/i.test(raw)) return '依赖冲突(peer dependency 不匹配)'
1000
+ if (/incompatible|版本不兼容|requires .* but (?:got|found)/i.test(raw)) return '版本不兼容(插件与当前 DSH 版本不匹配)'
1001
+ if (/unsupported|not supported|does not support/i.test(raw)) return '当前端的安装器不支持这种来源'
1002
+ return ''
1003
+ }
1004
+
936
1005
  /** The desktop host runs `@deepseek-ai/dsh-desktop-host/lib/index.js`; its CLI is the sibling file. */
937
1006
  function dshCliEntry() {
938
1007
  const host = typeof process.argv[2] === 'string' ? process.argv[2] : ''
@@ -977,25 +1046,32 @@ function startInstallTask(ctx, jobs) {
977
1046
  try { writeFileSync(taskTotalPath(), '0\n') } catch {}
978
1047
  writeFileSync(taskLogPath(), '')
979
1048
  writeFileSync(taskStatusPath(), `running ${Math.floor(Date.now() / 1000)} apply\n`)
1049
+ const runId = ++installRun
980
1050
  const installs = jobs.filter((job) => job.action === 'install')
981
- const say = (line) => { try { writeFileSync(taskLogPath(), `${line}\n`, { flag: 'a' }) } catch {} }
1051
+ const say = (line) => {
1052
+ if (cancelledRun === runId) return
1053
+ try { writeFileSync(taskLogPath(), `${line}\n`, { flag: 'a' }) } catch {}
1054
+ }
1055
+ try { say(`host dshGo=${ctx.get?.('dshGo') === true} platform=${process.platform} profile=${profileName()}`) } catch {}
982
1056
  ;(async () => {
983
1057
  let failed = 0
984
1058
  for (const job of installs) {
1059
+ if (cancelledRun === runId) break
985
1060
  const name = markerName(job.name)
986
1061
  const target = job.localDir || job.registrySpec
987
1062
  say(`@@ install ${name} start`)
988
1063
  if (!target) {
989
1064
  failed += 1
990
- say(`@@ install ${name} fail`)
1065
+ say('原因:这个插件既没有本地文件也没有 registry 地址,无法安装')
991
1066
  say('no install source')
1067
+ say(`@@ install ${name} fail`)
992
1068
  continue
993
1069
  }
994
1070
  try {
995
1071
  const result = await manager.installBundle(target, { enabled: true })
996
1072
  const failure = installFailure(result)
997
1073
  if (failure && installTimedOut(result)) {
998
- say(`@@ install ${name} timeout, retry via dsh cli`)
1074
+ say(`install ${name} timeout, retry via dsh cli`)
999
1075
  const retry = await runCliInstall(target)
1000
1076
  if (retry.ok) {
1001
1077
  say(`@@ install ${name} ok`)
@@ -1004,13 +1080,23 @@ function startInstallTask(ctx, jobs) {
1004
1080
  say('重启 DSH 后生效')
1005
1081
  } else {
1006
1082
  failed += 1
1007
- say(`@@ install ${name} cli failed`)
1083
+ say(`install ${name} cli failed`)
1008
1084
  say(retry.output.slice(-1500))
1085
+ const hint = explainFailure(retry.output)
1086
+ if (hint) say(`原因:${hint}`)
1009
1087
  say(`@@ install ${name} fail`)
1010
1088
  }
1011
1089
  } else if (failure) {
1012
1090
  failed += 1
1013
- say(failure.slice(0, 2000))
1091
+ say(`target ${target}`)
1092
+ const rawFailure = [failure, result?.packageResult?.output, result?.error?.packageResult?.output]
1093
+ .filter((part) => typeof part === 'string' && part !== '')
1094
+ .join('\n') || failure
1095
+ say(rawFailure.length <= 2000 ? rawFailure : `${rawFailure.slice(0, 1200)}\n…\n${rawFailure.slice(-800)}`)
1096
+ const hint = explainFailure(rawFailure)
1097
+ if (hint) say(`原因:${hint}`)
1098
+ const logPath = result?.packageResult?.logPath || result?.error?.packageResult?.logPath
1099
+ if (logPath) say(`log ${logPath}`)
1014
1100
  say(`@@ install ${name} fail`)
1015
1101
  } else {
1016
1102
  say(`@@ install ${name} ok`)
@@ -1019,11 +1105,16 @@ function startInstallTask(ctx, jobs) {
1019
1105
  }
1020
1106
  } catch (error) {
1021
1107
  failed += 1
1022
- say(String(error && (error.stack || error.message) || error).slice(0, 2000))
1108
+ const text = String(error && (error.stack || error.message) || error).slice(0, 2000)
1109
+ say(text)
1110
+ const hint = explainFailure(text)
1111
+ if (hint) say(`原因:${hint}`)
1023
1112
  say(`@@ install ${name} fail`)
1024
1113
  }
1025
1114
  }
1026
- try { writeFileSync(taskStatusPath(), `done ${Math.floor(Date.now() / 1000)} ${failed} apply\n`) } catch {}
1115
+ if (cancelledRun !== runId) {
1116
+ try { writeFileSync(taskStatusPath(), `done ${Math.floor(Date.now() / 1000)} ${failed} apply\n`) } catch {}
1117
+ }
1027
1118
  })()
1028
1119
  return { ok: true }
1029
1120
  }
@@ -1335,15 +1426,15 @@ function enableText(caps) {
1335
1426
 
1336
1427
  function statusLine(row, en) {
1337
1428
  let text = {
1338
- same: en ? 'same' : '一致',
1339
- conflict: en ? 'local wins' : '本机优先',
1340
- install: en ? 'not installed' : '未安装',
1341
- installable: en ? 'ready' : '可安装',
1342
- missing: en ? 'no files' : '缺文件',
1343
- extra: en ? 'not listed' : '清单外',
1429
+ same: en ? 'already here' : '本地已有',
1430
+ conflict: en ? 'already here, different version' : '本地已有,版本不同',
1431
+ install: en ? 'already here, not enabled' : '本地已有,未启用',
1432
+ installable: en ? 'installable' : '可安装',
1433
+ missing: en ? 'missing files' : '缺文件',
1434
+ extra: en ? 'local only' : '仅本机有',
1344
1435
  push: en ? 'pushable' : '可推送',
1345
- 'native-only': en ? 'phone-only' : '手机专用',
1346
- 'web-only': en ? 'web-only' : '电脑/网页专用',
1436
+ 'native-only': en ? 'dsh-go only' : '仅dshgo',
1437
+ 'web-only': en ? 'desktop/web only' : '仅电脑/网页',
1347
1438
  }[row.status] || row.status
1348
1439
  if (row.status !== 'web-only' && row.status !== 'native-only') {
1349
1440
  if (row.action === 'install' && row.registrySpec) text = en ? 'via npm' : 'npm 安装'
@@ -1357,6 +1448,23 @@ function statusLine(row, en) {
1357
1448
  return `${version} · ${text}`
1358
1449
  }
1359
1450
 
1451
+ const STATUS_BRIEF = {
1452
+ same: ['本地已有', 'already here'],
1453
+ conflict: ['本地已有,版本不同', 'already here, different version'],
1454
+ install: ['本地已有,未启用', 'already here, not enabled'],
1455
+ installable: ['可安装', 'installable'],
1456
+ missing: ['缺文件', 'missing files'],
1457
+ extra: ['仅本机有', 'local only'],
1458
+ push: ['可推送', 'pushable'],
1459
+ 'native-only': ['仅dshgo', 'dsh-go only'],
1460
+ 'web-only': ['仅电脑/网页', 'desktop/web only'],
1461
+ }
1462
+
1463
+ function statusBrief(row, en) {
1464
+ const pair = STATUS_BRIEF[row.status]
1465
+ return pair ? pair[en ? 1 : 0] : row.status
1466
+ }
1467
+
1360
1468
  function statusTone(status) {
1361
1469
  if (status === 'conflict' || status === 'extra') return 'warn'
1362
1470
  if (status === 'installable' || status === 'install' || status === 'push') return 'info'
@@ -1435,7 +1543,7 @@ function buildView(scope, caps, ctx) {
1435
1543
  en ? `elapsed ${elapsed}` : `已用 ${elapsed}`,
1436
1544
  ].filter(Boolean).join(' · ')
1437
1545
  children.push({ type: 'callout', tone: stale ? 'warn' : 'info', text: stale
1438
- ? (en ? `${taskLabel(task.kind, true)} running too long (${progressText}); check the log.` : `${taskLabel(task.kind, false)}运行太久(${progressText}),看下日志。`)
1546
+ ? (en ? `${taskLabel(task.kind, true)} running too long (${progressText}); check the log, or tap Stop task.` : `${taskLabel(task.kind, false)}运行太久(${progressText}),看下日志,或点「取消任务」。`)
1439
1547
  : (en ? `${taskLabel(task.kind, true)} running: ${progressText}` : `${taskLabel(task.kind, false)}中:${progressText}`) })
1440
1548
  } else if (task && task.ok === false) {
1441
1549
  children.push({ type: 'callout', tone: 'bad', text: en
@@ -1470,20 +1578,8 @@ function buildView(scope, caps, ctx) {
1470
1578
 
1471
1579
  if (!state.manifest) {
1472
1580
  children.push({ type: 'callout', tone: 'info', text: en
1473
- ? 'Select plugins below, then Copy code; or import a manifest / pull the relay first.'
1474
- : '先在下面选中要同步的插件,再点复制同步码;也可以先导入清单或拉取中转。' })
1475
- if (local.length > 0) {
1476
- const shown = local.slice(0, 40)
1477
- children.push({ type: 'list', items: shown.map((plugin) => ({
1478
- title: plugin.name,
1479
- subtitle: `${plugin.version} · ${en ? 'tap to select' : '点选'}`,
1480
- trailing: state.selected.has(plugin.name) ? '✓' : '○',
1481
- action: { id: 'toggle', args: { name: plugin.name } },
1482
- })) })
1483
- if (local.length > shown.length) {
1484
- children.push({ type: 'text', text: en ? `…and ${local.length - shown.length} more` : `…还有 ${local.length - shown.length} 项` })
1485
- }
1486
- }
1581
+ ? 'Import a sync code or pull the relay/manifest first. This panel only lists plugins that still need action; Copy code uses all local plugins when nothing is selected.'
1582
+ : '先导入同步码或拉取中转。这里只列需要处理的插件;复制同步码在没选任何插件时会带上全部本机插件。' })
1487
1583
  } else {
1488
1584
  const when = state.manifest.exportedAt ? state.manifest.exportedAt.slice(0, 16).replace('T', ' ') : ''
1489
1585
  const source = state.sourceName || state.manifest.host?.profile || ''
@@ -1491,22 +1587,26 @@ function buildView(scope, caps, ctx) {
1491
1587
  ? `Manifest: ${source || 'imported'}${when ? ` · ${when}` : ''}`
1492
1588
  : `清单来源:${source || '已导入'}${when ? ` · ${when}` : ''}` })
1493
1589
 
1494
- const pending = rows.filter((row) => row.status !== 'same')
1590
+ const pending = rows.filter((row) => row.status !== 'same' && row.status !== 'extra')
1495
1591
  const installed = rows.filter((row) => row.status === 'same')
1496
- const visible = state.showAll ? rows : pending
1497
- if (rows.length === 0) {
1592
+ const listable = rows.filter((row) => row.status !== 'extra')
1593
+ const visible = (state.showAll ? listable : pending).slice()
1594
+ .sort((a, b) => Number(Boolean(b.action)) - Number(Boolean(a.action)))
1595
+ if (listable.length === 0) {
1498
1596
  children.push({ type: 'callout', tone: 'good', text: en ? 'The two hosts match.' : '两边完全一致。' })
1499
1597
  } else {
1500
1598
  if (pending.length === 0) {
1501
1599
  children.push({ type: 'callout', tone: 'good', text: en ? 'Nothing pending; everything is in sync.' : '没有待处理项,已全部一致。' })
1600
+ } else {
1601
+ children.push({ type: 'text', text: en ? `Pending plugins (${pending.length})` : `待处理插件(${pending.length})` })
1502
1602
  }
1503
1603
  const shown = visible.slice(0, 40)
1504
1604
  if (shown.length > 0) {
1505
1605
  children.push({ type: 'list', items: shown.map((row) => {
1506
1606
  const item = {
1507
1607
  title: row.name,
1508
- subtitle: statusLine(row, en),
1509
- trailing: state.selected.has(row.name) ? '✓' : '○',
1608
+ subtitle: statusBrief(row, en),
1609
+ trailing: state.selected.has(row.name) ? '✓' : undefined,
1510
1610
  action: { id: 'toggle', args: { name: row.name } },
1511
1611
  }
1512
1612
  const tone = statusTone(row.status)
@@ -1526,28 +1626,32 @@ function buildView(scope, caps, ctx) {
1526
1626
 
1527
1627
  }
1528
1628
 
1629
+ const selectableNames = state.manifest
1630
+ ? rows.filter((row) => row.status !== 'extra').map((row) => row.name)
1631
+ : local.map((plugin) => plugin.name)
1632
+ const allSelected = selectableNames.length > 0 && selectableNames.every((name) => state.selected.has(name))
1633
+
1529
1634
  const primary = [
1635
+ ...(task?.running ? [{ label: en ? 'Stop task' : '取消任务', action: 'stop-task' }] : []),
1530
1636
  { label: en ? 'Copy code' : '复制同步码', action: 'copy-code' },
1531
- { label: en ? 'Select all' : '全选', action: 'select-all' },
1532
- { label: en ? 'Clear' : '清空', action: 'clear' },
1637
+ { label: allSelected ? (en ? 'Select none' : '取消全选') : (en ? 'Select all' : '全选'), action: allSelected ? 'clear' : 'select-all' },
1533
1638
  { label: state.showAll ? (en ? 'Pending only' : '只看待处理') : (en ? 'Show all' : '显示全部'), action: 'toggle-show-all' },
1534
1639
  { label: en ? 'Refresh' : '刷新', action: 'refresh' },
1535
1640
  ]
1536
1641
  children.push({ type: 'actions', items: primary })
1537
1642
 
1538
- children.push({ type: 'actions', items: [
1539
- { label: en ? 'Retry failed' : '重试失败', action: 'retry-failed' },
1540
- { label: en ? 'Export' : '导出清单', action: 'export' },
1541
- { label: en ? 'Read workspace' : '工作区导入', action: 'import-workspace' },
1542
- { label: en ? 'Clear list' : '清空清单', action: 'clear-all' },
1543
- { label: en ? 'Guide' : '使用引导', action: 'guide' },
1544
- ] })
1643
+ const failedCount = results.filter((result) => !result.ok).length
1644
+ const secondary = []
1645
+ if (failedCount > 0) secondary.push({ label: en ? `Retry failed (${failedCount})` : `重试失败(${failedCount})`, action: 'retry-failed' })
1646
+ secondary.push({ label: en ? 'Reset list' : '重置清单', action: 'clear-all' })
1647
+ secondary.push({ label: en ? 'Guide' : '使用引导', action: 'guide' })
1648
+ children.push({ type: 'actions', items: secondary })
1545
1649
 
1546
1650
  if (state.manifest && state.selected.size > 0) {
1547
1651
  children.push({ type: 'confirm', id: 'apply', confirmLabel: en ? 'Apply' : '应用所选', cancelLabel: en ? 'Cancel' : '取消' })
1548
1652
  }
1549
1653
 
1550
- const log = readLogTail()
1654
+ const log = readLogTail(8)
1551
1655
  if (log.length > 0) {
1552
1656
  children.push({ type: 'keyValue', items: log.map((line, index) => [en ? `log ${index + 1}` : `日志 ${index + 1}`, line]) })
1553
1657
  }
@@ -1606,19 +1710,8 @@ function buildGuide(scope, caps, ctx) {
1606
1710
  ['ssh.host', cfg.ssh.host || '—'],
1607
1711
  ] },
1608
1712
  { type: 'text', text: en
1609
- ? 'Advanced: large plugins or two-way file sync use the Git relay / SSH below.'
1610
- : '高级:大插件或双向文件同步用下面的 Git 中转 / SSH。' },
1611
- { type: 'actions', items: [
1612
- { label: en ? 'Copy code' : '复制同步码', action: 'copy-code' },
1613
- { label: en ? 'Config template' : '生成配置模板', action: 'copy-config' },
1614
- { label: en ? 'Back' : '返回同步', action: 'back' },
1615
- ] },
1616
- { type: 'actions', items: [
1617
- { label: en ? 'Push relay' : '推送中转', action: 'relay-push' },
1618
- { label: en ? 'Pull relay' : '拉取中转', action: 'relay-pull' },
1619
- { label: en ? 'Scan SSH' : '拉远端清单', action: 'ssh-scan' },
1620
- { label: en ? 'Test SSH' : '测试 SSH', action: 'ssh-test' },
1621
- ] },
1713
+ ? 'Advanced: large plugins or two-way file sync use the Git relay / SSH from the Sync panel.'
1714
+ : '高级:大插件或双向文件同步,在「插件同步」面板里用 Git 中转 / SSH。' },
1622
1715
  ],
1623
1716
  }
1624
1717
  }
@@ -1693,7 +1786,7 @@ function webSnapshot(ctx) {
1693
1786
  cleared,
1694
1787
  task: readTaskStatus(),
1695
1788
  results: readTaskResults(),
1696
- log: readLogTail(3),
1789
+ log: readLogTail(12),
1697
1790
  config: cfg,
1698
1791
  configPath: configPathFor(ctx, scope),
1699
1792
  }
@@ -1823,6 +1916,12 @@ export function apply(ctx) {
1823
1916
  actions: {
1824
1917
  'copy-code': copyCode,
1825
1918
 
1919
+ 'stop-task'() {
1920
+ const result = stopTask()
1921
+ if (!result.ok) return { toast: result.error || '没有在运行的任务' }
1922
+ return [{ toast: '已取消任务' }, { refresh: true }]
1923
+ },
1924
+
1826
1925
  'import-code'(scope, event) {
1827
1926
  const text = codeFromSubmit(event?.value)
1828
1927
  if (text === '') return { toast: '先粘贴同步码' }
@@ -2033,6 +2132,11 @@ export function apply(ctx) {
2033
2132
  webJson(res, 200, { ok: true })
2034
2133
  return
2035
2134
  }
2135
+ if (action === 'stop') {
2136
+ const result = stopTask()
2137
+ webJson(res, 200, result.ok ? { ok: true } : { error: result.error || '没有在运行的任务' })
2138
+ return
2139
+ }
2036
2140
  if (action === 'relay-pull') {
2037
2141
  if (!cfg.relay.repo) { webJson(res, 200, { error: '先配置中转仓' }); return }
2038
2142
  state.relayLoadedAt = 0
package/package.json CHANGED
@@ -1,102 +1,102 @@
1
- {
2
- "name": "dsh-go-plugin-sync",
3
- "version": "0.4.1",
4
- "type": "module",
5
- "main": "lib/index.js",
6
- "dsh": {
7
- "bundle": {
8
- "patch": "./cordis.patch.yml"
9
- },
10
- "client": {
11
- "platform": "web",
12
- "immediately": true,
13
- "inject": [
14
- "@deepseek-ai/dsh-client-ui-settings"
15
- ]
16
- }
17
- },
18
- "engines": {
19
- "dsh": ">=0.2.1-rc.2 <0.3.0-0"
20
- },
21
- "dshGo": {
22
- "v": 1,
23
- "title": {
24
- "zh": "插件同步",
25
- "en": "Plugin sync"
26
- },
27
- "icon": "refresh",
28
- "contributes": {
29
- "composer.actions": [
30
- {
31
- "id": "open-sync",
32
- "label": {
33
- "zh": "插件同步",
34
- "en": "Sync"
35
- },
36
- "icon": "refresh",
37
- "effect": {
38
- "type": "open",
39
- "page": "panel:sync"
40
- }
41
- }
42
- ],
43
- "composer.strip": [
44
- {
45
- "id": "pending",
46
- "icon": "refresh",
47
- "panel": "sync"
48
- }
49
- ],
50
- "panels": [
51
- {
52
- "id": "sync",
53
- "title": {
54
- "zh": "插件同步",
55
- "en": "Plugin sync"
56
- },
57
- "icon": "refresh",
58
- "placement": [
59
- "session.tab",
60
- "features"
61
- ],
62
- "presentation": "page"
63
- },
64
- {
65
- "id": "guide",
66
- "title": {
67
- "zh": "同步引导",
68
- "en": "Sync guide"
69
- },
70
- "icon": "book",
71
- "placement": [
72
- "features"
73
- ],
74
- "presentation": "page"
75
- }
76
- ]
77
- }
78
- },
79
- "repository": {
80
- "type": "git",
81
- "url": "https://gitee.com/o12354654/dshgochajiantongbucha.git"
82
- },
83
- "description": "dsh-go 插件同步:用同步码在手机与电脑之间安装 dsh-go / Cordis 插件;支持 Git 中转与 SSH。",
84
- "keywords": [
85
- "dsh",
86
- "dsh-plugin",
87
- "dsh-go",
88
- "plugin-sync"
89
- ],
90
- "homepage": "https://gitee.com/o12354654/dshgochajiantongbucha",
91
- "files": [
92
- "lib",
93
- "cordis.patch.yml",
94
- "README.md",
95
- "CHANGELOG.md"
96
- ],
97
- "exports": {
98
- ".": "./lib/index.js",
99
- "./client": "./lib/client.js",
100
- "./package.json": "./package.json"
101
- }
102
- }
1
+ {
2
+ "name": "dsh-go-plugin-sync",
3
+ "version": "0.4.3",
4
+ "type": "module",
5
+ "main": "lib/index.js",
6
+ "dsh": {
7
+ "bundle": {
8
+ "patch": "./cordis.patch.yml"
9
+ },
10
+ "client": {
11
+ "platform": "web",
12
+ "immediately": true,
13
+ "inject": [
14
+ "@deepseek-ai/dsh-client-ui-settings"
15
+ ]
16
+ }
17
+ },
18
+ "engines": {
19
+ "dsh": ">=0.2.1-rc.2 <0.3.0-0"
20
+ },
21
+ "dshGo": {
22
+ "v": 1,
23
+ "title": {
24
+ "zh": "插件同步",
25
+ "en": "Plugin sync"
26
+ },
27
+ "icon": "refresh",
28
+ "contributes": {
29
+ "composer.actions": [
30
+ {
31
+ "id": "open-sync",
32
+ "label": {
33
+ "zh": "插件同步",
34
+ "en": "Sync"
35
+ },
36
+ "icon": "refresh",
37
+ "effect": {
38
+ "type": "open",
39
+ "page": "panel:sync"
40
+ }
41
+ }
42
+ ],
43
+ "composer.strip": [
44
+ {
45
+ "id": "pending",
46
+ "icon": "refresh",
47
+ "panel": "sync"
48
+ }
49
+ ],
50
+ "panels": [
51
+ {
52
+ "id": "sync",
53
+ "title": {
54
+ "zh": "插件同步",
55
+ "en": "Plugin sync"
56
+ },
57
+ "icon": "refresh",
58
+ "placement": [
59
+ "session.tab",
60
+ "features"
61
+ ],
62
+ "presentation": "page"
63
+ },
64
+ {
65
+ "id": "guide",
66
+ "title": {
67
+ "zh": "同步引导",
68
+ "en": "Sync guide"
69
+ },
70
+ "icon": "book",
71
+ "placement": [
72
+ "features"
73
+ ],
74
+ "presentation": "page"
75
+ }
76
+ ]
77
+ }
78
+ },
79
+ "repository": {
80
+ "type": "git",
81
+ "url": "https://gitee.com/o12354654/dshgochajiantongbucha.git"
82
+ },
83
+ "description": "dsh-go 插件同步:用同步码在手机与电脑之间安装 dsh-go / Cordis 插件;支持 Git 中转与 SSH。",
84
+ "keywords": [
85
+ "dsh",
86
+ "dsh-plugin",
87
+ "dsh-go",
88
+ "plugin-sync"
89
+ ],
90
+ "homepage": "https://gitee.com/o12354654/dshgochajiantongbucha",
91
+ "files": [
92
+ "lib",
93
+ "cordis.patch.yml",
94
+ "README.md",
95
+ "CHANGELOG.md"
96
+ ],
97
+ "exports": {
98
+ ".": "./lib/index.js",
99
+ "./client": "./lib/client.js",
100
+ "./package.json": "./package.json"
101
+ }
102
+ }