Skip to content

Commit 69c2767

Browse files
committed
docs: document gateway cli helpers
1 parent cb5d43b commit 69c2767

10 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/cli/gateway-cli/discover.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Gateway discovery rendering helpers for Bonjour and wide-area DNS beacon output.
12
import { colorize, theme } from "../../../packages/terminal-core/src/theme.js";
23
import type { GatewayBonjourBeacon } from "../../infra/bonjour-discovery.js";
34
import { buildGatewayDiscoveryTarget } from "../../infra/gateway-discovery-targets.js";
@@ -21,6 +22,7 @@ export function pickGatewayPort(beacon: GatewayBonjourBeacon): number | null {
2122
}
2223

2324
export function dedupeBeacons(beacons: GatewayBonjourBeacon[]): GatewayBonjourBeacon[] {
25+
// Use display and endpoint fields; Bonjour can surface the same gateway on multiple interfaces.
2426
const out: GatewayBonjourBeacon[] = [];
2527
const seen = new Set<string>();
2628
for (const b of beacons) {

src/cli/gateway-cli/lifecycle.runtime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Lazy lifecycle runtime export hub used by gateway run-loop restart paths.
12
export {
23
abortEmbeddedAgentRun,
34
getActiveEmbeddedRunCount,

src/cli/gateway-cli/qa-parent-watchdog.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// QA watchdog for shutting down orphaned gateway children and cleaning staged temp roots.
12
import fs from "node:fs/promises";
23
import path from "node:path";
34
import { uniqueStrings } from "@openclaw/normalization-core/string-normalization";
@@ -48,6 +49,7 @@ function resolveQaParentPid(env: NodeJS.ProcessEnv, ownPid: number): number | nu
4849
}
4950

5051
function resolveQaCleanupRoot(rawValue: string | undefined): string | null {
52+
// Only cleanup roots with the QA prefix; env values are external to the child process.
5153
const raw = rawValue?.trim();
5254
if (!raw) {
5355
return null;

src/cli/gateway-cli/register.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Commander registration for gateway status, health, diagnostics, discovery, and run commands.
12
import type { Command } from "commander";
23
import { formatDocsLink } from "../../../packages/terminal-core/src/links.js";
34
import { colorize, isRich, theme } from "../../../packages/terminal-core/src/theme.js";
@@ -107,6 +108,7 @@ async function runGatewayCommand(
107108
label?: string,
108109
opts?: { json?: boolean },
109110
) {
111+
// JSON mode preserves structured gateway transport errors for automation callers.
110112
try {
111113
await action();
112114
} catch (err) {

src/cli/gateway-cli/run-command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Gateway run command option registration and lazy handoff to runtime startup.
12
import type { Command } from "commander";
23

34
const GATEWAY_AUTH_MODES = ["none", "token", "password", "trusted-proxy"] as const;

src/cli/gateway-cli/run-loop.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// In-process gateway run loop, restart signaling, drain, and update respawn handling.
12
import { randomUUID } from "node:crypto";
23
import net from "node:net";
34
import { clearRuntimeConfigSnapshot } from "../../config/runtime-snapshot.js";
@@ -45,6 +46,7 @@ const gatewayLifecycleRuntimeLoader = createLazyImportLoader<GatewayLifecycleRun
4546
const loadGatewayLifecycleRuntimeModule = () => gatewayLifecycleRuntimeLoader.load();
4647

4748
function createRestartIterationHook(onRestart: () => Promise<void> | void): () => Promise<boolean> {
49+
// The first loop starts fresh; subsequent iterations are in-process restarts.
4850
let isFirstIteration = true;
4951
return async () => {
5052
if (isFirstIteration) {

src/cli/gateway-cli/run.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Gateway run option resolution and local server startup command implementation.
12
import fs from "node:fs";
23
import { request } from "node:http";
34
import path from "node:path";
@@ -133,6 +134,7 @@ function extractGatewayMiskeys(parsed: unknown): {
133134
hasGatewayToken: boolean;
134135
hasRemoteToken: boolean;
135136
} {
137+
// Detect common token misplacements before startup falls back to unauthenticated mode.
136138
if (!parsed || typeof parsed !== "object") {
137139
return { hasGatewayToken: false, hasRemoteToken: false };
138140
}

src/cli/gateway-cli/shared.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Shared gateway CLI helpers for supervised-service stop guidance.
12
import {
23
resolveGatewayLaunchAgentLabel,
34
resolveGatewaySystemdServiceName,
@@ -31,6 +32,7 @@ function renderGatewayServiceStopHints(env: NodeJS.ProcessEnv = process.env): st
3132
}
3233

3334
export async function maybeExplainGatewayServiceStop() {
35+
// Direct `gateway run` should not race a managed service on the same port.
3436
const service = resolveGatewayService();
3537
let loaded: boolean | null;
3638
try {

src/cli/gateway-rpc.runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime gateway RPC helper shared by CLI commands that call the Gateway.
12
import {
23
GATEWAY_CLIENT_MODES,
34
GATEWAY_CLIENT_NAMES,
@@ -24,6 +25,7 @@ export async function callGatewayFromCliRuntime(
2425
params?: unknown,
2526
extra?: CallGatewayFromCliRuntimeExtra,
2627
) {
28+
// Progress is disabled for JSON output so stdout stays parseable.
2729
const showProgress = extra?.progress ?? opts.json !== true;
2830
return await withProgress(
2931
{

src/cli/gateway-rpc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Lazy gateway RPC facade and shared Commander options for CLI subcommands.
12
import type { Command } from "commander";
23
import type {
34
GatewayClientMode,
@@ -16,6 +17,7 @@ const gatewayRpcRuntimeLoader = createLazyImportLoader<GatewayRpcRuntimeModule>(
1617
);
1718

1819
async function loadGatewayRpcRuntime(): Promise<GatewayRpcRuntimeModule> {
20+
// Keep gateway transport/runtime imports out of help and shell completion startup.
1921
return gatewayRpcRuntimeLoader.load();
2022
}
2123

0 commit comments

Comments
 (0)