97845b3d69
- Added a `worktree.base` setting to allow users to specify a custom directory for agent-managed git worktrees. - Updated the `worktree` command to ensure settings are initialized before operations to respect the configured base path. - Enhanced directory resolution logic to support `~` expansion and enforce absolute paths for worktree environments.
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
/**
|
|
* List and clean up agent-managed git worktrees under `~/.omp/wt`.
|
|
*/
|
|
import { getProjectDir } from "@oh-my-pi/pi-utils";
|
|
import { Args, Command, Flags } from "@oh-my-pi/pi-utils/cli";
|
|
import { clearWorktrees, listWorktrees } from "../cli/worktree-cli";
|
|
import { Settings } from "../config/settings";
|
|
|
|
export default class Worktree extends Command {
|
|
static description = "List or clear agent-managed git worktrees (~/.omp/wt)";
|
|
|
|
static aliases = ["wt"];
|
|
|
|
static args = {
|
|
// `list` (default) inspects the worktree dir; `clear` removes entries.
|
|
// A positional action keeps `omp worktree` (the no-arg form) useful.
|
|
action: Args.string({
|
|
description: "list (default) or clear",
|
|
required: false,
|
|
options: ["list", "clear"],
|
|
default: "list",
|
|
}),
|
|
};
|
|
|
|
static flags = {
|
|
all: Flags.boolean({
|
|
description: "Clear every entry, including live PR-checkout worktrees (clear)",
|
|
default: false,
|
|
}),
|
|
"dry-run": Flags.boolean({
|
|
char: "n",
|
|
description: "Print what would be removed without touching the filesystem (clear)",
|
|
default: false,
|
|
}),
|
|
json: Flags.boolean({ char: "j", description: "Emit machine-readable JSON", default: false }),
|
|
};
|
|
|
|
static examples = [
|
|
"omp worktree",
|
|
"omp worktree list --json",
|
|
"omp worktree clear",
|
|
"omp worktree clear --dry-run",
|
|
"omp worktree clear --all",
|
|
];
|
|
|
|
async run(): Promise<void> {
|
|
const { args, flags } = await this.parse(Worktree);
|
|
// Load settings so the `worktree.base` override is applied before we scan
|
|
// — otherwise this command would inspect ~/.omp/wt while the agent created
|
|
// its worktrees under the configured base.
|
|
await Settings.init({ cwd: getProjectDir() });
|
|
if (args.action === "clear") {
|
|
await clearWorktrees({
|
|
all: flags.all ?? false,
|
|
dryRun: flags["dry-run"] ?? false,
|
|
json: flags.json ?? false,
|
|
});
|
|
return;
|
|
}
|
|
await listWorktrees({ json: flags.json ?? false });
|
|
}
|
|
}
|