MCPcopy
hub / github.com/coder/mux / handleNewCommand

Function handleNewCommand

src/browser/utils/chatCommands.ts:1670–1745  ·  view source on GitHub ↗
(
  parsed: Extract<ParsedCommand, { type: "new" }>,
  context: CommandHandlerContext
)

Source from the content-addressed store, hash-verified

1668 * `pendingAutoTitle`.
1669 */
1670export async function handleNewCommand(
1671 parsed: Extract<ParsedCommand, { type: "new" }>,
1672 context: CommandHandlerContext
1673): Promise<CommandHandlerResult> {
1674 const {
1675 api: client,
1676 workspaceId,
1677 sendMessageOptions,
1678 setInput,
1679 setSendingState,
1680 setToast,
1681 } = context;
1682
1683 setInput(""); // Clear input immediately, like /fork.
1684 setSendingState(true);
1685
1686 try {
1687 // Get workspace info to extract projectPath. /new is a workspace-only
1688 // command, so the parent workspace's project becomes the new workspace's
1689 // project.
1690 const workspaceInfo = await client.workspace.getInfo({ workspaceId });
1691 if (!workspaceInfo) {
1692 throw new Error("Failed to get workspace info");
1693 }
1694
1695 // Treat blank/whitespace-only payloads the same as no message — pendingAutoTitle
1696 // only makes sense when there is real content for the LLM to title from.
1697 const trimmedStartMessage = parsed.startMessage?.trim() ?? "";
1698 const startMessage = trimmedStartMessage.length > 0 ? trimmedStartMessage : undefined;
1699
1700 const createResult = await createNewWorkspace({
1701 client,
1702 projectPath: workspaceInfo.projectPath,
1703 // workspaceName intentionally omitted — backend auto-generates (like /fork).
1704 startMessage,
1705 sendMessageOptions,
1706 // Match /fork: only flag pendingAutoTitle when there is a message to
1707 // generate the title from.
1708 pendingAutoTitle: Boolean(startMessage),
1709 });
1710
1711 if (!createResult.success) {
1712 const errorMsg = createResult.error ?? "Failed to create workspace";
1713 console.error("Failed to create workspace:", errorMsg);
1714 setToast({
1715 id: Date.now().toString(),
1716 type: "error",
1717 title: "Create Failed",
1718 message: errorMsg,
1719 });
1720 return { clearInput: false, toastShown: true };
1721 }
1722
1723 trackCommandUsed("new");
1724 const displayName =
1725 createResult.workspaceInfo?.title ?? createResult.workspaceInfo?.name ?? "new workspace";
1726 setToast({
1727 id: Date.now().toString(),

Callers 1

processSlashCommandFunction · 0.85

Calls 3

trackCommandUsedFunction · 0.90
createNewWorkspaceFunction · 0.85
getInfoMethod · 0.80

Tested by

no test coverage detected