Files
paseo/packages/cli/src/commands/worktree/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

73 lines
2.2 KiB
TypeScript

import path from "node:path";
import type { Command } from "commander";
import { connectToDaemon } from "../../utils/client.js";
import type { CommandError, OutputSchema, SingleResult } from "../../output/index.js";
import { buildCreateWorktreeRequest, type WorktreeCreateOptions } from "./create-input.js";
export interface WorktreeCreateResult {
name: string;
branchName: string;
worktreePath: string;
}
export const createSchema: OutputSchema<WorktreeCreateResult> = {
idField: "worktreePath",
columns: [
{ header: "NAME", field: "name", width: 24 },
{ header: "BRANCH", field: "branchName", width: 28 },
{ header: "PATH", field: "worktreePath", width: 50 },
],
};
function cmdError(code: string, message: string, details?: string): CommandError {
return details ? { code, message, details } : { code, message };
}
export async function runCreateCommand(
options: WorktreeCreateOptions,
_command: Command,
): Promise<SingleResult<WorktreeCreateResult>> {
const cwd = options.cwd ?? process.cwd();
const request = buildCreateWorktreeRequest(options, cwd);
const client = await connectToDaemon({ target: options.daemonTarget });
try {
const response = await client.createPaseoWorktree(request);
const workspace = response.workspace;
if (!workspace || response.error) {
throw cmdError(
"WORKTREE_CREATE_FAILED",
`Failed to create worktree: ${response.error ?? "no workspace returned"}`,
);
}
if (!workspace.workspaceDirectory) {
throw cmdError(
"WORKTREE_CREATE_FAILED",
"Failed to create worktree: workspace directory missing from daemon response",
);
}
const worktreePath = workspace.workspaceDirectory;
return {
type: "single",
data: {
name: path.basename(worktreePath),
branchName: workspace.name,
worktreePath,
},
schema: createSchema,
};
} catch (err) {
if (err && typeof err === "object" && "code" in err) {
throw err;
}
const message = err instanceof Error ? err.message : String(err);
throw cmdError("WORKTREE_CREATE_FAILED", `Failed to create worktree: ${message}`);
} finally {
await client.close().catch(() => {});
}
}