dsh-pstack-deck 0.1.0 → 0.2.0
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/README.md +38 -2
- package/docs/preview-list.png +0 -0
- package/package.json +3 -2
- package/scripts/dev.mjs +69 -0
- package/scripts/preview.mjs +4 -0
- package/src/client.js +37 -0
- package/src/host.js +7 -1
- package/src/update.js +58 -0
package/README.md
CHANGED
|
@@ -176,19 +176,55 @@ src/
|
|
|
176
176
|
zh/ 58 篇中文正文(与 repo/skills 逐篇对齐,npm run check:zh 校验)
|
|
177
177
|
repo/ pstack 上游只读快照(skills / plugin.json / LICENSE)
|
|
178
178
|
scripts/ sync-skills(推到 ~/.dsh/skills)、check-zh、preview(自渲染截图)
|
|
179
|
-
test/ node --test,
|
|
179
|
+
test/ node --test,45 条
|
|
180
180
|
docs/ parallel-tasks.md + 预览截图
|
|
181
181
|
```
|
|
182
182
|
|
|
183
183
|
## 开发
|
|
184
184
|
|
|
185
185
|
```bash
|
|
186
|
-
npm test #
|
|
186
|
+
npm test # 45 条:目录解析、路由信封、工具、看板、依赖图、建议、版本比较、客户端渲染
|
|
187
|
+
npm run dev # 起一个临时宿主(默认 web profile:5599),改 src/ 自动重启
|
|
187
188
|
npm run preview # 用假 React 把面板渲染成 HTML,再用 Chrome 截图,不用起宿主
|
|
188
189
|
npm run sync # 把 repo/skills 推到 ~/.dsh/skills(--dry 只看差异)
|
|
189
190
|
npm run check:zh # 中文正文与原文逐篇对齐检查
|
|
190
191
|
```
|
|
191
192
|
|
|
193
|
+
本地改代码用 `link:` 安装:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
dsh plugin --profile desktop add link:/绝对路径/dsh-pstack-deck
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 热更新与热安装:哪些是热的
|
|
200
|
+
|
|
201
|
+
这不是我保守,是宿主的能力边界。分三半看:
|
|
202
|
+
|
|
203
|
+
| 你改了什么 | 要不要重启宿主 |
|
|
204
|
+
|---|---|
|
|
205
|
+
| `repo/skills/*.md`、`zh/*.md`、`.pstack/board/*.md` | **不要**。每次请求现读磁盘,面板点「刷新」/「重读」立刻生效 |
|
|
206
|
+
| `src/client.js`(面板 UI) | **要**。客户端 bundle 在启动时按内容哈希构建一次(请求里的 `?rev=`),profile 里没有可覆盖的 bundle 缓存 |
|
|
207
|
+
| `src/host.js` / `src/tools.js` | **要**。往 cordis 注册的技能 provider、HTTP 路由、工具都没有卸载重挂的入口 |
|
|
208
|
+
| 升级到新版本 | 看宿主回报的 `activation`:`client-only` → 刷新页面;否则 → 重启 |
|
|
209
|
+
|
|
210
|
+
所以「技能内容热更新」是这个项目的设计红利,「代码热更新」没有。`npm run dev` 把手动退出重开压成一次保存,仅此而已;唯一存在 HMR 通道的是 DSH 自己 checkout 里 `pnpm run dev:web` 起的那条,不覆盖 npm 装的第三方包。
|
|
211
|
+
|
|
212
|
+
面板自己会查 npm:启一次(十分钟缓存)之后,标题栏显示 `插件 0.1.0` 或琥珀色的 `↑ 0.1.1`;有新版本时技能视图顶部给一条可复制的升级命令。
|
|
213
|
+
|
|
214
|
+
### 发版
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
npm version patch # 或 minor / major
|
|
218
|
+
npm test && npm run check:zh
|
|
219
|
+
npm publish --registry=https://registry.npmjs.org --access public
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
三个坑,踩过:
|
|
223
|
+
|
|
224
|
+
- 本机默认 registry 可能是国内镜像(`registry.npmmirror.com`),**镜像不能发**,必须显式带 `--registry`。
|
|
225
|
+
- 账号开了 2FA 时,普通 token 发布报 `403 … two-factor authentication … required`;要么 `--otp=123456`,要么用勾了 **Bypass two-factor authentication** 的 Granular Access Token。
|
|
226
|
+
- npm 对新包走 staged publishing:一发布先出现 `0.0.0-stage` 占位版,几秒后才落成真实版本,别看到占位版就以为失败了。
|
|
227
|
+
|
|
192
228
|
## 已知边界
|
|
193
229
|
|
|
194
230
|
- `scope` 冲突是**路径前缀比对**,不是代码级依赖分析。同目录不同文件互依的情况挡不住。
|
package/docs/preview-list.png
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-pstack-deck",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "pstack 的 DSH 面板:58 个技能点一下就用,带项目看板、依赖拓扑与三层决策推荐。",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"test": "node --test test/*.test.mjs",
|
|
16
16
|
"sync": "node scripts/sync-skills.mjs",
|
|
17
17
|
"check:zh": "node scripts/check-zh.mjs",
|
|
18
|
-
"preview": "node scripts/preview.mjs /tmp/psp-preview.html"
|
|
18
|
+
"preview": "node scripts/preview.mjs /tmp/psp-preview.html",
|
|
19
|
+
"dev": "node scripts/dev.mjs"
|
|
19
20
|
},
|
|
20
21
|
"dsh": {
|
|
21
22
|
"bundle": {
|
package/scripts/dev.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 开发热循环:改完 src/ 自动重启一个临时宿主,浏览器刷新就见到新代码。
|
|
3
|
+
//
|
|
4
|
+
// 为什么是「重启」而不是 HMR:宿主半注册的是 cordis 服务与工具,客户端 bundle
|
|
5
|
+
// 在启动时按内容哈希构建一次,两者都没有热替换入口。脚本能做的只是把手动
|
|
6
|
+
// 退出重开压成一次保存。
|
|
7
|
+
//
|
|
8
|
+
// 用法:
|
|
9
|
+
// node scripts/dev.mjs # 默认 web profile,端口 5599
|
|
10
|
+
// node scripts/dev.mjs web 5599
|
|
11
|
+
// node scripts/dev.mjs desktop 5600 # 注意:桌面 app 不能这样起,仅 web/tui 适用
|
|
12
|
+
|
|
13
|
+
import { spawn } from 'node:child_process'
|
|
14
|
+
import { watch } from 'node:fs'
|
|
15
|
+
import { join } from 'node:path'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
17
|
+
|
|
18
|
+
const ROOT = fileURLToPath(new URL('..', import.meta.url))
|
|
19
|
+
const profile = process.argv[2] || 'web'
|
|
20
|
+
const port = process.argv[3] || '5599'
|
|
21
|
+
const WATCH = ['src', 'cordis.patch.yml', 'package.json']
|
|
22
|
+
|
|
23
|
+
let child = null
|
|
24
|
+
let timer = null
|
|
25
|
+
let started = 0
|
|
26
|
+
|
|
27
|
+
function boot() {
|
|
28
|
+
if (child) {
|
|
29
|
+
child.kill('SIGTERM')
|
|
30
|
+
child = null
|
|
31
|
+
}
|
|
32
|
+
started = Date.now()
|
|
33
|
+
child = spawn('dsh', ['--profile', profile, '--port', port], {
|
|
34
|
+
cwd: ROOT,
|
|
35
|
+
stdio: 'inherit',
|
|
36
|
+
env: process.env,
|
|
37
|
+
})
|
|
38
|
+
child.on('exit', (code, signal) => {
|
|
39
|
+
// 自己杀的(重启)不算崩,也不重开
|
|
40
|
+
if (Date.now() - started < 1500 && signal) return
|
|
41
|
+
if (code) console.log(`\n[dev] 宿主退出了(code ${code}),改一次代码会重开;Ctrl+C 结束`)
|
|
42
|
+
child = null
|
|
43
|
+
})
|
|
44
|
+
console.log(`\n[dev] 宿主起来了:http://127.0.0.1:${port}(改 src/ 自动重启)`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function schedule(why) {
|
|
48
|
+
clearTimeout(timer)
|
|
49
|
+
timer = setTimeout(() => {
|
|
50
|
+
console.log(`\n[dev] ${why} → 重启`)
|
|
51
|
+
boot()
|
|
52
|
+
}, 250)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
boot()
|
|
56
|
+
for (const target of WATCH) {
|
|
57
|
+
watch(join(ROOT, target), { recursive: target === 'src' }, (_e, file) => {
|
|
58
|
+
if (!file || /\.(md|png)$/.test(file)) return // 文档改动不影响宿主
|
|
59
|
+
schedule(file)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const bye = () => {
|
|
64
|
+
clearTimeout(timer)
|
|
65
|
+
if (child) child.kill('SIGTERM')
|
|
66
|
+
process.exit(0)
|
|
67
|
+
}
|
|
68
|
+
process.on('SIGINT', bye)
|
|
69
|
+
process.on('SIGTERM', bye)
|
package/scripts/preview.mjs
CHANGED
|
@@ -156,6 +156,10 @@ const ctx = {
|
|
|
156
156
|
},
|
|
157
157
|
}))
|
|
158
158
|
}
|
|
159
|
+
if (req && req.method === 'update') {
|
|
160
|
+
// 演示「有新版本」长什么样:假装 npm 上多了一个 0.2.0
|
|
161
|
+
return Promise.resolve({ ok: true, value: { current: '0.1.0', latest: '0.2.0', hasUpdate: true, cached: false, error: '' } })
|
|
162
|
+
}
|
|
159
163
|
if (req && req.method === 'board') return boardView().then((value) => ({ ok: true, value }))
|
|
160
164
|
if (req && req.method === 'suggest') return suggest({ cwd: proj, roots: [] }).then((value) => ({ ok: true, value }))
|
|
161
165
|
return Promise.resolve(payload)
|
package/src/client.js
CHANGED
|
@@ -54,6 +54,8 @@ window.__ModuleLoader__.load({
|
|
|
54
54
|
flow: false, // 看板:列表 or 流程图
|
|
55
55
|
toast: '',
|
|
56
56
|
toastAt: 0,
|
|
57
|
+
upd: null, // {current, latest, hasUpdate, error};null = 还没问过 npm
|
|
58
|
+
updBusy: false,
|
|
57
59
|
}
|
|
58
60
|
const subs = new Set()
|
|
59
61
|
const emit = () => subs.forEach((fn) => fn(store))
|
|
@@ -81,6 +83,18 @@ window.__ModuleLoader__.load({
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
86
|
+
// 问一次 npm 上有没有新版本。宿主那半缓存十分钟,所以开面板顺手查一下不心疼。
|
|
87
|
+
const checkUpd = async (fresh) => {
|
|
88
|
+
if (store.updBusy) return
|
|
89
|
+
set({ updBusy: true })
|
|
90
|
+
try {
|
|
91
|
+
const r = await rpc('update', fresh ? { fresh: true } : {})
|
|
92
|
+
set({ upd: r, updBusy: false })
|
|
93
|
+
} catch (e) {
|
|
94
|
+
set({ upd: { error: String((e && e.message) || e) }, updBusy: false })
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
84
98
|
const openSkill = async (name) => {
|
|
85
99
|
set({ open: name, detail: null, draft: '' })
|
|
86
100
|
try {
|
|
@@ -696,6 +710,7 @@ window.__ModuleLoader__.load({
|
|
|
696
710
|
useStore()
|
|
697
711
|
const cat = store.catalog
|
|
698
712
|
React.useEffect(() => { if (!cat && store.loading) load(false) }, [])
|
|
713
|
+
React.useEffect(() => { if (!store.upd) checkUpd(false) }, [])
|
|
699
714
|
React.useEffect(() => {
|
|
700
715
|
if (props && props.sessionId && props.sessionId !== store.sid) set({ sid: props.sessionId })
|
|
701
716
|
}, [props && props.sessionId])
|
|
@@ -712,6 +727,19 @@ window.__ModuleLoader__.load({
|
|
|
712
727
|
h('div', { key: 'sp', style: { flex: 1 } }),
|
|
713
728
|
h('button', { key: 'vs', style: { ...s.chip(store.view === 'skills'), fontSize: 11 }, onClick: () => set({ view: 'skills' }) }, '技能'),
|
|
714
729
|
h('button', { key: 'vb', style: { ...s.chip(store.view === 'board'), fontSize: 11 }, onClick: toBoard }, '看板'),
|
|
730
|
+
store.upd && !store.upd.error
|
|
731
|
+
? h('span', {
|
|
732
|
+
key: 'pv',
|
|
733
|
+
title: store.upd.hasUpdate
|
|
734
|
+
? `插件有新版本 ${store.upd.latest}(当前 ${store.upd.current})`
|
|
735
|
+
: `插件 ${store.upd.current || ''} 是最新的`,
|
|
736
|
+
style: {
|
|
737
|
+
...s.faint, fontFamily: C.mono, fontSize: 11, cursor: 'pointer',
|
|
738
|
+
color: store.upd.hasUpdate ? '#f0b132' : undefined,
|
|
739
|
+
},
|
|
740
|
+
onClick: () => checkUpd(true),
|
|
741
|
+
}, store.upd.hasUpdate ? `↑ ${store.upd.latest}` : `插件 ${store.upd.current || '?'}`)
|
|
742
|
+
: null,
|
|
715
743
|
cat ? h('button', { key: 'r', style: { ...s.btn(), padding: '2px 6px', fontSize: 11 }, onClick: () => { load(true); if (store.board) loadBoard() }, title: '重新读一遍磁盘' }, '刷新') : null,
|
|
716
744
|
])
|
|
717
745
|
|
|
@@ -738,10 +766,19 @@ window.__ModuleLoader__.load({
|
|
|
738
766
|
return h('div', { style: s.wrap }, [head, h('div', { key: 'b', style: { ...s.body, ...s.faint } }, '读目录…')])
|
|
739
767
|
}
|
|
740
768
|
|
|
769
|
+
const updBar = store.upd && store.upd.hasUpdate
|
|
770
|
+
? h('div', { key: 'upd', style: { margin: '8px 10px 0', padding: '6px 8px', border: '1px solid #6b5a20', borderRadius: 6, background: 'rgba(240,177,50,.08)', color: '#f0b132', fontSize: 11.5, lineHeight: 1.6 } }, [
|
|
771
|
+
h('div', { key: 't' }, `插件有新版本 ${store.upd.latest}(当前 ${store.upd.current})。技能正文不受影响,但面板修的东西要升级才有。`),
|
|
772
|
+
h('div', { key: 'c', style: { fontFamily: C.mono, userSelect: 'all', marginTop: 4, color: '#d8d8d8' } }, 'dsh plugin --profile desktop add dsh-pstack-deck@' + store.upd.latest),
|
|
773
|
+
h('div', { key: 'n', style: { ...s.faint, marginTop: 4 } }, '装完重启宿主:Web 重启 dsh web,桌面版退出重开。'),
|
|
774
|
+
])
|
|
775
|
+
: null
|
|
776
|
+
|
|
741
777
|
const groups = GROUP_ORDER.filter((g) => (cat.groups[g] || []).length)
|
|
742
778
|
|
|
743
779
|
return h('div', { style: s.wrap }, [
|
|
744
780
|
head,
|
|
781
|
+
updBar,
|
|
745
782
|
h('div', { key: 'find', style: { padding: '8px 10px 0', flex: 'none' } }, [
|
|
746
783
|
h('input', {
|
|
747
784
|
key: 'q',
|
package/src/host.js
CHANGED
|
@@ -26,8 +26,9 @@ import {
|
|
|
26
26
|
saveCard,
|
|
27
27
|
stateZh,
|
|
28
28
|
} from './board.js'
|
|
29
|
-
import { buildCatalog, toProviderItem, repoRoot, zhRoot, PROVIDER } from './catalog.js'
|
|
29
|
+
import { buildCatalog, toProviderItem, repoRoot, zhRoot, PROVIDER, PKG_ROOT } from './catalog.js'
|
|
30
30
|
import { suggest } from './suggest.js'
|
|
31
|
+
import { checkUpdate } from './update.js'
|
|
31
32
|
import { zhOf } from './i18n.js'
|
|
32
33
|
|
|
33
34
|
export const name = 'dsh-pstack-deck'
|
|
@@ -81,6 +82,11 @@ async function skillBody(skillName) {
|
|
|
81
82
|
|
|
82
83
|
// 返回形状就是 connection.rpc.call 的解包契约:{ok:true, value} 或 {ok:false, error}。
|
|
83
84
|
const methods = {
|
|
85
|
+
async update(payload) {
|
|
86
|
+
const pkg = JSON.parse(await readFile(join(PKG_ROOT, 'package.json'), 'utf8'))
|
|
87
|
+
const r = await checkUpdate({ current: pkg.version, useCache: payload?.fresh !== true })
|
|
88
|
+
return { ok: true, value: r }
|
|
89
|
+
},
|
|
84
90
|
async catalog(payload) {
|
|
85
91
|
const cat = await catalog({ fresh: payload?.fresh === true })
|
|
86
92
|
return {
|
package/src/update.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// 版本检查:面板上「是不是落后了」这个问题,答案只可能是「去 npm 看一眼」。
|
|
2
|
+
//
|
|
3
|
+
// 不引 semver 依赖——比版本号这件事按 x.y.z 数字比就够了,
|
|
4
|
+
// 预发布标记(0.2.0-beta.1)按「比同号正式版旧」处理。
|
|
5
|
+
|
|
6
|
+
const REGISTRY = 'https://registry.npmjs.org'
|
|
7
|
+
const TTL = 10 * 60 * 1000 // 十分钟内不重复打 npm,免得每次开面板都发请求
|
|
8
|
+
|
|
9
|
+
// 缓存只存「npm 上最新版是多少」,不存结论——结论取决于调用方传进来的 current,
|
|
10
|
+
// 而 current 会随升级变化,缓存结论会在升级后撒谎。
|
|
11
|
+
let cache = { at: 0, latest: '', error: '' }
|
|
12
|
+
|
|
13
|
+
/** 把 "0.1.0" / "0.2.0-beta.3" 拆成 [0,1,0] + 预发布标记 */
|
|
14
|
+
export function parseVersion(v) {
|
|
15
|
+
const m = String(v).trim().match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/)
|
|
16
|
+
if (!m) return null
|
|
17
|
+
return { num: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] || '' }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** a 比 b 新返回 true;解析不了就一律 false(宁可漏报,不误报) */
|
|
21
|
+
export function newer(a, b) {
|
|
22
|
+
const x = parseVersion(a)
|
|
23
|
+
const y = parseVersion(b)
|
|
24
|
+
if (!x || !y) return false
|
|
25
|
+
for (let i = 0; i < 3; i += 1) {
|
|
26
|
+
if (x.num[i] !== y.num[i]) return x.num[i] > y.num[i]
|
|
27
|
+
}
|
|
28
|
+
if (x.pre === y.pre) return false
|
|
29
|
+
if (!x.pre) return true // 正式版比预发布新
|
|
30
|
+
if (!y.pre) return false
|
|
31
|
+
return x.pre > y.pre
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 问一次 npm:这个包最新版是多少。
|
|
36
|
+
* fetcher 可注入,测试里不用真联网。
|
|
37
|
+
*/
|
|
38
|
+
export async function checkUpdate({ current, fetcher = fetch, now = Date.now(), useCache = true } = {}) {
|
|
39
|
+
const base = { current, latest: '', hasUpdate: false, cached: false, error: '' }
|
|
40
|
+
const age = now - cache.at
|
|
41
|
+
if (useCache && cache.at && age >= 0 && age < TTL) { // age<0 = 时钟回拨,别信缓存
|
|
42
|
+
return { ...base, latest: cache.latest, error: cache.error, hasUpdate: newer(cache.latest, current), cached: true }
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const res = await fetcher(`${REGISTRY}/dsh-pstack-deck`, {
|
|
46
|
+
headers: { accept: 'application/vnd.npm.install-v1+json' },
|
|
47
|
+
})
|
|
48
|
+
if (!res || !res.ok) throw new Error(`registry ${res ? res.status : 'no response'}`)
|
|
49
|
+
const meta = await res.json()
|
|
50
|
+
const latest = meta?.['dist-tags']?.latest || ''
|
|
51
|
+
cache = { at: now, latest, error: '' }
|
|
52
|
+
return { ...base, latest, hasUpdate: newer(latest, current) }
|
|
53
|
+
} catch (e) {
|
|
54
|
+
// 离线、被墙、registry 抽风:说清楚没查到,不要装作是最新
|
|
55
|
+
// 失败不写缓存:断网十秒后恢复,不该还拿着十秒前的失败结论
|
|
56
|
+
return { ...base, error: String((e && e.message) || e) }
|
|
57
|
+
}
|
|
58
|
+
}
|