@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,53 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { extname, isAbsolute, resolve, win32 } from "node:path";
|
|
4
|
+
import { getDataDir } from "@nextclaw/core";
|
|
5
|
+
//#region src/commands/service/services/autostart/host-autostart-runtime.service.ts
|
|
6
|
+
const TYPESCRIPT_EXTENSIONS = new Set([
|
|
7
|
+
".ts",
|
|
8
|
+
".tsx",
|
|
9
|
+
".mts",
|
|
10
|
+
".cts"
|
|
11
|
+
]);
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
const resolveCliAppEntryFromImportMeta = (importMetaUrl) => {
|
|
14
|
+
const modulePath = fileURLToPath(importMetaUrl);
|
|
15
|
+
const cliRootIndex = modulePath.replace(/\\/g, "/").lastIndexOf("/cli/");
|
|
16
|
+
if (cliRootIndex === -1) return fileURLToPath(new URL("../../../app/index.js", importMetaUrl));
|
|
17
|
+
const extension = extname(modulePath) || ".js";
|
|
18
|
+
return resolve(modulePath.slice(0, cliRootIndex + 5), "app", `index${extension}`);
|
|
19
|
+
};
|
|
20
|
+
var HostAutostartRuntimeService = class {
|
|
21
|
+
nodePath;
|
|
22
|
+
argvEntry;
|
|
23
|
+
importMetaUrl;
|
|
24
|
+
getResolvedDataDir;
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
this.nodePath = options.nodePath ?? process.execPath;
|
|
27
|
+
this.argvEntry = options.argvEntry ?? process.argv[1];
|
|
28
|
+
this.importMetaUrl = options.importMetaUrl ?? import.meta.url;
|
|
29
|
+
this.getResolvedDataDir = options.getDataDir ?? getDataDir;
|
|
30
|
+
}
|
|
31
|
+
resolveForegroundServeLaunch = () => {
|
|
32
|
+
const cliEntry = this.resolveCliEntry();
|
|
33
|
+
return {
|
|
34
|
+
homeDir: this.getResolvedDataDir(),
|
|
35
|
+
command: this.nodePath,
|
|
36
|
+
args: TYPESCRIPT_EXTENSIONS.has(extname(cliEntry).toLowerCase()) ? [
|
|
37
|
+
require.resolve("tsx/cli"),
|
|
38
|
+
cliEntry,
|
|
39
|
+
"serve"
|
|
40
|
+
] : [cliEntry, "serve"]
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
resolveCliEntry = () => {
|
|
44
|
+
const argvEntry = this.argvEntry?.trim();
|
|
45
|
+
if (argvEntry) {
|
|
46
|
+
if (isAbsolute(argvEntry) || win32.isAbsolute(argvEntry)) return argvEntry;
|
|
47
|
+
return resolve(argvEntry);
|
|
48
|
+
}
|
|
49
|
+
return resolveCliAppEntryFromImportMeta(this.importMetaUrl);
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { HostAutostartRuntimeService };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HostAutostartDoctorReport, HostAutostartInstallResult, HostAutostartScope, HostAutostartStatus, HostAutostartUninstallResult } from "../../types/autostart/host-autostart.types.js";
|
|
2
|
+
import { LinuxSystemdAutostartService } from "./linux-systemd-autostart.service.js";
|
|
3
|
+
import { MacosLaunchAgentAutostartService } from "./macos-launch-agent-autostart.service.js";
|
|
4
|
+
import { WindowsTaskAutostartService } from "./windows-task-autostart.service.js";
|
|
5
|
+
|
|
6
|
+
//#region src/commands/service/services/autostart/host-autostart.service.d.ts
|
|
7
|
+
type HostAutostartServiceOptions = {
|
|
8
|
+
linuxSystemdService?: LinuxSystemdAutostartService;
|
|
9
|
+
macosLaunchAgentService?: MacosLaunchAgentAutostartService;
|
|
10
|
+
windowsTaskService?: WindowsTaskAutostartService;
|
|
11
|
+
platform?: NodeJS.Platform;
|
|
12
|
+
};
|
|
13
|
+
declare class HostAutostartService {
|
|
14
|
+
private readonly platform;
|
|
15
|
+
private readonly linuxSystemdService;
|
|
16
|
+
private readonly macosLaunchAgentService;
|
|
17
|
+
private readonly windowsTaskService;
|
|
18
|
+
constructor(options?: HostAutostartServiceOptions);
|
|
19
|
+
installSystemd: (scope: HostAutostartScope, options?: {
|
|
20
|
+
dryRun?: boolean;
|
|
21
|
+
}) => Promise<HostAutostartInstallResult>;
|
|
22
|
+
uninstallSystemd: (scope: HostAutostartScope, options?: {
|
|
23
|
+
dryRun?: boolean;
|
|
24
|
+
}) => Promise<HostAutostartUninstallResult>;
|
|
25
|
+
installLaunchAgent: (options?: {
|
|
26
|
+
dryRun?: boolean;
|
|
27
|
+
}) => Promise<HostAutostartInstallResult>;
|
|
28
|
+
uninstallLaunchAgent: (options?: {
|
|
29
|
+
dryRun?: boolean;
|
|
30
|
+
}) => Promise<HostAutostartUninstallResult>;
|
|
31
|
+
installWindowsTask: (options?: {
|
|
32
|
+
dryRun?: boolean;
|
|
33
|
+
}) => Promise<HostAutostartInstallResult>;
|
|
34
|
+
uninstallWindowsTask: (options?: {
|
|
35
|
+
dryRun?: boolean;
|
|
36
|
+
}) => Promise<HostAutostartUninstallResult>;
|
|
37
|
+
status: (scope?: HostAutostartScope) => Promise<HostAutostartStatus>;
|
|
38
|
+
doctor: (scope?: HostAutostartScope) => Promise<HostAutostartDoctorReport>;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { HostAutostartService };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { LinuxSystemdAutostartService } from "./linux-systemd-autostart.service.js";
|
|
2
|
+
import { MacosLaunchAgentAutostartService } from "./macos-launch-agent-autostart.service.js";
|
|
3
|
+
import { WindowsTaskAutostartService } from "./windows-task-autostart.service.js";
|
|
4
|
+
//#region src/commands/service/services/autostart/host-autostart.service.ts
|
|
5
|
+
var HostAutostartService = class {
|
|
6
|
+
platform;
|
|
7
|
+
linuxSystemdService;
|
|
8
|
+
macosLaunchAgentService;
|
|
9
|
+
windowsTaskService;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.platform = options.platform ?? process.platform;
|
|
12
|
+
this.linuxSystemdService = options.linuxSystemdService ?? new LinuxSystemdAutostartService();
|
|
13
|
+
this.macosLaunchAgentService = options.macosLaunchAgentService ?? new MacosLaunchAgentAutostartService();
|
|
14
|
+
this.windowsTaskService = options.windowsTaskService ?? new WindowsTaskAutostartService();
|
|
15
|
+
}
|
|
16
|
+
installSystemd = async (scope, options = {}) => {
|
|
17
|
+
return await this.linuxSystemdService.install(scope, options);
|
|
18
|
+
};
|
|
19
|
+
uninstallSystemd = async (scope, options = {}) => {
|
|
20
|
+
return await this.linuxSystemdService.uninstall(scope, options);
|
|
21
|
+
};
|
|
22
|
+
installLaunchAgent = async (options = {}) => {
|
|
23
|
+
return await this.macosLaunchAgentService.install("user", options);
|
|
24
|
+
};
|
|
25
|
+
uninstallLaunchAgent = async (options = {}) => {
|
|
26
|
+
return await this.macosLaunchAgentService.uninstall("user", options);
|
|
27
|
+
};
|
|
28
|
+
installWindowsTask = async (options = {}) => {
|
|
29
|
+
return await this.windowsTaskService.install("user", options);
|
|
30
|
+
};
|
|
31
|
+
uninstallWindowsTask = async (options = {}) => {
|
|
32
|
+
return await this.windowsTaskService.uninstall("user", options);
|
|
33
|
+
};
|
|
34
|
+
status = async (scope) => {
|
|
35
|
+
if (this.platform === "linux") return await this.linuxSystemdService.status(scope);
|
|
36
|
+
if (this.platform === "darwin") return await this.macosLaunchAgentService.status(scope);
|
|
37
|
+
if (this.platform === "win32") return await this.windowsTaskService.status(scope);
|
|
38
|
+
return await this.linuxSystemdService.status(scope);
|
|
39
|
+
};
|
|
40
|
+
doctor = async (scope) => {
|
|
41
|
+
if (this.platform === "linux") return await this.linuxSystemdService.doctor(scope);
|
|
42
|
+
if (this.platform === "darwin") return await this.macosLaunchAgentService.doctor(scope);
|
|
43
|
+
if (this.platform === "win32") return await this.windowsTaskService.doctor(scope);
|
|
44
|
+
return await this.linuxSystemdService.doctor(scope);
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { HostAutostartService };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { HostAutostartDoctorReport, HostAutostartInstallResult, HostAutostartRunCommand, HostAutostartScope, HostAutostartStatus, HostAutostartUninstallResult } from "../../types/autostart/host-autostart.types.js";
|
|
2
|
+
import { HostAutostartRuntimeService } from "./host-autostart-runtime.service.js";
|
|
3
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/service/services/autostart/linux-systemd-autostart.service.d.ts
|
|
6
|
+
type LinuxSystemdAutostartServiceOptions = {
|
|
7
|
+
platform?: NodeJS.Platform;
|
|
8
|
+
env?: NodeJS.ProcessEnv;
|
|
9
|
+
getHomeDir?: () => string;
|
|
10
|
+
existsSync?: (path: string) => boolean;
|
|
11
|
+
mkdirSync?: typeof mkdirSync;
|
|
12
|
+
writeFileSync?: typeof writeFileSync;
|
|
13
|
+
rmSync?: typeof rmSync;
|
|
14
|
+
runCommand?: HostAutostartRunCommand;
|
|
15
|
+
runtimeService?: HostAutostartRuntimeService;
|
|
16
|
+
};
|
|
17
|
+
declare class LinuxSystemdAutostartService {
|
|
18
|
+
private readonly platform;
|
|
19
|
+
private readonly env;
|
|
20
|
+
private readonly getHomeDir;
|
|
21
|
+
private readonly pathExists;
|
|
22
|
+
private readonly ensureDir;
|
|
23
|
+
private readonly writeFile;
|
|
24
|
+
private readonly removeFile;
|
|
25
|
+
private readonly runCommandImpl;
|
|
26
|
+
private readonly runtimeService;
|
|
27
|
+
constructor(options?: LinuxSystemdAutostartServiceOptions);
|
|
28
|
+
install: (scope: HostAutostartScope, options?: {
|
|
29
|
+
dryRun?: boolean;
|
|
30
|
+
}) => Promise<HostAutostartInstallResult>;
|
|
31
|
+
uninstall: (scope: HostAutostartScope, options?: {
|
|
32
|
+
dryRun?: boolean;
|
|
33
|
+
}) => Promise<HostAutostartUninstallResult>;
|
|
34
|
+
status: (requestedScope?: HostAutostartScope) => Promise<HostAutostartStatus>;
|
|
35
|
+
doctor: (requestedScope?: HostAutostartScope) => Promise<HostAutostartDoctorReport>;
|
|
36
|
+
private isSupported;
|
|
37
|
+
private getUnsupportedReason;
|
|
38
|
+
private createUnsupportedStatus;
|
|
39
|
+
private createUnsupportedInstallResult;
|
|
40
|
+
private resolveScopeForRead;
|
|
41
|
+
private buildPlan;
|
|
42
|
+
private getUnitPath;
|
|
43
|
+
private escapeSystemdValue;
|
|
44
|
+
private formatCommand;
|
|
45
|
+
private runCheckedCommand;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { LinuxSystemdAutostartService };
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { HostAutostartRuntimeService } from "./host-autostart-runtime.service.js";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
//#region src/commands/service/services/autostart/linux-systemd-autostart.service.ts
|
|
7
|
+
const DEFAULT_SYSTEMD_SERVICE_NAME = "nextclaw.service";
|
|
8
|
+
const SUPPORTED_PLATFORM = "linux";
|
|
9
|
+
var LinuxSystemdAutostartService = class {
|
|
10
|
+
platform;
|
|
11
|
+
env;
|
|
12
|
+
getHomeDir;
|
|
13
|
+
pathExists;
|
|
14
|
+
ensureDir;
|
|
15
|
+
writeFile;
|
|
16
|
+
removeFile;
|
|
17
|
+
runCommandImpl;
|
|
18
|
+
runtimeService;
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
this.platform = options.platform ?? process.platform;
|
|
21
|
+
this.env = options.env ?? process.env;
|
|
22
|
+
this.getHomeDir = options.getHomeDir ?? homedir;
|
|
23
|
+
this.pathExists = options.existsSync ?? existsSync;
|
|
24
|
+
this.ensureDir = options.mkdirSync ?? mkdirSync;
|
|
25
|
+
this.writeFile = options.writeFileSync ?? writeFileSync;
|
|
26
|
+
this.removeFile = options.rmSync ?? rmSync;
|
|
27
|
+
this.runCommandImpl = options.runCommand ?? defaultRunCommand;
|
|
28
|
+
this.runtimeService = options.runtimeService ?? new HostAutostartRuntimeService();
|
|
29
|
+
}
|
|
30
|
+
install = async (scope, options = {}) => {
|
|
31
|
+
if (!this.isSupported()) return this.createUnsupportedInstallResult(scope, Boolean(options.dryRun));
|
|
32
|
+
const plan = this.buildPlan(scope);
|
|
33
|
+
const actions = [
|
|
34
|
+
`write unit file ${plan.resourcePath}`,
|
|
35
|
+
`run ${this.formatCommand(plan.systemctlCommand, [...plan.systemctlScopeArgs, "daemon-reload"])}`,
|
|
36
|
+
`run ${this.formatCommand(plan.systemctlCommand, [
|
|
37
|
+
...plan.systemctlScopeArgs,
|
|
38
|
+
"enable",
|
|
39
|
+
plan.resourceName
|
|
40
|
+
])}`,
|
|
41
|
+
`run ${this.formatCommand(plan.systemctlCommand, [
|
|
42
|
+
...plan.systemctlScopeArgs,
|
|
43
|
+
"restart",
|
|
44
|
+
plan.resourceName
|
|
45
|
+
])}`
|
|
46
|
+
];
|
|
47
|
+
try {
|
|
48
|
+
if (!options.dryRun) {
|
|
49
|
+
this.ensureDir(dirname(plan.resourcePath), { recursive: true });
|
|
50
|
+
this.writeFile(plan.resourcePath, plan.unitContent);
|
|
51
|
+
await this.runCheckedCommand({
|
|
52
|
+
command: plan.systemctlCommand,
|
|
53
|
+
args: [...plan.systemctlScopeArgs, "daemon-reload"]
|
|
54
|
+
});
|
|
55
|
+
await this.runCheckedCommand({
|
|
56
|
+
command: plan.systemctlCommand,
|
|
57
|
+
args: [
|
|
58
|
+
...plan.systemctlScopeArgs,
|
|
59
|
+
"enable",
|
|
60
|
+
plan.resourceName
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
await this.runCheckedCommand({
|
|
64
|
+
command: plan.systemctlCommand,
|
|
65
|
+
args: [
|
|
66
|
+
...plan.systemctlScopeArgs,
|
|
67
|
+
"restart",
|
|
68
|
+
plan.resourceName
|
|
69
|
+
]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
dryRun: Boolean(options.dryRun),
|
|
76
|
+
scope,
|
|
77
|
+
hostOwner: plan.hostOwner,
|
|
78
|
+
resourceName: plan.resourceName,
|
|
79
|
+
resourcePath: plan.resourcePath,
|
|
80
|
+
homeDir: plan.homeDir,
|
|
81
|
+
command: plan.command,
|
|
82
|
+
logHint: plan.logHint,
|
|
83
|
+
actions,
|
|
84
|
+
reasonIfUnavailable: error instanceof Error ? error.message : "systemd autostart install failed."
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
ok: true,
|
|
89
|
+
dryRun: Boolean(options.dryRun),
|
|
90
|
+
scope,
|
|
91
|
+
hostOwner: plan.hostOwner,
|
|
92
|
+
resourceName: plan.resourceName,
|
|
93
|
+
resourcePath: plan.resourcePath,
|
|
94
|
+
homeDir: plan.homeDir,
|
|
95
|
+
command: plan.command,
|
|
96
|
+
logHint: plan.logHint,
|
|
97
|
+
actions,
|
|
98
|
+
reasonIfUnavailable: null
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
uninstall = async (scope, options = {}) => {
|
|
102
|
+
const plan = this.buildPlan(scope);
|
|
103
|
+
if (!this.isSupported()) return {
|
|
104
|
+
ok: false,
|
|
105
|
+
dryRun: Boolean(options.dryRun),
|
|
106
|
+
scope,
|
|
107
|
+
hostOwner: plan.hostOwner,
|
|
108
|
+
resourceName: plan.resourceName,
|
|
109
|
+
resourcePath: plan.resourcePath,
|
|
110
|
+
removed: false,
|
|
111
|
+
logHint: plan.logHint,
|
|
112
|
+
actions: [],
|
|
113
|
+
reasonIfUnavailable: this.getUnsupportedReason()
|
|
114
|
+
};
|
|
115
|
+
const installed = this.pathExists(plan.resourcePath);
|
|
116
|
+
const actions = [];
|
|
117
|
+
if (!installed) return {
|
|
118
|
+
ok: true,
|
|
119
|
+
dryRun: Boolean(options.dryRun),
|
|
120
|
+
scope,
|
|
121
|
+
hostOwner: plan.hostOwner,
|
|
122
|
+
resourceName: plan.resourceName,
|
|
123
|
+
resourcePath: plan.resourcePath,
|
|
124
|
+
removed: false,
|
|
125
|
+
logHint: plan.logHint,
|
|
126
|
+
actions: ["no installed unit file found"],
|
|
127
|
+
reasonIfUnavailable: null
|
|
128
|
+
};
|
|
129
|
+
actions.push(`run ${this.formatCommand(plan.systemctlCommand, [
|
|
130
|
+
...plan.systemctlScopeArgs,
|
|
131
|
+
"disable",
|
|
132
|
+
"--now",
|
|
133
|
+
plan.resourceName
|
|
134
|
+
])}`);
|
|
135
|
+
actions.push(`remove unit file ${plan.resourcePath}`);
|
|
136
|
+
actions.push(`run ${this.formatCommand(plan.systemctlCommand, [...plan.systemctlScopeArgs, "daemon-reload"])}`);
|
|
137
|
+
try {
|
|
138
|
+
if (!options.dryRun) {
|
|
139
|
+
await this.runCheckedCommand({
|
|
140
|
+
command: plan.systemctlCommand,
|
|
141
|
+
args: [
|
|
142
|
+
...plan.systemctlScopeArgs,
|
|
143
|
+
"disable",
|
|
144
|
+
"--now",
|
|
145
|
+
plan.resourceName
|
|
146
|
+
]
|
|
147
|
+
});
|
|
148
|
+
this.removeFile(plan.resourcePath, { force: true });
|
|
149
|
+
await this.runCheckedCommand({
|
|
150
|
+
command: plan.systemctlCommand,
|
|
151
|
+
args: [...plan.systemctlScopeArgs, "daemon-reload"]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
return {
|
|
156
|
+
ok: false,
|
|
157
|
+
dryRun: Boolean(options.dryRun),
|
|
158
|
+
scope,
|
|
159
|
+
hostOwner: plan.hostOwner,
|
|
160
|
+
resourceName: plan.resourceName,
|
|
161
|
+
resourcePath: plan.resourcePath,
|
|
162
|
+
removed: false,
|
|
163
|
+
logHint: plan.logHint,
|
|
164
|
+
actions,
|
|
165
|
+
reasonIfUnavailable: error instanceof Error ? error.message : "systemd autostart uninstall failed."
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
ok: true,
|
|
170
|
+
dryRun: Boolean(options.dryRun),
|
|
171
|
+
scope,
|
|
172
|
+
hostOwner: plan.hostOwner,
|
|
173
|
+
resourceName: plan.resourceName,
|
|
174
|
+
resourcePath: plan.resourcePath,
|
|
175
|
+
removed: true,
|
|
176
|
+
logHint: plan.logHint,
|
|
177
|
+
actions,
|
|
178
|
+
reasonIfUnavailable: null
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
status = async (requestedScope) => {
|
|
182
|
+
if (!this.isSupported()) return this.createUnsupportedStatus();
|
|
183
|
+
const resolvedScope = this.resolveScopeForRead(requestedScope);
|
|
184
|
+
if (!resolvedScope.scope) return {
|
|
185
|
+
supported: true,
|
|
186
|
+
installed: false,
|
|
187
|
+
enabled: null,
|
|
188
|
+
active: null,
|
|
189
|
+
scope: null,
|
|
190
|
+
hostOwner: null,
|
|
191
|
+
resourceName: null,
|
|
192
|
+
resourcePath: null,
|
|
193
|
+
homeDir: null,
|
|
194
|
+
command: null,
|
|
195
|
+
logHint: null,
|
|
196
|
+
reasonIfUnavailable: resolvedScope.reasonIfUnavailable
|
|
197
|
+
};
|
|
198
|
+
const plan = this.buildPlan(resolvedScope.scope);
|
|
199
|
+
if (!this.pathExists(plan.resourcePath)) return {
|
|
200
|
+
supported: true,
|
|
201
|
+
installed: false,
|
|
202
|
+
enabled: false,
|
|
203
|
+
active: false,
|
|
204
|
+
scope: resolvedScope.scope,
|
|
205
|
+
hostOwner: plan.hostOwner,
|
|
206
|
+
resourceName: plan.resourceName,
|
|
207
|
+
resourcePath: plan.resourcePath,
|
|
208
|
+
homeDir: plan.homeDir,
|
|
209
|
+
command: plan.command,
|
|
210
|
+
logHint: plan.logHint,
|
|
211
|
+
reasonIfUnavailable: null
|
|
212
|
+
};
|
|
213
|
+
const enabledResult = await this.runCommandImpl(plan.systemctlCommand, [
|
|
214
|
+
...plan.systemctlScopeArgs,
|
|
215
|
+
"is-enabled",
|
|
216
|
+
plan.resourceName
|
|
217
|
+
]);
|
|
218
|
+
const activeResult = await this.runCommandImpl(plan.systemctlCommand, [
|
|
219
|
+
...plan.systemctlScopeArgs,
|
|
220
|
+
"is-active",
|
|
221
|
+
plan.resourceName
|
|
222
|
+
]);
|
|
223
|
+
return {
|
|
224
|
+
supported: true,
|
|
225
|
+
installed: true,
|
|
226
|
+
enabled: enabledResult.code === 0,
|
|
227
|
+
active: activeResult.code === 0,
|
|
228
|
+
scope: resolvedScope.scope,
|
|
229
|
+
hostOwner: plan.hostOwner,
|
|
230
|
+
resourceName: plan.resourceName,
|
|
231
|
+
resourcePath: plan.resourcePath,
|
|
232
|
+
homeDir: plan.homeDir,
|
|
233
|
+
command: plan.command,
|
|
234
|
+
logHint: plan.logHint,
|
|
235
|
+
reasonIfUnavailable: null
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
doctor = async (requestedScope) => {
|
|
239
|
+
const status = await this.status(requestedScope);
|
|
240
|
+
const checks = [];
|
|
241
|
+
const launchPlan = this.runtimeService.resolveForegroundServeLaunch();
|
|
242
|
+
checks.push({
|
|
243
|
+
name: "platform",
|
|
244
|
+
status: status.supported ? "pass" : "fail",
|
|
245
|
+
detail: status.supported ? "linux supported" : status.reasonIfUnavailable ?? "unsupported platform"
|
|
246
|
+
});
|
|
247
|
+
checks.push({
|
|
248
|
+
name: "unit-file",
|
|
249
|
+
status: status.installed ? "pass" : "warn",
|
|
250
|
+
detail: status.resourcePath ?? "no unit path"
|
|
251
|
+
});
|
|
252
|
+
checks.push({
|
|
253
|
+
name: "exec-path",
|
|
254
|
+
status: this.pathExists(launchPlan.command) ? "pass" : "fail",
|
|
255
|
+
detail: launchPlan.command
|
|
256
|
+
});
|
|
257
|
+
checks.push({
|
|
258
|
+
name: "home-dir",
|
|
259
|
+
status: this.pathExists(launchPlan.homeDir) ? "pass" : "warn",
|
|
260
|
+
detail: launchPlan.homeDir
|
|
261
|
+
});
|
|
262
|
+
if (status.installed) {
|
|
263
|
+
checks.push({
|
|
264
|
+
name: "enabled",
|
|
265
|
+
status: status.enabled ? "pass" : "warn",
|
|
266
|
+
detail: status.enabled ? "systemd unit enabled" : "systemd unit not enabled"
|
|
267
|
+
});
|
|
268
|
+
checks.push({
|
|
269
|
+
name: "active",
|
|
270
|
+
status: status.active ? "pass" : "warn",
|
|
271
|
+
detail: status.active ? "systemd unit active" : "systemd unit not active"
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
status,
|
|
276
|
+
checks,
|
|
277
|
+
exitCode: checks.some((check) => check.status === "fail") ? 1 : checks.some((check) => check.status === "warn") ? 1 : 0
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
isSupported = () => {
|
|
281
|
+
return this.platform === SUPPORTED_PLATFORM;
|
|
282
|
+
};
|
|
283
|
+
getUnsupportedReason = () => {
|
|
284
|
+
return "systemd autostart currently supports Linux only.";
|
|
285
|
+
};
|
|
286
|
+
createUnsupportedStatus = () => {
|
|
287
|
+
return {
|
|
288
|
+
supported: false,
|
|
289
|
+
installed: false,
|
|
290
|
+
enabled: null,
|
|
291
|
+
active: null,
|
|
292
|
+
scope: null,
|
|
293
|
+
hostOwner: null,
|
|
294
|
+
resourceName: null,
|
|
295
|
+
resourcePath: null,
|
|
296
|
+
homeDir: null,
|
|
297
|
+
command: null,
|
|
298
|
+
logHint: null,
|
|
299
|
+
reasonIfUnavailable: this.getUnsupportedReason()
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
createUnsupportedInstallResult = (scope, dryRun) => {
|
|
303
|
+
const plan = this.buildPlan(scope);
|
|
304
|
+
return {
|
|
305
|
+
ok: false,
|
|
306
|
+
dryRun,
|
|
307
|
+
scope,
|
|
308
|
+
hostOwner: plan.hostOwner,
|
|
309
|
+
resourceName: plan.resourceName,
|
|
310
|
+
resourcePath: plan.resourcePath,
|
|
311
|
+
homeDir: plan.homeDir,
|
|
312
|
+
command: plan.command,
|
|
313
|
+
logHint: plan.logHint,
|
|
314
|
+
actions: [],
|
|
315
|
+
reasonIfUnavailable: this.getUnsupportedReason()
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
resolveScopeForRead = (requestedScope) => {
|
|
319
|
+
if (requestedScope) return {
|
|
320
|
+
scope: requestedScope,
|
|
321
|
+
reasonIfUnavailable: null
|
|
322
|
+
};
|
|
323
|
+
const userInstalled = this.pathExists(this.getUnitPath("user"));
|
|
324
|
+
const systemInstalled = this.pathExists(this.getUnitPath("system"));
|
|
325
|
+
if (userInstalled && systemInstalled) return {
|
|
326
|
+
scope: null,
|
|
327
|
+
reasonIfUnavailable: "Both user and system units are installed. Re-run with --user or --system."
|
|
328
|
+
};
|
|
329
|
+
if (userInstalled) return {
|
|
330
|
+
scope: "user",
|
|
331
|
+
reasonIfUnavailable: null
|
|
332
|
+
};
|
|
333
|
+
if (systemInstalled) return {
|
|
334
|
+
scope: "system",
|
|
335
|
+
reasonIfUnavailable: null
|
|
336
|
+
};
|
|
337
|
+
return {
|
|
338
|
+
scope: "user",
|
|
339
|
+
reasonIfUnavailable: null
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
buildPlan = (scope) => {
|
|
343
|
+
const launch = this.runtimeService.resolveForegroundServeLaunch();
|
|
344
|
+
const command = this.formatCommand(launch.command, launch.args);
|
|
345
|
+
const resourceName = DEFAULT_SYSTEMD_SERVICE_NAME;
|
|
346
|
+
const resourcePath = this.getUnitPath(scope);
|
|
347
|
+
const homeDir = launch.homeDir;
|
|
348
|
+
const hostOwner = scope === "user" ? "systemd-user-service" : "systemd-system-service";
|
|
349
|
+
const systemctlScopeArgs = scope === "user" ? ["--user"] : [];
|
|
350
|
+
const logHint = scope === "user" ? `journalctl --user -u ${resourceName} -f` : `journalctl -u ${resourceName} -f`;
|
|
351
|
+
const wantedBy = scope === "user" ? "default.target" : "multi-user.target";
|
|
352
|
+
return {
|
|
353
|
+
scope,
|
|
354
|
+
resourceName,
|
|
355
|
+
resourcePath,
|
|
356
|
+
homeDir,
|
|
357
|
+
hostOwner,
|
|
358
|
+
command,
|
|
359
|
+
logHint,
|
|
360
|
+
unitContent: [
|
|
361
|
+
"[Unit]",
|
|
362
|
+
"Description=NextClaw managed local service",
|
|
363
|
+
"After=network-online.target",
|
|
364
|
+
"Wants=network-online.target",
|
|
365
|
+
"",
|
|
366
|
+
"[Service]",
|
|
367
|
+
"Type=simple",
|
|
368
|
+
`WorkingDirectory=${this.escapeSystemdValue(homeDir)}`,
|
|
369
|
+
`Environment=NEXTCLAW_HOME=${this.escapeSystemdValue(homeDir)}`,
|
|
370
|
+
`ExecStart=${command}`,
|
|
371
|
+
"Restart=on-failure",
|
|
372
|
+
"RestartSec=2",
|
|
373
|
+
"",
|
|
374
|
+
"[Install]",
|
|
375
|
+
`WantedBy=${wantedBy}`,
|
|
376
|
+
""
|
|
377
|
+
].join("\n"),
|
|
378
|
+
systemctlCommand: "systemctl",
|
|
379
|
+
systemctlScopeArgs
|
|
380
|
+
};
|
|
381
|
+
};
|
|
382
|
+
getUnitPath = (scope) => {
|
|
383
|
+
if (scope === "system") return "/etc/systemd/system/nextclaw.service";
|
|
384
|
+
return resolve(this.env.XDG_CONFIG_HOME?.trim() || join(this.getHomeDir(), ".config"), "systemd", "user", "nextclaw.service");
|
|
385
|
+
};
|
|
386
|
+
escapeSystemdValue = (value) => {
|
|
387
|
+
if (/^[A-Za-z0-9_./:@%+=,-]+$/.test(value)) return value;
|
|
388
|
+
return `"${value.replace(/(["\\])/g, "\\$1")}"`;
|
|
389
|
+
};
|
|
390
|
+
formatCommand = (command, args) => {
|
|
391
|
+
return [command, ...args].map((value) => this.escapeSystemdValue(value)).join(" ");
|
|
392
|
+
};
|
|
393
|
+
runCheckedCommand = async ({ command, args }) => {
|
|
394
|
+
const result = await this.runCommandImpl(command, args);
|
|
395
|
+
if (result.code === 0) return;
|
|
396
|
+
const detail = result.stderr || result.stdout || `exit code ${result.code}`;
|
|
397
|
+
throw new Error(`Command failed: ${this.formatCommand(command, args)} (${detail})`);
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
const defaultRunCommand = async (command, args) => {
|
|
401
|
+
return await new Promise((resolvePromise, rejectPromise) => {
|
|
402
|
+
const child = spawn(command, args, {
|
|
403
|
+
env: process.env,
|
|
404
|
+
stdio: [
|
|
405
|
+
"ignore",
|
|
406
|
+
"pipe",
|
|
407
|
+
"pipe"
|
|
408
|
+
]
|
|
409
|
+
});
|
|
410
|
+
let stdout = "";
|
|
411
|
+
let stderr = "";
|
|
412
|
+
child.stdout?.setEncoding("utf-8");
|
|
413
|
+
child.stderr?.setEncoding("utf-8");
|
|
414
|
+
child.stdout?.on("data", (chunk) => {
|
|
415
|
+
stdout += chunk;
|
|
416
|
+
});
|
|
417
|
+
child.stderr?.on("data", (chunk) => {
|
|
418
|
+
stderr += chunk;
|
|
419
|
+
});
|
|
420
|
+
child.on("error", (error) => {
|
|
421
|
+
rejectPromise(error);
|
|
422
|
+
});
|
|
423
|
+
child.on("close", (code) => {
|
|
424
|
+
resolvePromise({
|
|
425
|
+
code: code ?? 1,
|
|
426
|
+
stdout: stdout.trim(),
|
|
427
|
+
stderr: stderr.trim()
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
//#endregion
|
|
433
|
+
export { LinuxSystemdAutostartService };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { HostAutostartDoctorReport, HostAutostartInstallResult, HostAutostartRunCommand, HostAutostartScope, HostAutostartStatus, HostAutostartUninstallResult } from "../../types/autostart/host-autostart.types.js";
|
|
2
|
+
import { HostAutostartRuntimeService } from "./host-autostart-runtime.service.js";
|
|
3
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/service/services/autostart/macos-launch-agent-autostart.service.d.ts
|
|
6
|
+
type MacosLaunchAgentAutostartServiceOptions = {
|
|
7
|
+
platform?: NodeJS.Platform;
|
|
8
|
+
env?: NodeJS.ProcessEnv;
|
|
9
|
+
getHomeDir?: () => string;
|
|
10
|
+
getUid?: () => number;
|
|
11
|
+
existsSync?: (path: string) => boolean;
|
|
12
|
+
mkdirSync?: typeof mkdirSync;
|
|
13
|
+
writeFileSync?: typeof writeFileSync;
|
|
14
|
+
rmSync?: typeof rmSync;
|
|
15
|
+
runCommand?: HostAutostartRunCommand;
|
|
16
|
+
runtimeService?: HostAutostartRuntimeService;
|
|
17
|
+
};
|
|
18
|
+
declare class MacosLaunchAgentAutostartService {
|
|
19
|
+
private readonly platform;
|
|
20
|
+
private readonly env;
|
|
21
|
+
private readonly getHomeDir;
|
|
22
|
+
private readonly getUid;
|
|
23
|
+
private readonly pathExists;
|
|
24
|
+
private readonly ensureDir;
|
|
25
|
+
private readonly writeFile;
|
|
26
|
+
private readonly removeFile;
|
|
27
|
+
private readonly runCommandImpl;
|
|
28
|
+
private readonly runtimeService;
|
|
29
|
+
constructor(options?: MacosLaunchAgentAutostartServiceOptions);
|
|
30
|
+
install: (scope: HostAutostartScope, options?: {
|
|
31
|
+
dryRun?: boolean;
|
|
32
|
+
}) => Promise<HostAutostartInstallResult>;
|
|
33
|
+
uninstall: (scope: HostAutostartScope, options?: {
|
|
34
|
+
dryRun?: boolean;
|
|
35
|
+
}) => Promise<HostAutostartUninstallResult>;
|
|
36
|
+
status: (requestedScope?: HostAutostartScope) => Promise<HostAutostartStatus>;
|
|
37
|
+
doctor: (requestedScope?: HostAutostartScope) => Promise<HostAutostartDoctorReport>;
|
|
38
|
+
private isSupported;
|
|
39
|
+
private createUnsupportedStatus;
|
|
40
|
+
private createUnsupportedInstallResult;
|
|
41
|
+
private createUnsupportedUninstallResult;
|
|
42
|
+
private buildPlan;
|
|
43
|
+
private renderPlist;
|
|
44
|
+
private escapeXml;
|
|
45
|
+
private escapeShellValue;
|
|
46
|
+
private formatCommand;
|
|
47
|
+
private hasGuiDomain;
|
|
48
|
+
private readEnabledState;
|
|
49
|
+
private escapeRegExp;
|
|
50
|
+
private runCheckedCommand;
|
|
51
|
+
private runTolerantCommand;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { MacosLaunchAgentAutostartService };
|