Files
paseo/packages/cli/src/commands/project/create.ts
T
Mohamed Boudra 0110302b6f fix(daemon): keep lifecycle operations on the selected instance (#4575)
* fix(daemon): keep lifecycle operations on the selected instance

Restart reconstructed launch inputs and address fallback could redirect a home-selected shutdown to another daemon. Let supervisors publish bound endpoints, retain their worker restart contract, and share captured local lifecycle ownership between CLI and Desktop.

* test(daemon): verify bounded desktop readiness and cancellable artifacts

* test(cli): verify reload target hints and durable offline pairing

* test(daemon): align lifecycle fixtures with ownership and targeting

* fix(daemon): preserve reachability when status details time out

Provider discovery can outlast a status request after authentication succeeds. Keep local connection facts separate from unavailable details, while explicit remote queries retain their error outcome.

Migrate CLI and packaged Desktop fixtures to persistent managed configuration and explicit targets. Isolate generic Git observation from forge discovery and reuse disposable CLI homes on Windows.

* test(daemon): observe restart through the worker status RPC

The bounded CLI status observation may omit worker details while an authenticated connection remains healthy. Exercise the app-style restart through its full RPC and retain the replacement observation, with a real slow provider probe covering the distinction.
2026-09-11 08:33:22 +02:00

54 lines
1.9 KiB
TypeScript

import path from "node:path";
import type { Command } from "commander";
import type { CommandError, CommandOptions, SingleResult } from "../../output/index.js";
import { buildDaemonConnectionCommandError, connectToDaemon } from "../../utils/client.js";
import { projectSchema, toProjectRow, type ProjectRow } from "./shared.js";
export function resolveProjectPath(input: {
pathArg?: string;
cwd: string;
daemonTarget?: string;
}): string {
if (input.daemonTarget) {
if (input.pathArg === undefined) {
throw {
code: "MISSING_PATH",
message: "Project path is required when targeting a daemon explicitly",
details: "Usage: paseo project create <path> --host <host>",
} satisfies CommandError;
}
return input.pathArg;
}
return path.resolve(input.cwd, input.pathArg ?? ".");
}
export async function runCreateCommand(
pathArg: string | undefined,
options: CommandOptions,
_command: Command,
): Promise<SingleResult<ProjectRow>> {
const projectPath = resolveProjectPath({
pathArg,
cwd: process.cwd(),
daemonTarget: options.daemonTarget.kind === "endpoint" ? options.daemonTarget.host : undefined,
});
const client = await connectToDaemon({ target: options.daemonTarget }).catch((error: unknown) => {
throw buildDaemonConnectionCommandError({ target: options.daemonTarget, error });
});
try {
const payload = await client.addProject(projectPath);
if (!payload.project) {
throw new Error(payload.error ?? "Project creation failed");
}
return { type: "single", data: toProjectRow(payload.project), schema: projectSchema };
} catch (error) {
if (error && typeof error === "object" && "code" in error) throw error;
const message = error instanceof Error ? error.message : String(error);
throw { code: "PROJECT_CREATE_FAILED", message } satisfies CommandError;
} finally {
await client.close().catch(() => undefined);
}
}