@mininglamp-oss/octo-runtime 1.1.10 → 1.1.11

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 (170) hide show
  1. package/README.md +1 -1
  2. package/apps/cli/README.md +1 -1
  3. package/apps/cli/dist/adapters.js +40 -14
  4. package/apps/cli/dist/build-info.json +2 -2
  5. package/apps/cli/dist/command-tree.js +2 -3
  6. package/apps/cli/dist/extras.js +11 -1
  7. package/apps/cli/dist/index.js +14 -1
  8. package/apps/cli/dist/main.js +58 -23
  9. package/apps/cli/dist/module-manifest.js +21 -3
  10. package/apps/cli/dist/output.d.ts +19 -1
  11. package/apps/cli/dist/output.js +179 -27
  12. package/apps/cli/dist/playboard.js +2 -2
  13. package/apps/cli/dist/state.d.ts +5 -2
  14. package/apps/cli/dist/state.js +48 -13
  15. package/dist/public/codex.d.ts +1 -0
  16. package/dist/public/codex.js +1 -0
  17. package/dist/public/executor-kernel.d.ts +4 -0
  18. package/dist/public/executor-kernel.js +2 -0
  19. package/dist/public/extra.d.ts +1 -1
  20. package/dist/public/host.d.ts +5 -0
  21. package/dist/public/host.js +2 -0
  22. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  23. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +20 -0
  24. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  25. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  26. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  27. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  28. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.d.ts +6 -6
  29. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +68 -253
  30. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.d.ts +11 -6
  31. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +198 -52
  32. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.d.ts +58 -0
  33. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.js +650 -0
  34. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.d.ts +3 -0
  35. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.js +15 -0
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +2 -0
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +5 -0
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.d.ts +25 -0
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.js +1 -0
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +3 -0
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  52. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.js +40 -14
  53. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  54. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +2 -3
  55. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +11 -1
  56. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/index.js +14 -1
  57. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +58 -23
  58. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +21 -3
  59. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.d.ts +19 -1
  60. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +179 -27
  61. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +2 -2
  62. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.d.ts +5 -2
  63. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -13
  64. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +23 -23
  65. package/node_modules/@mininglamp-oss/octo-runtime-client/build-info.json +5 -0
  66. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/async-question-reply.d.ts +30 -0
  67. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/async-question-reply.js +199 -0
  68. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/browser.d.ts +1 -0
  69. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/browser.js +1 -0
  70. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.d.ts +10 -0
  71. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.js +465 -0
  72. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/index.d.ts +6 -0
  73. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/index.js +6 -0
  74. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/internal.d.ts +4 -0
  75. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/internal.js +5 -0
  76. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/invocation-lifecycle.d.ts +59 -0
  77. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/invocation-lifecycle.js +287 -0
  78. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/notification.d.ts +1 -0
  79. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/notification.js +1 -0
  80. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/protocol.d.ts +1 -0
  81. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/protocol.js +1 -0
  82. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/runtime-path.d.ts +21 -0
  83. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/runtime-path.js +138 -0
  84. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-catalog.d.ts +8 -0
  85. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-catalog.js +65 -0
  86. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-diagnostics.d.ts +82 -0
  87. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-diagnostics.js +371 -0
  88. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/submission-error.d.ts +10 -0
  89. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/submission-error.js +23 -0
  90. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/types.d.ts +72 -0
  91. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/types.js +10 -0
  92. package/node_modules/@mininglamp-oss/octo-runtime-client/package.json +54 -0
  93. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-configuration-fixtures.json +1219 -0
  94. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-fixtures.json +5988 -0
  95. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-client.behavior.json +56 -0
  96. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc-fixtures.json +53 -0
  97. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc.schema.json +538 -0
  98. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/native-invoke-fixtures.json +116 -0
  99. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/protocol.schema.json +4525 -0
  100. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/run-protocol-fixtures.json +761 -0
  101. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/runtime-selection-fixtures.json +663 -0
  102. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/session-name-fixtures.json +191 -0
  103. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  104. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +26 -18
  105. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +151 -11
  106. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  107. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.d.ts +1 -30
  108. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.js +2 -199
  109. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.d.ts +1 -10
  110. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.js +2 -446
  111. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/endpoint.js +2 -0
  112. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.d.ts +2 -0
  113. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.js +13 -2
  114. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +4 -1
  115. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +4 -1
  116. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.d.ts +1 -53
  117. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -280
  118. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/lifecycle.d.ts +5 -10
  119. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/lifecycle.js +4 -1
  120. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-home.d.ts +20 -0
  121. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-home.js +180 -0
  122. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +31 -8
  123. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.d.ts +5 -2
  124. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.js +48 -5
  125. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-catalog.d.ts +1 -0
  126. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-catalog.js +1 -0
  127. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-diagnostics.d.ts +1 -0
  128. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-diagnostics.js +1 -0
  129. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-logging.d.ts +4 -0
  130. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-logging.js +18 -0
  131. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +1 -10
  132. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +2 -23
  133. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/types.d.ts +2 -72
  134. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/types.js +2 -10
  135. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +5 -4
  136. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/extra.js +1 -1
  137. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/ports.d.ts +2 -2
  138. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
  139. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/extra.js +1 -1
  140. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/ports.d.ts +2 -2
  141. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
  142. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/index.js +4 -4
  143. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
  144. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.d.ts +1 -1
  145. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.js +12 -5
  146. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/errors.d.ts +5 -1
  147. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/errors.js +9 -0
  148. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/execution.d.ts +44 -0
  149. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/execution.js +207 -0
  150. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +23 -3
  151. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.d.ts +27 -4
  152. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.js +133 -25
  153. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extras.d.ts +10 -3
  154. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extras.js +18 -4
  155. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.d.ts +5 -6
  156. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +33 -45
  157. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/identity.js +6 -0
  158. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +4 -0
  159. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +3 -0
  160. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +5 -4
  161. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.d.ts +7 -0
  162. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.js +1 -0
  163. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +19 -0
  164. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +3 -1
  165. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +1 -0
  166. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.d.ts +5 -0
  167. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.js +65 -0
  168. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  169. package/package.json +33 -27
  170. package/packages/octo-runtime-protocol/schema/protocol.schema.json +42 -0
@@ -3,23 +3,22 @@ import { runExtraCommand, commandError } from "./extra-commands.js";
3
3
  import net from "node:net";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { once } from "node:events";
6
- import { lstat, mkdir } from "node:fs/promises";
6
+ import { lstat } from "node:fs/promises";
7
7
  import { join, resolve } from "node:path";
8
- import { attachKernel, acknowledgeOrphanCleanup, inspectOrphanCleanup, createKernelService } from "@mininglamp-oss/octo-runtime-executor-kernel";
9
- import { componentEndpoint, createExtraService } from "@mininglamp-oss/octo-runtime-host-sdk";
8
+ import { attachKernel, acknowledgeOrphanCleanup, inspectOrphanCleanup, createKernelService, safeStartupValue } from "@mininglamp-oss/octo-runtime-executor-kernel";
9
+ import { componentEndpoint, createExtraService, validateRuntimeHome, RuntimeHomeError } from "@mininglamp-oss/octo-runtime-host-sdk";
10
10
  import { getExtra, readExtra, setExtra } from "./extras.js";
11
11
  import { cliVersionInfo } from "./help.js";
12
12
  import { parseCliCommand } from "./command-tree.js";
13
13
  import { runForegroundService } from "./foreground.js";
14
14
  import { showExtraLogs } from "./logs.js";
15
15
  import { StatusOutput } from "./status-output.js";
16
- import { defaultRuntimeHome, runtimePaths, withSetupLock, readJsonFile } from "./state.js";
16
+ import { selectRuntimeHome, prepareRuntimeHome, runtimePaths, withSetupLock, readJsonFile } from "./state.js";
17
17
  import { resolveServiceControl } from "./service-control.js";
18
18
  import { loadCliManifest } from "./module-manifest.js";
19
19
  import { readCliAdapterConfigurations } from "./adapter-configurations.js";
20
- import { resolveAdapterModules } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
21
20
  import { readExtraDirectory } from "@mininglamp-oss/octo-runtime-host-sdk";
22
- import { describeError, formatStatus, recordStartupFailure, readStartupFailure } from "./output.js";
21
+ import { describeError, formatErrorDetails, formatStatus, residentProcesses, formatResidentProcesses, recordStartupFailure, readStartupFailure } from "./output.js";
23
22
  const components = ["executor-kernel", "channel-gateway"];
24
23
  const builtinComponents = [...components, "channel-wecom", "webui"];
25
24
  export async function runCli(args, dependencies = {}) {
@@ -28,6 +27,12 @@ export async function runCli(args, dependencies = {}) {
28
27
  const literalIndex = args.indexOf("--");
29
28
  let json = (literalIndex < 0 ? args : args.slice(0, literalIndex)).some((arg) => arg === "--json" || arg.startsWith("--json="));
30
29
  let context = {};
30
+ // 实际日志 IO 仍使用原路径;失败输出的附带元信息与 diagnostic 使用同一净化。
31
+ const failureContext = () => ({
32
+ component: context.component === undefined ? undefined : safeStartupValue(context.component, 128),
33
+ action: context.action === undefined ? undefined : safeStartupValue(context.action, 128),
34
+ logs: context.logs === undefined ? undefined : safeStartupValue(context.logs)
35
+ });
31
36
  let runningComponent;
32
37
  let statusOutput;
33
38
  try {
@@ -37,6 +42,7 @@ export async function runCli(args, dependencies = {}) {
37
42
  return 0;
38
43
  }
39
44
  const { flags, positional } = parsed;
45
+ context = { component: positional[0], action: positional[1] };
40
46
  json = Boolean(flags.json);
41
47
  if (parsed.extra)
42
48
  return await runExtraCommand(parsed, dependencies);
@@ -50,7 +56,18 @@ export async function runCli(args, dependencies = {}) {
50
56
  output(cliVersionInfo);
51
57
  return 0;
52
58
  }
53
- const home = resolve(flags.home ?? defaultRuntimeHome(dependencies.env, dependencies.platform));
59
+ const home = selectRuntimeHome(flags.home, dependencies.env, dependencies.platform);
60
+ // 先验证已存在的根,避免普通文件先退化成配置读取 ENOTDIR。
61
+ // 缺失根只由后面已确认的宿主动作准备;未知/已移除命令不能因此创建 Home。
62
+ if (["install", "start", "restart", "run"].includes(positional[1])) {
63
+ try {
64
+ validateRuntimeHome(home);
65
+ }
66
+ catch (error) {
67
+ if (!(error instanceof RuntimeHomeError && error.code === "HOME_NOT_FOUND"))
68
+ throw error;
69
+ }
70
+ }
54
71
  // 模块清单不决定运行状态位置;前台 Kernel、doctor 和恢复确认共用 Home 下的同一路径。
55
72
  const kernelStateDirectory = join(home, "run");
56
73
  const kernelInvocationManifest = join(kernelStateDirectory, "kernel-invocations.json");
@@ -115,7 +132,8 @@ export async function runCli(args, dependencies = {}) {
115
132
  const root = await readJsonFile(runtimePaths(home, "default").rootConfig);
116
133
  const profile = flags.profile ?? root?.default_profile ?? "default";
117
134
  const paths = runtimePaths(home, profile, dependencies.platform);
118
- const endpoint = componentEndpoint(home, "executor-kernel", dependencies.platform);
135
+ // 配置/恢复和 Playboard 不使用常驻端点;只在实际连接或托管常驻服务时派生并校验。
136
+ const kernelEndpoint = () => componentEndpoint(home, "executor-kernel", dependencies.platform);
119
137
  context = { component: positional[0], action: positional[1], logs: join(home, "logs") };
120
138
  const registrations = await readExtraDirectory(join(home, "extras"));
121
139
  // 部署、停止及配置修复命令不启动模块,也不因尚未可读的启动清单而无法操作。
@@ -192,7 +210,7 @@ export async function runCli(args, dependencies = {}) {
192
210
  });
193
211
  }
194
212
  if (positional[0] === "adapter" && positional[1] === "list" && positional.length === 2) {
195
- const client = attachKernel({ endpoint });
213
+ const client = attachKernel({ endpoint: kernelEndpoint() });
196
214
  try {
197
215
  publish(await client.list());
198
216
  }
@@ -202,7 +220,7 @@ export async function runCli(args, dependencies = {}) {
202
220
  return 0;
203
221
  }
204
222
  if (positional[0] === "adapter" && positional[1] === "probe" && positional.length === 3) {
205
- const client = attachKernel({ endpoint });
223
+ const client = attachKernel({ endpoint: kernelEndpoint() });
206
224
  try {
207
225
  const adapter = (await client.list()).find((value) => value.type === positional[2]);
208
226
  if (!adapter)
@@ -219,9 +237,10 @@ export async function runCli(args, dependencies = {}) {
219
237
  const status = await snapshots(componentNames);
220
238
  const checks = Object.entries(status).map(([component, value]) => ({ component, ...value }));
221
239
  const recovery = await inspectOrphanCleanup(kernelInvocationManifest);
222
- publish({ manager, checks, recovery }, `Manager: ${manager.manager} (${manager.supported ? "available" : "unavailable"})\n\n${Object.entries(status)
240
+ const processes = residentProcesses(status);
241
+ publish({ manager, checks, recovery, processes }, `Manager: ${manager.manager} (${manager.supported ? "available" : "unavailable"})\n\n${Object.entries(status)
223
242
  .map(([name, value]) => formatStatus(name, value))
224
- .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." : ""}`);
243
+ .join("\n\n")}\n\n${formatResidentProcesses(processes)}\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." : ""}`);
225
244
  return 0;
226
245
  }
227
246
  if (positional[0] === "status" && positional.length === 1) {
@@ -238,6 +257,8 @@ export async function runCli(args, dependencies = {}) {
238
257
  throw new Error("INVALID_ARGUMENTS");
239
258
  if (flags.autostart !== undefined && action !== "install")
240
259
  throw new Error("INVALID_ARGUMENTS");
260
+ if (["install", "start", "restart", "run"].includes(action))
261
+ componentEndpoint(home, component, dependencies.platform);
241
262
  if (action === "status") {
242
263
  const status = await snapshots([component]);
243
264
  publish(status[component], formatStatus(component, status[component]));
@@ -248,15 +269,16 @@ export async function runCli(args, dependencies = {}) {
248
269
  throw new Error("MANIFEST_INVALID");
249
270
  runningComponent = component;
250
271
  dependencies.onComponentRun?.();
251
- await mkdir(home, { recursive: true, mode: 0o700 });
272
+ await prepareRuntimeHome(home);
252
273
  let handle;
253
274
  if (component === "executor-kernel") {
254
275
  const config = await readJsonFile(paths.profileConfig);
255
276
  handle = createKernelService({
277
+ home,
256
278
  logging: { directory: join(home, "logs") },
257
- endpoint,
279
+ endpoint: kernelEndpoint(),
258
280
  stateDirectory: kernelStateDirectory,
259
- adapters: await loadCliAdapters(resolveAdapterModules(manifest), {
281
+ adapters: await loadCliAdapters(manifest.adapters, {
260
282
  profileRoot: paths.profileRoot,
261
283
  syncOpenClawTools: true
262
284
  }),
@@ -274,6 +296,7 @@ export async function runCli(args, dependencies = {}) {
274
296
  if (!dependencies.output)
275
297
  statusOutput = new StatusOutput(process.stdout);
276
298
  handle = createExtraService({
299
+ home,
277
300
  logging: {
278
301
  directory: join(home, "logs"),
279
302
  statusOutput: dependencies.output
@@ -284,7 +307,7 @@ export async function runCli(args, dependencies = {}) {
284
307
  config: registration.config,
285
308
  dependencies: {},
286
309
  enabled: registration.enabled,
287
- endpoint,
310
+ endpoint: kernelEndpoint(),
288
311
  controlEndpoint: componentEndpoint(home, component, dependencies.platform)
289
312
  });
290
313
  }
@@ -294,13 +317,16 @@ export async function runCli(args, dependencies = {}) {
294
317
  }
295
318
  finally {
296
319
  const failure = {
297
- ...describeError(error, "SERVICE_INITIALIZATION_FAILED"),
298
- ...context
320
+ ...describeError(error, "SERVICE_INITIALIZATION_FAILED", {
321
+ component,
322
+ phase: "initializing"
323
+ }),
324
+ ...failureContext()
299
325
  };
300
326
  if (json)
301
327
  publish({ error: failure });
302
328
  else
303
- (dependencies.errorOutput ?? ((line) => process.stderr.write(`${line}\n`)))(`${component}: ${failure.code}${failure.cause_code ? ` (${failure.cause_code})` : ""}\n${failure.message}\nLogs: ${context.logs}`);
329
+ (dependencies.errorOutput ?? ((line) => process.stderr.write(`${line}\n`)))(`${component}: ${failure.code}${failure.cause_code ? ` (${failure.cause_code})` : ""}\n${formatErrorDetails(failure)}\nLogs: ${failure.logs}`);
304
330
  }
305
331
  });
306
332
  }
@@ -313,7 +339,7 @@ export async function runCli(args, dependencies = {}) {
313
339
  return await withSetupLock({ ...paths, setupLock: join(home, "run", `${component}.setup.lock`) }, async () => {
314
340
  if (action === "install") {
315
341
  spec = { ...spec, enabled: flags.autostart !== "false" };
316
- await mkdir(home, { recursive: true, mode: 0o700 });
342
+ await prepareRuntimeHome(home);
317
343
  await service.backend.install(spec);
318
344
  }
319
345
  else {
@@ -323,7 +349,7 @@ export async function runCli(args, dependencies = {}) {
323
349
  const progress = dependencies.errorOutput ?? ((line) => process.stderr.write(`${line}\n`));
324
350
  progress(`${component}: service not installed; installing with autostart enabled...`);
325
351
  spec = { ...spec, enabled: true };
326
- await mkdir(home, { recursive: true, mode: 0o700 });
352
+ await prepareRuntimeHome(home);
327
353
  await service.backend.install(spec);
328
354
  progress(`${component}: installation complete; starting service...`);
329
355
  }
@@ -375,12 +401,21 @@ export async function runCli(args, dependencies = {}) {
375
401
  catch (error) {
376
402
  if (runningComponent && context.logs)
377
403
  await recordStartupFailure(context.logs, runningComponent, error);
378
- const failure = { ...(commandError(error) ?? describeError(error)), ...context };
404
+ const failure = {
405
+ ...(commandError(error) ??
406
+ describeError(error, "COMMAND_FAILED", ["run", "start", "restart", "install"].includes(context.action ?? "")
407
+ ? {
408
+ component: context.component ?? "cli",
409
+ phase: runningComponent ? "initializing" : "created"
410
+ }
411
+ : undefined)),
412
+ ...failureContext()
413
+ };
379
414
  const code = failure.code;
380
415
  if (json)
381
416
  output(JSON.stringify({ error: failure }, null, context.action === "logs" ? undefined : 2));
382
417
  else
383
- (dependencies.errorOutput ?? ((line) => process.stderr.write(`${line}\n`)))(`${[context.component, context.action].filter(Boolean).join(" ") || "octo-runtime"}: ${code}${failure.cause_code ? ` (${failure.cause_code})` : ""}\n${failure.message}${context.logs ? `\nLogs: ${context.logs}` : ""}`);
418
+ (dependencies.errorOutput ?? ((line) => process.stderr.write(`${line}\n`)))(`${[failure.component, failure.action].filter(Boolean).join(" ") || "octo-runtime"}: ${code}${failure.cause_code ? ` (${failure.cause_code})` : ""}\n${formatErrorDetails(failure)}${failure.logs ? `\nLogs: ${failure.logs}` : ""}`);
384
419
  return code === "EXTRA_COMMAND_CANCELLED"
385
420
  ? 130
386
421
  : ["SERVICE_NOT_INSTALLED", "NOT_INSTALLED"].includes(code)
@@ -2,11 +2,29 @@ import { join, resolve } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { mergeModuleManifests, readModuleManifest } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
4
4
  import { discoverGlobalExtras, mergeGlobalExtras } from "./global-extras.js";
5
+ import { withStartupContext } from "@mininglamp-oss/octo-runtime-executor-kernel";
5
6
  /** CLI 独占内置、Home 与全局 Extra 目录;SDK 不扫描,显式清单完全替换。 */
6
7
  export async function loadCliManifest(home, override, report = (message) => console.error(message)) {
8
+ const read = async (path, options) => {
9
+ try {
10
+ return await readModuleManifest(path, options);
11
+ }
12
+ catch (error) {
13
+ throw withStartupContext(error, {
14
+ component: "cli",
15
+ phase: "created",
16
+ context: {
17
+ path,
18
+ resource: "module-manifest",
19
+ operation: "read-manifest",
20
+ configKey: "manifest"
21
+ }
22
+ });
23
+ }
24
+ };
7
25
  if (override)
8
- return readModuleManifest(resolve(override), { legacy: true });
9
- const builtin = await readModuleManifest(fileURLToPath(new URL("./manifest.json", import.meta.url)));
10
- const extension = await readModuleManifest(join(home, "manifest.json"), { optional: true });
26
+ return read(resolve(override), { legacy: true });
27
+ const builtin = await read(fileURLToPath(new URL("./manifest.json", import.meta.url)));
28
+ const extension = await read(join(home, "manifest.json"), { optional: true });
11
29
  return mergeGlobalExtras(mergeModuleManifests(builtin, extension, report), await discoverGlobalExtras(report), report);
12
30
  }
@@ -1,19 +1,37 @@
1
1
  import type { ServiceStatus } from "@mininglamp-oss/octo-runtime-cross-service";
2
+ import { type StartupLocation } from "@mininglamp-oss/octo-runtime-executor-kernel";
2
3
  export interface ComponentSnapshot {
3
4
  service: ServiceStatus;
4
5
  runtime: unknown;
5
6
  }
7
+ export interface ResidentProcessView {
8
+ pid?: number;
9
+ owner_pid?: number;
10
+ roles: string[];
11
+ state: string;
12
+ observation: string;
13
+ service_id?: string;
14
+ incarnation?: number;
15
+ }
16
+ /** doctor 仅投影已取得的常驻快照;同 PID 合并角色,层级表示所有权而非猜测 OS PPID。 */
17
+ export declare function residentProcesses(snapshots: Record<string, ComponentSnapshot>): ResidentProcessView[];
18
+ export declare function formatResidentProcesses(processes: readonly ResidentProcessView[]): string;
6
19
  /** 展示公开状态的摘要,不为输出克隆完整 session/delivery 集合。JSON 模式保留原结果。 */
7
20
  export declare function formatStatus(name: string, snapshot: ComponentSnapshot): string;
8
21
  /** 只保留受控错误码和管理器元信息;异常正文及任意 stderr 可能含凭据,不能直出。 */
9
- export declare function describeError(error: unknown, fallback?: string): {
22
+ export declare function describeError(error: unknown, fallback?: string, startup?: StartupLocation): {
10
23
  backend?: import("@mininglamp-oss/octo-runtime-cross-service").ServiceBackendKind | undefined;
11
24
  command?: string | undefined;
12
25
  exit_code?: number | undefined;
26
+ cleanup?: import("@mininglamp-oss/octo-runtime-executor-kernel").ServiceCleanupResult | undefined;
27
+ startup?: import("@mininglamp-oss/octo-runtime-executor-kernel").StartupPathDiagnostic | undefined;
28
+ diagnostic?: import("@mininglamp-oss/octo-runtime-executor-kernel").StartupDiagnostic | undefined;
13
29
  cause_code?: string | undefined;
14
30
  code: string;
15
31
  message: string;
16
32
  };
33
+ /** 保留兼容 code/cause_code;共享启动结构决定动态解释与下一步。 */
34
+ export declare function formatErrorDetails(failure: ReturnType<typeof describeError>): string;
17
35
  /** 前台启动失败沿既有白名单和小时轮转落盘;不捕获任意进程 stdout/stderr。 */
18
36
  export declare function recordStartupFailure(directory: string, component: string, error: unknown): Promise<void>;
19
37
  /** 只读本次 start 后的白名单失败事件;每个轮转文件最多读取末尾 64 KiB。 */
@@ -1,13 +1,72 @@
1
1
  import { ServiceError } from "@mininglamp-oss/octo-runtime-cross-service";
2
2
  import { RuntimeLogging } from "@mininglamp-oss/octo-runtime-adapter-sdk";
3
- import { open, readdir } from "node:fs/promises";
3
+ import { describeStartupError, formatStartupDiagnostic, restoreStartupDiagnostic, safeStartupValue, startupPathDiagnostic, STARTUP_CATALOG } from "@mininglamp-oss/octo-runtime-executor-kernel";
4
+ import { constants } from "node:fs";
5
+ import { randomUUID } from "node:crypto";
6
+ import { open, readdir, mkdir, rename, rm, lstat } from "node:fs/promises";
4
7
  import { join } from "node:path";
8
+ /** doctor 仅投影已取得的常驻快照;同 PID 合并角色,层级表示所有权而非猜测 OS PPID。 */
9
+ export function residentProcesses(snapshots) {
10
+ const processes = [];
11
+ const pid = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : undefined;
12
+ const add = (entry) => {
13
+ const existing = entry.pid &&
14
+ processes.find((value) => value.pid === entry.pid &&
15
+ value.observation === "alive" &&
16
+ entry.observation === "alive" &&
17
+ value.owner_pid === entry.owner_pid &&
18
+ value.service_id === entry.service_id &&
19
+ value.incarnation === entry.incarnation);
20
+ if (existing)
21
+ existing.roles.push(...entry.roles.filter((role) => !existing.roles.includes(role)));
22
+ else
23
+ processes.push(entry);
24
+ };
25
+ for (const [name, snapshot] of Object.entries(snapshots)) {
26
+ const runtime = record(snapshot.runtime);
27
+ const actualPid = pid(runtime.pid);
28
+ const managedPid = pid(snapshot.service.pid);
29
+ add({
30
+ ...(actualPid || managedPid ? { pid: actualPid ?? managedPid } : {}),
31
+ roles: [name === "executor-kernel" ? "Host/Kernel" : `Extra:${name}`],
32
+ state: actualPid ? "running" : snapshot.service.state,
33
+ observation: actualPid ? "alive" : "unknown"
34
+ });
35
+ if (!Array.isArray(runtime.service_processes))
36
+ continue;
37
+ for (const value of runtime.service_processes.slice(0, 256)) {
38
+ const service = record(value);
39
+ add({
40
+ ...(pid(service.pid) ? { pid: pid(service.pid) } : {}),
41
+ owner_pid: pid(service.owner_pid),
42
+ roles: [`${text(service.provider)} app-server`],
43
+ state: text(service.state),
44
+ observation: text(service.observation),
45
+ service_id: text(service.service_id),
46
+ incarnation: typeof service.incarnation === "number" ? service.incarnation : undefined
47
+ });
48
+ }
49
+ }
50
+ return processes;
51
+ }
52
+ export function formatResidentProcesses(processes) {
53
+ const lines = ["Resident processes (ownership):"];
54
+ for (const entry of processes.filter((value) => !value.owner_pid)) {
55
+ lines.push(` ${entry.roles.join(", ")} PID ${entry.pid ?? "unknown"} ${entry.state} (${entry.observation})`);
56
+ for (const child of processes.filter((value) => entry.pid && value.owner_pid === entry.pid))
57
+ lines.push(` +-- ${child.roles.join(", ")} PID ${child.pid ?? "-"} ${child.state} (${child.observation}) incarnation ${child.incarnation ?? "-"} service ${child.service_id ?? "-"}`);
58
+ }
59
+ for (const entry of processes.filter((value) => value.owner_pid && !processes.some((parent) => parent.pid === value.owner_pid)))
60
+ lines.push(` ${entry.roles.join(", ")} PID ${entry.pid ?? "-"} ${entry.state} (${entry.observation}) owner PID ${entry.owner_pid}`);
61
+ return lines.join("\n");
62
+ }
5
63
  const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value)
6
64
  ? value
7
65
  : {};
8
66
  const text = (value) => String(value)
9
67
  .replace(/\p{Cc}/gu, " ")
10
68
  .slice(0, 200);
69
+ const stableCode = (value) => typeof value === "string" && /^[A-Z][A-Z0-9_]{1,100}$/.test(value) ? value : undefined;
11
70
  /** 展示公开状态的摘要,不为输出克隆完整 session/delivery 集合。JSON 模式保留原结果。 */
12
71
  export function formatStatus(name, snapshot) {
13
72
  const service = snapshot.service;
@@ -87,26 +146,36 @@ export function formatStatus(name, snapshot) {
87
146
  return lines.join("\n");
88
147
  }
89
148
  /** 只保留受控错误码和管理器元信息;异常正文及任意 stderr 可能含凭据,不能直出。 */
90
- export function describeError(error, fallback = "COMMAND_FAILED") {
91
- const stableCode = (value) => typeof value === "string" && /^[A-Z][A-Z0-9_]{1,100}$/.test(value) ? value : undefined;
92
- const value = record(error);
93
- const code = stableCode(value.code) ??
94
- (error instanceof Error ? stableCode(error.message) : undefined) ??
149
+ export function describeError(error, fallback = "COMMAND_FAILED", startup) {
150
+ const field = (value, key) => {
151
+ try {
152
+ return value !== null && typeof value === "object"
153
+ ? Object.getOwnPropertyDescriptor(value, key)?.value
154
+ : undefined;
155
+ }
156
+ catch {
157
+ return undefined;
158
+ }
159
+ };
160
+ const code = stableCode(field(error, "code")) ??
161
+ (error instanceof Error ? stableCode(field(error, "message")) : undefined) ??
95
162
  fallback;
96
- const cause = record(value.cause);
97
- const causeCode = stableCode(cause.code) ?? stableCode(cause.message);
163
+ const cause = field(error, "cause");
164
+ const causeCode = stableCode(field(cause, "code")) ?? stableCode(field(cause, "message"));
165
+ const projection = describeStartupError(error, startup);
166
+ const pathDiagnostic = startupPathDiagnostic(projection);
167
+ const diagnostic = startup ||
168
+ pathDiagnostic ||
169
+ field(field(error, "diagnostic"), "domain") === "startup" ||
170
+ projection.causes.some((cause) => cause.component && cause.phase)
171
+ ? projection
172
+ : undefined;
98
173
  const hints = {
99
174
  COMMAND_FAILED: "The command failed. Check the native manager, configuration and service logs.",
100
- ENOENT: "The component endpoint or required file does not exist. Check installation and service status.",
101
- ECONNREFUSED: "The component is not accepting IPC connections. Check its process and logs.",
102
175
  KERNEL_UNAVAILABLE: "Kernel is unavailable. Check executor-kernel status; Extras can remain running.",
103
176
  INVALID_ARGUMENTS: "Use --help to see the available commands and flags.",
104
- SETUP_IN_PROGRESS: "Another component lifecycle operation is in progress. Wait for it to finish, then retry.",
105
- 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.",
106
177
  ORPHAN_CLEANUP_OWNER_ALIVE: "The original Kernel or worker is still alive or its identity cannot be verified. Stop it safely before acknowledging cleanup.",
107
178
  ORPHAN_CLEANUP_NOT_PENDING: "There is no valid incomplete orphan cleanup to acknowledge. Run doctor with the same --home.",
108
- SERVICE_NOT_INSTALLED: "Run this component's install command, then start it.",
109
- NOT_INSTALLED: "Run this component's install command, then start it.",
110
179
  EXTRA_COMMAND_FAILED: "The Extra command failed. No private backend error is printed; check its input and configuration, then retry.",
111
180
  EXTRA_CONFIG_CONFLICT: "Configuration changed after this command read it. Read the latest configuration and retry.",
112
181
  EXTRA_COMMAND_LOAD_FAILED: "The selected Extra command module or one of its dependencies is broken. Check its package and commands export; lifecycle commands remain available.",
@@ -116,33 +185,75 @@ export function describeError(error, fallback = "COMMAND_FAILED") {
116
185
  EXTRA_COMMAND_NOT_FOUND: "Unknown command. Use --help on the service command to see available subcommands.",
117
186
  EXTRA_COMMAND_CANCELLED: "The command was cancelled. Any save that already completed remains persisted.",
118
187
  EXTRA_COMMAND_STDIN_REQUIRED: "Pipe the required input through stdin; do not put credentials in command arguments.",
119
- EXTRA_NOT_REGISTERED: "Save the service configuration using its configure or extraset subcommand before starting it.",
120
188
  EXTRA_MANIFEST_DECLARATION_REQUIRED: "Install this Extra alongside the global Runtime, or add its name and module to the selected Home manifest.json (extras array), then retry.",
121
- EXTRA_NAME_MISMATCH: "The selected Extra must export the same name as its catalog entry. Check the reported package origin.",
122
- EXTRA_MODULE_LOAD_FAILED: "Check the selected catalog declaration, discovery diagnostics, installation and ESM exports; reinstall it or select a valid Home manifest entry, then retry.",
123
- EXTRA_MODULE_MIGRATION_REQUIRED: "The saved module differs from manifest.json. Review both declarations, then save matching module text or omit module from the Extra configuration.",
124
- MANIFEST_INVALID: "Check manifest.json: version must be 1 and adapters/extras must be valid arrays without duplicate keys.",
125
- MANAGER_UNAVAILABLE: "Run doctor and check the current user's native service manager.",
126
- COMPONENT_UNAVAILABLE: "Check component status and the service logs; the IPC endpoint or execution service is not ready.",
127
- SERVICE_PROCESS_EXITED: "The service exited unexpectedly. Check its logs and configuration.",
128
- SERVICE_INITIALIZATION_FAILED: "Check the component configuration, manifest and service logs.",
129
- SERVICE_DISABLED: "Enable this component with install --autostart=true, then start it."
189
+ EXTRA_MODULE_MIGRATION_REQUIRED: "The saved module differs from manifest.json. Review both declarations, then save matching module text or omit module from the Extra configuration."
130
190
  };
131
191
  return {
132
192
  code,
133
- message: hints[code] ?? "Check --help, component status and service logs for this operation.",
193
+ message: diagnostic?.explanation ??
194
+ STARTUP_CATALOG[code]?.action ??
195
+ hints[code] ??
196
+ "Check --help, component status and service logs for this operation.",
134
197
  ...(causeCode ? { cause_code: causeCode } : {}),
198
+ ...(diagnostic ? { diagnostic } : {}),
199
+ ...(pathDiagnostic
200
+ ? { startup: pathDiagnostic, ...(diagnostic?.cleanup ? { cleanup: diagnostic.cleanup } : {}) }
201
+ : {}),
135
202
  ...(error instanceof ServiceError
136
- ? { backend: error.backend, command: error.command, exit_code: error.exitCode }
203
+ ? {
204
+ backend: error.backend,
205
+ command: typeof error.command === "string" ? safeStartupValue(error.command) : undefined,
206
+ exit_code: error.exitCode
207
+ }
137
208
  : {})
138
209
  };
139
210
  }
211
+ /** 保留兼容 code/cause_code;共享启动结构决定动态解释与下一步。 */
212
+ export function formatErrorDetails(failure) {
213
+ return failure.diagnostic ? formatStartupDiagnostic(failure.diagnostic) : failure.message;
214
+ }
140
215
  /** 前台启动失败沿既有白名单和小时轮转落盘;不捕获任意进程 stdout/stderr。 */
141
216
  export async function recordStartupFailure(directory, component, error) {
217
+ if (!/^[a-z][a-z0-9-]{0,63}$/.test(component))
218
+ return;
219
+ // Home 校验失败不得由诊断日志递归补建根目录(#306)。
220
+ if (startupPathDiagnostic(describeStartupError(error)))
221
+ return;
142
222
  const logging = new RuntimeLogging({ directory });
143
223
  try {
144
- const log = component === "executor-kernel" ? logging.kernel : logging.extra(component);
224
+ // 单份最近失败记录拥有独立有界文件;不放宽通用日志的配置/异常白名单。
225
+ const diagnostic = describeStartupError(error, { component, phase: "initializing" });
145
226
  const failure = describeError(error, "SERVICE_INITIALIZATION_FAILED");
227
+ const file = join(directory, `startup-${component}.json`);
228
+ const temporary = `${file}.${randomUUID()}.tmp`;
229
+ try {
230
+ const line = JSON.stringify({
231
+ schema_version: 1,
232
+ time: new Date().toISOString(),
233
+ component,
234
+ code: failure.code,
235
+ ...(failure.cause_code ? { cause_code: failure.cause_code } : {}),
236
+ diagnostic
237
+ });
238
+ if (Buffer.byteLength(line) <= 262144) {
239
+ await mkdir(directory, { recursive: true, mode: 0o700 });
240
+ const handle = await open(temporary, "wx", 0o600);
241
+ try {
242
+ await handle.writeFile(line);
243
+ }
244
+ finally {
245
+ await handle.close();
246
+ }
247
+ await rename(temporary, file);
248
+ }
249
+ }
250
+ catch {
251
+ // 诊断落盘失败不能覆盖原始启动/清理错误,调用方仍持有完整安全投影。
252
+ }
253
+ finally {
254
+ await rm(temporary, { force: true }).catch(() => undefined);
255
+ }
256
+ const log = component === "executor-kernel" ? logging.kernel : logging.extra(component);
146
257
  if (failure.cause_code)
147
258
  log("error", "cli.initialization_cause", { code: failure.cause_code });
148
259
  log("error", "cli.initialization_failed", { code: failure.code });
@@ -153,6 +264,47 @@ export async function recordStartupFailure(directory, component, error) {
153
264
  }
154
265
  /** 只读本次 start 后的白名单失败事件;每个轮转文件最多读取末尾 64 KiB。 */
155
266
  export async function readStartupFailure(directory, component, since) {
267
+ if (!/^[a-z][a-z0-9-]{0,63}$/.test(component))
268
+ return undefined;
269
+ try {
270
+ const file = await open(join(directory, `startup-${component}.json`), constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
271
+ try {
272
+ const stat = await file.stat();
273
+ if (!constants.O_NOFOLLOW) {
274
+ const entry = await lstat(join(directory, `startup-${component}.json`));
275
+ if (!entry.isFile() || entry.dev !== stat.dev || entry.ino !== stat.ino)
276
+ return undefined;
277
+ }
278
+ if (stat.isFile() && stat.size <= 262144) {
279
+ const bytes = Buffer.alloc(262145);
280
+ let length = 0;
281
+ while (length < bytes.length) {
282
+ const { bytesRead } = await file.read(bytes, length, bytes.length - length, null);
283
+ if (!bytesRead)
284
+ break;
285
+ length += bytesRead;
286
+ }
287
+ if (length > 262144)
288
+ return undefined;
289
+ const row = record(JSON.parse(bytes.subarray(0, length).toString("utf8")));
290
+ if (row.schema_version === 1 &&
291
+ row.component === component &&
292
+ typeof row.time === "string" &&
293
+ Date.parse(row.time) >= since) {
294
+ const diagnostic = restoreStartupDiagnostic(row.diagnostic);
295
+ const code = stableCode(row.code), causeCode = stableCode(row.cause_code);
296
+ if (diagnostic && code)
297
+ return Object.assign(new Error(code, causeCode ? { cause: new Error(causeCode) } : undefined), { diagnostic });
298
+ }
299
+ }
300
+ }
301
+ finally {
302
+ await file.close();
303
+ }
304
+ }
305
+ catch {
306
+ // 缺失、损坏或旧版本记录继续走既有白名单日志,不影响真实就绪等待。
307
+ }
156
308
  const root = component === "executor-kernel" ? directory : join(directory, "extras");
157
309
  const prefix = component === "executor-kernel" ? "kernel-" : `${component}-`;
158
310
  try {
@@ -2,7 +2,6 @@ import { loadCliAdapters } from "./adapters.js";
2
2
  import { defaultRuntimeHome, runtimePaths, readJsonFile } from "./state.js";
3
3
  import { loadCliManifest } from "./module-manifest.js";
4
4
  import { readCliAdapterConfigurations } from "./adapter-configurations.js";
5
- import { resolveAdapterModules } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
6
5
  import { createKernelService } from "@mininglamp-oss/octo-runtime-executor-kernel";
7
6
  import { componentEndpoint } from "@mininglamp-oss/octo-runtime-host-sdk";
8
7
  import { mkdtemp, rm } from "node:fs/promises";
@@ -89,8 +88,9 @@ export async function runPlayboard(options) {
89
88
  const manifest = await loadCliManifest(home, options.manifest);
90
89
  const configuration = await readJsonFile(paths.profileConfig);
91
90
  kernel = createKernelService({
91
+ home: temporary,
92
92
  endpoint: process.platform === "win32" ? componentEndpoint(temporary) : join(temporary, "k.sock"),
93
- adapters: await loadCliAdapters(resolveAdapterModules(manifest), {
93
+ adapters: await loadCliAdapters(manifest.adapters, {
94
94
  profileRoot: paths.profileRoot,
95
95
  syncOpenClawTools: false
96
96
  }),
@@ -49,10 +49,13 @@ export interface RuntimePaths {
49
49
  openclawRoot: string;
50
50
  setupLock: string;
51
51
  pid: string;
52
- socket: string;
53
52
  logs: string;
54
53
  }
55
- export declare function defaultRuntimeHome(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string;
54
+ export declare function defaultRuntimeHome(env?: NodeJS.ProcessEnv): string;
55
+ /** CLI 明确接受相对 --home 并转为绝对路径;不展开 ~,空值必须失败。 */
56
+ export declare function selectRuntimeHome(input: string | undefined, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string;
57
+ /** 根目录只由 CLI 准备;先检查完整预算,创建失败保留原 path/errno,不换根。 */
58
+ export declare function prepareRuntimeHome(home: string): Promise<void>;
56
59
  export declare function runtimePaths(home: string, profile: string, platform?: NodeJS.Platform): RuntimePaths;
57
60
  /** Call under the Home setup lock; this label is shared by all profiles, not an authentication key. */
58
61
  export declare function ensureMachineIdentity(paths: RuntimePaths): Promise<MachineIdentity>;