@nextclaw/service 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cli/commands/agent/agent-runtime.utils.d.ts +15 -0
  3. package/dist/cli/commands/agent/agent-runtime.utils.js +85 -0
  4. package/dist/cli/commands/agent/cli-agent-runner.utils.d.ts +21 -0
  5. package/dist/cli/commands/agent/cli-agent-runner.utils.js +89 -0
  6. package/dist/cli/commands/agent/index.d.ts +3 -0
  7. package/dist/cli/commands/agent/index.js +3 -0
  8. package/dist/cli/commands/agent/services/agent-commands.service.d.ts +17 -0
  9. package/dist/cli/commands/agent/services/agent-commands.service.js +112 -0
  10. package/dist/cli/commands/companion/index.d.ts +15 -0
  11. package/dist/cli/commands/companion/index.js +24 -0
  12. package/dist/cli/commands/companion/services/companion-process.service.d.ts +17 -0
  13. package/dist/cli/commands/companion/services/companion-process.service.js +49 -0
  14. package/dist/cli/commands/config/index.d.ts +2 -0
  15. package/dist/cli/commands/config/index.js +2 -0
  16. package/dist/cli/commands/config/services/config-commands.service.d.ts +18 -0
  17. package/dist/cli/commands/config/services/config-commands.service.js +133 -0
  18. package/dist/cli/commands/cron/index.d.ts +2 -0
  19. package/dist/cli/commands/cron/index.js +2 -0
  20. package/dist/cli/commands/cron/services/cron-commands.service.d.ts +22 -0
  21. package/dist/cli/commands/cron/services/cron-commands.service.js +107 -0
  22. package/dist/cli/commands/cron/services/cron-local.service.d.ts +25 -0
  23. package/dist/cli/commands/cron/services/cron-local.service.js +95 -0
  24. package/dist/cli/commands/cron/utils/cron-job.utils.d.ts +31 -0
  25. package/dist/cli/commands/cron/utils/cron-job.utils.js +15 -0
  26. package/dist/cli/commands/diagnostics/index.d.ts +2 -0
  27. package/dist/cli/commands/diagnostics/index.js +2 -0
  28. package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.d.ts +22 -0
  29. package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.js +319 -0
  30. package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.d.ts +23 -0
  31. package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.js +66 -0
  32. package/dist/cli/commands/gateway/index.d.ts +14 -0
  33. package/dist/cli/commands/gateway/index.js +15 -0
  34. package/dist/cli/commands/logs/index.d.ts +12 -0
  35. package/dist/cli/commands/logs/index.js +29 -0
  36. package/dist/cli/commands/mcp/index.d.ts +14 -0
  37. package/dist/cli/commands/mcp/index.js +193 -0
  38. package/dist/cli/commands/restart/index.d.ts +20 -0
  39. package/dist/cli/commands/restart/index.js +88 -0
  40. package/dist/cli/commands/secrets/index.d.ts +22 -0
  41. package/dist/cli/commands/secrets/index.js +280 -0
  42. package/dist/cli/commands/serve/index.d.ts +14 -0
  43. package/dist/cli/commands/serve/index.js +19 -0
  44. package/dist/cli/commands/skills/index.d.ts +26 -0
  45. package/dist/cli/commands/skills/index.js +147 -0
  46. package/dist/cli/commands/skills/marketplace-client.d.ts +31 -0
  47. package/dist/cli/commands/skills/marketplace-client.js +84 -0
  48. package/dist/cli/commands/skills/marketplace-command-options.utils.d.ts +25 -0
  49. package/dist/cli/commands/skills/marketplace-command-options.utils.js +31 -0
  50. package/dist/cli/commands/skills/marketplace-identity.utils.d.ts +14 -0
  51. package/dist/cli/commands/skills/marketplace-identity.utils.js +77 -0
  52. package/dist/cli/commands/skills/marketplace-network-retry.d.ts +4 -0
  53. package/dist/cli/commands/skills/marketplace-network-retry.js +32 -0
  54. package/dist/cli/commands/skills/marketplace.metadata.d.ts +29 -0
  55. package/dist/cli/commands/skills/marketplace.metadata.js +158 -0
  56. package/dist/cli/commands/skills/marketplace.service.d.ts +46 -0
  57. package/dist/cli/commands/skills/marketplace.service.js +238 -0
  58. package/dist/cli/commands/skills/skills-query.service.d.ts +141 -0
  59. package/dist/cli/commands/skills/skills-query.service.js +212 -0
  60. package/dist/cli/commands/start/index.d.ts +18 -0
  61. package/dist/cli/commands/start/index.js +25 -0
  62. package/dist/cli/commands/stop/index.d.ts +12 -0
  63. package/dist/cli/commands/stop/index.js +11 -0
  64. package/dist/cli/commands/ui/index.d.ts +14 -0
  65. package/dist/cli/commands/ui/index.js +17 -0
  66. package/dist/cli/commands/usage/index.d.ts +2 -0
  67. package/dist/cli/commands/usage/index.js +2 -0
  68. package/dist/cli/commands/usage/services/llm-usage-command.service.d.ts +22 -0
  69. package/dist/cli/commands/usage/services/llm-usage-command.service.js +160 -0
  70. package/dist/cli/commands/usage/services/llm-usage-query.service.d.ts +43 -0
  71. package/dist/cli/commands/usage/services/llm-usage-query.service.js +85 -0
  72. package/dist/commands/channel/channel-config-view.d.ts +7 -0
  73. package/dist/commands/channel/channel-config-view.js +7 -0
  74. package/dist/commands/channel/index.d.ts +28 -0
  75. package/dist/commands/channel/index.js +224 -0
  76. package/dist/commands/platform-auth/index.d.ts +2 -0
  77. package/dist/commands/platform-auth/index.js +2 -0
  78. package/dist/commands/platform-auth/services/account-status.service.d.ts +18 -0
  79. package/dist/commands/platform-auth/services/account-status.service.js +34 -0
  80. package/dist/commands/platform-auth/services/platform-auth-commands.service.d.ts +77 -0
  81. package/dist/commands/platform-auth/services/platform-auth-commands.service.js +295 -0
  82. package/dist/commands/platform-auth/utils/payload.utils.d.ts +28 -0
  83. package/dist/commands/platform-auth/utils/payload.utils.js +87 -0
  84. package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.d.ts +18 -0
  85. package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.js +111 -0
  86. package/dist/commands/plugin/development-source/first-party-plugin-load-paths.d.ts +9 -0
  87. package/dist/commands/plugin/development-source/first-party-plugin-load-paths.js +183 -0
  88. package/dist/commands/plugin/index.d.ts +30 -0
  89. package/dist/commands/plugin/index.js +266 -0
  90. package/dist/commands/plugin/plugin-command-utils.d.ts +13 -0
  91. package/dist/commands/plugin/plugin-command-utils.js +37 -0
  92. package/dist/commands/plugin/plugin-extension-registry.d.ts +10 -0
  93. package/dist/commands/plugin/plugin-extension-registry.js +35 -0
  94. package/dist/commands/plugin/plugin-mutation-actions.d.ts +15 -0
  95. package/dist/commands/plugin/plugin-mutation-actions.js +162 -0
  96. package/dist/commands/plugin/plugin-registry-loader.d.ts +15 -0
  97. package/dist/commands/plugin/plugin-registry-loader.js +43 -0
  98. package/dist/commands/plugin/plugin-reload.d.ts +13 -0
  99. package/dist/commands/plugin/plugin-reload.js +42 -0
  100. package/dist/commands/remote/index.d.ts +47 -0
  101. package/dist/commands/remote/index.js +174 -0
  102. package/dist/commands/remote/services/remote-access-host.service.d.ts +41 -0
  103. package/dist/commands/remote/services/remote-access-host.service.js +126 -0
  104. package/dist/commands/remote/services/remote-runtime-support.service.d.ts +15 -0
  105. package/dist/commands/remote/services/remote-runtime-support.service.js +79 -0
  106. package/dist/commands/remote/services/remote-service-control.service.d.ts +33 -0
  107. package/dist/commands/remote/services/remote-service-control.service.js +188 -0
  108. package/dist/commands/remote/utils/platform-api-base.utils.d.ts +14 -0
  109. package/dist/commands/remote/utils/platform-api-base.utils.js +39 -0
  110. package/dist/commands/service/index.d.ts +16 -0
  111. package/dist/commands/service/index.js +31 -0
  112. package/dist/commands/service/services/autostart/host-autostart-command.service.d.ts +29 -0
  113. package/dist/commands/service/services/autostart/host-autostart-command.service.js +158 -0
  114. package/dist/commands/service/services/autostart/host-autostart-runtime.service.d.ts +23 -0
  115. package/dist/commands/service/services/autostart/host-autostart-runtime.service.js +53 -0
  116. package/dist/commands/service/services/autostart/host-autostart.service.d.ts +41 -0
  117. package/dist/commands/service/services/autostart/host-autostart.service.js +48 -0
  118. package/dist/commands/service/services/autostart/linux-systemd-autostart.service.d.ts +48 -0
  119. package/dist/commands/service/services/autostart/linux-systemd-autostart.service.js +433 -0
  120. package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.d.ts +54 -0
  121. package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.js +405 -0
  122. package/dist/commands/service/services/autostart/windows-task-autostart.service.d.ts +54 -0
  123. package/dist/commands/service/services/autostart/windows-task-autostart.service.js +403 -0
  124. package/dist/commands/service/types/autostart/host-autostart.types.d.ts +64 -0
  125. package/dist/commands/service/types/autostart/host-autostart.types.js +1 -0
  126. package/dist/index.d.ts +4 -0
  127. package/dist/index.js +3 -0
  128. package/dist/launcher/npm-runtime-bundle-layout.store.d.ts +23 -0
  129. package/dist/launcher/npm-runtime-bundle-layout.store.js +37 -0
  130. package/dist/launcher/npm-runtime-bundle-manifest.service.d.ts +9 -0
  131. package/dist/launcher/npm-runtime-bundle-manifest.service.js +39 -0
  132. package/dist/launcher/npm-runtime-bundle.service.d.ts +47 -0
  133. package/dist/launcher/npm-runtime-bundle.service.js +150 -0
  134. package/dist/launcher/npm-runtime-bundle.types.d.ts +49 -0
  135. package/dist/launcher/npm-runtime-bundle.types.js +1 -0
  136. package/dist/launcher/npm-runtime-launcher.service.d.ts +19 -0
  137. package/dist/launcher/npm-runtime-launcher.service.js +57 -0
  138. package/dist/launcher/npm-runtime-update-command.service.d.ts +12 -0
  139. package/dist/launcher/npm-runtime-update-command.service.js +87 -0
  140. package/dist/launcher/npm-runtime-update-source.service.d.ts +19 -0
  141. package/dist/launcher/npm-runtime-update-source.service.js +57 -0
  142. package/dist/launcher/npm-runtime-update-state.store.d.ts +17 -0
  143. package/dist/launcher/npm-runtime-update-state.store.js +92 -0
  144. package/dist/launcher/npm-runtime-update.manager.d.ts +42 -0
  145. package/dist/launcher/npm-runtime-update.manager.js +179 -0
  146. package/dist/launcher/npm-runtime-update.service.d.ts +54 -0
  147. package/dist/launcher/npm-runtime-update.service.js +183 -0
  148. package/dist/service-runtime.service.d.ts +91 -0
  149. package/dist/service-runtime.service.js +392 -0
  150. package/dist/shared/controllers/gateway.controller.d.ts +61 -0
  151. package/dist/shared/controllers/gateway.controller.js +318 -0
  152. package/dist/shared/services/extensions/extension-lifecycle.service.d.ts +56 -0
  153. package/dist/shared/services/extensions/extension-lifecycle.service.js +143 -0
  154. package/dist/shared/services/extensions/service-extension-runtime.service.d.ts +51 -0
  155. package/dist/shared/services/extensions/service-extension-runtime.service.js +338 -0
  156. package/dist/shared/services/gateway/cron-job-handler.service.d.ts +26 -0
  157. package/dist/shared/services/gateway/cron-job-handler.service.js +100 -0
  158. package/dist/shared/services/gateway/gateway-restart-wake.service.d.ts +12 -0
  159. package/dist/shared/services/gateway/gateway-restart-wake.service.js +91 -0
  160. package/dist/shared/services/gateway/managers/gateway-plugin.manager.d.ts +37 -0
  161. package/dist/shared/services/gateway/managers/gateway-plugin.manager.js +218 -0
  162. package/dist/shared/services/gateway/managers/gateway-remote.manager.d.ts +20 -0
  163. package/dist/shared/services/gateway/managers/gateway-remote.manager.js +25 -0
  164. package/dist/shared/services/gateway/nextclaw-app.service.d.ts +22 -0
  165. package/dist/shared/services/gateway/nextclaw-app.service.js +53 -0
  166. package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.d.ts +89 -0
  167. package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.js +337 -0
  168. package/dist/shared/services/gateway/service-bootstrap-status.d.ts +33 -0
  169. package/dist/shared/services/gateway/service-bootstrap-status.js +152 -0
  170. package/dist/shared/services/gateway/service-startup-support.service.d.ts +42 -0
  171. package/dist/shared/services/gateway/service-startup-support.service.js +96 -0
  172. package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.d.ts +9 -0
  173. package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.js +10 -0
  174. package/dist/shared/services/marketplace/service-marketplace-installer.service.d.ts +31 -0
  175. package/dist/shared/services/marketplace/service-marketplace-installer.service.js +99 -0
  176. package/dist/shared/services/marketplace/service-mcp-marketplace-ops.d.ts +39 -0
  177. package/dist/shared/services/marketplace/service-mcp-marketplace-ops.js +67 -0
  178. package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.d.ts +24 -0
  179. package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.js +117 -0
  180. package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.d.ts +6 -0
  181. package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.js +96 -0
  182. package/dist/shared/services/restart/restart-coordinator.service.d.ts +30 -0
  183. package/dist/shared/services/restart/restart-coordinator.service.js +51 -0
  184. package/dist/shared/services/restart/restart-sentinel.service.d.ts +39 -0
  185. package/dist/shared/services/restart/restart-sentinel.service.js +88 -0
  186. package/dist/shared/services/restart/runtime-restart-request.service.d.ts +24 -0
  187. package/dist/shared/services/restart/runtime-restart-request.service.js +42 -0
  188. package/dist/shared/services/runtime/runtime-command.service.d.ts +37 -0
  189. package/dist/shared/services/runtime/runtime-command.service.js +163 -0
  190. package/dist/shared/services/runtime/runtime-config-init.service.d.ts +4 -0
  191. package/dist/shared/services/runtime/runtime-config-init.service.js +10 -0
  192. package/dist/shared/services/runtime/service-managed-startup.service.d.ts +146 -0
  193. package/dist/shared/services/runtime/service-managed-startup.service.js +426 -0
  194. package/dist/shared/services/runtime/service-remote-runtime.service.d.ts +53 -0
  195. package/dist/shared/services/runtime/service-remote-runtime.service.js +173 -0
  196. package/dist/shared/services/runtime/utils/skills-loader.utils.d.ts +12 -0
  197. package/dist/shared/services/runtime/utils/skills-loader.utils.js +9 -0
  198. package/dist/shared/services/session/service-deferred-ncp-agent.service.d.ts +14 -0
  199. package/dist/shared/services/session/service-deferred-ncp-agent.service.js +85 -0
  200. package/dist/shared/services/ui/companion-runtime.service.d.ts +33 -0
  201. package/dist/shared/services/ui/companion-runtime.service.js +145 -0
  202. package/dist/shared/services/ui/local-ui-discovery.service.d.ts +19 -0
  203. package/dist/shared/services/ui/local-ui-discovery.service.js +41 -0
  204. package/dist/shared/services/ui/npm-runtime-update-host.service.d.ts +40 -0
  205. package/dist/shared/services/ui/npm-runtime-update-host.service.js +181 -0
  206. package/dist/shared/services/ui/runtime-control-host.service.d.ts +28 -0
  207. package/dist/shared/services/ui/runtime-control-host.service.js +89 -0
  208. package/dist/shared/services/ui/service-remote-access.service.d.ts +25 -0
  209. package/dist/shared/services/ui/service-remote-access.service.js +38 -0
  210. package/dist/shared/services/ui/ui-bridge-api.service.d.ts +16 -0
  211. package/dist/shared/services/ui/ui-bridge-api.service.js +43 -0
  212. package/dist/shared/services/workspace/workspace-manager.service.d.ts +19 -0
  213. package/dist/shared/services/workspace/workspace-manager.service.js +135 -0
  214. package/dist/shared/stores/companion-runtime.store.d.ts +15 -0
  215. package/dist/shared/stores/companion-runtime.store.js +27 -0
  216. package/dist/shared/stores/local-ui-runtime.store.d.ts +25 -0
  217. package/dist/shared/stores/local-ui-runtime.store.js +54 -0
  218. package/dist/shared/stores/managed-service-state.store.d.ts +28 -0
  219. package/dist/shared/stores/managed-service-state.store.js +38 -0
  220. package/dist/shared/stores/pending-restart.store.d.ts +21 -0
  221. package/dist/shared/stores/pending-restart.store.js +35 -0
  222. package/dist/shared/types/cli.types.d.ts +295 -0
  223. package/dist/shared/types/cli.types.js +1 -0
  224. package/dist/shared/utils/cli.utils.d.ts +34 -0
  225. package/dist/shared/utils/cli.utils.js +262 -0
  226. package/dist/shared/utils/config-path.d.ts +15 -0
  227. package/dist/shared/utils/config-path.js +167 -0
  228. package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.d.ts +16 -0
  229. package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.js +46 -0
  230. package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.d.ts +9 -0
  231. package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.js +33 -0
  232. package/dist/shared/utils/package/package-manifest.utils.d.ts +8 -0
  233. package/dist/shared/utils/package/package-manifest.utils.js +48 -0
  234. package/dist/shared/utils/runtime-helpers.d.ts +14 -0
  235. package/dist/shared/utils/runtime-helpers.js +26 -0
  236. package/dist/shared/utils/service-port-probe.utils.d.ts +41 -0
  237. package/dist/shared/utils/service-port-probe.utils.js +164 -0
  238. package/dist/shared/utils/startup-trace.d.ts +7 -0
  239. package/dist/shared/utils/startup-trace.js +37 -0
  240. package/dist/shared/utils/top-level-nextclaw-command-env.utils.d.ts +4 -0
  241. package/dist/shared/utils/top-level-nextclaw-command-env.utils.js +10 -0
  242. package/package.json +68 -0
@@ -0,0 +1,392 @@
1
+ import { getPackageVersion as getPackageVersion$1 } from "./shared/utils/package/package-manifest.utils.js";
2
+ import { isProcessRunning } from "./shared/utils/cli.utils.js";
3
+ import { NpmRuntimeLauncher } from "./launcher/npm-runtime-launcher.service.js";
4
+ import { NpmRuntimeUpdateCommandService } from "./launcher/npm-runtime-update-command.service.js";
5
+ import { managedServiceStateStore } from "./shared/stores/managed-service-state.store.js";
6
+ import { logStartupTrace, measureStartupSync } from "./shared/utils/startup-trace.js";
7
+ import { createTopLevelNextclawCommandEnv } from "./shared/utils/top-level-nextclaw-command-env.utils.js";
8
+ import { writeRestartSentinel } from "./shared/services/restart/restart-sentinel.service.js";
9
+ import { hasRunningNextclawManagedService } from "./commands/remote/services/remote-runtime-support.service.js";
10
+ import { RemoteCommands } from "./commands/remote/index.js";
11
+ import { PlatformAuthCommands } from "./commands/platform-auth/services/platform-auth-commands.service.js";
12
+ import "./commands/platform-auth/index.js";
13
+ import { WorkspaceManager } from "./shared/services/workspace/workspace-manager.service.js";
14
+ import { toExtensionRegistry } from "./commands/plugin/plugin-extension-registry.js";
15
+ import { PluginCommands, loadPluginRegistry, logPluginDiagnostics, mergePluginConfigView, toPluginConfigView as toPluginConfigView$1 } from "./commands/plugin/index.js";
16
+ import { RuntimeCommandService } from "./shared/services/runtime/runtime-command.service.js";
17
+ import { initializeConfigIfMissing } from "./shared/services/runtime/runtime-config-init.service.js";
18
+ import { RuntimeRestartRequestService } from "./shared/services/restart/runtime-restart-request.service.js";
19
+ import { RestartCoordinator } from "./shared/services/restart/restart-coordinator.service.js";
20
+ import { UiCommands } from "./cli/commands/ui/index.js";
21
+ import { ChannelCommands } from "./commands/channel/index.js";
22
+ import { ConfigCommands } from "./cli/commands/config/services/config-commands.service.js";
23
+ import "./cli/commands/config/index.js";
24
+ import { SecretsCommands } from "./cli/commands/secrets/index.js";
25
+ import { StartCommands } from "./cli/commands/start/index.js";
26
+ import { StopCommands } from "./cli/commands/stop/index.js";
27
+ import { LlmUsageCommandService } from "./cli/commands/usage/services/llm-usage-command.service.js";
28
+ import "./cli/commands/usage/index.js";
29
+ import { runCliAgentCommand } from "./cli/commands/agent/cli-agent-runner.utils.js";
30
+ import { AgentCommands } from "./cli/commands/agent/services/agent-commands.service.js";
31
+ import "./cli/commands/agent/index.js";
32
+ import { McpCommands } from "./cli/commands/mcp/index.js";
33
+ import { RestartCommands } from "./cli/commands/restart/index.js";
34
+ import { LogsCommands } from "./cli/commands/logs/index.js";
35
+ import { DiagnosticsCommands } from "./cli/commands/diagnostics/services/diagnostics-commands.service.js";
36
+ import "./cli/commands/diagnostics/index.js";
37
+ import { SkillsCommands } from "./cli/commands/skills/index.js";
38
+ import { ServeCommands } from "./cli/commands/serve/index.js";
39
+ import { GatewayCommands } from "./cli/commands/gateway/index.js";
40
+ import { CronCommands } from "./cli/commands/cron/services/cron-commands.service.js";
41
+ import "./cli/commands/cron/index.js";
42
+ import { CompanionCommands } from "./cli/commands/companion/index.js";
43
+ import { ServiceCommands } from "./commands/service/index.js";
44
+ import { spawn } from "node:child_process";
45
+ import { fileURLToPath } from "node:url";
46
+ import { join } from "node:path";
47
+ import { APP_NAME, DEFAULT_WORKSPACE_DIR, DEFAULT_WORKSPACE_PATH, expandHome, getConfigPath, getDataDir, getWorkspacePath, loadConfig, resolveConfigSecrets, saveConfig } from "@nextclaw/core";
48
+ import { existsSync, mkdirSync } from "node:fs";
49
+ import { RemoteRuntimeActions } from "@nextclaw/remote";
50
+ import { getPluginChannelBindings, resolvePluginChannelMessageToolHints, setPluginRuntimeBridge } from "@nextclaw/openclaw-compat";
51
+ import { NextclawKernel } from "@nextclaw/kernel";
52
+ //#region src/service-runtime.service.ts
53
+ const FORCED_PUBLIC_UI_HOST = "0.0.0.0";
54
+ var NextclawServiceRuntime = class {
55
+ logo;
56
+ restartCoordinator;
57
+ serviceRestartTask = null;
58
+ selfRelaunchArmed = false;
59
+ restartRequestService;
60
+ workspaceManager;
61
+ runtimeCommandService;
62
+ platformAuthCommands;
63
+ remoteCommands;
64
+ account;
65
+ commands;
66
+ constructor(options = {}) {
67
+ logStartupTrace("cli.runtime.constructor.begin");
68
+ this.logo = options.logo ?? "🤖";
69
+ this.workspaceManager = measureStartupSync("cli.runtime.workspace_manager", () => new WorkspaceManager(this.logo));
70
+ this.runtimeCommandService = measureStartupSync("cli.runtime.runtime_command_service", () => new RuntimeCommandService({
71
+ requestRestart: (params) => this.requestRestart(params),
72
+ initializeAgentHomeDirectory: (homeDirectory) => this.workspaceManager.createWorkspaceTemplates(homeDirectory)
73
+ }));
74
+ this.commands = this.createCommands();
75
+ this.restartCoordinator = measureStartupSync("cli.runtime.restart_coordinator", () => new RestartCoordinator({
76
+ readServiceState: managedServiceStateStore.read,
77
+ isProcessRunning,
78
+ currentPid: () => process.pid,
79
+ restartBackgroundService: async (reason) => this.restartBackgroundService(reason),
80
+ scheduleProcessExit: (delayMs, reason) => this.scheduleProcessExit(delayMs, reason)
81
+ }));
82
+ this.restartRequestService = new RuntimeRestartRequestService({
83
+ armManagedServiceRelaunch: (params) => this.armManagedServiceRelaunch(params),
84
+ requestRestartFromCoordinator: async (params) => await this.restartCoordinator.requestRestart(params)
85
+ });
86
+ this.account = {
87
+ status: async (opts = {}) => {
88
+ await this.init({
89
+ source: "account status",
90
+ auto: true
91
+ });
92
+ await this.platformAuthCommands.accountStatus(opts);
93
+ },
94
+ setUsername: async (username, opts = {}) => {
95
+ await this.init({
96
+ source: "account set-username",
97
+ auto: true
98
+ });
99
+ await this.platformAuthCommands.accountSetUsername({
100
+ apiBase: opts.apiBase,
101
+ json: opts.json,
102
+ username
103
+ });
104
+ }
105
+ };
106
+ logStartupTrace("cli.runtime.constructor.end");
107
+ }
108
+ createCommands = () => {
109
+ const start = measureStartupSync("cli.runtime.start_commands", () => new StartCommands({
110
+ runtimeCommandService: this.runtimeCommandService,
111
+ forcedPublicHost: FORCED_PUBLIC_UI_HOST,
112
+ init: (params) => this.init(params)
113
+ }));
114
+ this.platformAuthCommands = measureStartupSync("cli.runtime.platform_auth_commands", () => new PlatformAuthCommands());
115
+ this.remoteCommands = measureStartupSync("cli.runtime.remote_commands", () => new RemoteCommands());
116
+ return {
117
+ remote: measureStartupSync("cli.runtime.remote_runtime_actions", () => new RemoteRuntimeActions({
118
+ appName: APP_NAME,
119
+ initAuto: (source) => this.init({
120
+ source,
121
+ auto: true
122
+ }),
123
+ remoteCommands: this.remoteCommands,
124
+ restartBackgroundService: (reason) => this.restartBackgroundService(reason),
125
+ hasRunningManagedService: hasRunningNextclawManagedService
126
+ })),
127
+ skills: measureStartupSync("cli.runtime.skills_commands", () => new SkillsCommands()),
128
+ service: measureStartupSync("cli.runtime.service_commands", () => new ServiceCommands()),
129
+ config: measureStartupSync("cli.runtime.config_commands", () => new ConfigCommands({ requestRestart: (params) => this.requestRestart(params) })),
130
+ mcp: measureStartupSync("cli.runtime.mcp_commands", () => new McpCommands()),
131
+ secrets: measureStartupSync("cli.runtime.secrets_commands", () => new SecretsCommands({ requestRestart: (params) => this.requestRestart(params) })),
132
+ plugins: measureStartupSync("cli.runtime.plugin_commands", () => new PluginCommands()),
133
+ agents: measureStartupSync("cli.runtime.agent_commands", () => new AgentCommands({ initializeAgentHomeDirectory: (homeDirectory) => this.workspaceManager.createWorkspaceTemplates(homeDirectory) })),
134
+ channels: measureStartupSync("cli.runtime.channel_commands", () => new ChannelCommands({
135
+ logo: this.logo,
136
+ getBridgeDir: () => this.workspaceManager.getBridgeDir(),
137
+ requestRestart: (params) => this.requestRestart(params)
138
+ })),
139
+ cron: measureStartupSync("cli.runtime.cron_commands", () => new CronCommands()),
140
+ diagnostics: measureStartupSync("cli.runtime.diagnostics_commands", () => new DiagnosticsCommands({ logo: this.logo })),
141
+ logs: measureStartupSync("cli.runtime.logs_commands", () => new LogsCommands()),
142
+ gateway: measureStartupSync("cli.runtime.gateway_commands", () => new GatewayCommands({
143
+ runtimeCommandService: this.runtimeCommandService,
144
+ forcedPublicHost: FORCED_PUBLIC_UI_HOST
145
+ })),
146
+ ui: measureStartupSync("cli.runtime.ui_commands", () => new UiCommands({
147
+ runtimeCommandService: this.runtimeCommandService,
148
+ forcedPublicHost: FORCED_PUBLIC_UI_HOST
149
+ })),
150
+ start,
151
+ restart: measureStartupSync("cli.runtime.restart_commands", () => new RestartCommands({
152
+ runtimeCommandService: this.runtimeCommandService,
153
+ startCommands: start,
154
+ forcedPublicHost: FORCED_PUBLIC_UI_HOST,
155
+ writeRestartSentinelFromExecContext: (reason) => this.writeRestartSentinelFromExecContext(reason)
156
+ })),
157
+ serve: measureStartupSync("cli.runtime.serve_commands", () => new ServeCommands({
158
+ runtimeCommandService: this.runtimeCommandService,
159
+ forcedPublicHost: FORCED_PUBLIC_UI_HOST
160
+ })),
161
+ stop: measureStartupSync("cli.runtime.stop_commands", () => new StopCommands({ runtimeCommandService: this.runtimeCommandService })),
162
+ companion: measureStartupSync("cli.runtime.companion_commands", () => new CompanionCommands()),
163
+ usage: measureStartupSync("cli.runtime.usage_commands", () => new LlmUsageCommandService())
164
+ };
165
+ };
166
+ get version() {
167
+ return getPackageVersion$1();
168
+ }
169
+ scheduleProcessExit = (delayMs, reason) => {
170
+ console.warn(`Gateway restart requested (${reason}).`);
171
+ setTimeout(() => {
172
+ process.exit(0);
173
+ }, delayMs);
174
+ };
175
+ restartBackgroundService = async (reason) => {
176
+ if (this.serviceRestartTask) return this.serviceRestartTask;
177
+ this.serviceRestartTask = (async () => {
178
+ const state = managedServiceStateStore.read();
179
+ if (!state || !isProcessRunning(state.pid) || state.pid === process.pid) return false;
180
+ const uiHost = FORCED_PUBLIC_UI_HOST;
181
+ const uiPort = typeof state.uiPort === "number" && Number.isFinite(state.uiPort) ? state.uiPort : 55667;
182
+ console.log(`Applying changes (${reason}): restarting ${APP_NAME} background service...`);
183
+ await this.runtimeCommandService.stopService();
184
+ await this.runtimeCommandService.startService({
185
+ uiOverrides: {
186
+ enabled: true,
187
+ host: uiHost,
188
+ port: uiPort
189
+ },
190
+ open: false
191
+ });
192
+ return true;
193
+ })();
194
+ try {
195
+ return await this.serviceRestartTask;
196
+ } finally {
197
+ this.serviceRestartTask = null;
198
+ }
199
+ };
200
+ armManagedServiceRelaunch = (params) => {
201
+ const { delayMs: requestedDelayMs, reason, strategy: requestedStrategy } = params;
202
+ const strategy = requestedStrategy ?? "background-service-or-manual";
203
+ if (strategy !== "background-service-or-exit" && strategy !== "exit-process") return;
204
+ if (this.selfRelaunchArmed) return;
205
+ const state = managedServiceStateStore.read();
206
+ if (!state || state.pid !== process.pid) return;
207
+ const uiPort = typeof state.uiPort === "number" && Number.isFinite(state.uiPort) ? state.uiPort : 55667;
208
+ const delayMs = typeof requestedDelayMs === "number" && Number.isFinite(requestedDelayMs) ? Math.max(0, Math.floor(requestedDelayMs)) : 100;
209
+ const startArgs = [
210
+ process.env.NEXTCLAW_SELF_RELAUNCH_CLI?.trim() || fileURLToPath(new URL("./index.js", import.meta.url)),
211
+ "start",
212
+ "--ui-port",
213
+ String(uiPort)
214
+ ];
215
+ const serviceStatePath = managedServiceStateStore.path;
216
+ const helperScript = [
217
+ "const { spawnSync } = require(\"node:child_process\");",
218
+ "const { readFileSync } = require(\"node:fs\");",
219
+ `const parentPid = ${process.pid};`,
220
+ `const delayMs = ${delayMs};`,
221
+ "const maxWaitMs = 120000;",
222
+ "const retryIntervalMs = 1000;",
223
+ "const startTimeoutMs = 60000;",
224
+ `const nodePath = ${JSON.stringify(process.execPath)};`,
225
+ `const startArgs = ${JSON.stringify(startArgs)};`,
226
+ `const serviceStatePath = ${JSON.stringify(serviceStatePath)};`,
227
+ "function isRunning(pid) {",
228
+ " try {",
229
+ " process.kill(pid, 0);",
230
+ " return true;",
231
+ " } catch {",
232
+ " return false;",
233
+ " }",
234
+ "}",
235
+ "function hasReplacementService() {",
236
+ " try {",
237
+ " const raw = readFileSync(serviceStatePath, \"utf-8\");",
238
+ " const state = JSON.parse(raw);",
239
+ " const pid = Number(state?.pid);",
240
+ " return Number.isFinite(pid) && pid > 0 && pid !== parentPid && isRunning(pid);",
241
+ " } catch {",
242
+ " return false;",
243
+ " }",
244
+ "}",
245
+ "function tryStart() {",
246
+ " spawnSync(nodePath, startArgs, {",
247
+ " stdio: \"ignore\",",
248
+ " env: process.env,",
249
+ " timeout: startTimeoutMs",
250
+ " });",
251
+ "}",
252
+ "setTimeout(() => {",
253
+ " const startedAt = Date.now();",
254
+ " const tick = () => {",
255
+ " if (hasReplacementService()) {",
256
+ " process.exit(0);",
257
+ " return;",
258
+ " }",
259
+ " if (Date.now() - startedAt >= maxWaitMs) {",
260
+ " process.exit(0);",
261
+ " return;",
262
+ " }",
263
+ " tryStart();",
264
+ " if (hasReplacementService()) {",
265
+ " process.exit(0);",
266
+ " return;",
267
+ " }",
268
+ " setTimeout(tick, retryIntervalMs);",
269
+ " };",
270
+ " tick();",
271
+ "}, delayMs);"
272
+ ].join("\n");
273
+ try {
274
+ spawn(process.execPath, ["-e", helperScript], {
275
+ detached: true,
276
+ stdio: "ignore",
277
+ env: createTopLevelNextclawCommandEnv(process.env)
278
+ }).unref();
279
+ this.selfRelaunchArmed = true;
280
+ console.warn(`Gateway self-restart armed (${reason}).`);
281
+ } catch (error) {
282
+ console.error(`Failed to arm gateway self-restart: ${String(error)}`);
283
+ }
284
+ };
285
+ requestRestart = async (params) => {
286
+ await this.restartRequestService.run(params);
287
+ };
288
+ writeRestartSentinelFromExecContext = async (reason) => {
289
+ const sessionKeyRaw = process.env.NEXTCLAW_RUNTIME_SESSION_KEY;
290
+ const sessionKey = typeof sessionKeyRaw === "string" ? sessionKeyRaw.trim() : "";
291
+ if (!sessionKey) return;
292
+ try {
293
+ await writeRestartSentinel({
294
+ kind: "restart",
295
+ status: "ok",
296
+ ts: Date.now(),
297
+ sessionKey,
298
+ stats: {
299
+ reason: reason || "cli.restart",
300
+ strategy: "exec-tool"
301
+ }
302
+ });
303
+ } catch (error) {
304
+ console.warn(`Warning: failed to write restart sentinel from exec context: ${String(error)}`);
305
+ }
306
+ };
307
+ onboard = async () => {
308
+ console.warn(`Warning: ${APP_NAME} onboard is deprecated. Use "${APP_NAME} init" instead.`);
309
+ await this.init({ source: "onboard" });
310
+ };
311
+ init = async (options = {}) => {
312
+ const source = options.source ?? "init";
313
+ const prefix = options.auto ? "Auto init" : "Init";
314
+ const force = Boolean(options.force);
315
+ const configPath = getConfigPath();
316
+ const createdConfig = initializeConfigIfMissing(configPath);
317
+ const workspaceSetting = loadConfig().agents.defaults.workspace;
318
+ const workspacePath = !workspaceSetting || workspaceSetting === DEFAULT_WORKSPACE_PATH ? join(getDataDir(), DEFAULT_WORKSPACE_DIR) : expandHome(workspaceSetting);
319
+ const workspaceExisted = existsSync(workspacePath);
320
+ mkdirSync(workspacePath, { recursive: true });
321
+ const templateResult = this.workspaceManager.createWorkspaceTemplates(workspacePath, { force });
322
+ if (createdConfig) console.log(`✓ ${prefix}: created config at ${configPath}`);
323
+ if (!workspaceExisted) console.log(`✓ ${prefix}: created workspace at ${workspacePath}`);
324
+ for (const file of templateResult.created) console.log(`✓ ${prefix}: created ${file}`);
325
+ if (!createdConfig && workspaceExisted && templateResult.created.length === 0) console.log(`${prefix}: already initialized.`);
326
+ if (!options.auto) {
327
+ console.log(`\n${this.logo} ${APP_NAME} is ready! (${source})`);
328
+ console.log("\nNext steps:");
329
+ console.log(` 1. Add your API key to ${configPath}`);
330
+ console.log(` 2. Chat: ${APP_NAME} agent -m "Hello!"`);
331
+ } else console.log(`Tip: Run "${APP_NAME} init${force ? " --force" : ""}" to re-run initialization if needed.`);
332
+ };
333
+ login = async (opts = {}) => {
334
+ await this.init({
335
+ source: "login",
336
+ auto: true
337
+ });
338
+ await this.platformAuthCommands.login(opts);
339
+ };
340
+ agent = async (opts) => {
341
+ const configPath = getConfigPath();
342
+ const kernel = new NextclawKernel({
343
+ homeDir: getDataDir(),
344
+ configPath
345
+ });
346
+ const config = kernel.configManager.config;
347
+ const pluginRegistry = loadPluginRegistry(config, getWorkspacePath(config.agents.defaults.workspace));
348
+ const extensionRegistry = toExtensionRegistry(pluginRegistry);
349
+ logPluginDiagnostics(pluginRegistry);
350
+ const pluginChannelBindings = getPluginChannelBindings(pluginRegistry);
351
+ setPluginRuntimeBridge({
352
+ loadConfig: () => toPluginConfigView$1(resolveConfigSecrets(loadConfig(), { configPath }), pluginChannelBindings),
353
+ writeConfigFile: async (nextConfigView) => {
354
+ if (!nextConfigView || typeof nextConfigView !== "object" || Array.isArray(nextConfigView)) throw new Error("plugin runtime writeConfigFile expects an object config");
355
+ saveConfig(mergePluginConfigView(loadConfig(), nextConfigView, pluginChannelBindings));
356
+ }
357
+ });
358
+ try {
359
+ const providerManager = kernel.llmUsage.observeProviderManager(kernel.llmProviders, "cli-agent");
360
+ await runCliAgentCommand({
361
+ logo: this.logo,
362
+ opts,
363
+ config,
364
+ kernel,
365
+ providerManager,
366
+ extensionRegistry,
367
+ loadResolvedConfig: () => resolveConfigSecrets(loadConfig(), { configPath }),
368
+ resolveMessageToolHints: ({ channel, accountId }) => resolvePluginChannelMessageToolHints({
369
+ registry: pluginRegistry,
370
+ channel,
371
+ cfg: resolveConfigSecrets(loadConfig(), { configPath }),
372
+ accountId
373
+ })
374
+ });
375
+ } finally {
376
+ setPluginRuntimeBridge(null);
377
+ }
378
+ };
379
+ update = async (opts) => {
380
+ const versionBefore = getPackageVersion$1();
381
+ if (!opts.json) console.log(`Current npm launcher version: ${versionBefore}`);
382
+ const snapshot = await new NpmRuntimeUpdateCommandService().run(opts);
383
+ if (snapshot.status === "blocked" || snapshot.status === "failed") process.exit(1);
384
+ const state = managedServiceStateStore.read();
385
+ if (snapshot.requiresRestart && state && isProcessRunning(state.pid)) console.log(`Tip: restart ${APP_NAME} to apply the update.`);
386
+ };
387
+ };
388
+ const runNextclawNpmRuntimeLauncher = (argv = process.argv) => {
389
+ new NpmRuntimeLauncher({ argv }).run();
390
+ };
391
+ //#endregion
392
+ export { NextclawServiceRuntime, runNextclawNpmRuntimeLauncher };
@@ -0,0 +1,61 @@
1
+ import { Config, CronService, GatewayController, SessionManager } from "@nextclaw/core";
2
+ import { ChannelManager } from "@nextclaw/kernel";
3
+
4
+ //#region src/shared/controllers/gateway.controller.d.ts
5
+ type ConfigManagerLike = {
6
+ applyReloadPlan: (nextConfig: Config) => Promise<void>;
7
+ reloadConfig: (reason?: string) => Promise<string>;
8
+ };
9
+ type ControllerDeps = {
10
+ configManager: ConfigManagerLike;
11
+ channels: ChannelManager;
12
+ cron: CronService;
13
+ sessionManager?: SessionManager;
14
+ getConfigPath: () => string;
15
+ saveConfig: (config: Config) => void;
16
+ requestRestart?: (options?: {
17
+ delayMs?: number;
18
+ reason?: string;
19
+ }) => Promise<void> | void;
20
+ };
21
+ declare class GatewayControllerImpl implements GatewayController {
22
+ private deps;
23
+ constructor(deps: ControllerDeps);
24
+ private normalizeOptionalString;
25
+ private resolveDeliveryContext;
26
+ private writeRestartSentinelPayload;
27
+ private requestRestart;
28
+ private createConfigMutationResult;
29
+ private applyConfigChange;
30
+ status: () => Record<string, unknown>;
31
+ reloadConfig: (reason?: string) => Promise<string>;
32
+ restart: (options?: {
33
+ delayMs?: number;
34
+ reason?: string;
35
+ sessionKey?: string;
36
+ }) => Promise<string>;
37
+ getConfig: () => Promise<Record<string, unknown>>;
38
+ getConfigSchema: () => Promise<Record<string, unknown>>;
39
+ applyConfig: (params: {
40
+ raw: string;
41
+ baseHash?: string;
42
+ note?: string;
43
+ restartDelayMs?: number;
44
+ sessionKey?: string;
45
+ }) => Promise<Record<string, unknown>>;
46
+ patchConfig: (params: {
47
+ raw: string;
48
+ baseHash?: string;
49
+ note?: string;
50
+ restartDelayMs?: number;
51
+ sessionKey?: string;
52
+ }) => Promise<Record<string, unknown>>;
53
+ updateRun: (params: {
54
+ note?: string;
55
+ restartDelayMs?: number;
56
+ timeoutMs?: number;
57
+ sessionKey?: string;
58
+ }) => Promise<Record<string, unknown>>;
59
+ }
60
+ //#endregion
61
+ export { GatewayControllerImpl };