dsh-plugin-update-hub 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: dsh-plugin-update-hub
3
+ name: dsh-plugin-update-hub
package/icon.png ADDED
Binary file
package/index.js ADDED
@@ -0,0 +1,220 @@
1
+ import { existsSync, lstatSync, readFileSync, readdirSync, statSync } from 'node:fs'
2
+ import { homedir } from 'node:os'
3
+ import { dirname, join } from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
5
+
6
+ export const name = 'dsh-plugin-update-hub'
7
+ export const inject = ['webServer', 'connection']
8
+
9
+ const ROUTE = '/dsh-plugin-update-hub-api'
10
+ const SAFE_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/i
11
+
12
+ function moduleDir() {
13
+ try {
14
+ return dirname(fileURLToPath(import.meta.url))
15
+ } catch (error) {
16
+ return process.cwd()
17
+ }
18
+ }
19
+
20
+ function isDirectory(path) {
21
+ try {
22
+ return statSync(path).isDirectory()
23
+ } catch (error) {
24
+ return false
25
+ }
26
+ }
27
+
28
+ /**
29
+ * A DSH profile directory keeps its installed packages in node_modules and
30
+ * always describes its own composition, so the marker file tells a real
31
+ * profile apart from the read-only installation bundle directory.
32
+ */
33
+ function isProfileDir(dir) {
34
+ return isDirectory(join(dir, 'node_modules')) && existsSync(join(dir, 'cordis.patch.yml'))
35
+ }
36
+
37
+ function hasNodeModules(dir) {
38
+ return isDirectory(join(dir, 'node_modules'))
39
+ }
40
+
41
+ function profileCandidates() {
42
+ const candidates = []
43
+ const envProfile = process.env.DSH_PROFILE_DIR
44
+ if (envProfile) candidates.push(envProfile)
45
+ const home = process.env.DSH_HOME || join(homedir(), '.dsh')
46
+ const envProfileName = process.env.DSH_PROFILE
47
+ if (envProfileName) candidates.push(join(home, 'profiles', envProfileName))
48
+ for (const arg of process.argv.slice(1)) {
49
+ if (!arg || arg.charAt(0) === '-' || arg.charAt(0) !== '/') continue
50
+ candidates.push(arg)
51
+ }
52
+ let dir = moduleDir()
53
+ for (let step = 0; step < 8; step += 1) {
54
+ candidates.push(dir)
55
+ const parent = dirname(dir)
56
+ if (parent === dir) break
57
+ dir = parent
58
+ }
59
+ const profilesRoot = join(home, 'profiles')
60
+ try {
61
+ for (const entry of readdirSync(profilesRoot)) {
62
+ if (entry.charAt(0) !== '.') candidates.push(join(profilesRoot, entry))
63
+ }
64
+ } catch (error) { /* no profiles directory */ }
65
+ const seen = new Set()
66
+ return candidates.filter((candidate) => {
67
+ if (seen.has(candidate)) return false
68
+ seen.add(candidate)
69
+ return true
70
+ })
71
+ }
72
+
73
+ let resolvedProfileDir
74
+
75
+ function findProfileDir() {
76
+ if (resolvedProfileDir !== undefined) return resolvedProfileDir
77
+ const candidates = profileCandidates()
78
+ const strict = candidates.find((candidate) => isProfileDir(candidate))
79
+ if (strict !== undefined) {
80
+ resolvedProfileDir = strict
81
+ return resolvedProfileDir
82
+ }
83
+ const loose = candidates.find((candidate) => hasNodeModules(candidate))
84
+ resolvedProfileDir = loose
85
+ return resolvedProfileDir
86
+ }
87
+
88
+ /**
89
+ * Installation time of one installed package: the moment its directory entry
90
+ * appeared inside the profile's node_modules. The entry itself is usually a
91
+ * pnpm symlink, so read the link's own timestamp first and only fall back to
92
+ * the followed target when the entry is a real directory.
93
+ */
94
+ function installedAtOf(profileDir, packageName) {
95
+ const entry = join(profileDir, 'node_modules', packageName)
96
+ try {
97
+ return Math.round(lstatSync(entry).mtimeMs)
98
+ } catch (error) {
99
+ try {
100
+ return Math.round(statSync(join(entry, 'package.json')).mtimeMs)
101
+ } catch (inner) {
102
+ return undefined
103
+ }
104
+ }
105
+ }
106
+
107
+ function listInstalled(profileDir) {
108
+ try {
109
+ return readdirSync(join(profileDir, 'node_modules')).filter((entry) => entry !== '.bin' && !entry.startsWith('.'))
110
+ } catch (error) {
111
+ return []
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Package metadata the plugin manager does not surface: the short description
117
+ * a publisher wrote in package.json, used as a fallback when the bundle meta
118
+ * carries no localized description.
119
+ */
120
+ function packageInfo(profileDir, packageName) {
121
+ try {
122
+ const raw = readFileSync(join(profileDir, 'node_modules', packageName, 'package.json'), 'utf8')
123
+ const parsed = JSON.parse(raw)
124
+ const description = typeof parsed.description === 'string' ? parsed.description.slice(0, 400) : ''
125
+ const version = typeof parsed.version === 'string' ? parsed.version : ''
126
+ const info = {}
127
+ if (description) info.description = description
128
+ if (version) info.version = version
129
+ return info
130
+ } catch (error) {
131
+ return undefined
132
+ }
133
+ }
134
+
135
+ function collect(profileDir, requested) {
136
+ const names = requested && requested.length
137
+ ? requested.filter((entry) => SAFE_NAME.test(entry))
138
+ : listInstalled(profileDir).flatMap((entry) => {
139
+ if (!entry.startsWith('@')) return [entry]
140
+ try {
141
+ return readdirSync(join(profileDir, 'node_modules', entry))
142
+ .filter((child) => !child.startsWith('.'))
143
+ .map((child) => `${entry}/${child}`)
144
+ } catch (error) {
145
+ return []
146
+ }
147
+ })
148
+ const installedAt = {}
149
+ const info = {}
150
+ for (const packageName of names) {
151
+ const at = installedAtOf(profileDir, packageName)
152
+ if (at !== undefined) installedAt[packageName] = at
153
+ const meta = packageInfo(profileDir, packageName)
154
+ if (meta !== undefined && (meta.description || meta.version)) info[packageName] = meta
155
+ }
156
+ return { installedAt, info }
157
+ }
158
+
159
+ /**
160
+ * Host admission fence for the local route. Delegates to the runtime's own
161
+ * `connection.requestRejection()` so the route inherits the browser auth the
162
+ * app already enforces; when that service is missing or throws, the request is
163
+ * rejected instead of falling through to a Host/Origin/loopback guess.
164
+ * @returns 0 when the request may proceed, otherwise the status code to send.
165
+ */
166
+ function refusalOf(ctx, req) {
167
+ try {
168
+ const connection = ctx.get('connection')
169
+ if (connection === undefined || connection === null) return 403
170
+ if (typeof connection.requestRejection !== 'function') return 403
171
+ const rejection = connection.requestRejection(req)
172
+ if (rejection === undefined || rejection === null || rejection === false) return 0
173
+ return typeof rejection === 'number' ? rejection : 403
174
+ } catch (error) {
175
+ return 403
176
+ }
177
+ }
178
+
179
+ function respond(res, status, payload) {
180
+ res.writeHead(status, {
181
+ 'Content-Type': 'application/json; charset=utf-8',
182
+ 'Cache-Control': 'no-store',
183
+ })
184
+ res.end(JSON.stringify(payload))
185
+ }
186
+
187
+ export function apply(ctx) {
188
+ const webServer = ctx.webServer ?? ctx.get('webServer')
189
+ if (webServer === undefined) return
190
+ ctx.effect(() => webServer.register({
191
+ kind: 'exact',
192
+ path: ROUTE,
193
+ async handler(req, res) {
194
+ const refusal = refusalOf(ctx, req)
195
+ if (refusal !== 0) {
196
+ respond(res, refusal, { error: 'unauthorized' })
197
+ return
198
+ }
199
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
200
+ respond(res, 405, { error: 'method-not-allowed' })
201
+ return
202
+ }
203
+ const profileDir = findProfileDir()
204
+ if (profileDir === undefined) {
205
+ respond(res, 503, { error: 'profile-not-found' })
206
+ return
207
+ }
208
+ let requested
209
+ try {
210
+ const url = new URL(req.url ?? ROUTE, 'http://localhost')
211
+ const raw = url.searchParams.get('names')
212
+ if (raw !== null) requested = raw.split(',').map((entry) => entry.trim()).filter(Boolean)
213
+ } catch (error) {
214
+ requested = undefined
215
+ }
216
+ const collected = collect(profileDir, requested)
217
+ respond(res, 200, collected)
218
+ },
219
+ }))
220
+ }
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "dsh-plugin-update-hub",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "已安装插件版本中枢:一次并发检查所有插件的落后情况,展示安装时间与可升级版本,按版本批量排队升级并实时显示进度。",
5
+ "icon": "icon.png",
6
+ "license": "MIT",
7
+ "author": "darianzes",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/darianzes/dsh-plugin-update-hub.git"
11
+ },
12
+ "homepage": "https://github.com/darianzes/dsh-plugin-update-hub#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/darianzes/dsh-plugin-update-hub/issues"
15
+ },
16
+ "type": "module",
17
+ "main": "index.js",
18
+ "files": [
19
+ "index.js",
20
+ "client.js",
21
+ "cordis.patch.yml",
22
+ "icon.png",
23
+ "README.md",
24
+ "LICENSE",
25
+ "README.zh.md"
26
+ ],
27
+ "exports": {
28
+ ".": "./index.js",
29
+ "./client": "./client.js",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "scripts": {
33
+ "test": "node test/host.mjs && node test/smoke.mjs"
34
+ },
35
+ "dsh": {
36
+ "bundle": {
37
+ "patch": "./cordis.patch.yml"
38
+ },
39
+ "client": {
40
+ "inject": [
41
+ "@deepseek-ai/dsh-api-remotes",
42
+ "@deepseek-ai/dsh-client-runtime",
43
+ "@deepseek-ai/dsh-client-connection",
44
+ "@deepseek-ai/dsh-client-ui-settings"
45
+ ],
46
+ "platform": "web"
47
+ }
48
+ },
49
+ "engines": {
50
+ "node": ">=22.13.0",
51
+ "dsh": ">=0.2.2-0 <0.3.0"
52
+ },
53
+ "keywords": [
54
+ "dsh",
55
+ "dsh-plugin",
56
+ "deepseek-harness",
57
+ "cordis",
58
+ "client-plugin",
59
+ "plugin-manager",
60
+ "update",
61
+ "upgrade",
62
+ "versions"
63
+ ]
6
64
  }