@mininglamp-oss/octo-runtime 1.1.3 → 1.1.5

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 (214) hide show
  1. package/README.md +62 -38
  2. package/apps/cli/README.md +58 -22
  3. package/apps/cli/dist/build-info.json +2 -2
  4. package/apps/cli/dist/cli-entrypoint.d.ts +2 -0
  5. package/apps/cli/dist/cli-entrypoint.js +16 -0
  6. package/apps/cli/dist/command-tree.d.ts +20 -0
  7. package/apps/cli/dist/command-tree.js +402 -0
  8. package/apps/cli/dist/extra-command-config.d.ts +4 -0
  9. package/apps/cli/dist/extra-command-config.js +50 -0
  10. package/apps/cli/dist/extra-commands.d.ts +15 -0
  11. package/apps/cli/dist/extra-commands.js +275 -0
  12. package/apps/cli/dist/extras.js +14 -2
  13. package/apps/cli/dist/global-extras.d.ts +16 -0
  14. package/apps/cli/dist/global-extras.js +201 -0
  15. package/apps/cli/dist/help.d.ts +4 -1
  16. package/apps/cli/dist/help.js +31 -75
  17. package/apps/cli/dist/main.d.ts +2 -0
  18. package/apps/cli/dist/main.js +53 -63
  19. package/apps/cli/dist/manifest.json +53 -3
  20. package/apps/cli/dist/module-manifest.d.ts +1 -1
  21. package/apps/cli/dist/module-manifest.js +3 -2
  22. package/apps/cli/dist/openclaw.js +32 -8
  23. package/apps/cli/dist/output.js +16 -2
  24. package/apps/cli/dist/playboard.d.ts +5 -0
  25. package/apps/cli/dist/playboard.js +41 -13
  26. package/apps/cli/dist/service-control.js +2 -2
  27. package/apps/cli/dist/state.js +48 -19
  28. package/dist/public/channel-gateway-commands.d.ts +1 -0
  29. package/dist/public/channel-gateway-commands.js +1 -0
  30. package/dist/public/channel-wecom-commands.d.ts +1 -0
  31. package/dist/public/channel-wecom-commands.js +1 -0
  32. package/dist/public/dsh.d.ts +2 -0
  33. package/dist/public/dsh.js +1 -0
  34. package/dist/public/executor-kernel.d.ts +1 -1
  35. package/dist/public/executor-kernel.js +1 -1
  36. package/dist/public/extra.d.ts +1 -0
  37. package/dist/public/extra.js +1 -0
  38. package/dist/public/host.d.ts +2 -4
  39. package/dist/public/host.js +1 -2
  40. package/dist/public/webui-commands.d.ts +1 -0
  41. package/dist/public/webui-commands.js +1 -0
  42. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +2 -2
  43. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +4 -0
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +26 -2
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +3 -3
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-DYOJCNWF.js +854 -0
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-G5PWGRL5.js +209 -0
  54. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-UOQRXV3Q.js +340 -0
  55. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.d.ts +1 -0
  56. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.js +16 -0
  57. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +6 -0
  58. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-client-LICENSE.txt +21 -0
  59. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-protocol-LICENSE.txt +21 -0
  60. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +35 -0
  61. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +14 -0
  62. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +52 -0
  63. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +306 -0
  64. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +11 -0
  65. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +13 -0
  66. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.d.ts +12 -0
  67. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +7 -0
  68. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +15 -0
  69. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +2 -1
  70. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  71. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  72. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  73. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  74. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  75. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +10 -5
  76. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +214 -55
  77. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  78. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  79. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  80. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +3 -0
  81. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.d.ts +4 -0
  82. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +24 -2
  83. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/hourly-log.js +11 -3
  84. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +12 -3
  85. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +30 -8
  86. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +4 -3
  87. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.d.ts +6 -0
  88. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.js +16 -4
  89. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +15 -2
  90. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +29 -1
  91. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  92. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +5 -5
  93. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  94. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  95. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.d.ts +2 -0
  96. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.js +16 -0
  97. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.d.ts +20 -0
  98. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +402 -0
  99. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.d.ts +4 -0
  100. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.js +50 -0
  101. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.d.ts +15 -0
  102. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.js +275 -0
  103. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +14 -2
  104. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.d.ts +16 -0
  105. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.js +201 -0
  106. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.d.ts +4 -1
  107. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +31 -75
  108. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +2 -0
  109. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +53 -63
  110. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +53 -3
  111. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.d.ts +1 -1
  112. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +3 -2
  113. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +32 -8
  114. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +16 -2
  115. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +5 -0
  116. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +41 -13
  117. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/service-control.js +2 -2
  118. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -19
  119. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +25 -23
  120. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.d.ts +2 -2
  121. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.js +16 -6
  122. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/systemd.js +9 -7
  123. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.d.ts +4 -1
  124. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +36 -11
  125. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  126. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -2
  127. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  128. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +2 -1
  129. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +2 -1
  130. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -1
  131. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +16 -1
  132. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +152 -21
  133. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +9 -2
  134. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +8 -0
  135. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +17 -0
  136. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
  137. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +56 -0
  138. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +170 -28
  139. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +3 -1
  140. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.d.ts +4 -0
  141. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.js +124 -0
  142. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +19 -1
  143. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +23 -0
  144. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +43 -0
  145. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +15 -0
  146. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +283 -0
  147. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +2 -0
  148. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +15 -1
  149. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts +5 -1
  150. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +48 -13
  151. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.d.ts +1 -1
  152. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.js +5 -3
  153. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +26 -1
  154. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +2 -1
  155. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +1 -0
  156. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +3 -2
  157. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +3 -2
  158. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +4 -0
  159. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +104 -3
  160. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/rules.js +4 -3
  161. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.d.ts +2 -0
  162. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.js +7 -0
  163. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.d.ts +1 -1
  164. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +4 -3
  165. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +9 -0
  166. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +44 -13
  167. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.d.ts +7 -0
  168. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.js +44 -3
  169. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/image-input.js +2 -1
  170. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +7 -0
  171. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +18 -12
  172. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +10 -6
  173. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +141 -16
  174. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/session-store.d.ts +3 -1
  175. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.d.ts +4 -0
  176. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.js +128 -0
  177. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +9 -5
  178. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.d.ts +3 -0
  179. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.js +51 -0
  180. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-CXTvRGim.js +74 -0
  181. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
  182. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +7 -3
  183. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.d.ts +70 -0
  184. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.js +16 -0
  185. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +33 -9
  186. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +9 -4
  187. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +1 -3
  188. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +1 -2
  189. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +8 -4
  190. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +5 -0
  191. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +39 -1
  192. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +76 -7
  193. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  194. package/node_modules/commander/LICENSE +22 -0
  195. package/node_modules/commander/Readme.md +1172 -0
  196. package/node_modules/commander/index.js +21 -0
  197. package/node_modules/commander/lib/argument.js +147 -0
  198. package/node_modules/commander/lib/command.js +2790 -0
  199. package/node_modules/commander/lib/error.js +36 -0
  200. package/node_modules/commander/lib/help.js +731 -0
  201. package/node_modules/commander/lib/option.js +377 -0
  202. package/node_modules/commander/lib/suggestSimilar.js +99 -0
  203. package/node_modules/commander/package-support.json +19 -0
  204. package/node_modules/commander/package.json +64 -0
  205. package/node_modules/commander/typings/index.d.ts +1113 -0
  206. package/package.json +49 -29
  207. package/packages/octo-runtime-extra-channel-gateway/config-schema.json +56 -0
  208. package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +443 -56
  209. package/packages/octo-runtime-protocol/schema/protocol.schema.json +357 -37
  210. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-DiPc-ipL.js +0 -74
  211. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.d.ts +0 -15
  212. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.js +0 -22
  213. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.d.ts +0 -16
  214. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.js +0 -160
@@ -0,0 +1,50 @@
1
+ import { createHash } from "node:crypto";
2
+ import { join } from "node:path";
3
+ import { assertStoredExtra, readStoredExtra } from "@mininglamp-oss/octo-runtime-host-sdk";
4
+ import { withSetupLock, writeJsonAtomic } from "./state.js";
5
+ /** 与 extraset 共用 Home 锁和原子写入;网络/交互发生在调用方,不能占用写锁。 */
6
+ export function commandConfig(paths, name, module, signal) {
7
+ const read = async () => {
8
+ try {
9
+ const stored = await readStoredExtra(join(paths.home, "extras"), name);
10
+ if (stored.module !== undefined && stored.module !== module)
11
+ throw new Error("EXTRA_MODULE_MIGRATION_REQUIRED");
12
+ return stored;
13
+ }
14
+ catch (error) {
15
+ if (error.code === "ENOENT")
16
+ return undefined;
17
+ throw error;
18
+ }
19
+ };
20
+ const revision = (stored) => createHash("sha256")
21
+ .update(JSON.stringify(stored ?? null))
22
+ .digest("hex");
23
+ return {
24
+ async readConfig() {
25
+ signal.throwIfAborted();
26
+ const stored = await read();
27
+ return { config: stored?.config ?? {}, revision: revision(stored) };
28
+ },
29
+ async saveConfig(config, expected) {
30
+ signal.throwIfAborted();
31
+ // 先复制并校验,异步获取锁期间插件不能改变待保存值。
32
+ assertStoredExtra({ config });
33
+ const copy = JSON.parse(JSON.stringify(config));
34
+ return withSetupLock(paths, async () => {
35
+ signal.throwIfAborted();
36
+ const stored = await read();
37
+ if (revision(stored) !== expected)
38
+ throw new Error("EXTRA_CONFIG_CONFLICT");
39
+ const next = { ...stored, config: copy };
40
+ if (Buffer.byteLength(JSON.stringify(next, null, 2) + "\n") > 1024 * 1024)
41
+ throw new Error("EXTRA_CONFIG_TOO_LARGE");
42
+ signal.throwIfAborted();
43
+ const file = join(paths.home, "extras", name, "config.json");
44
+ // 原子写入开始后以写入结果为准;不在 rename 后因取消误报未保存。
45
+ await writeJsonAtomic(file, next);
46
+ return { saved: true, name, file, reload_required: true };
47
+ });
48
+ }
49
+ };
50
+ }
@@ -0,0 +1,15 @@
1
+ import { type ExtraCommandExtension } from "@mininglamp-oss/octo-runtime-host-sdk";
2
+ import { type ExtraModuleEntry } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
3
+ import type { ParsedCliCommand } from "./command-tree.js";
4
+ import type { CliDependencies } from "./main.js";
5
+ /** 仅执行已解析的自有命令;CLI 持有 IO、取消与配置锁,业务 handler 不管理宿主服务。 */
6
+ export declare function runExtraCommand(parsed: ParsedCliCommand, dependencies: CliDependencies): Promise<number>;
7
+ /** 仅解析选中模块的可选导出;解析不存在与导入后依赖损坏严格分开。 */
8
+ export declare function loadExtraCommands(entry: ExtraModuleEntry): Promise<ExtraCommandExtension | undefined>;
9
+ export declare function validateCommands(extension: ExtraCommandExtension): void;
10
+ /** 只允许插件显式构造的安全诊断进入文本输出;任意异常仍沿宿主白名单处理。 */
11
+ export declare function commandError(error: unknown): {
12
+ code: string;
13
+ message: string;
14
+ cause_code?: string;
15
+ } | undefined;
@@ -0,0 +1,275 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
3
+ import { describeError } from "./output.js";
4
+ import { dirname, isAbsolute, join } from "node:path";
5
+ import { createInterface } from "node:readline/promises";
6
+ import { ExtraCommandError } from "@mininglamp-oss/octo-runtime-host-sdk";
7
+ import { resolveModuleSpecifier } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
8
+ import { commandConfig } from "./extra-command-config.js";
9
+ import { runtimePaths } from "./state.js";
10
+ import { resolveExtraModule } from "./global-extras.js";
11
+ import { lifecycleCommands } from "./help.js";
12
+ const reservedOptions = new Set([
13
+ "home",
14
+ "manifest",
15
+ "profile",
16
+ "json",
17
+ "help",
18
+ "version",
19
+ "autostart",
20
+ "lines",
21
+ "follow",
22
+ "acknowledge-orphan-cleanup"
23
+ ]);
24
+ const validName = /^[a-z][a-z0-9-]{0,63}$/;
25
+ const validOptionName = /^[a-z][a-z0-9_-]{0,63}$/;
26
+ /** 仅执行已解析的自有命令;CLI 持有 IO、取消与配置锁,业务 handler 不管理宿主服务。 */
27
+ export async function runExtraCommand(parsed, dependencies) {
28
+ const { entry, command, input: commandInput, home: commandHome } = parsed.extra;
29
+ const { flags } = parsed;
30
+ const name = entry.name;
31
+ const output = dependencies.output ??
32
+ ((line) => {
33
+ process.stdout.write(`${line}\n`);
34
+ });
35
+ const controller = new AbortController();
36
+ const cancel = () => controller.abort();
37
+ const externalCancel = () => controller.abort();
38
+ process.once("SIGINT", cancel);
39
+ process.once("SIGTERM", cancel);
40
+ dependencies.commandSignal?.addEventListener("abort", externalCancel, { once: true });
41
+ if (dependencies.commandSignal?.aborted)
42
+ controller.abort();
43
+ const input = dependencies.input ?? process.stdin;
44
+ let stdinRead = false;
45
+ const context = {
46
+ name,
47
+ home: commandHome,
48
+ signal: controller.signal,
49
+ interactive: Boolean(input.isTTY),
50
+ ...commandConfig(runtimePaths(commandHome, "default", dependencies.platform), name, entry.module, controller.signal),
51
+ output,
52
+ async readStdin() {
53
+ if (stdinRead || input.isTTY)
54
+ throw new Error("EXTRA_COMMAND_STDIN_REQUIRED");
55
+ stdinRead = true;
56
+ return readInput(input, controller.signal);
57
+ },
58
+ async prompt(question) {
59
+ if (!input.isTTY)
60
+ throw new Error("EXTRA_COMMAND_INTERACTIVE_REQUIRED");
61
+ const terminal = createInterface({ input, output: process.stderr });
62
+ try {
63
+ return await terminal.question(question, { signal: controller.signal });
64
+ }
65
+ finally {
66
+ terminal.close();
67
+ }
68
+ }
69
+ };
70
+ try {
71
+ controller.signal.throwIfAborted();
72
+ const result = await command.run(context, commandInput);
73
+ if (result?.exitCode !== undefined &&
74
+ (!Number.isInteger(result.exitCode) || result.exitCode < 0 || result.exitCode > 255))
75
+ throw new Error("EXTRA_COMMAND_RESULT_INVALID");
76
+ if (result?.message !== undefined && typeof result.message !== "string")
77
+ throw new Error("EXTRA_COMMAND_RESULT_INVALID");
78
+ if (!flags.json && result?.message !== undefined)
79
+ output(result.message);
80
+ else if (result?.value !== undefined)
81
+ output(JSON.stringify(result.value, null, 2));
82
+ return result?.exitCode ?? 0;
83
+ }
84
+ catch (error) {
85
+ if (controller.signal.aborted)
86
+ throw new Error("EXTRA_COMMAND_CANCELLED", { cause: error });
87
+ // 第三方异常可能直接包含凭据;只透出显式安全诊断和宿主固定错误集合。
88
+ if (error instanceof ExtraCommandError)
89
+ throw error;
90
+ const safe = new Set([
91
+ "EXTRA_CONFIG_CONFLICT",
92
+ "EXTRA_CONFIG_TOO_LARGE",
93
+ "EXTRA_CONFIG_OBJECT_REQUIRED",
94
+ "EXTRA_CONFIG_JSON_REQUIRED",
95
+ "EXTRA_CONFIG_FIELD_INVALID",
96
+ "EXTRA_CONFIG_PERMISSIONS_INVALID",
97
+ "EXTRA_CONFIG_FILE_INVALID",
98
+ "EXTRA_MODULE_MIGRATION_REQUIRED",
99
+ "SETUP_IN_PROGRESS",
100
+ "EXTRA_COMMAND_STDIN_REQUIRED",
101
+ "EXTRA_COMMAND_STDIN_CLOSED",
102
+ "EXTRA_COMMAND_INTERACTIVE_REQUIRED",
103
+ "EXTRA_COMMAND_RESULT_INVALID"
104
+ ]);
105
+ if (error instanceof Error && safe.has(error.message))
106
+ throw new Error(error.message, { cause: error });
107
+ throw new Error("EXTRA_COMMAND_FAILED", { cause: error });
108
+ }
109
+ finally {
110
+ process.removeListener("SIGINT", cancel);
111
+ process.removeListener("SIGTERM", cancel);
112
+ dependencies.commandSignal?.removeEventListener("abort", externalCancel);
113
+ }
114
+ }
115
+ /** 仅解析选中模块的可选导出;解析不存在与导入后依赖损坏严格分开。 */
116
+ export async function loadExtraCommands(entry) {
117
+ let specifier;
118
+ if (entry.commands)
119
+ specifier = resolveModuleSpecifier(entry.commands, entry.sourceManifest);
120
+ else {
121
+ if (entry.module.startsWith(".") ||
122
+ isAbsolute(entry.module) ||
123
+ /^[a-z][a-z0-9+.-]*:/i.test(entry.module))
124
+ return undefined;
125
+ try {
126
+ if (!(await declaresExports(entry)))
127
+ return undefined;
128
+ specifier = resolveModuleSpecifier(`${entry.module}/commands`, entry.sourceManifest);
129
+ }
130
+ catch (error) {
131
+ if (error.code === "ERR_PACKAGE_PATH_NOT_EXPORTED")
132
+ return undefined;
133
+ throw new Error("EXTRA_COMMAND_LOAD_FAILED", { cause: error });
134
+ }
135
+ }
136
+ try {
137
+ const module = (await import(specifier));
138
+ if (!module.default || module.default.apiVersion !== 1)
139
+ throw new Error("EXTRA_COMMAND_API_UNSUPPORTED");
140
+ return module.default;
141
+ }
142
+ catch (error) {
143
+ if (error instanceof Error && error.message === "EXTRA_COMMAND_API_UNSUPPORTED")
144
+ throw error;
145
+ throw new Error("EXTRA_COMMAND_LOAD_FAILED", { cause: error });
146
+ }
147
+ }
148
+ /** 从选中服务的真实位置查所属包元数据;旧包未声明 exports 就没有可选命令入口。 */
149
+ async function declaresExports(entry) {
150
+ // 全局来源复用服务的安装身份检查;包被移除或替换后不能回退到祖先同名包。
151
+ // 这里只解析服务地址用于查元数据,不 import 或启动服务。
152
+ const service = await resolveExtraModule(entry);
153
+ const parts = entry.module.split("/");
154
+ const packageName = entry.module.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
155
+ let directory = dirname(fileURLToPath(service));
156
+ while (true) {
157
+ try {
158
+ const value = JSON.parse(await readFile(join(directory, "package.json"), "utf8"));
159
+ if (value && typeof value === "object" && "name" in value && value.name === packageName)
160
+ return "exports" in value && value.exports !== null;
161
+ }
162
+ catch (error) {
163
+ if (error.code !== "ENOENT")
164
+ throw error;
165
+ }
166
+ const parent = dirname(directory);
167
+ if (parent === directory)
168
+ throw new Error("EXTRA_COMMAND_LOAD_FAILED");
169
+ directory = parent;
170
+ }
171
+ }
172
+ function isCommandArray(value) {
173
+ return Array.isArray(value);
174
+ }
175
+ export function validateCommands(extension) {
176
+ let count = 0;
177
+ const walk = (commands, depth) => {
178
+ if (!isCommandArray(commands) || depth > 8 || commands.length === 0)
179
+ throw new Error("EXTRA_COMMAND_DEFINITION_INVALID");
180
+ const names = new Set();
181
+ for (const command of commands) {
182
+ if (++count > 128 ||
183
+ !command ||
184
+ !validName.test(command.name) ||
185
+ names.has(command.name) ||
186
+ lifecycleCommands.has(command.name) ||
187
+ !command.description ||
188
+ typeof command.description !== "string")
189
+ throw new Error("EXTRA_COMMAND_DEFINITION_INVALID");
190
+ names.add(command.name);
191
+ if (Boolean(command.commands) === Boolean(command.run) ||
192
+ (command.run !== undefined && typeof command.run !== "function"))
193
+ throw new Error("EXTRA_COMMAND_DEFINITION_INVALID");
194
+ const options = new Set();
195
+ if (command.options !== undefined && !isCommandArray(command.options))
196
+ throw new Error("EXTRA_COMMAND_DEFINITION_INVALID");
197
+ for (const option of command.options ?? []) {
198
+ if (!option ||
199
+ !validOptionName.test(option.name) ||
200
+ options.has(option.name) ||
201
+ reservedOptions.has(option.name) ||
202
+ !["string", "boolean"].includes(option.type) ||
203
+ typeof option.description !== "string")
204
+ throw new Error("EXTRA_COMMAND_DEFINITION_INVALID");
205
+ options.add(option.name);
206
+ }
207
+ if (command.arguments !== undefined &&
208
+ (!Array.isArray(command.arguments) ||
209
+ command.arguments.some((arg) => !arg || !validName.test(arg.name))))
210
+ throw new Error("EXTRA_COMMAND_DEFINITION_INVALID");
211
+ if (command.examples !== undefined &&
212
+ (!Array.isArray(command.examples) ||
213
+ command.examples.some((example) => typeof example !== "string")))
214
+ throw new Error("EXTRA_COMMAND_DEFINITION_INVALID");
215
+ if (command.commands) {
216
+ if (command.options?.length || command.arguments?.length)
217
+ throw new Error("EXTRA_COMMAND_DEFINITION_INVALID");
218
+ walk(command.commands, depth + 1);
219
+ }
220
+ }
221
+ };
222
+ walk(extension.commands, 0);
223
+ }
224
+ /** 有界 stdin 读取;取消解除监听且不等待对端 EOF,不接管调用方 stream 的生命周期。 */
225
+ function readInput(input, signal) {
226
+ return new Promise((accept, reject) => {
227
+ const chunks = [];
228
+ let size = 0;
229
+ const cleanup = () => {
230
+ input.removeListener("data", data);
231
+ input.removeListener("end", end);
232
+ input.removeListener("error", fail);
233
+ input.removeListener("close", closed);
234
+ signal.removeEventListener("abort", abort);
235
+ input.pause();
236
+ };
237
+ const fail = (error) => {
238
+ cleanup();
239
+ reject(error);
240
+ };
241
+ const abort = () => fail(new Error("EXTRA_COMMAND_CANCELLED"));
242
+ const data = (chunk) => {
243
+ const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
244
+ size += bytes.length;
245
+ if (size > 1024 * 1024)
246
+ fail(new Error("EXTRA_CONFIG_TOO_LARGE"));
247
+ else
248
+ chunks.push(bytes);
249
+ };
250
+ const end = () => {
251
+ cleanup();
252
+ accept(Buffer.concat(chunks).toString("utf8"));
253
+ };
254
+ const closed = () => fail(new Error("EXTRA_COMMAND_STDIN_CLOSED"));
255
+ input.on("data", data);
256
+ input.once("end", end);
257
+ input.once("error", fail);
258
+ input.once("close", closed);
259
+ signal.addEventListener("abort", abort, { once: true });
260
+ if (signal.aborted)
261
+ abort();
262
+ else if (input.readableEnded)
263
+ end();
264
+ });
265
+ }
266
+ /** 只允许插件显式构造的安全诊断进入文本输出;任意异常仍沿宿主白名单处理。 */
267
+ export function commandError(error) {
268
+ if (error instanceof Error && /^EXTRA_COMMAND_[A-Z_]+$/.test(error.message)) {
269
+ const failure = describeError(error);
270
+ return { code: failure.code, message: failure.message };
271
+ }
272
+ if (error instanceof ExtraCommandError && /^[A-Z][A-Z0-9_]{1,100}$/.test(error.code))
273
+ return { code: error.code, message: error.message };
274
+ return undefined;
275
+ }
@@ -1,7 +1,7 @@
1
1
  import { join } from "node:path";
2
+ import { resolveExtraModule } from "./global-extras.js";
2
3
  import { assertExtraName, assertStoredExtra, readStoredExtra } from "@mininglamp-oss/octo-runtime-host-sdk";
3
4
  import { withSetupLock, writeJsonAtomic } from "./state.js";
4
- import { resolveModuleSpecifier } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
5
5
  /** Generic full replacement: no platform-specific CLI fields or validation. */
6
6
  export async function setExtra(paths, name, input) {
7
7
  assertExtraName(name);
@@ -44,7 +44,19 @@ export async function readExtra(paths, name, manifest) {
44
44
  module: entry.module,
45
45
  config: stored.config,
46
46
  enabled: stored.enabled,
47
- load: () => import(resolveModuleSpecifier(entry.module, entry.sourceManifest))
47
+ load: async () => {
48
+ try {
49
+ const plugin = (await import(await resolveExtraModule(entry)));
50
+ if (plugin.name !== name)
51
+ throw new Error("EXTRA_NAME_MISMATCH");
52
+ return plugin;
53
+ }
54
+ catch (error) {
55
+ if (error instanceof Error && error.message === "EXTRA_NAME_MISMATCH")
56
+ throw error;
57
+ throw new Error("EXTRA_MODULE_LOAD_FAILED", { cause: error });
58
+ }
59
+ }
48
60
  };
49
61
  }
50
62
  export async function getExtra(paths, name) {
@@ -0,0 +1,16 @@
1
+ import { type ExtraModuleEntry, type ModuleManifest } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
2
+ type Report = (message: string) => void;
3
+ interface Installation {
4
+ kind: "npm" | "pnpm" | "pnpm-isolated";
5
+ root: string;
6
+ modules: string;
7
+ }
8
+ /** 纯路径分类不证明安装身份;调用方还须核对包名、全局 bin 或有效安装组。 */
9
+ export declare function installationLayout(entry: string, platform?: NodeJS.Platform): Installation | undefined;
10
+ /** 每次只读当前 CLI 对应环境的顶层包元数据;不可用的可选目录不阻止 Kernel/manifest 使用。 */
11
+ export declare function discoverGlobalExtras(report: Report, entry?: string): Promise<ExtraModuleEntry[]>;
12
+ /** 两份清单已完成自身校验;全局候选排序后按逻辑名补缺,决胜之前不解析 exports。 */
13
+ export declare function mergeGlobalExtras(manifest: ModuleManifest, candidates: ExtraModuleEntry[], report: Report): ModuleManifest;
14
+ /** 仅在启用的 Extra 真正加载时解析入口;移除/替换后拒绝沿祖先目录加载另一份同名包。 */
15
+ export declare function resolveExtraModule(entry: ExtraModuleEntry): Promise<string>;
16
+ export {};
@@ -0,0 +1,201 @@
1
+ import { readFile, readdir, realpath } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { assertExtraName } from "@mininglamp-oss/octo-runtime-host-sdk";
4
+ import { resolveModuleSpecifier } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
5
+ import { cliEntrypoint } from "./cli-entrypoint.js";
6
+ const runtimePackage = "@mininglamp-oss/octo-runtime";
7
+ /** 纯路径分类不证明安装身份;调用方还须核对包名、全局 bin 或有效安装组。 */
8
+ export function installationLayout(entry, platform = process.platform) {
9
+ const p = platform === "win32" ? path.win32 : path.posix;
10
+ const suffix = p.join("node_modules", "@mininglamp-oss", "octo-runtime", "apps", "cli", "dist", "index.js");
11
+ if (!entry.endsWith(p.sep + suffix))
12
+ return;
13
+ const modules = entry.slice(0, -p.join("@mininglamp-oss", "octo-runtime", "apps", "cli", "dist", "index.js").length - 1);
14
+ const parent = p.dirname(modules);
15
+ if (p.basename(p.dirname(parent)) === "v11")
16
+ return { kind: "pnpm-isolated", root: p.dirname(parent), modules };
17
+ if (p.basename(parent) === "5")
18
+ return { kind: "pnpm", root: parent, modules };
19
+ if (platform === "win32")
20
+ return { kind: "npm", root: parent, modules };
21
+ if (p.basename(parent) === "lib")
22
+ return { kind: "npm", root: p.dirname(parent), modules };
23
+ }
24
+ function errorCode(error) {
25
+ return error?.code ?? "INVALID_METADATA";
26
+ }
27
+ async function metadata(file) {
28
+ const value = JSON.parse(await readFile(file, "utf8"));
29
+ if (!value || typeof value !== "object" || Array.isArray(value))
30
+ throw new Error("INVALID_METADATA");
31
+ return value;
32
+ }
33
+ async function entries(directory, report) {
34
+ try {
35
+ return await readdir(directory, { withFileTypes: true });
36
+ }
37
+ catch (error) {
38
+ report(`Global Extra discovery cannot read ${JSON.stringify(directory)} (${errorCode(error)}); manifests remain available.`);
39
+ return [];
40
+ }
41
+ }
42
+ async function installationRoots(entry, report) {
43
+ let actual;
44
+ try {
45
+ actual = await realpath(entry);
46
+ }
47
+ catch (error) {
48
+ report(`Global Extra discovery cannot locate CLI ${JSON.stringify(entry)} (${errorCode(error)}); use a Home manifest.`);
49
+ return [];
50
+ }
51
+ // pnpm argv 保留组内链接,realpath 则可能已进入共享 store;不能从共享 store 反查其他环境。
52
+ for (const candidate of new Set([path.resolve(entry), actual])) {
53
+ const layout = installationLayout(candidate);
54
+ if (!layout)
55
+ continue;
56
+ try {
57
+ const runtime = path.join(layout.modules, runtimePackage);
58
+ if ((await metadata(path.join(runtime, "package.json"))).name !== runtimePackage)
59
+ continue;
60
+ if ((await realpath(path.join(runtime, "apps/cli/dist/index.js"))) !== actual)
61
+ continue;
62
+ if (layout.kind === "pnpm-isolated") {
63
+ const roots = [];
64
+ let ownsRuntime = false;
65
+ const group = await realpath(path.dirname(layout.modules));
66
+ for (const item of await entries(layout.root, report)) {
67
+ // 只接受活动索引链接;pnpm 保留的旧 target 目录不是已安装包。
68
+ if (!item.isSymbolicLink())
69
+ continue;
70
+ const install = path.join(layout.root, item.name);
71
+ try {
72
+ const target = await realpath(install);
73
+ const data = await metadata(path.join(install, "package.json"));
74
+ if (!data.dependencies || typeof data.dependencies !== "object")
75
+ continue;
76
+ roots.push({
77
+ directory: path.join(install, "node_modules"),
78
+ directPackages: new Set(Object.keys(data.dependencies))
79
+ });
80
+ if (target === group && Object.hasOwn(data.dependencies, runtimePackage))
81
+ ownsRuntime = true;
82
+ }
83
+ catch (error) {
84
+ report(`Ignoring global install ${JSON.stringify(install)} (${errorCode(error)}).`);
85
+ }
86
+ }
87
+ if (ownsRuntime)
88
+ return roots.sort((a, b) => compare(a.directory, b.directory));
89
+ }
90
+ else if (layout.kind === "pnpm") {
91
+ const data = await metadata(path.join(layout.root, "package.json"));
92
+ await readFile(path.join(layout.modules, ".modules.yaml"));
93
+ if (data.dependencies &&
94
+ typeof data.dependencies === "object" &&
95
+ Object.hasOwn(data.dependencies, runtimePackage))
96
+ return [
97
+ { directory: layout.modules, directPackages: new Set(Object.keys(data.dependencies)) }
98
+ ];
99
+ }
100
+ else if (process.platform === "win32") {
101
+ const shim = await readFile(path.join(layout.root, "octo-runtime.cmd"), "utf8");
102
+ if (shim
103
+ .replaceAll("\\", "/")
104
+ .includes("node_modules/@mininglamp-oss/octo-runtime/apps/cli/dist/index.js"))
105
+ return [{ directory: layout.modules }];
106
+ }
107
+ else if ((await realpath(path.join(layout.root, "bin/octo-runtime"))) === actual) {
108
+ return [{ directory: layout.modules }];
109
+ }
110
+ }
111
+ catch (error) {
112
+ report(`Global Extra discovery could not verify ${JSON.stringify(layout.root)} (${errorCode(error)}).`);
113
+ }
114
+ }
115
+ report("Global Extra discovery unavailable for this CLI installation; use <Home>/manifest.json or --manifest (no PATH-based fallback).");
116
+ return [];
117
+ }
118
+ /** 每次只读当前 CLI 对应环境的顶层包元数据;不可用的可选目录不阻止 Kernel/manifest 使用。 */
119
+ export async function discoverGlobalExtras(report, entry = cliEntrypoint()) {
120
+ const found = [];
121
+ for (const root of await installationRoots(entry, report)) {
122
+ const modules = root.directory;
123
+ const packages = [];
124
+ for (const item of await entries(modules, report)) {
125
+ if (!item.isDirectory() && !item.isSymbolicLink())
126
+ continue;
127
+ if (item.name.startsWith("@")) {
128
+ for (const child of await entries(path.join(modules, item.name), report))
129
+ if (child.isDirectory() || child.isSymbolicLink())
130
+ packages.push(`${item.name}/${child.name}`);
131
+ }
132
+ else if (!item.name.startsWith("."))
133
+ packages.push(item.name);
134
+ }
135
+ for (const module of packages.sort(compare)) {
136
+ if (root.directPackages && !root.directPackages.has(module))
137
+ continue;
138
+ const match = /^(?:@[^/]+\/)?octo-runtime-extra-(.+)$/.exec(module);
139
+ if (!match)
140
+ continue;
141
+ const directory = path.join(modules, module);
142
+ try {
143
+ const name = match[1];
144
+ assertExtraName(name);
145
+ const packageInfo = await metadata(path.join(directory, "package.json"));
146
+ if (packageInfo.name !== module)
147
+ throw new Error("PACKAGE_NAME_MISMATCH");
148
+ found.push({
149
+ name,
150
+ ...(typeof packageInfo.description === "string" && packageInfo.description.trim()
151
+ ? { description: packageInfo.description }
152
+ : {}),
153
+ module,
154
+ sourceManifest: path.join(path.dirname(modules), "package.json"),
155
+ installation: { directory, realDirectory: await realpath(directory) }
156
+ });
157
+ }
158
+ catch (error) {
159
+ report(`Ignoring global Extra ${JSON.stringify(directory)} (${errorCode(error)}; check package.json name and Extra suffix).`);
160
+ }
161
+ }
162
+ }
163
+ return found.sort((a, b) => compare(a.module, b.module) || compare(a.installation.directory, b.installation.directory));
164
+ }
165
+ function compare(a, b) {
166
+ return a < b ? -1 : a > b ? 1 : 0;
167
+ }
168
+ function origin(entry) {
169
+ return JSON.stringify({
170
+ module: entry.module,
171
+ source: isDiscovered(entry) ? entry.installation.directory : entry.sourceManifest
172
+ });
173
+ }
174
+ function isDiscovered(entry) {
175
+ return "installation" in entry;
176
+ }
177
+ /** 两份清单已完成自身校验;全局候选排序后按逻辑名补缺,决胜之前不解析 exports。 */
178
+ export function mergeGlobalExtras(manifest, candidates, report) {
179
+ const selected = new Map(manifest.extras.map((entry) => [entry.name, entry]));
180
+ for (const entry of candidates) {
181
+ const previous = selected.get(entry.name);
182
+ if (previous)
183
+ report(`Ignoring global Extra "${entry.name}": selected ${origin(previous)}; ignored ${origin(entry)}.`);
184
+ else {
185
+ selected.set(entry.name, entry);
186
+ report(`Discovered global Extra "${entry.name}": selected ${origin(entry)}; configure with "octo-runtime ${entry.name} extraset", then start explicitly.`);
187
+ }
188
+ }
189
+ return { ...manifest, extras: [...selected.values()] };
190
+ }
191
+ /** 仅在启用的 Extra 真正加载时解析入口;移除/替换后拒绝沿祖先目录加载另一份同名包。 */
192
+ export async function resolveExtraModule(entry) {
193
+ if (isDiscovered(entry)) {
194
+ if ((await realpath(entry.installation.directory)) !== entry.installation.realDirectory)
195
+ throw new Error("GLOBAL_EXTRA_INSTALLATION_CHANGED");
196
+ if ((await metadata(path.join(entry.installation.directory, "package.json"))).name !==
197
+ entry.module)
198
+ throw new Error("GLOBAL_EXTRA_INSTALLATION_CHANGED");
199
+ }
200
+ return resolveModuleSpecifier(entry.module, entry.sourceManifest);
201
+ }
@@ -1,3 +1,6 @@
1
1
  export declare const cliVersion: string;
2
2
  export declare const cliVersionInfo: string;
3
- export declare function helpText(component?: string): string;
3
+ export declare const cliHelpHeader: string;
4
+ export declare const preferredRootCommands: string[];
5
+ export declare const lifecycleCommands: Map<string, string>;
6
+ export declare const rootCommands: Map<string, string>;