Skip to content

Commit 407f477

Browse files
committed
docs: document daemon service env helpers
1 parent a3c44d5 commit 407f477

6 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/daemon/service-env.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Builds minimal, portable environment blocks for managed daemon services. */
12
import fs from "node:fs";
23
import os from "node:os";
34
import path from "node:path";
@@ -65,6 +66,8 @@ export const SERVICE_PROXY_ENV_KEYS = [
6566
function readServiceProxyEnvironment(
6667
env: Record<string, string | undefined>,
6768
): Record<string, string | undefined> {
69+
// Service env intentionally preserves only the canonical OpenClaw proxy knob;
70+
// generic shell proxy vars are audited but not frozen into services.
6871
const proxyUrl = normalizeOptionalString(env.OPENCLAW_PROXY_URL);
6972
return proxyUrl ? { OPENCLAW_PROXY_URL: proxyUrl } : {};
7073
}
@@ -90,6 +93,8 @@ function realpathServicePathDir(dir: string): string | undefined {
9093
function realpathExistingServicePathDir(dir: string): string | undefined {
9194
const parts: string[] = [];
9295
let current = dir;
96+
// Resolve the nearest existing ancestor so future-created bin dirs can still
97+
// be compared against the install workspace realpath.
9398
while (current && current !== path.posix.dirname(current)) {
9499
const realCurrent = realpathServicePathDir(current);
95100
if (realCurrent) {
@@ -333,6 +338,8 @@ function resolveLinuxUserBinDirs(
333338
export function getMinimalServicePathParts(options: MinimalServicePathOptions = {}): string[] {
334339
const platform = options.platform ?? process.platform;
335340
if (platform === "win32") {
341+
// Windows scheduled tasks inherit PATH from the task host; generated cmd
342+
// launchers should not freeze install-time PATH snapshots.
336343
return [];
337344
}
338345

src/daemon/service-layout.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Summarizes installed service command paths and OpenClaw package layout. */
12
import fs from "node:fs/promises";
23
import path from "node:path";
34
import { pathExists } from "../infra/fs-safe.js";
@@ -81,6 +82,8 @@ async function isSourceCheckoutRoot(candidate: string): Promise<boolean> {
8182

8283
async function resolveOpenClawPackageRoot(entrypoint: string): Promise<string | undefined> {
8384
let current = path.dirname(path.resolve(entrypoint));
85+
// Installed dist entrypoints can sit several levels below package root in
86+
// pnpm layouts; bound the walk to avoid scanning arbitrary filesystem depth.
8487
for (let depth = 0; depth < 8; depth += 1) {
8588
const packageJson = path.join(current, "package.json");
8689
if (await pathExists(packageJson)) {

src/daemon/service-managed-env.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Tracks managed service environment keys across reinstall and repair flows. */
12
import { sortUniqueStrings } from "@openclaw/normalization-core/string-normalization";
23
import { normalizeEnvVarKey } from "../infra/host-env-security.js";
34
import type { GatewayServiceEnvironmentValueSource } from "./service-types.js";
@@ -92,6 +93,8 @@ function deleteManagedServiceEnvKeys(
9293
if (normalizedKeys.size === 0) {
9394
return;
9495
}
96+
// Delete by normalized key so casing changes between installs do not leave
97+
// stale service-owned values behind.
9598
for (const rawKey of Object.keys(environment)) {
9699
const key = normalizeServiceEnvKey(rawKey);
97100
if (key && normalizedKeys.has(key)) {
@@ -155,6 +158,8 @@ export function collectInlineManagedServiceEnvKeys(
155158
if (!hasInlineEnvironmentSource(readEnvironmentValueSource(command, normalized))) {
156159
continue;
157160
}
161+
// Only inline/file-overlap sources can be repaired from the service command
162+
// itself; file-only values must stay owned by the generated env file.
158163
inlineKeys.push(normalized);
159164
}
160165
return sortUniqueStrings(inlineKeys);

src/daemon/service-path-policy.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Classifies service PATH entries that should not be frozen into daemons. */
12
import path from "node:path";
23
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
34

@@ -20,6 +21,8 @@ export function isNonMinimalServicePathEntry(entry: string, platform: NodeJS.Pla
2021
return false;
2122
}
2223
const normalized = normalizeServicePathEntry(entry, platform);
24+
// User shell package-manager paths are fragile in non-interactive services and
25+
// should be replaced by stable system/runtime paths.
2326
return (
2427
normalized.includes("/.nvm/") ||
2528
normalized.includes("/.fnm/") ||

src/daemon/service-runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Shared daemon runtime status types and systemd cgroup hygiene helpers. */
12
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
23

34
/** systemd cgroup fields used to spot unhealthy gateway service supervision. */
@@ -46,6 +47,7 @@ function describeSystemdCgroupLoadWarnings(runtime?: GatewayServiceSystemdRuntim
4647
if (!isRiskySystemdKillMode(killMode)) {
4748
return [];
4849
}
50+
// KillMode=process/none only becomes noisy when the cgroup is visibly large.
4951
const details: string[] = [];
5052
if (
5153
runtime.tasksCurrent !== undefined &&

src/daemon/service-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Shared daemon service argument, state, and command config contracts. */
12
import type { GatewayServiceRuntime } from "./service-runtime.js";
23

34
/** Environment map passed to service renderers and platform supervisors. */
@@ -35,6 +36,7 @@ export type GatewayServiceEnvArgs = {
3536

3637
export type GatewayServiceEnvironmentValueSource = "inline" | "file" | "inline-and-file";
3738

39+
/** Parsed command and env metadata from an installed platform service. */
3840
export type GatewayServiceCommandConfig = {
3941
programArguments: string[];
4042
workingDirectory?: string;

0 commit comments

Comments
 (0)