* Add metrics collection and terminal performance tests
* fix: handle Windows drive-letter paths across the codebase
Windows paths like C:\Users\foo\project were broken in multiple places:
- agent-storage slugified D:\MyProject as D:-MyProject (illegal colon)
- terminal-manager rejected all non-/ paths as relative
- bootstrap parser misparsed drive colons as TCP host:port
- daemon/client connection helpers misclassified Windows paths
- CLI cwd filtering used hardcoded / separators
- checkout-git worktree detection used hardcoded / in path checks
- worktree archive used split("/").pop() instead of path.basename()
All path helpers now normalize separators and handle Windows
drive letters with case-insensitive comparison where needed.
136 lines
3.6 KiB
TypeScript
136 lines
3.6 KiB
TypeScript
import path from "path";
|
|
import type { Command } from "commander";
|
|
import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
|
|
import type {
|
|
CommandOptions,
|
|
SingleResult,
|
|
OutputSchema,
|
|
CommandError,
|
|
} from "../../output/index.js";
|
|
|
|
/** Result type for worktree archive command */
|
|
export interface WorktreeArchiveResult {
|
|
name: string;
|
|
status: "archived";
|
|
removedAgents: string[];
|
|
}
|
|
|
|
/** Schema for archive command output */
|
|
export const archiveSchema: OutputSchema<WorktreeArchiveResult> = {
|
|
idField: "name",
|
|
columns: [
|
|
{ header: "NAME", field: "name" },
|
|
{ header: "STATUS", field: "status" },
|
|
{
|
|
header: "REMOVED AGENTS",
|
|
field: (item) => (item.removedAgents.length > 0 ? item.removedAgents.join(", ") : "-"),
|
|
},
|
|
],
|
|
};
|
|
|
|
export interface WorktreeArchiveOptions extends CommandOptions {
|
|
host?: string;
|
|
}
|
|
|
|
export type WorktreeArchiveCommandResult = SingleResult<WorktreeArchiveResult>;
|
|
|
|
export async function runArchiveCommand(
|
|
nameArg: string,
|
|
options: WorktreeArchiveOptions,
|
|
_command: Command,
|
|
): Promise<WorktreeArchiveCommandResult> {
|
|
const host = getDaemonHost({ host: options.host });
|
|
|
|
// Validate arguments
|
|
if (!nameArg || nameArg.trim().length === 0) {
|
|
const error: CommandError = {
|
|
code: "MISSING_WORKTREE_NAME",
|
|
message: "Worktree name is required",
|
|
details: "Usage: paseo worktree archive <name>",
|
|
};
|
|
throw error;
|
|
}
|
|
|
|
let client;
|
|
try {
|
|
client = await connectToDaemon({ host: options.host });
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
const error: CommandError = {
|
|
code: "DAEMON_NOT_RUNNING",
|
|
message: `Cannot connect to daemon at ${host}: ${message}`,
|
|
details: "Start the daemon with: paseo daemon start",
|
|
};
|
|
throw error;
|
|
}
|
|
|
|
try {
|
|
// Get the list of worktrees first to resolve the name
|
|
const listResponse = await client.getPaseoWorktreeList({});
|
|
|
|
if (listResponse.error) {
|
|
const error: CommandError = {
|
|
code: "WORKTREE_LIST_FAILED",
|
|
message: `Failed to list worktrees: ${listResponse.error.message}`,
|
|
};
|
|
throw error;
|
|
}
|
|
|
|
// Find the worktree by name or branch
|
|
const worktree = listResponse.worktrees.find((wt) => {
|
|
const name = path.basename(wt.worktreePath);
|
|
return name === nameArg || wt.branchName === nameArg;
|
|
});
|
|
|
|
if (!worktree) {
|
|
const error: CommandError = {
|
|
code: "WORKTREE_NOT_FOUND",
|
|
message: `Worktree not found: ${nameArg}`,
|
|
details: 'Use "paseo worktree ls" to list available worktrees',
|
|
};
|
|
throw error;
|
|
}
|
|
|
|
// Archive the worktree
|
|
const response = await client.archivePaseoWorktree({
|
|
worktreePath: worktree.worktreePath,
|
|
});
|
|
|
|
await client.close();
|
|
|
|
if (response.error) {
|
|
const error: CommandError = {
|
|
code: "WORKTREE_ARCHIVE_FAILED",
|
|
message: `Failed to archive worktree: ${response.error.message}`,
|
|
};
|
|
throw error;
|
|
}
|
|
|
|
const worktreeName = path.basename(worktree.worktreePath) || nameArg;
|
|
|
|
return {
|
|
type: "single",
|
|
data: {
|
|
name: worktreeName,
|
|
status: "archived",
|
|
removedAgents: response.removedAgents ?? [],
|
|
},
|
|
schema: archiveSchema,
|
|
};
|
|
} catch (err) {
|
|
await client.close().catch(() => {});
|
|
|
|
// Re-throw CommandError as-is
|
|
if (err && typeof err === "object" && "code" in err) {
|
|
throw err;
|
|
}
|
|
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
const error: CommandError = {
|
|
code: "WORKTREE_ARCHIVE_FAILED",
|
|
message: `Failed to archive worktree: ${message}`,
|
|
};
|
|
throw error;
|
|
}
|
|
}
|