@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.
- package/LICENSE +21 -0
- package/dist/cli/commands/agent/agent-runtime.utils.d.ts +15 -0
- package/dist/cli/commands/agent/agent-runtime.utils.js +85 -0
- package/dist/cli/commands/agent/cli-agent-runner.utils.d.ts +21 -0
- package/dist/cli/commands/agent/cli-agent-runner.utils.js +89 -0
- package/dist/cli/commands/agent/index.d.ts +3 -0
- package/dist/cli/commands/agent/index.js +3 -0
- package/dist/cli/commands/agent/services/agent-commands.service.d.ts +17 -0
- package/dist/cli/commands/agent/services/agent-commands.service.js +112 -0
- package/dist/cli/commands/companion/index.d.ts +15 -0
- package/dist/cli/commands/companion/index.js +24 -0
- package/dist/cli/commands/companion/services/companion-process.service.d.ts +17 -0
- package/dist/cli/commands/companion/services/companion-process.service.js +49 -0
- package/dist/cli/commands/config/index.d.ts +2 -0
- package/dist/cli/commands/config/index.js +2 -0
- package/dist/cli/commands/config/services/config-commands.service.d.ts +18 -0
- package/dist/cli/commands/config/services/config-commands.service.js +133 -0
- package/dist/cli/commands/cron/index.d.ts +2 -0
- package/dist/cli/commands/cron/index.js +2 -0
- package/dist/cli/commands/cron/services/cron-commands.service.d.ts +22 -0
- package/dist/cli/commands/cron/services/cron-commands.service.js +107 -0
- package/dist/cli/commands/cron/services/cron-local.service.d.ts +25 -0
- package/dist/cli/commands/cron/services/cron-local.service.js +95 -0
- package/dist/cli/commands/cron/utils/cron-job.utils.d.ts +31 -0
- package/dist/cli/commands/cron/utils/cron-job.utils.js +15 -0
- package/dist/cli/commands/diagnostics/index.d.ts +2 -0
- package/dist/cli/commands/diagnostics/index.js +2 -0
- package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.d.ts +22 -0
- package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.js +319 -0
- package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.d.ts +23 -0
- package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.js +66 -0
- package/dist/cli/commands/gateway/index.d.ts +14 -0
- package/dist/cli/commands/gateway/index.js +15 -0
- package/dist/cli/commands/logs/index.d.ts +12 -0
- package/dist/cli/commands/logs/index.js +29 -0
- package/dist/cli/commands/mcp/index.d.ts +14 -0
- package/dist/cli/commands/mcp/index.js +193 -0
- package/dist/cli/commands/restart/index.d.ts +20 -0
- package/dist/cli/commands/restart/index.js +88 -0
- package/dist/cli/commands/secrets/index.d.ts +22 -0
- package/dist/cli/commands/secrets/index.js +280 -0
- package/dist/cli/commands/serve/index.d.ts +14 -0
- package/dist/cli/commands/serve/index.js +19 -0
- package/dist/cli/commands/skills/index.d.ts +26 -0
- package/dist/cli/commands/skills/index.js +147 -0
- package/dist/cli/commands/skills/marketplace-client.d.ts +31 -0
- package/dist/cli/commands/skills/marketplace-client.js +84 -0
- package/dist/cli/commands/skills/marketplace-command-options.utils.d.ts +25 -0
- package/dist/cli/commands/skills/marketplace-command-options.utils.js +31 -0
- package/dist/cli/commands/skills/marketplace-identity.utils.d.ts +14 -0
- package/dist/cli/commands/skills/marketplace-identity.utils.js +77 -0
- package/dist/cli/commands/skills/marketplace-network-retry.d.ts +4 -0
- package/dist/cli/commands/skills/marketplace-network-retry.js +32 -0
- package/dist/cli/commands/skills/marketplace.metadata.d.ts +29 -0
- package/dist/cli/commands/skills/marketplace.metadata.js +158 -0
- package/dist/cli/commands/skills/marketplace.service.d.ts +46 -0
- package/dist/cli/commands/skills/marketplace.service.js +238 -0
- package/dist/cli/commands/skills/skills-query.service.d.ts +141 -0
- package/dist/cli/commands/skills/skills-query.service.js +212 -0
- package/dist/cli/commands/start/index.d.ts +18 -0
- package/dist/cli/commands/start/index.js +25 -0
- package/dist/cli/commands/stop/index.d.ts +12 -0
- package/dist/cli/commands/stop/index.js +11 -0
- package/dist/cli/commands/ui/index.d.ts +14 -0
- package/dist/cli/commands/ui/index.js +17 -0
- package/dist/cli/commands/usage/index.d.ts +2 -0
- package/dist/cli/commands/usage/index.js +2 -0
- package/dist/cli/commands/usage/services/llm-usage-command.service.d.ts +22 -0
- package/dist/cli/commands/usage/services/llm-usage-command.service.js +160 -0
- package/dist/cli/commands/usage/services/llm-usage-query.service.d.ts +43 -0
- package/dist/cli/commands/usage/services/llm-usage-query.service.js +85 -0
- package/dist/commands/channel/channel-config-view.d.ts +7 -0
- package/dist/commands/channel/channel-config-view.js +7 -0
- package/dist/commands/channel/index.d.ts +28 -0
- package/dist/commands/channel/index.js +224 -0
- package/dist/commands/platform-auth/index.d.ts +2 -0
- package/dist/commands/platform-auth/index.js +2 -0
- package/dist/commands/platform-auth/services/account-status.service.d.ts +18 -0
- package/dist/commands/platform-auth/services/account-status.service.js +34 -0
- package/dist/commands/platform-auth/services/platform-auth-commands.service.d.ts +77 -0
- package/dist/commands/platform-auth/services/platform-auth-commands.service.js +295 -0
- package/dist/commands/platform-auth/utils/payload.utils.d.ts +28 -0
- package/dist/commands/platform-auth/utils/payload.utils.js +87 -0
- package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.d.ts +18 -0
- package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.js +111 -0
- package/dist/commands/plugin/development-source/first-party-plugin-load-paths.d.ts +9 -0
- package/dist/commands/plugin/development-source/first-party-plugin-load-paths.js +183 -0
- package/dist/commands/plugin/index.d.ts +30 -0
- package/dist/commands/plugin/index.js +266 -0
- package/dist/commands/plugin/plugin-command-utils.d.ts +13 -0
- package/dist/commands/plugin/plugin-command-utils.js +37 -0
- package/dist/commands/plugin/plugin-extension-registry.d.ts +10 -0
- package/dist/commands/plugin/plugin-extension-registry.js +35 -0
- package/dist/commands/plugin/plugin-mutation-actions.d.ts +15 -0
- package/dist/commands/plugin/plugin-mutation-actions.js +162 -0
- package/dist/commands/plugin/plugin-registry-loader.d.ts +15 -0
- package/dist/commands/plugin/plugin-registry-loader.js +43 -0
- package/dist/commands/plugin/plugin-reload.d.ts +13 -0
- package/dist/commands/plugin/plugin-reload.js +42 -0
- package/dist/commands/remote/index.d.ts +47 -0
- package/dist/commands/remote/index.js +174 -0
- package/dist/commands/remote/services/remote-access-host.service.d.ts +41 -0
- package/dist/commands/remote/services/remote-access-host.service.js +126 -0
- package/dist/commands/remote/services/remote-runtime-support.service.d.ts +15 -0
- package/dist/commands/remote/services/remote-runtime-support.service.js +79 -0
- package/dist/commands/remote/services/remote-service-control.service.d.ts +33 -0
- package/dist/commands/remote/services/remote-service-control.service.js +188 -0
- package/dist/commands/remote/utils/platform-api-base.utils.d.ts +14 -0
- package/dist/commands/remote/utils/platform-api-base.utils.js +39 -0
- package/dist/commands/service/index.d.ts +16 -0
- package/dist/commands/service/index.js +31 -0
- package/dist/commands/service/services/autostart/host-autostart-command.service.d.ts +29 -0
- package/dist/commands/service/services/autostart/host-autostart-command.service.js +158 -0
- package/dist/commands/service/services/autostart/host-autostart-runtime.service.d.ts +23 -0
- package/dist/commands/service/services/autostart/host-autostart-runtime.service.js +53 -0
- package/dist/commands/service/services/autostart/host-autostart.service.d.ts +41 -0
- package/dist/commands/service/services/autostart/host-autostart.service.js +48 -0
- package/dist/commands/service/services/autostart/linux-systemd-autostart.service.d.ts +48 -0
- package/dist/commands/service/services/autostart/linux-systemd-autostart.service.js +433 -0
- package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.d.ts +54 -0
- package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.js +405 -0
- package/dist/commands/service/services/autostart/windows-task-autostart.service.d.ts +54 -0
- package/dist/commands/service/services/autostart/windows-task-autostart.service.js +403 -0
- package/dist/commands/service/types/autostart/host-autostart.types.d.ts +64 -0
- package/dist/commands/service/types/autostart/host-autostart.types.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/launcher/npm-runtime-bundle-layout.store.d.ts +23 -0
- package/dist/launcher/npm-runtime-bundle-layout.store.js +37 -0
- package/dist/launcher/npm-runtime-bundle-manifest.service.d.ts +9 -0
- package/dist/launcher/npm-runtime-bundle-manifest.service.js +39 -0
- package/dist/launcher/npm-runtime-bundle.service.d.ts +47 -0
- package/dist/launcher/npm-runtime-bundle.service.js +150 -0
- package/dist/launcher/npm-runtime-bundle.types.d.ts +49 -0
- package/dist/launcher/npm-runtime-bundle.types.js +1 -0
- package/dist/launcher/npm-runtime-launcher.service.d.ts +19 -0
- package/dist/launcher/npm-runtime-launcher.service.js +57 -0
- package/dist/launcher/npm-runtime-update-command.service.d.ts +12 -0
- package/dist/launcher/npm-runtime-update-command.service.js +87 -0
- package/dist/launcher/npm-runtime-update-source.service.d.ts +19 -0
- package/dist/launcher/npm-runtime-update-source.service.js +57 -0
- package/dist/launcher/npm-runtime-update-state.store.d.ts +17 -0
- package/dist/launcher/npm-runtime-update-state.store.js +92 -0
- package/dist/launcher/npm-runtime-update.manager.d.ts +42 -0
- package/dist/launcher/npm-runtime-update.manager.js +179 -0
- package/dist/launcher/npm-runtime-update.service.d.ts +54 -0
- package/dist/launcher/npm-runtime-update.service.js +183 -0
- package/dist/service-runtime.service.d.ts +91 -0
- package/dist/service-runtime.service.js +392 -0
- package/dist/shared/controllers/gateway.controller.d.ts +61 -0
- package/dist/shared/controllers/gateway.controller.js +318 -0
- package/dist/shared/services/extensions/extension-lifecycle.service.d.ts +56 -0
- package/dist/shared/services/extensions/extension-lifecycle.service.js +143 -0
- package/dist/shared/services/extensions/service-extension-runtime.service.d.ts +51 -0
- package/dist/shared/services/extensions/service-extension-runtime.service.js +338 -0
- package/dist/shared/services/gateway/cron-job-handler.service.d.ts +26 -0
- package/dist/shared/services/gateway/cron-job-handler.service.js +100 -0
- package/dist/shared/services/gateway/gateway-restart-wake.service.d.ts +12 -0
- package/dist/shared/services/gateway/gateway-restart-wake.service.js +91 -0
- package/dist/shared/services/gateway/managers/gateway-plugin.manager.d.ts +37 -0
- package/dist/shared/services/gateway/managers/gateway-plugin.manager.js +218 -0
- package/dist/shared/services/gateway/managers/gateway-remote.manager.d.ts +20 -0
- package/dist/shared/services/gateway/managers/gateway-remote.manager.js +25 -0
- package/dist/shared/services/gateway/nextclaw-app.service.d.ts +22 -0
- package/dist/shared/services/gateway/nextclaw-app.service.js +53 -0
- package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.d.ts +89 -0
- package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.js +337 -0
- package/dist/shared/services/gateway/service-bootstrap-status.d.ts +33 -0
- package/dist/shared/services/gateway/service-bootstrap-status.js +152 -0
- package/dist/shared/services/gateway/service-startup-support.service.d.ts +42 -0
- package/dist/shared/services/gateway/service-startup-support.service.js +96 -0
- package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.d.ts +9 -0
- package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.js +10 -0
- package/dist/shared/services/marketplace/service-marketplace-installer.service.d.ts +31 -0
- package/dist/shared/services/marketplace/service-marketplace-installer.service.js +99 -0
- package/dist/shared/services/marketplace/service-mcp-marketplace-ops.d.ts +39 -0
- package/dist/shared/services/marketplace/service-mcp-marketplace-ops.js +67 -0
- package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.d.ts +24 -0
- package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.js +117 -0
- package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.d.ts +6 -0
- package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.js +96 -0
- package/dist/shared/services/restart/restart-coordinator.service.d.ts +30 -0
- package/dist/shared/services/restart/restart-coordinator.service.js +51 -0
- package/dist/shared/services/restart/restart-sentinel.service.d.ts +39 -0
- package/dist/shared/services/restart/restart-sentinel.service.js +88 -0
- package/dist/shared/services/restart/runtime-restart-request.service.d.ts +24 -0
- package/dist/shared/services/restart/runtime-restart-request.service.js +42 -0
- package/dist/shared/services/runtime/runtime-command.service.d.ts +37 -0
- package/dist/shared/services/runtime/runtime-command.service.js +163 -0
- package/dist/shared/services/runtime/runtime-config-init.service.d.ts +4 -0
- package/dist/shared/services/runtime/runtime-config-init.service.js +10 -0
- package/dist/shared/services/runtime/service-managed-startup.service.d.ts +146 -0
- package/dist/shared/services/runtime/service-managed-startup.service.js +426 -0
- package/dist/shared/services/runtime/service-remote-runtime.service.d.ts +53 -0
- package/dist/shared/services/runtime/service-remote-runtime.service.js +173 -0
- package/dist/shared/services/runtime/utils/skills-loader.utils.d.ts +12 -0
- package/dist/shared/services/runtime/utils/skills-loader.utils.js +9 -0
- package/dist/shared/services/session/service-deferred-ncp-agent.service.d.ts +14 -0
- package/dist/shared/services/session/service-deferred-ncp-agent.service.js +85 -0
- package/dist/shared/services/ui/companion-runtime.service.d.ts +33 -0
- package/dist/shared/services/ui/companion-runtime.service.js +145 -0
- package/dist/shared/services/ui/local-ui-discovery.service.d.ts +19 -0
- package/dist/shared/services/ui/local-ui-discovery.service.js +41 -0
- package/dist/shared/services/ui/npm-runtime-update-host.service.d.ts +40 -0
- package/dist/shared/services/ui/npm-runtime-update-host.service.js +181 -0
- package/dist/shared/services/ui/runtime-control-host.service.d.ts +28 -0
- package/dist/shared/services/ui/runtime-control-host.service.js +89 -0
- package/dist/shared/services/ui/service-remote-access.service.d.ts +25 -0
- package/dist/shared/services/ui/service-remote-access.service.js +38 -0
- package/dist/shared/services/ui/ui-bridge-api.service.d.ts +16 -0
- package/dist/shared/services/ui/ui-bridge-api.service.js +43 -0
- package/dist/shared/services/workspace/workspace-manager.service.d.ts +19 -0
- package/dist/shared/services/workspace/workspace-manager.service.js +135 -0
- package/dist/shared/stores/companion-runtime.store.d.ts +15 -0
- package/dist/shared/stores/companion-runtime.store.js +27 -0
- package/dist/shared/stores/local-ui-runtime.store.d.ts +25 -0
- package/dist/shared/stores/local-ui-runtime.store.js +54 -0
- package/dist/shared/stores/managed-service-state.store.d.ts +28 -0
- package/dist/shared/stores/managed-service-state.store.js +38 -0
- package/dist/shared/stores/pending-restart.store.d.ts +21 -0
- package/dist/shared/stores/pending-restart.store.js +35 -0
- package/dist/shared/types/cli.types.d.ts +295 -0
- package/dist/shared/types/cli.types.js +1 -0
- package/dist/shared/utils/cli.utils.d.ts +34 -0
- package/dist/shared/utils/cli.utils.js +262 -0
- package/dist/shared/utils/config-path.d.ts +15 -0
- package/dist/shared/utils/config-path.js +167 -0
- package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.d.ts +16 -0
- package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.js +46 -0
- package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.d.ts +9 -0
- package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.js +33 -0
- package/dist/shared/utils/package/package-manifest.utils.d.ts +8 -0
- package/dist/shared/utils/package/package-manifest.utils.js +48 -0
- package/dist/shared/utils/runtime-helpers.d.ts +14 -0
- package/dist/shared/utils/runtime-helpers.js +26 -0
- package/dist/shared/utils/service-port-probe.utils.d.ts +41 -0
- package/dist/shared/utils/service-port-probe.utils.js +164 -0
- package/dist/shared/utils/startup-trace.d.ts +7 -0
- package/dist/shared/utils/startup-trace.js +37 -0
- package/dist/shared/utils/top-level-nextclaw-command-env.utils.d.ts +4 -0
- package/dist/shared/utils/top-level-nextclaw-command-env.utils.js +10 -0
- package/package.json +68 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Config } from "@nextclaw/core";
|
|
2
|
+
import { RemoteConnector, RemoteLogger, RemotePlatformClient, RemoteRuntimeState, RemoteStatusSnapshot, RemoteStatusStore } from "@nextclaw/remote";
|
|
3
|
+
|
|
4
|
+
//#region src/commands/remote/services/remote-runtime-support.service.d.ts
|
|
5
|
+
declare function hasRunningNextclawManagedService(): boolean;
|
|
6
|
+
declare function createNextclawRemotePlatformClient(): RemotePlatformClient;
|
|
7
|
+
declare function createNextclawRemoteConnector(params?: {
|
|
8
|
+
logger?: RemoteLogger;
|
|
9
|
+
}): RemoteConnector;
|
|
10
|
+
declare function createNextclawRemoteStatusStore(mode: RemoteRuntimeState["mode"]): RemoteStatusStore;
|
|
11
|
+
declare function buildNextclawConfiguredRemoteState(config: Config): RemoteRuntimeState;
|
|
12
|
+
declare function readCurrentNextclawRemoteRuntimeState(): RemoteRuntimeState | null;
|
|
13
|
+
declare function resolveNextclawRemoteStatusSnapshot(config: Config): RemoteStatusSnapshot;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { buildNextclawConfiguredRemoteState, createNextclawRemoteConnector, createNextclawRemotePlatformClient, createNextclawRemoteStatusStore, hasRunningNextclawManagedService, readCurrentNextclawRemoteRuntimeState, resolveNextclawRemoteStatusSnapshot };
|
|
@@ -0,0 +1,79 @@
|
|
|
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 { localUiRuntimeStore } from "../../../shared/stores/local-ui-runtime.store.js";
|
|
4
|
+
import { managedServiceStateStore } from "../../../shared/stores/managed-service-state.store.js";
|
|
5
|
+
import { resolvePlatformApiBase } from "../utils/platform-api-base.utils.js";
|
|
6
|
+
import { getConfigPath, getDataDir, loadConfig } from "@nextclaw/core";
|
|
7
|
+
import { RemoteConnector, RemotePlatformClient, RemoteStatusStore, buildConfiguredRemoteState, resolveRemoteStatusSnapshot } from "@nextclaw/remote";
|
|
8
|
+
//#region src/commands/remote/services/remote-runtime-support.service.ts
|
|
9
|
+
let currentProcessRemoteRuntimeState = null;
|
|
10
|
+
function hasRunningNextclawManagedService() {
|
|
11
|
+
const state = managedServiceStateStore.read();
|
|
12
|
+
return Boolean(state && isProcessRunning(state.pid));
|
|
13
|
+
}
|
|
14
|
+
function createNextclawRemotePlatformClient() {
|
|
15
|
+
return new RemotePlatformClient({
|
|
16
|
+
loadConfig: () => loadConfig(getConfigPath()),
|
|
17
|
+
getDataDir,
|
|
18
|
+
getPackageVersion: getPackageVersion$1,
|
|
19
|
+
resolvePlatformBase: (rawApiBase) => resolvePlatformApiBase({
|
|
20
|
+
explicitApiBase: rawApiBase,
|
|
21
|
+
requireConfigured: true
|
|
22
|
+
}).platformBase,
|
|
23
|
+
readManagedServiceState: () => {
|
|
24
|
+
const state = managedServiceStateStore.read();
|
|
25
|
+
if (!state) return null;
|
|
26
|
+
return {
|
|
27
|
+
pid: state.pid,
|
|
28
|
+
uiPort: state.uiPort
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
isProcessRunning
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function createNextclawRemoteConnector(params = {}) {
|
|
35
|
+
return new RemoteConnector({
|
|
36
|
+
platformClient: createNextclawRemotePlatformClient(),
|
|
37
|
+
logger: params.logger
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function createNextclawRemoteStatusStore(mode) {
|
|
41
|
+
return new RemoteStatusStore(mode, { writeRemoteState: (next) => {
|
|
42
|
+
currentProcessRemoteRuntimeState = next;
|
|
43
|
+
if (localUiRuntimeStore.read()?.pid === process.pid) localUiRuntimeStore.update((state) => ({
|
|
44
|
+
...state,
|
|
45
|
+
remote: next
|
|
46
|
+
}));
|
|
47
|
+
const serviceState = managedServiceStateStore.read();
|
|
48
|
+
if (!serviceState || serviceState.pid !== process.pid) return;
|
|
49
|
+
managedServiceStateStore.update((state) => ({
|
|
50
|
+
...state,
|
|
51
|
+
remote: next
|
|
52
|
+
}));
|
|
53
|
+
} });
|
|
54
|
+
}
|
|
55
|
+
function buildNextclawConfiguredRemoteState(config) {
|
|
56
|
+
return buildConfiguredRemoteState(config);
|
|
57
|
+
}
|
|
58
|
+
function readCurrentNextclawRemoteRuntimeState() {
|
|
59
|
+
const uiRuntimeState = localUiRuntimeStore.read();
|
|
60
|
+
const serviceState = managedServiceStateStore.read();
|
|
61
|
+
const currentRemoteState = currentProcessRemoteRuntimeState ?? uiRuntimeState?.remote ?? serviceState?.remote ?? null;
|
|
62
|
+
if (!currentRemoteState) return null;
|
|
63
|
+
const owningRuntime = uiRuntimeState ?? serviceState;
|
|
64
|
+
if (!owningRuntime || isProcessRunning(owningRuntime.pid)) return currentRemoteState;
|
|
65
|
+
return {
|
|
66
|
+
...currentRemoteState,
|
|
67
|
+
state: currentRemoteState.enabled ? "disconnected" : "disabled",
|
|
68
|
+
lastError: currentRemoteState.lastError ?? "Managed service is not running.",
|
|
69
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function resolveNextclawRemoteStatusSnapshot(config) {
|
|
73
|
+
return resolveRemoteStatusSnapshot({
|
|
74
|
+
config,
|
|
75
|
+
currentRemoteState: readCurrentNextclawRemoteRuntimeState()
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { buildNextclawConfiguredRemoteState, createNextclawRemoteConnector, createNextclawRemotePlatformClient, createNextclawRemoteStatusStore, hasRunningNextclawManagedService, readCurrentNextclawRemoteRuntimeState, resolveNextclawRemoteStatusSnapshot };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resolveUiConfig } from "../../../shared/utils/cli.utils.js";
|
|
2
|
+
import { RemoteServiceAction, RemoteServiceActionResult, RemoteServiceView } from "@nextclaw/server";
|
|
3
|
+
|
|
4
|
+
//#region src/commands/remote/services/remote-service-control.service.d.ts
|
|
5
|
+
type RemoteAccessHostServiceCommands = {
|
|
6
|
+
startService: (options: {
|
|
7
|
+
uiOverrides: Partial<ReturnType<typeof resolveUiConfig>>;
|
|
8
|
+
open: boolean;
|
|
9
|
+
}) => Promise<void>;
|
|
10
|
+
stopService: () => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
type RemoteRuntimeController = {
|
|
13
|
+
start: () => Promise<void> | null;
|
|
14
|
+
stop: () => Promise<void>;
|
|
15
|
+
restart: () => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
type CurrentUi = {
|
|
18
|
+
host: string;
|
|
19
|
+
port: number;
|
|
20
|
+
};
|
|
21
|
+
type RemoteServiceControlDeps = {
|
|
22
|
+
serviceCommands: RemoteAccessHostServiceCommands;
|
|
23
|
+
requestManagedServiceRestart: (options?: {
|
|
24
|
+
uiPort?: number;
|
|
25
|
+
reason?: string;
|
|
26
|
+
}) => Promise<void>;
|
|
27
|
+
currentUi?: CurrentUi;
|
|
28
|
+
remoteRuntimeController?: RemoteRuntimeController | null;
|
|
29
|
+
};
|
|
30
|
+
declare function resolveRemoteServiceView(currentUi?: CurrentUi): RemoteServiceView;
|
|
31
|
+
declare function controlRemoteService(action: RemoteServiceAction, deps: RemoteServiceControlDeps): Promise<RemoteServiceActionResult>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { RemoteAccessHostServiceCommands, RemoteRuntimeController, controlRemoteService, resolveRemoteServiceView };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { isProcessRunning, resolveUiApiBase, resolveUiConfig } from "../../../shared/utils/cli.utils.js";
|
|
2
|
+
import { managedServiceStateStore } from "../../../shared/stores/managed-service-state.store.js";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { getConfigPath, loadConfig } from "@nextclaw/core";
|
|
5
|
+
//#region src/commands/remote/services/remote-service-control.service.ts
|
|
6
|
+
const FORCED_PUBLIC_UI_HOST = "0.0.0.0";
|
|
7
|
+
function resolveRemoteServiceView(currentUi) {
|
|
8
|
+
if (currentUi) return {
|
|
9
|
+
running: true,
|
|
10
|
+
currentProcess: true,
|
|
11
|
+
pid: process.pid,
|
|
12
|
+
uiUrl: resolveUiApiBase(currentUi.host, currentUi.port),
|
|
13
|
+
uiPort: currentUi.port
|
|
14
|
+
};
|
|
15
|
+
const serviceState = managedServiceStateStore.read();
|
|
16
|
+
const serviceRunning = Boolean(serviceState && isProcessRunning(serviceState.pid));
|
|
17
|
+
return {
|
|
18
|
+
running: serviceRunning,
|
|
19
|
+
currentProcess: Boolean(serviceRunning && serviceState?.pid === process.pid),
|
|
20
|
+
...serviceState?.pid ? { pid: serviceState.pid } : {},
|
|
21
|
+
...serviceState?.uiUrl ? { uiUrl: serviceState.uiUrl } : {},
|
|
22
|
+
...typeof serviceState?.uiPort === "number" ? { uiPort: serviceState.uiPort } : {}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async function controlRemoteService(action, deps) {
|
|
26
|
+
if (deps.remoteRuntimeController) return controlCurrentProcessRuntime(action, deps.remoteRuntimeController);
|
|
27
|
+
return controlManagedService(action, deps);
|
|
28
|
+
}
|
|
29
|
+
async function controlCurrentProcessRuntime(action, controller) {
|
|
30
|
+
if (action === "start") {
|
|
31
|
+
await controller.start();
|
|
32
|
+
return {
|
|
33
|
+
accepted: true,
|
|
34
|
+
action,
|
|
35
|
+
message: "Remote runtime started."
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (action === "stop") {
|
|
39
|
+
await controller.stop();
|
|
40
|
+
return {
|
|
41
|
+
accepted: true,
|
|
42
|
+
action,
|
|
43
|
+
message: "Remote runtime stopped."
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
await controller.restart();
|
|
47
|
+
return {
|
|
48
|
+
accepted: true,
|
|
49
|
+
action,
|
|
50
|
+
message: "Remote runtime restarted."
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function controlManagedService(action, deps) {
|
|
54
|
+
const state = managedServiceStateStore.read();
|
|
55
|
+
const running = Boolean(state && isProcessRunning(state.pid));
|
|
56
|
+
const currentProcess = Boolean(running && state?.pid === process.pid);
|
|
57
|
+
const uiOverrides = resolveManagedUiOverrides();
|
|
58
|
+
if (action === "start") {
|
|
59
|
+
if (running) return {
|
|
60
|
+
accepted: true,
|
|
61
|
+
action,
|
|
62
|
+
message: currentProcess ? "Managed service is already running for this UI." : "Managed service is already running."
|
|
63
|
+
};
|
|
64
|
+
await deps.serviceCommands.startService({
|
|
65
|
+
uiOverrides,
|
|
66
|
+
open: false
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
accepted: true,
|
|
70
|
+
action,
|
|
71
|
+
message: "Managed service started."
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (!running) {
|
|
75
|
+
if (action === "restart") {
|
|
76
|
+
await deps.serviceCommands.startService({
|
|
77
|
+
uiOverrides,
|
|
78
|
+
open: false
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
accepted: true,
|
|
82
|
+
action,
|
|
83
|
+
message: "Managed service was not running and has been started."
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
accepted: true,
|
|
88
|
+
action,
|
|
89
|
+
message: "No managed service is currently running."
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (currentProcess) {
|
|
93
|
+
if (action === "restart") await deps.requestManagedServiceRestart({ uiPort: uiOverrides.port ?? 55667 });
|
|
94
|
+
else scheduleManagedSelfStop();
|
|
95
|
+
return {
|
|
96
|
+
accepted: true,
|
|
97
|
+
action,
|
|
98
|
+
message: action === "restart" ? "Restart scheduled. This page may disconnect for a few seconds." : "Stop scheduled. This page will disconnect shortly."
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (action === "stop") {
|
|
102
|
+
await deps.serviceCommands.stopService();
|
|
103
|
+
return {
|
|
104
|
+
accepted: true,
|
|
105
|
+
action,
|
|
106
|
+
message: "Managed service stopped."
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
await deps.serviceCommands.stopService();
|
|
110
|
+
await deps.serviceCommands.startService({
|
|
111
|
+
uiOverrides,
|
|
112
|
+
open: false
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
accepted: true,
|
|
116
|
+
action,
|
|
117
|
+
message: "Managed service restarted."
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function resolveManagedUiOverrides() {
|
|
121
|
+
return {
|
|
122
|
+
enabled: true,
|
|
123
|
+
host: FORCED_PUBLIC_UI_HOST,
|
|
124
|
+
open: false,
|
|
125
|
+
port: resolveUiConfig(loadConfig(getConfigPath()), {
|
|
126
|
+
enabled: true,
|
|
127
|
+
host: FORCED_PUBLIC_UI_HOST,
|
|
128
|
+
open: false
|
|
129
|
+
}).port
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function scheduleManagedSelfStop() {
|
|
133
|
+
launchManagedSelfControl();
|
|
134
|
+
}
|
|
135
|
+
function launchManagedSelfControl(params = {}) {
|
|
136
|
+
const script = [
|
|
137
|
+
"const { spawn } = require(\"node:child_process\");",
|
|
138
|
+
"const { rmSync } = require(\"node:fs\");",
|
|
139
|
+
`const parentPid = ${process.pid};`,
|
|
140
|
+
`const serviceStatePath = ${JSON.stringify(managedServiceStateStore.path)};`,
|
|
141
|
+
`const command = ${JSON.stringify(params.command ?? null)};`,
|
|
142
|
+
`const args = ${JSON.stringify(params.args ?? [])};`,
|
|
143
|
+
`const cwd = ${JSON.stringify(process.cwd())};`,
|
|
144
|
+
"const env = process.env;",
|
|
145
|
+
"function isRunning(pid) {",
|
|
146
|
+
" try {",
|
|
147
|
+
" process.kill(pid, 0);",
|
|
148
|
+
" return true;",
|
|
149
|
+
" } catch {",
|
|
150
|
+
" return false;",
|
|
151
|
+
" }",
|
|
152
|
+
"}",
|
|
153
|
+
"setTimeout(() => {",
|
|
154
|
+
" try {",
|
|
155
|
+
" process.kill(parentPid, 'SIGTERM');",
|
|
156
|
+
" } catch {}",
|
|
157
|
+
"}, 150);",
|
|
158
|
+
"const startedAt = Date.now();",
|
|
159
|
+
"const maxWaitMs = 30000;",
|
|
160
|
+
"const timer = setInterval(() => {",
|
|
161
|
+
" if (isRunning(parentPid)) {",
|
|
162
|
+
" if (Date.now() - startedAt > maxWaitMs) {",
|
|
163
|
+
" try {",
|
|
164
|
+
" process.kill(parentPid, 'SIGKILL');",
|
|
165
|
+
" } catch {}",
|
|
166
|
+
" }",
|
|
167
|
+
" return;",
|
|
168
|
+
" }",
|
|
169
|
+
" clearInterval(timer);",
|
|
170
|
+
" try {",
|
|
171
|
+
" rmSync(serviceStatePath, { force: true });",
|
|
172
|
+
" } catch {}",
|
|
173
|
+
" if (command) {",
|
|
174
|
+
" const child = spawn(command, args, { detached: true, stdio: 'ignore', cwd, env });",
|
|
175
|
+
" child.unref();",
|
|
176
|
+
" }",
|
|
177
|
+
" process.exit(0);",
|
|
178
|
+
"}, 250);"
|
|
179
|
+
].join("");
|
|
180
|
+
spawn(process.execPath, ["-e", script], {
|
|
181
|
+
detached: true,
|
|
182
|
+
stdio: "ignore",
|
|
183
|
+
env: process.env,
|
|
184
|
+
cwd: process.cwd()
|
|
185
|
+
}).unref();
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
export { controlRemoteService, resolveRemoteServiceView };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/commands/remote/utils/platform-api-base.utils.d.ts
|
|
2
|
+
declare function resolvePlatformApiBase(params: {
|
|
3
|
+
explicitApiBase?: string | null;
|
|
4
|
+
configuredApiBase?: string | null;
|
|
5
|
+
fallbackApiBase?: string;
|
|
6
|
+
requireConfigured?: boolean;
|
|
7
|
+
}): {
|
|
8
|
+
platformBase: string;
|
|
9
|
+
v1Base: string;
|
|
10
|
+
inputApiBase: string;
|
|
11
|
+
};
|
|
12
|
+
declare function buildPlatformApiBaseErrorMessage(inputApiBase: string, rawMessage: string): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { buildPlatformApiBaseErrorMessage, resolvePlatformApiBase };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/commands/remote/utils/platform-api-base.utils.ts
|
|
2
|
+
const DEFAULT_PLATFORM_API_BASE = "https://ai-gateway-api.nextclaw.io/v1";
|
|
3
|
+
const INVALID_PLATFORM_HINT = `Use ${DEFAULT_PLATFORM_API_BASE} or the platform root URL without a trailing path.`;
|
|
4
|
+
function trimTrailingSlash(value) {
|
|
5
|
+
return value.replace(/\/+$/, "");
|
|
6
|
+
}
|
|
7
|
+
function normalizeExplicitApiBase(rawApiBase) {
|
|
8
|
+
const trimmed = trimTrailingSlash(rawApiBase.trim());
|
|
9
|
+
if (!trimmed) return "";
|
|
10
|
+
return trimmed.replace(/\/v1?$/i, "");
|
|
11
|
+
}
|
|
12
|
+
function resolvePlatformApiBase(params) {
|
|
13
|
+
const explicitApiBase = typeof params.explicitApiBase === "string" ? params.explicitApiBase.trim() : "";
|
|
14
|
+
const configuredApiBase = typeof params.configuredApiBase === "string" ? params.configuredApiBase.trim() : "";
|
|
15
|
+
const fallbackApiBase = params.fallbackApiBase ?? DEFAULT_PLATFORM_API_BASE;
|
|
16
|
+
const inputApiBase = explicitApiBase || configuredApiBase || (params.requireConfigured ? "" : fallbackApiBase);
|
|
17
|
+
if (!inputApiBase) throw new Error("Platform API base is missing. Pass --api-base or run nextclaw login.");
|
|
18
|
+
const platformBase = normalizeExplicitApiBase(inputApiBase);
|
|
19
|
+
if (!platformBase) throw new Error(`Invalid --api-base "${inputApiBase}". ${INVALID_PLATFORM_HINT}`);
|
|
20
|
+
let parsedUrl;
|
|
21
|
+
try {
|
|
22
|
+
parsedUrl = new URL(platformBase);
|
|
23
|
+
} catch {
|
|
24
|
+
throw new Error(`Invalid --api-base "${inputApiBase}". ${INVALID_PLATFORM_HINT}`);
|
|
25
|
+
}
|
|
26
|
+
if (parsedUrl.pathname !== "" && parsedUrl.pathname !== "/") throw new Error(`Invalid --api-base "${inputApiBase}". ${INVALID_PLATFORM_HINT}`);
|
|
27
|
+
const normalizedPlatformBase = trimTrailingSlash(parsedUrl.toString());
|
|
28
|
+
return {
|
|
29
|
+
platformBase: normalizedPlatformBase,
|
|
30
|
+
v1Base: `${normalizedPlatformBase}/v1`,
|
|
31
|
+
inputApiBase
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function buildPlatformApiBaseErrorMessage(inputApiBase, rawMessage) {
|
|
35
|
+
if (rawMessage.includes("Remote session cookie missing") || rawMessage.includes("endpoint not found") || rawMessage.includes("NOT_FOUND")) return `Invalid --api-base "${inputApiBase}". ${INVALID_PLATFORM_HINT}`;
|
|
36
|
+
return rawMessage;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { buildPlatformApiBaseErrorMessage, resolvePlatformApiBase };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ServiceAutostartCommandOptions } from "../../shared/types/cli.types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/commands/service/index.d.ts
|
|
4
|
+
declare class ServiceCommands {
|
|
5
|
+
private readonly hostAutostartCommandService;
|
|
6
|
+
installSystemd: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
7
|
+
uninstallSystemd: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
8
|
+
installLaunchAgent: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
9
|
+
uninstallLaunchAgent: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
10
|
+
installWindowsTask: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
11
|
+
uninstallWindowsTask: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
12
|
+
autostartStatus: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
13
|
+
autostartDoctor: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ServiceCommands };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HostAutostartCommandService } from "./services/autostart/host-autostart-command.service.js";
|
|
2
|
+
//#region src/commands/service/index.ts
|
|
3
|
+
var ServiceCommands = class {
|
|
4
|
+
hostAutostartCommandService = new HostAutostartCommandService();
|
|
5
|
+
installSystemd = async (options = {}) => {
|
|
6
|
+
await this.hostAutostartCommandService.installSystemd(options);
|
|
7
|
+
};
|
|
8
|
+
uninstallSystemd = async (options = {}) => {
|
|
9
|
+
await this.hostAutostartCommandService.uninstallSystemd(options);
|
|
10
|
+
};
|
|
11
|
+
installLaunchAgent = async (options = {}) => {
|
|
12
|
+
await this.hostAutostartCommandService.installLaunchAgent(options);
|
|
13
|
+
};
|
|
14
|
+
uninstallLaunchAgent = async (options = {}) => {
|
|
15
|
+
await this.hostAutostartCommandService.uninstallLaunchAgent(options);
|
|
16
|
+
};
|
|
17
|
+
installWindowsTask = async (options = {}) => {
|
|
18
|
+
await this.hostAutostartCommandService.installWindowsTask(options);
|
|
19
|
+
};
|
|
20
|
+
uninstallWindowsTask = async (options = {}) => {
|
|
21
|
+
await this.hostAutostartCommandService.uninstallWindowsTask(options);
|
|
22
|
+
};
|
|
23
|
+
autostartStatus = async (options = {}) => {
|
|
24
|
+
await this.hostAutostartCommandService.autostartStatus(options);
|
|
25
|
+
};
|
|
26
|
+
autostartDoctor = async (options = {}) => {
|
|
27
|
+
await this.hostAutostartCommandService.autostartDoctor(options);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ServiceCommands };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ServiceAutostartCommandOptions } from "../../../../shared/types/cli.types.js";
|
|
2
|
+
import { HostAutostartService } from "./host-autostart.service.js";
|
|
3
|
+
|
|
4
|
+
//#region src/commands/service/services/autostart/host-autostart-command.service.d.ts
|
|
5
|
+
type HostAutostartCommandServiceOptions = {
|
|
6
|
+
hostAutostartService?: HostAutostartService;
|
|
7
|
+
};
|
|
8
|
+
declare class HostAutostartCommandService {
|
|
9
|
+
private readonly hostAutostartService;
|
|
10
|
+
constructor(options?: HostAutostartCommandServiceOptions);
|
|
11
|
+
installSystemd: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
12
|
+
uninstallSystemd: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
13
|
+
installLaunchAgent: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
14
|
+
uninstallLaunchAgent: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
15
|
+
installWindowsTask: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
16
|
+
uninstallWindowsTask: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
17
|
+
autostartStatus: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
18
|
+
autostartDoctor: (options?: ServiceAutostartCommandOptions) => Promise<void>;
|
|
19
|
+
private handleInstallResult;
|
|
20
|
+
private handleUninstallResult;
|
|
21
|
+
private printInstallLikeResult;
|
|
22
|
+
private resolveRequiredSystemdScope;
|
|
23
|
+
private resolveOptionalSystemdScope;
|
|
24
|
+
private printAutostartStatus;
|
|
25
|
+
private printAutostartDoctor;
|
|
26
|
+
private formatOwner;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { HostAutostartCommandService };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { HostAutostartService } from "./host-autostart.service.js";
|
|
2
|
+
//#region src/commands/service/services/autostart/host-autostart-command.service.ts
|
|
3
|
+
var HostAutostartCommandService = class {
|
|
4
|
+
hostAutostartService;
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
this.hostAutostartService = options.hostAutostartService ?? new HostAutostartService();
|
|
7
|
+
}
|
|
8
|
+
installSystemd = async (options = {}) => {
|
|
9
|
+
const scope = this.resolveRequiredSystemdScope(options);
|
|
10
|
+
if (!scope) {
|
|
11
|
+
process.exitCode = 1;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const result = await this.hostAutostartService.installSystemd(scope, { dryRun: Boolean(options.dryRun) });
|
|
15
|
+
this.handleInstallResult(result, options, "systemd autostart installed.");
|
|
16
|
+
};
|
|
17
|
+
uninstallSystemd = async (options = {}) => {
|
|
18
|
+
const scope = this.resolveRequiredSystemdScope(options);
|
|
19
|
+
if (!scope) {
|
|
20
|
+
process.exitCode = 1;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const result = await this.hostAutostartService.uninstallSystemd(scope, { dryRun: Boolean(options.dryRun) });
|
|
24
|
+
this.handleUninstallResult(result, options, "systemd autostart uninstalled.");
|
|
25
|
+
};
|
|
26
|
+
installLaunchAgent = async (options = {}) => {
|
|
27
|
+
const result = await this.hostAutostartService.installLaunchAgent({ dryRun: Boolean(options.dryRun) });
|
|
28
|
+
this.handleInstallResult(result, options, "LaunchAgent autostart installed.");
|
|
29
|
+
};
|
|
30
|
+
uninstallLaunchAgent = async (options = {}) => {
|
|
31
|
+
const result = await this.hostAutostartService.uninstallLaunchAgent({ dryRun: Boolean(options.dryRun) });
|
|
32
|
+
this.handleUninstallResult(result, options, "LaunchAgent autostart uninstalled.");
|
|
33
|
+
};
|
|
34
|
+
installWindowsTask = async (options = {}) => {
|
|
35
|
+
const result = await this.hostAutostartService.installWindowsTask({ dryRun: Boolean(options.dryRun) });
|
|
36
|
+
this.handleInstallResult(result, options, "Windows task autostart installed.");
|
|
37
|
+
};
|
|
38
|
+
uninstallWindowsTask = async (options = {}) => {
|
|
39
|
+
const result = await this.hostAutostartService.uninstallWindowsTask({ dryRun: Boolean(options.dryRun) });
|
|
40
|
+
this.handleUninstallResult(result, options, "Windows task autostart uninstalled.");
|
|
41
|
+
};
|
|
42
|
+
autostartStatus = async (options = {}) => {
|
|
43
|
+
const scope = this.resolveOptionalSystemdScope(options);
|
|
44
|
+
if (scope === "invalid") {
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const status = await this.hostAutostartService.status(scope ?? void 0);
|
|
49
|
+
if (options.json) {
|
|
50
|
+
console.log(JSON.stringify(status, null, 2));
|
|
51
|
+
process.exitCode = 0;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.printAutostartStatus(status);
|
|
55
|
+
process.exitCode = 0;
|
|
56
|
+
};
|
|
57
|
+
autostartDoctor = async (options = {}) => {
|
|
58
|
+
const scope = this.resolveOptionalSystemdScope(options);
|
|
59
|
+
if (scope === "invalid") {
|
|
60
|
+
process.exitCode = 1;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const report = await this.hostAutostartService.doctor(scope ?? void 0);
|
|
64
|
+
if (options.json) {
|
|
65
|
+
console.log(JSON.stringify(report, null, 2));
|
|
66
|
+
process.exitCode = report.exitCode;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.printAutostartDoctor(report);
|
|
70
|
+
process.exitCode = report.exitCode;
|
|
71
|
+
};
|
|
72
|
+
handleInstallResult = (result, options, successMessage) => {
|
|
73
|
+
if (options.json) {
|
|
74
|
+
console.log(JSON.stringify(result, null, 2));
|
|
75
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!result.ok) {
|
|
79
|
+
process.exitCode = 1;
|
|
80
|
+
console.error(`Error: ${result.reasonIfUnavailable ?? "host autostart install failed."}`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.printInstallLikeResult(result);
|
|
84
|
+
console.log(result.dryRun ? "Dry run complete." : successMessage);
|
|
85
|
+
process.exitCode = 0;
|
|
86
|
+
};
|
|
87
|
+
handleUninstallResult = (result, options, successMessage) => {
|
|
88
|
+
if (options.json) {
|
|
89
|
+
console.log(JSON.stringify(result, null, 2));
|
|
90
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!result.ok) {
|
|
94
|
+
process.exitCode = 1;
|
|
95
|
+
console.error(`Error: ${result.reasonIfUnavailable ?? "host autostart uninstall failed."}`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
this.printInstallLikeResult(result);
|
|
99
|
+
if (!result.removed) console.log("No installed host autostart resource was found.");
|
|
100
|
+
console.log(result.dryRun ? "Dry run complete." : successMessage);
|
|
101
|
+
process.exitCode = 0;
|
|
102
|
+
};
|
|
103
|
+
printInstallLikeResult = (result) => {
|
|
104
|
+
if (result.hostOwner) console.log(`Host autostart owner: ${this.formatOwner(result.hostOwner)}`);
|
|
105
|
+
if (result.scope) console.log(`Scope: ${result.scope}`);
|
|
106
|
+
if (result.resourceName) console.log(`Resource: ${result.resourceName}`);
|
|
107
|
+
if (result.resourcePath) console.log(`Resource path: ${result.resourcePath}`);
|
|
108
|
+
if ("homeDir" in result && result.homeDir) console.log(`Home: ${result.homeDir}`);
|
|
109
|
+
if ("command" in result && result.command) console.log(`Command: ${result.command}`);
|
|
110
|
+
if (result.logHint) console.log(`Logs: ${result.logHint}`);
|
|
111
|
+
for (const action of result.actions) console.log(`- ${action}`);
|
|
112
|
+
};
|
|
113
|
+
resolveRequiredSystemdScope = (options) => {
|
|
114
|
+
if (Boolean(options.user) === Boolean(options.system)) {
|
|
115
|
+
console.error("Error: Choose exactly one scope: --user or --system.");
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return options.system ? "system" : "user";
|
|
119
|
+
};
|
|
120
|
+
resolveOptionalSystemdScope = (options) => {
|
|
121
|
+
const { system, user } = options;
|
|
122
|
+
if (user && system) {
|
|
123
|
+
console.error("Error: Choose at most one scope: --user or --system.");
|
|
124
|
+
return "invalid";
|
|
125
|
+
}
|
|
126
|
+
if (system) return "system";
|
|
127
|
+
if (user) return "user";
|
|
128
|
+
return null;
|
|
129
|
+
};
|
|
130
|
+
printAutostartStatus = (status) => {
|
|
131
|
+
console.log("Host autostart status:");
|
|
132
|
+
console.log(`- Supported: ${status.supported ? "yes" : "no"}`);
|
|
133
|
+
console.log(`- Installed: ${status.installed ? "yes" : "no"}`);
|
|
134
|
+
if (status.scope) console.log(`- Scope: ${status.scope}`);
|
|
135
|
+
if (status.hostOwner) console.log(`- Owner: ${this.formatOwner(status.hostOwner)}`);
|
|
136
|
+
if (status.resourceName) console.log(`- Resource: ${status.resourceName}`);
|
|
137
|
+
if (status.resourcePath) console.log(`- Resource path: ${status.resourcePath}`);
|
|
138
|
+
if (status.homeDir) console.log(`- Home: ${status.homeDir}`);
|
|
139
|
+
if (status.command) console.log(`- Command: ${status.command}`);
|
|
140
|
+
if (status.enabled !== null) console.log(`- Enabled: ${status.enabled ? "yes" : "no"}`);
|
|
141
|
+
if (status.active !== null) console.log(`- Active: ${status.active ? "yes" : "no"}`);
|
|
142
|
+
if (status.logHint) console.log(`- Logs: ${status.logHint}`);
|
|
143
|
+
if (status.reasonIfUnavailable) console.log(`- Note: ${status.reasonIfUnavailable}`);
|
|
144
|
+
};
|
|
145
|
+
printAutostartDoctor = (report) => {
|
|
146
|
+
this.printAutostartStatus(report.status);
|
|
147
|
+
console.log("Autostart doctor:");
|
|
148
|
+
for (const check of report.checks) console.log(`- [${check.status}] ${check.name}: ${check.detail}`);
|
|
149
|
+
};
|
|
150
|
+
formatOwner = (owner) => {
|
|
151
|
+
if (owner === "systemd-user-service") return "systemd user service";
|
|
152
|
+
if (owner === "systemd-system-service") return "systemd system service";
|
|
153
|
+
if (owner === "launchd-launch-agent") return "launchd LaunchAgent";
|
|
154
|
+
return "Windows Scheduled Task";
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
//#endregion
|
|
158
|
+
export { HostAutostartCommandService };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/commands/service/services/autostart/host-autostart-runtime.service.d.ts
|
|
2
|
+
type HostAutostartRuntimeServiceOptions = {
|
|
3
|
+
nodePath?: string;
|
|
4
|
+
argvEntry?: string;
|
|
5
|
+
importMetaUrl?: string;
|
|
6
|
+
getDataDir?: () => string;
|
|
7
|
+
};
|
|
8
|
+
type HostAutostartLaunchPlan = {
|
|
9
|
+
homeDir: string;
|
|
10
|
+
command: string;
|
|
11
|
+
args: string[];
|
|
12
|
+
};
|
|
13
|
+
declare class HostAutostartRuntimeService {
|
|
14
|
+
private readonly nodePath;
|
|
15
|
+
private readonly argvEntry;
|
|
16
|
+
private readonly importMetaUrl;
|
|
17
|
+
private readonly getResolvedDataDir;
|
|
18
|
+
constructor(options?: HostAutostartRuntimeServiceOptions);
|
|
19
|
+
resolveForegroundServeLaunch: () => HostAutostartLaunchPlan;
|
|
20
|
+
private resolveCliEntry;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { HostAutostartLaunchPlan, HostAutostartRuntimeService };
|