@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,88 @@
1
+ import { resolve } from "node:path";
2
+ import { getDataDir } from "@nextclaw/core";
3
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
+ //#region src/shared/services/restart/restart-sentinel.service.ts
5
+ const RESTART_SENTINEL_FILENAME = "restart-sentinel.json";
6
+ const PENDING_SYSTEM_EVENTS_KEY = "pending_system_events";
7
+ const RESTART_REASON_MAX_CHARS = 240;
8
+ const RESTART_NOTE_MAX_CHARS = 600;
9
+ const RESTART_OUTBOUND_MAX_CHARS = 1200;
10
+ function trimTo(value, maxChars) {
11
+ const text = value.trim();
12
+ if (!text) return "";
13
+ if (text.length <= maxChars) return text;
14
+ return `${text.slice(0, Math.max(0, maxChars - 1)).trimEnd()}…`;
15
+ }
16
+ function normalizeLine(value, maxChars) {
17
+ const trimmed = trimTo(value, maxChars);
18
+ return trimmed ? trimmed : null;
19
+ }
20
+ function resolveRestartSentinelPath() {
21
+ return resolve(getDataDir(), "run", RESTART_SENTINEL_FILENAME);
22
+ }
23
+ async function writeRestartSentinel(payload) {
24
+ const path = resolveRestartSentinelPath();
25
+ mkdirSync(resolve(path, ".."), { recursive: true });
26
+ writeFileSync(path, `${JSON.stringify({
27
+ version: 1,
28
+ payload
29
+ }, null, 2)}\n`, "utf-8");
30
+ return path;
31
+ }
32
+ async function consumeRestartSentinel() {
33
+ const path = resolveRestartSentinelPath();
34
+ if (!existsSync(path)) return null;
35
+ try {
36
+ const raw = readFileSync(path, "utf-8");
37
+ const parsed = JSON.parse(raw);
38
+ if (!parsed || parsed.version !== 1 || !parsed.payload) {
39
+ rmSync(path, { force: true });
40
+ return null;
41
+ }
42
+ rmSync(path, { force: true });
43
+ return parsed;
44
+ } catch {
45
+ rmSync(path, { force: true });
46
+ return null;
47
+ }
48
+ }
49
+ function summarizeRestartSentinel(payload) {
50
+ const reason = normalizeLine(payload.stats?.reason ?? "", RESTART_REASON_MAX_CHARS);
51
+ if (payload.kind === "update.run") return payload.status === "ok" ? "✅ NextClaw update completed and service restarted." : "⚠️ NextClaw update finished with issues.";
52
+ if (payload.kind === "config.apply" || payload.kind === "config.patch") return payload.status === "ok" ? "✅ Config applied and service restarted." : "⚠️ Config change restart finished with issues.";
53
+ if (reason) return `Gateway restart complete (${reason}).`;
54
+ return "Gateway restart complete.";
55
+ }
56
+ function formatRestartSentinelMessage(payload) {
57
+ const lines = [summarizeRestartSentinel(payload)];
58
+ const note = normalizeLine(payload.message ?? "", RESTART_NOTE_MAX_CHARS);
59
+ if (note) lines.push(note);
60
+ const reason = normalizeLine(payload.stats?.reason ?? "", RESTART_REASON_MAX_CHARS);
61
+ if (reason && !lines.some((line) => line.includes(reason))) lines.push(`Reason: ${reason}`);
62
+ return trimTo(lines.join("\n").trim(), RESTART_OUTBOUND_MAX_CHARS);
63
+ }
64
+ function parseSessionKey(sessionKey) {
65
+ const value = sessionKey?.trim();
66
+ if (!value) return null;
67
+ const separator = value.indexOf(":");
68
+ if (separator <= 0 || separator >= value.length - 1) return null;
69
+ return {
70
+ channel: value.slice(0, separator),
71
+ chatId: value.slice(separator + 1)
72
+ };
73
+ }
74
+ function enqueuePendingSystemEvent(sessionManager, sessionKey, message) {
75
+ const text = message.trim();
76
+ if (!text) return;
77
+ const session = sessionManager.getOrCreate(sessionKey);
78
+ const queueRaw = session.metadata[PENDING_SYSTEM_EVENTS_KEY];
79
+ const queue = Array.isArray(queueRaw) ? queueRaw.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean) : [];
80
+ if (queue.at(-1) === text) return;
81
+ queue.push(text);
82
+ if (queue.length > 20) queue.splice(0, queue.length - 20);
83
+ session.metadata[PENDING_SYSTEM_EVENTS_KEY] = queue;
84
+ session.updatedAt = /* @__PURE__ */ new Date();
85
+ sessionManager.save(session);
86
+ }
87
+ //#endregion
88
+ export { consumeRestartSentinel, enqueuePendingSystemEvent, formatRestartSentinelMessage, parseSessionKey, resolveRestartSentinelPath, summarizeRestartSentinel, writeRestartSentinel };
@@ -0,0 +1,24 @@
1
+ import { RestartResult } from "./restart-coordinator.service.js";
2
+ import { RequestRestartParams } from "../../types/cli.types.js";
3
+
4
+ //#region src/shared/services/restart/runtime-restart-request.service.d.ts
5
+ type RuntimeRestartRequestServiceDeps = {
6
+ armManagedServiceRelaunch: (params: {
7
+ delayMs?: number;
8
+ reason: string;
9
+ strategy?: RequestRestartParams["strategy"];
10
+ }) => void;
11
+ requestRestartFromCoordinator: (params: {
12
+ delayMs?: number;
13
+ manualMessage?: string;
14
+ reason: string;
15
+ strategy?: RequestRestartParams["strategy"];
16
+ }) => Promise<RestartResult>;
17
+ };
18
+ declare class RuntimeRestartRequestService {
19
+ private readonly deps;
20
+ constructor(deps: RuntimeRestartRequestServiceDeps);
21
+ readonly run: (params: RequestRestartParams) => Promise<void>;
22
+ }
23
+ //#endregion
24
+ export { RuntimeRestartRequestService };
@@ -0,0 +1,42 @@
1
+ import { pendingRestartStore } from "../../stores/pending-restart.store.js";
2
+ //#region src/shared/services/restart/runtime-restart-request.service.ts
3
+ var RuntimeRestartRequestService = class {
4
+ constructor(deps) {
5
+ this.deps = deps;
6
+ }
7
+ run = async (params) => {
8
+ const { changedPaths, delayMs, manualMessage, mode, reason, silentOnServiceRestart, strategy } = params;
9
+ if (mode === "notify") {
10
+ pendingRestartStore.mark({
11
+ changedPaths,
12
+ manualMessage,
13
+ reason
14
+ });
15
+ console.warn(manualMessage);
16
+ return;
17
+ }
18
+ this.deps.armManagedServiceRelaunch({
19
+ reason,
20
+ strategy,
21
+ delayMs
22
+ });
23
+ const result = await this.deps.requestRestartFromCoordinator({
24
+ reason,
25
+ strategy,
26
+ delayMs,
27
+ manualMessage
28
+ });
29
+ if (result.status === "manual-required" || result.status === "restart-in-progress") {
30
+ console.log(result.message);
31
+ return;
32
+ }
33
+ pendingRestartStore.clear();
34
+ if (result.status === "service-restarted") {
35
+ if (!silentOnServiceRestart) console.log(result.message);
36
+ return;
37
+ }
38
+ console.warn(result.message);
39
+ };
40
+ };
41
+ //#endregion
42
+ export { RuntimeRestartRequestService };
@@ -0,0 +1,37 @@
1
+ import { RequestRestartParams } from "../../types/cli.types.js";
2
+ import { StartServiceOptions } from "./service-managed-startup.service.js";
3
+ import { describeUnmanagedHealthyTargetMessage } from "../../utils/service-port-probe.utils.js";
4
+ import { buildMarketplaceSkillInstallArgs, pickUserFacingCommandSummary } from "../../utils/marketplace/service-marketplace-helpers.utils.js";
5
+ import * as NextclawCore from "@nextclaw/core";
6
+
7
+ //#region src/shared/services/runtime/runtime-command.service.d.ts
8
+ type Config$1 = NextclawCore.Config;
9
+ declare class RuntimeCommandService {
10
+ private deps;
11
+ private loggingInstalled;
12
+ private readonly managedServiceCommandService;
13
+ constructor(deps: {
14
+ requestRestart: (params: RequestRestartParams) => Promise<void>;
15
+ initializeAgentHomeDirectory: (homeDirectory: string) => void;
16
+ });
17
+ startGateway: (options?: {
18
+ uiOverrides?: Partial<Config$1["ui"]>;
19
+ uiStaticDir?: string | null;
20
+ }) => Promise<void>;
21
+ startService: (options: StartServiceOptions) => Promise<void>;
22
+ stopService: () => Promise<void>;
23
+ runForeground: (options: {
24
+ uiOverrides: Partial<Config$1["ui"]>;
25
+ open: boolean;
26
+ }) => Promise<void>;
27
+ private installBuiltinMarketplaceSkill;
28
+ private mergeCommandOutput;
29
+ private runCliSubcommand;
30
+ private runCommand;
31
+ private ensureRuntimeLoggingInstalled;
32
+ private checkUiPortPreflight;
33
+ private printPublicUiUrls;
34
+ private printServiceControlHints;
35
+ }
36
+ //#endregion
37
+ export { RuntimeCommandService, buildMarketplaceSkillInstallArgs, describeUnmanagedHealthyTargetMessage, pickUserFacingCommandSummary };
@@ -0,0 +1,163 @@
1
+ import { isLoopbackHost, resolvePublicIp } from "../../utils/cli.utils.js";
2
+ import { describeUnmanagedHealthyTargetMessage, inspectUiTarget } from "../../utils/service-port-probe.utils.js";
3
+ import { buildMarketplaceSkillInstallArgs, pickUserFacingCommandSummary } from "../../utils/marketplace/service-marketplace-helpers.utils.js";
4
+ import { resolveCliSubcommandEntry } from "../../utils/marketplace/cli-subcommand-launch.utils.js";
5
+ import { ManagedServiceCommandService } from "./service-managed-startup.service.js";
6
+ import { NextclawGatewayRuntime } from "../gateway/nextclaw-gateway-runtime.service.js";
7
+ import { createSkillsLoader } from "./utils/skills-loader.utils.js";
8
+ import { spawn } from "node:child_process";
9
+ import * as NextclawCore from "@nextclaw/core";
10
+ //#region src/shared/services/runtime/runtime-command.service.ts
11
+ const { getWorkspacePath: getWorkspacePath$1, loadConfig: loadConfig$1 } = NextclawCore;
12
+ var RuntimeCommandService = class {
13
+ loggingInstalled = false;
14
+ managedServiceCommandService = new ManagedServiceCommandService({
15
+ startGateway: async (options) => await this.startGateway(options),
16
+ printPublicUiUrls: async (host, port) => await this.printPublicUiUrls(host, port),
17
+ printServiceControlHints: () => this.printServiceControlHints(),
18
+ checkUiPortPreflight: async (params) => await this.checkUiPortPreflight(params)
19
+ });
20
+ constructor(deps) {
21
+ this.deps = deps;
22
+ }
23
+ startGateway = async (options = {}) => {
24
+ this.ensureRuntimeLoggingInstalled();
25
+ await new NextclawGatewayRuntime({
26
+ requestRestart: this.deps.requestRestart,
27
+ initializeAgentHomeDirectory: this.deps.initializeAgentHomeDirectory,
28
+ startService: this.startService,
29
+ stopService: this.stopService,
30
+ runCliSubcommand: this.runCliSubcommand,
31
+ installBuiltinMarketplaceSkill: this.installBuiltinMarketplaceSkill
32
+ }, options).start();
33
+ };
34
+ startService = async (options) => {
35
+ await this.managedServiceCommandService.startService(options);
36
+ };
37
+ stopService = async () => {
38
+ await this.managedServiceCommandService.stopService();
39
+ };
40
+ runForeground = async (options) => {
41
+ await this.managedServiceCommandService.runForeground(options);
42
+ };
43
+ installBuiltinMarketplaceSkill = (slug, _force) => {
44
+ if (!(createSkillsLoader(getWorkspacePath$1(loadConfig$1().agents.defaults.workspace))?.listSkills(false) ?? []).find((skill) => skill.name === slug && skill.source === "builtin")) return null;
45
+ return { message: `${slug} is already available (built-in)` };
46
+ };
47
+ mergeCommandOutput = (stdout, stderr) => {
48
+ return `${stdout}\n${stderr}`.trim();
49
+ };
50
+ runCliSubcommand = (args, timeoutMs = 18e4) => {
51
+ const cliEntry = resolveCliSubcommandEntry({
52
+ argvEntry: process.argv[1],
53
+ importMetaUrl: import.meta.url
54
+ });
55
+ return this.runCommand(process.execPath, [
56
+ ...process.execArgv,
57
+ cliEntry,
58
+ ...args
59
+ ], {
60
+ cwd: process.cwd(),
61
+ timeoutMs
62
+ }).then((result) => this.mergeCommandOutput(result.stdout, result.stderr));
63
+ };
64
+ runCommand = (command, args, options = {}) => {
65
+ const timeoutMs = options.timeoutMs ?? 18e4;
66
+ return new Promise((resolvePromise, rejectPromise) => {
67
+ const child = spawn(command, args, {
68
+ cwd: options.cwd ?? process.cwd(),
69
+ env: process.env,
70
+ stdio: [
71
+ "ignore",
72
+ "pipe",
73
+ "pipe"
74
+ ]
75
+ });
76
+ let stdout = "";
77
+ let stderr = "";
78
+ child.stdout?.setEncoding("utf-8");
79
+ child.stderr?.setEncoding("utf-8");
80
+ child.stdout?.on("data", (chunk) => {
81
+ stdout += chunk;
82
+ });
83
+ child.stderr?.on("data", (chunk) => {
84
+ stderr += chunk;
85
+ });
86
+ const timer = setTimeout(() => {
87
+ child.kill("SIGTERM");
88
+ rejectPromise(/* @__PURE__ */ new Error(`command timed out after ${timeoutMs}ms`));
89
+ }, timeoutMs);
90
+ child.on("error", (error) => {
91
+ clearTimeout(timer);
92
+ rejectPromise(/* @__PURE__ */ new Error(`failed to start command: ${String(error)}`));
93
+ });
94
+ child.on("close", (code) => {
95
+ clearTimeout(timer);
96
+ const output = this.mergeCommandOutput(stdout, stderr);
97
+ if (code === 0) {
98
+ resolvePromise({
99
+ stdout,
100
+ stderr
101
+ });
102
+ return;
103
+ }
104
+ rejectPromise(new Error(output || `command failed with code ${code ?? 1}`));
105
+ });
106
+ });
107
+ };
108
+ ensureRuntimeLoggingInstalled = () => {
109
+ if (this.loggingInstalled) return;
110
+ NextclawCore.configureAppLogging({
111
+ installConsoleMirror: true,
112
+ installProcessCrashMonitor: true
113
+ });
114
+ this.loggingInstalled = true;
115
+ };
116
+ checkUiPortPreflight = async (params) => {
117
+ const target = await inspectUiTarget(params);
118
+ if (target.state === "available") return {
119
+ ok: true,
120
+ reusedExistingHealthyTarget: false
121
+ };
122
+ if (target.state === "healthy-existing") return {
123
+ ok: true,
124
+ reusedExistingHealthyTarget: true
125
+ };
126
+ const lines = [`Port probe: ${target.availabilityDetail}`];
127
+ if (target.probeError) lines.push(`Health probe: ${target.probeError}`);
128
+ lines.push("The port is occupied by a process that does not answer as a healthy NextClaw HTTP server.");
129
+ lines.push(`Fix: free port ${params.port} or start NextClaw with another port via --ui-port <port>.`);
130
+ lines.push(`Inspect locally with: ss -ltnp | grep ${params.port} || lsof -iTCP:${params.port} -sTCP:LISTEN -n -P`);
131
+ return {
132
+ ok: false,
133
+ message: lines.join("\n")
134
+ };
135
+ };
136
+ printPublicUiUrls = async (host, port) => {
137
+ if (isLoopbackHost(host)) {
138
+ console.log("Public URL: disabled (UI host is loopback). Current release expects public exposure; run nextclaw restart.");
139
+ return;
140
+ }
141
+ const publicIp = await resolvePublicIp();
142
+ if (!publicIp) {
143
+ console.log("Public URL: UI is exposed, but automatic public IP detection failed.");
144
+ return;
145
+ }
146
+ const publicBase = `http://${publicIp}:${port}`;
147
+ console.log(`Public UI (if firewall/NAT allows): ${publicBase}`);
148
+ console.log(`Public API (if firewall/NAT allows): ${publicBase}/api`);
149
+ console.log(`Public deploy note: NextClaw serves plain HTTP on ${port}.`);
150
+ console.log(`For https:// or standard 80/443 access, terminate TLS in Nginx/Caddy and proxy to http://127.0.0.1:${port}.`);
151
+ console.log(`If a reverse proxy returns 502, verify its upstream is http://127.0.0.1:${port} (not https://, not a stale port, and not a stopped process).`);
152
+ };
153
+ printServiceControlHints = () => {
154
+ console.log("Service controls:");
155
+ console.log(" - Check status: NextClaw status");
156
+ console.log(" - If you need to stop the service, run: NextClaw stop");
157
+ console.log(" - View log paths: NextClaw logs path");
158
+ console.log(" - Tail recent logs: NextClaw logs tail");
159
+ console.log(" - Check autostart: NextClaw service autostart status --user");
160
+ };
161
+ };
162
+ //#endregion
163
+ export { RuntimeCommandService, buildMarketplaceSkillInstallArgs, describeUnmanagedHealthyTargetMessage, pickUserFacingCommandSummary };
@@ -0,0 +1,4 @@
1
+ //#region src/shared/services/runtime/runtime-config-init.service.d.ts
2
+ declare function initializeConfigIfMissing(configPath?: string): boolean;
3
+ //#endregion
4
+ export { initializeConfigIfMissing };
@@ -0,0 +1,10 @@
1
+ import { getConfigPath, loadConfig } from "@nextclaw/core";
2
+ import { existsSync } from "node:fs";
3
+ //#region src/shared/services/runtime/runtime-config-init.service.ts
4
+ function initializeConfigIfMissing(configPath = getConfigPath()) {
5
+ if (existsSync(configPath)) return false;
6
+ loadConfig(configPath);
7
+ return true;
8
+ }
9
+ //#endregion
10
+ export { initializeConfigIfMissing };
@@ -0,0 +1,146 @@
1
+ import { ManagedServiceState } from "../../stores/managed-service-state.store.js";
2
+ import { localUiRuntimeStore } from "../../stores/local-ui-runtime.store.js";
3
+ import { spawn } from "node:child_process";
4
+ import * as NextclawCore from "@nextclaw/core";
5
+
6
+ //#region src/shared/services/runtime/service-managed-startup.service.d.ts
7
+ type Config$1 = NextclawCore.Config;
8
+ type StartServiceOptions = {
9
+ uiOverrides: Partial<Config$1["ui"]>;
10
+ open: boolean;
11
+ startupTimeoutMs?: number;
12
+ };
13
+ type ManagedServiceSnapshot = {
14
+ pid: number;
15
+ uiUrl: string;
16
+ apiUrl: string;
17
+ uiHost: string;
18
+ uiPort: number;
19
+ logPath: string;
20
+ };
21
+ declare function resolveManagedServiceReadySnapshot(params: {
22
+ snapshot: ManagedServiceSnapshot;
23
+ readLocalUiRuntimeState?: typeof localUiRuntimeStore.read;
24
+ isProcessRunningFn?: (pid: number) => boolean;
25
+ }): ManagedServiceSnapshot;
26
+ declare function resolveManagedServiceUiBinding(state: ManagedServiceState): {
27
+ host: string;
28
+ port: number;
29
+ };
30
+ declare function resolveSessionRouteCandidate(params: {
31
+ session: unknown;
32
+ normalizeOptionalString: (value: unknown) => string | undefined;
33
+ }): {
34
+ key: string;
35
+ updatedAt: number;
36
+ } | null;
37
+ declare function spawnManagedService(params: {
38
+ appName: string;
39
+ config: NextclawCore.Config;
40
+ uiConfig: {
41
+ host: string;
42
+ port: number;
43
+ };
44
+ uiUrl: string;
45
+ apiUrl: string;
46
+ healthUrl: string;
47
+ startupTimeoutMs?: number;
48
+ resolveStartupTimeoutMs: (overrideTimeoutMs: number | undefined) => number;
49
+ appendStartupStage: (logPath: string, message: string) => void;
50
+ printStartupFailureDiagnostics: (params: {
51
+ uiUrl: string;
52
+ apiUrl: string;
53
+ healthUrl: string;
54
+ logPath: string;
55
+ lastProbeError: string | null;
56
+ }) => void;
57
+ resolveServiceLogPath: () => string;
58
+ }): {
59
+ child: ReturnType<typeof spawn>;
60
+ logPath: string;
61
+ readinessTimeoutMs: number;
62
+ quickPhaseTimeoutMs: number;
63
+ extendedPhaseTimeoutMs: number;
64
+ snapshot: ManagedServiceSnapshot;
65
+ } | null;
66
+ declare function waitForManagedServiceReadiness(params: {
67
+ appName: string;
68
+ childPid: number;
69
+ healthUrl: string;
70
+ logPath: string;
71
+ readinessTimeoutMs: number;
72
+ quickPhaseTimeoutMs: number;
73
+ extendedPhaseTimeoutMs: number;
74
+ appendStartupStage: (logPath: string, message: string) => void;
75
+ waitForBackgroundServiceReady: (params: {
76
+ pid: number;
77
+ healthUrl: string;
78
+ timeoutMs: number;
79
+ }) => Promise<{
80
+ ready: boolean;
81
+ lastProbeError: string | null;
82
+ }>;
83
+ isProcessRunning: (pid: number) => boolean;
84
+ }): Promise<{
85
+ ready: boolean;
86
+ lastProbeError: string | null;
87
+ }>;
88
+ declare function reportManagedServiceStart(params: {
89
+ appName: string;
90
+ state: {
91
+ pid: number;
92
+ logPath: string;
93
+ };
94
+ uiConfig: {
95
+ host: string;
96
+ port: number;
97
+ };
98
+ uiUrl: string;
99
+ apiUrl: string;
100
+ readinessTimeoutMs: number;
101
+ readiness: {
102
+ ready: boolean;
103
+ lastProbeError: string | null;
104
+ };
105
+ printPublicUiUrls: (host: string, port: number) => Promise<void>;
106
+ printServiceControlHints: () => void;
107
+ }): Promise<void>;
108
+ declare class ManagedServiceCommandService {
109
+ private readonly deps;
110
+ private readonly loggingRuntime;
111
+ private readonly serviceLogger;
112
+ constructor(deps: {
113
+ startGateway: (options: {
114
+ uiOverrides: Partial<Config$1["ui"]>;
115
+ uiStaticDir?: string | null;
116
+ }) => Promise<void>;
117
+ printPublicUiUrls: (host: string, port: number) => Promise<void>;
118
+ printServiceControlHints: () => void;
119
+ checkUiPortPreflight: (params: {
120
+ host: string;
121
+ port: number;
122
+ healthUrl: string;
123
+ }) => Promise<{
124
+ ok: true;
125
+ reusedExistingHealthyTarget: boolean;
126
+ } | {
127
+ ok: false;
128
+ message: string;
129
+ }>;
130
+ });
131
+ runForeground: (options: {
132
+ uiOverrides: Partial<Config$1["ui"]>;
133
+ open: boolean;
134
+ }) => Promise<void>;
135
+ startService: (options: StartServiceOptions) => Promise<void>;
136
+ stopService: () => Promise<void>;
137
+ private handleExistingManagedService;
138
+ private reuseExistingHealthyStartTarget;
139
+ private startNewManagedServiceTarget;
140
+ private waitForBackgroundServiceReady;
141
+ private resolveStartupTimeoutMs;
142
+ private appendStartupStage;
143
+ private printStartupFailureDiagnostics;
144
+ }
145
+ //#endregion
146
+ export { ManagedServiceCommandService, ManagedServiceSnapshot, StartServiceOptions, reportManagedServiceStart, resolveManagedServiceReadySnapshot, resolveManagedServiceUiBinding, resolveSessionRouteCandidate, spawnManagedService, waitForManagedServiceReadiness };