dsh-snowbreak-heimdall 3.0.0 → 3.0.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # 雪境 Heimdall Terminal
1
+ # 雪境 Heimdall Terminal
2
2
 
3
3
  > 《尘白禁区》风格的 DeepSeek Harness **源码层皮肤**。
4
4
  > 加载画面、主题、菜单、品牌、图标、欢迎页/更新页与主界面文案由 `app.asar` 和安装目录负责;插件只保留启动动画。
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## 当前状态
9
9
 
10
- - 插件:`dsh-snowbreak-heimdall@3.0.0`,profile `desktop` 已启用。
10
+ - 插件:`dsh-snowbreak-heimdall@3.0.1`,profile `desktop` 已启用。
11
11
  - 当前运行:`142164e9…9555`
12
12
  - `reapply=false`,这一版已经应用完成;**不需要再退出或重写 asar**。
13
13
  - 当前版本已把主界面剩余的 DSH 原生内容换掉:
@@ -61,11 +61,14 @@ DSH 完全退出后,helper 启动 **PowerShell WPF WS_POPUP**:
61
61
  - 100% 后显示「接入链路已闭合」和「启动终端 / LAUNCH DSH」
62
62
  - 按钮 `Start-Process` 拉起 DSH 并关闭窗口
63
63
  - 失败时显示错误和关闭按钮
64
+ - **还原模式**:100% 后显示「官方源码层已恢复」,3 秒后自动关闭,并删除 `resources\HeimdallTerminal`(progress、runtime、备份、日志、锁)——窗口和临时文件一起清掉。
65
+ - 插件包本身由 DSH 插件管理器的卸载流程移除;helper 只清理安装目录内的运行状态。
64
66
 
65
67
  预览:
66
68
 
67
69
  - `assets/previews/progress-winforms.png`(84% 进行中)
68
- - `assets/previews/progress-winforms-complete.png`(100% 完成页)
70
+ - `assets/previews/progress-winforms-complete.png`(100% 应用完成页)
71
+ - `assets/previews/progress-winforms-restore.png`(还原完成,3 秒后自删)
69
72
 
70
73
  ---
71
74
 
@@ -97,7 +100,7 @@ DSH 完全退出后,helper 启动 **PowerShell WPF WS_POPUP**:
97
100
  不是“复制文件夹后双击即用”。对方需要:
98
101
 
99
102
  1. 同版本 DSH `0.2.2-rc.1`(补丁锚点按该版本校验,其他版本会拒绝写入)。
100
- 2. 在 DSH 插件管理器/安装指令中安装 npm 包 `dsh-snowbreak-heimdall`;安装后启用插件。
103
+ 2. 在 DSH 插件管理器/安装指令中安装 npm 包 `dsh-snowbreak-heimdall@3.0.1`;安装后启用插件。
101
104
  也可以手动把包安装到 profile 后加入 `dsh.profile.bundles`。
102
105
  3. 启用插件,然后完整退出 DSH;helper 才会写入源码层。
103
106
  4. Windows 用户;DSH 安装目录可写(默认 `%LOCALAPPDATA%\Programs\DeepSeek Harness`,自定义路径可设 `HEIMDALL_TARGET` / `HEIMDALL_RESOURCES`)。
@@ -171,5 +174,6 @@ snowbreak-heimdall/
171
174
  - 状态:已应用,`reapply=false`
172
175
 
173
176
  详细测试见 [TEST-REPORT.md](TEST-REPORT.md)。
174
-
175
-
177
+
178
+
179
+
package/SHA256SUMS.txt CHANGED
@@ -18,6 +18,7 @@ ea2a6dc80e61bd90cbb29f98eeeeff8bc9a803cdc2d9ec207aba665619db4164 *assets\preview
18
18
  633f757eaebbd7ae353a6a9a2a221d5c49ea7f0b3265a2bd1dc4d75546603141 *assets\previews\mask-test.png
19
19
  09128405ece6b38aa94b7e206f698d57ca50531b459ab14962662b9ffcbcadec *assets\previews\progress-winforms.png
20
20
  5df2fdd499cea77f8dde1efcf9fd842a6e939cacbc24cf5ec39b4622c30ed2e4 *assets\previews\progress-winforms-complete.png
21
+ b4019a637dc144f90d50336960a4e83531cf87ff94d1951dc0671ece70c333a5 *assets\previews\progress-winforms-restore.png
21
22
  b5f2ff21b67a6a0c178d251af49331319eb42e9e140e279e391edda30112bf47 *assets\previews\ui-chrome.png
22
23
  3ebaa8c085365385745ec2ceac437970a146581487c89ae4e4b4e4e15a5c5ec5 *assets\source\brand-client.js
23
24
  12ea3ea272ae13b66f2875c42d466053516588057bb90775499e0fdb575fe624 *assets\source\client-template.js
@@ -29,7 +30,7 @@ b7326e8f747b124547f19b8bbbf16ecb8d020778b360df28a7fec14efc55624c *assets\source\
29
30
  9926df428efeceb92b3242b2c21025cae84ceade8734d258ba67a2c231c0fddd *assets\source\logo.webp
30
31
  0a2e1c9c2a82487f414aaa68dbc01a59d9b1bbec973732bb32d08d90cc2ea982 *assets\source\mark-alpha.png
31
32
  ff37ef4ee56454e42d2d47cdbbdc634c6b0b34e43817d4139ef7831b049714ec *assets\source\mark-color.png
32
- e70d4b0c9084931eb3ae3405dfca633a3c43456158d40c89b79dd35940290451 *assets\source\progress.ps1
33
+ 105b2913a0232daf52793edf7531b27b1fa2830aa861d1e6c97e60e4f5bbd7d7 *assets\source\progress.ps1
33
34
  c82cfaafcb317919e117d7f9983bb6230a69adf5356d78c2bb3f2bf2016b79df *assets\source\shell.css
34
35
  724f25bb1908f43180c7330669767dca05cbd61d3aee4b65401949a16e3c4a2d *assets\source\shell.js
35
36
  f39417379634fd601613323bf56c0226bf135a41e153b90929627edc89b1edfe *assets\source\update.css
@@ -41,14 +42,14 @@ aef34c1fed4a009a78955f5316b999bbd157fd082d7441d34852d32f0a481c28 *assets\source\
41
42
  2a0b4b9c68d5f4b87bb8fbb768a1933c40394fe4e6f23c144fae88052ebe4a02 *cordis.patch.yml
42
43
  065af22a9be00dc76ce08bc647814d33da2779e937db6c5fa4ea0dcb8c65caa9 *icon.svg
43
44
  67fb090954b1d63521e8838b519bf82ce01a7fa4a36e2bd653accdcd6e789740 *lib\client.js
44
- 71dad9c6bb4eefbe3bdf668707f967950ef1f65e7aedc0c707739dd3a66b8533 *lib\index.js
45
+ 9612a760064aaf72e59763272b5e7f823cd37a380f64dcd3fc0a2bd411b7ce60 *lib\index.js
45
46
  0794a24c333ef529e56c6eb7b1dee62f4f5b8da1c56fe001885824ce2a3f8b2f *LICENSE
46
47
  de949631618eb48bf5cd6c06698a28214c8e9cb4bca23d298cd89462f4fb260e *locale\en.json
47
48
  e931cfb8c9b64aa4e01363e603537afee392e8309fe07daaff3e07e028ab8010 *locale\zh.json
48
- 8fb51c2a894dd3991cee6d4719d282a296c4d985d45b6fc9f53c66725923e0ff *package.json
49
+ 3a2c4f171864b124dbefbc62cd4669eca835cca5b3de9d5fba56e6d6c0e1b57e *package.json
49
50
  8fa6aff9fa2ab7eb11cc813c7ed9cda2b9ae7757c039aad8d71d5b56b5b683d9 *patch\asar.py
50
- 519cf7a69c96aa494bf5e99cb3304cbd6798a7e56a165c605aab51160337c7ef *patch\patcher.py
51
- 8653a5c487619bb9dde8fd139bb402771252abc03cb1bfc2b2db8e45b15ad57c *README.md
51
+ 771e160fc006714e373735a635638d33644eb686e0c7b41478262c136ad70710 *patch\patcher.py
52
+ 9466799d0b23c78e555660cd3c9a0d63553eb961a491029da05a90fc5198c6bc *README.md
52
53
  8978acd5618d9148ca20804d823af6decb0b20af4569b39e8a641f559277db0c *TEST-REPORT.md
53
54
  73ac5fa42ee7de25615deb7315de7e2609f76b52e636b6a03397c7203bf17bc2 *tools\build_assets.py
54
55
  a8c0badcd2e0cac12cf03528a892c51ec1e6cbde0352ebfb5d5243cbe1f59f8e *tools\build_client.py
@@ -4,7 +4,8 @@ $ErrorActionPreference = 'Stop'
4
4
  $ProgressPath = '__PROGRESS_PATH__'
5
5
  $LogoPath = '__LOGO_PATH__'
6
6
  $AppExe = '__APP_EXE__'
7
- $LogPath = Join-Path (Split-Path -Parent $ProgressPath) 'ui.log'
7
+ $StateDir = Split-Path -Parent $ProgressPath
8
+ $LogPath = Join-Path $StateDir 'ui.log'
8
9
 
9
10
  function Write-UiLog($text) {
10
11
  try { Add-Content -LiteralPath $LogPath -Value ("[" + (Get-Date -Format 'HH:mm:ss') + "] " + $text) -Encoding UTF8 } catch {}
@@ -91,9 +92,9 @@ public class HeimdallDpi {
91
92
  <Border Width="130" Height="130" CornerRadius="65" BorderBrush="#7FB2D0" BorderThickness="1" Background="#05080C" HorizontalAlignment="Center">
92
93
  <Image x:Name="CompleteLogo" Width="64" Height="40" Stretch="Uniform"/>
93
94
  </Border>
94
- <TextBlock Text="LINK CLOSED // 覆盖完成" FontSize="10" Foreground="#7FB2D0" HorizontalAlignment="Center" Margin="0,18,0,0"/>
95
- <TextBlock Text="接入链路已闭合" FontSize="34" FontWeight="Bold" Foreground="#E6EEF5" HorizontalAlignment="Center" Margin="0,8,0,0"/>
96
- <TextBlock Text="HM-04 · ANALYST-04 · CLEARANCE A · ZERO ZONE" FontSize="10" Foreground="#7E8E9E" HorizontalAlignment="Center" Margin="0,8,0,0"/>
95
+ <TextBlock x:Name="Kicker" Text="LINK CLOSED // 覆盖完成" FontSize="10" Foreground="#7FB2D0" HorizontalAlignment="Center" Margin="0,18,0,0"/>
96
+ <TextBlock x:Name="CompleteTitle" Text="接入链路已闭合" FontSize="34" FontWeight="Bold" Foreground="#E6EEF5" HorizontalAlignment="Center" Margin="0,8,0,0"/>
97
+ <TextBlock x:Name="CompleteMeta" Text="HM-04 · ANALYST-04 · CLEARANCE A · ZERO ZONE" FontSize="10" Foreground="#7E8E9E" HorizontalAlignment="Center" Margin="0,8,0,0"/>
97
98
  <Button x:Name="Launch" Width="300" Height="58" Margin="0,26,0,0" HorizontalAlignment="Center"
98
99
  Background="#D97745" Foreground="#0A0F14" BorderThickness="0" Cursor="Hand">
99
100
  <StackPanel>
@@ -101,7 +102,7 @@ public class HeimdallDpi {
101
102
  <TextBlock Text="LAUNCH DSH" FontSize="9" HorizontalAlignment="Center" Margin="0,2,0,0"/>
102
103
  </StackPanel>
103
104
  </Button>
104
- <TextBlock Text="点击后启动 DeepSeek Harness,当前窗口会自动关闭" FontSize="9" Foreground="#7E8E9E" HorizontalAlignment="Center" Margin="0,12,0,0"/>
105
+ <TextBlock x:Name="CompleteNote" Text="点击后启动 DeepSeek Harness,当前窗口会自动关闭" FontSize="9" Foreground="#7E8E9E" HorizontalAlignment="Center" Margin="0,12,0,0"/>
105
106
  </StackPanel>
106
107
  </Grid>
107
108
 
@@ -155,6 +156,10 @@ public class HeimdallDpi {
155
156
  $errorText = $window.FindName('ErrorText')
156
157
  $launch = $window.FindName('Launch')
157
158
  $closeError = $window.FindName('CloseError')
159
+ $kicker = $window.FindName('Kicker')
160
+ $completeTitle = $window.FindName('CompleteTitle')
161
+ $completeMeta = $window.FindName('CompleteMeta')
162
+ $completeNote = $window.FindName('CompleteNote')
158
163
 
159
164
  $stepNames = @('等待主进程退出', '备份官方归档与图标', '重打包源码层', '逐条目哈希校验', '写入图标并闭合链路')
160
165
  $stepCodes = @('WAIT', 'BACKUP', 'PACK', 'VERIFY', 'WRITE')
@@ -205,6 +210,27 @@ public class HeimdallDpi {
205
210
  }
206
211
 
207
212
  $script:lastPct = 0
213
+ $script:cleanupState = $false
214
+ $script:cleanupStarted = $false
215
+
216
+ function Start-StateCleanup {
217
+ if ($script:cleanupStarted) { return }
218
+ $script:cleanupStarted = $true
219
+ try {
220
+ $cleanup = Join-Path $env:TEMP ('heimdall-cleanup-' + [guid]::NewGuid().ToString('N') + '.cmd')
221
+ $lines = @(
222
+ '@echo off',
223
+ 'ping -n 7 127.0.0.1 >nul',
224
+ 'rmdir /s /q "' + $StateDir + '"',
225
+ 'del "%~f0" >nul 2>nul'
226
+ )
227
+ [IO.File]::WriteAllLines($cleanup, $lines, [Text.Encoding]::ASCII)
228
+ Start-Process -FilePath $env:ComSpec -ArgumentList '/c', $cleanup -WindowStyle Hidden
229
+ } catch {
230
+ Write-UiLog ('cleanup: ' + $_.Exception.Message)
231
+ }
232
+ }
233
+ $window.Add_Closed({ if ($script:cleanupState) { Start-StateCleanup } })
208
234
  $timer = New-Object Windows.Threading.DispatcherTimer
209
235
  $timer.Interval = [TimeSpan]::FromMilliseconds(350)
210
236
  $timer.Add_Tick({
@@ -249,9 +275,24 @@ public class HeimdallDpi {
249
275
  }
250
276
  if ($map['done'] -eq '1') {
251
277
  $timer.Stop()
278
+ $mode = if ($map['mode']) { $map['mode'] } else { 'apply' }
252
279
  $complete.Visibility = 'Visible'
253
280
  $complete.BringIntoView()
254
- $launch.Focus()
281
+ if ($mode -eq 'restore') {
282
+ $script:cleanupState = $true
283
+ $kicker.Text = 'OFFICIAL LAYER // 还原完成'
284
+ $completeTitle.Text = '官方源码层已恢复'
285
+ $completeMeta.Text = 'HEIMDALL // TEMP CLEANUP'
286
+ $completeNote.Text = '窗口将在 3 秒后关闭并清理临时文件'
287
+ $launch.Visibility = 'Collapsed'
288
+ Start-StateCleanup
289
+ $autoClose = New-Object Windows.Threading.DispatcherTimer
290
+ $autoClose.Interval = [TimeSpan]::FromSeconds(3)
291
+ $autoClose.Add_Tick({ $autoClose.Stop(); if ($script:cleanupState) { Start-StateCleanup }; $window.Close() })
292
+ $autoClose.Start()
293
+ } else {
294
+ $launch.Focus()
295
+ }
255
296
  return
256
297
  }
257
298
  $noteText.Text = '请勿关闭此窗口'
@@ -300,6 +341,7 @@ public class HeimdallDpi {
300
341
  } catch {
301
342
  Write-UiLog ("snapshot: " + $_.Exception.Message)
302
343
  }
344
+ if ($script:cleanupState) { Start-StateCleanup }
303
345
  $window.Close()
304
346
  })
305
347
  $window.Add_ContentRendered({ $snap.Start() })
package/lib/index.js CHANGED
@@ -1,239 +1,239 @@
1
- /**
2
- * Snowbreak: Heimdall Terminal — source-layer companion.
3
- *
4
- * The plugin does NOT paint the loading screen and does NOT own the palette.
5
- * It stages a self-contained copy of the source patcher inside the DSH
6
- * installation and leaves one disposable helper that reconciles the asar and
7
- * icons after every DSH process has exited. No Startup entry, scheduled task,
8
- * registry value, service, HTTP listener, or auto-relaunch is used.
9
- */
10
- import fs from 'node:fs';
11
- import os from 'node:os';
12
- import path from 'node:path';
13
- import { spawn } from 'node:child_process';
14
- import { fileURLToPath } from 'node:url';
15
-
16
- const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
17
- const VERSION = '3.0.0';
18
- const INSTALL = path.join(process.env.LOCALAPPDATA || '', 'Programs', 'DeepSeek Harness');
19
- const DEFAULT_RESOURCES = process.env.HEIMDALL_RESOURCES
20
- || (typeof process.resourcesPath === 'string' && /[\\/]resources$/i.test(process.resourcesPath)
21
- ? process.resourcesPath
22
- : path.join(INSTALL, 'resources'));
23
- const TARGET = process.env.HEIMDALL_TARGET || path.join(DEFAULT_RESOURCES, 'app.asar');
24
- const RESOURCES = path.dirname(TARGET);
25
- const STATE_DIR = path.join(RESOURCES, 'HeimdallTerminal');
26
- const RUNTIME = path.join(STATE_DIR, 'runtime');
27
- const LOG = path.join(STATE_DIR, 'host.log');
28
- const PROFILE_DIR = process.env.DSH_PROFILE_DIR
29
- || path.join(process.env.DSH_HOME || path.join(os.homedir(), '.dsh'), 'profiles', 'desktop');
30
- const WSCRIPT = path.join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'wscript.exe');
31
-
32
- const EXCLUDED_PY = new Set([
33
- 'site-packages', '__pycache__', 'test', 'tests', 'idlelib', 'tkinter', 'turtledemo',
34
- 'ensurepip', 'lib2to3', 'pydoc_data', 'venv', 'distutils', 'tcl', 'Scripts', 'include', 'libs',
35
- ]);
36
-
37
- function log(message) {
38
- try {
39
- fs.mkdirSync(STATE_DIR, { recursive: true });
40
- fs.appendFileSync(LOG, '[' + new Date().toISOString() + '] ' + message + '\n', 'utf8');
41
- } catch (_) { /* diagnostics only */ }
42
- }
43
-
44
- function readState() {
45
- try { return JSON.parse(fs.readFileSync(path.join(STATE_DIR, 'state.json'), 'utf8')); }
46
- catch (_) { return {}; }
47
- }
48
-
49
- function writeState(patch) {
50
- try {
51
- fs.mkdirSync(STATE_DIR, { recursive: true });
52
- const file = path.join(STATE_DIR, 'state.json');
53
- const next = { ...readState(), ...patch, hostUpdatedAt: new Date().toISOString() };
54
- const tmp = file + '.tmp';
55
- fs.writeFileSync(tmp, JSON.stringify(next, null, 2) + '\n', 'utf8');
56
- fs.renameSync(tmp, file);
57
- } catch (error) {
58
- log('state write failed: ' + error.message);
59
- }
60
- }
61
-
62
- function sleep(ms) {
63
- try { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); }
64
- catch (_) { /* best effort */ }
65
- }
66
-
67
- function copyFileRetry(source, destination) {
68
- for (let attempt = 0; attempt < 6; attempt += 1) {
69
- try {
70
- fs.copyFileSync(source, destination);
71
- return;
72
- } catch (error) {
73
- if (attempt === 5) throw error;
74
- sleep(120);
75
- }
76
- }
77
- }
78
-
79
- function copyTree(source, destination, filter) {
80
- if (!fs.existsSync(source)) return;
81
- fs.mkdirSync(destination, { recursive: true });
82
- for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
83
- const src = path.join(source, entry.name);
84
- if (filter && !filter(src)) continue;
85
- const dst = path.join(destination, entry.name);
86
- if (entry.isDirectory()) copyTree(src, dst, filter);
87
- else copyFileRetry(src, dst);
88
- }
89
- }
90
-
91
- function findPythonSource() {
92
- const home = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
93
- return path.join(home, 'dsh-runtimes', 'dsh-primary-runtime', 'dependencies', 'python');
94
- }
95
-
96
- function ensurePython() {
97
- const dest = path.join(RUNTIME, 'python');
98
- const pythonw = path.join(dest, 'pythonw.exe');
99
- if (fs.existsSync(pythonw)) return pythonw;
100
- const source = findPythonSource();
101
- if (!fs.existsSync(path.join(source, 'pythonw.exe'))) {
102
- log('bundled python runtime unavailable');
103
- return null;
104
- }
105
- fs.mkdirSync(dest, { recursive: true });
106
- for (const name of fs.readdirSync(source)) {
107
- if (!/^(python|pythonw|python3|python312|vcruntime.*)\.(exe|dll)$/i.test(name)) continue;
108
- fs.copyFileSync(path.join(source, name), path.join(dest, name));
109
- }
110
- copyTree(path.join(source, 'Lib'), path.join(dest, 'Lib'), (entry) => {
111
- const base = path.basename(entry);
112
- if (EXCLUDED_PY.has(base)) return false;
113
- if (base.endsWith('.pyc')) return false;
114
- return true;
115
- });
116
- copyTree(path.join(source, 'DLLs'), path.join(dest, 'DLLs'), (entry) => {
117
- return !entry.endsWith('.pdb');
118
- });
119
- fs.copyFileSync(path.join(source, 'LICENSE.txt'), path.join(dest, 'PYTHON-LICENSE.txt'));
120
- log('staged bundled python runtime');
121
- return pythonw;
122
- }
123
-
124
- function stageRuntime() {
125
- fs.mkdirSync(path.join(RUNTIME, 'patch'), { recursive: true });
126
- fs.mkdirSync(path.join(RUNTIME, 'assets'), { recursive: true });
127
- copyTree(path.join(ROOT, 'patch'), path.join(RUNTIME, 'patch'), (entry) => {
128
- return !entry.endsWith('.pyc') && !entry.includes('__pycache__');
129
- });
130
- const skip = new Set(['logo.webp', 'mark-color.png', 'client-template.js', 'hm-mark-ink.png']);
131
- copyTree(path.join(ROOT, 'assets', 'source'), path.join(RUNTIME, 'assets', 'source'), (entry) => {
132
- return !skip.has(path.basename(entry));
133
- });
134
- copyTree(path.join(ROOT, 'assets', 'icons'), path.join(RUNTIME, 'assets', 'icons'));
135
- copyTree(path.join(ROOT, 'vendor', 'rcedit'), path.join(RUNTIME, 'vendor', 'rcedit'));
136
- return ensurePython();
137
- }
138
-
139
- function vbsQuote(value) {
140
- return '"' + String(value).replace(/"/g, '""') + '"';
141
- }
142
-
143
- function writeRecovery(pythonw) {
144
- try {
145
- const patcher = path.join(RUNTIME, 'patch', 'patcher.py');
146
- for (const [mode, name] of [['apply', 'apply.vbs'], ['restore', 'restore.vbs']]) {
147
- const command = [
148
- vbsQuote(pythonw), vbsQuote(patcher),
149
- '--mode', mode,
150
- '--target', vbsQuote(TARGET),
151
- '--state-dir', vbsQuote(STATE_DIR),
152
- '--profile-dir', vbsQuote(PROFILE_DIR),
153
- ].join(' ');
154
- fs.writeFileSync(path.join(STATE_DIR, name), [
155
- 'Option Explicit',
156
- 'Dim sh',
157
- 'Set sh = CreateObject("WScript.Shell")',
158
- 'sh.Run ' + vbsQuote(command) + ', 0, False',
159
- '',
160
- ].join('\r\n'), 'utf8');
161
- }
162
- fs.writeFileSync(path.join(STATE_DIR, 'README.txt'), [
163
- '海姆达尔终端 · 源码层维护入口',
164
- '必须先完全退出 DeepSeek Harness。',
165
- ' apply.vbs 写入/修复皮肤',
166
- ' restore.vbs 还原官方 asar、图标与 EXE 图标',
167
- '备份与哈希在 backup\\,状态在 state.json,日志在 heimdall.log。',
168
- '全部位于 DSH 安装目录;没有启动项、计划任务、注册表写入或后台服务。',
169
- '',
170
- ].join('\r\n'), 'utf8');
171
- } catch (error) {
172
- log('recovery scripts failed: ' + error.message);
173
- }
174
- }
175
-
176
- function arm() {
177
- try {
178
- const pythonw = stageRuntime();
179
- if (!pythonw) throw new Error('python runtime not found');
180
- writeRecovery(pythonw);
181
- const patcher = path.join(RUNTIME, 'patch', 'patcher.py');
182
- const command = [
183
- vbsQuote(pythonw),
184
- vbsQuote(patcher),
185
- '--mode', 'sync',
186
- '--target', vbsQuote(TARGET),
187
- '--state-dir', vbsQuote(STATE_DIR),
188
- '--profile-dir', vbsQuote(PROFILE_DIR),
189
- '--wait-pid', String(process.pid),
190
- ].join(' ');
191
- const syncVbs = path.join(STATE_DIR, 'sync.vbs');
192
- fs.writeFileSync(syncVbs, [
193
- 'Option Explicit',
194
- 'Dim sh',
195
- 'Set sh = CreateObject("WScript.Shell")',
196
- 'sh.Run ' + vbsQuote(command) + ', 0, False',
197
- '',
198
- ].join('\r\n'), 'utf8');
199
-
200
- // Win32_Process.Create starts the helper outside Electron's job object, so
201
- // the helper can still reconcile the installation after DSH exits.
202
- const armVbs = path.join(STATE_DIR, 'wmi-arm.vbs');
203
- const wmiCommand = 'Chr(34) & ' + vbsQuote(WSCRIPT) + ' & Chr(34) & " //B "'
204
- + ' & Chr(34) & ' + vbsQuote(syncVbs) + ' & Chr(34)';
205
- fs.writeFileSync(armVbs, [
206
- 'Option Explicit',
207
- 'Dim wmi, proc, rc',
208
- 'Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2")',
209
- 'Set proc = wmi.Get("Win32_Process")',
210
- 'rc = proc.Create(' + wmiCommand + ', Null, Null)',
211
- 'If rc <> 0 Then WScript.Quit 1',
212
- '',
213
- ].join('\r\n'), 'utf8');
214
-
215
- const child = spawn(WSCRIPT, ['//B', armVbs], {
216
- detached: true, stdio: 'ignore', windowsHide: true,
217
- });
218
- child.unref();
219
- log('one-shot source helper armed');
220
- } catch (error) {
221
- log('arm failed: ' + error.message);
222
- }
223
- }
224
-
225
- export function apply(ctx) {
226
- try {
227
- fs.mkdirSync(STATE_DIR, { recursive: true });
228
- writeState({ desired: 'on', pluginVersion: VERSION });
229
- arm();
230
- if (ctx && typeof ctx.effect === 'function') {
231
- ctx.effect(() => () => {
232
- log('plugin disposing; helper will reconcile from profile state');
233
- arm();
234
- }, 'snowbreak-heimdall: source reconciliation');
235
- }
236
- } catch (error) {
237
- log('apply failed: ' + error.message);
238
- }
239
- }
1
+ /**
2
+ * Snowbreak: Heimdall Terminal — source-layer companion.
3
+ *
4
+ * The plugin does NOT paint the loading screen and does NOT own the palette.
5
+ * It stages a self-contained copy of the source patcher inside the DSH
6
+ * installation and leaves one disposable helper that reconciles the asar and
7
+ * icons after every DSH process has exited. No Startup entry, scheduled task,
8
+ * registry value, service, HTTP listener, or auto-relaunch is used.
9
+ */
10
+ import fs from 'node:fs';
11
+ import os from 'node:os';
12
+ import path from 'node:path';
13
+ import { spawn } from 'node:child_process';
14
+ import { fileURLToPath } from 'node:url';
15
+
16
+ const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
17
+ const VERSION = '3.0.1';
18
+ const INSTALL = path.join(process.env.LOCALAPPDATA || '', 'Programs', 'DeepSeek Harness');
19
+ const DEFAULT_RESOURCES = process.env.HEIMDALL_RESOURCES
20
+ || (typeof process.resourcesPath === 'string' && /[\\/]resources$/i.test(process.resourcesPath)
21
+ ? process.resourcesPath
22
+ : path.join(INSTALL, 'resources'));
23
+ const TARGET = process.env.HEIMDALL_TARGET || path.join(DEFAULT_RESOURCES, 'app.asar');
24
+ const RESOURCES = path.dirname(TARGET);
25
+ const STATE_DIR = path.join(RESOURCES, 'HeimdallTerminal');
26
+ const RUNTIME = path.join(STATE_DIR, 'runtime');
27
+ const LOG = path.join(STATE_DIR, 'host.log');
28
+ const PROFILE_DIR = process.env.DSH_PROFILE_DIR
29
+ || path.join(process.env.DSH_HOME || path.join(os.homedir(), '.dsh'), 'profiles', 'desktop');
30
+ const WSCRIPT = path.join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'wscript.exe');
31
+
32
+ const EXCLUDED_PY = new Set([
33
+ 'site-packages', '__pycache__', 'test', 'tests', 'idlelib', 'tkinter', 'turtledemo',
34
+ 'ensurepip', 'lib2to3', 'pydoc_data', 'venv', 'distutils', 'tcl', 'Scripts', 'include', 'libs',
35
+ ]);
36
+
37
+ function log(message) {
38
+ try {
39
+ fs.mkdirSync(STATE_DIR, { recursive: true });
40
+ fs.appendFileSync(LOG, '[' + new Date().toISOString() + '] ' + message + '\n', 'utf8');
41
+ } catch (_) { /* diagnostics only */ }
42
+ }
43
+
44
+ function readState() {
45
+ try { return JSON.parse(fs.readFileSync(path.join(STATE_DIR, 'state.json'), 'utf8')); }
46
+ catch (_) { return {}; }
47
+ }
48
+
49
+ function writeState(patch) {
50
+ try {
51
+ fs.mkdirSync(STATE_DIR, { recursive: true });
52
+ const file = path.join(STATE_DIR, 'state.json');
53
+ const next = { ...readState(), ...patch, hostUpdatedAt: new Date().toISOString() };
54
+ const tmp = file + '.tmp';
55
+ fs.writeFileSync(tmp, JSON.stringify(next, null, 2) + '\n', 'utf8');
56
+ fs.renameSync(tmp, file);
57
+ } catch (error) {
58
+ log('state write failed: ' + error.message);
59
+ }
60
+ }
61
+
62
+ function sleep(ms) {
63
+ try { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); }
64
+ catch (_) { /* best effort */ }
65
+ }
66
+
67
+ function copyFileRetry(source, destination) {
68
+ for (let attempt = 0; attempt < 6; attempt += 1) {
69
+ try {
70
+ fs.copyFileSync(source, destination);
71
+ return;
72
+ } catch (error) {
73
+ if (attempt === 5) throw error;
74
+ sleep(120);
75
+ }
76
+ }
77
+ }
78
+
79
+ function copyTree(source, destination, filter) {
80
+ if (!fs.existsSync(source)) return;
81
+ fs.mkdirSync(destination, { recursive: true });
82
+ for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
83
+ const src = path.join(source, entry.name);
84
+ if (filter && !filter(src)) continue;
85
+ const dst = path.join(destination, entry.name);
86
+ if (entry.isDirectory()) copyTree(src, dst, filter);
87
+ else copyFileRetry(src, dst);
88
+ }
89
+ }
90
+
91
+ function findPythonSource() {
92
+ const home = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
93
+ return path.join(home, 'dsh-runtimes', 'dsh-primary-runtime', 'dependencies', 'python');
94
+ }
95
+
96
+ function ensurePython() {
97
+ const dest = path.join(RUNTIME, 'python');
98
+ const pythonw = path.join(dest, 'pythonw.exe');
99
+ if (fs.existsSync(pythonw)) return pythonw;
100
+ const source = findPythonSource();
101
+ if (!fs.existsSync(path.join(source, 'pythonw.exe'))) {
102
+ log('bundled python runtime unavailable');
103
+ return null;
104
+ }
105
+ fs.mkdirSync(dest, { recursive: true });
106
+ for (const name of fs.readdirSync(source)) {
107
+ if (!/^(python|pythonw|python3|python312|vcruntime.*)\.(exe|dll)$/i.test(name)) continue;
108
+ fs.copyFileSync(path.join(source, name), path.join(dest, name));
109
+ }
110
+ copyTree(path.join(source, 'Lib'), path.join(dest, 'Lib'), (entry) => {
111
+ const base = path.basename(entry);
112
+ if (EXCLUDED_PY.has(base)) return false;
113
+ if (base.endsWith('.pyc')) return false;
114
+ return true;
115
+ });
116
+ copyTree(path.join(source, 'DLLs'), path.join(dest, 'DLLs'), (entry) => {
117
+ return !entry.endsWith('.pdb');
118
+ });
119
+ fs.copyFileSync(path.join(source, 'LICENSE.txt'), path.join(dest, 'PYTHON-LICENSE.txt'));
120
+ log('staged bundled python runtime');
121
+ return pythonw;
122
+ }
123
+
124
+ function stageRuntime() {
125
+ fs.mkdirSync(path.join(RUNTIME, 'patch'), { recursive: true });
126
+ fs.mkdirSync(path.join(RUNTIME, 'assets'), { recursive: true });
127
+ copyTree(path.join(ROOT, 'patch'), path.join(RUNTIME, 'patch'), (entry) => {
128
+ return !entry.endsWith('.pyc') && !entry.includes('__pycache__');
129
+ });
130
+ const skip = new Set(['logo.webp', 'mark-color.png', 'client-template.js', 'hm-mark-ink.png']);
131
+ copyTree(path.join(ROOT, 'assets', 'source'), path.join(RUNTIME, 'assets', 'source'), (entry) => {
132
+ return !skip.has(path.basename(entry));
133
+ });
134
+ copyTree(path.join(ROOT, 'assets', 'icons'), path.join(RUNTIME, 'assets', 'icons'));
135
+ copyTree(path.join(ROOT, 'vendor', 'rcedit'), path.join(RUNTIME, 'vendor', 'rcedit'));
136
+ return ensurePython();
137
+ }
138
+
139
+ function vbsQuote(value) {
140
+ return '"' + String(value).replace(/"/g, '""') + '"';
141
+ }
142
+
143
+ function writeRecovery(pythonw) {
144
+ try {
145
+ const patcher = path.join(RUNTIME, 'patch', 'patcher.py');
146
+ for (const [mode, name] of [['apply', 'apply.vbs'], ['restore', 'restore.vbs']]) {
147
+ const command = [
148
+ vbsQuote(pythonw), vbsQuote(patcher),
149
+ '--mode', mode,
150
+ '--target', vbsQuote(TARGET),
151
+ '--state-dir', vbsQuote(STATE_DIR),
152
+ '--profile-dir', vbsQuote(PROFILE_DIR),
153
+ ].join(' ');
154
+ fs.writeFileSync(path.join(STATE_DIR, name), [
155
+ 'Option Explicit',
156
+ 'Dim sh',
157
+ 'Set sh = CreateObject("WScript.Shell")',
158
+ 'sh.Run ' + vbsQuote(command) + ', 0, False',
159
+ '',
160
+ ].join('\r\n'), 'utf8');
161
+ }
162
+ fs.writeFileSync(path.join(STATE_DIR, 'README.txt'), [
163
+ '海姆达尔终端 · 源码层维护入口',
164
+ '必须先完全退出 DeepSeek Harness。',
165
+ ' apply.vbs 写入/修复皮肤',
166
+ ' restore.vbs 还原官方 asar、图标与 EXE 图标',
167
+ '备份与哈希在 backup\\,状态在 state.json,日志在 heimdall.log。',
168
+ '全部位于 DSH 安装目录;没有启动项、计划任务、注册表写入或后台服务。',
169
+ '',
170
+ ].join('\r\n'), 'utf8');
171
+ } catch (error) {
172
+ log('recovery scripts failed: ' + error.message);
173
+ }
174
+ }
175
+
176
+ function arm() {
177
+ try {
178
+ const pythonw = stageRuntime();
179
+ if (!pythonw) throw new Error('python runtime not found');
180
+ writeRecovery(pythonw);
181
+ const patcher = path.join(RUNTIME, 'patch', 'patcher.py');
182
+ const command = [
183
+ vbsQuote(pythonw),
184
+ vbsQuote(patcher),
185
+ '--mode', 'sync',
186
+ '--target', vbsQuote(TARGET),
187
+ '--state-dir', vbsQuote(STATE_DIR),
188
+ '--profile-dir', vbsQuote(PROFILE_DIR),
189
+ '--wait-pid', String(process.pid),
190
+ ].join(' ');
191
+ const syncVbs = path.join(STATE_DIR, 'sync.vbs');
192
+ fs.writeFileSync(syncVbs, [
193
+ 'Option Explicit',
194
+ 'Dim sh',
195
+ 'Set sh = CreateObject("WScript.Shell")',
196
+ 'sh.Run ' + vbsQuote(command) + ', 0, False',
197
+ '',
198
+ ].join('\r\n'), 'utf8');
199
+
200
+ // Win32_Process.Create starts the helper outside Electron's job object, so
201
+ // the helper can still reconcile the installation after DSH exits.
202
+ const armVbs = path.join(STATE_DIR, 'wmi-arm.vbs');
203
+ const wmiCommand = 'Chr(34) & ' + vbsQuote(WSCRIPT) + ' & Chr(34) & " //B "'
204
+ + ' & Chr(34) & ' + vbsQuote(syncVbs) + ' & Chr(34)';
205
+ fs.writeFileSync(armVbs, [
206
+ 'Option Explicit',
207
+ 'Dim wmi, proc, rc',
208
+ 'Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2")',
209
+ 'Set proc = wmi.Get("Win32_Process")',
210
+ 'rc = proc.Create(' + wmiCommand + ', Null, Null)',
211
+ 'If rc <> 0 Then WScript.Quit 1',
212
+ '',
213
+ ].join('\r\n'), 'utf8');
214
+
215
+ const child = spawn(WSCRIPT, ['//B', armVbs], {
216
+ detached: true, stdio: 'ignore', windowsHide: true,
217
+ });
218
+ child.unref();
219
+ log('one-shot source helper armed');
220
+ } catch (error) {
221
+ log('arm failed: ' + error.message);
222
+ }
223
+ }
224
+
225
+ export function apply(ctx) {
226
+ try {
227
+ fs.mkdirSync(STATE_DIR, { recursive: true });
228
+ writeState({ desired: 'on', pluginVersion: VERSION });
229
+ arm();
230
+ if (ctx && typeof ctx.effect === 'function') {
231
+ ctx.effect(() => () => {
232
+ log('plugin disposing; helper will reconcile from profile state');
233
+ arm();
234
+ }, 'snowbreak-heimdall: source reconciliation');
235
+ }
236
+ } catch (error) {
237
+ log('apply failed: ' + error.message);
238
+ }
239
+ }
package/package.json CHANGED
@@ -1,47 +1,46 @@
1
- {
2
- "name": "dsh-snowbreak-heimdall",
3
- "version": "3.0.0",
4
- "description": "《尘白禁区》海姆达尔终端 / 世界树公司源码级皮肤:加载画面、双主题、菜单/侧栏/图标,插件仅在加载后播放启动动画。Windows / DSH 0.2.2-rc.1。",
5
- "type": "module",
6
- "license": "MIT",
7
- "engines": {
8
- "dsh": "0.2.2-rc.1"
9
- },
10
- "os": [
11
- "win32"
12
- ],
13
- "cpu": [
14
- "x64"
15
- ],
16
- "exports": {
17
- ".": "./lib/index.js",
18
- "./client": "./lib/client.js",
19
- "./locale/*.json": "./locale/*.json",
20
- "./icon": "./icon.svg"
21
- },
22
- "files": [
23
- "lib/index.js",
24
- "lib/client.js",
25
- "cordis.patch.yml",
26
- "locale/*.json",
27
- "icon.svg",
28
- "LICENSE",
29
- "README.md",
30
- "TEST-REPORT.md",
31
- "SHA256SUMS.txt",
32
- "patch",
33
- "assets",
34
- "vendor",
35
- "tools"
36
- ],
37
- "dsh": {
38
- "bundle": {
39
- "patch": "./cordis.patch.yml"
40
- },
41
- "client": {
42
- "platform": "web",
43
- "immediately": true
44
- }
45
- }
46
- }
47
-
1
+ {
2
+ "name": "dsh-snowbreak-heimdall",
3
+ "version": "3.0.1",
4
+ "description": "《尘白禁区》海姆达尔终端 / 世界树公司源码级皮肤:加载画面、双主题、菜单/侧栏/图标,插件仅在加载后播放启动动画。Windows / DSH 0.2.2-rc.1。",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "engines": {
8
+ "dsh": "0.2.2-rc.1"
9
+ },
10
+ "os": [
11
+ "win32"
12
+ ],
13
+ "cpu": [
14
+ "x64"
15
+ ],
16
+ "exports": {
17
+ ".": "./lib/index.js",
18
+ "./client": "./lib/client.js",
19
+ "./locale/*.json": "./locale/*.json",
20
+ "./icon": "./icon.svg"
21
+ },
22
+ "files": [
23
+ "lib/index.js",
24
+ "lib/client.js",
25
+ "cordis.patch.yml",
26
+ "locale/*.json",
27
+ "icon.svg",
28
+ "LICENSE",
29
+ "README.md",
30
+ "TEST-REPORT.md",
31
+ "SHA256SUMS.txt",
32
+ "patch",
33
+ "assets",
34
+ "vendor",
35
+ "tools"
36
+ ],
37
+ "dsh": {
38
+ "bundle": {
39
+ "patch": "./cordis.patch.yml"
40
+ },
41
+ "client": {
42
+ "platform": "web",
43
+ "immediately": true
44
+ }
45
+ }
46
+ }
package/patch/patcher.py CHANGED
@@ -72,6 +72,27 @@ def write_progress(pct, stage, text="", error=None, done=False):
72
72
  log("progress write failed: %s" % exc)
73
73
 
74
74
 
75
+ def schedule_state_cleanup(delay_seconds=8):
76
+ """After a successful restore, remove the helper runtime and its backups.
77
+
78
+ The progress window is a separate PowerShell process; a short delayed cmd
79
+ removes HeimdallTerminal after the window has closed. Test mode never
80
+ deletes the caller's test state.
81
+ """
82
+ if TEST_MODE:
83
+ return
84
+ try:
85
+ comspec = os.path.join(os.environ.get("SystemRoot", r"C:\Windows"), "System32", "cmd.exe")
86
+ command = 'ping -n %d 127.0.0.1 >nul & rmdir /s /q "%s"' % (
87
+ max(2, int(delay_seconds) + 1), STATE_DIR,
88
+ )
89
+ subprocess.Popen([comspec, "/c", command], close_fds=True,
90
+ creationflags=0x08000000)
91
+ log("state cleanup scheduled")
92
+ except OSError as exc:
93
+ log("state cleanup failed: %s" % exc)
94
+
95
+
75
96
  def launch_progress(mode="apply"):
76
97
  """Show a fixed, borderless WS_POPUP progress window after DSH has exited."""
77
98
  global PROGRESS_STARTED, PROGRESS_MODE
@@ -1184,6 +1205,7 @@ def restore_skin(target, force=False, intermediate=False):
1184
1205
  write_progress(82, "WRITE", "旧层已还原,正在写入当前源码…", done=False)
1185
1206
  else:
1186
1207
  write_progress(100, "READY", "还原完成 · 可以重新打开 DSH", done=True)
1208
+ schedule_state_cleanup()
1187
1209
  return 0
1188
1210
  except Exception as exc:
1189
1211
  log("restore failed: %s" % exc)