@vibedev-si/dsh-island 0.2.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibedev-si/dsh-island",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "VibeDev 岛屿:在屏幕顶部常驻显示 VibeDev 会话进度、等你处理的审批和提问、插件后台任务,以及待办、剪贴板、音乐与截图。岛屿是独立的原生程序,由本插件启动和管理;仅支持 Windows · VibeDev Island: an always-on status surface for VibeDev, started and managed by this plugin (Windows only)",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -23,6 +23,9 @@
23
23
  "events.js",
24
24
  "selection.js",
25
25
  "approvals.js",
26
+ "approval-details.js",
27
+ "account-usage.js",
28
+ "usage-host.js",
26
29
  "outbox.js",
27
30
  "island-items.js",
28
31
  "diagnostics.js",
@@ -36,6 +39,8 @@
36
39
  "wechat.js",
37
40
  "contributions.js",
38
41
  "executable.js",
42
+ "platform.js",
43
+ "features.js",
39
44
  "contributor-display.js",
40
45
  "contributor-entry.js",
41
46
  "recent.js",
package/platform.js ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * 插件一半里和操作系统有关的几件事:设置放哪、开发时手动放的岛屿程序在哪、随包的程序在包里哪个目录、
3
+ * 怎么在文件管理器里选中一个文件、诊断信息里怎么写系统。
4
+ *
5
+ * Windows 上的结果和以前完全一样(`%APPDATA%\VibeDev`、`%LOCALAPPDATA%\VibeDev\island`、`explorer /select,`)。
6
+ * macOS 用 `~/Library/Application Support/VibeDev` 和 `open -R`。别的系统给出路径,但没有岛屿程序。
7
+ *
8
+ * 纯函数:系统、环境变量、主目录、CPU 架构都由调用方给,测试里换成假的。
9
+ */
10
+ import { join } from 'node:path'
11
+
12
+ /** 岛屿程序的文件名。 */
13
+ export const ISLAND_PROGRAM = Object.freeze({ win32: 'vibedev-island.exe', darwin: 'vibedev-island' })
14
+
15
+ /** 设置这类小文件放在哪个目录(`VibeDev` 那一层)。 */
16
+ export function appDataDir({ platform, env, home }) {
17
+ if (platform === 'win32') return join(env.APPDATA ?? join(env.USERPROFILE ?? home, 'AppData', 'Roaming'), 'VibeDev')
18
+ if (platform === 'darwin') return join(home, 'Library', 'Application Support', 'VibeDev')
19
+ return join(env.XDG_CONFIG_HOME ?? join(home, '.config'), 'VibeDev')
20
+ }
21
+
22
+ /** 开发时手动放岛屿程序的目录(`VibeDev/island` 那一层)。 */
23
+ export function devProgramDir({ platform, env, home }) {
24
+ if (platform === 'win32')
25
+ return join(env.LOCALAPPDATA ?? join(env.USERPROFILE ?? home, 'AppData', 'Local'), 'VibeDev', 'island')
26
+ if (platform === 'darwin') return join(home, 'Library', 'Application Support', 'VibeDev', 'island')
27
+ return join(env.XDG_DATA_HOME ?? join(home, '.local', 'share'), 'VibeDev', 'island')
28
+ }
29
+
30
+ /**
31
+ * 随包的岛屿程序在包里的位置(`bin/<系统>-<架构>/<文件名>`);这个系统没有岛屿程序时是 undefined。
32
+ * @param {{ platform: string, arch: string }} where
33
+ * @returns {string[] | undefined}
34
+ */
35
+ export function bundledProgram({ platform, arch }) {
36
+ const name = ISLAND_PROGRAM[platform]
37
+ return name === undefined ? undefined : ['bin', `${platform}-${arch}`, name]
38
+ }
39
+
40
+ /**
41
+ * 在文件管理器里选中一个文件要运行的程序和参数。
42
+ * @param {string} platform
43
+ * @param {string} path
44
+ * @returns {{ program: string, args: string[] }}
45
+ */
46
+ export function revealCommand(platform, path) {
47
+ if (platform === 'win32') return { program: 'explorer.exe', args: [`/select,${path}`] }
48
+ if (platform === 'darwin') return { program: 'open', args: ['-R', path] }
49
+ return { program: 'xdg-open', args: [path.replace(/[\\/][^\\/]*$/, '') || path] }
50
+ }
51
+
52
+ /** 诊断信息里的系统一行(macOS 的 `os.release()` 是 Darwin 内核版本,照实写)。 */
53
+ export function systemLabel(platform, release) {
54
+ if (platform === 'darwin') return `macOS (Darwin ${release})`
55
+ const name = { win32: 'Windows', linux: 'Linux' }[platform] ?? platform
56
+ return `${name} ${release}`
57
+ }
package/routes.js CHANGED
@@ -25,6 +25,7 @@ export const CONTROL_ACTIONS = [
25
25
  'stop',
26
26
  'restart',
27
27
  'suspend',
28
+ 'open-native-settings',
28
29
  'qq-request-access',
29
30
  'qq-open-settings',
30
31
  'reset-settings',
package/settings.js CHANGED
@@ -5,7 +5,9 @@
5
5
  * 读入时按默认值的结构合并、丢掉未知字段、把越界数字夹回范围——用户手改文件也不会把岛搞坏。
6
6
  */
7
7
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
8
+ import { homedir } from 'node:os'
8
9
  import { dirname, join } from 'node:path'
10
+ import { appDataDir } from './platform.js'
9
11
 
10
12
  /**
11
13
  * 岛屿真正会读的设置,一项不多。
@@ -88,8 +90,10 @@ export const DEFAULT_SETTINGS = {
88
90
  notifyOnQuestion: true,
89
91
  /** VibeDev 等你批准时在岛上出一张卡片。 */
90
92
  approveOnIsland: true,
91
- /** 不在 VibeDev 里时,先在小岛上问允许还是拒绝;危险操作只能回 VibeDev,60 秒没人管就交回。 */
93
+ /** 不在 VibeDev 里时,先在小岛上问允许还是拒绝;危险操作交回 VibeDev。 */
92
94
  decideOnIsland: true,
95
+ /** 原生岛屿上的交互请求没人处理时,多久交回 VibeDev。 */
96
+ approvalTimeoutSeconds: 60,
93
97
  },
94
98
 
95
99
  todos: {
@@ -162,6 +166,8 @@ const LIMITS = {
162
166
  'clipboard.maxItems': [20, 200],
163
167
  }
164
168
 
169
+ const APPROVAL_TIMEOUT_SECONDS = [15, 30, 60, 120]
170
+
165
171
  /** 枚举值:只接受列出的选项。 */
166
172
  const CHOICES = {
167
173
  'appearance.theme': ['vibedev', 'dark', 'light'],
@@ -172,6 +178,7 @@ const CHOICES = {
172
178
  'sessions.titleMode': ['changes', 'always', 'never'],
173
179
  'sessions.lightStyle': ['dot', 'ring'],
174
180
  'sessions.sound': ['exclamation', 'notify', 'message', 'calendar', 'chimes', 'chord', 'tada'],
181
+ 'sessions.approvalTimeoutSeconds': APPROVAL_TIMEOUT_SECONDS,
175
182
  // 发送到会话、识别文字还没做;旧值 send / ocr 会被夹回默认的 copy。
176
183
  'screenshot.action': ['copy', 'save', 'send'],
177
184
  // line 折叠条上一行 / banner 折叠的小岛下面的一张卡片 / panel 直接展开到消息页。
@@ -199,9 +206,9 @@ export function normalizePages(pages) {
199
206
  return { ...pages, order, hidden: allHidden ? hidden.filter((page) => page !== order[0]) : hidden }
200
207
  }
201
208
 
209
+ /** 设置文件:Windows 是 `%APPDATA%\VibeDev\island-settings.json`,macOS 在 `~/Library/Application Support/VibeDev`(platform.js)。 */
202
210
  export function settingsPath() {
203
- const appData = process.env.APPDATA ?? join(process.env.USERPROFILE ?? '', 'AppData', 'Roaming')
204
- return join(appData, 'VibeDev', 'island-settings.json')
211
+ return join(appDataDir({ platform: process.platform, env: process.env, home: homedir() }), 'island-settings.json')
205
212
  }
206
213
 
207
214
  function merge(defaults, incoming) {
@@ -265,8 +272,10 @@ function isShortcut(value) {
265
272
  )
266
273
  }
267
274
 
275
+ const validTranslationShortcut = (value) => typeof value === 'string' && (value.trim() === '' || isShortcut(value))
276
+
268
277
  /** 快捷键字段的位置,用来在合并后统一校验。 */
269
- const SHORTCUT_FIELDS = ['clipboard.shortcut', 'screenshot.shortcut', 'translation.shortcut']
278
+ const SHORTCUT_FIELDS = ['clipboard.shortcut', 'screenshot.shortcut']
270
279
 
271
280
  /** 可以不设的快捷键:空字符串合法,表示不注册。 */
272
281
  const OPTIONAL_SHORTCUT_FIELDS = ['behavior.toggleShortcut', 'behavior.sessionsShortcut']
@@ -291,6 +300,10 @@ export function normalize(incoming) {
291
300
  for (const path of SHORTCUT_FIELDS) {
292
301
  if (!isShortcut(getAt(merged, path))) setAt(merged, path, getAt(DEFAULT_SETTINGS, path))
293
302
  }
303
+ const translationShortcut = merged.translation.shortcut.trim()
304
+ merged.translation.shortcut = validTranslationShortcut(translationShortcut)
305
+ ? translationShortcut
306
+ : DEFAULT_SETTINGS.translation.shortcut
294
307
  // 可选的快捷键:格式不合法就当没设,而不是塞一个默认组合进去。
295
308
  for (const path of OPTIONAL_SHORTCUT_FIELDS) {
296
309
  const value = getAt(merged, path).trim()
@@ -312,6 +325,47 @@ export function applyPatch(current, patch) {
312
325
  return normalize(merge(normalize(current), patch))
313
326
  }
314
327
 
328
+ const boolean = (value) => typeof value === 'boolean'
329
+ const NATIVE_SETTINGS = {
330
+ sessions: {
331
+ approveOnIsland: boolean,
332
+ decideOnIsland: boolean,
333
+ approvalTimeoutSeconds: (value) => APPROVAL_TIMEOUT_SECONDS.includes(value),
334
+ },
335
+ screenshot: {
336
+ enabled: boolean,
337
+ action: (value) => CHOICES['screenshot.action'].includes(value),
338
+ saveDirectory: (value) => typeof value === 'string',
339
+ shortcut: isShortcut,
340
+ },
341
+ translation: {
342
+ selection: boolean,
343
+ provider: (value) => CHOICES['translation.provider'].includes(value),
344
+ shortcut: validTranslationShortcut,
345
+ readOtherApps: boolean,
346
+ },
347
+ }
348
+
349
+ /** 只允许原生设置窗口修改它真的显示的宿主设置,不把其它字段交给普通补丁合并。 */
350
+ export function nativeSettingsPatch(input) {
351
+ const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value)
352
+ if (!isObject(input)) return undefined
353
+ const sections = Object.entries(input)
354
+ if (sections.length === 0) return undefined
355
+ const patch = {}
356
+ for (const [section, inputFields] of sections) {
357
+ if (!Object.hasOwn(NATIVE_SETTINGS, section) || !isObject(inputFields)) return undefined
358
+ const fields = Object.entries(inputFields)
359
+ const allowed = NATIVE_SETTINGS[section]
360
+ if (fields.length === 0) return undefined
361
+ for (const [key, value] of fields) {
362
+ if (!Object.hasOwn(allowed, key) || !allowed[key](value)) return undefined
363
+ }
364
+ patch[section] = Object.fromEntries(fields)
365
+ }
366
+ return patch
367
+ }
368
+
315
369
  function getAt(target, path) {
316
370
  return path
317
371
  .split('.')