@mininglamp-oss/octo-runtime 1.1.2 → 1.1.4

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.
Files changed (140) hide show
  1. package/README.md +1 -1
  2. package/apps/cli/dist/build-info.json +2 -2
  3. package/apps/cli/dist/help.js +5 -1
  4. package/apps/cli/dist/main.js +32 -6
  5. package/apps/cli/dist/manifest.json +5 -0
  6. package/apps/cli/dist/openclaw.js +32 -8
  7. package/apps/cli/dist/output.js +3 -0
  8. package/apps/cli/dist/playboard.d.ts +5 -0
  9. package/apps/cli/dist/playboard.js +41 -13
  10. package/dist/public/dsh.d.ts +2 -0
  11. package/dist/public/dsh.js +1 -0
  12. package/dist/public/executor-kernel.d.ts +1 -1
  13. package/dist/public/executor-kernel.js +1 -1
  14. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +2 -2
  15. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  16. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +4 -0
  17. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +26 -2
  18. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  19. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  20. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  21. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  22. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +3 -3
  23. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  24. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-DYOJCNWF.js +854 -0
  25. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-G5PWGRL5.js +209 -0
  26. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-UOQRXV3Q.js +340 -0
  27. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.d.ts +1 -0
  28. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.js +16 -0
  29. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +6 -0
  30. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-client-LICENSE.txt +21 -0
  31. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-protocol-LICENSE.txt +21 -0
  32. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +35 -0
  33. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +14 -0
  34. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +52 -0
  35. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +306 -0
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +11 -0
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +13 -0
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.d.ts +12 -0
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +7 -0
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +15 -0
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +2 -1
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +10 -5
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +214 -55
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +3 -0
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.d.ts +4 -0
  54. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +24 -2
  55. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/hourly-log.js +11 -3
  56. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +12 -3
  57. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +30 -8
  58. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +4 -3
  59. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +15 -2
  60. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +29 -1
  61. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  62. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +5 -5
  63. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  64. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  65. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +5 -1
  66. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +32 -6
  67. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +5 -0
  68. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +32 -8
  69. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +3 -0
  70. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +5 -0
  71. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +41 -13
  72. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -23
  73. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.d.ts +2 -2
  74. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.js +16 -6
  75. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/systemd.js +9 -7
  76. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.d.ts +4 -1
  77. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +36 -11
  78. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  79. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -2
  80. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  81. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +2 -1
  82. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +2 -1
  83. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -1
  84. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +16 -1
  85. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +181 -27
  86. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +9 -2
  87. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +8 -0
  88. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +17 -0
  89. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
  90. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +57 -1
  91. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +167 -25
  92. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +3 -1
  93. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +20 -1
  94. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +23 -0
  95. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +43 -0
  96. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +15 -0
  97. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +283 -0
  98. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +2 -0
  99. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +15 -1
  100. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts +5 -1
  101. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +48 -13
  102. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.d.ts +1 -1
  103. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.js +5 -3
  104. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +26 -1
  105. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +2 -1
  106. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +1 -0
  107. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +3 -2
  108. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +3 -2
  109. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +4 -0
  110. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +104 -3
  111. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/rules.js +4 -3
  112. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.d.ts +2 -0
  113. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.js +7 -0
  114. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +2 -1
  115. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +9 -0
  116. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +49 -17
  117. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/image-input.js +2 -1
  118. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.d.ts +1 -1
  119. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.js +4 -2
  120. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +7 -0
  121. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +10 -7
  122. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
  123. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +141 -16
  124. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/session-store.d.ts +3 -1
  125. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
  126. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-CXTvRGim.js +74 -0
  127. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
  128. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
  129. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +33 -9
  130. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +9 -4
  131. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
  132. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +5 -0
  133. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +39 -1
  134. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +76 -7
  135. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  136. package/package.json +35 -29
  137. package/packages/octo-runtime-extra-channel-gateway/config-schema.json +57 -1
  138. package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +443 -56
  139. package/packages/octo-runtime-protocol/schema/protocol.schema.json +357 -37
  140. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-DiPc-ipL.js +0 -74
@@ -18,8 +18,21 @@ export function sanitizePublicValue(value, key = "", depth = 0) {
18
18
  ]));
19
19
  }
20
20
  function redactCredentialText(value) {
21
- return value
22
- .replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/gi, "[REDACTED]")
21
+ // 单向扫描 PEM,避免多个未闭合 BEGIN 反复扫描后缀;截断的私钥同样不能公开。
22
+ const begin = /-----BEGIN [^-]*PRIVATE KEY-----/gi;
23
+ const end = /-----END [^-]*PRIVATE KEY-----/gi;
24
+ const parts = [];
25
+ let offset = 0;
26
+ for (let match = begin.exec(value); match; match = begin.exec(value)) {
27
+ parts.push(value.slice(offset, match.index), "[REDACTED]");
28
+ end.lastIndex = begin.lastIndex;
29
+ const closing = end.exec(value);
30
+ offset = closing ? end.lastIndex : value.length;
31
+ begin.lastIndex = offset;
32
+ }
33
+ parts.push(value.slice(offset));
34
+ return parts
35
+ .join("")
23
36
  .replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]+/gi, "$1 [REDACTED]")
24
37
  .replace(/\b(api[_-]?key|(?:access[_-]?|refresh[_-]?|bf[_-]?)?token|password|passwd|secret)\s*["']?\s*[:=]\s*["']?[^\s,;&"'}]+/gi, "$1=[REDACTED]")
25
38
  .replace(/([?&](?:api[_-]?key|access[_-]?token|refresh[_-]?token|password|secret)=)[^&#\s]*/gi, "$1[REDACTED]")
@@ -11,12 +11,21 @@ const strings = new Set([
11
11
  "model",
12
12
  "status",
13
13
  "code",
14
+ "reason_code",
15
+ "native_code",
16
+ "primary_code",
17
+ "cleanup_code",
18
+ "signal",
14
19
  "endpoint_id",
15
20
  "state",
16
21
  "protocol_mode"
17
22
  ]);
18
23
  const numbers = new Set([
19
24
  "duration_ms",
25
+ "request_id",
26
+ "pid",
27
+ "exit_code",
28
+ "native_code",
20
29
  "input_count",
21
30
  "text_input_count",
22
31
  "image_input_count",
@@ -125,9 +134,28 @@ export class RuntimeLogging {
125
134
  }
126
135
  for (const key of numbers) {
127
136
  const value = data?.[key];
128
- if (typeof value === "number" && Number.isFinite(value) && value >= 0)
137
+ if (typeof value === "number" &&
138
+ Number.isFinite(value) &&
139
+ (value >= 0 || (key === "native_code" && Number.isSafeInteger(value))))
129
140
  safe[key] = value;
130
141
  }
142
+ // 任务诊断只进入普通日志;逐字段校验,保持组件状态输出的独立隐私边界。
143
+ const diagnosticId = data?.diagnostic_id;
144
+ if (typeof diagnosticId === "string" && /^diag_[0-9a-f]{32}$/.test(diagnosticId))
145
+ safe.diagnostic_id = diagnosticId;
146
+ const stage = data?.stage;
147
+ if (typeof stage === "string" &&
148
+ ["channel_session_read", "channel_presentation_initialize", "channel_admission"].includes(stage))
149
+ safe.stage = stage;
150
+ const component = data?.failure_component;
151
+ if (component === "octo-runtime" || component === "octo-agent-worker")
152
+ safe.failure_component = component;
153
+ const occurredAt = data?.occurred_at;
154
+ if (typeof occurredAt === "string" &&
155
+ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(occurredAt) &&
156
+ Number.isFinite(Date.parse(occurredAt)) &&
157
+ new Date(occurredAt).toISOString() === occurredAt)
158
+ safe.occurred_at = occurredAt;
131
159
  const record = {
132
160
  time: new Date().toISOString(),
133
161
  level,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-adapter-sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": {
@@ -9,7 +9,7 @@
9
9
  "./module-manifest": "./dist/module-manifest.js"
10
10
  },
11
11
  "dependencies": {
12
- "@mininglamp-oss/octo-runtime-protocol": "1.1.2",
12
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.4",
13
13
  "import-meta-resolve": "4.2.0"
14
14
  },
15
15
  "types": "./dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { hasImageInput, invocationEnvironment } from "@mininglamp-oss/octo-runtime-adapter-sdk";
1
+ import { hasImageInput, invocationEnvironment, processEnvironmentValue } from "@mininglamp-oss/octo-runtime-adapter-sdk";
2
2
  import { execFile } from "node:child_process";
3
3
  import { existsSync } from "node:fs";
4
4
  import { homedir } from "node:os";
@@ -15,7 +15,7 @@ const DEFAULT_APP_SERVER_ARGS = [
15
15
  ];
16
16
  /** Resolve the CLI embedded in ZCode Desktop when no PATH command is installed. */
17
17
  export function discoverZcodeBin(env = process.env) {
18
- const configured = nonEmptyString(env.ZCODE_BIN);
18
+ const configured = nonEmptyString(processEnvironmentValue(env, "ZCODE_BIN"));
19
19
  if (configured)
20
20
  return resolve(configured);
21
21
  const pathCommand = findOnPath("zcode", env);
@@ -24,7 +24,7 @@ export function discoverZcodeBin(env = process.env) {
24
24
  const home = homedir();
25
25
  const candidates = process.platform === "win32"
26
26
  ? [
27
- join(env.LOCALAPPDATA ?? join(home, "AppData", "Local"), "Programs", "ZCode", "resources", "glm", "zcode.cjs")
27
+ join(processEnvironmentValue(env, "LOCALAPPDATA") ?? join(home, "AppData", "Local"), "Programs", "ZCode", "resources", "glm", "zcode.cjs")
28
28
  ]
29
29
  : process.platform === "darwin"
30
30
  ? [
@@ -131,9 +131,9 @@ export function createZcodeGuiAdapter({ command, appServerArgs, spawnFn } = {})
131
131
  }
132
132
  function findOnPath(command, env) {
133
133
  const extensions = process.platform === "win32"
134
- ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";")]
134
+ ? ["", ...(processEnvironmentValue(env, "PATHEXT") ?? ".EXE;.CMD;.BAT;.COM").split(";")]
135
135
  : [""];
136
- for (const directory of (env.PATH ?? "").split(delimiter)) {
136
+ for (const directory of (processEnvironmentValue(env, "PATH") ?? "").split(delimiter)) {
137
137
  if (!directory)
138
138
  continue;
139
139
  for (const extension of extensions) {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-adapter-zcode-gui",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": "./dist/index.js",
7
7
  "dependencies": {
8
- "@mininglamp-oss/octo-runtime-protocol": "1.1.2",
9
- "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.2"
8
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.4",
9
+ "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.4"
10
10
  },
11
11
  "types": "./dist/index.d.ts",
12
12
  "files": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "commit": "5c1921dced4b0852e41426f1c04582159082f482",
2
+ "commit": "13f05e0139ae636ae40479d5609d893b3cb3702e",
3
3
  "dirty": false,
4
- "buildTime": "2026-10-22T12:44:46.791Z"
4
+ "buildTime": "2026-10-26T08:52:15.764Z"
5
5
  }
@@ -63,10 +63,12 @@ Commands:
63
63
  stop Stop this service, preserving its autostart setting
64
64
  status Show native service, IPC and component status
65
65
  run Run this component in the foreground
66
- ${component === "executor-kernel" ? "" : " logs Tail service status logs (no conversation content)\n"}
66
+ ${component === "executor-kernel" ? " recover Acknowledge a blocked orphan cleanup after stopping all orphan tools\n" : " logs Tail service status logs (no conversation content)\n"}
67
67
 
68
68
  Flags: --home <path> --profile <name> --manifest <path> --json --help
69
+ --manifest selects Provider/Extra modules; invocation state stays in --home/run.
69
70
  Install: --autostart=true|false
71
+ ${component === "executor-kernel" ? "Recover: --acknowledge-orphan-cleanup (retains evidence; refuses a live owner)\n" : ""}
70
72
  ${component === "executor-kernel" ? "" : "Logs: --lines <1..10000> (default 200) --follow --json (NDJSON)\n"}
71
73
  Kernel and Extras have independent services and autostart settings.
72
74
  An Extra may start before Kernel and connect when Kernel becomes available.`;
@@ -76,6 +78,7 @@ Manage the local Agent runtime and independent services.
76
78
 
77
79
  Usage:
78
80
  octo-runtime executor-kernel uninstall|install|start|restart|stop|status|run
81
+ octo-runtime executor-kernel recover --acknowledge-orphan-cleanup
79
82
  octo-runtime <extra-name> uninstall|install|start|restart|stop|status|run
80
83
  octo-runtime <extra-name> logs [--lines 200] [--follow] [--json]
81
84
  octo-runtime status [--json]
@@ -87,6 +90,7 @@ octo-runtime extraget <name>
87
90
  octo-runtime playboard < request.json
88
91
 
89
92
  Flags: --home <path> --profile <name> --manifest <path> --json
93
+ --manifest selects Provider/Extra modules; invocation state stays in --home/run.
90
94
  Install: --autostart=true|false (defaults to true)
91
95
  Extras: channel-gateway, channel-wecom, webui, or a name saved by extraset.
92
96
  Components:
@@ -4,7 +4,7 @@ import { once } from "node:events";
4
4
  import { lstat, mkdir } from "node:fs/promises";
5
5
  import { join, resolve } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
- import { attachKernel, createKernelService, readAdapterConfigurations } from "@mininglamp-oss/octo-runtime-executor-kernel";
7
+ import { attachKernel, acknowledgeOrphanCleanup, inspectOrphanCleanup, createKernelService, readAdapterConfigurations } from "@mininglamp-oss/octo-runtime-executor-kernel";
8
8
  import { componentEndpoint, createExtraService } from "@mininglamp-oss/octo-runtime-host-sdk";
9
9
  import { getExtra, readExtra, setExtra } from "./extras.js";
10
10
  import { cliVersionInfo, helpText } from "./help.js";
@@ -27,6 +27,9 @@ export async function runCli(args, dependencies = {}) {
27
27
  let statusOutput;
28
28
  try {
29
29
  const { flags, positional } = parse(args);
30
+ if (flags["acknowledge-orphan-cleanup"] !== undefined &&
31
+ !(positional[0] === "executor-kernel" && positional[1] === "recover"))
32
+ throw new Error("INVALID_ARGUMENTS");
30
33
  if ((flags.lines !== undefined || flags.follow !== undefined) && positional[1] !== "logs")
31
34
  throw new Error("INVALID_ARGUMENTS");
32
35
  json = Boolean(flags.json);
@@ -44,6 +47,25 @@ export async function runCli(args, dependencies = {}) {
44
47
  return 0;
45
48
  }
46
49
  const home = resolve(flags.home ?? defaultRuntimeHome(dependencies.env, dependencies.platform));
50
+ // 模块清单不决定运行状态位置;前台 Kernel、doctor 和恢复确认共用 Home 下的同一路径。
51
+ const kernelStateDirectory = join(home, "run");
52
+ const kernelInvocationManifest = join(kernelStateDirectory, "kernel-invocations.json");
53
+ // 恢复确认不加载 Provider 或访问服务管理器;原记录继续保留,下一次启动校验摘要后替换。
54
+ if (positional[0] === "executor-kernel" && positional[1] === "recover") {
55
+ context = { component: "executor-kernel", action: "recover", logs: join(home, "logs") };
56
+ if (positional.length !== 2 ||
57
+ flags["acknowledge-orphan-cleanup"] !== "true" ||
58
+ flags.autostart !== undefined)
59
+ throw new Error("INVALID_ARGUMENTS");
60
+ const recovery = await withSetupLock({
61
+ ...runtimePaths(home, "default", dependencies.platform),
62
+ setupLock: join(kernelStateDirectory, "executor-kernel.setup.lock")
63
+ }, () => acknowledgeOrphanCleanup(kernelInvocationManifest));
64
+ output(json
65
+ ? JSON.stringify(recovery)
66
+ : `Orphan cleanup acknowledged. Evidence: ${recovery.archivePath}\nStart executor-kernel again using the same --home.`);
67
+ return 0;
68
+ }
47
69
  // Route logs before config/module/manager access so offline failures remain diagnosable.
48
70
  if (positional[1] === "logs") {
49
71
  const extra = positional[0];
@@ -190,9 +212,10 @@ export async function runCli(args, dependencies = {}) {
190
212
  const manager = await service.backend.probe();
191
213
  const status = await snapshots(componentNames);
192
214
  const checks = Object.entries(status).map(([component, value]) => ({ component, ...value }));
193
- publish({ manager, checks }, `Manager: ${manager.manager} (${manager.supported ? "available" : "unavailable"})\n\n${Object.entries(status)
215
+ const recovery = await inspectOrphanCleanup(kernelInvocationManifest);
216
+ publish({ manager, checks, recovery }, `Manager: ${manager.manager} (${manager.supported ? "available" : "unavailable"})\n\n${Object.entries(status)
194
217
  .map(([name, value]) => formatStatus(name, value))
195
- .join("\n\n")}`);
218
+ .join("\n\n")}\n\nOrphan cleanup: ${recovery.state}\nManifest: ${recovery.manifestPath}${recovery.state === "cleanup_incomplete" ? "\nStop all orphan tools, then run executor-kernel recover --acknowledge-orphan-cleanup with the same --home." : ""}`);
196
219
  return 0;
197
220
  }
198
221
  if (positional[0] === "status" && positional.length === 1) {
@@ -225,7 +248,7 @@ export async function runCli(args, dependencies = {}) {
225
248
  const config = await readJsonFile(paths.profileConfig);
226
249
  handle = createKernelService({
227
250
  endpoint,
228
- stateDirectory: join(home, "run"),
251
+ stateDirectory: kernelStateDirectory,
229
252
  workerEntrypoint: fileURLToPath(new URL("./worker.js", import.meta.url)),
230
253
  adapterModules: resolveAdapterModules(manifest),
231
254
  adapterConfigurations: readAdapterConfigurations(paths.profileRoot, config?.adapters),
@@ -444,14 +467,17 @@ function parse(args) {
444
467
  "version",
445
468
  "autostart",
446
469
  "lines",
447
- "follow"
470
+ "follow",
471
+ "acknowledge-orphan-cleanup"
448
472
  ].includes(match[1]) ||
449
473
  Object.hasOwn(flags, match[1]))
450
474
  throw new Error("INVALID_ARGUMENTS");
451
475
  const key = match[1];
452
- flags[key] = ["json", "help", "version", "follow"].includes(key)
476
+ flags[key] = ["json", "help", "version", "follow", "acknowledge-orphan-cleanup"].includes(key)
453
477
  ? "true"
454
478
  : (match[2] ?? args[++i]);
479
+ if (key === "acknowledge-orphan-cleanup" && match[2] !== undefined)
480
+ throw new Error("INVALID_ARGUMENTS");
455
481
  if (!flags[key] ||
456
482
  flags[key].startsWith("--") ||
457
483
  (key === "autostart" && !["true", "false"].includes(flags[key])))
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "version": 1,
3
3
  "adapters": [
4
+ {
5
+ "type": "dsh",
6
+ "module": "@mininglamp-oss/octo-runtime-adapter-dsh",
7
+ "export": "dshAdapter"
8
+ },
4
9
  {
5
10
  "type": "codex",
6
11
  "module": "@mininglamp-oss/octo-runtime-adapter-codex",
@@ -1,4 +1,5 @@
1
- import { readFile, mkdir, writeFile, rename, lstat, chmod, rm } from "node:fs/promises";
1
+ import { constants } from "node:fs";
2
+ import { readFile, mkdir, writeFile, rename, lstat, open, rm } from "node:fs/promises";
2
3
  import { parseEnv, promisify } from "node:util";
3
4
  import { execFile } from "node:child_process";
4
5
  import { randomUUID } from "node:crypto";
@@ -134,8 +135,19 @@ export async function syncCliOpenClawToolEnvironment(runtimeRoot, extras) {
134
135
  (url.protocol !== "https:" &&
135
136
  !(url.protocol === "http:" && ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname))))
136
137
  throw new Error("IM_API_URL_INVALID");
137
- url.pathname = url.pathname.replace(/\/+$/, "").replace(/\/api$/, "");
138
- values = { OCTO_BOT_TOKEN: token, OCTO_API_BASE_URL: url.href.replace(/\/+$/, "") };
138
+ let end = url.pathname.length;
139
+ while (end > 0 && url.pathname[end - 1] === "/")
140
+ end--;
141
+ url.pathname = url.pathname.slice(0, end).replace(/\/api$/, "");
142
+ // 去掉 /api 后可能露出多重尾斜杠,仍需全部移除,并保留路径内部的分隔符。
143
+ const href = url.href;
144
+ end = href.length;
145
+ while (end > 0 && href[end - 1] === "/")
146
+ end--;
147
+ values = {
148
+ OCTO_BOT_TOKEN: token,
149
+ OCTO_API_BASE_URL: href.slice(0, end)
150
+ };
139
151
  }
140
152
  if (!values)
141
153
  return { written: false, restartRequired: false };
@@ -149,10 +161,23 @@ export async function syncCliOpenClawToolEnvironment(runtimeRoot, extras) {
149
161
  throw new Error("OPENCLAW_ENV_DIRECTORY_INVALID");
150
162
  let previous = "";
151
163
  try {
152
- const info = await lstat(file);
153
- if (!info.isFile())
154
- throw new Error("OPENCLAW_ENV_FILE_INVALID");
155
- previous = await readFile(file, "utf8");
164
+ const handle = await open(file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
165
+ try {
166
+ // 校验、读取和收紧权限绑定同一目标;拒绝链接,避免检查后重新按路径操作。
167
+ const info = await handle.stat();
168
+ if (!info.isFile())
169
+ throw new Error("OPENCLAW_ENV_FILE_INVALID");
170
+ if (!constants.O_NOFOLLOW) {
171
+ const entry = await lstat(file);
172
+ if (!entry.isFile() || entry.dev !== info.dev || entry.ino !== info.ino)
173
+ throw new Error("OPENCLAW_ENV_FILE_INVALID");
174
+ }
175
+ await handle.chmod(0o600);
176
+ previous = await handle.readFile("utf8");
177
+ }
178
+ finally {
179
+ await handle.close();
180
+ }
156
181
  }
157
182
  catch (error) {
158
183
  if (error.code !== "ENOENT")
@@ -170,7 +195,6 @@ export async function syncCliOpenClawToolEnvironment(runtimeRoot, extras) {
170
195
  Object.entries(values).some(([key, value]) => after[key] !== value))
171
196
  throw new Error("OPENCLAW_ENV_UPDATE_INVALID");
172
197
  if (content === previous) {
173
- await chmod(file, 0o600);
174
198
  return { file, written: false, restartRequired: true };
175
199
  }
176
200
  const temporary = join(origin.openclaw_home, `.octo-env-${randomUUID()}.tmp`);
@@ -99,6 +99,9 @@ export function describeError(error, fallback = "COMMAND_FAILED") {
99
99
  KERNEL_UNAVAILABLE: "Kernel is unavailable. Check executor-kernel status; Extras can remain running.",
100
100
  INVALID_ARGUMENTS: "Use --help to see the available commands and flags.",
101
101
  SETUP_IN_PROGRESS: "Another component lifecycle operation is in progress. Wait for it to finish, then retry.",
102
+ ORPHAN_CLEANUP_INCOMPLETE: "Run doctor with the same --home to inspect the manifest. After stopping all orphan tools, run executor-kernel recover --acknowledge-orphan-cleanup, then start again.",
103
+ ORPHAN_CLEANUP_OWNER_ALIVE: "The original Kernel or worker is still alive or its identity cannot be verified. Stop it safely before acknowledging cleanup.",
104
+ ORPHAN_CLEANUP_NOT_PENDING: "There is no valid incomplete orphan cleanup to acknowledge. Run doctor with the same --home.",
102
105
  SERVICE_NOT_INSTALLED: "Run this component's install command, then start it.",
103
106
  NOT_INSTALLED: "Run this component's install command, then start it.",
104
107
  EXTRA_NOT_REGISTERED: "Save this Extra's declaration with extraset before starting it.",
@@ -6,4 +6,9 @@ export interface PlayboardOptions {
6
6
  home?: string;
7
7
  profile?: string;
8
8
  }
9
+ /**
10
+ * CLI 单次执行入口:读取一个 InvokeInput,原生构造并拥有本次临时 Kernel,消费源帧后关闭。
11
+ * 返回执行退出码;关闭失败仍拒绝,并保留已发生的执行错误或非零结果,不能假报清理成功。
12
+ * Home/profile 属于调用者,仅删除本次创建的临时目录,不改变公共 SDK 调用合同。
13
+ */
9
14
  export declare function runPlayboard(options: PlayboardOptions): Promise<number>;
@@ -9,6 +9,11 @@ import { tmpdir } from "node:os";
9
9
  import { join } from "node:path";
10
10
  import { identifyInvokeInput, isHostTerminal, isTerminal } from "@mininglamp-oss/octo-runtime-protocol";
11
11
  import { INVOKE_REQUEST_MAX_BYTES } from "@mininglamp-oss/octo-runtime-protocol";
12
+ /**
13
+ * CLI 单次执行入口:读取一个 InvokeInput,原生构造并拥有本次临时 Kernel,消费源帧后关闭。
14
+ * 返回执行退出码;关闭失败仍拒绝,并保留已发生的执行错误或非零结果,不能假报清理成功。
15
+ * Home/profile 属于调用者,仅删除本次创建的临时目录,不改变公共 SDK 调用合同。
16
+ */
12
17
  export async function runPlayboard(options) {
13
18
  if (options.input.isTTY) {
14
19
  throw new Error("playboard requires a JSON request on stdin; use <<< '...JSON...' or < request.json");
@@ -46,6 +51,9 @@ export async function runPlayboard(options) {
46
51
  throw new Error("RUNTIME_CONFIGURATION_NOT_FOUND: request profile differs from --profile");
47
52
  input.runMetadata = { ...input.runMetadata, profile };
48
53
  const output = options.output ?? writeLine;
54
+ // Unix socket 的路径预算小于普通文件路径;固定短根,避免 TMPDIR 嵌套或中文路径超限。
55
+ // mkdtemp 创建本次独占的 0700 目录;常驻服务仍使用 Runtime Home,Windows 保留命名管道。
56
+ const temporary = await mkdtemp(join(process.platform === "win32" ? tmpdir() : "/tmp", "op-"));
49
57
  const controller = new AbortController();
50
58
  let interrupted = 0;
51
59
  const onInterrupt = () => {
@@ -64,7 +72,9 @@ export async function runPlayboard(options) {
64
72
  process.once("SIGINT", onInterrupt);
65
73
  process.once("SIGTERM", onTerminate);
66
74
  let kernel;
67
- const temporary = await mkdtemp(join(tmpdir(), "octo-playboard-"));
75
+ let outcome;
76
+ let primaryFailure;
77
+ let cleanupFailure;
68
78
  try {
69
79
  const paths = runtimePaths(home, profile);
70
80
  const manifest = await loadCliManifest(home, options.manifest);
@@ -101,25 +111,43 @@ export async function runPlayboard(options) {
101
111
  if (!("kind" in frame) && isTerminal(frame))
102
112
  exitCode = frame.type === "run.completed" ? 0 : frame.type === "run.cancelled" ? 130 : 1;
103
113
  }
104
- return interrupted || exitCode;
114
+ outcome = interrupted || exitCode;
105
115
  }
106
116
  catch (error) {
107
117
  if (interrupted)
108
- return interrupted;
109
- throw error;
118
+ outcome = interrupted;
119
+ else
120
+ primaryFailure = { error };
121
+ }
122
+ try {
123
+ await closeKernel(kernel);
124
+ await rm(temporary, { recursive: true, force: true });
125
+ }
126
+ catch (error) {
127
+ cleanupFailure = { error };
110
128
  }
111
129
  finally {
112
- try {
113
- await closeKernel(kernel);
114
- await rm(temporary, { recursive: true, force: true });
115
- }
116
- finally {
117
- if (!options.output)
118
- process.stdout.removeListener("error", onOutputError);
119
- process.removeListener("SIGINT", onInterrupt);
120
- process.removeListener("SIGTERM", onTerminate);
130
+ if (!options.output)
131
+ process.stdout.removeListener("error", onOutputError);
132
+ process.removeListener("SIGINT", onInterrupt);
133
+ process.removeListener("SIGTERM", onTerminate);
134
+ }
135
+ // 清理之后统一选择结果,避免 finally 的拒绝覆盖主结果。保留两个原始异常对象;
136
+ // 取消/失败已有帧不改写,清理失败仍非零退出,不返回原来的成功码。
137
+ if (cleanupFailure) {
138
+ const cleanupError = cleanupFailure.error;
139
+ const cleanupMessage = cleanupError instanceof Error ? cleanupError.message : String(cleanupError);
140
+ if (primaryFailure) {
141
+ const primary = primaryFailure.error;
142
+ throw new AggregateError([primary, cleanupError], `${primary instanceof Error ? primary.message : String(primary)}; cleanup: ${cleanupMessage}`, { cause: cleanupError });
121
143
  }
144
+ if (outcome !== undefined && outcome !== 0)
145
+ throw new AggregateError([cleanupError], `Playboard exited with code ${outcome}; cleanup: ${cleanupMessage}`, { cause: cleanupError });
146
+ throw cleanupError;
122
147
  }
148
+ if (primaryFailure)
149
+ throw primaryFailure.error;
150
+ return outcome ?? 1;
123
151
  }
124
152
  function writeLine(line) {
125
153
  return new Promise((resolve, reject) => {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-cli",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,28 +8,29 @@
8
8
  },
9
9
  "types": "./dist/index.d.ts",
10
10
  "dependencies": {
11
- "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.2",
11
+ "@mininglamp-oss/octo-runtime-adapter-dsh": "1.1.4",
12
+ "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.4",
12
13
  "json5": "2.2.3",
13
- "@mininglamp-oss/octo-runtime-extra-channel-gateway": "1.1.2",
14
- "@mininglamp-oss/octo-runtime-host-sdk": "1.1.2",
15
- "@mininglamp-oss/octo-runtime-adapter-openclaw": "1.1.2",
16
- "@mininglamp-oss/octo-runtime-cross-service": "1.1.2",
17
- "@mininglamp-oss/octo-runtime-protocol": "1.1.2",
18
- "@mininglamp-oss/octo-runtime-executor-kernel": "1.1.2",
19
- "@mininglamp-oss/octo-runtime-executor-core": "1.1.2",
20
- "@mininglamp-oss/octo-runtime-adapter-antigravity": "1.1.2",
21
- "@mininglamp-oss/octo-runtime-adapter-claude-code": "1.1.2",
22
- "@mininglamp-oss/octo-runtime-adapter-codebuddy": "1.1.2",
23
- "@mininglamp-oss/octo-runtime-adapter-codex": "1.1.2",
24
- "@mininglamp-oss/octo-runtime-adapter-hermes": "1.1.2",
25
- "@mininglamp-oss/octo-runtime-adapter-grok-build": "1.1.2",
26
- "@mininglamp-oss/octo-runtime-adapter-kimi-code": "1.1.2",
27
- "@mininglamp-oss/octo-runtime-adapter-mcode": "1.1.2",
28
- "@mininglamp-oss/octo-runtime-adapter-opencode": "1.1.2",
29
- "@mininglamp-oss/octo-runtime-adapter-qodercli": "1.1.2",
30
- "@mininglamp-oss/octo-runtime-adapter-qoderclicn": "1.1.2",
31
- "@mininglamp-oss/octo-runtime-adapter-zcode-gui": "1.1.2",
32
- "@mininglamp-oss/octo-runtime-extra-channel-wecom": "1.1.2",
33
- "@mininglamp-oss/octo-runtime-extra-webui": "1.1.2"
14
+ "@mininglamp-oss/octo-runtime-extra-channel-gateway": "1.1.4",
15
+ "@mininglamp-oss/octo-runtime-host-sdk": "1.1.4",
16
+ "@mininglamp-oss/octo-runtime-adapter-openclaw": "1.1.4",
17
+ "@mininglamp-oss/octo-runtime-cross-service": "1.1.4",
18
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.4",
19
+ "@mininglamp-oss/octo-runtime-executor-kernel": "1.1.4",
20
+ "@mininglamp-oss/octo-runtime-executor-core": "1.1.4",
21
+ "@mininglamp-oss/octo-runtime-adapter-antigravity": "1.1.4",
22
+ "@mininglamp-oss/octo-runtime-adapter-claude-code": "1.1.4",
23
+ "@mininglamp-oss/octo-runtime-adapter-codebuddy": "1.1.4",
24
+ "@mininglamp-oss/octo-runtime-adapter-codex": "1.1.4",
25
+ "@mininglamp-oss/octo-runtime-adapter-hermes": "1.1.4",
26
+ "@mininglamp-oss/octo-runtime-adapter-grok-build": "1.1.4",
27
+ "@mininglamp-oss/octo-runtime-adapter-kimi-code": "1.1.4",
28
+ "@mininglamp-oss/octo-runtime-adapter-mcode": "1.1.4",
29
+ "@mininglamp-oss/octo-runtime-adapter-opencode": "1.1.4",
30
+ "@mininglamp-oss/octo-runtime-adapter-qodercli": "1.1.4",
31
+ "@mininglamp-oss/octo-runtime-adapter-qoderclicn": "1.1.4",
32
+ "@mininglamp-oss/octo-runtime-adapter-zcode-gui": "1.1.4",
33
+ "@mininglamp-oss/octo-runtime-extra-channel-wecom": "1.1.4",
34
+ "@mininglamp-oss/octo-runtime-extra-webui": "1.1.4"
34
35
  }
35
36
  }
@@ -14,13 +14,13 @@ export declare function runCommand(runner: CommandRunner, backend: ServiceBacken
14
14
  }): Promise<CommandResult>;
15
15
  /** 平台仅在确认原生 not-found 后忽略失败,其他结果沿同一受控错误合同传播。 */
16
16
  export declare function assertCommandSucceeded(result: CommandResult, backend: ServiceBackendKind): void;
17
- /** Read a UTF-8 service definition; absence is represented as `undefined`. */
17
+ /** 读取服务定义;兼容 Windows UTF-16LE BOM 与既有 UTF-8,缺失返回 undefined。 */
18
18
  export declare function readDefinition(path: string): Promise<string | undefined>;
19
19
  /**
20
20
  * Atomically replace a service definition with mode 0600.
21
21
  * Returns `false` when the installed bytes already match the desired content.
22
22
  */
23
- export declare function writeDefinition(path: string, content: string): Promise<boolean>;
23
+ export declare function writeDefinition(path: string, content: string, encoding?: "utf8" | "utf16le"): Promise<boolean>;
24
24
  /** Remove a service definition if present. */
25
25
  export declare function removeDefinition(path: string): Promise<void>;
26
26
  /** Return stable drift identifiers for desired-versus-installed file content. */
@@ -107,10 +107,13 @@ export function assertCommandSucceeded(result, backend) {
107
107
  });
108
108
  }
109
109
  }
110
- /** Read a UTF-8 service definition; absence is represented as `undefined`. */
110
+ /** 读取服务定义;兼容 Windows UTF-16LE BOM 与既有 UTF-8,缺失返回 undefined。 */
111
111
  export async function readDefinition(path) {
112
112
  try {
113
- return await readFile(path, "utf8");
113
+ const bytes = await readFile(path);
114
+ return bytes[0] === 0xff && bytes[1] === 0xfe
115
+ ? bytes.subarray(2).toString("utf16le")
116
+ : bytes.toString("utf8");
114
117
  }
115
118
  catch (error) {
116
119
  if (isNodeError(error, "ENOENT"))
@@ -122,15 +125,22 @@ export async function readDefinition(path) {
122
125
  * Atomically replace a service definition with mode 0600.
123
126
  * Returns `false` when the installed bytes already match the desired content.
124
127
  */
125
- export async function writeDefinition(path, content) {
126
- if ((await readDefinition(path)) === content)
127
- return false;
128
+ export async function writeDefinition(path, content, encoding = "utf8") {
129
+ const bytes = Buffer.from(encoding === "utf16le" ? `\uFEFF${content}` : content, encoding);
130
+ try {
131
+ if ((await readFile(path)).equals(bytes))
132
+ return false;
133
+ }
134
+ catch (error) {
135
+ if (!isNodeError(error, "ENOENT"))
136
+ throw error;
137
+ }
128
138
  await mkdir(dirname(path), { recursive: true, mode: 0o700 });
129
139
  const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
130
140
  try {
131
141
  const file = await open(temporary, "wx", 0o600);
132
142
  try {
133
- await file.writeFile(content, "utf8");
143
+ await file.writeFile(bytes);
134
144
  await file.sync();
135
145
  }
136
146
  finally {
@@ -248,12 +248,8 @@ function renderSystemdUnitNormalized(spec) {
248
248
  .sort(([left], [right]) => left.localeCompare(right))
249
249
  .map(([key, value]) => `Environment=${systemdQuote(`${key}=${value}`)}`)
250
250
  .join("\n");
251
- const output = spec.stdoutPath
252
- ? `StandardOutput=${systemdQuote(`append:${spec.stdoutPath}`)}\n`
253
- : "";
254
- const error = spec.stderrPath
255
- ? `StandardError=${systemdQuote(`append:${spec.stderrPath}`)}\n`
256
- : "";
251
+ const output = spec.stdoutPath ? `StandardOutput=append:${systemdPath(spec.stdoutPath)}\n` : "";
252
+ const error = spec.stderrPath ? `StandardError=append:${systemdPath(spec.stderrPath)}\n` : "";
257
253
  return `[Unit]
258
254
  Description=${escapeSystemdText(spec.description)}
259
255
  After=network-online.target
@@ -264,7 +260,7 @@ StartLimitBurst=${spec.restart.maxBurst}
264
260
  [Service]
265
261
  Type=simple
266
262
  ExecStart=:${[spec.command, ...spec.args].map(systemdQuote).join(" ")}
267
- WorkingDirectory=${systemdQuote(spec.workingDirectory)}
263
+ WorkingDirectory=${systemdPath(spec.workingDirectory)}
268
264
  ${environment ? `${environment}\n` : ""}Restart=${restart}
269
265
  RestartSec=${spec.restart.delaySeconds}s
270
266
  TimeoutStopSec=${spec.timeoutStopSeconds}s
@@ -283,6 +279,12 @@ function systemdUnit(spec) {
283
279
  function systemdQuote(value) {
284
280
  return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replaceAll("%", "%%")}"`;
285
281
  }
282
+ function systemdPath(value) {
283
+ const trailingBackslashes = value.match(/\\+$/)?.[0].length ?? 0;
284
+ if (/[ \t]$/.test(value))
285
+ throw new ServiceError("UNSUPPORTED_SPEC", "systemd path directives cannot preserve trailing spaces or tabs");
286
+ return `${value.replaceAll("%", "%%")}${trailingBackslashes % 2 === 0 ? "" : " "}`;
287
+ }
286
288
  function escapeSystemdText(value) {
287
289
  return value.replaceAll("%", "%%");
288
290
  }
@@ -35,7 +35,10 @@ export declare class WindowsUserTaskBackend implements ServiceBackend {
35
35
  /** 确认旧实例停止后再启动替换实例;IPC 就绪仍由宿主查询,注销后不承诺继续运行。 */
36
36
  restart(spec: ServiceSpec): Promise<void>;
37
37
  }
38
- /** Validate and render deterministic Task Scheduler XML for one Windows user. */
38
+ /**
39
+ * 为一个 Windows 用户校验并返回确定的 XML 文本;声明为 UTF-16。
40
+ * 调用者写文件时必须使用带 BOM 的 UTF-16LE,不能按默认 UTF-8 序列化。
41
+ */
39
42
  export declare function renderWindowsTaskXml(spec: ServiceSpec, userId: string): string;
40
43
  /**
41
44
  * Quote one argv element with the Windows `CommandLineToArgvW` escaping rules.