@mininglamp-oss/octo-runtime 1.1.4 → 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 (117) hide show
  1. package/README.md +61 -37
  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 -79
  17. package/apps/cli/dist/main.d.ts +2 -0
  18. package/apps/cli/dist/main.js +27 -63
  19. package/apps/cli/dist/manifest.json +48 -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/output.js +13 -2
  23. package/apps/cli/dist/service-control.js +2 -2
  24. package/apps/cli/dist/state.js +48 -19
  25. package/dist/public/channel-gateway-commands.d.ts +1 -0
  26. package/dist/public/channel-gateway-commands.js +1 -0
  27. package/dist/public/channel-wecom-commands.d.ts +1 -0
  28. package/dist/public/channel-wecom-commands.js +1 -0
  29. package/dist/public/extra.d.ts +1 -0
  30. package/dist/public/extra.js +1 -0
  31. package/dist/public/host.d.ts +2 -4
  32. package/dist/public/host.js +1 -2
  33. package/dist/public/webui-commands.d.ts +1 -0
  34. package/dist/public/webui-commands.js +1 -0
  35. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.d.ts +6 -0
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.js +16 -4
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  54. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  55. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.d.ts +2 -0
  56. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.js +16 -0
  57. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.d.ts +20 -0
  58. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +402 -0
  59. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.d.ts +4 -0
  60. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.js +50 -0
  61. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.d.ts +15 -0
  62. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.js +275 -0
  63. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +14 -2
  64. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.d.ts +16 -0
  65. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.js +201 -0
  66. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.d.ts +4 -1
  67. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +31 -79
  68. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +2 -0
  69. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +27 -63
  70. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +48 -3
  71. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.d.ts +1 -1
  72. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +3 -2
  73. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +13 -2
  74. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/service-control.js +2 -2
  75. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -19
  76. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +25 -24
  77. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  78. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  79. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
  80. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +3 -3
  81. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.d.ts +4 -0
  82. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.js +124 -0
  83. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.d.ts +1 -1
  84. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +2 -2
  85. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.d.ts +7 -0
  86. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.js +44 -3
  87. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +8 -5
  88. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +10 -6
  89. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.d.ts +4 -0
  90. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.js +128 -0
  91. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +9 -5
  92. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.d.ts +3 -0
  93. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.js +51 -0
  94. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +7 -3
  95. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.d.ts +70 -0
  96. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.js +16 -0
  97. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +1 -3
  98. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +1 -2
  99. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +8 -4
  100. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  101. package/node_modules/commander/LICENSE +22 -0
  102. package/node_modules/commander/Readme.md +1172 -0
  103. package/node_modules/commander/index.js +21 -0
  104. package/node_modules/commander/lib/argument.js +147 -0
  105. package/node_modules/commander/lib/command.js +2790 -0
  106. package/node_modules/commander/lib/error.js +36 -0
  107. package/node_modules/commander/lib/help.js +731 -0
  108. package/node_modules/commander/lib/option.js +377 -0
  109. package/node_modules/commander/lib/suggestSimilar.js +99 -0
  110. package/node_modules/commander/package-support.json +19 -0
  111. package/node_modules/commander/package.json +64 -0
  112. package/node_modules/commander/typings/index.d.ts +1113 -0
  113. package/package.json +41 -27
  114. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.d.ts +0 -15
  115. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.js +0 -22
  116. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.d.ts +0 -16
  117. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.js +0 -160
@@ -8,5 +8,7 @@ export interface CliDependencies extends ServiceControlOptions {
8
8
  /** CLI 入口选择前台组件的退出策略;仅确认命令类型,不表示服务 ready。 */
9
9
  onComponentRun?: () => void;
10
10
  logsSignal?: AbortSignal;
11
+ /** 自有命令的取消;不启动或停止任何服务。 */
12
+ commandSignal?: AbortSignal;
11
13
  }
12
14
  export declare function runCli(args: string[], dependencies?: CliDependencies): Promise<number>;
@@ -1,3 +1,4 @@
1
+ import { runExtraCommand, commandError } from "./extra-commands.js";
1
2
  import net from "node:net";
2
3
  import { randomUUID } from "node:crypto";
3
4
  import { once } from "node:events";
@@ -7,7 +8,8 @@ import { fileURLToPath } from "node:url";
7
8
  import { attachKernel, acknowledgeOrphanCleanup, inspectOrphanCleanup, createKernelService, readAdapterConfigurations } from "@mininglamp-oss/octo-runtime-executor-kernel";
8
9
  import { componentEndpoint, createExtraService } from "@mininglamp-oss/octo-runtime-host-sdk";
9
10
  import { getExtra, readExtra, setExtra } from "./extras.js";
10
- import { cliVersionInfo, helpText } from "./help.js";
11
+ import { cliVersionInfo } from "./help.js";
12
+ import { parseCliCommand } from "./command-tree.js";
11
13
  import { runForegroundService } from "./foreground.js";
12
14
  import { showExtraLogs } from "./logs.js";
13
15
  import { StatusOutput } from "./status-output.js";
@@ -21,12 +23,22 @@ const components = ["executor-kernel", "channel-gateway"];
21
23
  const builtinComponents = [...components, "channel-wecom", "webui"];
22
24
  export async function runCli(args, dependencies = {}) {
23
25
  const output = dependencies.output ?? ((line) => process.stdout.write(`${line}\n`));
24
- let json = args.includes("--json");
26
+ // 参数解析失败也按宿主布尔标记输出 JSON;-- 后的字面位置参数不选择输出格式。
27
+ const literalIndex = args.indexOf("--");
28
+ let json = (literalIndex < 0 ? args : args.slice(0, literalIndex)).some((arg) => arg === "--json" || arg.startsWith("--json="));
25
29
  let context = {};
26
30
  let runningComponent;
27
31
  let statusOutput;
28
32
  try {
29
- const { flags, positional } = parse(args);
33
+ const parsed = await parseCliCommand(args, dependencies);
34
+ if (parsed.help !== undefined) {
35
+ output(parsed.help);
36
+ return 0;
37
+ }
38
+ const { flags, positional } = parsed;
39
+ json = Boolean(flags.json);
40
+ if (parsed.extra)
41
+ return await runExtraCommand(parsed, dependencies);
30
42
  if (flags["acknowledge-orphan-cleanup"] !== undefined &&
31
43
  !(positional[0] === "executor-kernel" && positional[1] === "recover"))
32
44
  throw new Error("INVALID_ARGUMENTS");
@@ -37,15 +49,6 @@ export async function runCli(args, dependencies = {}) {
37
49
  output(cliVersionInfo);
38
50
  return 0;
39
51
  }
40
- if (flags.help || !positional.length || positional[0] === "help") {
41
- output(helpText(builtinComponents.includes(positional[0]) ? positional[0] : undefined));
42
- return 0;
43
- }
44
- // 裸组件帮助仅做词法校验,不读取配置或创建服务管理器。
45
- if (positional.length === 1 && builtinComponents.includes(positional[0])) {
46
- output(helpText(positional[0]));
47
- return 0;
48
- }
49
52
  const home = resolve(flags.home ?? defaultRuntimeHome(dependencies.env, dependencies.platform));
50
53
  // 模块清单不决定运行状态位置;前台 Kernel、doctor 和恢复确认共用 Home 下的同一路径。
51
54
  const kernelStateDirectory = join(home, "run");
@@ -125,10 +128,6 @@ export async function runCli(args, dependencies = {}) {
125
128
  const isComponent = (name) => builtinComponents.includes(name) ||
126
129
  registrations.some((entry) => entry.name === name) ||
127
130
  manifest?.extras.some((entry) => entry.name === name) === true;
128
- if (positional.length === 1 && isComponent(positional[0])) {
129
- output(helpText(positional[0]));
130
- return 0;
131
- }
132
131
  const service = resolveServiceControl(dependencies);
133
132
  const input = dependencies.input ?? process.stdin;
134
133
  const publish = (value, human) => output(typeof value === "string" ? value : !json && human ? human : JSON.stringify(value, null, 2));
@@ -372,21 +371,23 @@ export async function runCli(args, dependencies = {}) {
372
371
  catch (error) {
373
372
  if (runningComponent && context.logs)
374
373
  await recordStartupFailure(context.logs, runningComponent, error);
375
- const failure = { ...describeError(error), ...context };
374
+ const failure = { ...(commandError(error) ?? describeError(error)), ...context };
376
375
  const code = failure.code;
377
376
  if (json)
378
377
  output(JSON.stringify({ error: failure }, null, context.action === "logs" ? undefined : 2));
379
378
  else
380
379
  (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}` : ""}`);
381
- return ["SERVICE_NOT_INSTALLED", "NOT_INSTALLED"].includes(code)
382
- ? 3
383
- : /INVALID|REQUIRED/.test(code)
384
- ? 2
385
- : /INCOMPLETE/.test(code)
386
- ? 5
387
- : /UNAVAILABLE|SERVICE_PROCESS_EXITED/.test(code)
388
- ? 4
389
- : 1;
380
+ return code === "EXTRA_COMMAND_CANCELLED"
381
+ ? 130
382
+ : ["SERVICE_NOT_INSTALLED", "NOT_INSTALLED"].includes(code)
383
+ ? 3
384
+ : /INVALID|REQUIRED|COMMAND_NOT_FOUND/.test(code)
385
+ ? 2
386
+ : /INCOMPLETE/.test(code)
387
+ ? 5
388
+ : /UNAVAILABLE|SERVICE_PROCESS_EXITED/.test(code)
389
+ ? 4
390
+ : 1;
390
391
  }
391
392
  finally {
392
393
  statusOutput?.close();
@@ -448,40 +449,3 @@ async function componentStatus(home, component, platform, requireReady = false)
448
449
  });
449
450
  }
450
451
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
451
- function parse(args) {
452
- const flags = {}, positional = [];
453
- for (let i = 0; i < args.length; i++) {
454
- const arg = args[i] === "-h" ? "--help" : args[i] === "-v" ? "--version" : args[i];
455
- if (!arg.startsWith("-")) {
456
- positional.push(arg);
457
- continue;
458
- }
459
- const match = /^--([a-z-]+)(?:=(.*))?$/.exec(arg);
460
- if (!match ||
461
- ![
462
- "home",
463
- "profile",
464
- "manifest",
465
- "json",
466
- "help",
467
- "version",
468
- "autostart",
469
- "lines",
470
- "follow",
471
- "acknowledge-orphan-cleanup"
472
- ].includes(match[1]) ||
473
- Object.hasOwn(flags, match[1]))
474
- throw new Error("INVALID_ARGUMENTS");
475
- const key = match[1];
476
- flags[key] = ["json", "help", "version", "follow", "acknowledge-orphan-cleanup"].includes(key)
477
- ? "true"
478
- : (match[2] ?? args[++i]);
479
- if (key === "acknowledge-orphan-cleanup" && match[2] !== undefined)
480
- throw new Error("INVALID_ARGUMENTS");
481
- if (!flags[key] ||
482
- flags[key].startsWith("--") ||
483
- (key === "autostart" && !["true", "false"].includes(flags[key])))
484
- throw new Error("INVALID_ARGUMENTS");
485
- }
486
- return { flags, positional };
487
- }
@@ -73,8 +73,53 @@
73
73
  }
74
74
  ],
75
75
  "extras": [
76
- { "name": "channel-gateway", "module": "@mininglamp-oss/octo-runtime-extra-channel-gateway" },
77
- { "name": "channel-wecom", "module": "@mininglamp-oss/octo-runtime-extra-channel-wecom" },
78
- { "name": "webui", "module": "@mininglamp-oss/octo-runtime-extra-webui" }
76
+ {
77
+ "name": "channel-gateway",
78
+ "description": "Connect Octo IM Bots to local Agent execution",
79
+ "configExample": {
80
+ "bots": [
81
+ {
82
+ "api_url": "https://im.example.com/api",
83
+ "bot_id": "<BOT_ID>",
84
+ "bf_token": "<BOT_TOKEN>",
85
+ "adapter": {
86
+ "adapter_type": "codex",
87
+ "workdir": "/absolute/workspace",
88
+ "model": "<MODEL_ID>",
89
+ "effort": "medium"
90
+ }
91
+ }
92
+ ]
93
+ },
94
+ "module": "@mininglamp-oss/octo-runtime-extra-channel-gateway"
95
+ },
96
+ {
97
+ "name": "channel-wecom",
98
+ "description": "Connect WeCom Bots to local Agent execution",
99
+ "configExample": {
100
+ "bots": [
101
+ {
102
+ "bot_id": "<BOT_ID>",
103
+ "app_secret": "<APP_SECRET>",
104
+ "adapter": {
105
+ "adapter_type": "codex",
106
+ "workdir": "/absolute/workspace",
107
+ "model": "<MODEL_ID>",
108
+ "effort": "medium"
109
+ }
110
+ }
111
+ ]
112
+ },
113
+ "module": "@mininglamp-oss/octo-runtime-extra-channel-wecom"
114
+ },
115
+ {
116
+ "name": "webui",
117
+ "description": "Open a local browser workspace for Agent conversations",
118
+ "configExample": {
119
+ "port": 13888,
120
+ "sessionStorePath": "/absolute/host-home/extras/webui/sessions.json"
121
+ },
122
+ "module": "@mininglamp-oss/octo-runtime-extra-webui"
123
+ }
79
124
  ]
80
125
  }
@@ -1,3 +1,3 @@
1
1
  import { type ModuleManifest } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
2
- /** CLI 独占默认目录与 Home 扩展策略;SDK 原生装配不读取这两份文件。 */
2
+ /** CLI 独占内置、Home 与全局 Extra 目录;SDK 不扫描,显式清单完全替换。 */
3
3
  export declare function loadCliManifest(home: string, override?: string, report?: (message: string) => void): Promise<ModuleManifest>;
@@ -1,11 +1,12 @@
1
1
  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
- /** CLI 独占默认目录与 Home 扩展策略;SDK 原生装配不读取这两份文件。 */
4
+ import { discoverGlobalExtras, mergeGlobalExtras } from "./global-extras.js";
5
+ /** CLI 独占内置、Home 与全局 Extra 目录;SDK 不扫描,显式清单完全替换。 */
5
6
  export async function loadCliManifest(home, override, report = (message) => console.error(message)) {
6
7
  if (override)
7
8
  return readModuleManifest(resolve(override), { legacy: true });
8
9
  const builtin = await readModuleManifest(fileURLToPath(new URL("./manifest.json", import.meta.url)));
9
10
  const extension = await readModuleManifest(join(home, "manifest.json"), { optional: true });
10
- return mergeModuleManifests(builtin, extension, report);
11
+ return mergeGlobalExtras(mergeModuleManifests(builtin, extension, report), await discoverGlobalExtras(report), report);
11
12
  }
@@ -104,8 +104,19 @@ export function describeError(error, fallback = "COMMAND_FAILED") {
104
104
  ORPHAN_CLEANUP_NOT_PENDING: "There is no valid incomplete orphan cleanup to acknowledge. Run doctor with the same --home.",
105
105
  SERVICE_NOT_INSTALLED: "Run this component's install command, then start it.",
106
106
  NOT_INSTALLED: "Run this component's install command, then start it.",
107
- EXTRA_NOT_REGISTERED: "Save this Extra's declaration with extraset before starting it.",
108
- EXTRA_MANIFEST_DECLARATION_REQUIRED: "Add this Extra's name and module to the selected Home manifest.json (extras array), then retry.",
107
+ EXTRA_COMMAND_FAILED: "The Extra command failed. No private backend error is printed; check its input and configuration, then retry.",
108
+ EXTRA_CONFIG_CONFLICT: "Configuration changed after this command read it. Read the latest configuration and retry.",
109
+ 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.",
110
+ EXTRA_COMMAND_API_UNSUPPORTED: "This CLI supports Extra command apiVersion 1. Install a compatible command extension.",
111
+ EXTRA_COMMAND_DEFINITION_INVALID: "Command definitions must have unique names and valid options; lifecycle and host option names are reserved.",
112
+ EXTRA_COMMAND_NAMESPACE_CONFLICT: "An Extra name conflicts with a Runtime command. Rename its manifest entry.",
113
+ EXTRA_COMMAND_NOT_FOUND: "Unknown command. Use --help on the service command to see available subcommands.",
114
+ EXTRA_COMMAND_CANCELLED: "The command was cancelled. Any save that already completed remains persisted.",
115
+ EXTRA_COMMAND_STDIN_REQUIRED: "Pipe the required input through stdin; do not put credentials in command arguments.",
116
+ EXTRA_NOT_REGISTERED: "Save the service configuration using its configure or extraset subcommand before starting it.",
117
+ 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.",
118
+ EXTRA_NAME_MISMATCH: "The selected Extra must export the same name as its catalog entry. Check the reported package origin.",
119
+ 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.",
109
120
  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.",
110
121
  MANIFEST_INVALID: "Check manifest.json: version must be 1 and adapters/extras must be valid arrays without duplicate keys.",
111
122
  MANAGER_UNAVAILABLE: "Run doctor and check the current user's native service manager.",
@@ -1,6 +1,6 @@
1
1
  import { homedir } from "node:os";
2
2
  import { resolve } from "node:path";
3
- import { fileURLToPath } from "node:url";
3
+ import { cliEntrypoint } from "./cli-entrypoint.js";
4
4
  import { componentServiceId } from "@mininglamp-oss/octo-runtime-host-sdk";
5
5
  import { createServiceBackend } from "@mininglamp-oss/octo-runtime-cross-service";
6
6
  export function resolveServiceControl(options = {}) {
@@ -19,7 +19,7 @@ export function resolveServiceControl(options = {}) {
19
19
  description: `Octo Runtime ${component}`,
20
20
  command: resolve(options.nodeExecutable ?? process.execPath),
21
21
  args: [
22
- resolve(options.cliEntrypoint ?? fileURLToPath(new URL("./index.js", import.meta.url))),
22
+ resolve(options.cliEntrypoint ?? cliEntrypoint()),
23
23
  component,
24
24
  "run",
25
25
  "--home",
@@ -1,5 +1,5 @@
1
- import { randomUUID } from "node:crypto";
2
- import { access, chmod, mkdir, open, readFile, rename, rm, rmdir } from "node:fs/promises";
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { access, chmod, link, mkdir, open, readFile, rename, rm, rmdir } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { basename, dirname, join, resolve } from "node:path";
5
5
  import { componentEndpoint } from "@mininglamp-oss/octo-runtime-host-sdk";
@@ -235,35 +235,64 @@ async function writeFileAtomic(path, value) {
235
235
  throw error;
236
236
  }
237
237
  }
238
+ /**
239
+ * 主锁和回收锁使用同一协议:先完整写入独占临时文件,再用硬链接原子发布 PID/随机身份。
240
+ * 发布前退出只留下不参与互斥的临时文件;发布后退出可按 PID 回收,不存在无 owner 窗口。
241
+ * 回收前先持有该锁自己的回收锁,并再次核对原记录,防止删除后来取得的锁。
242
+ * 回收者也可能退出,因此回收锁递归遵循同一协议;固定长度哈希避免路径随层级增长。
243
+ */
238
244
  async function acquireProcessLock(path) {
239
- for (let attempt = 0; attempt < 2; attempt++) {
245
+ const record = `${JSON.stringify({ pid: process.pid, id: randomUUID() })}\n`;
246
+ const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
247
+ const handle = await open(temporary, "wx", 0o600);
248
+ try {
240
249
  try {
241
- const handle = await open(path, "wx", 0o600);
242
- await handle.writeFile(`${JSON.stringify({ pid: process.pid, created_at: new Date().toISOString() })}\n`, "utf8");
250
+ await handle.writeFile(record, "utf8");
251
+ }
252
+ finally {
243
253
  await handle.close();
244
- return async () => {
254
+ }
255
+ for (let attempt = 0; attempt < 2; attempt++) {
256
+ try {
257
+ await link(temporary, path);
258
+ return async () => {
259
+ if ((await readLockOwner(path))?.record === record)
260
+ await rm(path, { force: true });
261
+ };
262
+ }
263
+ catch (error) {
264
+ if (!isNodeError(error, "EEXIST"))
265
+ throw error;
245
266
  const owner = await readLockOwner(path);
246
- if (owner === process.pid)
267
+ // 旧格式的不完整记录仍需保守拒绝;不能根据时间猜测它已失效。
268
+ if (!owner || processAlive(owner.pid))
269
+ throw new Error("SETUP_IN_PROGRESS", { cause: error });
270
+ // 只哈希文件名,使同一 Home 的不同符号链接路径仍争用同一个回收锁。
271
+ const reclaim = join(dirname(path), `.reclaim-${createHash("sha256").update(basename(path)).digest("hex")}`);
272
+ const release = await acquireProcessLock(reclaim);
273
+ try {
274
+ const current = await readLockOwner(path);
275
+ if (!current || current.record !== owner.record || processAlive(current.pid))
276
+ throw new Error("SETUP_IN_PROGRESS", { cause: error });
247
277
  await rm(path, { force: true });
248
- };
249
- }
250
- catch (error) {
251
- if (!isNodeError(error, "EEXIST"))
252
- throw error;
253
- const owner = await readLockOwner(path);
254
- if (owner !== undefined && processAlive(owner)) {
255
- throw new Error("SETUP_IN_PROGRESS", { cause: error });
278
+ }
279
+ finally {
280
+ await release();
281
+ }
256
282
  }
257
- await rm(path, { force: true });
258
283
  }
284
+ throw new Error("could not acquire setup lock");
285
+ }
286
+ finally {
287
+ await rm(temporary, { force: true });
259
288
  }
260
- throw new Error("could not acquire setup lock");
261
289
  }
262
290
  async function readLockOwner(path) {
263
291
  try {
264
- const value = JSON.parse(await readFile(path, "utf8"));
292
+ const record = await readFile(path, "utf8");
293
+ const value = JSON.parse(record);
265
294
  return typeof value.pid === "number" && Number.isSafeInteger(value.pid) && value.pid > 0
266
- ? value.pid
295
+ ? { pid: value.pid, record }
267
296
  : undefined;
268
297
  }
269
298
  catch {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-cli",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,29 +8,30 @@
8
8
  },
9
9
  "types": "./dist/index.d.ts",
10
10
  "dependencies": {
11
- "@mininglamp-oss/octo-runtime-adapter-dsh": "1.1.4",
12
- "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.4",
11
+ "commander": "15.0.0",
12
+ "@mininglamp-oss/octo-runtime-adapter-dsh": "1.1.5",
13
+ "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.5",
13
14
  "json5": "2.2.3",
14
- "@mininglamp-oss/octo-runtime-extra-channel-gateway": "1.1.4",
15
- "@mininglamp-oss/octo-runtime-host-sdk": "1.1.4",
16
- "@mininglamp-oss/octo-runtime-adapter-openclaw": "1.1.4",
17
- "@mininglamp-oss/octo-runtime-cross-service": "1.1.4",
18
- "@mininglamp-oss/octo-runtime-protocol": "1.1.4",
19
- "@mininglamp-oss/octo-runtime-executor-kernel": "1.1.4",
20
- "@mininglamp-oss/octo-runtime-executor-core": "1.1.4",
21
- "@mininglamp-oss/octo-runtime-adapter-antigravity": "1.1.4",
22
- "@mininglamp-oss/octo-runtime-adapter-claude-code": "1.1.4",
23
- "@mininglamp-oss/octo-runtime-adapter-codebuddy": "1.1.4",
24
- "@mininglamp-oss/octo-runtime-adapter-codex": "1.1.4",
25
- "@mininglamp-oss/octo-runtime-adapter-hermes": "1.1.4",
26
- "@mininglamp-oss/octo-runtime-adapter-grok-build": "1.1.4",
27
- "@mininglamp-oss/octo-runtime-adapter-kimi-code": "1.1.4",
28
- "@mininglamp-oss/octo-runtime-adapter-mcode": "1.1.4",
29
- "@mininglamp-oss/octo-runtime-adapter-opencode": "1.1.4",
30
- "@mininglamp-oss/octo-runtime-adapter-qodercli": "1.1.4",
31
- "@mininglamp-oss/octo-runtime-adapter-qoderclicn": "1.1.4",
32
- "@mininglamp-oss/octo-runtime-adapter-zcode-gui": "1.1.4",
33
- "@mininglamp-oss/octo-runtime-extra-channel-wecom": "1.1.4",
34
- "@mininglamp-oss/octo-runtime-extra-webui": "1.1.4"
15
+ "@mininglamp-oss/octo-runtime-extra-channel-gateway": "1.1.5",
16
+ "@mininglamp-oss/octo-runtime-host-sdk": "1.1.5",
17
+ "@mininglamp-oss/octo-runtime-adapter-openclaw": "1.1.5",
18
+ "@mininglamp-oss/octo-runtime-cross-service": "1.1.5",
19
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.5",
20
+ "@mininglamp-oss/octo-runtime-executor-kernel": "1.1.5",
21
+ "@mininglamp-oss/octo-runtime-executor-core": "1.1.5",
22
+ "@mininglamp-oss/octo-runtime-adapter-antigravity": "1.1.5",
23
+ "@mininglamp-oss/octo-runtime-adapter-claude-code": "1.1.5",
24
+ "@mininglamp-oss/octo-runtime-adapter-codebuddy": "1.1.5",
25
+ "@mininglamp-oss/octo-runtime-adapter-codex": "1.1.5",
26
+ "@mininglamp-oss/octo-runtime-adapter-hermes": "1.1.5",
27
+ "@mininglamp-oss/octo-runtime-adapter-grok-build": "1.1.5",
28
+ "@mininglamp-oss/octo-runtime-adapter-kimi-code": "1.1.5",
29
+ "@mininglamp-oss/octo-runtime-adapter-mcode": "1.1.5",
30
+ "@mininglamp-oss/octo-runtime-adapter-opencode": "1.1.5",
31
+ "@mininglamp-oss/octo-runtime-adapter-qodercli": "1.1.5",
32
+ "@mininglamp-oss/octo-runtime-adapter-qoderclicn": "1.1.5",
33
+ "@mininglamp-oss/octo-runtime-adapter-zcode-gui": "1.1.5",
34
+ "@mininglamp-oss/octo-runtime-extra-channel-wecom": "1.1.5",
35
+ "@mininglamp-oss/octo-runtime-extra-webui": "1.1.5"
35
36
  }
36
37
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-cross-service",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "private": true,
5
5
  "description": "Native user-service lifecycle backends for Octo Runtime",
6
6
  "type": "module",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-executor-core",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": "./dist/index.js",
7
7
  "dependencies": {
8
- "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.4",
9
- "@mininglamp-oss/octo-runtime-protocol": "1.1.4"
8
+ "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.5",
9
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.5"
10
10
  },
11
11
  "types": "./dist/index.d.ts",
12
12
  "files": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-executor-kernel",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": {
@@ -18,9 +18,9 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@mininglamp-oss/octo-runtime-executor-core": "1.1.4",
22
- "@mininglamp-oss/octo-runtime-protocol": "1.1.4",
23
- "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.4"
21
+ "@mininglamp-oss/octo-runtime-executor-core": "1.1.5",
22
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.5",
23
+ "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.5"
24
24
  },
25
25
  "types": "./dist/index.d.ts",
26
26
  "files": [
@@ -199,7 +199,7 @@ export class ImRuntime {
199
199
  const failure = connectionFailure(error);
200
200
  this.#connectionAbort.abort();
201
201
  this.#error = failure.message;
202
- // Offline startup and later disconnects share recovery; only error semantics decide eligibility.
202
+ // 首次离线与后续断线共用恢复;服务端断开不等于永久拒绝,由传输分类决定资格。
203
203
  const retry = failure.retryable;
204
204
  this.#state = retry ? "retrying" : "failed";
205
205
  this.#log("channel.connection_failed", { state: this.#state, code: failure.message });
@@ -217,12 +217,12 @@ export class ImRuntime {
217
217
  }
218
218
  }
219
219
  #lostConnection(connector, failure) {
220
- this.#log("channel.disconnected", { code: failure.message });
221
220
  this.#error = failure.message;
222
221
  const retry = failure.retryable;
223
222
  this.#state = retry ? "retrying" : "failed";
223
+ this.#log("channel.disconnected", { state: this.#state, code: failure.message });
224
224
  this.#connectionAbort?.abort();
225
- // Reap the old connection before backoff; shutdown and stale callbacks cannot create a second owner.
225
+ // 先回收旧连接再开始退避;关闭和旧回调不能再创建连接,回收失败须单独诊断。
226
226
  this.#disconnecting = connector.close();
227
227
  void this.#disconnecting.then(() => {
228
228
  if (retry)
@@ -0,0 +1,4 @@
1
+ import { type ExtraCommandExtension } from "@mininglamp-oss/octo-runtime-host-sdk/extra-commands";
2
+ /** 单 Bot 配置命令按 bot_id upsert;省略字段保留,重复调用不会追加相同 Bot。 */
3
+ declare const extension: ExtraCommandExtension;
4
+ export default extension;
@@ -0,0 +1,124 @@
1
+ import { ExtraCommandError, savedConfigResult } from "@mininglamp-oss/octo-runtime-host-sdk/extra-commands";
2
+ import { validateImBots } from "./lifecycle/configuration.js";
3
+ /** 离线业务校验复用运行时 Bot 合同;不认证、不构造 manager 或服务。 */
4
+ function validate(config) {
5
+ try {
6
+ validateImBots(config.bots ?? []);
7
+ const spaces = config.authorized_space_ids;
8
+ if (spaces !== undefined &&
9
+ (!Array.isArray(spaces) || spaces.some((id) => typeof id !== "string" || !id.trim())))
10
+ throw new Error("IM_AUTHORIZED_SPACES_INVALID");
11
+ const settings = config.context_loading;
12
+ if (settings !== undefined) {
13
+ if (!settings ||
14
+ typeof settings !== "object" ||
15
+ Array.isArray(settings) ||
16
+ Object.keys(settings).some((key) => !["timeout_ms", "max_in_flight"].includes(key)))
17
+ throw new Error("IM_CONTEXT_LOADING_CONFIG_INVALID");
18
+ for (const [key, max] of [
19
+ ["timeout_ms", 30000],
20
+ ["max_in_flight", 32]
21
+ ]) {
22
+ const value = settings[key];
23
+ if (value !== undefined &&
24
+ (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > max))
25
+ throw new Error("IM_CONTEXT_LOADING_CONFIG_INVALID");
26
+ }
27
+ }
28
+ }
29
+ catch (error) {
30
+ const hints = {
31
+ IM_BOT_ID_REQUIRED: "Provide a non-empty --bot_id (JSON: bots[].bot_id).",
32
+ IM_ADAPTER_REQUIRED: "Each Bot requires an adapter object; configure maps --adapter_type/--workdir to it.",
33
+ IM_WORKDIR_ABSOLUTE_REQUIRED: "Provide an absolute --workdir for a local adapter.",
34
+ IM_OPENCLAW_WORKDIR_UNSUPPORTED: "OpenClaw uses its own workspace; remove config.bots[].adapter.workdir using extraset.",
35
+ IM_PROVIDER_AGENT_ID_UNSUPPORTED: "--provider_agent_id is supported only by OpenClaw.",
36
+ IM_API_URL_INVALID: "Use a valid endpoint URL without credentials, query or fragment; insecure URLs are loopback-only.",
37
+ IM_BOT_DUPLICATED: "Duplicate Bot identity in bots; keep one entry per endpoint and bot_id.",
38
+ IM_CONFIG_LIST_REQUIRED: "bots must be an array within this Extra's Bot limit.",
39
+ IM_AUTHORIZED_SPACES_INVALID: "authorized_space_ids must contain non-empty strings.",
40
+ IM_CONTEXT_LOADING_CONFIG_INVALID: "context_loading accepts timeout_ms (1..30000) and max_in_flight (1..32)."
41
+ };
42
+ const code = error instanceof Error && Object.hasOwn(hints, error.message)
43
+ ? error.message
44
+ : "EXTRA_CONFIG_INVALID";
45
+ throw new ExtraCommandError(code, hints[code] ??
46
+ "Invalid Bot configuration. Check configure --help and this Extra's configuration schema.");
47
+ }
48
+ }
49
+ /** 单 Bot 配置命令按 bot_id upsert;省略字段保留,重复调用不会追加相同 Bot。 */
50
+ const extension = {
51
+ apiVersion: 1,
52
+ commands: [
53
+ {
54
+ name: "configure",
55
+ description: "Add or update one Bot by bot_id; saves config only",
56
+ options: [
57
+ { name: "bot_id", type: "string", required: true, description: "Platform Bot ID" },
58
+ { name: "api_url", type: "string", required: true, description: "Octo API base URL" },
59
+ {
60
+ name: "adapter_type",
61
+ type: "string",
62
+ description: "Execution adapter type (adapter.adapter_type)"
63
+ },
64
+ { name: "workdir", type: "string", description: "Absolute local execution directory" },
65
+ { name: "model", type: "string", description: "Provider model ID" },
66
+ {
67
+ name: "effort",
68
+ type: "string",
69
+ description: "Reasoning effort: low, medium, high, xhigh"
70
+ },
71
+ { name: "provider_agent_id", type: "string", description: "Existing OpenClaw Agent ID" },
72
+ {
73
+ name: "bf_token",
74
+ type: "string",
75
+ description: "Raw credential (bots[].bf_token); omitted values are preserved"
76
+ }
77
+ ],
78
+ examples: [
79
+ "octo-runtime channel-gateway configure --bot_id assistant --api_url https://im.example.com/api --adapter_type codex --bf_token EXAMPLE_CREDENTIAL"
80
+ ],
81
+ async run(context, input) {
82
+ const snapshot = await context.readConfig();
83
+ validate(snapshot.config);
84
+ const bots = snapshot.config.bots ?? [];
85
+ validateImBots(bots);
86
+ const identityFields = {
87
+ bot_id: input.options["bot_id"],
88
+ api_url: input.options["api_url"]
89
+ };
90
+ // configure 用 bot_id 定位,更新 endpoint 不产生第二个 Bot。
91
+ // 旧 extraset 可能含跨 endpoint 的同名 Bot:保留首项未提供的字段,合并为一项。
92
+ const position = bots.findIndex((bot) => bot.bot_id === identityFields.bot_id);
93
+ const old = position < 0 ? undefined : bots[position];
94
+ const adapter = { ...old?.adapter };
95
+ for (const field of ["adapter_type", "workdir", "model", "effort", "provider_agent_id"]) {
96
+ const value = input.options[field];
97
+ if (typeof value === "string")
98
+ adapter[field] = value;
99
+ }
100
+ if (adapter.effort !== undefined &&
101
+ (typeof adapter.effort !== "string" ||
102
+ !["low", "medium", "high", "xhigh"].includes(adapter.effort)))
103
+ throw new ExtraCommandError("EXTRA_CONFIG_INVALID", "--effort must be low, medium, high or xhigh.");
104
+ const bot = { ...old, ...identityFields, adapter };
105
+ const credential = input.options.bf_token;
106
+ if (typeof credential === "string") {
107
+ if (!credential.trim())
108
+ throw new ExtraCommandError("EXTRA_CONFIG_INVALID", "--bf_token must not be blank.");
109
+ // 与 extraset 的业务字段同名;保存传入原文,省略时保留已有凭据。
110
+ bot.bf_token = credential;
111
+ }
112
+ const nextBots = bots.filter((bot, index) => index === position || bot.bot_id !== identityFields.bot_id);
113
+ if (position < 0)
114
+ nextBots.push(bot);
115
+ else
116
+ nextBots[position] = bot;
117
+ const config = { ...snapshot.config, bots: nextBots };
118
+ validate(config);
119
+ return savedConfigResult(await context.saveConfig(config, snapshot.revision));
120
+ }
121
+ }
122
+ ]
123
+ };
124
+ export default extension;
@@ -1,4 +1,4 @@
1
- /** Resolve tenant scope through the octo-auth verify-bot contract. */
1
+ /** 建联前用调用方提供的 Bot 凭据解析身份与租户;取消由调用方持有,不跟随重定向转发凭据。 */
2
2
  export declare function verifyBotIdentity(apiUrl: string, token: string, signal: AbortSignal): Promise<{
3
3
  bot_uid: string;
4
4
  space_id: string;