@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,25 @@
1
+ import { RequestRestartParams } from "../../types/cli.types.js";
2
+ import { RemoteAccessHost } from "../../../commands/remote/services/remote-access-host.service.js";
3
+ import { Config } from "@nextclaw/core";
4
+ import { RemoteServiceModule } from "@nextclaw/remote";
5
+
6
+ //#region src/shared/services/ui/service-remote-access.service.d.ts
7
+ type ManagedServiceRestartOptions = {
8
+ uiPort?: number;
9
+ reason?: string;
10
+ };
11
+ declare function requestManagedServiceRestart(requestRestart: (params: RequestRestartParams) => Promise<void>, options?: ManagedServiceRestartOptions): Promise<void>;
12
+ declare function createRemoteAccessHost(params: {
13
+ serviceCommands: {
14
+ startService: (options: {
15
+ uiOverrides: Record<string, unknown>;
16
+ open: boolean;
17
+ }) => Promise<void>;
18
+ stopService: () => Promise<void>;
19
+ };
20
+ requestRestart: (params: RequestRestartParams) => Promise<void>;
21
+ uiConfig: Pick<Config["ui"], "host" | "port">;
22
+ remoteModule: RemoteServiceModule | null;
23
+ }): RemoteAccessHost;
24
+ //#endregion
25
+ export { createRemoteAccessHost, requestManagedServiceRestart };
@@ -0,0 +1,38 @@
1
+ import { RemoteAccessHost } from "../../../commands/remote/services/remote-access-host.service.js";
2
+ import { RemoteCommands } from "../../../commands/remote/index.js";
3
+ import { PlatformAuthCommands } from "../../../commands/platform-auth/services/platform-auth-commands.service.js";
4
+ import "../../../commands/platform-auth/index.js";
5
+ //#region src/shared/services/ui/service-remote-access.service.ts
6
+ function requestManagedServiceRestart(requestRestart, options = {}) {
7
+ const uiPort = typeof options.uiPort === "number" && Number.isFinite(options.uiPort) ? Math.floor(options.uiPort) : void 0;
8
+ return requestRestart({
9
+ reason: options.reason?.trim() || "remote access service restart",
10
+ manualMessage: uiPort ? `Restart the managed service to restore the UI on port ${uiPort}.` : "Restart the managed service to restore the UI.",
11
+ strategy: "background-service-or-exit",
12
+ delayMs: 500,
13
+ silentOnServiceRestart: true
14
+ });
15
+ }
16
+ function createRemoteAccessHost(params) {
17
+ const { remoteModule, requestRestart, serviceCommands, uiConfig } = params;
18
+ return new RemoteAccessHost({
19
+ serviceCommands,
20
+ requestManagedServiceRestart: (options) => requestManagedServiceRestart(requestRestart, options),
21
+ remoteCommands: new RemoteCommands({ currentLocalOrigin: `http://127.0.0.1:${uiConfig.port}` }),
22
+ platformAuthCommands: new PlatformAuthCommands(),
23
+ currentUi: uiConfig,
24
+ remoteRuntimeController: remoteModule ? {
25
+ start: async () => {
26
+ remoteModule?.start();
27
+ },
28
+ stop: async () => {
29
+ await remoteModule?.stop();
30
+ },
31
+ restart: async () => {
32
+ await remoteModule?.restart();
33
+ }
34
+ } : null
35
+ });
36
+ }
37
+ //#endregion
38
+ export { createRemoteAccessHost, requestManagedServiceRestart };
@@ -0,0 +1,16 @@
1
+ //#region src/shared/services/ui/ui-bridge-api.service.d.ts
2
+ type UiBridgeApiMethod = "GET" | "POST" | "PUT" | "DELETE";
3
+ declare function resolveLocalUiApiBase(): string | null;
4
+ declare class UiBridgeApiClient {
5
+ private readonly apiBase;
6
+ private cookie;
7
+ constructor(apiBase: string);
8
+ private readonly getCookie;
9
+ readonly request: <T>(params: {
10
+ path: string;
11
+ method?: UiBridgeApiMethod;
12
+ body?: unknown;
13
+ }) => Promise<T>;
14
+ }
15
+ //#endregion
16
+ export { UiBridgeApiClient, UiBridgeApiMethod, resolveLocalUiApiBase };
@@ -0,0 +1,43 @@
1
+ import { localUiDiscoveryService } from "./local-ui-discovery.service.js";
2
+ import { ensureUiBridgeSecret } from "@nextclaw/server";
3
+ //#region src/shared/services/ui/ui-bridge-api.service.ts
4
+ function resolveLocalUiApiBase() {
5
+ return localUiDiscoveryService.resolveApiBase();
6
+ }
7
+ var UiBridgeApiClient = class {
8
+ cookie;
9
+ constructor(apiBase) {
10
+ this.apiBase = apiBase;
11
+ }
12
+ getCookie = async () => {
13
+ if (this.cookie !== void 0) return this.cookie;
14
+ const bridgeSecret = ensureUiBridgeSecret();
15
+ const response = await fetch(`${this.apiBase}/api/auth/bridge`, {
16
+ method: "POST",
17
+ headers: { "x-nextclaw-ui-bridge-secret": bridgeSecret }
18
+ });
19
+ if (!response.ok) throw new Error(`bridge auth failed with status ${response.status}`);
20
+ const payload = await response.json();
21
+ if (!payload.ok) throw new Error(payload.error?.message ?? "bridge auth failed");
22
+ this.cookie = typeof payload.data.cookie === "string" && payload.data.cookie.trim() ? payload.data.cookie.trim() : null;
23
+ return this.cookie;
24
+ };
25
+ request = async (params) => {
26
+ const { body, method, path } = params;
27
+ const cookie = await this.getCookie();
28
+ const response = await fetch(`${this.apiBase}${path}`, {
29
+ method: method ?? "GET",
30
+ headers: {
31
+ ...body ? { "Content-Type": "application/json" } : {},
32
+ ...cookie ? { Cookie: cookie } : {}
33
+ },
34
+ ...body ? { body: JSON.stringify(body) } : {}
35
+ });
36
+ if (!response.ok) throw new Error(`api request failed with status ${response.status}`);
37
+ const payload = await response.json();
38
+ if (!payload.ok) throw new Error(payload.error?.message ?? "api request failed");
39
+ return payload.data;
40
+ };
41
+ };
42
+ //#endregion
43
+ export { UiBridgeApiClient, resolveLocalUiApiBase };
@@ -0,0 +1,19 @@
1
+ //#region src/shared/services/workspace/workspace-manager.service.d.ts
2
+ declare class WorkspaceManager {
3
+ private logo;
4
+ constructor(logo: string);
5
+ private readonly pkgRoot;
6
+ readonly createWorkspaceTemplates: (workspace: string, options?: {
7
+ force?: boolean;
8
+ }) => {
9
+ created: string[];
10
+ };
11
+ private readonly resolveTemplateDir;
12
+ readonly getBridgeDir: () => string;
13
+ private readonly resolveBridgeSource;
14
+ private readonly assertCommandAvailable;
15
+ private readonly runBridgeCommand;
16
+ private readonly exitWithError;
17
+ }
18
+ //#endregion
19
+ export { WorkspaceManager };
@@ -0,0 +1,135 @@
1
+ import { findExecutableOnPath } from "../../utils/cli.utils.js";
2
+ import { spawnSync } from "node:child_process";
3
+ import { fileURLToPath } from "node:url";
4
+ import { dirname, join, resolve } from "node:path";
5
+ import { APP_NAME, getDataDir } from "@nextclaw/core";
6
+ import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7
+ //#region src/shared/services/workspace/workspace-manager.service.ts
8
+ var WorkspaceManager = class {
9
+ constructor(logo) {
10
+ this.logo = logo;
11
+ }
12
+ pkgRoot = resolve(fileURLToPath(new URL(".", import.meta.url)), "..", "..", "..", "..", "..");
13
+ createWorkspaceTemplates = (workspace, options = {}) => {
14
+ const created = [];
15
+ const force = Boolean(options.force);
16
+ const templateDir = this.resolveTemplateDir();
17
+ if (!templateDir) {
18
+ console.warn("Warning: Template directory not found. Skipping workspace templates.");
19
+ return { created };
20
+ }
21
+ for (const entry of [
22
+ {
23
+ source: "AGENTS.md",
24
+ target: "AGENTS.md"
25
+ },
26
+ {
27
+ source: "SOUL.md",
28
+ target: "SOUL.md"
29
+ },
30
+ {
31
+ source: "USER.md",
32
+ target: "USER.md"
33
+ },
34
+ {
35
+ source: "IDENTITY.md",
36
+ target: "IDENTITY.md"
37
+ },
38
+ {
39
+ source: "TOOLS.md",
40
+ target: "TOOLS.md"
41
+ },
42
+ {
43
+ source: "BOOT.md",
44
+ target: "BOOT.md"
45
+ },
46
+ {
47
+ source: "BOOTSTRAP.md",
48
+ target: "BOOTSTRAP.md"
49
+ },
50
+ {
51
+ source: "MEMORY.md",
52
+ target: "MEMORY.md"
53
+ },
54
+ {
55
+ source: "memory/MEMORY.md",
56
+ target: "memory/MEMORY.md"
57
+ }
58
+ ]) {
59
+ const filePath = join(workspace, entry.target);
60
+ if (!force && existsSync(filePath)) continue;
61
+ const templatePath = join(templateDir, entry.source);
62
+ if (!existsSync(templatePath)) {
63
+ console.warn(`Warning: Template file missing: ${templatePath}`);
64
+ continue;
65
+ }
66
+ const content = readFileSync(templatePath, "utf-8").replace(/\$\{APP_NAME\}/g, APP_NAME);
67
+ mkdirSync(dirname(filePath), { recursive: true });
68
+ writeFileSync(filePath, content);
69
+ created.push(entry.target);
70
+ }
71
+ const memoryDir = join(workspace, "memory");
72
+ if (!existsSync(memoryDir)) {
73
+ mkdirSync(memoryDir, { recursive: true });
74
+ created.push(join("memory", ""));
75
+ }
76
+ const skillsDir = join(workspace, "skills");
77
+ if (!existsSync(skillsDir)) {
78
+ mkdirSync(skillsDir, { recursive: true });
79
+ created.push(join("skills", ""));
80
+ }
81
+ return { created };
82
+ };
83
+ resolveTemplateDir = () => {
84
+ const override = process.env.NEXTCLAW_TEMPLATE_DIR?.trim();
85
+ if (override) return override;
86
+ const candidates = [join(this.pkgRoot, "templates")];
87
+ for (const candidate of candidates) if (existsSync(candidate)) return candidate;
88
+ return null;
89
+ };
90
+ getBridgeDir = () => {
91
+ const userBridge = join(getDataDir(), "bridge");
92
+ if (existsSync(join(userBridge, "dist", "index.js"))) return userBridge;
93
+ this.assertCommandAvailable("npm");
94
+ const source = this.resolveBridgeSource();
95
+ console.log(`${this.logo} Setting up bridge...`);
96
+ mkdirSync(resolve(userBridge, ".."), { recursive: true });
97
+ if (existsSync(userBridge)) rmSync(userBridge, {
98
+ recursive: true,
99
+ force: true
100
+ });
101
+ cpSync(source, userBridge, {
102
+ recursive: true,
103
+ filter: (src) => !src.includes("node_modules") && !src.includes("dist")
104
+ });
105
+ this.runBridgeCommand(userBridge, ["install"], "install");
106
+ this.runBridgeCommand(userBridge, ["run", "build"], "build");
107
+ console.log("✓ Bridge ready\n");
108
+ return userBridge;
109
+ };
110
+ resolveBridgeSource = () => {
111
+ const candidates = [join(this.pkgRoot, "bridge"), join(this.pkgRoot, "..", "..", "bridge")];
112
+ for (const candidate of candidates) if (existsSync(join(candidate, "package.json"))) return candidate;
113
+ return this.exitWithError(`Bridge source not found. Try reinstalling ${APP_NAME}.`);
114
+ };
115
+ assertCommandAvailable = (command) => {
116
+ if (findExecutableOnPath(command)) return;
117
+ this.exitWithError(`${command} not found. Please install Node.js >= 18.`);
118
+ };
119
+ runBridgeCommand = (cwd, args, step) => {
120
+ const result = spawnSync("npm", args, {
121
+ cwd,
122
+ stdio: "pipe"
123
+ });
124
+ if (result.status === 0) return;
125
+ const stderr = result.stderr ? String(result.stderr).slice(0, 500) : null;
126
+ this.exitWithError(`Bridge ${step} failed: ${result.status ?? 1}`, stderr);
127
+ };
128
+ exitWithError = (message, detail) => {
129
+ console.error(message);
130
+ if (detail) console.error(detail);
131
+ process.exit(1);
132
+ };
133
+ };
134
+ //#endregion
135
+ export { WorkspaceManager };
@@ -0,0 +1,15 @@
1
+ //#region src/shared/stores/companion-runtime.store.d.ts
2
+ type CompanionRuntimeState = {
3
+ pid: number;
4
+ startedAt: string;
5
+ baseUrl: string;
6
+ };
7
+ declare class CompanionRuntimeStore {
8
+ get path(): string;
9
+ readonly read: () => CompanionRuntimeState | null;
10
+ readonly write: (state: CompanionRuntimeState) => void;
11
+ readonly clear: () => void;
12
+ }
13
+ declare const companionRuntimeStore: CompanionRuntimeStore;
14
+ //#endregion
15
+ export { CompanionRuntimeState, CompanionRuntimeStore, companionRuntimeStore };
@@ -0,0 +1,27 @@
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/stores/companion-runtime.store.ts
5
+ var CompanionRuntimeStore = class {
6
+ get path() {
7
+ return resolve(getDataDir(), "run", "companion.json");
8
+ }
9
+ read = () => {
10
+ if (!existsSync(this.path)) return null;
11
+ try {
12
+ return JSON.parse(readFileSync(this.path, "utf-8"));
13
+ } catch {
14
+ return null;
15
+ }
16
+ };
17
+ write = (state) => {
18
+ mkdirSync(resolve(this.path, ".."), { recursive: true });
19
+ writeFileSync(this.path, JSON.stringify(state, null, 2));
20
+ };
21
+ clear = () => {
22
+ if (existsSync(this.path)) rmSync(this.path, { force: true });
23
+ };
24
+ };
25
+ const companionRuntimeStore = new CompanionRuntimeStore();
26
+ //#endregion
27
+ export { CompanionRuntimeStore, companionRuntimeStore };
@@ -0,0 +1,25 @@
1
+ import { Config } from "@nextclaw/core";
2
+ import { RemoteRuntimeState } from "@nextclaw/remote";
3
+
4
+ //#region src/shared/stores/local-ui-runtime.store.d.ts
5
+ type LocalUiRuntimeState = {
6
+ pid: number;
7
+ startedAt: string;
8
+ uiUrl: string;
9
+ apiUrl: string;
10
+ uiHost?: string;
11
+ uiPort?: number;
12
+ remote?: RemoteRuntimeState;
13
+ };
14
+ declare class LocalUiRuntimeStore {
15
+ get path(): string;
16
+ readonly read: () => LocalUiRuntimeState | null;
17
+ readonly write: (state: LocalUiRuntimeState) => void;
18
+ readonly update: (updater: (state: LocalUiRuntimeState) => LocalUiRuntimeState) => LocalUiRuntimeState | null;
19
+ readonly clear: () => void;
20
+ readonly clearIfOwnedByProcess: (pid?: number) => void;
21
+ readonly writeCurrentProcess: (uiConfig: Pick<Config["ui"], "host" | "port">, pid?: number) => LocalUiRuntimeState;
22
+ }
23
+ declare const localUiRuntimeStore: LocalUiRuntimeStore;
24
+ //#endregion
25
+ export { LocalUiRuntimeState, LocalUiRuntimeStore, localUiRuntimeStore };
@@ -0,0 +1,54 @@
1
+ import { resolveUiApiBase } from "../utils/cli.utils.js";
2
+ import { resolve } from "node:path";
3
+ import { getDataDir } from "@nextclaw/core";
4
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
+ //#region src/shared/stores/local-ui-runtime.store.ts
6
+ var LocalUiRuntimeStore = class {
7
+ get path() {
8
+ return resolve(getDataDir(), "run", "ui-runtime.json");
9
+ }
10
+ read = () => {
11
+ if (!existsSync(this.path)) return null;
12
+ try {
13
+ const raw = readFileSync(this.path, "utf-8");
14
+ return JSON.parse(raw);
15
+ } catch {
16
+ return null;
17
+ }
18
+ };
19
+ write = (state) => {
20
+ mkdirSync(resolve(this.path, ".."), { recursive: true });
21
+ writeFileSync(this.path, JSON.stringify(state, null, 2));
22
+ };
23
+ update = (updater) => {
24
+ const current = this.read();
25
+ if (!current) return null;
26
+ const next = updater(current);
27
+ this.write(next);
28
+ return next;
29
+ };
30
+ clear = () => {
31
+ if (existsSync(this.path)) rmSync(this.path, { force: true });
32
+ };
33
+ clearIfOwnedByProcess = (pid = process.pid) => {
34
+ if (this.read()?.pid === pid) this.clear();
35
+ };
36
+ writeCurrentProcess = (uiConfig, pid = process.pid) => {
37
+ const existing = this.read();
38
+ const uiUrl = resolveUiApiBase(uiConfig.host, uiConfig.port);
39
+ const state = {
40
+ pid,
41
+ startedAt: existing?.pid === pid && typeof existing.startedAt === "string" ? existing.startedAt : (/* @__PURE__ */ new Date()).toISOString(),
42
+ uiUrl,
43
+ apiUrl: `${uiUrl}/api`,
44
+ uiHost: uiConfig.host,
45
+ uiPort: uiConfig.port,
46
+ ...existing?.remote ? { remote: existing.remote } : {}
47
+ };
48
+ this.write(state);
49
+ return state;
50
+ };
51
+ };
52
+ const localUiRuntimeStore = new LocalUiRuntimeStore();
53
+ //#endregion
54
+ export { LocalUiRuntimeStore, localUiRuntimeStore };
@@ -0,0 +1,28 @@
1
+ import { RemoteRuntimeState } from "@nextclaw/remote";
2
+
3
+ //#region src/shared/stores/managed-service-state.store.d.ts
4
+ type ManagedServiceState = {
5
+ pid: number;
6
+ startedAt: string;
7
+ uiUrl: string;
8
+ apiUrl: string;
9
+ uiHost?: string;
10
+ uiPort?: number;
11
+ logPath: string;
12
+ startupState?: "ready" | "degraded";
13
+ startupLastProbeError?: string | null;
14
+ startupTimeoutMs?: number;
15
+ startupCheckedAt?: string;
16
+ remote?: RemoteRuntimeState;
17
+ };
18
+ declare class ManagedServiceStateStore {
19
+ get path(): string;
20
+ readonly read: () => ManagedServiceState | null;
21
+ readonly write: (state: ManagedServiceState) => void;
22
+ readonly update: (updater: (state: ManagedServiceState) => ManagedServiceState) => ManagedServiceState | null;
23
+ readonly clear: () => void;
24
+ readonly clearIfOwnedByProcess: (pid?: number) => void;
25
+ }
26
+ declare const managedServiceStateStore: ManagedServiceStateStore;
27
+ //#endregion
28
+ export { ManagedServiceState, ManagedServiceStateStore, managedServiceStateStore };
@@ -0,0 +1,38 @@
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/stores/managed-service-state.store.ts
5
+ var ManagedServiceStateStore = class {
6
+ get path() {
7
+ return resolve(getDataDir(), "run", "service.json");
8
+ }
9
+ read = () => {
10
+ if (!existsSync(this.path)) return null;
11
+ try {
12
+ const raw = readFileSync(this.path, "utf-8");
13
+ return JSON.parse(raw);
14
+ } catch {
15
+ return null;
16
+ }
17
+ };
18
+ write = (state) => {
19
+ mkdirSync(resolve(this.path, ".."), { recursive: true });
20
+ writeFileSync(this.path, JSON.stringify(state, null, 2));
21
+ };
22
+ update = (updater) => {
23
+ const current = this.read();
24
+ if (!current) return null;
25
+ const next = updater(current);
26
+ this.write(next);
27
+ return next;
28
+ };
29
+ clear = () => {
30
+ if (existsSync(this.path)) rmSync(this.path, { force: true });
31
+ };
32
+ clearIfOwnedByProcess = (pid = process.pid) => {
33
+ if (this.read()?.pid === pid) this.clear();
34
+ };
35
+ };
36
+ const managedServiceStateStore = new ManagedServiceStateStore();
37
+ //#endregion
38
+ export { ManagedServiceStateStore, managedServiceStateStore };
@@ -0,0 +1,21 @@
1
+ //#region src/shared/stores/pending-restart.store.d.ts
2
+ type PendingRestartState = {
3
+ changedPaths: string[];
4
+ message: string;
5
+ reasons: string[];
6
+ requestedAt: string;
7
+ };
8
+ type MarkPendingRestartParams = {
9
+ changedPaths?: string[];
10
+ manualMessage: string;
11
+ reason: string;
12
+ };
13
+ declare class PendingRestartStore {
14
+ private state;
15
+ readonly read: () => PendingRestartState | null;
16
+ readonly mark: (params: MarkPendingRestartParams) => PendingRestartState;
17
+ readonly clear: () => void;
18
+ }
19
+ declare const pendingRestartStore: PendingRestartStore;
20
+ //#endregion
21
+ export { PendingRestartState, PendingRestartStore, pendingRestartStore };
@@ -0,0 +1,35 @@
1
+ //#region src/shared/stores/pending-restart.store.ts
2
+ const clonePendingRestartState = (state) => {
3
+ if (!state) return null;
4
+ return {
5
+ changedPaths: [...state.changedPaths],
6
+ message: state.message,
7
+ reasons: [...state.reasons],
8
+ requestedAt: state.requestedAt
9
+ };
10
+ };
11
+ const dedupeStrings = (values) => {
12
+ return Array.from(new Set(values.map((value) => value.trim()).filter((value) => value.length > 0)));
13
+ };
14
+ var PendingRestartStore = class {
15
+ state = null;
16
+ read = () => {
17
+ return clonePendingRestartState(this.state);
18
+ };
19
+ mark = (params) => {
20
+ const nextState = {
21
+ changedPaths: dedupeStrings([...this.state?.changedPaths ?? [], ...params.changedPaths ?? []]),
22
+ message: params.manualMessage.trim() || this.state?.message || "Restart required to apply saved changes.",
23
+ reasons: dedupeStrings([...this.state?.reasons ?? [], params.reason]),
24
+ requestedAt: (/* @__PURE__ */ new Date()).toISOString()
25
+ };
26
+ this.state = nextState;
27
+ return clonePendingRestartState(nextState);
28
+ };
29
+ clear = () => {
30
+ this.state = null;
31
+ };
32
+ };
33
+ const pendingRestartStore = new PendingRestartStore();
34
+ //#endregion
35
+ export { PendingRestartStore, pendingRestartStore };