@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,403 @@
|
|
|
1
|
+
import { HostAutostartRuntimeService } from "./host-autostart-runtime.service.js";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { win32 } from "node:path";
|
|
4
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
//#region src/commands/service/services/autostart/windows-task-autostart.service.ts
|
|
6
|
+
const DEFAULT_TASK_NAME = "NextClaw Host Autostart";
|
|
7
|
+
const SUPPORTED_PLATFORM = "win32";
|
|
8
|
+
var WindowsTaskAutostartService = class {
|
|
9
|
+
platform;
|
|
10
|
+
pathExists;
|
|
11
|
+
ensureDir;
|
|
12
|
+
writeFile;
|
|
13
|
+
removeFile;
|
|
14
|
+
runCommandImpl;
|
|
15
|
+
runtimeService;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.platform = options.platform ?? process.platform;
|
|
18
|
+
this.pathExists = options.existsSync ?? existsSync;
|
|
19
|
+
this.ensureDir = options.mkdirSync ?? mkdirSync;
|
|
20
|
+
this.writeFile = options.writeFileSync ?? writeFileSync;
|
|
21
|
+
this.removeFile = options.rmSync ?? rmSync;
|
|
22
|
+
this.runCommandImpl = options.runCommand ?? defaultRunCommand;
|
|
23
|
+
this.runtimeService = options.runtimeService ?? new HostAutostartRuntimeService();
|
|
24
|
+
}
|
|
25
|
+
install = async (scope, options = {}) => {
|
|
26
|
+
const plan = this.buildPlan();
|
|
27
|
+
if (!this.isSupported()) return this.createUnsupportedInstallResult(scope, Boolean(options.dryRun));
|
|
28
|
+
if (scope === "system") return this.createUnsupportedInstallResult(scope, Boolean(options.dryRun), "Windows task autostart currently supports --user only.");
|
|
29
|
+
const actions = [
|
|
30
|
+
`write launcher script ${plan.resourcePath}`,
|
|
31
|
+
`register scheduled task ${plan.resourceName}`,
|
|
32
|
+
`start scheduled task ${plan.resourceName}`
|
|
33
|
+
];
|
|
34
|
+
try {
|
|
35
|
+
if (!options.dryRun) {
|
|
36
|
+
this.ensureDir(win32.dirname(plan.resourcePath), { recursive: true });
|
|
37
|
+
this.ensureDir(win32.dirname(plan.logPath), { recursive: true });
|
|
38
|
+
this.writeFile(plan.resourcePath, plan.launcherContent);
|
|
39
|
+
await this.runCheckedPowerShell(this.renderInstallScript(plan));
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
dryRun: Boolean(options.dryRun),
|
|
45
|
+
scope,
|
|
46
|
+
hostOwner: plan.hostOwner,
|
|
47
|
+
resourceName: plan.resourceName,
|
|
48
|
+
resourcePath: plan.resourcePath,
|
|
49
|
+
homeDir: plan.homeDir,
|
|
50
|
+
command: plan.command,
|
|
51
|
+
logHint: plan.logHint,
|
|
52
|
+
actions,
|
|
53
|
+
reasonIfUnavailable: error instanceof Error ? error.message : "windows task install failed."
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
ok: true,
|
|
58
|
+
dryRun: Boolean(options.dryRun),
|
|
59
|
+
scope,
|
|
60
|
+
hostOwner: plan.hostOwner,
|
|
61
|
+
resourceName: plan.resourceName,
|
|
62
|
+
resourcePath: plan.resourcePath,
|
|
63
|
+
homeDir: plan.homeDir,
|
|
64
|
+
command: plan.command,
|
|
65
|
+
logHint: plan.logHint,
|
|
66
|
+
actions,
|
|
67
|
+
reasonIfUnavailable: null
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
uninstall = async (scope, options = {}) => {
|
|
71
|
+
const plan = this.buildPlan();
|
|
72
|
+
if (!this.isSupported()) return this.createUnsupportedUninstallResult(scope, Boolean(options.dryRun));
|
|
73
|
+
if (scope === "system") return this.createUnsupportedUninstallResult(scope, Boolean(options.dryRun), "Windows task autostart currently supports --user only.");
|
|
74
|
+
const installed = (await this.readTaskInfo(plan.resourceName))?.installed ?? false;
|
|
75
|
+
const actions = [`unregister scheduled task ${plan.resourceName}`, `remove launcher script ${plan.resourcePath}`];
|
|
76
|
+
if (!installed && !this.pathExists(plan.resourcePath)) return {
|
|
77
|
+
ok: true,
|
|
78
|
+
dryRun: Boolean(options.dryRun),
|
|
79
|
+
scope,
|
|
80
|
+
hostOwner: plan.hostOwner,
|
|
81
|
+
resourceName: plan.resourceName,
|
|
82
|
+
resourcePath: plan.resourcePath,
|
|
83
|
+
removed: false,
|
|
84
|
+
logHint: plan.logHint,
|
|
85
|
+
actions: ["no installed scheduled task or launcher script found"],
|
|
86
|
+
reasonIfUnavailable: null
|
|
87
|
+
};
|
|
88
|
+
try {
|
|
89
|
+
if (!options.dryRun) {
|
|
90
|
+
if (installed) await this.runCheckedPowerShell(this.renderUninstallScript(plan.resourceName));
|
|
91
|
+
this.removeFile(plan.resourcePath, { force: true });
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return {
|
|
95
|
+
ok: false,
|
|
96
|
+
dryRun: Boolean(options.dryRun),
|
|
97
|
+
scope,
|
|
98
|
+
hostOwner: plan.hostOwner,
|
|
99
|
+
resourceName: plan.resourceName,
|
|
100
|
+
resourcePath: plan.resourcePath,
|
|
101
|
+
removed: false,
|
|
102
|
+
logHint: plan.logHint,
|
|
103
|
+
actions,
|
|
104
|
+
reasonIfUnavailable: error instanceof Error ? error.message : "windows task uninstall failed."
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
ok: true,
|
|
109
|
+
dryRun: Boolean(options.dryRun),
|
|
110
|
+
scope,
|
|
111
|
+
hostOwner: plan.hostOwner,
|
|
112
|
+
resourceName: plan.resourceName,
|
|
113
|
+
resourcePath: plan.resourcePath,
|
|
114
|
+
removed: true,
|
|
115
|
+
logHint: plan.logHint,
|
|
116
|
+
actions,
|
|
117
|
+
reasonIfUnavailable: null
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
status = async (requestedScope) => {
|
|
121
|
+
const plan = this.buildPlan();
|
|
122
|
+
if (!this.isSupported()) return this.createUnsupportedStatus();
|
|
123
|
+
if (requestedScope === "system") return this.createUnsupportedStatus("Windows task autostart currently supports --user only.");
|
|
124
|
+
const taskInfo = await this.readTaskInfo(plan.resourceName);
|
|
125
|
+
return {
|
|
126
|
+
supported: true,
|
|
127
|
+
installed: taskInfo?.installed ?? false,
|
|
128
|
+
enabled: taskInfo?.enabled ?? false,
|
|
129
|
+
active: taskInfo?.active ?? false,
|
|
130
|
+
scope: "user",
|
|
131
|
+
hostOwner: plan.hostOwner,
|
|
132
|
+
resourceName: plan.resourceName,
|
|
133
|
+
resourcePath: plan.resourcePath,
|
|
134
|
+
homeDir: plan.homeDir,
|
|
135
|
+
command: plan.command,
|
|
136
|
+
logHint: plan.logHint,
|
|
137
|
+
reasonIfUnavailable: null
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
doctor = async (requestedScope) => {
|
|
141
|
+
const status = await this.status(requestedScope);
|
|
142
|
+
const plan = this.buildPlan();
|
|
143
|
+
const taskInfo = await this.readTaskInfo(plan.resourceName);
|
|
144
|
+
const checks = [
|
|
145
|
+
this.createPlatformCheck(status),
|
|
146
|
+
this.createTaskCheck(status, taskInfo, plan.resourceName),
|
|
147
|
+
this.createLauncherScriptCheck(plan.resourcePath),
|
|
148
|
+
this.createExecPathCheck(plan.launch.command),
|
|
149
|
+
this.createHomeDirCheck(plan.homeDir),
|
|
150
|
+
...this.createInstalledDoctorChecks(status, taskInfo)
|
|
151
|
+
];
|
|
152
|
+
return {
|
|
153
|
+
status,
|
|
154
|
+
checks,
|
|
155
|
+
exitCode: checks.some((check) => check.status === "fail" || check.status === "warn") ? 1 : 0
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
isSupported = () => {
|
|
159
|
+
return this.platform === SUPPORTED_PLATFORM;
|
|
160
|
+
};
|
|
161
|
+
createUnsupportedStatus = (reason = "windows task autostart currently supports Windows only.") => {
|
|
162
|
+
return {
|
|
163
|
+
supported: false,
|
|
164
|
+
installed: false,
|
|
165
|
+
enabled: null,
|
|
166
|
+
active: null,
|
|
167
|
+
scope: null,
|
|
168
|
+
hostOwner: null,
|
|
169
|
+
resourceName: null,
|
|
170
|
+
resourcePath: null,
|
|
171
|
+
homeDir: null,
|
|
172
|
+
command: null,
|
|
173
|
+
logHint: null,
|
|
174
|
+
reasonIfUnavailable: reason
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
createUnsupportedInstallResult = (scope, dryRun, reason = "windows task autostart currently supports Windows only.") => {
|
|
178
|
+
const plan = this.buildPlan();
|
|
179
|
+
const includePlan = this.isSupported();
|
|
180
|
+
return {
|
|
181
|
+
ok: false,
|
|
182
|
+
dryRun,
|
|
183
|
+
scope,
|
|
184
|
+
hostOwner: includePlan ? plan.hostOwner : "windows-logon-task",
|
|
185
|
+
resourceName: includePlan ? plan.resourceName : DEFAULT_TASK_NAME,
|
|
186
|
+
resourcePath: includePlan ? plan.resourcePath : null,
|
|
187
|
+
homeDir: includePlan ? plan.homeDir : null,
|
|
188
|
+
command: includePlan ? plan.command : null,
|
|
189
|
+
logHint: includePlan ? plan.logHint : null,
|
|
190
|
+
actions: [],
|
|
191
|
+
reasonIfUnavailable: reason
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
createUnsupportedUninstallResult = (scope, dryRun, reason = "windows task autostart currently supports Windows only.") => {
|
|
195
|
+
const plan = this.buildPlan();
|
|
196
|
+
const includePlan = this.isSupported();
|
|
197
|
+
return {
|
|
198
|
+
ok: false,
|
|
199
|
+
dryRun,
|
|
200
|
+
scope,
|
|
201
|
+
hostOwner: includePlan ? plan.hostOwner : "windows-logon-task",
|
|
202
|
+
resourceName: includePlan ? plan.resourceName : DEFAULT_TASK_NAME,
|
|
203
|
+
resourcePath: includePlan ? plan.resourcePath : null,
|
|
204
|
+
removed: false,
|
|
205
|
+
logHint: includePlan ? plan.logHint : null,
|
|
206
|
+
actions: [],
|
|
207
|
+
reasonIfUnavailable: reason
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
createPlatformCheck = (status) => {
|
|
211
|
+
return {
|
|
212
|
+
name: "platform",
|
|
213
|
+
status: status.supported ? "pass" : "fail",
|
|
214
|
+
detail: status.supported ? "windows supported" : status.reasonIfUnavailable ?? "unsupported platform"
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
createTaskCheck = (status, taskInfo, taskName) => {
|
|
218
|
+
return {
|
|
219
|
+
name: "task",
|
|
220
|
+
status: status.installed ? "pass" : "warn",
|
|
221
|
+
detail: taskInfo?.taskPath ?? taskName
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
createLauncherScriptCheck = (resourcePath) => {
|
|
225
|
+
return {
|
|
226
|
+
name: "launcher-script",
|
|
227
|
+
status: this.pathExists(resourcePath) ? "pass" : "warn",
|
|
228
|
+
detail: resourcePath
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
createExecPathCheck = (commandPath) => {
|
|
232
|
+
return {
|
|
233
|
+
name: "exec-path",
|
|
234
|
+
status: this.pathExists(commandPath) ? "pass" : "fail",
|
|
235
|
+
detail: commandPath
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
createHomeDirCheck = (homeDir) => {
|
|
239
|
+
return {
|
|
240
|
+
name: "home-dir",
|
|
241
|
+
status: this.pathExists(homeDir) ? "pass" : "warn",
|
|
242
|
+
detail: homeDir
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
createInstalledDoctorChecks = (status, taskInfo) => {
|
|
246
|
+
if (!status.installed) return [];
|
|
247
|
+
return [
|
|
248
|
+
{
|
|
249
|
+
name: "enabled",
|
|
250
|
+
status: status.enabled === false ? "warn" : "pass",
|
|
251
|
+
detail: status.enabled === false ? "scheduled task disabled" : "scheduled task enabled"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: "active",
|
|
255
|
+
status: status.active ? "pass" : "warn",
|
|
256
|
+
detail: taskInfo?.state ?? (status.active ? "Running" : "Not running")
|
|
257
|
+
},
|
|
258
|
+
this.createLastTaskResultCheck(taskInfo)
|
|
259
|
+
];
|
|
260
|
+
};
|
|
261
|
+
createLastTaskResultCheck = (taskInfo) => {
|
|
262
|
+
const lastTaskResult = taskInfo?.lastTaskResult;
|
|
263
|
+
return {
|
|
264
|
+
name: "last-task-result",
|
|
265
|
+
status: lastTaskResult === null || lastTaskResult === void 0 || lastTaskResult === 0 ? "pass" : "warn",
|
|
266
|
+
detail: lastTaskResult === null || lastTaskResult === void 0 ? "no recorded task result" : String(lastTaskResult)
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
buildPlan = () => {
|
|
270
|
+
const launch = this.runtimeService.resolveForegroundServeLaunch();
|
|
271
|
+
const homeDir = launch.homeDir;
|
|
272
|
+
const resourcePath = win32.resolve(homeDir, "autostart", "nextclaw-host-autostart.cmd");
|
|
273
|
+
const logPath = win32.resolve(homeDir, "logs", "host-autostart", "windows-task.log");
|
|
274
|
+
return {
|
|
275
|
+
launch,
|
|
276
|
+
homeDir,
|
|
277
|
+
hostOwner: "windows-logon-task",
|
|
278
|
+
resourceName: DEFAULT_TASK_NAME,
|
|
279
|
+
resourcePath,
|
|
280
|
+
logPath,
|
|
281
|
+
command: `cmd.exe /d /c "${resourcePath}"`,
|
|
282
|
+
logHint: `Get-Content -Path '${logPath.replace(/'/g, "''")}' -Wait`,
|
|
283
|
+
launcherContent: this.renderLauncher({
|
|
284
|
+
launch,
|
|
285
|
+
homeDir,
|
|
286
|
+
logPath
|
|
287
|
+
}),
|
|
288
|
+
actionExecute: "cmd.exe",
|
|
289
|
+
actionArguments: `/d /c "${resourcePath}"`
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
renderLauncher = (params) => {
|
|
293
|
+
const { launch, homeDir, logPath } = params;
|
|
294
|
+
const args = launch.args.map((value) => `"${this.escapeBatchValue(value)}"`).join(" ");
|
|
295
|
+
return [
|
|
296
|
+
"@echo off",
|
|
297
|
+
"setlocal",
|
|
298
|
+
`set "NEXTCLAW_HOME=${this.escapeBatchValue(homeDir)}"`,
|
|
299
|
+
`cd /d "${this.escapeBatchValue(homeDir)}"`,
|
|
300
|
+
`"${this.escapeBatchValue(launch.command)}" ${args} >> "${this.escapeBatchValue(logPath)}" 2>&1`,
|
|
301
|
+
""
|
|
302
|
+
].join("\r\n");
|
|
303
|
+
};
|
|
304
|
+
escapeBatchValue = (value) => {
|
|
305
|
+
return value.replace(/"/g, "\"\"");
|
|
306
|
+
};
|
|
307
|
+
renderInstallScript = (plan) => {
|
|
308
|
+
return [
|
|
309
|
+
`$taskName = '${plan.resourceName.replace(/'/g, "''")}'`,
|
|
310
|
+
`$userId = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name`,
|
|
311
|
+
`$action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument '/d /c "${plan.resourcePath.replace(/'/g, "''")}"'`,
|
|
312
|
+
"$trigger = New-ScheduledTaskTrigger -AtLogOn",
|
|
313
|
+
"$principal = New-ScheduledTaskPrincipal -UserId $userId -LogonType InteractiveToken -RunLevel Limited",
|
|
314
|
+
"$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries",
|
|
315
|
+
"Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null",
|
|
316
|
+
"Start-ScheduledTask -TaskName $taskName"
|
|
317
|
+
].join("\n");
|
|
318
|
+
};
|
|
319
|
+
renderUninstallScript = (taskName) => {
|
|
320
|
+
return [
|
|
321
|
+
`$task = Get-ScheduledTask -TaskName '${taskName.replace(/'/g, "''")}' -ErrorAction SilentlyContinue`,
|
|
322
|
+
"if ($null -ne $task) {",
|
|
323
|
+
" Unregister-ScheduledTask -TaskName $task.TaskName -Confirm:$false",
|
|
324
|
+
"}"
|
|
325
|
+
].join("\n");
|
|
326
|
+
};
|
|
327
|
+
readTaskInfo = async (taskName) => {
|
|
328
|
+
const result = await this.runPowerShell(this.renderStatusScript(taskName));
|
|
329
|
+
if (result.code !== 0) return null;
|
|
330
|
+
const payload = result.stdout.trim();
|
|
331
|
+
if (!payload) return null;
|
|
332
|
+
return JSON.parse(payload);
|
|
333
|
+
};
|
|
334
|
+
renderStatusScript = (taskName) => {
|
|
335
|
+
return [
|
|
336
|
+
`$task = Get-ScheduledTask -TaskName '${taskName.replace(/'/g, "''")}' -ErrorAction SilentlyContinue`,
|
|
337
|
+
"if ($null -eq $task) {",
|
|
338
|
+
" [pscustomobject]@{ installed = $false; enabled = $false; active = $false; state = $null; taskPath = $null; lastTaskResult = $null } | ConvertTo-Json -Compress",
|
|
339
|
+
" exit 0",
|
|
340
|
+
"}",
|
|
341
|
+
"$info = Get-ScheduledTaskInfo -TaskName $task.TaskName",
|
|
342
|
+
"[pscustomobject]@{",
|
|
343
|
+
" installed = $true",
|
|
344
|
+
" enabled = [bool]$task.Settings.Enabled",
|
|
345
|
+
" active = ([string]$task.State -eq 'Running')",
|
|
346
|
+
" state = [string]$task.State",
|
|
347
|
+
" taskPath = [string]$task.TaskPath",
|
|
348
|
+
" lastTaskResult = [int]$info.LastTaskResult",
|
|
349
|
+
"} | ConvertTo-Json -Compress"
|
|
350
|
+
].join("\n");
|
|
351
|
+
};
|
|
352
|
+
runCheckedPowerShell = async (script) => {
|
|
353
|
+
const result = await this.runPowerShell(script);
|
|
354
|
+
if (result.code === 0) return;
|
|
355
|
+
const detail = result.stderr || result.stdout || `exit code ${result.code}`;
|
|
356
|
+
throw new Error(`PowerShell command failed: ${detail}`);
|
|
357
|
+
};
|
|
358
|
+
runPowerShell = async (script) => {
|
|
359
|
+
const encodedScript = Buffer.from(script, "utf16le").toString("base64");
|
|
360
|
+
return await this.runCommandImpl("powershell", [
|
|
361
|
+
"-NoProfile",
|
|
362
|
+
"-NonInteractive",
|
|
363
|
+
"-ExecutionPolicy",
|
|
364
|
+
"Bypass",
|
|
365
|
+
"-EncodedCommand",
|
|
366
|
+
encodedScript
|
|
367
|
+
]);
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
const defaultRunCommand = async (command, args) => {
|
|
371
|
+
return await new Promise((resolvePromise, rejectPromise) => {
|
|
372
|
+
const child = spawn(command, args, {
|
|
373
|
+
env: process.env,
|
|
374
|
+
stdio: [
|
|
375
|
+
"ignore",
|
|
376
|
+
"pipe",
|
|
377
|
+
"pipe"
|
|
378
|
+
]
|
|
379
|
+
});
|
|
380
|
+
let stdout = "";
|
|
381
|
+
let stderr = "";
|
|
382
|
+
child.stdout?.setEncoding("utf-8");
|
|
383
|
+
child.stderr?.setEncoding("utf-8");
|
|
384
|
+
child.stdout?.on("data", (chunk) => {
|
|
385
|
+
stdout += chunk;
|
|
386
|
+
});
|
|
387
|
+
child.stderr?.on("data", (chunk) => {
|
|
388
|
+
stderr += chunk;
|
|
389
|
+
});
|
|
390
|
+
child.on("error", (error) => {
|
|
391
|
+
rejectPromise(error);
|
|
392
|
+
});
|
|
393
|
+
child.on("close", (code) => {
|
|
394
|
+
resolvePromise({
|
|
395
|
+
code: code ?? 1,
|
|
396
|
+
stdout: stdout.trim(),
|
|
397
|
+
stderr: stderr.trim()
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
//#endregion
|
|
403
|
+
export { WindowsTaskAutostartService };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/commands/service/types/autostart/host-autostart.types.d.ts
|
|
2
|
+
type HostAutostartScope = "user" | "system";
|
|
3
|
+
type HostAutostartOwner = "systemd-user-service" | "systemd-system-service" | "launchd-launch-agent" | "windows-logon-task";
|
|
4
|
+
type HostAutostartRunCommandResult = {
|
|
5
|
+
code: number;
|
|
6
|
+
stdout: string;
|
|
7
|
+
stderr: string;
|
|
8
|
+
};
|
|
9
|
+
type HostAutostartRunCommand = (command: string, args: string[]) => Promise<HostAutostartRunCommandResult>;
|
|
10
|
+
type HostAutostartStatus = {
|
|
11
|
+
supported: boolean;
|
|
12
|
+
installed: boolean;
|
|
13
|
+
enabled: boolean | null;
|
|
14
|
+
active: boolean | null;
|
|
15
|
+
scope: HostAutostartScope | null;
|
|
16
|
+
hostOwner: HostAutostartOwner | null;
|
|
17
|
+
resourceName: string | null;
|
|
18
|
+
resourcePath: string | null;
|
|
19
|
+
homeDir: string | null;
|
|
20
|
+
command: string | null;
|
|
21
|
+
logHint: string | null;
|
|
22
|
+
reasonIfUnavailable: string | null;
|
|
23
|
+
};
|
|
24
|
+
type HostAutostartCheck = {
|
|
25
|
+
name: string;
|
|
26
|
+
status: "pass" | "warn" | "fail";
|
|
27
|
+
detail: string;
|
|
28
|
+
};
|
|
29
|
+
type HostAutostartDoctorReport = {
|
|
30
|
+
status: HostAutostartStatus;
|
|
31
|
+
checks: HostAutostartCheck[];
|
|
32
|
+
exitCode: number;
|
|
33
|
+
};
|
|
34
|
+
type HostAutostartInstallResult = {
|
|
35
|
+
ok: boolean;
|
|
36
|
+
dryRun: boolean;
|
|
37
|
+
scope: HostAutostartScope | null;
|
|
38
|
+
hostOwner: HostAutostartOwner | null;
|
|
39
|
+
resourceName: string | null;
|
|
40
|
+
resourcePath: string | null;
|
|
41
|
+
homeDir: string | null;
|
|
42
|
+
command: string | null;
|
|
43
|
+
logHint: string | null;
|
|
44
|
+
actions: string[];
|
|
45
|
+
reasonIfUnavailable: string | null;
|
|
46
|
+
};
|
|
47
|
+
type HostAutostartUninstallResult = {
|
|
48
|
+
ok: boolean;
|
|
49
|
+
dryRun: boolean;
|
|
50
|
+
scope: HostAutostartScope | null;
|
|
51
|
+
hostOwner: HostAutostartOwner | null;
|
|
52
|
+
resourceName: string | null;
|
|
53
|
+
resourcePath: string | null;
|
|
54
|
+
removed: boolean;
|
|
55
|
+
logHint: string | null;
|
|
56
|
+
actions: string[];
|
|
57
|
+
reasonIfUnavailable: string | null;
|
|
58
|
+
};
|
|
59
|
+
type SystemdScopeFlags = {
|
|
60
|
+
user?: boolean;
|
|
61
|
+
system?: boolean;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { HostAutostartCheck, HostAutostartDoctorReport, HostAutostartInstallResult, HostAutostartOwner, HostAutostartRunCommand, HostAutostartRunCommandResult, HostAutostartScope, HostAutostartStatus, HostAutostartUninstallResult, SystemdScopeFlags };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AccountCommandOptions, AccountSetUsernameCommandOptions, AgentCommandOptions, AgentsListCommandOptions, AgentsNewCommandOptions, AgentsRemoveCommandOptions, AgentsRuntimesCommandOptions, AgentsUpdateCommandOptions, ChannelsAddOptions, ChannelsLoginOptions, CompanionDisableCommandOptions, CompanionEnableCommandOptions, CompanionStartCommandOptions, CompanionStatusCommandOptions, CompanionStopCommandOptions, ConfigGetOptions, ConfigSetOptions, CronAddOptions, DoctorCommandOptions, GatewayCommandOptions, HealthProbe, LoginCommandOptions, LogsTailCommandOptions, MarketplaceSkillsRecommendCommandOptions, MarketplaceSkillsSearchCommandOptions, McpAddCommandOptions, McpDoctorOptions, McpListOptions, PluginsInfoOptions, PluginsInstallOptions, PluginsListOptions, PluginsUninstallOptions, RemoteConnectCommandOptions, RemoteDoctorCommandOptions, RemoteEnableCommandOptions, RemoteStatusCommandOptions, RequestRestartParams, RuntimeStatusReport, SecretsApplyOptions, SecretsAuditOptions, SecretsConfigureOptions, SecretsReloadOptions, ServiceAutostartCommandOptions, SkillsInfoCommandOptions, SkillsInstalledCommandOptions, StartCommandOptions, StatusCommandOptions, UiCommandOptions, UpdateCommandOptions, UsageCommandOptions } from "./shared/types/cli.types.js";
|
|
2
|
+
import { NextclawServiceRuntime, NextclawServiceRuntimeOptions, runNextclawNpmRuntimeLauncher } from "./service-runtime.service.js";
|
|
3
|
+
import { readLearningLoopRuntimeConfig } from "@nextclaw/kernel";
|
|
4
|
+
export { AccountCommandOptions, AccountSetUsernameCommandOptions, AgentCommandOptions, AgentsListCommandOptions, AgentsNewCommandOptions, AgentsRemoveCommandOptions, AgentsRuntimesCommandOptions, AgentsUpdateCommandOptions, ChannelsAddOptions, ChannelsLoginOptions, CompanionDisableCommandOptions, CompanionEnableCommandOptions, CompanionStartCommandOptions, CompanionStatusCommandOptions, CompanionStopCommandOptions, ConfigGetOptions, ConfigSetOptions, CronAddOptions, DoctorCommandOptions, GatewayCommandOptions, HealthProbe, LoginCommandOptions, LogsTailCommandOptions, MarketplaceSkillsRecommendCommandOptions, MarketplaceSkillsSearchCommandOptions, McpAddCommandOptions, McpDoctorOptions, McpListOptions, NextclawServiceRuntime, type NextclawServiceRuntimeOptions, PluginsInfoOptions, PluginsInstallOptions, PluginsListOptions, PluginsUninstallOptions, RemoteConnectCommandOptions, RemoteDoctorCommandOptions, RemoteEnableCommandOptions, RemoteStatusCommandOptions, RequestRestartParams, RuntimeStatusReport, SecretsApplyOptions, SecretsAuditOptions, SecretsConfigureOptions, SecretsReloadOptions, ServiceAutostartCommandOptions, SkillsInfoCommandOptions, SkillsInstalledCommandOptions, StartCommandOptions, StatusCommandOptions, UiCommandOptions, UpdateCommandOptions, UsageCommandOptions, readLearningLoopRuntimeConfig, runNextclawNpmRuntimeLauncher };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { NpmRuntimeBundlePointer } from "./npm-runtime-bundle.types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/launcher/npm-runtime-bundle-layout.store.d.ts
|
|
4
|
+
declare class NpmRuntimeBundleLayoutStore {
|
|
5
|
+
private readonly rootDirectory;
|
|
6
|
+
constructor(rootDirectory?: string);
|
|
7
|
+
getRootDir: () => string;
|
|
8
|
+
getVersionsDir: () => string;
|
|
9
|
+
getVersionDir: (version: string) => string;
|
|
10
|
+
getStagingDir: () => string;
|
|
11
|
+
getCurrentPointerPath: () => string;
|
|
12
|
+
getPreviousPointerPath: () => string;
|
|
13
|
+
getStatePath: () => string;
|
|
14
|
+
ensureLauncherDirs: () => void;
|
|
15
|
+
readCurrentPointer: () => NpmRuntimeBundlePointer | null;
|
|
16
|
+
readPreviousPointer: () => NpmRuntimeBundlePointer | null;
|
|
17
|
+
writeCurrentPointer: (pointer: NpmRuntimeBundlePointer) => void;
|
|
18
|
+
writePreviousPointer: (pointer: NpmRuntimeBundlePointer) => void;
|
|
19
|
+
private readPointer;
|
|
20
|
+
private writePointer;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { NpmRuntimeBundleLayoutStore };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { getDataDir } from "@nextclaw/core";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
//#region src/launcher/npm-runtime-bundle-layout.store.ts
|
|
5
|
+
var NpmRuntimeBundleLayoutStore = class {
|
|
6
|
+
constructor(rootDirectory = join(getDataDir(), "launcher", "runtime-bundles")) {
|
|
7
|
+
this.rootDirectory = rootDirectory;
|
|
8
|
+
}
|
|
9
|
+
getRootDir = () => this.rootDirectory;
|
|
10
|
+
getVersionsDir = () => join(this.rootDirectory, "versions");
|
|
11
|
+
getVersionDir = (version) => join(this.getVersionsDir(), version);
|
|
12
|
+
getStagingDir = () => join(this.rootDirectory, "staging");
|
|
13
|
+
getCurrentPointerPath = () => join(this.rootDirectory, "current.json");
|
|
14
|
+
getPreviousPointerPath = () => join(this.rootDirectory, "previous.json");
|
|
15
|
+
getStatePath = () => join(getDataDir(), "launcher", "npm-runtime-update-state.json");
|
|
16
|
+
ensureLauncherDirs = () => {
|
|
17
|
+
mkdirSync(this.getVersionsDir(), { recursive: true });
|
|
18
|
+
mkdirSync(this.getStagingDir(), { recursive: true });
|
|
19
|
+
mkdirSync(dirname(this.getStatePath()), { recursive: true });
|
|
20
|
+
};
|
|
21
|
+
readCurrentPointer = () => this.readPointer(this.getCurrentPointerPath());
|
|
22
|
+
readPreviousPointer = () => this.readPointer(this.getPreviousPointerPath());
|
|
23
|
+
writeCurrentPointer = (pointer) => this.writePointer(this.getCurrentPointerPath(), pointer);
|
|
24
|
+
writePreviousPointer = (pointer) => this.writePointer(this.getPreviousPointerPath(), pointer);
|
|
25
|
+
readPointer = (pointerPath) => {
|
|
26
|
+
if (!existsSync(pointerPath)) return null;
|
|
27
|
+
const parsed = JSON.parse(readFileSync(pointerPath, "utf8"));
|
|
28
|
+
const version = typeof parsed.version === "string" ? parsed.version.trim() : "";
|
|
29
|
+
return version ? { version } : null;
|
|
30
|
+
};
|
|
31
|
+
writePointer = (pointerPath, pointer) => {
|
|
32
|
+
mkdirSync(dirname(pointerPath), { recursive: true });
|
|
33
|
+
writeFileSync(pointerPath, `${JSON.stringify(pointer, null, 2)}\n`, "utf8");
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { NpmRuntimeBundleLayoutStore };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NpmRuntimeBundleManifest } from "./npm-runtime-bundle.types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/launcher/npm-runtime-bundle-manifest.service.d.ts
|
|
4
|
+
declare class NpmRuntimeBundleManifestReader {
|
|
5
|
+
readFile: (filePath: string) => NpmRuntimeBundleManifest;
|
|
6
|
+
parse: (input: unknown, context?: string) => NpmRuntimeBundleManifest;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { NpmRuntimeBundleManifestReader };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
//#region src/launcher/npm-runtime-bundle-manifest.service.ts
|
|
3
|
+
function readRequiredString(record, key, context) {
|
|
4
|
+
const value = record[key];
|
|
5
|
+
if (typeof value !== "string" || !value.trim()) throw new Error(`${context} missing required string field: ${key}`);
|
|
6
|
+
return value.trim();
|
|
7
|
+
}
|
|
8
|
+
function readRequiredObject(record, key, context) {
|
|
9
|
+
const value = record[key];
|
|
10
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${context} missing required object field: ${key}`);
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
var NpmRuntimeBundleManifestReader = class {
|
|
14
|
+
readFile = (filePath) => {
|
|
15
|
+
if (!existsSync(filePath)) throw new Error(`runtime bundle manifest not found: ${filePath}`);
|
|
16
|
+
return this.parse(JSON.parse(readFileSync(filePath, "utf8")), filePath);
|
|
17
|
+
};
|
|
18
|
+
parse = (input, context = "runtime bundle manifest") => {
|
|
19
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error(`${context} must be an object`);
|
|
20
|
+
const record = input;
|
|
21
|
+
const launcherCompatibility = readRequiredObject(record, "launcherCompatibility", context);
|
|
22
|
+
const entrypoints = readRequiredObject(record, "entrypoints", context);
|
|
23
|
+
const migrationVersion = Number(record.migrationVersion);
|
|
24
|
+
if (!Number.isInteger(migrationVersion) || migrationVersion < 0) throw new Error(`${context} has invalid migrationVersion`);
|
|
25
|
+
return {
|
|
26
|
+
bundleVersion: readRequiredString(record, "bundleVersion", context),
|
|
27
|
+
platform: readRequiredString(record, "platform", context),
|
|
28
|
+
arch: readRequiredString(record, "arch", context),
|
|
29
|
+
uiVersion: readRequiredString(record, "uiVersion", context),
|
|
30
|
+
runtimeVersion: readRequiredString(record, "runtimeVersion", context),
|
|
31
|
+
builtInPluginSetVersion: readRequiredString(record, "builtInPluginSetVersion", context),
|
|
32
|
+
launcherCompatibility: { minVersion: readRequiredString(launcherCompatibility, "minVersion", `${context}.launcherCompatibility`) },
|
|
33
|
+
entrypoints: { runtimeScript: readRequiredString(entrypoints, "runtimeScript", `${context}.entrypoints`) },
|
|
34
|
+
migrationVersion
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { NpmRuntimeBundleManifestReader };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { NpmRuntimeBundleManifest } from "./npm-runtime-bundle.types.js";
|
|
2
|
+
import { NpmRuntimeBundleLayoutStore } from "./npm-runtime-bundle-layout.store.js";
|
|
3
|
+
import { NpmRuntimeBundleManifestReader } from "./npm-runtime-bundle-manifest.service.js";
|
|
4
|
+
import { NpmRuntimeUpdateStateStore } from "./npm-runtime-update-state.store.js";
|
|
5
|
+
|
|
6
|
+
//#region src/launcher/npm-runtime-bundle.service.d.ts
|
|
7
|
+
type ResolvedNpmRuntimeBundle = {
|
|
8
|
+
bundleDirectory: string;
|
|
9
|
+
manifest: NpmRuntimeBundleManifest;
|
|
10
|
+
runtimeScriptPath: string;
|
|
11
|
+
};
|
|
12
|
+
type NpmRuntimeBundleServiceOptions = {
|
|
13
|
+
layout: NpmRuntimeBundleLayoutStore;
|
|
14
|
+
stateStore: NpmRuntimeUpdateStateStore;
|
|
15
|
+
manifestReader?: NpmRuntimeBundleManifestReader;
|
|
16
|
+
platform?: NodeJS.Platform;
|
|
17
|
+
arch?: string;
|
|
18
|
+
launcherVersion?: string;
|
|
19
|
+
now?: () => number;
|
|
20
|
+
};
|
|
21
|
+
declare class NpmRuntimeBundleService {
|
|
22
|
+
private readonly options;
|
|
23
|
+
private readonly manifestReader;
|
|
24
|
+
private readonly platform;
|
|
25
|
+
private readonly arch;
|
|
26
|
+
private readonly launcherVersion;
|
|
27
|
+
private readonly now;
|
|
28
|
+
constructor(options: NpmRuntimeBundleServiceOptions);
|
|
29
|
+
resolveCurrentBundle: () => ResolvedNpmRuntimeBundle | null;
|
|
30
|
+
resolveVersion: (version: string) => ResolvedNpmRuntimeBundle;
|
|
31
|
+
installFromDirectory: (sourceDirectory: string) => Promise<ResolvedNpmRuntimeBundle>;
|
|
32
|
+
activateVersion: (version: string) => void;
|
|
33
|
+
pruneRetainedArtifacts: () => Promise<void>;
|
|
34
|
+
private clearStagingDirectory;
|
|
35
|
+
private verifyBundle;
|
|
36
|
+
}
|
|
37
|
+
declare function compareNpmRuntimeVersions(left: string, right: string): number;
|
|
38
|
+
declare function resolveEffectiveNpmRuntimeVersion(params: {
|
|
39
|
+
launcherVersion: string | null;
|
|
40
|
+
currentBundleVersion: string | null;
|
|
41
|
+
}): string | null;
|
|
42
|
+
declare function shouldPreferPackagedNpmRuntime(params: {
|
|
43
|
+
launcherVersion: string | null;
|
|
44
|
+
currentBundleVersion: string | null;
|
|
45
|
+
}): boolean;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { NpmRuntimeBundleService, ResolvedNpmRuntimeBundle, compareNpmRuntimeVersions, resolveEffectiveNpmRuntimeVersion, shouldPreferPackagedNpmRuntime };
|