From cac41e8889e4e948e079a7f6c39df63dc88301fb Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Sat, 21 Nov 2026 22:18:48 +0000 Subject: [PATCH] cli/workspace: Expose Jujutsu checkout actions Route `paseo workspace jj` through the daemon for describe, new, fetch, bookmark publication and pull request creation. Co-Authored-By: Claude Opus 5.5 --- packages/cli/src/commands/workspace/index.ts | 2 + .../cli/src/commands/workspace/jujutsu.ts | 80 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 packages/cli/src/commands/workspace/jujutsu.ts diff --git a/packages/cli/src/commands/workspace/index.ts b/packages/cli/src/commands/workspace/index.ts index 7d15ef26f..1bfdf887e 100644 --- a/packages/cli/src/commands/workspace/index.ts +++ b/packages/cli/src/commands/workspace/index.ts @@ -5,6 +5,7 @@ import { runArchiveCommand } from "./archive.js"; import { runCreateCommand } from "./create.js"; import { runLsCommand } from "./ls.js"; import { runRenameCommand } from "./rename.js"; +import { createJujutsuCommand } from "./jujutsu.js"; import { runSetupCommand } from "./setup.js"; export function createWorkspaceCommand(): Command { @@ -65,5 +66,6 @@ export function createWorkspaceCommand(): Command { .argument("", "Workspace id"), ).action(withOutput(runArchiveCommand)); + workspace.addCommand(createJujutsuCommand()); return workspace; } diff --git a/packages/cli/src/commands/workspace/jujutsu.ts b/packages/cli/src/commands/workspace/jujutsu.ts new file mode 100644 index 000000000..4e32cb926 --- /dev/null +++ b/packages/cli/src/commands/workspace/jujutsu.ts @@ -0,0 +1,80 @@ +import { Argument, Command } from "commander"; +import { JujutsuCheckoutActionSchema } from "@getpaseo/protocol/messages"; +import { + withOutput, + type CommandOptions, + type OutputSchema, + type SingleResult, +} from "../../output/index.js"; +import { connectToDaemon } from "../../utils/client.js"; +import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js"; +import { resolveRepositoryDirectory } from "../worktree/repository-directory.js"; + +interface JujutsuCommandOptions extends CommandOptions { + path?: string; + description?: string; + bookmark?: string; + remote?: string; + base?: string; + title?: string; + body?: string; + create?: boolean; + parent?: string; +} + +const outputSchema: OutputSchema<{ action: string; url: string | null }> = { + idField: "action", + columns: [ + { header: "ACTION", field: "action" }, + { header: "URL", field: "url" }, + ], +}; + +export function createJujutsuCommand(): Command { + return addJsonAndDaemonHostOptions( + new Command("jj") + .description("Run a Jujutsu checkout action") + .addArgument( + new Argument("").choices([ + "describe", + "new", + "fetch", + "publish", + "create-pull-request", + ]), + ) + .option("--path ", "Checkout directory (default: current directory)") + .option("--description ", "Change description for describe or new") + .option("--parent ", "Start new on this instead of the current change") + .option("--bookmark ", "Head bookmark for publish or create-pull-request") + .option("--create", "Create the bookmark at the current change before publishing") + .option("--remote ", "Remote for fetch or publish") + .option("--base ", "Base bookmark for create-pull-request") + .option("--title ", "Pull request title") + .option("--body ", "Pull request body"), + ).action(withOutput(runJujutsuCommand)); +} + +async function runJujutsuCommand( + name: string, + options: JujutsuCommandOptions, + _command: Command, +): Promise> { + const action = JujutsuCheckoutActionSchema.parse({ + ...options, + kind: name === "create-pull-request" ? "create_pull_request" : name, + }); + const target = options.daemonTarget; + const cwd = resolveRepositoryDirectory({ cwd: options.path, daemonTarget: target }); + const client = await connectToDaemon({ target }); + try { + const status = await client.getCheckoutStatus(cwd); + if (status.error) throw new Error(status.error.message); + if (!status.jujutsu) throw new Error("The selected checkout does not use Jujutsu."); + const response = await client.checkoutJujutsuAction(cwd, status.jujutsu.changeId, action); + if (response.error) throw new Error(response.error.message); + return { type: "single", data: { action: name, url: response.url }, schema: outputSchema }; + } finally { + await client.close().catch(() => undefined); + } +}