dsh-opencode-palette 1.4.0 → 1.4.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.
package/lib/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * dsh-opencode-palette v1.4.0 — 浏览器半(构建产物,勿手改)
2
+ * dsh-opencode-palette v1.4.1 — 浏览器半(构建产物,勿手改)
3
3
  * 数据驱动管线:opencode v1.18.12 官方主题 JSON → 颜色解析 → DSH 适配注入
4
4
  * 源:src/engine/* + runtime/client.mjs(npm run build 重新生成)
5
5
  */
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * dsh-opencode-palette v1.4.0 — 宿主半(no-op)
2
+ * dsh-opencode-palette v1.4.1 — 宿主半(no-op)
3
3
  *
4
4
  * 主题的全部工作在浏览器端(./client.js)完成:
5
5
  * - 34 个 opencode 主题(33 内置 JSON + system)经数据驱动管线解析
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-opencode-palette",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "DSH Web 多主题引擎:完整支持 opencode TUI 全部 34 个主题(33 内置 + system)。数据驱动管线:主题 JSON → 颜色解析 → DSH 适配注入;设置面板即时切换、持久化。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -10,8 +10,13 @@
10
10
  "./package.json": "./package.json"
11
11
  },
12
12
  "files": [
13
- "lib"
13
+ "lib",
14
+ "scripts"
14
15
  ],
16
+ "scripts": {
17
+ "postinstall": "node scripts/install-patch.cjs",
18
+ "preuninstall": "node scripts/uninstall-patch.cjs"
19
+ },
15
20
  "keywords": [
16
21
  "dsh",
17
22
  "deepseek-harness",
@@ -0,0 +1,58 @@
1
+ /**
2
+ * dsh-opencode-palette postinstall — 自动注册到 DSH profile(npm 标准安装即完成,无需手动编辑 patch)
3
+ *
4
+ * 行为:
5
+ * 1. 定位 $DSH_HOME/profiles/web/cordis.patch.yml(DSH_HOME 未设 → ~/.dsh/profiles/web/…)
6
+ * 2. 文件不存在 → 跳过(非 DSH 环境不打扰)
7
+ * 3. 已含注册行 → 跳过(幂等,重装/升级不叠加)
8
+ * 4. 否则文件末尾追加注册块(- insert: id opencode-palette / name dsh-opencode-palette)
9
+ * 容错:任何异常只警告,绝不令 npm install 失败(退出码恒 0)。
10
+ */
11
+ const fs = require('fs')
12
+ const path = require('path')
13
+
14
+ const PLUGIN_ID = 'opencode-palette'
15
+ const PLUGIN_NAME = 'dsh-opencode-palette'
16
+
17
+ function findPatchPath() {
18
+ const home = process.env.DSH_HOME
19
+ || (process.platform === 'win32' ? process.env.USERPROFILE : process.env.HOME)
20
+ if (!home) return null
21
+ return path.join(home, '.dsh', 'profiles', 'web', 'cordis.patch.yml')
22
+ }
23
+
24
+ const REGISTER_BLOCK =
25
+ '\n# dsh-opencode-palette(npm 安装 · 自动注册)\n' +
26
+ '- insert:\n' +
27
+ ' - id: ' + PLUGIN_ID + '\n' +
28
+ " name: '" + PLUGIN_NAME + "'\n"
29
+
30
+ function main() {
31
+ const patch = findPatchPath()
32
+ if (!patch) {
33
+ console.log('[dsh-opencode-palette] 未找到 DSH_HOME,跳过自动注册(非 DSH 环境)')
34
+ return
35
+ }
36
+ let existed = true
37
+ let text = ''
38
+ try {
39
+ text = fs.readFileSync(patch, 'utf8')
40
+ } catch (e) {
41
+ existed = false
42
+ }
43
+ if (existed && new RegExp("id\\s*:\\s*['\"]?" + PLUGIN_ID + "['\"]?").test(text)) {
44
+ console.log('[dsh-opencode-palette] 已在 cordis.patch.yml 注册,跳过')
45
+ return
46
+ }
47
+ try {
48
+ fs.mkdirSync(path.dirname(patch), { recursive: true })
49
+ fs.appendFileSync(patch, REGISTER_BLOCK, 'utf8')
50
+ console.log('[dsh-opencode-palette] 已自动注册到 ' + patch + '(刷新浏览器页面即生效)')
51
+ } catch (e) {
52
+ console.warn('[dsh-opencode-palette] 自动注册失败(不影响本包安装):' + String((e && e.message) || e))
53
+ }
54
+ }
55
+
56
+ try { main() } catch (e) {
57
+ console.warn('[dsh-opencode-palette] postinstall 异常(已忽略):' + String((e && e.message) || e))
58
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * dsh-opencode-palette preuninstall — 自动从 DSH profile 移除注册(npm remove 即完成,无需手动编辑 patch)
3
+ * 幂等:不存在注册块 → 直接返回;任何异常只警告,退出码恒 0。
4
+ */
5
+ const fs = require('fs')
6
+ const path = require('path')
7
+
8
+ const PLUGIN_ID = 'opencode-palette'
9
+
10
+ function findPatchPath() {
11
+ const home = process.env.DSH_HOME
12
+ || (process.platform === 'win32' ? process.env.USERPROFILE : process.env.HOME)
13
+ if (!home) return null
14
+ return path.join(home, '.dsh', 'profiles', 'web', 'cordis.patch.yml')
15
+ }
16
+
17
+ // 匹配注册块:可选注释行 + insert 块(容错 name 引号/缩进变化)
18
+ const BLOCK_RE = new RegExp(
19
+ '(?:^|\\n)\\s*# dsh-opencode-palette[^\\n]*\\n' +
20
+ '\\s*- insert:\\n' +
21
+ '\\s*\\s*- id:\\s*' + PLUGIN_ID + '\\s*\\n' +
22
+ "\\s*\\s*name:\\s*['\"]?dsh-opencode-palette['\"]?\\s*\\n",
23
+ 'g'
24
+ )
25
+
26
+ function main() {
27
+ const patch = findPatchPath()
28
+ if (!patch) return
29
+ let text = ''
30
+ try {
31
+ text = fs.readFileSync(patch, 'utf8')
32
+ } catch (e) {
33
+ return // 文件不存在 → 无需清理
34
+ }
35
+ const next = text.replace(BLOCK_RE, '\n')
36
+ if (next === text) {
37
+ console.log('[dsh-opencode-palette] 未在 cordis.patch.yml 找到注册块,无需清理')
38
+ return
39
+ }
40
+ try {
41
+ fs.writeFileSync(patch, next, 'utf8')
42
+ console.log('[dsh-opencode-palette] 已从 cordis.patch.yml 移除注册(卸载完成)')
43
+ } catch (e) {
44
+ console.warn('[dsh-opencode-palette] 移除注册失败:' + String((e && e.message) || e))
45
+ }
46
+ }
47
+
48
+ try { main() } catch (e) {
49
+ console.warn('[dsh-opencode-palette] preuninstall 异常(已忽略):' + String((e && e.message) || e))
50
+ }