Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e7c8d3d
feat(cmux): add tools cmux profiles save / view / restore
genesiscz Apr 27, 2026
b234a7c
docs(cmux): add comprehensive Cmux.md command reference
genesiscz Apr 27, 2026
6cafac9
fix(cmux/save): propagate interactive overwrite confirmation to store…
claude Apr 27, 2026
4888111
fix(cmux/snapshot): ListPaneSurfacesResponse was wrapping a bare arra…
claude Apr 27, 2026
1265286
fix(cmux/cli): switch to Bun.spawn and reject signal-terminated proce…
claude Apr 27, 2026
e93aadc
fix(cmux/shell-probe): handle paths with spaces and bare ~ or … titles
claude Apr 27, 2026
33f3fd5
fix(cmux/profiles): add suggestCommand to non-interactive refusals
claude Apr 27, 2026
e5ee269
fix(cmux/restore): shell-quote cwd path before sending cd command
claude Apr 27, 2026
dcf2882
fix(cmux/edit): switch to Bun.spawn and guard empty EDITOR env value
claude Apr 27, 2026
70dedca
fix(cmux/resize): re-read layout after MAX_ITERATIONS to get accurate…
claude Apr 27, 2026
cfa8d5b
fix(cmux/store): normalize profile.name and version at write time
claude Apr 27, 2026
a643277
fix(cmux/docs): add language labels to all unlabeled fenced code blocks
claude Apr 27, 2026
5e68dc6
style(cmux): apply biome import-order and trailing-comma formatting
claude Apr 27, 2026
869b68a
fix(cmux): per-pane screen replay, correct surface placement, split-t…
genesiscz Apr 27, 2026
571646b
fix(cmux/snapshot): list-pane-surfaces does return a {surfaces:[]} wr…
genesiscz Apr 27, 2026
e9fce15
feat(cmux/save): clack multiselect step — pick what to capture per pane
genesiscz Apr 27, 2026
7c118f8
fix(cmux/snapshot): skip screen capture for the surface running save
genesiscz Apr 27, 2026
0401c85
fix(cmux): address remaining PR #154 review comments
genesiscz Apr 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/cmux/commands/profiles/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ProfileNotFoundError, ProfileStore } from "@app/cmux/lib/store";
import { isInteractive, suggestCommand } from "@app/utils/cli";
import { withCancel } from "@app/utils/prompts/clack/helpers";
import * as p from "@clack/prompts";
import type { Command } from "commander";
import pc from "picocolors";

export function registerDeleteCommand(parent: Command): void {
parent
.command("delete <name>")
.alias("rm")
.description("Remove a saved profile")
.option("-y, --yes", "Skip the confirmation prompt")
.action(async (name: string, flags: { yes?: boolean }) => {
const store = new ProfileStore();
try {
const summary = store.summarize(store.read(name));
if (!flags.yes) {
if (!isInteractive()) {
console.error(
`Refusing to delete in non-interactive mode without --yes. ${suggestCommand(`tools cmux profiles delete ${name} --yes`)}`
);
process.exitCode = 1;
return;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const confirmed = await withCancel(
p.confirm({
message: `Delete profile "${name}" (${summary.workspaces} workspace(s))?`,
initialValue: false,
})
);
if (!confirmed) {
p.cancel("Aborted.");
return;
}
}
store.delete(name);
console.log(`${pc.green("✓")} Deleted profile "${name}".`);
} catch (error) {
if (error instanceof ProfileNotFoundError) {
console.error(error.message);
process.exitCode = 1;
return;
}
throw error;
}
});
}
34 changes: 34 additions & 0 deletions src/cmux/commands/profiles/edit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { existsSync } from "node:fs";
import { ProfileNotFoundError, ProfileStore } from "@app/cmux/lib/store";
import type { Command } from "commander";

export function registerEditCommand(parent: Command): void {
parent
.command("edit <name>")
.description("Open the profile JSON in $EDITOR")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
.action(async (name: string) => {
const store = new ProfileStore();
const path = store.pathFor(name);
if (!existsSync(path)) {
throw new ProfileNotFoundError(name, path);
}

const editor = pickEditor();
const proc = Bun.spawn([editor.bin, ...editor.args, path], { stdio: ["inherit", "inherit", "inherit"] });
const exitCode = await proc.exited;
if (exitCode !== 0) {
throw new Error(`${editor.bin} exited with code ${exitCode}`);
}
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

function pickEditor(): { bin: string; args: string[] } {
const fromEnv = process.env.VISUAL || process.env.EDITOR;
if (fromEnv) {
const parts = fromEnv.split(/\s+/).filter(Boolean);
if (parts.length > 0) {
return { bin: parts[0], args: parts.slice(1) };
}
}
return { bin: "vi", args: [] };
}
22 changes: 22 additions & 0 deletions src/cmux/commands/profiles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Command } from "commander";
import { registerDeleteCommand } from "@app/cmux/commands/profiles/delete";
import { registerEditCommand } from "@app/cmux/commands/profiles/edit";
import { registerListCommand } from "@app/cmux/commands/profiles/list";
import { registerPathCommand } from "@app/cmux/commands/profiles/path";
import { registerRestoreCommand } from "@app/cmux/commands/profiles/restore";
import { registerSaveCommand } from "@app/cmux/commands/profiles/save";
import { registerViewCommand } from "@app/cmux/commands/profiles/view";

export function registerProfilesCommand(program: Command): void {
const profiles = program
.command("profiles")
.description("Manage saved cmux workspace profiles");

registerSaveCommand(profiles);
registerListCommand(profiles);
registerViewCommand(profiles);
registerRestoreCommand(profiles);
registerEditCommand(profiles);
registerDeleteCommand(profiles);
registerPathCommand(profiles);
}
25 changes: 25 additions & 0 deletions src/cmux/commands/profiles/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Command } from "commander";
import pc from "picocolors";
import { renderProfileList } from "@app/cmux/lib/format";
import { ProfileStore } from "@app/cmux/lib/store";

export function registerListCommand(parent: Command): void {
parent
.command("list")
.alias("ls")
.description("List saved cmux profiles")
.option("--json", "Emit JSON instead of the rendered table")
.action((opts: { json?: boolean }) => {
const store = new ProfileStore();
const summaries = store.list();
if (opts.json) {
console.log(JSON.stringify(summaries, null, 2));
return;
}
console.log(renderProfileList(summaries));
if (summaries.length > 0) {
console.log("");
console.log(pc.dim(`profiles dir: ${store.getProfilesDir()}`));
}
});
}
16 changes: 16 additions & 0 deletions src/cmux/commands/profiles/path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Command } from "commander";
import { ProfileStore } from "@app/cmux/lib/store";

export function registerPathCommand(parent: Command): void {
parent
.command("path [name]")
.description("Print the absolute path of a profile (or the profiles directory if no name)")
.action((name: string | undefined) => {
const store = new ProfileStore();
if (!name) {
console.log(store.getProfilesDir());
return;
}
console.log(store.pathFor(name));
});
}
107 changes: 107 additions & 0 deletions src/cmux/commands/profiles/restore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { buildPlan, type RestoreOptions, restoreProfile } from "@app/cmux/lib/restore";
import { ProfileNotFoundError, ProfileStore } from "@app/cmux/lib/store";
import type { Profile } from "@app/cmux/lib/types";
import logger from "@app/logger";
import { isInteractive, suggestCommand } from "@app/utils/cli";
import { withCancel } from "@app/utils/prompts/clack/helpers";
import * as p from "@clack/prompts";
import type { Command } from "commander";
import pc from "picocolors";

interface RestoreFlags {
prefix?: string;
replay?: boolean;
yes?: boolean;
dryRun?: boolean;
}

export function registerRestoreCommand(parent: Command): void {
parent
.command("restore <name>")
.description("Recreate cmux workspaces from a saved profile (always non-destructive)")
.option("--prefix <str>", "Workspace name prefix to apply on restore (default '<name>-')")
.option("--no-replay", "Skip queueing the captured shell command — only cd into cwd")
.option("-y, --yes", "Do not ask for confirmation")
.option("--dry-run", "Print the plan without modifying cmux")
.action(async (name: string, flags: RestoreFlags) => {
await runRestore(name, flags);
});
}

async function runRestore(name: string, flags: RestoreFlags): Promise<void> {
const store = new ProfileStore();
let profile: Profile;
try {
profile = store.read(name);
} catch (error) {
if (error instanceof ProfileNotFoundError) {
console.error(error.message);
process.exitCode = 1;
return;
}
throw error;
}

const opts: RestoreOptions = {
prefix: flags.prefix !== undefined ? flags.prefix : `${name}-`,
replay: flags.replay !== false,
yes: !!flags.yes,
dryRun: !!flags.dryRun,
};

const plan = buildPlan(profile, opts);

p.intro(pc.bgCyan(pc.black(" cmux profiles restore ")));
const planLines = plan.workspaces.map((ws) => {
return ` ${pc.cyan(ws.targetTitle)} ${pc.dim(`(${ws.paneCount} pane(s), ${ws.surfaceCount} surface(s))`)}`;
});
p.note(planLines.join("\n") || "(empty profile)", `Restore plan for ${pc.cyan(name)}`);

if (opts.dryRun) {
p.outro(pc.dim("Dry run — nothing changed."));
return;
}

if (!opts.yes) {
if (!isInteractive()) {
console.error(
`Pass --yes to skip the confirmation in non-interactive mode. ${suggestCommand(`tools cmux profiles restore ${name} --yes`)}`
);
process.exitCode = 1;
return;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
const proceed = await withCancel(
p.confirm({ message: `Create ${plan.workspaces.length} workspace(s)?`, initialValue: true })
);
if (!proceed) {
p.cancel("Aborted.");
return;
}
}

const spinner = p.spinner();
spinner.start("Recreating workspaces…");
const startedAt = Date.now();

try {
const outcome = await restoreProfile(profile, opts, {
onWorkspaceStart: ({ title, index, total }) => {
spinner.message(`Restoring ${index}/${total}: ${title}`);
},
});
spinner.stop(`Restored ${outcome.workspaces.length} workspace(s) in ${Date.now() - startedAt} ms`);

const summary = outcome.workspaces
.map((w) => {
const status = w.converged ? pc.green("✓") : pc.yellow("≈");
return ` ${status} ${pc.cyan(w.title)} ${pc.dim(`(${w.iterations} resize iter${w.iterations === 1 ? "" : "s"})`)}`;
})
.join("\n");
p.note(summary, "Result");
p.outro(pc.green("Done."));
} catch (error) {
spinner.stop("Restore failed.");
logger.error({ error }, "[cmux restore] failed");
throw error;
}
}
Loading
Loading