@shundoo-ai/dsh-cosmic 1.0.4-alpha.0 → 1.0.4-alpha.2

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": "@shundoo-ai/dsh-cosmic",
3
- "version": "1.0.4-alpha.0",
3
+ "version": "1.0.4-alpha.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  ".config",
@@ -46,12 +46,10 @@ description: >
46
46
 
47
47
  > 下面各职责给的是 **macOS/Linux** 命令。Windows 上**手拼这套流程代价极高** —— 实测一个 Windows 会话为跑通「构建 + 热部署」发了 **63 条 pwsh**、**6 次提权**(探测 PID → 找 JDK → 找 tools.jar → attach,每步都要单独授权)。
48
48
 
49
- 本 skill 随包提供封装脚本,**把全程收敛成一次调用 ⇒ 只需一次提权**:
49
+ 本 skill 随包提供封装脚本,**把全程收敛成一次调用 ⇒ 一次授权就够**:
50
50
 
51
51
  ```powershell
52
- # 体检(不部署)
53
- pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1
54
- # 构建 + 热部署
52
+ # ⭐ 推荐:直接带 -Module 一次跑完(脚本内部会先体检,再构建 + 热部署)
55
53
  pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Module <模块名>
56
54
  # 干净重建 + 热部署
57
55
  pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Module <模块名> -Clean
@@ -59,8 +57,16 @@ pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Module <模块名> -Clean
59
57
  pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Jar <jar路径>
60
58
  # 只构建、不部署
61
59
  pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Module <模块名> -WhatIf
60
+ # 仅体检(已经有授权时用;没授权时它会因端口查询被拒而报错,见下)
61
+ pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1
62
62
  ```
63
63
 
64
+ > ⚠️ **本脚本在 Windows 上需要放开沙箱(`danger-full-access`),且必须「整条命令一次授权」**:
65
+ > 它要 `Get-NetTCPConnection` 查端口归属、并跨进程 attach 到 cosmic JVM,受限沙箱下二者都被拒
66
+ > (`CreatePipe error=5` / `access denied`)。
67
+ > **所以:不要先跑一次「体检」再去跑构建** —— 那会白花一次授权。直接带 `-Module` 发**一条**命令、**一次性**授权,全流程都在这一次调用里完成。
68
+ > 若端口查询被沙箱拒绝,脚本会**明确报出这一点**(而不是误报「cosmic 没在跑」)—— 看到该提示就带沙箱放开重发同一条命令。
69
+
64
70
  内部依次完成:定位工作区 → 解析 preset bundle → 读 `dev.json` → **按端口反查 cosmic PID**(不是 `jps`,见职责②)→ 挑含 `tools.jar` 的 JDK → 构建 → Attacher 热加载。
65
71
 
66
72
  参数:`-Module`|`-Jar`|`-Clean`|`-WhatIf`|`-LogFile`|`-Workspace`|`-PresetDir`|`-Port`。
@@ -131,7 +137,12 @@ pwsh -File {SKILL_DIR}\scripts\cosmic-hotdeploy.ps1 -Module <模块名> -WhatIf
131
137
  > ⚠️ **别直接用 preset 里的 `{SKILL_DIR}/assets/kd-reloadjar-agent.jar`** —— 先把 agent jar 复制到**机器级缓存**再用(`{AGENT}`,见下)。原因:Attacher 会把这个 jar **载入运行中的 cosmic JVM**,而 JVM 的 classloader 会**长期持有**该文件句柄;preset 一旦升级,包管理器要**整目录替换**(每个文件都得能删/改名)→ 必然在这个 jar 上失败(Windows 报 `os error 32`/拒绝访问)。
132
138
  >
133
139
  > `{AGENT}` = `$DSH_HOME/cache/cosmic/agent/kd-reloadjar-agent-<sha1前8位>.jar`(**带内容哈希命名**,所以新版永远不会覆盖可能已被 JVM 载入的旧副本)。`init-python.{sh,ps1}` 会预先复制;`cosmic-hotdeploy.ps1` 也会自动解析并复制。手工操作时:
134
-
140
+ >
141
+ > **平台差异(重要)**
142
+ > - **Windows:必须**这么做。JVM 持有句柄会**直接让 preset 升级失败**(`os error 32`/拒绝访问),必须重启 cosmic 服务才能解开。
143
+ > - **macOS/Linux:不是必须**。POSIX 允许替换/删除**已被打开**的文件,直接用原件也安全(升级不会失败)。
144
+ > - **但仍然统一用副本**,理由有二:① 两个平台同一条规则,少一处"看平台下菜"的判断题;② 万一漏了复制这一步,在 macOS 上**无害**,在 Windows 上却会重新引入死锁 —— 统一规则对两种平台都安全。
145
+ >
135
146
  ```bash
136
147
  # 先把 preset 里的原件复制到机器级缓存(哈希命名),再用缓存路径
137
148
  AGENT_DIR="${DSH_HOME:-$HOME/.dsh}/cache/cosmic/agent"
@@ -122,9 +122,25 @@ $tenantId = $dev.tenant_id
122
122
  if (-not $accountId) { throw "dev.json has no account_id -- re-run 'dev.py init'." }
123
123
 
124
124
  # ---- 2. Discover the cosmic PID by port ownership, then validate the JVM ----
125
- $conn = Get-NetTCPConnection -LocalPort $effPort -State Listen -ErrorAction SilentlyContinue |
126
- Select-Object -First 1
127
- if (-not $conn) { throw "Nothing is listening on port $effPort -- is cosmic running?" }
125
+ # NOTE: do NOT use -ErrorAction SilentlyContinue here. Get-NetTCPConnection is a cross-process
126
+ # query and the DSH sandbox DENIES it ("access denied") unless the call runs with danger-full-access.
127
+ # Swallowing that error makes an empty result mean two very different things, and the old code
128
+ # reported it as "cosmic is not running" -- sending the caller off to hunt a non-existent problem.
129
+ $conn = $null
130
+ try {
131
+ $conn = Get-NetTCPConnection -LocalPort $effPort -State Listen -ErrorAction Stop |
132
+ Select-Object -First 1
133
+ } catch {
134
+ throw @"
135
+ Port query was DENIED: $($_.Exception.Message)
136
+ This script needs the DSH sandbox opened for the whole run (Windows: danger-full-access).
137
+ Rationale: it must query port ownership (Get-NetTCPConnection) and attach to the cosmic JVM
138
+ across processes; both are blocked by the restricted sandbox (CreatePipe error=5 / access denied).
139
+ Re-run this single command with the sandbox escalated -- the whole discover+build+attach flow
140
+ is one call, so one grant covers it.
141
+ "@
142
+ }
143
+ if (-not $conn) { throw "Nothing is listening on port $effPort -- is cosmic running? (port query itself succeeded)" }
128
144
  $targetPid = $conn.OwningProcess
129
145
  $proc = Get-CimInstance Win32_Process -Filter "ProcessId=$targetPid"
130
146
  if ($proc.CommandLine -notmatch 'kd\.bos\.service\.webserver\.JettyServer') {