@marktrue/dsh-mobile-remote 3.2.4-alpha.9 → 3.2.4-rc.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.
@@ -35,7 +35,7 @@ import {
35
35
  } from "./plugin-update-transaction.js";
36
36
  import { pluginContentDigest } from "./plugin-content-digest.js";
37
37
  import { verifyFrozenPackage } from "./runtime-dependency-snapshot.js";
38
- import { restartPlan } from "./plugin-self-update.js";
38
+ import { restartPlan, respawnCommandOf } from "./plugin-self-update.js";
39
39
  import { shellOptions } from "./tool-process.js";
40
40
 
41
41
  /** 等待宿主的默认超时:足够冷启动(含语料预热),又不至于让用户无限等。 */
@@ -138,14 +138,47 @@ export function portKillSnippet(port, fallbackPid = null) {
138
138
  * 默认重启器:**按当前实例**(端口占用者)终止,而不是事务里记的旧 PID;
139
139
  * 前台形态自行重新拉起。**返回结果不再被忽略**(F3)。
140
140
  */
141
- export function defaultRestart({ restartForm, port, pid = null, profile = "web", dshCommand = "dsh", log = () => {} }) {
142
- const plan = restartPlan({ form: restartForm, pid: null, profile, dshCommand });
141
+ /** 从 `/proc/<pid>/cmdline` 还原宿主原命令行(supervisor 的 argv 不是宿主 argv)。 */
142
+ export function respawnCommandFromProc(pid) {
143
+ if (!Number.isInteger(pid) || pid <= 0) return "";
144
+ try {
145
+ const parts = readFileSync(`/proc/${pid}/cmdline`, "utf8").split("\0").filter((part) => part !== "");
146
+ return respawnCommandOf(parts);
147
+ } catch {
148
+ return "";
149
+ }
150
+ }
151
+
152
+ export function defaultRestart({
153
+ restartForm,
154
+ port,
155
+ pid = null,
156
+ hostPid = null,
157
+ profile = "web",
158
+ dshCommand = "dsh",
159
+ respawnCommand = "",
160
+ log = () => {},
161
+ spawnSyncImpl = spawnSync,
162
+ }) {
163
+ // issue #110 P2:supervisor 的 process.argv 是 `update-supervisor.js --state`,
164
+ // 不能拿它当宿主命令行;优先事务写入的 respawnCommand,其次 `/proc/<hostPid>/cmdline`。
165
+ let originalCommand = respawnCommand;
166
+ if (originalCommand === "" && Number.isInteger(hostPid)) originalCommand = respawnCommandFromProc(hostPid);
167
+ if (originalCommand === "") originalCommand = respawnCommandOf(process.argv);
168
+ const plan = restartPlan({ form: restartForm, pid: null, profile, dshCommand, respawnCommand: originalCommand });
143
169
  if (plan.mode === "unsupported") return { ok: false, error: "restart-unsupported" };
144
170
  const kill = portKillSnippet(port, pid);
171
+ // 保留原始 argv(如 --port 3082 / --no-open),不能落回 `dsh web --profile web`。
172
+ const respawn = plan.mode === "respawn"
173
+ ? (plan.commands?.[plan.commands.length - 1] ?? "")
174
+ : "";
175
+ if (plan.mode === "respawn" && (respawn === "" || originalCommand === "")) {
176
+ return { ok: false, error: "restart-command-missing" };
177
+ }
145
178
  const script = plan.mode === "respawn"
146
- ? `sleep 1; ${kill}; sleep 2; nohup ${dshCommand} web --profile ${profile} >/dev/null 2>&1 &`
179
+ ? `sleep 1; ${kill}; sleep 2; nohup ${respawn} >/dev/null 2>&1 &`
147
180
  : `sleep 1; ${kill}`;
148
- const r = spawnSync("bash", ["-lc", script], { encoding: "utf8" });
181
+ const r = spawnSyncImpl("bash", ["-lc", script], { encoding: "utf8" });
149
182
  if (r.error) return { ok: false, error: r.error.message };
150
183
  if (r.status !== 0) return { ok: false, error: `restart-script-exit-${r.status}: ${(r.stderr || "").trim()}` };
151
184
  log(`supervisor: 已安排重启(${plan.mode},目标=当前端口占用者)`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marktrue/dsh-mobile-remote",
3
- "version": "3.2.4-alpha.9",
3
+ "version": "3.2.4-rc.1",
4
4
  "description": "DSH Mobile:把 DeepSeek Harness 变成随身控制台——手机远程发消息派活、看进度、收通知、审批决策、管理会话;配套 Flutter App(当前 Android 端,iOS 未开发)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -52,7 +52,7 @@
52
52
  "qrcode"
53
53
  ],
54
54
  "optionalDependencies": {
55
- "@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.2.4-alpha.9-app"
55
+ "@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.2.4-rc.1-app"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@deepseek-ai/dsh-credentials": ">=0.1.0-rc.6 <=0.2.2 || >=0.2.0-0 <0.2.0 || >=0.2.1-0 <0.2.1 || >=0.2.2-0 <0.2.2",