

























@@ -50,6 +50,7 @@ import {
5050shouldUseSecretsHelpFastPath,
5151shouldUseSetupOnboardConfigureHelpFastPath,
5252} from "./run-main-policy.js";
53+import { createGatewayStartupTrace } from "./startup-trace.js";
5354import { normalizeWindowsArgv } from "./windows-argv.js";
54555556export {
@@ -66,8 +67,6 @@ export {
6667shouldUseSetupOnboardConfigureHelpFastPath,
6768} from "./run-main-policy.js";
686969-type Awaitable<T> = T | Promise<T>;
70-7170const CLI_PROXY_ENV_KEYS = [
7271"HTTP_PROXY",
7372"HTTPS_PROXY",
@@ -87,40 +86,6 @@ const loadProxyLifecycleModule = async () => await import("../infra/net/proxy/pr
8786const loadCrestodianModule = async () => await import("../crestodian/crestodian.js");
8887const loadProgressModule = async () => await import("./progress.js");
898890-function createGatewayCliMainStartupTrace(argv: string[]) {
91-// Startup trace is scoped to gateway invocations to avoid routine CLI stderr noise.
92-const enabled =
93-isTruthyEnvValue(process.env.OPENCLAW_GATEWAY_STARTUP_TRACE) &&
94-argv.slice(2).includes("gateway");
95-const started = performance.now();
96-let last = started;
97-const emit = (name: string, durationMs: number, totalMs: number) => {
98-if (!enabled) {
99-return;
100-}
101-process.stderr.write(
102-`[gateway] startup trace: cli.main.${name} ${durationMs.toFixed(1)}ms total=${totalMs.toFixed(1)}ms\n`,
103-);
104-};
105-return {
106-mark(name: string) {
107-const now = performance.now();
108-emit(name, now - last, now - started);
109-last = now;
110-},
111-async measure<T>(name: string, run: () => Awaitable<T>): Promise<T> {
112-const before = performance.now();
113-try {
114-return await run();
115-} finally {
116-const now = performance.now();
117-emit(name, now - before, now - started);
118-last = now;
119-}
120-},
121-};
122-}
123-12489function isRemoteAgentDispatchInvocation(argv: string[], primary: string | null): boolean {
12590return primary === "agent" && !argv.includes("--local");
12691}
@@ -177,7 +142,7 @@ function isGatewayRunInvocationArgv(argv: string[]): boolean {
177142178143async function tryRunGatewayRunFastPath(
179144argv: string[],
180-startupTrace: ReturnType<typeof createGatewayCliMainStartupTrace>,
145+startupTrace: ReturnType<typeof createGatewayStartupTrace>,
181146): Promise<boolean> {
182147if (!isGatewayRunFastPathArgv(argv)) {
183148return false;
@@ -623,7 +588,7 @@ async function resolveUnownedCliPrimaryMessage(params: {
623588}
624589625590async function bootstrapCliProxyCaptureAndDispatcher(
626-startupTrace: ReturnType<typeof createGatewayCliMainStartupTrace>,
591+startupTrace: ReturnType<typeof createGatewayStartupTrace>,
627592options: { ensureDispatcher?: boolean } = {},
628593): Promise<void> {
629594const [
@@ -644,7 +609,7 @@ async function bootstrapCliProxyCaptureAndDispatcher(
644609645610export async function runCli(argv: string[] = process.argv) {
646611const originalArgv = normalizeWindowsArgv(argv);
647-const startupTrace = createGatewayCliMainStartupTrace(originalArgv);
612+const startupTrace = createGatewayStartupTrace(originalArgv, "cli.main");
648613const parsedContainer = parseCliContainerArgs(originalArgv);
649614if (!parsedContainer.ok) {
650615throw new Error(parsedContainer.error);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。