Repository navigation
feat(cmux): add tools cmux profiles save / view / restore #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
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 b234a7c
docs(cmux): add comprehensive Cmux.md command reference
genesiscz 6cafac9
fix(cmux/save): propagate interactive overwrite confirmation to store…
claude 4888111
fix(cmux/snapshot): ListPaneSurfacesResponse was wrapping a bare arra…
claude 1265286
fix(cmux/cli): switch to Bun.spawn and reject signal-terminated proce…
claude e93aadc
fix(cmux/shell-probe): handle paths with spaces and bare ~ or … titles
claude 33f3fd5
fix(cmux/profiles): add suggestCommand to non-interactive refusals
claude e5ee269
fix(cmux/restore): shell-quote cwd path before sending cd command
claude dcf2882
fix(cmux/edit): switch to Bun.spawn and guard empty EDITOR env value
claude 70dedca
fix(cmux/resize): re-read layout after MAX_ITERATIONS to get accurate…
claude cfa8d5b
fix(cmux/store): normalize profile.name and version at write time
claude a643277
fix(cmux/docs): add language labels to all unlabeled fenced code blocks
claude 5e68dc6
style(cmux): apply biome import-order and trailing-comma formatting
claude 869b68a
fix(cmux): per-pane screen replay, correct surface placement, split-t…
genesiscz 571646b
fix(cmux/snapshot): list-pane-surfaces does return a {surfaces:[]} wr…
genesiscz e9fce15
feat(cmux/save): clack multiselect step — pick what to capture per pane
genesiscz 7c118f8
fix(cmux/snapshot): skip screen capture for the surface running save
genesiscz 0401c85
fix(cmux): address remaining PR #154 review comments
genesiscz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| 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; | ||
| } | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
|
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}`); | ||
| } | ||
| }); | ||
|
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: [] }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()}`)); | ||
| } | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
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; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.