File size: 4,119 Bytes
fc93158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { resolveCliName, ALT_CLI_NAME } from "../cli/cli-name.js";

// Default service labels (canonical + legacy compatibility)
export const GATEWAY_LAUNCH_AGENT_LABEL = "ai.openclaw.gateway";
export const GATEWAY_SYSTEMD_SERVICE_NAME = "openclaw-gateway";
export const GATEWAY_WINDOWS_TASK_NAME = "OpenClaw Gateway";
export const GATEWAY_SERVICE_MARKER = "openclaw";
export const GATEWAY_SERVICE_KIND = "gateway";
export const NODE_LAUNCH_AGENT_LABEL = "ai.openclaw.node";
export const NODE_SYSTEMD_SERVICE_NAME = "openclaw-node";
export const NODE_WINDOWS_TASK_NAME = "OpenClaw Node";
export const NODE_SERVICE_MARKER = "openclaw";
export const NODE_SERVICE_KIND = "node";
export const NODE_WINDOWS_TASK_SCRIPT_NAME = "node.cmd";

export const LEGACY_GATEWAY_SYSTEMD_SERVICE_NAMES: string[] = [
  "clawdbot-gateway",
  "moltbot-gateway",
];

export function resolveLegacyGatewayLaunchAgentLabels(profile?: string): string[] {
  const normalized = normalizeGatewayProfile(profile);
  const labels: string[] = [];
  if (resolveCliName() === ALT_CLI_NAME) {
    labels.push(normalized ? `ai.openclaw.${normalized}` : `ai.openclaw.gateway`);
  }
  return labels;
}

function resolveBaseName(): string {
  return resolveCliName();
}

function resolveDisplayName(): string {
  return resolveCliName() === ALT_CLI_NAME ? "OpenSkyNet" : "OpenClaw";
}

export function normalizeGatewayProfile(profile?: string): string | null {
  const trimmed = profile?.trim();
  if (!trimmed || trimmed.toLowerCase() === "default") {
    return null;
  }
  return trimmed;
}

export function resolveGatewayProfileSuffix(profile?: string): string {
  const normalized = normalizeGatewayProfile(profile);
  return normalized ? `-${normalized}` : "";
}

export function resolveGatewayLaunchAgentLabel(profile?: string): string {
  const normalized = normalizeGatewayProfile(profile);
  const base = resolveCliName() === ALT_CLI_NAME ? "ai.openskynet" : "ai.openclaw";
  if (!normalized) {
    return `${base}.gateway`;
  }
  return `${base}.${normalized}`;
}

export function resolveGatewaySystemdServiceName(profile?: string): string {
  const base = resolveBaseName();
  const suffix = resolveGatewayProfileSuffix(profile);
  return `${base}-gateway${suffix}`;
}

export function resolveGatewayWindowsTaskName(profile?: string): string {
  const base = resolveDisplayName();
  const normalized = normalizeGatewayProfile(profile);
  if (!normalized) {
    return `${base} Gateway`;
  }
  return `${base} Gateway (${normalized})`;
}

export function formatGatewayServiceDescription(params?: {
  profile?: string;
  version?: string;
}): string {
  const base = resolveDisplayName();
  const profile = normalizeGatewayProfile(params?.profile);
  const version = params?.version?.trim();
  const parts: string[] = [];
  if (profile) {
    parts.push(`profile: ${profile}`);
  }
  if (version) {
    parts.push(`v${version}`);
  }
  if (parts.length === 0) {
    return `${base} Gateway`;
  }
  return `${base} Gateway (${parts.join(", ")})`;
}

export function resolveGatewayServiceDescription(params: {
  env: Record<string, string | undefined>;
  environment?: Record<string, string | undefined>;
  description?: string;
}): string {
  return (
    params.description ??
    formatGatewayServiceDescription({
      profile: params.env.OPENCLAW_PROFILE,
      version: params.environment?.OPENCLAW_SERVICE_VERSION ?? params.env.OPENCLAW_SERVICE_VERSION,
    })
  );
}

export function resolveNodeLaunchAgentLabel(): string {
  const base = resolveCliName() === ALT_CLI_NAME ? "ai.openskynet" : "ai.openclaw";
  return `${base}.node`;
}

export function resolveNodeSystemdServiceName(): string {
  const base = resolveBaseName();
  return `${base}-node`;
}

export function resolveNodeWindowsTaskName(): string {
  const base = resolveDisplayName();
  return `${base} Node`;
}

export function formatNodeServiceDescription(params?: { version?: string }): string {
  const base = resolveDisplayName();
  const version = params?.version?.trim();
  if (!version) {
    return `${base} Node Host`;
  }
  return `${base} Node Host (v${version})`;
}