

























@@ -1,3 +1,4 @@
1+/** Shared helpers for onboarding, reset, gateway checks, and wizard output. */
12import fs from "node:fs/promises";
23import path from "node:path";
34import { inspect } from "node:util";
@@ -42,6 +43,7 @@ export { detectBinary };
4243export { detectBrowserOpenSupport, openUrl, resolveBrowserOpenCommand };
4344export { resolveControlUiLinks };
444546+/** Handles Clack cancellation by exiting through the runtime. */
4547export function guardCancel<T>(value: T | symbol, runtime: RuntimeEnv): T {
4648if (isCancel(value)) {
4749cancel(stylePromptTitle("Setup cancelled.") ?? "Setup cancelled.");
@@ -51,6 +53,7 @@ export function guardCancel<T>(value: T | symbol, runtime: RuntimeEnv): T {
5153return value;
5254}
535556+/** Summarizes existing config values before onboarding overwrites or reuses them. */
5457export function summarizeExistingConfig(config: OpenClawConfig): string {
5558const rows: string[] = [];
5659const defaults = config.agents?.defaults;
@@ -127,6 +130,7 @@ function formatGatewayBind(value: string | undefined): string | undefined {
127130}
128131}
129132133+/** Normalizes gateway token prompts while rejecting JS stringification sentinels. */
130134export function normalizeGatewayTokenInput(value: unknown): string {
131135if (typeof value !== "string") {
132136return "";
@@ -140,6 +144,7 @@ export function normalizeGatewayTokenInput(value: unknown): string {
140144return trimmed;
141145}
142146147+/** Validates gateway password prompt input. */
143148export function validateGatewayPasswordInput(value: unknown): string | undefined {
144149if (typeof value !== "string") {
145150return "Required";
@@ -154,6 +159,7 @@ export function validateGatewayPasswordInput(value: unknown): string | undefined
154159return undefined;
155160}
156161162+/** Prints the onboarding banner. */
157163export function printWizardHeader(runtime: RuntimeEnv) {
158164const bannerWidth = 54;
159165const icon = decorativeEmoji("🦞");
@@ -172,6 +178,7 @@ export function printWizardHeader(runtime: RuntimeEnv) {
172178runtime.log(header);
173179}
174180181+/** Records wizard provenance metadata on config writes. */
175182export function applyWizardMetadata(
176183cfg: OpenClawConfig,
177184params: { command: string; mode: OnboardMode },
@@ -191,6 +198,7 @@ export function applyWizardMetadata(
191198};
192199}
193200201+/** Formats the no-GUI SSH tunnel hint for opening the Control UI remotely. */
194202export function formatControlUiSshHint(params: {
195203port: number;
196204basePath?: string;
@@ -226,6 +234,7 @@ function resolveSshTargetHint(): string {
226234return `${user}@${host}`;
227235}
228236237+/** Ensures workspace bootstrap files and session transcript directories exist. */
229238export async function ensureWorkspaceAndSessions(
230239workspaceDir: string,
231240runtime: RuntimeEnv,
@@ -246,6 +255,7 @@ export async function ensureWorkspaceAndSessions(
246255runtime.log(`Sessions OK: ${shortenHomePath(sessionsDir)}`);
247256}
248257258+/** Returns package manager choices offered by onboarding. */
249259export function resolveNodeManagerOptions(): Array<{
250260value: NodeManagerChoice;
251261label: string;
@@ -257,6 +267,7 @@ export function resolveNodeManagerOptions(): Array<{
257267];
258268}
259269270+/** Moves a path to Trash when it exists, logging a manual-delete fallback on failure. */
260271export async function moveToTrash(pathname: string, runtime: RuntimeEnv): Promise<void> {
261272if (!pathname) {
262273return;
@@ -297,6 +308,7 @@ async function resolveMoveToTrashAllowedRoots(targetPath: string): Promise<strin
297308return uniqueStrings(allowedRoots);
298309}
299310311+/** Deletes onboarding-managed state according to the selected reset scope. */
300312export async function handleReset(scope: ResetScope, workspaceDir: string, runtime: RuntimeEnv) {
301313await moveToTrash(resolveConfigPath(), runtime);
302314if (scope === "config") {
@@ -316,6 +328,7 @@ export async function handleReset(scope: ResetScope, workspaceDir: string, runti
316328}
317329}
318330331+/** Runs a single lightweight gateway probe for onboarding readiness checks. */
319332export async function probeGatewayReachable(params: {
320333url: string;
321334token?: string;
@@ -340,6 +353,7 @@ export async function probeGatewayReachable(params: {
340353}
341354}
342355356+/** Polls gateway reachability until success or deadline. */
343357export async function waitForGatewayReachable(params: {
344358url: string;
345359token?: string;
@@ -395,4 +409,5 @@ function summarizeError(err: unknown): string {
395409return line.length > 120 ? `${line.slice(0, 119)}…` : line;
396410}
397411412+/** Default workspace path shown by onboarding prompts. */
398413export const DEFAULT_WORKSPACE = DEFAULT_AGENT_WORKSPACE_DIR;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。